PensionTasks.php 67 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526
  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\common\repositories\user\UserRepository;
  14. use app\traits\GzcApiRequest;
  15. use Carbon\Carbon;
  16. use think\console\Command;
  17. use think\console\Input;
  18. use think\console\Output;
  19. use think\Exception;
  20. use think\facade\Db;
  21. use think\facade\Log;
  22. use app\common\repositories\store\order\StoreOrderRepository;
  23. /**
  24. * Class PensionTasks
  25. * @package app\command
  26. * @author: php迷途小书童
  27. * @created: 2021/3/19 9:14
  28. */
  29. class PensionTasks extends Command
  30. {
  31. use GzcApiRequest;
  32. protected function configure()
  33. {
  34. // 指令配置
  35. $this->setName('pensiontask')
  36. ->setDescription('the pensiontask command');
  37. }
  38. protected function execute(Input $input, Output $output)
  39. {
  40. //1线下2在线3拼多多4京东5苏宁6淘宝7VIP
  41. $nowTime = time();
  42. try {
  43. //线下符合条件的养老金收集(线下交易后第8天)
  44. $this->doOfflineOrderGzc($nowTime, $timeLimit = 1);
  45. //在线订单符合条件的养老金收集(线上收货后第30天)
  46. $this->doOnlineOrderGzc($timeLimit = 30);
  47. //在线订单符合条件的话费养老金收集(话费到账后第1天)
  48. $this->doOnlineHuuafeiOrderGzc($timeLimit = 1);
  49. //第三方订单符合条件的养老金收集(三方结算后第2天)
  50. $this->doThridPddOrderGzc($nowTime, $timeLimit = 2);
  51. $this->doThridJdOrderGzc($nowTime, $timeLimit = 2);
  52. $this->doThridSnOrderGzc($nowTime, $timeLimit = 2);
  53. $this->doThridTaobaoOrderGzc($nowTime, $timeLimit = 2);
  54. $this->doThridVipOrderGzc($nowTime, $timeLimit = 2);
  55. $this->doThridDyOrderGzc($nowTime, $timeLimit = 2);
  56. $this->doThridHfOrderGzc($nowTime, $timeLimit = 2);
  57. $this->billGzcAdd($nowTime);
  58. //升级
  59. // $this -> doUpgrade();
  60. } catch (\Throwable $e) {
  61. Log::info('公证处入账:' . $e->getFile() . ':' . $e->getLine() . '【' . $e->getMessage() . '】');
  62. var_dump('公证处入账:' . $e->getFile() . ':' . $e->getLine() . '【' . $e->getMessage() . '】');
  63. }
  64. // 指令输出
  65. $output->writeln('pensiontask');
  66. }
  67. /**
  68. * 线下支付订单公证处IN10入账
  69. * @param $nowTime
  70. * author: php迷途小书童
  71. * created: 2021/3/20 9:26
  72. */
  73. public function billGzcAdd($nowTime)
  74. {
  75. $OrderGzcRepository = app()->make(OrderGzcRepository::class);
  76. $OrderMerchantRepository = app()->make(OrderMerchantRepository::class);
  77. $StoreOrderRepository = app()->make(StoreOrderRepository::class);
  78. $cursor = Db::table('user_bill')
  79. ->where('status', 1)
  80. ->where('is_gzc', 0)
  81. ->where('commission_type', 5)
  82. ->select()->toArray();
  83. foreach ($cursor as $bill) {
  84. $type_shop = $bill['type_shop'] ?? 0;
  85. switch ($type_shop){
  86. case "0":
  87. $online = $cursor = Db::table('rrx_store_order')->where('uid', $bill['uid'])->where('order_sn', $bill['order_sn'])->where('paid', 1)->find();
  88. break;
  89. case "1":
  90. $online = Db::table('rrx_order_pdd')->where('uid', $bill['uid'])->where('order_sn', $bill['order_sn'])->find();
  91. break;
  92. case "2":
  93. $online = Db::table('rrx_order_vip')->where('uid', $bill['uid'])->where('order_sn', $bill['order_sn'])->find();
  94. break;
  95. case "3":
  96. $online = Db::table('rrx_order_su')->where('uid', $bill['uid'])->where('order_sn', $bill['order_sn'])->find();
  97. break;
  98. case "4":
  99. $online = '';
  100. break;
  101. case "5":
  102. $online = Db::table('rrx_order_tb')->where('uid', $bill['uid'])->where('order_sn', $bill['order_sn'])->find();
  103. break;
  104. case "6":
  105. $online = Db::table('rrx_order_jd')->where('uid', $bill['uid'])->where('order_sn', $bill['order_sn'])->find();
  106. break;
  107. case "7":
  108. $online = '';
  109. break;
  110. case "8":
  111. $online = '';
  112. break;
  113. case "9":
  114. $online = Db::table('rrx_order_huafei')->where('uid', $bill['uid'])->where('order_sn', $bill['order_sn'])->find();
  115. break;
  116. default:
  117. $online = Db::table('rrx_store_order')->where('uid', $bill['uid'])->where('order_sn', $bill['order_sn'])->where('paid', 1)->find();
  118. }
  119. if (!$online) {
  120. Log::info($bill['uid'] . '查询不到订单');
  121. continue;
  122. }
  123. $certification = UserCertification::getInstance()->where('uid', $bill['uid'])->find();
  124. if (!$certification) {
  125. Log::info($online['uid'] . '没有实名认证');
  126. continue;
  127. }
  128. $pension = $bill['number'] ?? 0;
  129. if ($pension <= 0) {
  130. Log::info($online['order_sn'] . 'pension' . $pension);
  131. continue;
  132. }
  133. //新增入账明细记录
  134. $orderId = $OrderMerchantRepository->getNewOrderId('IN10');
  135. $create = [
  136. 'uid' => $online['uid'],
  137. 'platform_no' => $orderId,
  138. 'account_type' => $online['pay_type'] == 1 ? 3 : 2,
  139. 'user_name' => $certification['user_name'],
  140. 'mobile' => $certification['mobile'],
  141. 'user_card' => $certification['user_card'],
  142. 'pension' => $pension,
  143. 'order_type' => 2,
  144. 'out_trade_no' => $online['order_sn'],
  145. 'link_id'=> $bill['bill_id']
  146. ];
  147. $test_user = Db::name('user')->where('uid', $online['uid'])->value('test_user');
  148. $check = Db::name("gzc_logs")->where("link_id", $bill['id'])->where("order_type", 2)->count();
  149. if ($test_user == 0 && $check <= 0) {
  150. $OrderGzcRepository->create($create);
  151. Db::name('user_bill')
  152. ->where('bill_id', $bill['bill_id'])
  153. ->where('commission_type', 5)
  154. ->update([
  155. 'is_gzc' => 1
  156. ]);
  157. }
  158. }
  159. }
  160. /**
  161. * 线下支付订单公证处IN10入账
  162. * @param $nowTime
  163. * @param $timeLimit
  164. * author: php迷途小书童
  165. * created: 2021/3/20 9:26
  166. */
  167. public function doOfflineOrderGzc($nowTime, $timeLimit)
  168. {
  169. $cursor = Db::table('rrx_order_merchant')
  170. ->whereNotNull('pay_time')
  171. ->where('paid', 1)
  172. ->where('gzc', 0)
  173. ->whereTime('pay_time', '<', $nowTime - bcmul((string)$timeLimit, (string)86400))
  174. ->cursor();
  175. $OrderGzcRepository = app()->make(OrderGzcRepository::class);
  176. $OrderMerchantRepository = app()->make(OrderMerchantRepository::class);
  177. $StoreOrderRepository = app()->make(StoreOrderRepository::class);
  178. foreach ($cursor as $offline) {
  179. if ($offline['mer_id'] == 496) {
  180. continue;
  181. }
  182. $uid = 0;
  183. switch ($offline['trade_type']) {
  184. case 'WX':
  185. $uid = User::getInstance()->where('wechat_user_id', $offline['pay_user_id'])->value('uid');
  186. $accountType = 3;
  187. break;
  188. case 'ALI':
  189. $uid = User::getInstance()->where('ali_user_id', $offline['pay_user_id'])->value('uid');
  190. $accountType = 2;
  191. break;
  192. default:
  193. break;
  194. }
  195. if (!$uid) {
  196. Log::info($offline['pay_user_id'] . '未绑定用户');
  197. continue;
  198. }
  199. // $certification = UserCertification::getInstance()->where('uid', $uid)->find();
  200. // if (!$certification) {
  201. // Log::info($offline['pay_user_id'] . '未实名认证');
  202. // continue;
  203. // }
  204. //查询养老金金额
  205. $UserBillRepository = app()->make(UserBillRepository::class);
  206. $bill = $UserBillRepository->getWhere(['uid' => $uid, 'link_id' => $offline['id'], 'order_sn' => $offline['out_trade_no'], 'title' => '养老金']);
  207. $pension = $bill->number ?? 0;
  208. // if ($pension <= 0) {
  209. // Log::info($offline['out_trade_no'] . 'pension' . $pension);
  210. // continue;
  211. // }
  212. // Db::transaction(function () use ($uid, $certification, $accountType, $offline, $OrderGzcRepository, $OrderMerchantRepository, $pension, $StoreOrderRepository) {
  213. Db::transaction(function () use ($uid, $accountType, $offline, $OrderGzcRepository, $OrderMerchantRepository, $pension, $StoreOrderRepository) {
  214. $order = OrderMerchant::getInstance()->find($offline['id']);
  215. $order->gzc = 1;
  216. $order->is_settlement = 1;
  217. $order->settlement_time = date('Y-m-d H:i:s');
  218. $order->save();
  219. //新增入账明细记录
  220. // $orderId = $OrderMerchantRepository->getNewOrderId('IN10');
  221. // $create = [
  222. // 'uid' => $uid,
  223. // 'platform_no' => $orderId,
  224. // 'account_type' => $accountType,
  225. // 'user_name' => $certification['user_name'],
  226. // 'mobile' => $certification['mobile'],
  227. // 'user_card' => $certification['user_card'],
  228. // 'pension' => $pension,
  229. // 'order_type' => 1,
  230. // 'out_trade_no' => $offline['out_trade_no']
  231. // ];
  232. // $test_user = Db::name('user')->where('uid', $uid)->value('test_user');
  233. // if ($test_user == 0) {
  234. // $OrderGzcRepository->create($create);
  235. // }
  236. // // 养老金区域奖励
  237. // $order_data = [
  238. // 'pay_price' => $pension,
  239. // 'user_address_ids' => $offline['user_address_ids'],
  240. // 'uid' => $offline['uid'],
  241. // 'order_sn' => $offline['out_trade_no']
  242. // ];
  243. // $StoreOrderRepository->area_manage_details($order_data, 0, 2);
  244. // 结算红包
  245. // $user_sign_hongbao_list = Db::name('user_sign_hongbao')
  246. // ->where('status', -1)
  247. // ->where('order_id', $offline['id'])
  248. // ->whereIn('type', [1, 2])
  249. // ->select()
  250. // ->toArray();
  251. // foreach ($user_sign_hongbao_list as $user_sign_hongbao) {
  252. // if($user_sign_hongbao['uid']){
  253. // // 修改红包
  254. // Db::name('user')
  255. // ->where('uid', $user_sign_hongbao['uid'])
  256. // ->inc('hongbao', (float)$user_sign_hongbao['number'])
  257. // ->update();
  258. // Db::name('user_sign_hongbao')
  259. // ->where('status', -1)
  260. // ->where('id', $user_sign_hongbao['id'])
  261. // ->update([
  262. // 'status' => 1,
  263. // 'settlement_time' => date('Y-m-d H:i:s')
  264. // ]);
  265. // }
  266. // }
  267. // // 结算积分
  268. // $user_sign_score_list = Db::name('user_sign_score')
  269. // ->where('status', -1)
  270. // ->where('order_id', $offline['id'])
  271. // ->whereIn('type', [1, 2])
  272. // ->select()
  273. // ->toArray();
  274. // foreach ($user_sign_score_list as $user_sign_score) {
  275. // if($user_sign_score['uid']){
  276. // // 修改积分
  277. // Db::name('user')
  278. // ->where('uid', $user_sign_score['uid'])
  279. // ->inc('score', (float)$user_sign_score['reward_socre'])
  280. // ->update();
  281. // Db::name('user_sign_score')
  282. // ->where('status', -1)
  283. // ->where('id', $user_sign_score['id'])
  284. // ->update([
  285. // 'status' => 1,
  286. // 'settlement_time' => date('Y-m-d H:i:s')
  287. // ]);
  288. // }
  289. // }
  290. // // 结算贡献值
  291. // $user_sign_gongxian_list = Db::name('user_sign_gongxian')
  292. // ->where('status', -1)
  293. // ->where('order_id', $offline['id'])
  294. // ->whereIn('type', [1, 2])
  295. // ->select()
  296. // ->toArray();
  297. // foreach ($user_sign_gongxian_list as $user_sign_gongxian) {
  298. // if($user_sign_gongxian['uid']){
  299. // // 修改贡献值
  300. // Db::name('user')
  301. // ->where('uid', $user_sign_gongxian['uid'])
  302. // ->inc('contribute', (float)$user_sign_gongxian['number'])
  303. // ->update();
  304. // Db::name('user_sign_gongxian')
  305. // ->where('status', -1)
  306. // ->where('id', $user_sign_gongxian['id'])
  307. // ->update([
  308. // 'status' => 1,
  309. // 'settlement_time' => date('Y-m-d H:i:s')
  310. // ]);
  311. // }
  312. // }
  313. // // 结算佣金
  314. // $user_bill_list = Db::name('user_bill')
  315. // ->where('status', 0)
  316. // ->where('commission_type','<>', 5)
  317. // ->where([ 'link_id' => $offline['id'], 'order_sn' => $offline['order_sn']])
  318. // ->select()
  319. // ->toArray();
  320. // foreach ($user_bill_list as $user_bill) {
  321. // if($user_bill['uid']){
  322. // if ($user_bill['commission_type'] != 5) {
  323. // if (in_array($user_bill['commission_type'], [7,12,19])) {
  324. // Db::name("merchant")
  325. // ->where("mer_id", $user_bill['mer_id'])
  326. // ->inc('brokerage_price', (float)$user_bill['number'])
  327. // ->update();
  328. // } else {
  329. // Db::name('user')
  330. // ->where('uid', $user_bill['uid'])
  331. // ->inc('brokerage_price', (float)$user_bill['number'])
  332. // ->update();
  333. // }
  334. // }
  335. // }
  336. // }
  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 doOnlineHuuafeiOrderGzc($timeLimit)
  348. {
  349. // 普通订单
  350. $cursor = Db::table('rrx_order_huafei')->where('status', 3)->where('gzc', 0)->cursor();
  351. $StoreOrderStatusRepository = app()->make(StoreOrderStatusRepository::class);
  352. $OrderMerchantRepository = app()->make(OrderMerchantRepository::class);
  353. $OrderGzcRepository = app()->make(OrderGzcRepository::class);
  354. foreach ($cursor as $online) {
  355. if (time() < strtotime($online['finish_time']) + 3600 * 24) {
  356. Log::info('还没有话费到账后' . $timeLimit . '天');
  357. continue;
  358. }
  359. $certification = UserCertification::getInstance()->where('uid', $online['uid'])->find();
  360. if (!$certification) {
  361. Log::info($online['uid'] . '没有实名认证');
  362. continue;
  363. }
  364. //查询养老金金额
  365. $UserBillRepository = app()->make(UserBillRepository::class);
  366. $bill = $UserBillRepository->getWhere(['uid' => $online['uid'], 'order_sn' => $online['order_sn'], 'commission_type' => 5]);
  367. $pension = $bill->number ?? 0;
  368. if ($pension <= 0) {
  369. Log::info($online['order_sn'] . 'pension' . $pension);
  370. continue;
  371. }
  372. //首信易分账
  373. // $StoreOrderRepository = app()->make(StoreOrderRepository::class);
  374. // if ($online['pay_type'] > 0) {
  375. // $StoreOrderRepository->splitOrder($online);
  376. // }
  377. $StoreOrderRepository = [];
  378. Db::transaction(function () use ($certification, $online, $pension, $OrderGzcRepository, $OrderMerchantRepository, $StoreOrderRepository) {
  379. //新增入账明细记录
  380. $orderId = $OrderMerchantRepository->getNewOrderId('IN10');
  381. $create = [
  382. 'uid' => $online['uid'],
  383. 'platform_no' => $orderId,
  384. 'account_type' => 3,//账号类型1银行卡2支付宝3微信
  385. 'user_name' => $certification['user_name'],
  386. 'mobile' => $certification['mobile'],
  387. 'user_card' => $certification['user_card'],
  388. 'pension' => $pension,
  389. 'order_type' => 2,
  390. 'out_trade_no' => $online['order_sn']
  391. ];
  392. $test_user = Db::name('user')->where('uid', $online['uid'])->value('test_user');
  393. $check = Db::name("gzc_logs")->where("out_trade_no", $online['order_sn'])->where("order_type", 2)->count();
  394. if ($test_user == 0 && $check <= 0) {
  395. $OrderGzcRepository->create($create);
  396. }
  397. $order = StoreOrder::getInstance()->find($online['order_id']);
  398. $order->gzc = 1;
  399. $order->save();
  400. });
  401. }
  402. // 普通订单(红包,积分,京东,佣金,复购金,养老金,贡献值)
  403. $cursor = Db::table('rrx_order_huafei')->where('status', 3)->where('bill_status', 0)->cursor();
  404. $StoreOrderStatusRepository = app()->make(StoreOrderStatusRepository::class);
  405. $OrderMerchantRepository = app()->make(OrderMerchantRepository::class);
  406. $OrderGzcRepository = app()->make(OrderGzcRepository::class);
  407. foreach ($cursor as $online) {
  408. if (time() < strtotime($online['finish_time']) + 3600 * 24) {
  409. Log::info('还没有话费到账后' . $timeLimit . '天');
  410. continue;
  411. }
  412. Db::transaction(function () use ($online) {
  413. //订单状态改为已结算
  414. Db::name('rrx_order_huafei')
  415. ->where('status', 3)->where('bill_status', 0)
  416. ->where('order_sn', $online['order_sn'])
  417. ->update([
  418. 'bill_status'=> 1,
  419. 'bill_create_time' => time()
  420. ]);
  421. // 结算积分
  422. $user_sign_score_list = Db::name('user_sign_score')
  423. ->where('status', -1)
  424. ->where('order_id', $online['order_sn'])
  425. ->whereIn('type', [1, 2])
  426. ->select()
  427. ->toArray();
  428. foreach ($user_sign_score_list as $user_sign_score) {
  429. // 修改积分
  430. Db::name('user')
  431. ->where('uid', $user_sign_score['uid'])
  432. ->inc('score', (float)$user_sign_score['reward_socre'])
  433. ->update();
  434. Db::name('user_sign_score')
  435. ->where('status', -1)
  436. ->where('id', $user_sign_score['id'])
  437. ->update([
  438. 'status' => 1,
  439. 'settlement_time' => date('Y-m-d H:i:s')
  440. ]);
  441. }
  442. // 结算复购金
  443. $user_sign_fugou_list = Db::name('user_sign_fugou')
  444. ->where('status', -1)
  445. ->where('order_id', $online['order_sn'])
  446. ->whereIn('type', [1, 2])
  447. ->select()
  448. ->toArray();
  449. foreach ($user_sign_fugou_list as $user_sign_fugou) {
  450. // 修改复购金
  451. Db::name('user')
  452. ->where('uid', $user_sign_fugou['uid'])
  453. ->inc('fugou', (float)$user_sign_fugou['number'])
  454. ->update();
  455. Db::name('user_sign_fugou')
  456. ->where('status', -1)
  457. ->where('id', $user_sign_fugou['id'])
  458. ->update([
  459. 'status' => 1,
  460. 'settlement_time' => date('Y-m-d H:i:s')
  461. ]);
  462. }
  463. // 结算贡献值
  464. $user_sign_gongxian_list = Db::name('user_sign_gongxian')
  465. ->where('status', -1)
  466. ->where('order_id', $online['order_sn'])
  467. ->whereIn('type', [1, 2])
  468. ->select()
  469. ->toArray();
  470. foreach ($user_sign_gongxian_list as $user_sign_gongxian) {
  471. // 修改贡献值
  472. Db::name('user')
  473. ->where('uid', $user_sign_gongxian['uid'])
  474. ->inc('contribute', (float)$user_sign_gongxian['number'])
  475. ->update();
  476. Db::name('user_sign_gongxian')
  477. ->where('status', -1)
  478. ->where('id', $user_sign_gongxian['id'])
  479. ->update([
  480. 'status' => 1,
  481. 'settlement_time' => date('Y-m-d H:i:s')
  482. ]);
  483. /** @var UserRepository $userRepository */
  484. $userRepository = app()->make(UserRepository::class);
  485. $userRepository->setUserIdentity($user_sign_gongxian['uid']);
  486. }
  487. });
  488. }
  489. }
  490. /**
  491. * 在线支付公证处IN10入账 (红包,积分,京东,佣金,复购金,养老金,贡献值)
  492. * @param $nowTime
  493. * @param $timeLimit
  494. * author: php迷途小书童
  495. * created: 2021/3/20 9:25
  496. */
  497. public function doOnlineOrderGzc($timeLimit)
  498. {
  499. return true;
  500. // 普通订单
  501. $cursor = Db::table('rrx_store_order')->where('paid', 1)->where('gzc', 0)->where('pay_type', 'in', '0,1,2,4')->cursor();
  502. $StoreOrderStatusRepository = app()->make(StoreOrderStatusRepository::class);
  503. $OrderMerchantRepository = app()->make(OrderMerchantRepository::class);
  504. $OrderGzcRepository = app()->make(OrderGzcRepository::class);
  505. foreach ($cursor as $online) {
  506. $status = $StoreOrderStatusRepository->getWhere(['order_id' => $online['order_id'], 'change_type' => 'take']);
  507. if ($online['mer_id'] == 496) {
  508. if (!in_array($online['status'], [0, 1, 2, 3])) {
  509. continue;
  510. }
  511. // if (time() < strtotime($online['pay_time']) + 3600 * 24) {
  512. // Log::info('还没有到收货后' . $timeLimit . '天');
  513. // continue;
  514. // }
  515. } else {
  516. if (!in_array($online['status'], [2, 3])) {
  517. continue;
  518. }
  519. if (Carbon::now()->modify("-{$timeLimit} days")->lt($status->change_time ?? $status['change_time'])) {
  520. Log::info('还没有到收货后' . $timeLimit . '天');
  521. continue;
  522. }
  523. }
  524. // $certification = UserCertification::getInstance()->where('uid', $online['uid'])->find();
  525. // if (!$certification) {
  526. // Log::info($online['uid'] . '没有实名认证');
  527. // continue;
  528. // }
  529. //查询养老金金额
  530. $UserBillRepository = app()->make(UserBillRepository::class);
  531. $bill = $UserBillRepository->getWhere(['uid' => $online['uid'], 'link_id' => $online['order_id'], 'order_sn' => $online['order_sn'], 'commission_type' => 5]);
  532. $pension = $bill->number ?? 0;
  533. // if ($pension <= 0) {
  534. // Log::info($online['order_sn'] . 'pension' . $pension);
  535. // continue;
  536. // }
  537. //首信易分账
  538. // $StoreOrderRepository = app()->make(StoreOrderRepository::class);
  539. // if ($online['pay_type'] > 0) {
  540. // $StoreOrderRepository->splitOrder($online);
  541. // }
  542. Db::transaction(function () use ($online, $pension, $OrderGzcRepository, $OrderMerchantRepository, $StoreOrderRepository) {
  543. //新增入账明细记录
  544. // $orderId = $OrderMerchantRepository->getNewOrderId('IN10');
  545. // $create = [
  546. // 'uid' => $online['uid'],
  547. // 'platform_no' => $orderId,
  548. // 'account_type' => $online['pay_type'] == 1 ? 3 : 2,
  549. // 'user_name' => $certification['user_name'],
  550. // 'mobile' => $certification['mobile'],
  551. // 'user_card' => $certification['user_card'],
  552. // 'pension' => $pension,
  553. // 'order_type' => 2,
  554. // 'out_trade_no' => $online['order_sn']
  555. // ];
  556. // $test_user = Db::name('user')->where('uid', $online['uid'])->value('test_user');
  557. // $check = Db::name("gzc_logs")->where("out_trade_no", $online['order_sn'])->where("order_type", 2)->count();
  558. // if ($test_user == 0 && $check <= 0) {
  559. // $OrderGzcRepository->create($create);
  560. // }
  561. $order = StoreOrder::getInstance()->find($online['order_id']);
  562. $order->gzc = 1;
  563. $order->save();
  564. Db::name('user_bill')
  565. ->where('order_sn', $online['order_sn'])
  566. ->where('commission_type', 5)
  567. ->update(['status'=> 1]);
  568. // 养老金区域奖励
  569. // $order_data = [
  570. // 'pay_price' => $pension,
  571. // 'user_address_ids' => $online['user_address_ids'],
  572. // 'uid' => $online['uid'],
  573. // 'order_sn' => $online['order_sn']
  574. // ];
  575. // $StoreOrderRepository->area_manage_details($order_data, 8, 2);
  576. });
  577. }
  578. // 普通订单(红包,积分,京东,佣金,复购金,贡献值)
  579. $cursor = Db::table('rrx_store_order')->where('paid', 1)->where('is_settlement', 0)->where('pay_type', 'in', '0,1,2,4')->cursor();
  580. $StoreOrderStatusRepository = app()->make(StoreOrderStatusRepository::class);
  581. $OrderMerchantRepository = app()->make(OrderMerchantRepository::class);
  582. $OrderGzcRepository = app()->make(OrderGzcRepository::class);
  583. foreach ($cursor as $online) {
  584. $status = $StoreOrderStatusRepository->getWhere(['order_id' => $online['order_id'], 'change_type' => 'take']);
  585. if ($online['mer_id'] == 496) {
  586. if (!in_array($online['status'], [0, 1, 2, 3])) {
  587. continue;
  588. }
  589. if (time() < strtotime($online['pay_time']) + 3600 * 24) {
  590. Log::info('还没有到收货后' . $timeLimit . '天');
  591. continue;
  592. }
  593. } else {
  594. if (!in_array($online['status'], [2, 3])) {
  595. continue;
  596. }
  597. if (Carbon::now()->modify("-{$timeLimit} days")->lt($status->change_time ?? $status['change_time'])) {
  598. Log::info('还没有到收货后' . $timeLimit . '天');
  599. continue;
  600. }
  601. }
  602. $StoreOrderRepository = app()->make(StoreOrderRepository::class);
  603. Db::transaction(function () use ($online, $StoreOrderRepository) {
  604. $order = StoreOrder::getInstance()->find($online['order_id']);
  605. $order->is_settlement = 1;
  606. $order->settlement_time = date('Y-m-d H:i:s');
  607. $order->save();
  608. // 结算积分
  609. $user_sign_score_list = Db::name('user_sign_score')
  610. ->where('status', -1)
  611. ->where('order_id', $online['order_id'])
  612. ->whereIn('type', [1, 2])
  613. ->select()
  614. ->toArray();
  615. foreach ($user_sign_score_list as $user_sign_score) {
  616. // 修改积分
  617. Db::name('user')
  618. ->where('uid', $user_sign_score['uid'])
  619. ->inc('score', (float)$user_sign_score['reward_socre'])
  620. ->update();
  621. Db::name('user_sign_score')
  622. ->where('status', -1)
  623. ->where('id', $user_sign_score['id'])
  624. ->update([
  625. 'status' => 1,
  626. 'settlement_time' => date('Y-m-d H:i:s')
  627. ]);
  628. }
  629. // 结算红包
  630. $user_sign_hongbao_list = Db::name('user_sign_hongbao')
  631. ->where('status', -1)
  632. ->where('order_id', $online['order_id'])
  633. ->whereIn('type', [1, 2])
  634. ->select()
  635. ->toArray();
  636. foreach ($user_sign_hongbao_list as $user_sign_hongbao) {
  637. // 修改红包
  638. Db::name('user')
  639. ->where('uid', $user_sign_hongbao['uid'])
  640. ->inc('hongbao', (float)$user_sign_hongbao['number'])
  641. ->update();
  642. Db::name('user_sign_hongbao')
  643. ->where('status', -1)
  644. ->where('id', $user_sign_hongbao['id'])
  645. ->update([
  646. 'status' => 1,
  647. 'settlement_time' => date('Y-m-d H:i:s')
  648. ]);
  649. }
  650. // 结算京豆
  651. $user_sign_jingdou_list = Db::name('user_sign_jingdou')
  652. ->where('status', -1)
  653. ->where('order_id', $online['order_id'])
  654. ->whereIn('type', [1, 2])
  655. ->select()
  656. ->toArray();
  657. foreach ($user_sign_jingdou_list as $user_sign_jingdou) {
  658. // 修改京豆
  659. Db::name('user')
  660. ->where('uid', $user_sign_jingdou['uid'])
  661. ->inc('jingdou', (float)$user_sign_jingdou['number'])
  662. ->update();
  663. Db::name('user_sign_jingdou')
  664. ->where('status', -1)
  665. ->where('id', $user_sign_jingdou['id'])
  666. ->update([
  667. 'status' => 1,
  668. 'settlement_time' => date('Y-m-d H:i:s')
  669. ]);
  670. }
  671. // 结算复购金
  672. $user_sign_fugou_list = Db::name('user_sign_fugou')
  673. ->where('status', -1)
  674. ->where('order_id', $online['order_id'])
  675. ->whereIn('type', [1, 2])
  676. ->select()
  677. ->toArray();
  678. foreach ($user_sign_fugou_list as $user_sign_fugou) {
  679. // 修改复购金
  680. Db::name('user')
  681. ->where('uid', $user_sign_fugou['uid'])
  682. ->inc('fugou', (float)$user_sign_fugou['number'])
  683. ->update();
  684. Db::name('user_sign_fugou')
  685. ->where('status', -1)
  686. ->where('id', $user_sign_fugou['id'])
  687. ->update([
  688. 'status' => 1,
  689. 'settlement_time' => date('Y-m-d H:i:s')
  690. ]);
  691. }
  692. // 结算贡献值
  693. $user_sign_gongxian_list = Db::name('user_sign_gongxian')
  694. ->where('status', -1)
  695. ->where('order_id', $online['order_id'])
  696. ->whereIn('type', [1, 2])
  697. ->select()
  698. ->toArray();
  699. foreach ($user_sign_gongxian_list as $user_sign_gongxian) {
  700. // 修改贡献值
  701. Db::name('user')
  702. ->where('uid', $user_sign_gongxian['uid'])
  703. ->inc('contribute', (float)$user_sign_gongxian['number'])
  704. ->update();
  705. Db::name('user_sign_gongxian')
  706. ->where('status', -1)
  707. ->where('id', $user_sign_gongxian['id'])
  708. ->update([
  709. 'status' => 1,
  710. 'settlement_time' => date('Y-m-d H:i:s')
  711. ]);
  712. /** @var UserRepository $userRepository */
  713. $userRepository = app()->make(UserRepository::class);
  714. $userRepository->setUserIdentity($user_sign_gongxian['uid']);
  715. }
  716. // 结算PV值
  717. $user_pv_list = Db::name('user_pv_log')
  718. ->where('status', -1)
  719. ->where('order_id', $online['order_id'])
  720. ->whereIn('type', [1, 2])
  721. ->select()
  722. ->toArray();
  723. foreach ($user_pv_list as $user_pv) {
  724. // 修改pv
  725. Db::name('user')
  726. ->where('uid', $user_pv['uid'])
  727. ->inc('pv', (float)$user_pv['pv'])
  728. ->update();
  729. Db::name('user_pv_log')
  730. ->where('status', -1)
  731. ->where('id', $user_pv['id'])
  732. ->update([
  733. 'status' => 1,
  734. 'settlement_time' => date('Y-m-d H:i:s')
  735. ]);
  736. }
  737. // 结算佣金
  738. $user_bill_list = Db::name('user_bill')
  739. ->where('status', 0)
  740. ->where('commission_type','<>', 5)
  741. ->where([ 'link_id' => $online['order_id'], 'order_sn' => $online['order_sn']])
  742. ->select()
  743. ->toArray();
  744. foreach ($user_bill_list as $user_bill) {
  745. if ($user_bill['commission_type'] != 5) {
  746. if (in_array($user_bill['commission_type'], [7,12,19])) {
  747. Db::name("merchant")
  748. ->where("mer_id", $user_bill['mer_id'])
  749. ->inc('brokerage_price', (float)$user_bill['number'])
  750. ->update();
  751. } else {
  752. Db::name('user')
  753. ->where('uid', $user_bill['uid'])
  754. ->inc('brokerage_price', (float)$user_bill['number'])
  755. ->update();
  756. }
  757. }
  758. if ($online['pay_type'] == 0 && $user_bill['commission_type'] == 5) {
  759. } else {
  760. // 虚拟支付的养老金不修改不结算
  761. Db::name('user_bill')
  762. ->where('status', 0)
  763. ->where('bill_id', $user_bill['bill_id'])
  764. ->update([
  765. 'status' => 1,
  766. 'take_time' => time()
  767. ]);
  768. }
  769. if ($online['pay_type'] == 0 && $user_bill['commission_type'] == 5) {
  770. } else {
  771. // 虚拟支付的养老金不修改不结算
  772. Db::name('user_bill')
  773. ->where('status', 0)
  774. ->where('bill_id', $user_bill['bill_id'])
  775. ->update([
  776. 'status' => 1,
  777. 'take_time' => time()
  778. ]);
  779. }
  780. }
  781. //按角色结算
  782. $StoreOrderRepository->close_order($online['order_id']);
  783. });
  784. }
  785. }
  786. /**
  787. * 第三方订单拼多多IN10入账
  788. * @param $nowTime
  789. * @param $timeLimit
  790. * author: php迷途小书童
  791. * created: 2021/3/20 9:26
  792. */
  793. public function doThridPddOrderGzc($nowTime, $timeLimit)
  794. {
  795. $cursor = Db::table('rrx_order_pdd')
  796. ->where('gzc', 0)
  797. ->where('bill_status', 1)
  798. ->where('commission', '>', 0)
  799. ->whereTime('bill_end_time', '<', $nowTime - bcmul((string)$timeLimit, (string)86400))
  800. ->cursor();
  801. $ProductRepository = app()->make(ProductRepository::class);
  802. $OrderGzcRepository = app()->make(OrderGzcRepository::class);
  803. $OrderMerchantRepository = app()->make(OrderMerchantRepository::class);
  804. $StoreOrderRepository = app()->make(StoreOrderRepository::class);
  805. foreach ($cursor as $thrid) {
  806. $uid = $thrid['uid'];
  807. if (!$uid)
  808. continue;
  809. // $certification = UserCertification::getInstance()->where('uid', $uid)->find();
  810. // if (!$certification) {
  811. // Log::info('用户ID' . $uid . '未实名认证');
  812. // continue;
  813. // }
  814. $pension = $ProductRepository->yanglaojin(0, sprintf('%.2f', $thrid['commission']));
  815. Db::transaction(function () use ($uid, $thrid, $pension, $OrderGzcRepository, $OrderMerchantRepository, $StoreOrderRepository) {
  816. //新增入账明细记录
  817. // $orderId = $OrderMerchantRepository->getNewOrderId('IN10');
  818. // $create = [
  819. // 'uid' => $uid,
  820. // 'platform_no' => $orderId,
  821. // 'user_name' => $certification['user_name'],
  822. // 'mobile' => $certification['mobile'],
  823. // 'user_card' => $certification['user_card'],
  824. // 'pension' => $pension,
  825. // 'order_type' => 3,
  826. // 'out_trade_no' => $thrid['order_sn']
  827. // ];
  828. // $test_user = Db::name('user')->where('uid', $uid)->value('test_user');
  829. // if ($test_user == 0) {
  830. // $OrderGzcRepository->create($create);
  831. // }
  832. // $OrderGzcRepository->create($create);
  833. Db::table('rrx_order_pdd')
  834. ->update(['gzc' => 1, 'order_pdd_id' => $thrid['order_pdd_id']]);
  835. Db::name('user_bill')
  836. ->where('order_sn', $thrid['order_sn'])
  837. ->where('commission_type', 5)
  838. ->update(['status'=> 1]);
  839. // 养老金区域奖励
  840. $order_data = [
  841. 'pay_price' => $pension,
  842. 'user_address_ids' => $thrid['user_address_ids'],
  843. 'uid' => $thrid['uid'],
  844. 'order_sn' => $thrid['order_sn']
  845. ];
  846. // $StoreOrderRepository->area_manage_details($order_data, 1, 2);
  847. });
  848. }
  849. }
  850. /**
  851. * 第三方订单京东IN10入账
  852. * @param $nowTime
  853. * @param $timeLimit
  854. * author: php迷途小书童
  855. * created: 2021/3/20 9:26
  856. */
  857. public function doThridJdOrderGzc($nowTime, $timeLimit)
  858. {
  859. $cursor = Db::table('rrx_order_jd')
  860. ->where('gzc', 0)
  861. ->where('bill_status', 1)
  862. ->where('commission', '>', 0)
  863. ->whereTime('bill_end_time', '<', $nowTime - bcmul((string)$timeLimit, (string)86400))
  864. ->cursor();
  865. // Db::name('log')->insert(['data'=>'abbbb入库语句'.$nowTime - bcmul((string)$timeLimit, (string)86400)]);
  866. // Db::name('log')->insert(['data'=>'abbbb'.json_encode($cursor)]);
  867. $ProductRepository = app()->make(ProductRepository::class);
  868. $OrderGzcRepository = app()->make(OrderGzcRepository::class);
  869. $OrderMerchantRepository = app()->make(OrderMerchantRepository::class);
  870. $StoreOrderRepository = app()->make(StoreOrderRepository::class);
  871. foreach ($cursor as $thrid) {
  872. $uid = $thrid['uid'];
  873. if (!$uid)
  874. continue;
  875. // $certification = UserCertification::getInstance()->where('uid', $uid)->find();
  876. // if (!$certification) {
  877. // Log::info('用户ID' . $uid . '未实名认证');
  878. // continue;
  879. // }
  880. $pension = $ProductRepository->yanglaojin(0, sprintf('%.2f', $thrid['commission']));
  881. Db::transaction(function () use ($uid, $thrid, $pension, $OrderGzcRepository, $OrderMerchantRepository, $StoreOrderRepository) {
  882. //新增入账明细记录
  883. // $orderId = $OrderMerchantRepository->getNewOrderId('IN10');
  884. // $create = [
  885. // 'uid' => $uid,
  886. // 'platform_no' => $orderId,
  887. // 'user_name' => $certification['user_name'],
  888. // 'mobile' => $certification['mobile'],
  889. // 'user_card' => $certification['user_card'],
  890. // 'pension' => $pension,
  891. // 'order_type' => 4,
  892. // 'out_trade_no' => $thrid['order_sn']
  893. // ];
  894. // $test_user = Db::name('user')->where('uid', $uid)->value('test_user');
  895. // if ($test_user == 0) {
  896. // $OrderGzcRepository->create($create);
  897. // }
  898. // $OrderGzcRepository->create($create);
  899. Db::table('rrx_order_jd')
  900. ->update(['gzc' => 1, 'order_jd_id' => $thrid['order_jd_id']]);
  901. Db::name('user_bill')
  902. ->where('order_sn', $thrid['order_sn'])
  903. ->where('commission_type', 5)
  904. ->update(['status'=> 1]);
  905. // 养老金区域奖励
  906. // $order_data = [
  907. // 'pay_price' => $pension,
  908. // 'user_address_ids' => $thrid['user_address_ids'],
  909. // 'uid' => $thrid['uid'],
  910. // 'order_sn' => $thrid['order_sn']
  911. // ];
  912. // $StoreOrderRepository->area_manage_details($order_data, 6, 2);
  913. });
  914. }
  915. }
  916. /**
  917. * 第三方订单苏宁IN10入账
  918. * @param $nowTime
  919. * @param $timeLimit
  920. * author: php迷途小书童
  921. * created: 2021/3/20 9:26
  922. */
  923. public function doThridSnOrderGzc($nowTime, $timeLimit)
  924. {
  925. $cursor = Db::table('rrx_order_su')
  926. ->where('gzc', 0)
  927. ->where('bill_status', 1)
  928. ->where('commission', '>', 0)
  929. ->whereTime('bill_end_time', '<', $nowTime - bcmul((string)$timeLimit, (string)86400))
  930. ->cursor();
  931. $ProductRepository = app()->make(ProductRepository::class);
  932. $OrderGzcRepository = app()->make(OrderGzcRepository::class);
  933. $OrderMerchantRepository = app()->make(OrderMerchantRepository::class);
  934. $StoreOrderRepository = app()->make(StoreOrderRepository::class);
  935. foreach ($cursor as $thrid) {
  936. $uid = $thrid['uid'];
  937. if (!$uid)
  938. continue;
  939. // $certification = UserCertification::getInstance()->where('uid', $uid)->find();
  940. // if (!$certification) {
  941. // Log::info('用户ID' . $uid . '未实名认证');
  942. // continue;
  943. // }
  944. $pension = $ProductRepository->yanglaojin(0, sprintf('%.2f', $thrid['commission']));
  945. Db::transaction(function () use ($uid, $thrid, $pension, $OrderGzcRepository, $OrderMerchantRepository, $StoreOrderRepository) {
  946. //新增入账明细记录
  947. // $orderId = $OrderMerchantRepository->getNewOrderId('IN10');
  948. // $create = [
  949. // 'uid' => $uid,
  950. // 'platform_no' => $orderId,
  951. // 'user_name' => $certification['user_name'],
  952. // 'mobile' => $certification['mobile'],
  953. // 'user_card' => $certification['user_card'],
  954. // 'pension' => $pension,
  955. // 'order_type' => 5,
  956. // 'out_trade_no' => $thrid['order_sn']
  957. // ];
  958. // $test_user = Db::name('user')->where('uid', $uid)->value('test_user');
  959. // if ($test_user == 0) {
  960. // $OrderGzcRepository->create($create);
  961. // }
  962. // $OrderGzcRepository->create($create);
  963. Db::table('rrx_order_su')
  964. ->update(['gzc' => 1, 'order_su_id' => $thrid['order_su_id']]);
  965. Db::name('user_bill')
  966. ->where('order_sn', $thrid['order_sn'])
  967. ->where('commission_type', 5)
  968. ->update(['status'=> 1]);
  969. // 养老金区域奖励
  970. $order_data = [
  971. 'pay_price' => $pension,
  972. 'user_address_ids' => $thrid['user_address_ids'],
  973. 'uid' => $thrid['uid'],
  974. 'order_sn' => $thrid['order_sn']
  975. ];
  976. // $StoreOrderRepository->area_manage_details($order_data, 3, 2);
  977. });
  978. }
  979. }
  980. /**
  981. * 第三方订单话费IN10入账
  982. * @param $nowTime
  983. * @param $timeLimit
  984. * author: php迷途小书童
  985. * created: 2021/3/20 9:26
  986. */
  987. public function doThridHfOrderGzc($nowTime, $timeLimit)
  988. {
  989. $cursor = Db::table('rrx_order_huafei')
  990. ->where('gzc', 0)
  991. ->where('bill_status', 1)
  992. ->where('commission', '>', 0)
  993. ->whereTime('bill_end_time', '<', $nowTime - bcmul((string)$timeLimit, (string)86400))
  994. ->cursor();
  995. $ProductRepository = app()->make(ProductRepository::class);
  996. $OrderGzcRepository = app()->make(OrderGzcRepository::class);
  997. $OrderMerchantRepository = app()->make(OrderMerchantRepository::class);
  998. foreach ($cursor as $thrid) {
  999. $uid = $thrid['uid'];
  1000. if (!$uid)
  1001. continue;
  1002. // $certification = UserCertification::getInstance()->where('uid', $uid)->find();
  1003. // if (!$certification) {
  1004. // Log::info('用户ID' . $uid . '未实名认证');
  1005. // continue;
  1006. // }
  1007. $pension = $ProductRepository->yanglaojin(0, sprintf('%.2f', $thrid['commission']));
  1008. Db::transaction(function () use ($uid, $thrid, $pension, $OrderGzcRepository, $OrderMerchantRepository) {
  1009. // //新增入账明细记录
  1010. // $orderId = $OrderMerchantRepository->getNewOrderId('IN10');
  1011. // $create = [
  1012. // 'uid' => $uid,
  1013. // 'platform_no' => $orderId,
  1014. // 'user_name' => $certification['user_name'],
  1015. // 'mobile' => $certification['mobile'],
  1016. // 'user_card' => $certification['user_card'],
  1017. // 'pension' => $pension,
  1018. // 'order_type' => 6,
  1019. // 'out_trade_no' => $thrid['order_sn']
  1020. // ];
  1021. // $test_user = Db::name('user')->where('uid', $uid)->value('test_user');
  1022. // if ($test_user == 0) {
  1023. // $OrderGzcRepository->create($create);
  1024. // }
  1025. Db::table('rrx_order_huafei')->update(['gzc' => 1, 'order_tb_id' => $thrid['order_tb_id']]);
  1026. Db::name('user_bill')
  1027. ->where('order_sn', $thrid['order_sn'])
  1028. ->where('commission_type', 5)
  1029. ->update(['status'=> 1]);
  1030. });
  1031. }
  1032. }
  1033. /**
  1034. * 第三方订单淘宝IN10入账
  1035. * @param $nowTime
  1036. * @param $timeLimit
  1037. * author: php迷途小书童
  1038. * created: 2021/3/20 9:26
  1039. */
  1040. public function doThridTaobaoOrderGzc($nowTime, $timeLimit)
  1041. {
  1042. $cursor = Db::table('rrx_order_tb')
  1043. ->where('gzc', 0)
  1044. ->where('bill_status', 1)
  1045. ->where('commission', '>', 0)
  1046. ->whereTime('bill_end_time', '<', $nowTime - bcmul((string)$timeLimit, (string)86400))
  1047. ->cursor();
  1048. $ProductRepository = app()->make(ProductRepository::class);
  1049. $OrderGzcRepository = app()->make(OrderGzcRepository::class);
  1050. $OrderMerchantRepository = app()->make(OrderMerchantRepository::class);
  1051. $StoreOrderRepository = app()->make(StoreOrderRepository::class);
  1052. foreach ($cursor as $thrid) {
  1053. $uid = $thrid['uid'];
  1054. if (!$uid)
  1055. continue;
  1056. // $certification = UserCertification::getInstance()->where('uid', $uid)->find();
  1057. // if (!$certification) {
  1058. // Log::info('用户ID' . $uid . '未实名认证');
  1059. // continue;
  1060. // }
  1061. $pension = $ProductRepository->yanglaojin(0, sprintf('%.2f', $thrid['commission']));
  1062. Db::transaction(function () use ($uid, $thrid, $pension, $OrderGzcRepository, $OrderMerchantRepository, $StoreOrderRepository) {
  1063. //新增入账明细记录
  1064. // $orderId = $OrderMerchantRepository->getNewOrderId('IN10');
  1065. // $create = [
  1066. // 'uid' => $uid,
  1067. // 'platform_no' => $orderId,
  1068. // 'user_name' => $certification['user_name'],
  1069. // 'mobile' => $certification['mobile'],
  1070. // 'user_card' => $certification['user_card'],
  1071. // 'pension' => $pension,
  1072. // 'order_type' => 6,
  1073. // 'out_trade_no' => $thrid['order_sn']
  1074. // ];
  1075. // $test_user = Db::name('user')->where('uid', $uid)->value('test_user');
  1076. // if ($test_user == 0) {
  1077. // $OrderGzcRepository->create($create);
  1078. // }
  1079. // $OrderGzcRepository->create($create);
  1080. Db::table('rrx_order_tb')
  1081. ->update(['gzc' => 1, 'order_tb_id' => $thrid['order_tb_id']]);
  1082. Db::name('user_bill')
  1083. ->where('order_sn', $thrid['order_sn'])
  1084. ->where('commission_type', 5)
  1085. ->update(['status'=> 1]);
  1086. // 养老金区域奖励
  1087. $order_data = [
  1088. 'pay_price' => $pension,
  1089. 'user_address_ids' => $thrid['user_address_ids'],
  1090. 'uid' => $thrid['uid'],
  1091. 'order_sn' => $thrid['order_sn']
  1092. ];
  1093. // $StoreOrderRepository->area_manage_details($order_data, 5, 2);
  1094. });
  1095. }
  1096. }
  1097. /**
  1098. * 第三方订单唯品会IN10入账
  1099. * @param $nowTime
  1100. * @param $timeLimit
  1101. * author: php迷途小书童
  1102. * created: 2021/3/20 9:26
  1103. */
  1104. public function doThridVipOrderGzc($nowTime, $timeLimit)
  1105. {
  1106. $cursor = Db::table('rrx_order_vip')
  1107. ->where('gzc', 0)
  1108. ->where('bill_status', 1)
  1109. ->where('commission', '>', 0)
  1110. ->whereTime('bill_end_time', '<', $nowTime - bcmul((string)$timeLimit, (string)86400))
  1111. ->cursor();
  1112. $ProductRepository = app()->make(ProductRepository::class);
  1113. $OrderGzcRepository = app()->make(OrderGzcRepository::class);
  1114. $OrderMerchantRepository = app()->make(OrderMerchantRepository::class);
  1115. $StoreOrderRepository = app()->make(StoreOrderRepository::class);
  1116. foreach ($cursor as $thrid) {
  1117. $uid = $thrid['uid'];
  1118. if (!$uid)
  1119. continue;
  1120. // $certification = UserCertification::getInstance()->where('uid', $uid)->find();
  1121. // if (!$certification) {
  1122. // Log::info('用户ID' . $uid . '未实名认证');
  1123. // continue;
  1124. // }
  1125. $pension = $ProductRepository->yanglaojin(0, sprintf('%.2f', $thrid['commission']));
  1126. Db::transaction(function () use ($uid, $thrid, $pension, $OrderGzcRepository, $OrderMerchantRepository, $StoreOrderRepository) {
  1127. //新增入账明细记录
  1128. // $orderId = $OrderMerchantRepository->getNewOrderId('IN10');
  1129. // $create = [
  1130. // 'uid' => $uid,
  1131. // 'platform_no' => $orderId,
  1132. // 'user_name' => $certification['user_name'],
  1133. // 'mobile' => $certification['mobile'],
  1134. // 'user_card' => $certification['user_card'],
  1135. // 'pension' => $pension,
  1136. // 'order_type' => 7,
  1137. // 'out_trade_no' => $thrid['order_sn']
  1138. // ];
  1139. // $test_user = Db::name('user')->where('uid', $uid)->value('test_user');
  1140. // if ($test_user == 0) {
  1141. // $OrderGzcRepository->create($create);
  1142. // }
  1143. // $OrderGzcRepository->create($create);
  1144. Db::table('rrx_order_vip')
  1145. ->update(['gzc' => 1, 'order_vip_id' => $thrid['order_vip_id']]);
  1146. Db::name('user_bill')
  1147. ->where('order_sn', $thrid['order_sn'])
  1148. ->where('commission_type', 5)
  1149. ->update(['status'=> 1]);
  1150. // 养老金区域奖励
  1151. $order_data = [
  1152. 'pay_price' => $pension,
  1153. 'user_address_ids' => $thrid['user_address_ids'],
  1154. 'uid' => $thrid['uid'],
  1155. 'order_sn' => $thrid['order_sn']
  1156. ];
  1157. // $StoreOrderRepository->area_manage_details($order_data, 2, 2);
  1158. });
  1159. }
  1160. }
  1161. /**
  1162. * 第三方订单抖音IN10入账
  1163. * @param $nowTime
  1164. * @param $timeLimit
  1165. * author: php迷途小书童
  1166. * created: 2021/3/20 9:26
  1167. */
  1168. public function doThridDyOrderGzc($nowTime, $timeLimit)
  1169. {
  1170. $cursor = Db::table('rrx_order_dy')
  1171. ->where('gzc', 0)
  1172. ->where('bill_status', 1)
  1173. ->where('commission', '>', 0)
  1174. ->whereTime('bill_end_time', '<', $nowTime - bcmul((string)$timeLimit, (string)86400))
  1175. ->cursor();
  1176. $ProductRepository = app()->make(ProductRepository::class);
  1177. $OrderGzcRepository = app()->make(OrderGzcRepository::class);
  1178. $OrderMerchantRepository = app()->make(OrderMerchantRepository::class);
  1179. $StoreOrderRepository = app()->make(StoreOrderRepository::class);
  1180. foreach ($cursor as $thrid) {
  1181. $uid = $thrid['uid'];
  1182. if (!$uid)
  1183. continue;
  1184. // $certification = UserCertification::getInstance()->where('uid', $uid)->find();
  1185. // if (!$certification) {
  1186. // Log::info('用户ID' . $uid . '未实名认证');
  1187. // continue;
  1188. // }
  1189. $pension = $ProductRepository->yanglaojin(0, sprintf('%.2f', $thrid['commission']));
  1190. Db::transaction(function () use ($uid, $thrid, $pension, $OrderGzcRepository, $OrderMerchantRepository, $StoreOrderRepository) {
  1191. // //新增入账明细记录
  1192. // $orderId = $OrderMerchantRepository->getNewOrderId('IN10');
  1193. // $create = [
  1194. // 'uid' => $uid,
  1195. // 'platform_no' => $orderId,
  1196. // 'user_name' => $certification['user_name'],
  1197. // 'mobile' => $certification['mobile'],
  1198. // 'user_card' => $certification['user_card'],
  1199. // 'pension' => $pension,
  1200. // 'order_type' => 8,
  1201. // 'out_trade_no' => $thrid['order_sn']
  1202. // ];
  1203. // $test_user = Db::name('user')->where('uid', $uid)->value('test_user');
  1204. // if ($test_user == 0) {
  1205. // $OrderGzcRepository->create($create);
  1206. // }
  1207. Db::table('rrx_order_dy')
  1208. ->update(['gzc' => 1, 'order_dy_id' => $thrid['order_dy_id']]);
  1209. Db::name('user_bill')
  1210. ->where('order_sn', $thrid['order_sn'])
  1211. ->where('commission_type', 5)
  1212. ->update(['status'=> 1]);
  1213. // 养老金区域奖励
  1214. $order_data = [
  1215. 'pay_price' => $pension,
  1216. 'user_address_ids' => $thrid['user_address_ids'],
  1217. 'uid' => $thrid['uid'],
  1218. 'order_sn' => $thrid['order_sn']
  1219. ];
  1220. // $StoreOrderRepository->area_manage_details($order_data, 9, 2);
  1221. });
  1222. }
  1223. }
  1224. /**
  1225. * 志愿者升级
  1226. * */
  1227. public function doUpgrade()
  1228. {
  1229. set_time_limit(0);
  1230. try {
  1231. //志愿者条件
  1232. $volunteer_achievement = systemConfig("volunteer_achievement"); //volunteer_achievement:用户本人满足养老金要求可升级为志愿者
  1233. //一星条件
  1234. $a_volunteer_achievement = systemConfig("a_volunteer_achievement");//团队养老金要求
  1235. $a_volunteer_number = systemConfig("a_volunteer_number"); //团队人数要求
  1236. //二星条件
  1237. $b_volunteer_achievement = systemConfig("b_volunteer_achievement");//团队养老金要求
  1238. $b_volunteer_number = systemConfig("b_volunteer_number"); //团队人数要求
  1239. //三星条件
  1240. $c_volunteer_achievement = systemConfig("c_volunteer_achievement");//团队养老金要求
  1241. $c_volunteer_number = systemConfig("c_volunteer_number"); //团队人数要求
  1242. //董事条件
  1243. $d_volunteer_achievement = systemConfig("d_volunteer_achievement");//团队养老金要求
  1244. $d_volunteer_number = systemConfig("d_volunteer_number"); //团队人数要求
  1245. //用户列表
  1246. $userList = Db::name("User")
  1247. ->field("uid")
  1248. ->select();
  1249. foreach ($userList as $key => $value) {
  1250. $volunteer = $this->volunteer($value['uid']);
  1251. //本人养老金小于志愿者要求
  1252. if ($volunteer['self_yanglao'] < $volunteer_achievement) {
  1253. $this->grade($value['uid'], 0, $volunteer);
  1254. }
  1255. //满足志愿者要求
  1256. if ($volunteer['self_yanglao'] >= $volunteer_achievement) {
  1257. //志愿者
  1258. if ($volunteer['team'] < $a_volunteer_number || $volunteer['yanglao'] < $a_volunteer_achievement) {
  1259. $this->grade($value['uid'], 1, $volunteer);
  1260. }
  1261. //一星
  1262. if ($volunteer['team'] >= $a_volunteer_number && $volunteer['yanglao'] >= $a_volunteer_achievement//满足一星条件
  1263. &&
  1264. ($volunteer['team'] < $b_volunteer_number || $volunteer['yanglao'] < $b_volunteer_achievement)//未满足二星条件
  1265. ) {
  1266. $this->grade($value['uid'], 2, $volunteer);
  1267. }
  1268. //二星
  1269. if ($volunteer['team'] >= $b_volunteer_number && $volunteer['yanglao'] >= $b_volunteer_achievement//满足二星条件
  1270. &&
  1271. ($volunteer['team'] < $c_volunteer_number || $volunteer['yanglao'] < $c_volunteer_achievement)//未满足三星条件
  1272. ) {
  1273. $this->grade($value['uid'], 3, $volunteer);
  1274. }
  1275. //三星
  1276. if ($volunteer['team'] >= $c_volunteer_number && $volunteer['yanglao'] >= $c_volunteer_achievement//满足三星条件
  1277. &&
  1278. ($volunteer['team'] < $d_volunteer_number || $volunteer['yanglao'] < $d_volunteer_achievement)//未满足董事条件
  1279. ) {
  1280. $this->grade($value['uid'], 4, $volunteer);
  1281. }
  1282. //董事
  1283. if ($volunteer['team'] >= $d_volunteer_number && $volunteer['yanglao'] >= $d_volunteer_achievement) {
  1284. $this->grade($value['uid'], 5, $volunteer);
  1285. }
  1286. }
  1287. //团队各等级数量统计
  1288. $this->statistics($value['uid']);
  1289. }
  1290. } catch (Exception $e) {
  1291. Log::info('志愿者升级:' . $e->getMessage());
  1292. }
  1293. }
  1294. //志愿者信息
  1295. public function volunteer($uid)
  1296. {
  1297. if (!$uid) {
  1298. return false;
  1299. }
  1300. //本人养老金
  1301. $data['self_yanglao'] = $this->getYanglao($uid);
  1302. //团队人数
  1303. $data['team'] = $this->volunteer_number($uid);
  1304. //团队养老金
  1305. $data['yanglao'] = $this->volunteer_achievement($uid);
  1306. //直推人数
  1307. $data['extension'] = Db::name("user_identity_log")->where(["uid" => $uid])->count();
  1308. //直推商户数量
  1309. $data['shop'] = Db::name("user_identity_log")->where(["uid" => $uid, 'identity' => 4])->whereNotIn("identity", "0")->count();
  1310. return $data;
  1311. }
  1312. //团队人数
  1313. public function volunteer_number($uid)
  1314. {
  1315. $number = 0;
  1316. $number1 = Db::name("user_identity_log")->where(["uid" => $uid])->field("link_id")->select();
  1317. $number += count($number1);
  1318. foreach ($number1 as $key => $value) {
  1319. $number += Db::name("user_identity_log")->where(["uid" => $value['link_id']])->field("link_id")->count();
  1320. }
  1321. return $number;
  1322. }
  1323. //团队养老金
  1324. public function volunteer_achievement($uid)
  1325. {
  1326. $yanglao = 0;
  1327. $number1 = Db::name("user_identity_log")->where(["uid" => $uid])->field("link_id")->select();
  1328. foreach ($number1 as $key => $value) {
  1329. $yanglao += $this->getYanglao($value['link_id']);
  1330. $number2 = Db::name("user_identity_log")->where(["uid" => $value['link_id']])->field("link_id")->select();
  1331. foreach ($number2 as $k => $v) {
  1332. $yanglao += $this->getYanglao($v['link_id']);
  1333. }
  1334. unset($number2);
  1335. }
  1336. return $yanglao;
  1337. }
  1338. //用户养老金
  1339. public function getYanglao($uid)
  1340. {
  1341. return Db::name("UserBill")
  1342. ->where([
  1343. 'uid' => $uid,
  1344. 'commission_type' => 5,
  1345. 'status' => 1,
  1346. 'pm' => 1
  1347. ])
  1348. ->sum("number");
  1349. }
  1350. //升级
  1351. public function grade($uid, $grade, $volunteer)
  1352. {
  1353. $exist = Db::name("Volunteer")->where(["uid" => $uid])->find();
  1354. if ($exist) {
  1355. Db::name("Volunteer")
  1356. ->where(["uid" => $uid])
  1357. ->update([
  1358. "grade" => $grade,
  1359. "team" => $volunteer['team'],
  1360. "yanglao" => $volunteer['yanglao'],
  1361. "extension" => $volunteer['extension'],
  1362. "shop" => $volunteer['shop'],
  1363. "time" => time()
  1364. ]);
  1365. return true;
  1366. }
  1367. Db::name("Volunteer")
  1368. ->insert([
  1369. "uid" => $uid,
  1370. "grade" => $grade,
  1371. "team" => $volunteer['team'],
  1372. "yanglao" => $volunteer['yanglao'],
  1373. "extension" => $volunteer['extension'],
  1374. "shop" => $volunteer['shop'],
  1375. "time" => time()
  1376. ]
  1377. );
  1378. return true;
  1379. }
  1380. //下级各等级数量统计
  1381. public function statistics($uid)
  1382. {
  1383. $data = [
  1384. 'v' => 0,
  1385. 'v1' => 0,
  1386. 'v2' => 0,
  1387. 'v3' => 0,
  1388. 'v4' => 0
  1389. ];
  1390. $fns = function ($uid) use (&$fns, &$data) {
  1391. $identity = Db::name("user_identity_log")
  1392. ->alias("u")
  1393. ->join("Volunteer v", "u.link_id = v.uid")
  1394. ->where(["u.uid" => $uid])
  1395. ->field("u.link_id,v.grade")
  1396. ->select();
  1397. if ($identity) {
  1398. foreach ($identity as $key => $value) {
  1399. if ($value['grade'] == 1) {
  1400. $data['v']++;
  1401. }
  1402. if ($value['grade'] == 2) {
  1403. $data['v1']++;
  1404. }
  1405. if ($value['grade'] == 3) {
  1406. $data['v2']++;
  1407. }
  1408. if ($value['grade'] == 4) {
  1409. $data['v3']++;
  1410. }
  1411. if ($value['grade'] == 5) {
  1412. $data['v4']++;
  1413. }
  1414. $fns($value['link_id']);
  1415. }
  1416. }
  1417. };
  1418. $fns($uid);
  1419. Db::name("Volunteer")
  1420. ->where(["uid" => $uid])
  1421. ->update([
  1422. "v" => $data['v'],
  1423. "v1" => $data['v1'],
  1424. "v2" => $data['v2'],
  1425. "v3" => $data['v3'],
  1426. "v4" => $data['v4'],
  1427. "time" => time()
  1428. ]);
  1429. return $data;
  1430. }
  1431. }