PensionTasks.php 44 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004
  1. <?php
  2. declare (strict_types=1);
  3. namespace app\command;
  4. use app\common\model\merchant\order\OrderMerchant;
  5. use app\common\model\store\order\StoreOrder;
  6. use app\common\model\user\User;
  7. use app\common\model\user\UserCertification;
  8. use app\common\repositories\merchant\order\OrderGzcRepository;
  9. use app\common\repositories\merchant\order\OrderMerchantRepository;
  10. use app\common\repositories\store\order\StoreOrderStatusRepository;
  11. use app\common\repositories\store\product\ProductRepository;
  12. use app\common\repositories\user\UserBillRepository;
  13. use app\traits\GzcApiRequest;
  14. use Carbon\Carbon;
  15. use think\console\Command;
  16. use think\console\Input;
  17. use think\console\Output;
  18. use think\Exception;
  19. use think\facade\Db;
  20. use think\facade\Log;
  21. use app\common\repositories\store\order\StoreOrderRepository;
  22. /**
  23. * Class PensionTasks
  24. * @package app\command
  25. * @author: php迷途小书童
  26. * @created: 2021/3/19 9:14
  27. */
  28. class PensionTasks extends Command
  29. {
  30. use GzcApiRequest;
  31. protected function configure()
  32. {
  33. // 指令配置
  34. $this->setName('pensiontask')
  35. ->setDescription('the pensiontask command');
  36. }
  37. protected function execute(Input $input, Output $output)
  38. {
  39. //1线下2在线3拼多多4京东5苏宁6淘宝7VIP
  40. $nowTime = time();
  41. try {
  42. //线下符合条件的养老金收集(线下交易后第8天)
  43. $this->doOfflineOrderGzc($nowTime, $timeLimit = 1);
  44. //在线订单符合条件的养老金收集(线上收货后第8天)
  45. $this->doOnlineOrderGzc($timeLimit = 8);
  46. //第三方订单符合条件的养老金收集(三方结算后第2天)
  47. $this->doThridPddOrderGzc($nowTime, $timeLimit = 2);
  48. $this->doThridJdOrderGzc($nowTime, $timeLimit = 2);
  49. $this->doThridSnOrderGzc($nowTime, $timeLimit = 2);
  50. $this->doThridTaobaoOrderGzc($nowTime, $timeLimit = 2);
  51. $this->doThridVipOrderGzc($nowTime, $timeLimit = 2);
  52. $this->doThridDyOrderGzc($nowTime, $timeLimit = 2);
  53. $this->doThridHfOrderGzc($nowTime, $timeLimit = 2);
  54. //升级
  55. // $this -> doUpgrade();
  56. } catch (\Throwable $e) {
  57. Log::info('公证处入账:' . $e->getFile() . ':' . $e->getLine() . '【' . $e->getMessage() . '】');
  58. var_dump('公证处入账:' . $e->getFile() . ':' . $e->getLine() . '【' . $e->getMessage() . '】');
  59. }
  60. // 指令输出
  61. $output->writeln('pensiontask');
  62. }
  63. /**
  64. * 线下支付订单公证处IN10入账
  65. * @param $nowTime
  66. * @param $timeLimit
  67. * author: php迷途小书童
  68. * created: 2021/3/20 9:26
  69. */
  70. public function doOfflineOrderGzc($nowTime, $timeLimit)
  71. {
  72. $cursor = Db::table('rrx_order_merchant')
  73. ->whereNotNull('pay_time')
  74. ->where('paid', 1)
  75. ->where('gzc', 0)
  76. ->whereTime('pay_time', '<', $nowTime - bcmul((string)$timeLimit, (string)86400))
  77. ->cursor();
  78. $OrderGzcRepository = app()->make(OrderGzcRepository::class);
  79. $OrderMerchantRepository = app()->make(OrderMerchantRepository::class);
  80. $StoreOrderRepository = app()->make(StoreOrderRepository::class);
  81. foreach ($cursor as $offline) {
  82. if ($offline['mer_id'] == 496) {
  83. continue;
  84. }
  85. $uid = 0;
  86. switch ($offline['trade_type']) {
  87. case 'WX':
  88. $uid = User::getInstance()->where('wechat_user_id', $offline['pay_user_id'])->value('uid');
  89. $accountType = 3;
  90. break;
  91. case 'ALI':
  92. $uid = User::getInstance()->where('ali_user_id', $offline['pay_user_id'])->value('uid');
  93. $accountType = 2;
  94. break;
  95. default:
  96. break;
  97. }
  98. if (!$uid) {
  99. Log::info($offline['pay_user_id'] . '未绑定用户');
  100. continue;
  101. }
  102. $certification = UserCertification::getInstance()->where('uid', $uid)->find();
  103. if (!$certification) {
  104. Log::info($offline['pay_user_id'] . '未实名认证');
  105. continue;
  106. }
  107. //查询养老金金额
  108. $UserBillRepository = app()->make(UserBillRepository::class);
  109. $bill = $UserBillRepository->getWhere(['uid' => $uid, 'link_id' => $offline['id'], 'order_sn' => $offline['out_trade_no'], 'title' => '养老金']);
  110. // if ($bill->status == 0) {
  111. // Log::info($offline['out_trade_no'] . 'pension未交年费');
  112. // continue;
  113. // }
  114. $pension = $bill->number ?? 0;
  115. if ($pension <= 0) {
  116. Log::info($offline['out_trade_no'] . 'pension' . $pension);
  117. continue;
  118. }
  119. Db::transaction(function () use ($uid, $certification, $accountType, $offline, $OrderGzcRepository, $OrderMerchantRepository, $pension, $StoreOrderRepository) {
  120. $order = OrderMerchant::getInstance()->find($offline['id']);
  121. $order->gzc = 1;
  122. $order->is_settlement = 1;
  123. $order->settlement_time = date('Y-m-d H:i:s');
  124. $order->save();
  125. //新增入账明细记录
  126. $orderId = $OrderMerchantRepository->getNewOrderId('IN10');
  127. $create = [
  128. 'uid' => $uid,
  129. 'platform_no' => $orderId,
  130. 'account_type' => $accountType,
  131. 'user_name' => $certification['user_name'],
  132. 'mobile' => $certification['mobile'],
  133. 'user_card' => $certification['user_card'],
  134. 'pension' => $pension,
  135. 'order_type' => 1,
  136. 'out_trade_no' => $offline['out_trade_no']
  137. ];
  138. $test_user = Db::name('user')->where('uid', $uid)->value('test_user');
  139. if ($test_user == 0) {
  140. $OrderGzcRepository->create($create);
  141. }
  142. // 养老金区域奖励
  143. $order_data = [
  144. 'pay_price' => $pension,
  145. 'user_address_ids' => $offline['user_address_ids'],
  146. 'uid' => $offline['uid'],
  147. 'order_sn' => $offline['out_trade_no']
  148. ];
  149. // $StoreOrderRepository->area_manage_details($order_data, 0, 2);
  150. });
  151. }
  152. }
  153. /**
  154. * 在线支付公证处IN10入账
  155. * @param $nowTime
  156. * @param $timeLimit
  157. * author: php迷途小书童
  158. * created: 2021/3/20 9:25
  159. */
  160. public function doOnlineOrderGzc($timeLimit)
  161. {
  162. $cursor = Db::table('rrx_store_order')
  163. ->where('paid', 1)
  164. ->where('gzc', 0)
  165. ->where('pay_type', 'in', '0,1,2,4')
  166. ->cursor();
  167. $StoreOrderStatusRepository = app()->make(StoreOrderStatusRepository::class);
  168. $OrderMerchantRepository = app()->make(OrderMerchantRepository::class);
  169. $OrderGzcRepository = app()->make(OrderGzcRepository::class);
  170. foreach ($cursor as $online) {
  171. $status = $StoreOrderStatusRepository->getWhere(['order_id' => $online['order_id'], 'change_type' => 'take']);
  172. if ($online['mer_id'] == 496) {
  173. if (!in_array($online['status'], [0, 1, 2, 3])) {
  174. continue;
  175. }
  176. if (time() < strtotime($online['pay_time']) + 3600 * 24) {
  177. Log::info('还没有到收货后' . $timeLimit . '天');
  178. continue;
  179. }
  180. } else {
  181. if (!in_array($online['status'], [2, 3])) {
  182. continue;
  183. }
  184. if (Carbon::now()->modify("-{$timeLimit} days")->lt($status->change_time ?? $status['change_time'])) {
  185. Log::info('还没有到收货后' . $timeLimit . '天');
  186. continue;
  187. }
  188. }
  189. $certification = UserCertification::getInstance()->where('uid', $online['uid'])->find();
  190. if (!$certification) {
  191. Log::info($online['uid'] . '没有实名认证');
  192. continue;
  193. }
  194. //查询养老金金额
  195. $UserBillRepository = app()->make(UserBillRepository::class);
  196. $bill = $UserBillRepository->getWhere(['uid' => $online['uid'], 'link_id' => $online['order_id'], 'order_sn' => $online['order_sn'], 'commission_type' => 5]);
  197. $pension = $bill->number ?? 0;
  198. if ($pension <= 0) {
  199. Log::info($online['order_sn'] . 'pension' . $pension);
  200. continue;
  201. }
  202. //首信易分账
  203. $StoreOrderRepository = app()->make(StoreOrderRepository::class);
  204. if ($online['pay_type'] > 0) {
  205. $StoreOrderRepository->splitOrder($online);
  206. }
  207. Db::transaction(function () use ($certification, $online, $pension, $OrderGzcRepository, $OrderMerchantRepository, $StoreOrderRepository) {
  208. //新增入账明细记录
  209. $orderId = $OrderMerchantRepository->getNewOrderId('IN10');
  210. $create = [
  211. 'uid' => $online['uid'],
  212. 'platform_no' => $orderId,
  213. 'account_type' => $online['pay_type'] == 1 ? 3 : 2,
  214. 'user_name' => $certification['user_name'],
  215. 'mobile' => $certification['mobile'],
  216. 'user_card' => $certification['user_card'],
  217. 'pension' => $pension,
  218. 'order_type' => 2,
  219. 'out_trade_no' => $online['order_sn']
  220. ];
  221. $test_user = Db::name('user')->where('uid', $online['uid'])->value('test_user');
  222. $check = Db::name("gzc_logs")->where("out_trade_no", $online['order_sn'])->where("order_type", 2)->count();
  223. if ($test_user == 0 && $check <= 0) {
  224. $OrderGzcRepository->create($create);
  225. }
  226. $order = StoreOrder::getInstance()->find($online['order_id']);
  227. $order->gzc = 1;
  228. $order->save();
  229. // 养老金区域奖励
  230. // $order_data = [
  231. // 'pay_price' => $pension,
  232. // 'user_address_ids' => $online['user_address_ids'],
  233. // 'uid' => $online['uid'],
  234. // 'order_sn' => $online['order_sn']
  235. // ];
  236. // $StoreOrderRepository->area_manage_details($order_data, 8, 2);
  237. });
  238. }
  239. $cursor = Db::table('rrx_store_order')
  240. ->where('paid', 1)
  241. ->where('is_settlement', 0)
  242. ->where('pay_type', 'in', '0,1,2,4')
  243. ->cursor();
  244. $StoreOrderStatusRepository = app()->make(StoreOrderStatusRepository::class);
  245. $OrderMerchantRepository = app()->make(OrderMerchantRepository::class);
  246. $OrderGzcRepository = app()->make(OrderGzcRepository::class);
  247. foreach ($cursor as $online) {
  248. $status = $StoreOrderStatusRepository->getWhere(['order_id' => $online['order_id'], 'change_type' => 'take']);
  249. if ($online['mer_id'] == 496) {
  250. if (!in_array($online['status'], [0, 1, 2, 3])) {
  251. continue;
  252. }
  253. if (time() < strtotime($online['pay_time']) + 3600 * 24) {
  254. Log::info('还没有到收货后' . $timeLimit . '天');
  255. continue;
  256. }
  257. } else {
  258. if (!in_array($online['status'], [2, 3])) {
  259. continue;
  260. }
  261. if (Carbon::now()->modify("-{$timeLimit} days")->lt($status->change_time ?? $status['change_time'])) {
  262. Log::info('还没有到收货后' . $timeLimit . '天');
  263. continue;
  264. }
  265. }
  266. $StoreOrderRepository = app()->make(StoreOrderRepository::class);
  267. Db::transaction(function () use ($online, $StoreOrderRepository) {
  268. $order = StoreOrder::getInstance()->find($online['order_id']);
  269. $order->is_settlement = 1;
  270. $order->settlement_time = date('Y-m-d H:i:s');
  271. $order->save();
  272. // 结算积分
  273. $user_sign_score_list = Db::name('user_sign_score')
  274. ->where('status', -1)
  275. ->where('order_id', $online['order_id'])
  276. ->whereIn('type', [1, 2])
  277. ->select()
  278. ->toArray();
  279. foreach ($user_sign_score_list as $user_sign_score) {
  280. // 修改积分
  281. Db::name('user')
  282. ->where('uid', $user_sign_score['uid'])
  283. ->inc('score', (float)$user_sign_score['reward_socre'])
  284. ->update();
  285. Db::name('user_sign_score')
  286. ->where('status', -1)
  287. ->where('id', $user_sign_score['id'])
  288. ->update([
  289. 'status' => 1,
  290. 'settlement_time' => date('Y-m-d H:i:s')
  291. ]);
  292. }
  293. $user_bill_list = Db::name('user_bill')
  294. ->where('status', 0)
  295. ->where('commission_type','<>', 5)
  296. ->where([ 'link_id' => $online['order_id'], 'order_sn' => $online['order_sn']])
  297. ->select()
  298. ->toArray();
  299. foreach ($user_bill_list as $user_bill) {
  300. if ($user_bill['commission_type'] != 5) {
  301. if (in_array($user_bill['commission_type'], [7,12,19])) {
  302. Db::name("merchant")
  303. ->where("mer_id", $user_bill['mer_id'])
  304. ->inc('brokerage_price', (float)$user_bill['number'])
  305. ->update();
  306. } else {
  307. Db::name('user')
  308. ->where('uid', $user_bill['uid'])
  309. ->inc('brokerage_price', (float)$user_bill['number'])
  310. ->update();
  311. }
  312. }
  313. if ($online['pay_type'] == 0 && $user_bill['commission_type'] == 5) {
  314. } else {
  315. // 虚拟支付的养老金不修改不结算
  316. Db::name('user_bill')
  317. ->where('status', 0)
  318. ->where('bill_id', $user_bill['bill_id'])
  319. ->update([
  320. 'status' => 1,
  321. 'take_time' => time()
  322. ]);
  323. }
  324. if ($online['pay_type'] == 0 && $user_bill['commission_type'] == 5) {
  325. } else {
  326. // 虚拟支付的养老金不修改不结算
  327. Db::name('user_bill')
  328. ->where('status', 0)
  329. ->where('bill_id', $user_bill['bill_id'])
  330. ->update([
  331. 'status' => 1,
  332. 'take_time' => time()
  333. ]);
  334. }
  335. }
  336. $StoreOrderRepository->close_order($online['order_id']);
  337. });
  338. }
  339. }
  340. /**
  341. * 第三方订单拼多多IN10入账
  342. * @param $nowTime
  343. * @param $timeLimit
  344. * author: php迷途小书童
  345. * created: 2021/3/20 9:26
  346. */
  347. public function doThridPddOrderGzc($nowTime, $timeLimit)
  348. {
  349. $cursor = Db::table('rrx_order_pdd')
  350. ->where('gzc', 0)
  351. ->where('bill_status', 1)
  352. ->where('commission', '>', 0)
  353. ->whereTime('bill_end_time', '<', $nowTime - bcmul((string)$timeLimit, (string)86400))
  354. ->cursor();
  355. $ProductRepository = app()->make(ProductRepository::class);
  356. $OrderGzcRepository = app()->make(OrderGzcRepository::class);
  357. $OrderMerchantRepository = app()->make(OrderMerchantRepository::class);
  358. $StoreOrderRepository = app()->make(StoreOrderRepository::class);
  359. foreach ($cursor as $thrid) {
  360. $uid = $thrid['uid'];
  361. if (!$uid)
  362. continue;
  363. $certification = UserCertification::getInstance()->where('uid', $uid)->find();
  364. if (!$certification) {
  365. Log::info('用户ID' . $uid . '未实名认证');
  366. continue;
  367. }
  368. $pension = $ProductRepository->yanglaojin(0, sprintf('%.2f', $thrid['commission']));
  369. Db::transaction(function () use ($uid, $certification, $thrid, $pension, $OrderGzcRepository, $OrderMerchantRepository, $StoreOrderRepository) {
  370. //新增入账明细记录
  371. $orderId = $OrderMerchantRepository->getNewOrderId('IN10');
  372. $create = [
  373. 'uid' => $uid,
  374. 'platform_no' => $orderId,
  375. 'user_name' => $certification['user_name'],
  376. 'mobile' => $certification['mobile'],
  377. 'user_card' => $certification['user_card'],
  378. 'pension' => $pension,
  379. 'order_type' => 3,
  380. 'out_trade_no' => $thrid['order_sn']
  381. ];
  382. $test_user = Db::name('user')->where('uid', $uid)->value('test_user');
  383. if ($test_user == 0) {
  384. $OrderGzcRepository->create($create);
  385. }
  386. // $OrderGzcRepository->create($create);
  387. Db::table('rrx_order_pdd')
  388. ->update(['gzc' => 1, 'order_pdd_id' => $thrid['order_pdd_id']]);
  389. // 养老金区域奖励
  390. $order_data = [
  391. 'pay_price' => $pension,
  392. 'user_address_ids' => $thrid['user_address_ids'],
  393. 'uid' => $thrid['uid'],
  394. 'order_sn' => $thrid['order_sn']
  395. ];
  396. // $StoreOrderRepository->area_manage_details($order_data, 1, 2);
  397. });
  398. }
  399. }
  400. /**
  401. * 第三方订单京东IN10入账
  402. * @param $nowTime
  403. * @param $timeLimit
  404. * author: php迷途小书童
  405. * created: 2021/3/20 9:26
  406. */
  407. public function doThridJdOrderGzc($nowTime, $timeLimit)
  408. {
  409. $cursor = Db::table('rrx_order_jd')
  410. ->where('gzc', 0)
  411. ->where('bill_status', 1)
  412. ->where('commission', '>', 0)
  413. ->whereTime('bill_end_time', '<', $nowTime - bcmul((string)$timeLimit, (string)86400))
  414. ->cursor();
  415. // Db::name('log')->insert(['data'=>'abbbb入库语句'.$nowTime - bcmul((string)$timeLimit, (string)86400)]);
  416. // Db::name('log')->insert(['data'=>'abbbb'.json_encode($cursor)]);
  417. $ProductRepository = app()->make(ProductRepository::class);
  418. $OrderGzcRepository = app()->make(OrderGzcRepository::class);
  419. $OrderMerchantRepository = app()->make(OrderMerchantRepository::class);
  420. $StoreOrderRepository = app()->make(StoreOrderRepository::class);
  421. foreach ($cursor as $thrid) {
  422. $uid = $thrid['uid'];
  423. if (!$uid)
  424. continue;
  425. $certification = UserCertification::getInstance()->where('uid', $uid)->find();
  426. if (!$certification) {
  427. Log::info('用户ID' . $uid . '未实名认证');
  428. continue;
  429. }
  430. $pension = $ProductRepository->yanglaojin(0, sprintf('%.2f', $thrid['commission']));
  431. Db::transaction(function () use ($uid, $certification, $thrid, $pension, $OrderGzcRepository, $OrderMerchantRepository, $StoreOrderRepository) {
  432. //新增入账明细记录
  433. $orderId = $OrderMerchantRepository->getNewOrderId('IN10');
  434. $create = [
  435. 'uid' => $uid,
  436. 'platform_no' => $orderId,
  437. 'user_name' => $certification['user_name'],
  438. 'mobile' => $certification['mobile'],
  439. 'user_card' => $certification['user_card'],
  440. 'pension' => $pension,
  441. 'order_type' => 4,
  442. 'out_trade_no' => $thrid['order_sn']
  443. ];
  444. $test_user = Db::name('user')->where('uid', $uid)->value('test_user');
  445. if ($test_user == 0) {
  446. $OrderGzcRepository->create($create);
  447. }
  448. // $OrderGzcRepository->create($create);
  449. Db::table('rrx_order_jd')
  450. ->update(['gzc' => 1, 'order_jd_id' => $thrid['order_jd_id']]);
  451. // 养老金区域奖励
  452. $order_data = [
  453. 'pay_price' => $pension,
  454. 'user_address_ids' => $thrid['user_address_ids'],
  455. 'uid' => $thrid['uid'],
  456. 'order_sn' => $thrid['order_sn']
  457. ];
  458. // $StoreOrderRepository->area_manage_details($order_data, 6, 2);
  459. });
  460. }
  461. }
  462. /**
  463. * 第三方订单苏宁IN10入账
  464. * @param $nowTime
  465. * @param $timeLimit
  466. * author: php迷途小书童
  467. * created: 2021/3/20 9:26
  468. */
  469. public function doThridSnOrderGzc($nowTime, $timeLimit)
  470. {
  471. $cursor = Db::table('rrx_order_su')
  472. ->where('gzc', 0)
  473. ->where('bill_status', 1)
  474. ->where('commission', '>', 0)
  475. ->whereTime('bill_end_time', '<', $nowTime - bcmul((string)$timeLimit, (string)86400))
  476. ->cursor();
  477. $ProductRepository = app()->make(ProductRepository::class);
  478. $OrderGzcRepository = app()->make(OrderGzcRepository::class);
  479. $OrderMerchantRepository = app()->make(OrderMerchantRepository::class);
  480. $StoreOrderRepository = app()->make(StoreOrderRepository::class);
  481. foreach ($cursor as $thrid) {
  482. $uid = $thrid['uid'];
  483. if (!$uid)
  484. continue;
  485. $certification = UserCertification::getInstance()->where('uid', $uid)->find();
  486. if (!$certification) {
  487. Log::info('用户ID' . $uid . '未实名认证');
  488. continue;
  489. }
  490. $pension = $ProductRepository->yanglaojin(0, sprintf('%.2f', $thrid['commission']));
  491. Db::transaction(function () use ($uid, $certification, $thrid, $pension, $OrderGzcRepository, $OrderMerchantRepository, $StoreOrderRepository) {
  492. //新增入账明细记录
  493. $orderId = $OrderMerchantRepository->getNewOrderId('IN10');
  494. $create = [
  495. 'uid' => $uid,
  496. 'platform_no' => $orderId,
  497. 'user_name' => $certification['user_name'],
  498. 'mobile' => $certification['mobile'],
  499. 'user_card' => $certification['user_card'],
  500. 'pension' => $pension,
  501. 'order_type' => 5,
  502. 'out_trade_no' => $thrid['order_sn']
  503. ];
  504. $test_user = Db::name('user')->where('uid', $uid)->value('test_user');
  505. if ($test_user == 0) {
  506. $OrderGzcRepository->create($create);
  507. }
  508. // $OrderGzcRepository->create($create);
  509. Db::table('rrx_order_su')
  510. ->update(['gzc' => 1, 'order_su_id' => $thrid['order_su_id']]);
  511. // 养老金区域奖励
  512. $order_data = [
  513. 'pay_price' => $pension,
  514. 'user_address_ids' => $thrid['user_address_ids'],
  515. 'uid' => $thrid['uid'],
  516. 'order_sn' => $thrid['order_sn']
  517. ];
  518. // $StoreOrderRepository->area_manage_details($order_data, 3, 2);
  519. });
  520. }
  521. }
  522. /**
  523. * 第三方订单话费IN10入账
  524. * @param $nowTime
  525. * @param $timeLimit
  526. * author: php迷途小书童
  527. * created: 2021/3/20 9:26
  528. */
  529. public function doThridHfOrderGzc($nowTime, $timeLimit)
  530. {
  531. $cursor = Db::table('rrx_order_huafei')
  532. ->where('gzc', 0)
  533. ->where('bill_status', 1)
  534. ->where('commission', '>', 0)
  535. ->whereTime('bill_end_time', '<', $nowTime - bcmul((string)$timeLimit, (string)86400))
  536. ->cursor();
  537. $ProductRepository = app()->make(ProductRepository::class);
  538. $OrderGzcRepository = app()->make(OrderGzcRepository::class);
  539. $OrderMerchantRepository = app()->make(OrderMerchantRepository::class);
  540. foreach ($cursor as $thrid) {
  541. $uid = $thrid['uid'];
  542. if (!$uid)
  543. continue;
  544. $certification = UserCertification::getInstance()->where('uid', $uid)->find();
  545. if (!$certification) {
  546. Log::info('用户ID' . $uid . '未实名认证');
  547. continue;
  548. }
  549. $pension = $ProductRepository->yanglaojin(0, sprintf('%.2f', $thrid['commission']));
  550. Db::transaction(function () use ($uid, $certification, $thrid, $pension, $OrderGzcRepository, $OrderMerchantRepository) {
  551. //新增入账明细记录
  552. $orderId = $OrderMerchantRepository->getNewOrderId('IN10');
  553. $create = [
  554. 'uid' => $uid,
  555. 'platform_no' => $orderId,
  556. 'user_name' => $certification['user_name'],
  557. 'mobile' => $certification['mobile'],
  558. 'user_card' => $certification['user_card'],
  559. 'pension' => $pension,
  560. 'order_type' => 6,
  561. 'out_trade_no' => $thrid['order_sn']
  562. ];
  563. $test_user = Db::name('user')->where('uid', $uid)->value('test_user');
  564. if ($test_user == 0) {
  565. $OrderGzcRepository->create($create);
  566. }
  567. Db::table('rrx_order_huafei')->update(['gzc' => 1, 'order_tb_id' => $thrid['order_tb_id']]);
  568. });
  569. }
  570. }
  571. /**
  572. * 第三方订单淘宝IN10入账
  573. * @param $nowTime
  574. * @param $timeLimit
  575. * author: php迷途小书童
  576. * created: 2021/3/20 9:26
  577. */
  578. public function doThridTaobaoOrderGzc($nowTime, $timeLimit)
  579. {
  580. $cursor = Db::table('rrx_order_tb')
  581. ->where('gzc', 0)
  582. ->where('bill_status', 1)
  583. ->where('commission', '>', 0)
  584. ->whereTime('bill_end_time', '<', $nowTime - bcmul((string)$timeLimit, (string)86400))
  585. ->cursor();
  586. $ProductRepository = app()->make(ProductRepository::class);
  587. $OrderGzcRepository = app()->make(OrderGzcRepository::class);
  588. $OrderMerchantRepository = app()->make(OrderMerchantRepository::class);
  589. $StoreOrderRepository = app()->make(StoreOrderRepository::class);
  590. foreach ($cursor as $thrid) {
  591. $uid = $thrid['uid'];
  592. if (!$uid)
  593. continue;
  594. $certification = UserCertification::getInstance()->where('uid', $uid)->find();
  595. if (!$certification) {
  596. Log::info('用户ID' . $uid . '未实名认证');
  597. continue;
  598. }
  599. $pension = $ProductRepository->yanglaojin(0, sprintf('%.2f', $thrid['commission']));
  600. Db::transaction(function () use ($uid, $certification, $thrid, $pension, $OrderGzcRepository, $OrderMerchantRepository, $StoreOrderRepository) {
  601. //新增入账明细记录
  602. $orderId = $OrderMerchantRepository->getNewOrderId('IN10');
  603. $create = [
  604. 'uid' => $uid,
  605. 'platform_no' => $orderId,
  606. 'user_name' => $certification['user_name'],
  607. 'mobile' => $certification['mobile'],
  608. 'user_card' => $certification['user_card'],
  609. 'pension' => $pension,
  610. 'order_type' => 6,
  611. 'out_trade_no' => $thrid['order_sn']
  612. ];
  613. $test_user = Db::name('user')->where('uid', $uid)->value('test_user');
  614. if ($test_user == 0) {
  615. $OrderGzcRepository->create($create);
  616. }
  617. // $OrderGzcRepository->create($create);
  618. Db::table('rrx_order_tb')
  619. ->update(['gzc' => 1, 'order_tb_id' => $thrid['order_tb_id']]);
  620. // 养老金区域奖励
  621. $order_data = [
  622. 'pay_price' => $pension,
  623. 'user_address_ids' => $thrid['user_address_ids'],
  624. 'uid' => $thrid['uid'],
  625. 'order_sn' => $thrid['order_sn']
  626. ];
  627. // $StoreOrderRepository->area_manage_details($order_data, 5, 2);
  628. });
  629. }
  630. }
  631. /**
  632. * 第三方订单唯品会IN10入账
  633. * @param $nowTime
  634. * @param $timeLimit
  635. * author: php迷途小书童
  636. * created: 2021/3/20 9:26
  637. */
  638. public function doThridVipOrderGzc($nowTime, $timeLimit)
  639. {
  640. $cursor = Db::table('rrx_order_vip')
  641. ->where('gzc', 0)
  642. ->where('bill_status', 1)
  643. ->where('commission', '>', 0)
  644. ->whereTime('bill_end_time', '<', $nowTime - bcmul((string)$timeLimit, (string)86400))
  645. ->cursor();
  646. $ProductRepository = app()->make(ProductRepository::class);
  647. $OrderGzcRepository = app()->make(OrderGzcRepository::class);
  648. $OrderMerchantRepository = app()->make(OrderMerchantRepository::class);
  649. $StoreOrderRepository = app()->make(StoreOrderRepository::class);
  650. foreach ($cursor as $thrid) {
  651. $uid = $thrid['uid'];
  652. if (!$uid)
  653. continue;
  654. $certification = UserCertification::getInstance()->where('uid', $uid)->find();
  655. if (!$certification) {
  656. Log::info('用户ID' . $uid . '未实名认证');
  657. continue;
  658. }
  659. $pension = $ProductRepository->yanglaojin(0, sprintf('%.2f', $thrid['commission']));
  660. Db::transaction(function () use ($uid, $certification, $thrid, $pension, $OrderGzcRepository, $OrderMerchantRepository, $StoreOrderRepository) {
  661. //新增入账明细记录
  662. $orderId = $OrderMerchantRepository->getNewOrderId('IN10');
  663. $create = [
  664. 'uid' => $uid,
  665. 'platform_no' => $orderId,
  666. 'user_name' => $certification['user_name'],
  667. 'mobile' => $certification['mobile'],
  668. 'user_card' => $certification['user_card'],
  669. 'pension' => $pension,
  670. 'order_type' => 7,
  671. 'out_trade_no' => $thrid['order_sn']
  672. ];
  673. $test_user = Db::name('user')->where('uid', $uid)->value('test_user');
  674. if ($test_user == 0) {
  675. $OrderGzcRepository->create($create);
  676. }
  677. // $OrderGzcRepository->create($create);
  678. Db::table('rrx_order_vip')
  679. ->update(['gzc' => 1, 'order_vip_id' => $thrid['order_vip_id']]);
  680. // 养老金区域奖励
  681. $order_data = [
  682. 'pay_price' => $pension,
  683. 'user_address_ids' => $thrid['user_address_ids'],
  684. 'uid' => $thrid['uid'],
  685. 'order_sn' => $thrid['order_sn']
  686. ];
  687. // $StoreOrderRepository->area_manage_details($order_data, 2, 2);
  688. });
  689. }
  690. }
  691. /**
  692. * 第三方订单抖音IN10入账
  693. * @param $nowTime
  694. * @param $timeLimit
  695. * author: php迷途小书童
  696. * created: 2021/3/20 9:26
  697. */
  698. public function doThridDyOrderGzc($nowTime, $timeLimit)
  699. {
  700. $cursor = Db::table('rrx_order_dy')
  701. ->where('gzc', 0)
  702. ->where('bill_status', 1)
  703. ->where('commission', '>', 0)
  704. ->whereTime('bill_end_time', '<', $nowTime - bcmul((string)$timeLimit, (string)86400))
  705. ->cursor();
  706. $ProductRepository = app()->make(ProductRepository::class);
  707. $OrderGzcRepository = app()->make(OrderGzcRepository::class);
  708. $OrderMerchantRepository = app()->make(OrderMerchantRepository::class);
  709. $StoreOrderRepository = app()->make(StoreOrderRepository::class);
  710. foreach ($cursor as $thrid) {
  711. $uid = $thrid['uid'];
  712. if (!$uid)
  713. continue;
  714. $certification = UserCertification::getInstance()->where('uid', $uid)->find();
  715. if (!$certification) {
  716. Log::info('用户ID' . $uid . '未实名认证');
  717. continue;
  718. }
  719. $pension = $ProductRepository->yanglaojin(0, sprintf('%.2f', $thrid['commission']));
  720. Db::transaction(function () use ($uid, $certification, $thrid, $pension, $OrderGzcRepository, $OrderMerchantRepository, $StoreOrderRepository) {
  721. //新增入账明细记录
  722. $orderId = $OrderMerchantRepository->getNewOrderId('IN10');
  723. $create = [
  724. 'uid' => $uid,
  725. 'platform_no' => $orderId,
  726. 'user_name' => $certification['user_name'],
  727. 'mobile' => $certification['mobile'],
  728. 'user_card' => $certification['user_card'],
  729. 'pension' => $pension,
  730. 'order_type' => 8,
  731. 'out_trade_no' => $thrid['order_sn']
  732. ];
  733. $test_user = Db::name('user')->where('uid', $uid)->value('test_user');
  734. if ($test_user == 0) {
  735. $OrderGzcRepository->create($create);
  736. }
  737. Db::table('rrx_order_dy')
  738. ->update(['gzc' => 1, 'order_dy_id' => $thrid['order_dy_id']]);
  739. // 养老金区域奖励
  740. $order_data = [
  741. 'pay_price' => $pension,
  742. 'user_address_ids' => $thrid['user_address_ids'],
  743. 'uid' => $thrid['uid'],
  744. 'order_sn' => $thrid['order_sn']
  745. ];
  746. // $StoreOrderRepository->area_manage_details($order_data, 9, 2);
  747. });
  748. }
  749. }
  750. /**
  751. * 志愿者升级
  752. * */
  753. public function doUpgrade()
  754. {
  755. set_time_limit(0);
  756. try {
  757. //志愿者条件
  758. $volunteer_achievement = systemConfig("volunteer_achievement"); //volunteer_achievement:用户本人满足养老金要求可升级为志愿者
  759. //一星条件
  760. $a_volunteer_achievement = systemConfig("a_volunteer_achievement");//团队养老金要求
  761. $a_volunteer_number = systemConfig("a_volunteer_number"); //团队人数要求
  762. //二星条件
  763. $b_volunteer_achievement = systemConfig("b_volunteer_achievement");//团队养老金要求
  764. $b_volunteer_number = systemConfig("b_volunteer_number"); //团队人数要求
  765. //三星条件
  766. $c_volunteer_achievement = systemConfig("c_volunteer_achievement");//团队养老金要求
  767. $c_volunteer_number = systemConfig("c_volunteer_number"); //团队人数要求
  768. //董事条件
  769. $d_volunteer_achievement = systemConfig("d_volunteer_achievement");//团队养老金要求
  770. $d_volunteer_number = systemConfig("d_volunteer_number"); //团队人数要求
  771. //用户列表
  772. $userList = Db::name("User")
  773. ->field("uid")
  774. ->select();
  775. foreach ($userList as $key => $value) {
  776. $volunteer = $this->volunteer($value['uid']);
  777. //本人养老金小于志愿者要求
  778. if ($volunteer['self_yanglao'] < $volunteer_achievement) {
  779. $this->grade($value['uid'], 0, $volunteer);
  780. }
  781. //满足志愿者要求
  782. if ($volunteer['self_yanglao'] >= $volunteer_achievement) {
  783. //志愿者
  784. if ($volunteer['team'] < $a_volunteer_number || $volunteer['yanglao'] < $a_volunteer_achievement) {
  785. $this->grade($value['uid'], 1, $volunteer);
  786. }
  787. //一星
  788. if ($volunteer['team'] >= $a_volunteer_number && $volunteer['yanglao'] >= $a_volunteer_achievement//满足一星条件
  789. &&
  790. ($volunteer['team'] < $b_volunteer_number || $volunteer['yanglao'] < $b_volunteer_achievement)//未满足二星条件
  791. ) {
  792. $this->grade($value['uid'], 2, $volunteer);
  793. }
  794. //二星
  795. if ($volunteer['team'] >= $b_volunteer_number && $volunteer['yanglao'] >= $b_volunteer_achievement//满足二星条件
  796. &&
  797. ($volunteer['team'] < $c_volunteer_number || $volunteer['yanglao'] < $c_volunteer_achievement)//未满足三星条件
  798. ) {
  799. $this->grade($value['uid'], 3, $volunteer);
  800. }
  801. //三星
  802. if ($volunteer['team'] >= $c_volunteer_number && $volunteer['yanglao'] >= $c_volunteer_achievement//满足三星条件
  803. &&
  804. ($volunteer['team'] < $d_volunteer_number || $volunteer['yanglao'] < $d_volunteer_achievement)//未满足董事条件
  805. ) {
  806. $this->grade($value['uid'], 4, $volunteer);
  807. }
  808. //董事
  809. if ($volunteer['team'] >= $d_volunteer_number && $volunteer['yanglao'] >= $d_volunteer_achievement) {
  810. $this->grade($value['uid'], 5, $volunteer);
  811. }
  812. }
  813. //团队各等级数量统计
  814. $this->statistics($value['uid']);
  815. }
  816. } catch (Exception $e) {
  817. Log::info('志愿者升级:' . $e->getMessage());
  818. }
  819. }
  820. //志愿者信息
  821. public function volunteer($uid)
  822. {
  823. if (!$uid) {
  824. return false;
  825. }
  826. //本人养老金
  827. $data['self_yanglao'] = $this->getYanglao($uid);
  828. //团队人数
  829. $data['team'] = $this->volunteer_number($uid);
  830. //团队养老金
  831. $data['yanglao'] = $this->volunteer_achievement($uid);
  832. //直推人数
  833. $data['extension'] = Db::name("user_identity_log")->where(["uid" => $uid])->count();
  834. //直推商户数量
  835. $data['shop'] = Db::name("user_identity_log")->where(["uid" => $uid, 'identity' => 4])->whereNotIn("identity", "0")->count();
  836. return $data;
  837. }
  838. //团队人数
  839. public function volunteer_number($uid)
  840. {
  841. $number = 0;
  842. $number1 = Db::name("user_identity_log")->where(["uid" => $uid])->field("link_id")->select();
  843. $number += count($number1);
  844. foreach ($number1 as $key => $value) {
  845. $number += Db::name("user_identity_log")->where(["uid" => $value['link_id']])->field("link_id")->count();
  846. }
  847. return $number;
  848. }
  849. //团队养老金
  850. public function volunteer_achievement($uid)
  851. {
  852. $yanglao = 0;
  853. $number1 = Db::name("user_identity_log")->where(["uid" => $uid])->field("link_id")->select();
  854. foreach ($number1 as $key => $value) {
  855. $yanglao += $this->getYanglao($value['link_id']);
  856. $number2 = Db::name("user_identity_log")->where(["uid" => $value['link_id']])->field("link_id")->select();
  857. foreach ($number2 as $k => $v) {
  858. $yanglao += $this->getYanglao($v['link_id']);
  859. }
  860. unset($number2);
  861. }
  862. return $yanglao;
  863. }
  864. //用户养老金
  865. public function getYanglao($uid)
  866. {
  867. return Db::name("UserBill")
  868. ->where([
  869. 'uid' => $uid,
  870. 'commission_type' => 5,
  871. 'status' => 1,
  872. 'pm' => 1
  873. ])
  874. ->sum("number");
  875. }
  876. //升级
  877. public function grade($uid, $grade, $volunteer)
  878. {
  879. $exist = Db::name("Volunteer")->where(["uid" => $uid])->find();
  880. if ($exist) {
  881. Db::name("Volunteer")
  882. ->where(["uid" => $uid])
  883. ->update([
  884. "grade" => $grade,
  885. "team" => $volunteer['team'],
  886. "yanglao" => $volunteer['yanglao'],
  887. "extension" => $volunteer['extension'],
  888. "shop" => $volunteer['shop'],
  889. "time" => time()
  890. ]);
  891. return true;
  892. }
  893. Db::name("Volunteer")
  894. ->insert([
  895. "uid" => $uid,
  896. "grade" => $grade,
  897. "team" => $volunteer['team'],
  898. "yanglao" => $volunteer['yanglao'],
  899. "extension" => $volunteer['extension'],
  900. "shop" => $volunteer['shop'],
  901. "time" => time()
  902. ]
  903. );
  904. return true;
  905. }
  906. //下级各等级数量统计
  907. public function statistics($uid)
  908. {
  909. $data = [
  910. 'v' => 0,
  911. 'v1' => 0,
  912. 'v2' => 0,
  913. 'v3' => 0,
  914. 'v4' => 0
  915. ];
  916. $fns = function ($uid) use (&$fns, &$data) {
  917. $identity = Db::name("user_identity_log")
  918. ->alias("u")
  919. ->join("Volunteer v", "u.link_id = v.uid")
  920. ->where(["u.uid" => $uid])
  921. ->field("u.link_id,v.grade")
  922. ->select();
  923. if ($identity) {
  924. foreach ($identity as $key => $value) {
  925. if ($value['grade'] == 1) {
  926. $data['v']++;
  927. }
  928. if ($value['grade'] == 2) {
  929. $data['v1']++;
  930. }
  931. if ($value['grade'] == 3) {
  932. $data['v2']++;
  933. }
  934. if ($value['grade'] == 4) {
  935. $data['v3']++;
  936. }
  937. if ($value['grade'] == 5) {
  938. $data['v4']++;
  939. }
  940. $fns($value['link_id']);
  941. }
  942. }
  943. };
  944. $fns($uid);
  945. Db::name("Volunteer")
  946. ->where(["uid" => $uid])
  947. ->update([
  948. "v" => $data['v'],
  949. "v1" => $data['v1'],
  950. "v2" => $data['v2'],
  951. "v3" => $data['v3'],
  952. "v4" => $data['v4'],
  953. "time" => time()
  954. ]);
  955. return $data;
  956. }
  957. }