getFile(), $e->getLine(), $e->getMessage() ]; Log::record(implode('-', $record)); return $e->getMessage(); } } /** * @notes 添加订单日志表 * @param $order_id * @param $user_id * @param $shop_id * @return array * @author suny * @date 2021/7/13 6:32 下午 */ public static function getOrderLogData($order_id, $user_id, $shop_id) { $order_log_data = []; $order_log_data['type'] = OrderLogEnum::TYPE_USER; $order_log_data['channel'] = OrderLogEnum::USER_PAID_ORDER; $order_log_data['order_id'] = $order_id; $order_log_data['handle_id'] = $user_id; $order_log_data['shop_id'] = $shop_id; $order_log_data['content'] = OrderLogEnum::getLogDesc(OrderLogEnum::USER_PAID_ORDER); $order_log_data['create_time'] = time(); return $order_log_data; } /** * @notes 父订单回调 * @param $order_sn * @param array $extra * @throws \think\db\exception\DataNotFoundException * @throws \think\db\exception\DbException * @throws \think\db\exception\ModelNotFoundException * @throws \think\exception\DbException * @author suny * @date 2021/7/13 6:33 下午 */ private static function trade($order_sn, $extra = []) { //根据父订单号查找父订单 $trade = OrderTrade::where(['t_sn' => $order_sn])->find(); //根据父订单id查找子订单 $orders = Order::with(['order_goods', 'shop']) ->where('trade_id', $trade['id']) ->select()->toArray(); //修改用户消费累计额度 $user = User::find($trade['user_id']); $user->total_order_amount = ['inc', $trade['order_amount']]; $user->save(); //赠送成长值 $growth_ratio = ConfigServer::get('transaction', 'money_to_growth', 0); if ($growth_ratio > 0) { $able_get_growth = floor($trade['total_amount'] / $growth_ratio); $user->where('id', $trade['user_id']) ->inc('user_growth', $able_get_growth) ->update(); AccountLogLogic::AccountRecord($trade['user_id'], $able_get_growth, 1, AccountLog::order_give_growth, '', $trade['id'], $order_sn); } // 生成分销订单 PayLogic::distributionOrderGoods(array_column($orders, 'id')); // 更新分销会员等级 DistributionLevelLogic::updateDistributionLevel($trade['user_id']); foreach ($orders as $item) { //赠送积分 $open_award = ConfigServer::get('order_award', 'open_award', 0); if ($open_award == 1) { $award_event = ConfigServer::get('order_award', 'award_event', 0); $award_ratio = ConfigServer::get('order_award', 'award_ratio', 0); if ($award_ratio > 0) { $award_integral = floor($item['order_amount'] * ($award_ratio / 100)); } } //更新订单状态 $data = [ 'pay_status' => PayEnum::ISPAID, 'pay_time' => time(), 'order_status' => Order::STATUS_WAIT_DELIVERY, 'award_integral_status' => $award_event ?? 0, 'award_integral' => $award_integral ?? 0 ]; //如果返回了第三方流水号 if (isset($extra['transaction_id'])) { $data['transaction_id'] = $extra['transaction_id']; } Order::update($data, ['id' => $item['id']]); // 增加一条订单日志 $order_log_add_data = self::getOrderLogData($item['id'], $item['user_id'], $item['shop_id']); $order_log_datas_insert[] = $order_log_add_data; OrderLog::insertAll($order_log_datas_insert); // if ($item['order_type'] == order::NORMAL_ORDER){ // DistributionServer::commission($item['id']); // } //通知用户 event('Notice', [ 'scene' => NoticeEnum::ORDER_PAY_NOTICE, 'mobile' => $user['mobile'], 'params' => ['order_id' => $item['id'], 'user_id' => $item['user_id']] ]); //通知商家 if (!empty($item['shop']['mobile'])) { event('Notice', [ 'scene' => NoticeEnum::USER_PAID_NOTICE_SHOP, 'mobile' => $item['shop']['mobile'], 'params' => ['order_id' => $item['id'], 'user_id' => $item['user_id']] ]); } event('Printer', [ 'order_id' => $item['id'], ]); } //如果返回了第三方流水号 if (isset($extra['transaction_id'])) { $trade->transaction_id = $extra['transaction_id']; $trade->save(); } $order_ids = array_column($orders, 'id'); // 虚拟商品更新订单信息 GoodsVirtualLogic::afterPayVirtualDelivery($order_ids); // 更新商品销量 self::updateGoodsSales($order_ids); } /** * @notes 子订单回调 * @param $order_sn * @param array $extra * @throws \think\db\exception\DataNotFoundException * @throws \think\db\exception\DbException * @throws \think\db\exception\ModelNotFoundException * @throws \think\exception\DbException * @author suny * @date 2021/7/13 6:33 下午 */ private static function order($order_sn, $extra = []) { $time = time(); $order = Order::with(['order_goods', 'shop']) ->where('order_sn', $order_sn) ->find()->toArray(); //赠送积分 $open_award = ConfigServer::get('order_award', 'open_award', 0); if ($open_award == 1) { $award_event = ConfigServer::get('order_award', 'award_event', 0); $award_ratio = ConfigServer::get('order_award', 'award_ratio', 0); if ($award_ratio > 0) { $award_integral = floor($order['order_amount'] * ($award_ratio / 100)); } } //更新订单状态 $data = [ 'pay_status' => PayEnum::ISPAID, 'pay_time' => time(), 'order_status' => Order::STATUS_WAIT_DELIVERY, 'award_integral_status' => $award_event ?? 0, 'award_integral' => $award_integral ?? 0 ]; //如果返回了第三方流水号 if (isset($extra['transaction_id'])) { $data['transaction_id'] = $extra['transaction_id']; } Order::update($data, ['id' => $order['id']]); // 增加商品销量 // 增加一条订单日志 $order_log_add_data = self::getOrderLogData($order['id'], $order['user_id'], $order['shop_id']); $order_log_datas_insert[] = $order_log_add_data; OrderLog::insertAll($order_log_datas_insert); //修改用户消费累计额度 $user = User::find($order['user_id']); $user->total_order_amount = ['inc', $order['order_amount']]; $user->save(); //赠送成长值 $growth_ratio = ConfigServer::get('transaction', 'money_to_growth', 0); if ($growth_ratio > 0) { $able_get_growth = floor($order['order_amount'] / $growth_ratio); $user->where('id', $order['user_id']) ->inc('user_growth', $able_get_growth) ->update(); AccountLogLogic::AccountRecord($order['user_id'], $able_get_growth, 1, AccountLog::order_give_growth, '', $order['id'], $order_sn); } // 生成分销订单 PayLogic::distributionOrderGoods([$order['id']]); // 更新分销会员等级 DistributionLevelLogic::updateDistributionLevel($order['user_id']); // //拼购,砍价的订单不参与分销分佣 // if ($order['order_type'] == order::NORMAL_ORDER){ // DistributionServer::commission($order['id']); // } // 虚拟商品更新订单信息 GoodsVirtualLogic::afterPayVirtualDelivery($order['id']); // 更新商品销量 self::updateGoodsSales($order['id']); //通知用户 event('Notice', [ 'scene' => NoticeEnum::ORDER_PAY_NOTICE, 'mobile' => $user['mobile'], 'params' => ['order_id' => $order['id'], 'user_id' => $order['user_id']] ]); //通知商家 if (!empty($order['shop']['mobile'])) { event('Notice', [ 'scene' => NoticeEnum::USER_PAID_NOTICE_SHOP, 'mobile' => $order['shop']['mobile'], 'params' => ['order_id' => $order['id'], 'user_id' => $order['user_id']] ]); } event('Printer', [ 'order_id' => $order['id'], ]); } /** * @notes 充值回调 * @param $order_sn * @param array $extra * @throws \think\db\exception\DataNotFoundException * @throws \think\db\exception\DbException * @throws \think\db\exception\ModelNotFoundException * @throws \think\exception\DbException * @author suny * @date 2021/7/13 6:33 下午 */ private static function recharge($order_sn, $extra = []) { /* 会有定时任务检索订单状态,所以在时间上可能会前后不一致,因此需要做个过滤 */ $new = time(); $recharge_order = new RechargeOrder(); $order = $recharge_order->where(['order_sn' => $order_sn])->find(); if ($order['pay_status'] != PayEnum::ISPAID) { $update_data['pay_time'] = $new; $update_data['pay_status'] = PayEnum::ISPAID; if (isset($extra['transaction_id'])) { $update_data['transaction_id'] = $extra['transaction_id']; } $recharge_order->where(['id' => $order['id']])->update($update_data); $user = User::find($order['user_id']); $total_money = $order['order_amount'] + $order['give_money']; $total_integral = $order['give_integral']; $user->user_money = ['inc', $total_money]; $user->user_integral = ['inc', $total_integral]; $user->user_growth = ['inc', $order['give_growth']]; $user->total_recharge_amount = ['inc', $total_money]; $user->save(); //记录余额 $total_money > 0 && AccountLogLogic::AccountRecord($user->id, $total_money, 1, AccountLog::recharge_money, '', $order['id'], $order_sn); //记录积分 $total_integral > 0 && AccountLogLogic::AccountRecord($user->id, $total_integral, 1, AccountLog::recharge_give_integral); //记录成长值 $order['give_growth'] > 0 && AccountLogLogic::AccountRecord($user->id, $order['give_growth'], 1, AccountLog::recharge_give_growth); // 余额充值参与百亿补贴 self::recharge_billions($order, $order['user_id']); } } private static function recharge_billions($order, $user_id) { $user_subsidy = 2; // 自我补贴 $all_user_subsidy = 20; //全用户获取的比例 $user_start_num = 5; // 补贴前几位数量 $user_start_subsidy = 30; //补贴前几位比例 全用户比例中扣除 $user_end_subsidy = 70; //补贴剩余部分比例 $user_first_leader = 30; // 推广者排队补贴 $first_leader = 5; //分销推广者补贴 $store_subsidy = 5; // 店铺推广者补贴 如没有补贴给店铺拥有者 $donglonghui = 5; //东龙汇服务费 $other_leader = 3; //分公司收入 如没有则并入东龙汇 $shop_com = 60; // 商家获取收入 $user = Db::name("user")->where(['id' => $user_id])->find(); $is_d = Distribution::where('user_id', $user['first_leader'] )->where('is_distribution', 1 )->find(); $data['order_price'] = $order['order_amount']; // 改为充值金额 $data['user_id'] = $user_id; $data['goods_id'] = 0; // 充值接口不需要该参数 $data['shop_id'] = 0; // 充值接口不需要该参数 $data['goods_num'] = 1; // 充值接口设置为1 $data['order_id'] = $order['id']; $data['dtime'] = date("Y-m-d H:i:s"); $data['type'] = 2; // 类型是充值 $data['subsidy_price'] = round($order['order_amount'] * $user_subsidy / 100,5); $res = Db::name("user_billions")->save($data); $billions_msg = Db::name("user_billions")->where("state",0)->select()->toArray(); $subsidy = $order['order_amount'] * $all_user_subsidy / 100; if($is_d != null){ $ufl = round($subsidy*$user_first_leader/100,5); $subsidy_ufl = round($subsidy - $ufl,5); $first_billions_msg = Db::name("user_billions")->where("user_id",$user['first_leader'])->where("state",0)->select()->toArray(); if(count($first_billions_msg) > 0){ foreach($first_billions_msg as $k=>$v){ if($ufl > 0){ if($v['order_price'] <= $ufl+$v['subsidy_price']){ // 查询用户总余额账户 $first_user_all_account = Db::name("subsidy_withdrawal")->where("user_id",$v['user_id'])->find(); if($first_user_all_account != null){ // 判断账户是否可用 if($first_user_all_account['state'] == 0 || $first_user_all_account['state'] == 2){ return -2; } // 更新主表 $first_update_subsidy_withdrawal = Db::name("subsidy_withdrawal")->where("user_id",$v['user_id'])->inc("total_amount",$v['order_price'])->update(); if(!$first_update_subsidy_withdrawal){ return -4; } $dat['subsidy_withdrawal_id'] = $first_user_all_account['id']; $dat['user_id'] = $v['user_id']; $dat['billions_id'] = $v['billions_id']; $dat['type'] = 1; $dat['money'] = $v['order_price']; $dat['create_time'] = date("Y-m-d H:i:s"); // 插入提现记录 $first_save_record = Db::name("subsidy_withdrawal_record")->save($dat); if(!$first_save_record){ return -5; } }else{ $d['user_id'] = $v['user_id']; $d['total_amount'] = $v['order_price']; $first_update_subsidy_withdrawal = Db::name("subsidy_withdrawal")->insertGetId($d); if(!$first_update_subsidy_withdrawal){ return -4; } $dat['subsidy_withdrawal_id'] = $first_update_subsidy_withdrawal; $dat['user_id'] = $v['user_id']; $dat['billions_id'] = $v['billions_id']; $dat['type'] = 1; $dat['money'] = $v['order_price']; $dat['create_time'] = date("Y-m-d H:i:s"); // 插入提现记录 $first_save_record = Db::name("subsidy_withdrawal_record")->save($dat); if(!$first_save_record){ return -5; } } // 更新排队状态 $first_update_user_billions = Db::name("user_billions")->where("billions_id",$v['billions_id'])->update(['subsidy_price'=>$v['order_price'],"state"=>2]); if(!$first_update_user_billions){ return -3; } // 剩余金额 $ufl = round($ufl+$v['subsidy_price']-$v['order_price'],5); }else{ Db::name("user_billions")->where("billions_id",$v['billions_id'])->inc("subsidy_price",$ufl)->update(); $ufl = 0; } } } $subsidy = round($subsidy_ufl + $ufl,5); } } // $first_msg = Db::name("user_billions")->where("user_id",$user['first_leader'])->where("state",0)->select()->toArray(); $count = count($billions_msg); $arr = $arr1 = array(); // 数量超出前几位补贴用户 if($count > $user_start_num) { $start_subsidy = $subsidy * $user_start_subsidy / 100; $average = round($start_subsidy / $user_start_num, 5); $last = round($start_subsidy - $average * ($user_start_num - 1), 5); for ($i = 0; $i < $user_start_num; $i++) { if ($i + 1 == $user_start_num) { $arr[$i] = $last; } else { $arr[$i] = $average; } } // 剩余人数补贴 $end_average = round(($subsidy - $start_subsidy)/ ($count-$user_start_num), 5); $end_last = round($subsidy - $start_subsidy - $end_average * ($count-$user_start_num - 1), 5); for ($y = 0; $y < $count-$user_start_num; $y++) { if ($y + 1 == $count-$user_start_num) { $arr1[$y] = $end_average; } else { $arr1[$y] = $end_last; } } }else{ $user_start_num = $count; // 数量不超出前几位补贴用户,按全部金额计算 $average = round($subsidy/$count, 5); $last = round($subsidy - $average * ($count - 1), 5); for ($i = 0; $i < $count; $i++) { if ($i + 1 == $count) { $arr[$i] = $last; } else { $arr[$i] = $average; } } } foreach($billions_msg as $k=>$v){ if($k + 1 <= $user_start_num){ // var_dump($v['order_price']); // var_dump($arr[$k]); // var_dump($v['subsidy_price']); if($v['order_price'] <= $arr[$k] + $v['subsidy_price']){ // 查询用户总余额账户 $user_all_account = Db::name("subsidy_withdrawal")->where("user_id", $v['user_id'])->find(); if($user_all_account != null){ // 判断账户是否可用 if($user_all_account['state'] == 0 || $user_all_account['state'] == 2){ return -2; } // 更新主表 $update_subsidy_withdrawal = Db::name("subsidy_withdrawal")->where("user_id", $v['user_id'])->inc("total_amount", $v['order_price'])->update(); if(!$update_subsidy_withdrawal){ return -4; } $dat['subsidy_withdrawal_id'] = $user_all_account['id']; $dat['user_id'] = $v['user_id']; $dat['billions_id'] = $v['billions_id']; $dat['type'] = 1; $dat['money'] = $v['order_price']; $dat['create_time'] = date("Y-m-d H:i:s"); // 插入提现记录 $save_record = Db::name("subsidy_withdrawal_record")->save($dat); if(!$save_record){ return -5; } }else{ $d['user_id'] = $v['user_id']; $d['total_amount'] = $v['order_price']; $update_subsidy_withdrawal = Db::name("subsidy_withdrawal")->insertGetId($d); if(!$update_subsidy_withdrawal){ return -4; } $dat['subsidy_withdrawal_id'] = $update_subsidy_withdrawal; $dat['user_id'] = $v['user_id']; $dat['billions_id'] = $v['billions_id']; $dat['type'] = 1; $dat['money'] = $v['order_price']; $dat['is_recharge'] = 1; $dat['create_time'] = date("Y-m-d H:i:s"); // 插入提现记录 $save_record = Db::name("subsidy_withdrawal_record")->save($dat); if(!$save_record){ return -5; } } // 更新排队状态 $update_user_billions = Db::name("user_billions")->where("billions_id", $v['billions_id'])->update(['subsidy_price' => $v['order_price'], "state" => 2]); if(!$update_user_billions){ return -3; } // 剩余数量 $residue_count = $user_start_num - $k - 1; // 剩余金额 $residue_price = round($arr[$k]+$v['subsidy_price']-$v['order_price'],5); foreach($arr as $k1=>$v1){ if($k1 > $k){ $residue_price+=$arr[$k1]; } } $average = round($residue_price/$residue_count,5); $last = round($residue_price - $average*($residue_count-1),5); foreach($arr as $k1=>$v1){ if($k1+1 == $user_start_num){ $arr[$k1] = $last; }else{ if($k1 > $k){ $arr[$k1] = $average; } } } }else{ Db::name("user_billions")->where("billions_id", $v['billions_id'])->inc("subsidy_price", $arr[$k])->update(); } }else{ if($v['order_price'] <= $arr1[$k - $user_start_num] + $v['subsidy_price']){ // 查询用户总余额账户 $user_all_account = Db::name("subsidy_withdrawal")->where("user_id", $v['user_id'])->find(); if($user_all_account == null){ $d['user_id'] = $v['user_id']; $d['total_amount'] = $v['order_price']; $update_subsidy_withdrawal = Db::name("subsidy_withdrawal")->insertGetId($d); if(!$update_subsidy_withdrawal){ return -4; } $dat['subsidy_withdrawal_id'] = $update_subsidy_withdrawal; $dat['user_id'] = $v['user_id']; $dat['billions_id'] = $v['billions_id']; $dat['type'] = 1; $dat['money'] = $v['order_price']; $dat['is_recharge'] = 1; $dat['create_time'] = date("Y-m-d H:i:s"); // 插入提现记录 $save_record = Db::name("subsidy_withdrawal_record")->save($dat); if(!$save_record){ return -5; } }else{ // 判断账户是否可用 if($user_all_account['state'] == 0 || $user_all_account['state'] == 2){ return -2; } // 更新主表 $update_subsidy_withdrawal = Db::name("subsidy_withdrawal")->where("user_id",$v['user_id'])->inc("total_amount",$v['order_price'])->update(); if(!$update_subsidy_withdrawal){ return -4; } $dat['subsidy_withdrawal_id'] = $user_all_account['id']; $dat['user_id'] = $v['user_id']; $dat['billions_id'] = $v['billions_id']; $dat['type'] = 1; $dat['money'] = $v['order_price']; $dat['is_recharge'] = 1; $dat['create_time'] = date("Y-m-d H:i:s"); // 插入提现记录 $save_record = Db::name("subsidy_withdrawal_record")->save($dat); if(!$save_record){ return -5; } } // 更新排队状态 $update_user_billions = Db::name("user_billions")->where("billions_id",$v['billions_id'])->update(['subsidy_price'=>$v['order_price'],"state"=>2]); if(!$update_user_billions){ return -3; } // 剩余数量 $residue_count = $count-$user_start_num - $k+$user_start_num - 1; // 剩余金额 $residue_price = round($arr1[$k-$user_start_num]+$v['subsidy_price']-$v['order_price'],5); foreach($arr1 as $k1=>$v1){ if($k1 > $k - $user_start_num){ $residue_price+=$arr1[$k1]; } } $average = round($residue_price/$residue_count,5); $last = round($residue_price - $average*($residue_count-1),5); foreach($arr1 as $k1=>$v1){ if($k1+1 == $count-$user_start_num){ $arr1[$k1] = $last; }else{ if($k1 > $k){ $arr[$k1] = $average; } } } }else{ Db::name("user_billions")->where("billions_id",$v['billions_id'])->inc("subsidy_price",$arr1[$k-$user_start_num])->update(); } } } if($is_d!=null){ if($user['first_leader']>0){ $first_leader_percent = round($order['order_amount'] * $first_leader / 100, 5); // Order::where('id', $order['id']) // ->inc('distribution_money',$first_leader_percent)->update(); UserDistribution::where('user_id', $user['first_leader']) ->inc('order_amount', $first_leader_percent)->update(); UserDistribution::where('user_id', $user['first_leader']) ->inc('order_num')->update(); User::where('id', $user['first_leader']) ->inc('earnings', $first_leader_percent)->update(); $earnings_buy = AccountLog::where('user_id', $user['first_leader'])->order("create_time desc")->limit(1)->value('left_amount'); $sn = createSn('account_log', 'log_sn', '', 4); AccountLog::create([ 'log_sn' => $sn, 'user_id' => $user['first_leader'], 'source_type' => AccountLog::recharge_billions_inc_earnings, //todo 改为充值类型 'source_id' => $order['id'], //todo 改为充值订单主键 'source_sn' => $order['order_sn'], // todo 改为充值订单编号 'change_amount' => $first_leader_percent, 'left_amount' => $earnings_buy + $first_leader_percent, 'change_type' => 1, 'remark' => '百亿返补佣金增加' ]); DistributionOrderGoods::create([ 'sn' => $sn, 'user_id' => $user['first_leader'], 'ratio' => $first_leader, 'order_id' => $order['id'], //todo 改为充值订单主键 'order_goods_id' => 0, //todo 因为是充值所以改为0 'goods_num' => 1, // todo 因为是充值所以改为1 'money' => $first_leader_percent, 'status' => 2, 'create_time' => time(), 'shop_id' => 0, // todo 因为是充值所以改为默认0 'is_recharge' => 1, // todo 因为是充值所以改为1 'settlement_time' => time() ]); } $role_user_msg = Db::name("user")->where("id",$user['divide_role_user_id'])->find(); $state = 0; if($role_user_msg != null){ $state = $role_user_msg['divide_state']; } // 3%对公司 if($user['divide_role_user_id'] > 0&&$state>0 ){ $divide_percent = round($order['order_amount'] * $other_leader / 100, 5); // Order::where('id', $order['id']) // ->inc('distribution_money',$divide_percent)->update(); // $shopDistribution_msg = UserShopDistribution::where('shop_id', $value['shop_id']) // ->find(); User::where('id', $user['divide_role_user_id']) ->inc('earnings', $divide_percent)->update(); $earnings_buy = AccountLog::where('user_id', $user['divide_role_user_id'])->order("create_time desc")->limit(1)->value('left_amount'); $sn = createSn('account_log', 'log_sn', '', 4); AccountLog::create([ 'log_sn' => $sn, 'user_id' => $user['divide_role_user_id'], 'source_type' => AccountLog::recharge_billions_inc_earnings, //todo 改为充值类型 'source_id' => $order['id'], //todo 改为充值订单主键 'source_sn' => $order['order_sn'], // todo 改为充值订单编号 'change_amount' => $divide_percent, 'left_amount' => $earnings_buy + $divide_percent, 'change_type' => 1, 'remark' => '充值百亿返补佣金增加' ]); DistributionOrderGoods::create([ 'sn' => $sn, 'user_id' => $user['divide_role_user_id'], 'ratio' => $other_leader, 'order_id' => $order['id'], //todo 改为充值订单主键 'order_goods_id' => 0, //todo 因为是充值所以改为0 'goods_num' => 1, // todo 因为是充值所以改为1 'money' => $divide_percent, 'status' => 2, 'create_time' => time(), 'shop_id' => 0, // todo 因为是充值所以改为默认0 'is_recharge' => 1, // todo 因为是充值所以改为1 'settlement_time' => time() ]); } } } /** * @notes 积分订单回调 * @param $order_sn * @param array $extra * @throws \think\db\exception\DataNotFoundException * @throws \think\db\exception\ModelNotFoundException * @author 段誉 * @date 2022/3/1 14:36 */ private static function integral($order_sn, $extra = []) { $order = IntegralOrder::where(['order_sn' => $order_sn])->findOrEmpty(); $goods = $order['goods_snap']; // 更新订单状态 $data = [ 'order_status' => IntegralOrderEnum::ORDER_STATUS_DELIVERY, 'pay_status' => PayEnum::ISPAID, 'pay_time' => time(), ]; // 红包类型 或者 无需物流 支付完即订单完成 if ($goods['type'] == IntegralGoodsEnum::TYPE_BALANCE || $goods['delivery_way'] == IntegralGoodsEnum::DELIVERY_NO_EXPRESS) { $data['order_status'] = IntegralOrderEnum::ORDER_STATUS_COMPLETE; $data['confirm_time'] = time(); } // 第三方流水号 if (isset($extra['transaction_id'])) { $data['transaction_id'] = $extra['transaction_id']; } IntegralOrder::update($data, ['id' => $order['id']]); // 更新商品销量 IntegralGoods::where([['id', '=', $goods['id']], ['stock', '>=', $order['total_num']]]) ->dec('stock', $order['total_num']) ->inc('sales', $order['total_num']) ->update(); // 红包类型,直接增加余额 if ($goods['type'] == IntegralGoodsEnum::TYPE_BALANCE) { $reward = round($goods['balance'] * $order['total_num'], 2); User::where(['id' => $order['user_id']]) ->inc('user_money', $reward) ->update(); AccountLogLogic::AccountRecord( $order['user_id'], $reward, 1, AccountLog::integral_order_inc_balance, '', $order['id'], $order['order_sn'] ); } } /** * @notes 更新商品销量 * @param $order_id * @return bool * @throws \think\db\exception\DataNotFoundException * @throws \think\db\exception\DbException * @throws \think\db\exception\ModelNotFoundException * @author 段誉 * @date 2022/10/14 10:16 */ private static function updateGoodsSales($order_ids) { if (!is_array($order_ids)) { $order_ids = [$order_ids]; } $order_goods = OrderGoods::whereIn('order_id', $order_ids) ->select() ->toArray(); if (empty($order_goods)) { return false; } foreach ($order_goods as $item) { // 增加商品销量 Goods::where('id', $item['goods_id']) ->inc('sales_actual', $item['goods_num']) ->update(); } return true; } }