| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004 |
- <?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);
- //在线订单符合条件的养老金收集(线上收货后第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;
- }
- }
|