| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497 |
- <?php
- declare (strict_types=1);
- namespace app\command;
- use app\common\model\merchant\order\OrderMerchant;
- use app\common\model\store\order\StoreOrder;
- use app\common\model\user\User;
- use app\common\model\user\UserCertification;
- use app\common\repositories\merchant\order\OrderGzcRepository;
- use app\common\repositories\merchant\order\OrderMerchantRepository;
- use app\common\repositories\store\order\StoreOrderStatusRepository;
- use app\common\repositories\store\product\ProductRepository;
- use app\common\repositories\user\UserBillRepository;
- use app\traits\GzcApiRequest;
- use Carbon\Carbon;
- use think\console\Command;
- use think\console\Input;
- use think\console\Output;
- use think\Exception;
- use think\facade\Db;
- use think\facade\Log;
- use app\common\repositories\store\order\StoreOrderRepository;
- /**
- * Class PensionTasks
- * @package app\command
- * @author: php迷途小书童
- * @created: 2021/3/19 9:14
- */
- class PensionTasks extends Command
- {
- use GzcApiRequest;
- protected function configure()
- {
- // 指令配置
- $this->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);
- //在线订单符合条件的养老金收集(线上收货后第30天)
- $this->doOnlineOrderGzc($timeLimit = 30);
- //在线订单符合条件的话费养老金收集(话费到账后第1天)
- $this->doOnlineHuuafeiOrderGzc($timeLimit = 1);
- //第三方订单符合条件的养老金收集(三方结算后第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->billGzcAdd($nowTime);
- //升级
- // $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
- * author: php迷途小书童
- * created: 2021/3/20 9:26
- */
- public function billGzcAdd($nowTime)
- {
- $OrderGzcRepository = app()->make(OrderGzcRepository::class);
- $OrderMerchantRepository = app()->make(OrderMerchantRepository::class);
- $StoreOrderRepository = app()->make(StoreOrderRepository::class);
- $cursor = Db::table('user_bill')
- ->where('status', 1)
- ->where('is_gzc', 0)
- ->where('commission_type', 5)
- ->select()->toArray();
- foreach ($cursor as $bill) {
- $type_shop = $bill['type_shop'] ?? 0;
- switch ($type_shop){
- case "0":
- $online = $cursor = Db::table('rrx_store_order')->where('uid', $bill['uid'])->where('order_sn', $bill['order_sn'])->where('paid', 1)->find();
- break;
- case "1":
- $online = Db::table('rrx_order_pdd')->where('uid', $bill['uid'])->where('order_sn', $bill['order_sn'])->find();
- break;
- case "2":
- $online = Db::table('rrx_order_vip')->where('uid', $bill['uid'])->where('order_sn', $bill['order_sn'])->find();
- break;
- case "3":
- $online = Db::table('rrx_order_su')->where('uid', $bill['uid'])->where('order_sn', $bill['order_sn'])->find();
- break;
- case "4":
- $online = '';
- break;
- case "5":
- $online = Db::table('rrx_order_tb')->where('uid', $bill['uid'])->where('order_sn', $bill['order_sn'])->find();
- break;
- case "6":
- $online = Db::table('rrx_order_jd')->where('uid', $bill['uid'])->where('order_sn', $bill['order_sn'])->find();
- break;
- case "7":
- $online = '';
- break;
- case "8":
- $online = '';
- break;
- case "9":
- $online = Db::table('rrx_order_huafei')->where('uid', $bill['uid'])->where('order_sn', $bill['order_sn'])->find();
- break;
- default:
- $online = Db::table('rrx_store_order')->where('uid', $bill['uid'])->where('order_sn', $bill['order_sn'])->where('paid', 1)->find();
- }
- if (!$online) {
- Log::info($bill['uid'] . '查询不到订单');
- continue;
- }
- $certification = UserCertification::getInstance()->where('uid', $bill['uid'])->find();
- if (!$certification) {
- Log::info($online['uid'] . '没有实名认证');
- continue;
- }
- $pension = $bill['number'] ?? 0;
- if ($pension <= 0) {
- Log::info($online['order_sn'] . 'pension' . $pension);
- continue;
- }
- //新增入账明细记录
- $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'],
- 'link_id'=> $bill['bill_id']
- ];
- $test_user = Db::name('user')->where('uid', $online['uid'])->value('test_user');
- $check = Db::name("gzc_logs")->where("link_id", $bill['id'])->where("order_type", 2)->count();
- if ($test_user == 0 && $check <= 0) {
- $OrderGzcRepository->create($create);
- Db::name('user_bill')
- ->where('bill_id', $bill['bill_id'])
- ->where('commission_type', 5)
- ->update([
- 'is_gzc' => 1
- ]);
- }
- }
- }
- /**
- * 线下支付订单公证处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' => '养老金']);
- $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) {
- Db::transaction(function () use ($uid, $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);
- // 结算红包
- // $user_sign_hongbao_list = Db::name('user_sign_hongbao')
- // ->where('status', -1)
- // ->where('order_id', $offline['id'])
- // ->whereIn('type', [1, 2])
- // ->select()
- // ->toArray();
- // foreach ($user_sign_hongbao_list as $user_sign_hongbao) {
- // if($user_sign_hongbao['uid']){
- // // 修改红包
- // Db::name('user')
- // ->where('uid', $user_sign_hongbao['uid'])
- // ->inc('hongbao', (float)$user_sign_hongbao['number'])
- // ->update();
- // Db::name('user_sign_hongbao')
- // ->where('status', -1)
- // ->where('id', $user_sign_hongbao['id'])
- // ->update([
- // 'status' => 1,
- // 'settlement_time' => date('Y-m-d H:i:s')
- // ]);
- // }
- // }
- // // 结算积分
- // $user_sign_score_list = Db::name('user_sign_score')
- // ->where('status', -1)
- // ->where('order_id', $offline['id'])
- // ->whereIn('type', [1, 2])
- // ->select()
- // ->toArray();
- // foreach ($user_sign_score_list as $user_sign_score) {
- // if($user_sign_score['uid']){
- // // 修改积分
- // 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_sign_gongxian_list = Db::name('user_sign_gongxian')
- // ->where('status', -1)
- // ->where('order_id', $offline['id'])
- // ->whereIn('type', [1, 2])
- // ->select()
- // ->toArray();
- // foreach ($user_sign_gongxian_list as $user_sign_gongxian) {
- // if($user_sign_gongxian['uid']){
- // // 修改贡献值
- // Db::name('user')
- // ->where('uid', $user_sign_gongxian['uid'])
- // ->inc('contribute', (float)$user_sign_gongxian['number'])
- // ->update();
- // Db::name('user_sign_gongxian')
- // ->where('status', -1)
- // ->where('id', $user_sign_gongxian['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' => $offline['id'], 'order_sn' => $offline['order_sn']])
- // ->select()
- // ->toArray();
- // foreach ($user_bill_list as $user_bill) {
- // if($user_bill['uid']){
- // 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();
- // }
- // }
- // }
- // }
- });
- }
- }
- /**
- * 话费支付订单公证处IN10入账
- * @param $nowTime
- * @param $timeLimit
- * author: php迷途小书童
- * created: 2021/3/20 9:26
- */
- public function doOnlineHuuafeiOrderGzc($timeLimit)
- {
- // 普通订单
- $cursor = Db::table('rrx_order_huafei')->where('status', 3)->where('gzc', 0)->cursor();
- $StoreOrderStatusRepository = app()->make(StoreOrderStatusRepository::class);
- $OrderMerchantRepository = app()->make(OrderMerchantRepository::class);
- $OrderGzcRepository = app()->make(OrderGzcRepository::class);
- foreach ($cursor as $online) {
-
- if (time() < strtotime($online['finish_time']) + 3600 * 24) {
- 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'], '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);
- // }
- $StoreOrderRepository = [];
- Db::transaction(function () use ($certification, $online, $pension, $OrderGzcRepository, $OrderMerchantRepository, $StoreOrderRepository) {
- //新增入账明细记录
- $orderId = $OrderMerchantRepository->getNewOrderId('IN10');
- $create = [
- 'uid' => $online['uid'],
- 'platform_no' => $orderId,
- 'account_type' => 3,//账号类型1银行卡2支付宝3微信
- '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();
- });
- }
- // 普通订单(红包,积分,京东,佣金,复购金,养老金,贡献值)
- $cursor = Db::table('rrx_order_huafei')->where('status', 3)->where('bill_status', 0)->cursor();
- $StoreOrderStatusRepository = app()->make(StoreOrderStatusRepository::class);
- $OrderMerchantRepository = app()->make(OrderMerchantRepository::class);
- $OrderGzcRepository = app()->make(OrderGzcRepository::class);
- foreach ($cursor as $online) {
- if (time() < strtotime($online['finish_time']) + 3600 * 24) {
- Log::info('还没有话费到账后' . $timeLimit . '天');
- continue;
- }
-
- Db::transaction(function () use ($online) {
- //订单状态改为已结算
- Db::name('rrx_order_huafei')
- ->where('status', 3)->where('bill_status', 0)
- ->where('order_sn', $online['order_sn'])
- ->update([
- 'bill_status'=> 1,
- 'bill_create_time' => time()
- ]);
- // 结算积分
- $user_sign_score_list = Db::name('user_sign_score')
- ->where('status', -1)
- ->where('order_id', $online['order_sn'])
- ->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_sign_fugou_list = Db::name('user_sign_fugou')
- ->where('status', -1)
- ->where('order_id', $online['order_sn'])
- ->whereIn('type', [1, 2])
- ->select()
- ->toArray();
- foreach ($user_sign_fugou_list as $user_sign_fugou) {
- // 修改复购金
- Db::name('user')
- ->where('uid', $user_sign_fugou['uid'])
- ->inc('fugou', (float)$user_sign_fugou['number'])
- ->update();
- Db::name('user_sign_fugou')
- ->where('status', -1)
- ->where('id', $user_sign_fugou['id'])
- ->update([
- 'status' => 1,
- 'settlement_time' => date('Y-m-d H:i:s')
- ]);
- }
- // 结算贡献值
- $user_sign_gongxian_list = Db::name('user_sign_gongxian')
- ->where('status', -1)
- ->where('order_id', $online['order_sn'])
- ->whereIn('type', [1, 2])
- ->select()
- ->toArray();
- foreach ($user_sign_gongxian_list as $user_sign_gongxian) {
- // 修改贡献值
- Db::name('user')
- ->where('uid', $user_sign_gongxian['uid'])
- ->inc('contribute', (float)$user_sign_gongxian['number'])
- ->update();
- Db::name('user_sign_gongxian')
- ->where('status', -1)
- ->where('id', $user_sign_gongxian['id'])
- ->update([
- 'status' => 1,
- 'settlement_time' => date('Y-m-d H:i:s')
- ]);
- }
- });
- }
- }
-
- /**
- * 在线支付公证处IN10入账 (红包,积分,京东,佣金,复购金,养老金,贡献值)
- * @param $nowTime
- * @param $timeLimit
- * author: php迷途小书童
- * created: 2021/3/20 9:25
- */
- public function doOnlineOrderGzc($timeLimit)
- {
- return true;
- // 普通订单
- $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 ($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();
- Db::name('user_bill')
- ->where('order_sn', $online['order_sn'])
- ->where('commission_type', 5)
- ->update(['status'=> 1]);
- // 养老金区域奖励
- // $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_sign_hongbao_list = Db::name('user_sign_hongbao')
- ->where('status', -1)
- ->where('order_id', $online['order_id'])
- ->whereIn('type', [1, 2])
- ->select()
- ->toArray();
- foreach ($user_sign_hongbao_list as $user_sign_hongbao) {
- // 修改红包
- Db::name('user')
- ->where('uid', $user_sign_hongbao['uid'])
- ->inc('hongbao', (float)$user_sign_hongbao['number'])
- ->update();
- Db::name('user_sign_hongbao')
- ->where('status', -1)
- ->where('id', $user_sign_hongbao['id'])
- ->update([
- 'status' => 1,
- 'settlement_time' => date('Y-m-d H:i:s')
- ]);
- }
-
- // 结算京豆
- $user_sign_jingdou_list = Db::name('user_sign_jingdou')
- ->where('status', -1)
- ->where('order_id', $online['order_id'])
- ->whereIn('type', [1, 2])
- ->select()
- ->toArray();
- foreach ($user_sign_jingdou_list as $user_sign_jingdou) {
- // 修改京豆
- Db::name('user')
- ->where('uid', $user_sign_jingdou['uid'])
- ->inc('jingdou', (float)$user_sign_jingdou['number'])
- ->update();
- Db::name('user_sign_jingdou')
- ->where('status', -1)
- ->where('id', $user_sign_jingdou['id'])
- ->update([
- 'status' => 1,
- 'settlement_time' => date('Y-m-d H:i:s')
- ]);
- }
- // 结算复购金
- $user_sign_fugou_list = Db::name('user_sign_fugou')
- ->where('status', -1)
- ->where('order_id', $online['order_id'])
- ->whereIn('type', [1, 2])
- ->select()
- ->toArray();
- foreach ($user_sign_fugou_list as $user_sign_fugou) {
- // 修改复购金
- Db::name('user')
- ->where('uid', $user_sign_fugou['uid'])
- ->inc('fugou', (float)$user_sign_fugou['number'])
- ->update();
- Db::name('user_sign_fugou')
- ->where('status', -1)
- ->where('id', $user_sign_fugou['id'])
- ->update([
- 'status' => 1,
- 'settlement_time' => date('Y-m-d H:i:s')
- ]);
- }
- // 结算贡献值
- $user_sign_gongxian_list = Db::name('user_sign_gongxian')
- ->where('status', -1)
- ->where('order_id', $online['order_id'])
- ->whereIn('type', [1, 2])
- ->select()
- ->toArray();
- foreach ($user_sign_gongxian_list as $user_sign_gongxian) {
- // 修改贡献值
- Db::name('user')
- ->where('uid', $user_sign_gongxian['uid'])
- ->inc('contribute', (float)$user_sign_gongxian['number'])
- ->update();
- Db::name('user_sign_gongxian')
- ->where('status', -1)
- ->where('id', $user_sign_gongxian['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, $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']]);
- Db::name('user_bill')
- ->where('order_sn', $thrid['order_sn'])
- ->where('commission_type', 5)
- ->update(['status'=> 1]);
- // 养老金区域奖励
- $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, $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']]);
- Db::name('user_bill')
- ->where('order_sn', $thrid['order_sn'])
- ->where('commission_type', 5)
- ->update(['status'=> 1]);
- // 养老金区域奖励
- // $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, $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']]);
- Db::name('user_bill')
- ->where('order_sn', $thrid['order_sn'])
- ->where('commission_type', 5)
- ->update(['status'=> 1]);
- // 养老金区域奖励
- $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, $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']]);
- Db::name('user_bill')
- ->where('order_sn', $thrid['order_sn'])
- ->where('commission_type', 5)
- ->update(['status'=> 1]);
- });
- }
- }
- /**
- * 第三方订单淘宝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, $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']]);
- Db::name('user_bill')
- ->where('order_sn', $thrid['order_sn'])
- ->where('commission_type', 5)
- ->update(['status'=> 1]);
- // 养老金区域奖励
- $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, $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']]);
- Db::name('user_bill')
- ->where('order_sn', $thrid['order_sn'])
- ->where('commission_type', 5)
- ->update(['status'=> 1]);
- // 养老金区域奖励
- $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, $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']]);
- Db::name('user_bill')
- ->where('order_sn', $thrid['order_sn'])
- ->where('commission_type', 5)
- ->update(['status'=> 1]);
- // 养老金区域奖励
- $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;
- }
- }
|