belongsTo('App\Models\Merchant', 'merchant_id', 'id'); } public function getTypeNameAttribute() { $type = config('adconfig.money_log_type'); return $type[$this->type]; } /** * 钱包余额增加日志 * @param $order * @param $money * @return mixed */ public static function addMoney($order, $money) { $model = self::where(['order_id' => $order->id, 'order_type' => 'order', 'merchant_id' => $order->merchant_id])->orderBy('id', 'desc')->first(); //Log::info('资金变动有问题吗?'); if (empty($model)) { //例如:支付宝扫码支付 $desc = config('adconfig.pay_type')[$order->pay_type] . config('adconfig.pay_client')[$order->gateway_method]; //取得原来账号金额 $before_money = 0; //进行锁表 $before_obj = self::where('merchant_id', $order->merchant_id)->lockForUpdate()->orderBy('id', 'desc')->first(); if ($before_obj) { $before_money = $before_obj['money']; } $data = [ 'order_type' => 'order', 'order_id' => $order->id, 'before_money' => $before_money,//原金额 'merchant_id' => $order->merchant_id, 'after_money' => $money,//增加金额 'money' => $before_money + $money,//现在金额=原金额+增加的金额 'type' => 1, 'pay_at' => $order->pay_ok_at, 'order_at' => $order->order_at, 'mark' => $desc, 'created_at' => date('Y-m-d H:i:s') ]; Log::channel('notify_order')->info('资金变动准备插入'); $r = self::insert($data); if ($r) { Log::channel('notify_order')->info('资金变动准备插入完成'); } return $r; } } public static function drawMoney($merchant_id, $money, $desc = '提现申请', $model_id = 0) { //取得原来账号金额 $before_money = 0; $before_obj = self::where('merchant_id', $merchant_id)->orderBy('id', 'desc')->first(); if (!empty($before_obj)) { $before_money = $before_obj['money']; } $data = [ 'order_type' => 'draw', 'order_id' => $model_id, 'before_money' => $before_money,//原金额 'merchant_id' => $merchant_id, 'after_money' => $money,//增加金额 'money' => $before_money + $money,//现在金额=原金额+增加的金额 'type' => 3,//提现 'pay_at' => date('Y-m-d H:i:s'), 'order_at' => date('Y-m-d H:i:s'), 'mark' => $desc, 'created_at' => date('Y-m-d H:i:s') ]; return self::insert($data); } /** * 增加推荐佣金 * @param $commission * @param $money * @return bool */ public static function addCommissionMoney($commission, $money) { //检查这个商户是否已经有日志了, $model = self::where(['order_id' => $commission->id, 'order_type' => 'merchant_commission', 'merchant_id' => $commission->from_merchant_id])->count(); //Log::info('资金变动有问题吗?'); if ($model <= 0) { //例如:支付宝扫码支付 $desc = '代理结算佣金'; //取得原来账号金额 $before_money = 0; $before_obj = self::where('merchant_id', $commission->from_merchant_id)->orderBy('id', 'desc')->first(); if ($before_obj) { $before_money = $before_obj['money']; } $data = [ 'order_type' => 'merchant_commission', 'order_id' => $commission->id, 'before_money' => $before_money,//原金额 'merchant_id' => $commission->from_merchant_id,//上级 'after_money' => $money,//增加金额 'money' => $before_money + $money,//现在金额=原金额+增加的金额 'type' => 4, 'pay_at' => $commission->pay_ok_at, 'order_at' => $commission->order_at, 'mark' => $desc, 'created_at' => date('Y-m-d H:i:s') ]; $r = self::insert($data); return $r; } return false; } /** * 增加注册推广商户 * @param $commission * @param $money * @return bool */ public static function adRegistMerchantMoney($modelObj, $money) { //检查这个商户是否已经有日志了, $has = self::where(['order_id' => $modelObj->id, 'order_type' => 'merchant_order', 'merchant_id' => $modelObj->from_merchant_id])->count(); if ($has <= 0) { $desc = '推广开户佣金'; $before_money = 0; $before_obj = self::where('merchant_id', $modelObj->from_merchant_id)->orderBy('id', 'desc')->first(); if ($before_obj) { $before_money = $before_obj['money']; } $data = [ 'order_type' => 'merchant_commission', 'order_id' => $modelObj->id, 'before_money' => $before_money,//原金额 'merchant_id' => $modelObj->from_merchant_id,//上级 'after_money' => $money,//增加金额 'money' => $before_money + $money,//现在金额=原金额+增加的金额 'type' => 4, 'pay_at' => $modelObj->updated_at, 'order_at' => $modelObj->updated_at, 'mark' => $desc, 'created_at' => date('Y-m-d H:i:s') ]; $r = self::insert($data); return $r; } return false; } }