setName('pensiontask') ->setDescription('the pensiontask command'); } protected function execute(Input $input, Output $output) { //1线下2在线3拼多多4京东5苏宁6淘宝7VIP $nowTime = time(); try { //线下符合条件的养老金收集(线下交易后第8天) $this->doOfflineOrderGzc($nowTime, $timeLimit = 1); //在线订单符合条件的养老金收集(线上收货后第8天) $this->doOnlineOrderGzc($timeLimit = 8); //第三方订单符合条件的养老金收集(三方结算后第2天) $this->doThridPddOrderGzc($nowTime, $timeLimit = 2); $this->doThridJdOrderGzc($nowTime, $timeLimit = 2); $this->doThridSnOrderGzc($nowTime, $timeLimit = 2); $this->doThridTaobaoOrderGzc($nowTime, $timeLimit = 2); $this->doThridVipOrderGzc($nowTime, $timeLimit = 2); $this->doThridDyOrderGzc($nowTime, $timeLimit = 2); $this->doThridHfOrderGzc($nowTime, $timeLimit = 2); //升级 // $this -> doUpgrade(); } catch (\Throwable $e) { Log::info('公证处入账:' . $e->getFile() . ':' . $e->getLine() . '【' . $e->getMessage() . '】'); var_dump('公证处入账:' . $e->getFile() . ':' . $e->getLine() . '【' . $e->getMessage() . '】'); } // 指令输出 $output->writeln('pensiontask'); } /** * 线下支付订单公证处IN10入账 * @param $nowTime * @param $timeLimit * author: php迷途小书童 * created: 2021/3/20 9:26 */ public function doOfflineOrderGzc($nowTime, $timeLimit) { $cursor = Db::table('rrx_order_merchant') ->whereNotNull('pay_time') ->where('paid', 1) ->where('gzc', 0) ->whereTime('pay_time', '<', $nowTime - bcmul((string)$timeLimit, (string)86400)) ->cursor(); $OrderGzcRepository = app()->make(OrderGzcRepository::class); $OrderMerchantRepository = app()->make(OrderMerchantRepository::class); $StoreOrderRepository = app()->make(StoreOrderRepository::class); foreach ($cursor as $offline) { if ($offline['mer_id'] == 496) { continue; } $uid = 0; switch ($offline['trade_type']) { case 'WX': $uid = User::getInstance()->where('wechat_user_id', $offline['pay_user_id'])->value('uid'); $accountType = 3; break; case 'ALI': $uid = User::getInstance()->where('ali_user_id', $offline['pay_user_id'])->value('uid'); $accountType = 2; break; default: break; } if (!$uid) { Log::info($offline['pay_user_id'] . '未绑定用户'); continue; } $certification = UserCertification::getInstance()->where('uid', $uid)->find(); if (!$certification) { Log::info($offline['pay_user_id'] . '未实名认证'); continue; } //查询养老金金额 $UserBillRepository = app()->make(UserBillRepository::class); $bill = $UserBillRepository->getWhere(['uid' => $uid, 'link_id' => $offline['id'], 'order_sn' => $offline['out_trade_no'], 'title' => '养老金']); // if ($bill->status == 0) { // Log::info($offline['out_trade_no'] . 'pension未交年费'); // continue; // } $pension = $bill->number ?? 0; if ($pension <= 0) { Log::info($offline['out_trade_no'] . 'pension' . $pension); continue; } Db::transaction(function () use ($uid, $certification, $accountType, $offline, $OrderGzcRepository, $OrderMerchantRepository, $pension, $StoreOrderRepository) { $order = OrderMerchant::getInstance()->find($offline['id']); $order->gzc = 1; $order->is_settlement = 1; $order->settlement_time = date('Y-m-d H:i:s'); $order->save(); //新增入账明细记录 $orderId = $OrderMerchantRepository->getNewOrderId('IN10'); $create = [ 'uid' => $uid, 'platform_no' => $orderId, 'account_type' => $accountType, 'user_name' => $certification['user_name'], 'mobile' => $certification['mobile'], 'user_card' => $certification['user_card'], 'pension' => $pension, 'order_type' => 1, 'out_trade_no' => $offline['out_trade_no'] ]; $test_user = Db::name('user')->where('uid', $uid)->value('test_user'); if ($test_user == 0) { $OrderGzcRepository->create($create); } // 养老金区域奖励 $order_data = [ 'pay_price' => $pension, 'user_address_ids' => $offline['user_address_ids'], 'uid' => $offline['uid'], 'order_sn' => $offline['out_trade_no'] ]; // $StoreOrderRepository->area_manage_details($order_data, 0, 2); }); } } /** * 在线支付公证处IN10入账 * @param $nowTime * @param $timeLimit * author: php迷途小书童 * created: 2021/3/20 9:25 */ public function doOnlineOrderGzc($timeLimit) { $cursor = Db::table('rrx_store_order') ->where('paid', 1) ->where('gzc', 0) ->where('pay_type', 'in', '0,1,2,4') ->cursor(); $StoreOrderStatusRepository = app()->make(StoreOrderStatusRepository::class); $OrderMerchantRepository = app()->make(OrderMerchantRepository::class); $OrderGzcRepository = app()->make(OrderGzcRepository::class); foreach ($cursor as $online) { $status = $StoreOrderStatusRepository->getWhere(['order_id' => $online['order_id'], 'change_type' => 'take']); if ($online['mer_id'] == 496) { if (!in_array($online['status'], [0, 1, 2, 3])) { continue; } if (time() < strtotime($online['pay_time']) + 3600 * 24) { Log::info('还没有到收货后' . $timeLimit . '天'); continue; } } else { if (!in_array($online['status'], [2, 3])) { continue; } if (Carbon::now()->modify("-{$timeLimit} days")->lt($status->change_time ?? $status['change_time'])) { Log::info('还没有到收货后' . $timeLimit . '天'); continue; } } $certification = UserCertification::getInstance()->where('uid', $online['uid'])->find(); if (!$certification) { Log::info($online['uid'] . '没有实名认证'); continue; } //查询养老金金额 $UserBillRepository = app()->make(UserBillRepository::class); $bill = $UserBillRepository->getWhere(['uid' => $online['uid'], 'link_id' => $online['order_id'], 'order_sn' => $online['order_sn'], 'commission_type' => 5]); $pension = $bill->number ?? 0; if ($pension <= 0) { Log::info($online['order_sn'] . 'pension' . $pension); continue; } //首信易分账 $StoreOrderRepository = app()->make(StoreOrderRepository::class); if ($online['pay_type'] > 0) { $StoreOrderRepository->splitOrder($online); } Db::transaction(function () use ($certification, $online, $pension, $OrderGzcRepository, $OrderMerchantRepository, $StoreOrderRepository) { //新增入账明细记录 $orderId = $OrderMerchantRepository->getNewOrderId('IN10'); $create = [ 'uid' => $online['uid'], 'platform_no' => $orderId, 'account_type' => $online['pay_type'] == 1 ? 3 : 2, 'user_name' => $certification['user_name'], 'mobile' => $certification['mobile'], 'user_card' => $certification['user_card'], 'pension' => $pension, 'order_type' => 2, 'out_trade_no' => $online['order_sn'] ]; $test_user = Db::name('user')->where('uid', $online['uid'])->value('test_user'); $check = Db::name("gzc_logs")->where("out_trade_no", $online['order_sn'])->where("order_type", 2)->count(); if ($test_user == 0 && $check <= 0) { $OrderGzcRepository->create($create); } $order = StoreOrder::getInstance()->find($online['order_id']); $order->gzc = 1; $order->save(); // 养老金区域奖励 // $order_data = [ // 'pay_price' => $pension, // 'user_address_ids' => $online['user_address_ids'], // 'uid' => $online['uid'], // 'order_sn' => $online['order_sn'] // ]; // $StoreOrderRepository->area_manage_details($order_data, 8, 2); }); } $cursor = Db::table('rrx_store_order') ->where('paid', 1) ->where('is_settlement', 0) ->where('pay_type', 'in', '0,1,2,4') ->cursor(); $StoreOrderStatusRepository = app()->make(StoreOrderStatusRepository::class); $OrderMerchantRepository = app()->make(OrderMerchantRepository::class); $OrderGzcRepository = app()->make(OrderGzcRepository::class); foreach ($cursor as $online) { $status = $StoreOrderStatusRepository->getWhere(['order_id' => $online['order_id'], 'change_type' => 'take']); if ($online['mer_id'] == 496) { if (!in_array($online['status'], [0, 1, 2, 3])) { continue; } if (time() < strtotime($online['pay_time']) + 3600 * 24) { Log::info('还没有到收货后' . $timeLimit . '天'); continue; } } else { if (!in_array($online['status'], [2, 3])) { continue; } if (Carbon::now()->modify("-{$timeLimit} days")->lt($status->change_time ?? $status['change_time'])) { Log::info('还没有到收货后' . $timeLimit . '天'); continue; } } $StoreOrderRepository = app()->make(StoreOrderRepository::class); Db::transaction(function () use ($online, $StoreOrderRepository) { $order = StoreOrder::getInstance()->find($online['order_id']); $order->is_settlement = 1; $order->settlement_time = date('Y-m-d H:i:s'); $order->save(); // 结算积分 $user_sign_score_list = Db::name('user_sign_score') ->where('status', -1) ->where('order_id', $online['order_id']) ->whereIn('type', [1, 2]) ->select() ->toArray(); foreach ($user_sign_score_list as $user_sign_score) { // 修改积分 Db::name('user') ->where('uid', $user_sign_score['uid']) ->inc('score', (float)$user_sign_score['reward_socre']) ->update(); Db::name('user_sign_score') ->where('status', -1) ->where('id', $user_sign_score['id']) ->update([ 'status' => 1, 'settlement_time' => date('Y-m-d H:i:s') ]); } $user_bill_list = Db::name('user_bill') ->where('status', 0) ->where('commission_type','<>', 5) ->where([ 'link_id' => $online['order_id'], 'order_sn' => $online['order_sn']]) ->select() ->toArray(); foreach ($user_bill_list as $user_bill) { if ($user_bill['commission_type'] != 5) { if (in_array($user_bill['commission_type'], [7,12,19])) { Db::name("merchant") ->where("mer_id", $user_bill['mer_id']) ->inc('brokerage_price', (float)$user_bill['number']) ->update(); } else { Db::name('user') ->where('uid', $user_bill['uid']) ->inc('brokerage_price', (float)$user_bill['number']) ->update(); } } if ($online['pay_type'] == 0 && $user_bill['commission_type'] == 5) { } else { // 虚拟支付的养老金不修改不结算 Db::name('user_bill') ->where('status', 0) ->where('bill_id', $user_bill['bill_id']) ->update([ 'status' => 1, 'take_time' => time() ]); } if ($online['pay_type'] == 0 && $user_bill['commission_type'] == 5) { } else { // 虚拟支付的养老金不修改不结算 Db::name('user_bill') ->where('status', 0) ->where('bill_id', $user_bill['bill_id']) ->update([ 'status' => 1, 'take_time' => time() ]); } } $StoreOrderRepository->close_order($online['order_id']); }); } } /** * 第三方订单拼多多IN10入账 * @param $nowTime * @param $timeLimit * author: php迷途小书童 * created: 2021/3/20 9:26 */ public function doThridPddOrderGzc($nowTime, $timeLimit) { $cursor = Db::table('rrx_order_pdd') ->where('gzc', 0) ->where('bill_status', 1) ->where('commission', '>', 0) ->whereTime('bill_end_time', '<', $nowTime - bcmul((string)$timeLimit, (string)86400)) ->cursor(); $ProductRepository = app()->make(ProductRepository::class); $OrderGzcRepository = app()->make(OrderGzcRepository::class); $OrderMerchantRepository = app()->make(OrderMerchantRepository::class); $StoreOrderRepository = app()->make(StoreOrderRepository::class); foreach ($cursor as $thrid) { $uid = $thrid['uid']; if (!$uid) continue; $certification = UserCertification::getInstance()->where('uid', $uid)->find(); if (!$certification) { Log::info('用户ID' . $uid . '未实名认证'); continue; } $pension = $ProductRepository->yanglaojin(0, sprintf('%.2f', $thrid['commission'])); Db::transaction(function () use ($uid, $certification, $thrid, $pension, $OrderGzcRepository, $OrderMerchantRepository, $StoreOrderRepository) { //新增入账明细记录 $orderId = $OrderMerchantRepository->getNewOrderId('IN10'); $create = [ 'uid' => $uid, 'platform_no' => $orderId, 'user_name' => $certification['user_name'], 'mobile' => $certification['mobile'], 'user_card' => $certification['user_card'], 'pension' => $pension, 'order_type' => 3, 'out_trade_no' => $thrid['order_sn'] ]; $test_user = Db::name('user')->where('uid', $uid)->value('test_user'); if ($test_user == 0) { $OrderGzcRepository->create($create); } // $OrderGzcRepository->create($create); Db::table('rrx_order_pdd') ->update(['gzc' => 1, 'order_pdd_id' => $thrid['order_pdd_id']]); // 养老金区域奖励 $order_data = [ 'pay_price' => $pension, 'user_address_ids' => $thrid['user_address_ids'], 'uid' => $thrid['uid'], 'order_sn' => $thrid['order_sn'] ]; // $StoreOrderRepository->area_manage_details($order_data, 1, 2); }); } } /** * 第三方订单京东IN10入账 * @param $nowTime * @param $timeLimit * author: php迷途小书童 * created: 2021/3/20 9:26 */ public function doThridJdOrderGzc($nowTime, $timeLimit) { $cursor = Db::table('rrx_order_jd') ->where('gzc', 0) ->where('bill_status', 1) ->where('commission', '>', 0) ->whereTime('bill_end_time', '<', $nowTime - bcmul((string)$timeLimit, (string)86400)) ->cursor(); // Db::name('log')->insert(['data'=>'abbbb入库语句'.$nowTime - bcmul((string)$timeLimit, (string)86400)]); // Db::name('log')->insert(['data'=>'abbbb'.json_encode($cursor)]); $ProductRepository = app()->make(ProductRepository::class); $OrderGzcRepository = app()->make(OrderGzcRepository::class); $OrderMerchantRepository = app()->make(OrderMerchantRepository::class); $StoreOrderRepository = app()->make(StoreOrderRepository::class); foreach ($cursor as $thrid) { $uid = $thrid['uid']; if (!$uid) continue; $certification = UserCertification::getInstance()->where('uid', $uid)->find(); if (!$certification) { Log::info('用户ID' . $uid . '未实名认证'); continue; } $pension = $ProductRepository->yanglaojin(0, sprintf('%.2f', $thrid['commission'])); Db::transaction(function () use ($uid, $certification, $thrid, $pension, $OrderGzcRepository, $OrderMerchantRepository, $StoreOrderRepository) { //新增入账明细记录 $orderId = $OrderMerchantRepository->getNewOrderId('IN10'); $create = [ 'uid' => $uid, 'platform_no' => $orderId, 'user_name' => $certification['user_name'], 'mobile' => $certification['mobile'], 'user_card' => $certification['user_card'], 'pension' => $pension, 'order_type' => 4, 'out_trade_no' => $thrid['order_sn'] ]; $test_user = Db::name('user')->where('uid', $uid)->value('test_user'); if ($test_user == 0) { $OrderGzcRepository->create($create); } // $OrderGzcRepository->create($create); Db::table('rrx_order_jd') ->update(['gzc' => 1, 'order_jd_id' => $thrid['order_jd_id']]); // 养老金区域奖励 $order_data = [ 'pay_price' => $pension, 'user_address_ids' => $thrid['user_address_ids'], 'uid' => $thrid['uid'], 'order_sn' => $thrid['order_sn'] ]; // $StoreOrderRepository->area_manage_details($order_data, 6, 2); }); } } /** * 第三方订单苏宁IN10入账 * @param $nowTime * @param $timeLimit * author: php迷途小书童 * created: 2021/3/20 9:26 */ public function doThridSnOrderGzc($nowTime, $timeLimit) { $cursor = Db::table('rrx_order_su') ->where('gzc', 0) ->where('bill_status', 1) ->where('commission', '>', 0) ->whereTime('bill_end_time', '<', $nowTime - bcmul((string)$timeLimit, (string)86400)) ->cursor(); $ProductRepository = app()->make(ProductRepository::class); $OrderGzcRepository = app()->make(OrderGzcRepository::class); $OrderMerchantRepository = app()->make(OrderMerchantRepository::class); $StoreOrderRepository = app()->make(StoreOrderRepository::class); foreach ($cursor as $thrid) { $uid = $thrid['uid']; if (!$uid) continue; $certification = UserCertification::getInstance()->where('uid', $uid)->find(); if (!$certification) { Log::info('用户ID' . $uid . '未实名认证'); continue; } $pension = $ProductRepository->yanglaojin(0, sprintf('%.2f', $thrid['commission'])); Db::transaction(function () use ($uid, $certification, $thrid, $pension, $OrderGzcRepository, $OrderMerchantRepository, $StoreOrderRepository) { //新增入账明细记录 $orderId = $OrderMerchantRepository->getNewOrderId('IN10'); $create = [ 'uid' => $uid, 'platform_no' => $orderId, 'user_name' => $certification['user_name'], 'mobile' => $certification['mobile'], 'user_card' => $certification['user_card'], 'pension' => $pension, 'order_type' => 5, 'out_trade_no' => $thrid['order_sn'] ]; $test_user = Db::name('user')->where('uid', $uid)->value('test_user'); if ($test_user == 0) { $OrderGzcRepository->create($create); } // $OrderGzcRepository->create($create); Db::table('rrx_order_su') ->update(['gzc' => 1, 'order_su_id' => $thrid['order_su_id']]); // 养老金区域奖励 $order_data = [ 'pay_price' => $pension, 'user_address_ids' => $thrid['user_address_ids'], 'uid' => $thrid['uid'], 'order_sn' => $thrid['order_sn'] ]; // $StoreOrderRepository->area_manage_details($order_data, 3, 2); }); } } /** * 第三方订单话费IN10入账 * @param $nowTime * @param $timeLimit * author: php迷途小书童 * created: 2021/3/20 9:26 */ public function doThridHfOrderGzc($nowTime, $timeLimit) { $cursor = Db::table('rrx_order_huafei') ->where('gzc', 0) ->where('bill_status', 1) ->where('commission', '>', 0) ->whereTime('bill_end_time', '<', $nowTime - bcmul((string)$timeLimit, (string)86400)) ->cursor(); $ProductRepository = app()->make(ProductRepository::class); $OrderGzcRepository = app()->make(OrderGzcRepository::class); $OrderMerchantRepository = app()->make(OrderMerchantRepository::class); foreach ($cursor as $thrid) { $uid = $thrid['uid']; if (!$uid) continue; $certification = UserCertification::getInstance()->where('uid', $uid)->find(); if (!$certification) { Log::info('用户ID' . $uid . '未实名认证'); continue; } $pension = $ProductRepository->yanglaojin(0, sprintf('%.2f', $thrid['commission'])); Db::transaction(function () use ($uid, $certification, $thrid, $pension, $OrderGzcRepository, $OrderMerchantRepository) { //新增入账明细记录 $orderId = $OrderMerchantRepository->getNewOrderId('IN10'); $create = [ 'uid' => $uid, 'platform_no' => $orderId, 'user_name' => $certification['user_name'], 'mobile' => $certification['mobile'], 'user_card' => $certification['user_card'], 'pension' => $pension, 'order_type' => 6, 'out_trade_no' => $thrid['order_sn'] ]; $test_user = Db::name('user')->where('uid', $uid)->value('test_user'); if ($test_user == 0) { $OrderGzcRepository->create($create); } Db::table('rrx_order_huafei')->update(['gzc' => 1, 'order_tb_id' => $thrid['order_tb_id']]); }); } } /** * 第三方订单淘宝IN10入账 * @param $nowTime * @param $timeLimit * author: php迷途小书童 * created: 2021/3/20 9:26 */ public function doThridTaobaoOrderGzc($nowTime, $timeLimit) { $cursor = Db::table('rrx_order_tb') ->where('gzc', 0) ->where('bill_status', 1) ->where('commission', '>', 0) ->whereTime('bill_end_time', '<', $nowTime - bcmul((string)$timeLimit, (string)86400)) ->cursor(); $ProductRepository = app()->make(ProductRepository::class); $OrderGzcRepository = app()->make(OrderGzcRepository::class); $OrderMerchantRepository = app()->make(OrderMerchantRepository::class); $StoreOrderRepository = app()->make(StoreOrderRepository::class); foreach ($cursor as $thrid) { $uid = $thrid['uid']; if (!$uid) continue; $certification = UserCertification::getInstance()->where('uid', $uid)->find(); if (!$certification) { Log::info('用户ID' . $uid . '未实名认证'); continue; } $pension = $ProductRepository->yanglaojin(0, sprintf('%.2f', $thrid['commission'])); Db::transaction(function () use ($uid, $certification, $thrid, $pension, $OrderGzcRepository, $OrderMerchantRepository, $StoreOrderRepository) { //新增入账明细记录 $orderId = $OrderMerchantRepository->getNewOrderId('IN10'); $create = [ 'uid' => $uid, 'platform_no' => $orderId, 'user_name' => $certification['user_name'], 'mobile' => $certification['mobile'], 'user_card' => $certification['user_card'], 'pension' => $pension, 'order_type' => 6, 'out_trade_no' => $thrid['order_sn'] ]; $test_user = Db::name('user')->where('uid', $uid)->value('test_user'); if ($test_user == 0) { $OrderGzcRepository->create($create); } // $OrderGzcRepository->create($create); Db::table('rrx_order_tb') ->update(['gzc' => 1, 'order_tb_id' => $thrid['order_tb_id']]); // 养老金区域奖励 $order_data = [ 'pay_price' => $pension, 'user_address_ids' => $thrid['user_address_ids'], 'uid' => $thrid['uid'], 'order_sn' => $thrid['order_sn'] ]; // $StoreOrderRepository->area_manage_details($order_data, 5, 2); }); } } /** * 第三方订单唯品会IN10入账 * @param $nowTime * @param $timeLimit * author: php迷途小书童 * created: 2021/3/20 9:26 */ public function doThridVipOrderGzc($nowTime, $timeLimit) { $cursor = Db::table('rrx_order_vip') ->where('gzc', 0) ->where('bill_status', 1) ->where('commission', '>', 0) ->whereTime('bill_end_time', '<', $nowTime - bcmul((string)$timeLimit, (string)86400)) ->cursor(); $ProductRepository = app()->make(ProductRepository::class); $OrderGzcRepository = app()->make(OrderGzcRepository::class); $OrderMerchantRepository = app()->make(OrderMerchantRepository::class); $StoreOrderRepository = app()->make(StoreOrderRepository::class); foreach ($cursor as $thrid) { $uid = $thrid['uid']; if (!$uid) continue; $certification = UserCertification::getInstance()->where('uid', $uid)->find(); if (!$certification) { Log::info('用户ID' . $uid . '未实名认证'); continue; } $pension = $ProductRepository->yanglaojin(0, sprintf('%.2f', $thrid['commission'])); Db::transaction(function () use ($uid, $certification, $thrid, $pension, $OrderGzcRepository, $OrderMerchantRepository, $StoreOrderRepository) { //新增入账明细记录 $orderId = $OrderMerchantRepository->getNewOrderId('IN10'); $create = [ 'uid' => $uid, 'platform_no' => $orderId, 'user_name' => $certification['user_name'], 'mobile' => $certification['mobile'], 'user_card' => $certification['user_card'], 'pension' => $pension, 'order_type' => 7, 'out_trade_no' => $thrid['order_sn'] ]; $test_user = Db::name('user')->where('uid', $uid)->value('test_user'); if ($test_user == 0) { $OrderGzcRepository->create($create); } // $OrderGzcRepository->create($create); Db::table('rrx_order_vip') ->update(['gzc' => 1, 'order_vip_id' => $thrid['order_vip_id']]); // 养老金区域奖励 $order_data = [ 'pay_price' => $pension, 'user_address_ids' => $thrid['user_address_ids'], 'uid' => $thrid['uid'], 'order_sn' => $thrid['order_sn'] ]; // $StoreOrderRepository->area_manage_details($order_data, 2, 2); }); } } /** * 第三方订单抖音IN10入账 * @param $nowTime * @param $timeLimit * author: php迷途小书童 * created: 2021/3/20 9:26 */ public function doThridDyOrderGzc($nowTime, $timeLimit) { $cursor = Db::table('rrx_order_dy') ->where('gzc', 0) ->where('bill_status', 1) ->where('commission', '>', 0) ->whereTime('bill_end_time', '<', $nowTime - bcmul((string)$timeLimit, (string)86400)) ->cursor(); $ProductRepository = app()->make(ProductRepository::class); $OrderGzcRepository = app()->make(OrderGzcRepository::class); $OrderMerchantRepository = app()->make(OrderMerchantRepository::class); $StoreOrderRepository = app()->make(StoreOrderRepository::class); foreach ($cursor as $thrid) { $uid = $thrid['uid']; if (!$uid) continue; $certification = UserCertification::getInstance()->where('uid', $uid)->find(); if (!$certification) { Log::info('用户ID' . $uid . '未实名认证'); continue; } $pension = $ProductRepository->yanglaojin(0, sprintf('%.2f', $thrid['commission'])); Db::transaction(function () use ($uid, $certification, $thrid, $pension, $OrderGzcRepository, $OrderMerchantRepository, $StoreOrderRepository) { //新增入账明细记录 $orderId = $OrderMerchantRepository->getNewOrderId('IN10'); $create = [ 'uid' => $uid, 'platform_no' => $orderId, 'user_name' => $certification['user_name'], 'mobile' => $certification['mobile'], 'user_card' => $certification['user_card'], 'pension' => $pension, 'order_type' => 8, 'out_trade_no' => $thrid['order_sn'] ]; $test_user = Db::name('user')->where('uid', $uid)->value('test_user'); if ($test_user == 0) { $OrderGzcRepository->create($create); } Db::table('rrx_order_dy') ->update(['gzc' => 1, 'order_dy_id' => $thrid['order_dy_id']]); // 养老金区域奖励 $order_data = [ 'pay_price' => $pension, 'user_address_ids' => $thrid['user_address_ids'], 'uid' => $thrid['uid'], 'order_sn' => $thrid['order_sn'] ]; // $StoreOrderRepository->area_manage_details($order_data, 9, 2); }); } } /** * 志愿者升级 * */ public function doUpgrade() { set_time_limit(0); try { //志愿者条件 $volunteer_achievement = systemConfig("volunteer_achievement"); //volunteer_achievement:用户本人满足养老金要求可升级为志愿者 //一星条件 $a_volunteer_achievement = systemConfig("a_volunteer_achievement");//团队养老金要求 $a_volunteer_number = systemConfig("a_volunteer_number"); //团队人数要求 //二星条件 $b_volunteer_achievement = systemConfig("b_volunteer_achievement");//团队养老金要求 $b_volunteer_number = systemConfig("b_volunteer_number"); //团队人数要求 //三星条件 $c_volunteer_achievement = systemConfig("c_volunteer_achievement");//团队养老金要求 $c_volunteer_number = systemConfig("c_volunteer_number"); //团队人数要求 //董事条件 $d_volunteer_achievement = systemConfig("d_volunteer_achievement");//团队养老金要求 $d_volunteer_number = systemConfig("d_volunteer_number"); //团队人数要求 //用户列表 $userList = Db::name("User") ->field("uid") ->select(); foreach ($userList as $key => $value) { $volunteer = $this->volunteer($value['uid']); //本人养老金小于志愿者要求 if ($volunteer['self_yanglao'] < $volunteer_achievement) { $this->grade($value['uid'], 0, $volunteer); } //满足志愿者要求 if ($volunteer['self_yanglao'] >= $volunteer_achievement) { //志愿者 if ($volunteer['team'] < $a_volunteer_number || $volunteer['yanglao'] < $a_volunteer_achievement) { $this->grade($value['uid'], 1, $volunteer); } //一星 if ($volunteer['team'] >= $a_volunteer_number && $volunteer['yanglao'] >= $a_volunteer_achievement//满足一星条件 && ($volunteer['team'] < $b_volunteer_number || $volunteer['yanglao'] < $b_volunteer_achievement)//未满足二星条件 ) { $this->grade($value['uid'], 2, $volunteer); } //二星 if ($volunteer['team'] >= $b_volunteer_number && $volunteer['yanglao'] >= $b_volunteer_achievement//满足二星条件 && ($volunteer['team'] < $c_volunteer_number || $volunteer['yanglao'] < $c_volunteer_achievement)//未满足三星条件 ) { $this->grade($value['uid'], 3, $volunteer); } //三星 if ($volunteer['team'] >= $c_volunteer_number && $volunteer['yanglao'] >= $c_volunteer_achievement//满足三星条件 && ($volunteer['team'] < $d_volunteer_number || $volunteer['yanglao'] < $d_volunteer_achievement)//未满足董事条件 ) { $this->grade($value['uid'], 4, $volunteer); } //董事 if ($volunteer['team'] >= $d_volunteer_number && $volunteer['yanglao'] >= $d_volunteer_achievement) { $this->grade($value['uid'], 5, $volunteer); } } //团队各等级数量统计 $this->statistics($value['uid']); } } catch (Exception $e) { Log::info('志愿者升级:' . $e->getMessage()); } } //志愿者信息 public function volunteer($uid) { if (!$uid) { return false; } //本人养老金 $data['self_yanglao'] = $this->getYanglao($uid); //团队人数 $data['team'] = $this->volunteer_number($uid); //团队养老金 $data['yanglao'] = $this->volunteer_achievement($uid); //直推人数 $data['extension'] = Db::name("user_identity_log")->where(["uid" => $uid])->count(); //直推商户数量 $data['shop'] = Db::name("user_identity_log")->where(["uid" => $uid, 'identity' => 4])->whereNotIn("identity", "0")->count(); return $data; } //团队人数 public function volunteer_number($uid) { $number = 0; $number1 = Db::name("user_identity_log")->where(["uid" => $uid])->field("link_id")->select(); $number += count($number1); foreach ($number1 as $key => $value) { $number += Db::name("user_identity_log")->where(["uid" => $value['link_id']])->field("link_id")->count(); } return $number; } //团队养老金 public function volunteer_achievement($uid) { $yanglao = 0; $number1 = Db::name("user_identity_log")->where(["uid" => $uid])->field("link_id")->select(); foreach ($number1 as $key => $value) { $yanglao += $this->getYanglao($value['link_id']); $number2 = Db::name("user_identity_log")->where(["uid" => $value['link_id']])->field("link_id")->select(); foreach ($number2 as $k => $v) { $yanglao += $this->getYanglao($v['link_id']); } unset($number2); } return $yanglao; } //用户养老金 public function getYanglao($uid) { return Db::name("UserBill") ->where([ 'uid' => $uid, 'commission_type' => 5, 'status' => 1, 'pm' => 1 ]) ->sum("number"); } //升级 public function grade($uid, $grade, $volunteer) { $exist = Db::name("Volunteer")->where(["uid" => $uid])->find(); if ($exist) { Db::name("Volunteer") ->where(["uid" => $uid]) ->update([ "grade" => $grade, "team" => $volunteer['team'], "yanglao" => $volunteer['yanglao'], "extension" => $volunteer['extension'], "shop" => $volunteer['shop'], "time" => time() ]); return true; } Db::name("Volunteer") ->insert([ "uid" => $uid, "grade" => $grade, "team" => $volunteer['team'], "yanglao" => $volunteer['yanglao'], "extension" => $volunteer['extension'], "shop" => $volunteer['shop'], "time" => time() ] ); return true; } //下级各等级数量统计 public function statistics($uid) { $data = [ 'v' => 0, 'v1' => 0, 'v2' => 0, 'v3' => 0, 'v4' => 0 ]; $fns = function ($uid) use (&$fns, &$data) { $identity = Db::name("user_identity_log") ->alias("u") ->join("Volunteer v", "u.link_id = v.uid") ->where(["u.uid" => $uid]) ->field("u.link_id,v.grade") ->select(); if ($identity) { foreach ($identity as $key => $value) { if ($value['grade'] == 1) { $data['v']++; } if ($value['grade'] == 2) { $data['v1']++; } if ($value['grade'] == 3) { $data['v2']++; } if ($value['grade'] == 4) { $data['v3']++; } if ($value['grade'] == 5) { $data['v4']++; } $fns($value['link_id']); } } }; $fns($uid); Db::name("Volunteer") ->where(["uid" => $uid]) ->update([ "v" => $data['v'], "v1" => $data['v1'], "v2" => $data['v2'], "v3" => $data['v3'], "v4" => $data['v4'], "time" => time() ]); return $data; } }