PensionTasks.php 66 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504
  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. // 结算佣金
  717. $user_bill_list = Db::name('user_bill')
  718. ->where('status', 0)
  719. ->where('commission_type','<>', 5)
  720. ->where([ 'link_id' => $online['order_id'], 'order_sn' => $online['order_sn']])
  721. ->select()
  722. ->toArray();
  723. foreach ($user_bill_list as $user_bill) {
  724. if ($user_bill['commission_type'] != 5) {
  725. if (in_array($user_bill['commission_type'], [7,12,19])) {
  726. Db::name("merchant")
  727. ->where("mer_id", $user_bill['mer_id'])
  728. ->inc('brokerage_price', (float)$user_bill['number'])
  729. ->update();
  730. } else {
  731. Db::name('user')
  732. ->where('uid', $user_bill['uid'])
  733. ->inc('brokerage_price', (float)$user_bill['number'])
  734. ->update();
  735. }
  736. }
  737. if ($online['pay_type'] == 0 && $user_bill['commission_type'] == 5) {
  738. } else {
  739. // 虚拟支付的养老金不修改不结算
  740. Db::name('user_bill')
  741. ->where('status', 0)
  742. ->where('bill_id', $user_bill['bill_id'])
  743. ->update([
  744. 'status' => 1,
  745. 'take_time' => time()
  746. ]);
  747. }
  748. if ($online['pay_type'] == 0 && $user_bill['commission_type'] == 5) {
  749. } else {
  750. // 虚拟支付的养老金不修改不结算
  751. Db::name('user_bill')
  752. ->where('status', 0)
  753. ->where('bill_id', $user_bill['bill_id'])
  754. ->update([
  755. 'status' => 1,
  756. 'take_time' => time()
  757. ]);
  758. }
  759. }
  760. //按角色结算
  761. $StoreOrderRepository->close_order($online['order_id']);
  762. });
  763. }
  764. }
  765. /**
  766. * 第三方订单拼多多IN10入账
  767. * @param $nowTime
  768. * @param $timeLimit
  769. * author: php迷途小书童
  770. * created: 2021/3/20 9:26
  771. */
  772. public function doThridPddOrderGzc($nowTime, $timeLimit)
  773. {
  774. $cursor = Db::table('rrx_order_pdd')
  775. ->where('gzc', 0)
  776. ->where('bill_status', 1)
  777. ->where('commission', '>', 0)
  778. ->whereTime('bill_end_time', '<', $nowTime - bcmul((string)$timeLimit, (string)86400))
  779. ->cursor();
  780. $ProductRepository = app()->make(ProductRepository::class);
  781. $OrderGzcRepository = app()->make(OrderGzcRepository::class);
  782. $OrderMerchantRepository = app()->make(OrderMerchantRepository::class);
  783. $StoreOrderRepository = app()->make(StoreOrderRepository::class);
  784. foreach ($cursor as $thrid) {
  785. $uid = $thrid['uid'];
  786. if (!$uid)
  787. continue;
  788. // $certification = UserCertification::getInstance()->where('uid', $uid)->find();
  789. // if (!$certification) {
  790. // Log::info('用户ID' . $uid . '未实名认证');
  791. // continue;
  792. // }
  793. $pension = $ProductRepository->yanglaojin(0, sprintf('%.2f', $thrid['commission']));
  794. Db::transaction(function () use ($uid, $thrid, $pension, $OrderGzcRepository, $OrderMerchantRepository, $StoreOrderRepository) {
  795. //新增入账明细记录
  796. // $orderId = $OrderMerchantRepository->getNewOrderId('IN10');
  797. // $create = [
  798. // 'uid' => $uid,
  799. // 'platform_no' => $orderId,
  800. // 'user_name' => $certification['user_name'],
  801. // 'mobile' => $certification['mobile'],
  802. // 'user_card' => $certification['user_card'],
  803. // 'pension' => $pension,
  804. // 'order_type' => 3,
  805. // 'out_trade_no' => $thrid['order_sn']
  806. // ];
  807. // $test_user = Db::name('user')->where('uid', $uid)->value('test_user');
  808. // if ($test_user == 0) {
  809. // $OrderGzcRepository->create($create);
  810. // }
  811. // $OrderGzcRepository->create($create);
  812. Db::table('rrx_order_pdd')
  813. ->update(['gzc' => 1, 'order_pdd_id' => $thrid['order_pdd_id']]);
  814. Db::name('user_bill')
  815. ->where('order_sn', $thrid['order_sn'])
  816. ->where('commission_type', 5)
  817. ->update(['status'=> 1]);
  818. // 养老金区域奖励
  819. $order_data = [
  820. 'pay_price' => $pension,
  821. 'user_address_ids' => $thrid['user_address_ids'],
  822. 'uid' => $thrid['uid'],
  823. 'order_sn' => $thrid['order_sn']
  824. ];
  825. // $StoreOrderRepository->area_manage_details($order_data, 1, 2);
  826. });
  827. }
  828. }
  829. /**
  830. * 第三方订单京东IN10入账
  831. * @param $nowTime
  832. * @param $timeLimit
  833. * author: php迷途小书童
  834. * created: 2021/3/20 9:26
  835. */
  836. public function doThridJdOrderGzc($nowTime, $timeLimit)
  837. {
  838. $cursor = Db::table('rrx_order_jd')
  839. ->where('gzc', 0)
  840. ->where('bill_status', 1)
  841. ->where('commission', '>', 0)
  842. ->whereTime('bill_end_time', '<', $nowTime - bcmul((string)$timeLimit, (string)86400))
  843. ->cursor();
  844. // Db::name('log')->insert(['data'=>'abbbb入库语句'.$nowTime - bcmul((string)$timeLimit, (string)86400)]);
  845. // Db::name('log')->insert(['data'=>'abbbb'.json_encode($cursor)]);
  846. $ProductRepository = app()->make(ProductRepository::class);
  847. $OrderGzcRepository = app()->make(OrderGzcRepository::class);
  848. $OrderMerchantRepository = app()->make(OrderMerchantRepository::class);
  849. $StoreOrderRepository = app()->make(StoreOrderRepository::class);
  850. foreach ($cursor as $thrid) {
  851. $uid = $thrid['uid'];
  852. if (!$uid)
  853. continue;
  854. // $certification = UserCertification::getInstance()->where('uid', $uid)->find();
  855. // if (!$certification) {
  856. // Log::info('用户ID' . $uid . '未实名认证');
  857. // continue;
  858. // }
  859. $pension = $ProductRepository->yanglaojin(0, sprintf('%.2f', $thrid['commission']));
  860. Db::transaction(function () use ($uid, $thrid, $pension, $OrderGzcRepository, $OrderMerchantRepository, $StoreOrderRepository) {
  861. //新增入账明细记录
  862. // $orderId = $OrderMerchantRepository->getNewOrderId('IN10');
  863. // $create = [
  864. // 'uid' => $uid,
  865. // 'platform_no' => $orderId,
  866. // 'user_name' => $certification['user_name'],
  867. // 'mobile' => $certification['mobile'],
  868. // 'user_card' => $certification['user_card'],
  869. // 'pension' => $pension,
  870. // 'order_type' => 4,
  871. // 'out_trade_no' => $thrid['order_sn']
  872. // ];
  873. // $test_user = Db::name('user')->where('uid', $uid)->value('test_user');
  874. // if ($test_user == 0) {
  875. // $OrderGzcRepository->create($create);
  876. // }
  877. // $OrderGzcRepository->create($create);
  878. Db::table('rrx_order_jd')
  879. ->update(['gzc' => 1, 'order_jd_id' => $thrid['order_jd_id']]);
  880. Db::name('user_bill')
  881. ->where('order_sn', $thrid['order_sn'])
  882. ->where('commission_type', 5)
  883. ->update(['status'=> 1]);
  884. // 养老金区域奖励
  885. // $order_data = [
  886. // 'pay_price' => $pension,
  887. // 'user_address_ids' => $thrid['user_address_ids'],
  888. // 'uid' => $thrid['uid'],
  889. // 'order_sn' => $thrid['order_sn']
  890. // ];
  891. // $StoreOrderRepository->area_manage_details($order_data, 6, 2);
  892. });
  893. }
  894. }
  895. /**
  896. * 第三方订单苏宁IN10入账
  897. * @param $nowTime
  898. * @param $timeLimit
  899. * author: php迷途小书童
  900. * created: 2021/3/20 9:26
  901. */
  902. public function doThridSnOrderGzc($nowTime, $timeLimit)
  903. {
  904. $cursor = Db::table('rrx_order_su')
  905. ->where('gzc', 0)
  906. ->where('bill_status', 1)
  907. ->where('commission', '>', 0)
  908. ->whereTime('bill_end_time', '<', $nowTime - bcmul((string)$timeLimit, (string)86400))
  909. ->cursor();
  910. $ProductRepository = app()->make(ProductRepository::class);
  911. $OrderGzcRepository = app()->make(OrderGzcRepository::class);
  912. $OrderMerchantRepository = app()->make(OrderMerchantRepository::class);
  913. $StoreOrderRepository = app()->make(StoreOrderRepository::class);
  914. foreach ($cursor as $thrid) {
  915. $uid = $thrid['uid'];
  916. if (!$uid)
  917. continue;
  918. // $certification = UserCertification::getInstance()->where('uid', $uid)->find();
  919. // if (!$certification) {
  920. // Log::info('用户ID' . $uid . '未实名认证');
  921. // continue;
  922. // }
  923. $pension = $ProductRepository->yanglaojin(0, sprintf('%.2f', $thrid['commission']));
  924. Db::transaction(function () use ($uid, $thrid, $pension, $OrderGzcRepository, $OrderMerchantRepository, $StoreOrderRepository) {
  925. //新增入账明细记录
  926. // $orderId = $OrderMerchantRepository->getNewOrderId('IN10');
  927. // $create = [
  928. // 'uid' => $uid,
  929. // 'platform_no' => $orderId,
  930. // 'user_name' => $certification['user_name'],
  931. // 'mobile' => $certification['mobile'],
  932. // 'user_card' => $certification['user_card'],
  933. // 'pension' => $pension,
  934. // 'order_type' => 5,
  935. // 'out_trade_no' => $thrid['order_sn']
  936. // ];
  937. // $test_user = Db::name('user')->where('uid', $uid)->value('test_user');
  938. // if ($test_user == 0) {
  939. // $OrderGzcRepository->create($create);
  940. // }
  941. // $OrderGzcRepository->create($create);
  942. Db::table('rrx_order_su')
  943. ->update(['gzc' => 1, 'order_su_id' => $thrid['order_su_id']]);
  944. Db::name('user_bill')
  945. ->where('order_sn', $thrid['order_sn'])
  946. ->where('commission_type', 5)
  947. ->update(['status'=> 1]);
  948. // 养老金区域奖励
  949. $order_data = [
  950. 'pay_price' => $pension,
  951. 'user_address_ids' => $thrid['user_address_ids'],
  952. 'uid' => $thrid['uid'],
  953. 'order_sn' => $thrid['order_sn']
  954. ];
  955. // $StoreOrderRepository->area_manage_details($order_data, 3, 2);
  956. });
  957. }
  958. }
  959. /**
  960. * 第三方订单话费IN10入账
  961. * @param $nowTime
  962. * @param $timeLimit
  963. * author: php迷途小书童
  964. * created: 2021/3/20 9:26
  965. */
  966. public function doThridHfOrderGzc($nowTime, $timeLimit)
  967. {
  968. $cursor = Db::table('rrx_order_huafei')
  969. ->where('gzc', 0)
  970. ->where('bill_status', 1)
  971. ->where('commission', '>', 0)
  972. ->whereTime('bill_end_time', '<', $nowTime - bcmul((string)$timeLimit, (string)86400))
  973. ->cursor();
  974. $ProductRepository = app()->make(ProductRepository::class);
  975. $OrderGzcRepository = app()->make(OrderGzcRepository::class);
  976. $OrderMerchantRepository = app()->make(OrderMerchantRepository::class);
  977. foreach ($cursor as $thrid) {
  978. $uid = $thrid['uid'];
  979. if (!$uid)
  980. continue;
  981. // $certification = UserCertification::getInstance()->where('uid', $uid)->find();
  982. // if (!$certification) {
  983. // Log::info('用户ID' . $uid . '未实名认证');
  984. // continue;
  985. // }
  986. $pension = $ProductRepository->yanglaojin(0, sprintf('%.2f', $thrid['commission']));
  987. Db::transaction(function () use ($uid, $thrid, $pension, $OrderGzcRepository, $OrderMerchantRepository) {
  988. // //新增入账明细记录
  989. // $orderId = $OrderMerchantRepository->getNewOrderId('IN10');
  990. // $create = [
  991. // 'uid' => $uid,
  992. // 'platform_no' => $orderId,
  993. // 'user_name' => $certification['user_name'],
  994. // 'mobile' => $certification['mobile'],
  995. // 'user_card' => $certification['user_card'],
  996. // 'pension' => $pension,
  997. // 'order_type' => 6,
  998. // 'out_trade_no' => $thrid['order_sn']
  999. // ];
  1000. // $test_user = Db::name('user')->where('uid', $uid)->value('test_user');
  1001. // if ($test_user == 0) {
  1002. // $OrderGzcRepository->create($create);
  1003. // }
  1004. Db::table('rrx_order_huafei')->update(['gzc' => 1, 'order_tb_id' => $thrid['order_tb_id']]);
  1005. Db::name('user_bill')
  1006. ->where('order_sn', $thrid['order_sn'])
  1007. ->where('commission_type', 5)
  1008. ->update(['status'=> 1]);
  1009. });
  1010. }
  1011. }
  1012. /**
  1013. * 第三方订单淘宝IN10入账
  1014. * @param $nowTime
  1015. * @param $timeLimit
  1016. * author: php迷途小书童
  1017. * created: 2021/3/20 9:26
  1018. */
  1019. public function doThridTaobaoOrderGzc($nowTime, $timeLimit)
  1020. {
  1021. $cursor = Db::table('rrx_order_tb')
  1022. ->where('gzc', 0)
  1023. ->where('bill_status', 1)
  1024. ->where('commission', '>', 0)
  1025. ->whereTime('bill_end_time', '<', $nowTime - bcmul((string)$timeLimit, (string)86400))
  1026. ->cursor();
  1027. $ProductRepository = app()->make(ProductRepository::class);
  1028. $OrderGzcRepository = app()->make(OrderGzcRepository::class);
  1029. $OrderMerchantRepository = app()->make(OrderMerchantRepository::class);
  1030. $StoreOrderRepository = app()->make(StoreOrderRepository::class);
  1031. foreach ($cursor as $thrid) {
  1032. $uid = $thrid['uid'];
  1033. if (!$uid)
  1034. continue;
  1035. // $certification = UserCertification::getInstance()->where('uid', $uid)->find();
  1036. // if (!$certification) {
  1037. // Log::info('用户ID' . $uid . '未实名认证');
  1038. // continue;
  1039. // }
  1040. $pension = $ProductRepository->yanglaojin(0, sprintf('%.2f', $thrid['commission']));
  1041. Db::transaction(function () use ($uid, $thrid, $pension, $OrderGzcRepository, $OrderMerchantRepository, $StoreOrderRepository) {
  1042. //新增入账明细记录
  1043. // $orderId = $OrderMerchantRepository->getNewOrderId('IN10');
  1044. // $create = [
  1045. // 'uid' => $uid,
  1046. // 'platform_no' => $orderId,
  1047. // 'user_name' => $certification['user_name'],
  1048. // 'mobile' => $certification['mobile'],
  1049. // 'user_card' => $certification['user_card'],
  1050. // 'pension' => $pension,
  1051. // 'order_type' => 6,
  1052. // 'out_trade_no' => $thrid['order_sn']
  1053. // ];
  1054. // $test_user = Db::name('user')->where('uid', $uid)->value('test_user');
  1055. // if ($test_user == 0) {
  1056. // $OrderGzcRepository->create($create);
  1057. // }
  1058. // $OrderGzcRepository->create($create);
  1059. Db::table('rrx_order_tb')
  1060. ->update(['gzc' => 1, 'order_tb_id' => $thrid['order_tb_id']]);
  1061. Db::name('user_bill')
  1062. ->where('order_sn', $thrid['order_sn'])
  1063. ->where('commission_type', 5)
  1064. ->update(['status'=> 1]);
  1065. // 养老金区域奖励
  1066. $order_data = [
  1067. 'pay_price' => $pension,
  1068. 'user_address_ids' => $thrid['user_address_ids'],
  1069. 'uid' => $thrid['uid'],
  1070. 'order_sn' => $thrid['order_sn']
  1071. ];
  1072. // $StoreOrderRepository->area_manage_details($order_data, 5, 2);
  1073. });
  1074. }
  1075. }
  1076. /**
  1077. * 第三方订单唯品会IN10入账
  1078. * @param $nowTime
  1079. * @param $timeLimit
  1080. * author: php迷途小书童
  1081. * created: 2021/3/20 9:26
  1082. */
  1083. public function doThridVipOrderGzc($nowTime, $timeLimit)
  1084. {
  1085. $cursor = Db::table('rrx_order_vip')
  1086. ->where('gzc', 0)
  1087. ->where('bill_status', 1)
  1088. ->where('commission', '>', 0)
  1089. ->whereTime('bill_end_time', '<', $nowTime - bcmul((string)$timeLimit, (string)86400))
  1090. ->cursor();
  1091. $ProductRepository = app()->make(ProductRepository::class);
  1092. $OrderGzcRepository = app()->make(OrderGzcRepository::class);
  1093. $OrderMerchantRepository = app()->make(OrderMerchantRepository::class);
  1094. $StoreOrderRepository = app()->make(StoreOrderRepository::class);
  1095. foreach ($cursor as $thrid) {
  1096. $uid = $thrid['uid'];
  1097. if (!$uid)
  1098. continue;
  1099. // $certification = UserCertification::getInstance()->where('uid', $uid)->find();
  1100. // if (!$certification) {
  1101. // Log::info('用户ID' . $uid . '未实名认证');
  1102. // continue;
  1103. // }
  1104. $pension = $ProductRepository->yanglaojin(0, sprintf('%.2f', $thrid['commission']));
  1105. Db::transaction(function () use ($uid, $thrid, $pension, $OrderGzcRepository, $OrderMerchantRepository, $StoreOrderRepository) {
  1106. //新增入账明细记录
  1107. // $orderId = $OrderMerchantRepository->getNewOrderId('IN10');
  1108. // $create = [
  1109. // 'uid' => $uid,
  1110. // 'platform_no' => $orderId,
  1111. // 'user_name' => $certification['user_name'],
  1112. // 'mobile' => $certification['mobile'],
  1113. // 'user_card' => $certification['user_card'],
  1114. // 'pension' => $pension,
  1115. // 'order_type' => 7,
  1116. // 'out_trade_no' => $thrid['order_sn']
  1117. // ];
  1118. // $test_user = Db::name('user')->where('uid', $uid)->value('test_user');
  1119. // if ($test_user == 0) {
  1120. // $OrderGzcRepository->create($create);
  1121. // }
  1122. // $OrderGzcRepository->create($create);
  1123. Db::table('rrx_order_vip')
  1124. ->update(['gzc' => 1, 'order_vip_id' => $thrid['order_vip_id']]);
  1125. Db::name('user_bill')
  1126. ->where('order_sn', $thrid['order_sn'])
  1127. ->where('commission_type', 5)
  1128. ->update(['status'=> 1]);
  1129. // 养老金区域奖励
  1130. $order_data = [
  1131. 'pay_price' => $pension,
  1132. 'user_address_ids' => $thrid['user_address_ids'],
  1133. 'uid' => $thrid['uid'],
  1134. 'order_sn' => $thrid['order_sn']
  1135. ];
  1136. // $StoreOrderRepository->area_manage_details($order_data, 2, 2);
  1137. });
  1138. }
  1139. }
  1140. /**
  1141. * 第三方订单抖音IN10入账
  1142. * @param $nowTime
  1143. * @param $timeLimit
  1144. * author: php迷途小书童
  1145. * created: 2021/3/20 9:26
  1146. */
  1147. public function doThridDyOrderGzc($nowTime, $timeLimit)
  1148. {
  1149. $cursor = Db::table('rrx_order_dy')
  1150. ->where('gzc', 0)
  1151. ->where('bill_status', 1)
  1152. ->where('commission', '>', 0)
  1153. ->whereTime('bill_end_time', '<', $nowTime - bcmul((string)$timeLimit, (string)86400))
  1154. ->cursor();
  1155. $ProductRepository = app()->make(ProductRepository::class);
  1156. $OrderGzcRepository = app()->make(OrderGzcRepository::class);
  1157. $OrderMerchantRepository = app()->make(OrderMerchantRepository::class);
  1158. $StoreOrderRepository = app()->make(StoreOrderRepository::class);
  1159. foreach ($cursor as $thrid) {
  1160. $uid = $thrid['uid'];
  1161. if (!$uid)
  1162. continue;
  1163. // $certification = UserCertification::getInstance()->where('uid', $uid)->find();
  1164. // if (!$certification) {
  1165. // Log::info('用户ID' . $uid . '未实名认证');
  1166. // continue;
  1167. // }
  1168. $pension = $ProductRepository->yanglaojin(0, sprintf('%.2f', $thrid['commission']));
  1169. Db::transaction(function () use ($uid, $thrid, $pension, $OrderGzcRepository, $OrderMerchantRepository, $StoreOrderRepository) {
  1170. // //新增入账明细记录
  1171. // $orderId = $OrderMerchantRepository->getNewOrderId('IN10');
  1172. // $create = [
  1173. // 'uid' => $uid,
  1174. // 'platform_no' => $orderId,
  1175. // 'user_name' => $certification['user_name'],
  1176. // 'mobile' => $certification['mobile'],
  1177. // 'user_card' => $certification['user_card'],
  1178. // 'pension' => $pension,
  1179. // 'order_type' => 8,
  1180. // 'out_trade_no' => $thrid['order_sn']
  1181. // ];
  1182. // $test_user = Db::name('user')->where('uid', $uid)->value('test_user');
  1183. // if ($test_user == 0) {
  1184. // $OrderGzcRepository->create($create);
  1185. // }
  1186. Db::table('rrx_order_dy')
  1187. ->update(['gzc' => 1, 'order_dy_id' => $thrid['order_dy_id']]);
  1188. Db::name('user_bill')
  1189. ->where('order_sn', $thrid['order_sn'])
  1190. ->where('commission_type', 5)
  1191. ->update(['status'=> 1]);
  1192. // 养老金区域奖励
  1193. $order_data = [
  1194. 'pay_price' => $pension,
  1195. 'user_address_ids' => $thrid['user_address_ids'],
  1196. 'uid' => $thrid['uid'],
  1197. 'order_sn' => $thrid['order_sn']
  1198. ];
  1199. // $StoreOrderRepository->area_manage_details($order_data, 9, 2);
  1200. });
  1201. }
  1202. }
  1203. /**
  1204. * 志愿者升级
  1205. * */
  1206. public function doUpgrade()
  1207. {
  1208. set_time_limit(0);
  1209. try {
  1210. //志愿者条件
  1211. $volunteer_achievement = systemConfig("volunteer_achievement"); //volunteer_achievement:用户本人满足养老金要求可升级为志愿者
  1212. //一星条件
  1213. $a_volunteer_achievement = systemConfig("a_volunteer_achievement");//团队养老金要求
  1214. $a_volunteer_number = systemConfig("a_volunteer_number"); //团队人数要求
  1215. //二星条件
  1216. $b_volunteer_achievement = systemConfig("b_volunteer_achievement");//团队养老金要求
  1217. $b_volunteer_number = systemConfig("b_volunteer_number"); //团队人数要求
  1218. //三星条件
  1219. $c_volunteer_achievement = systemConfig("c_volunteer_achievement");//团队养老金要求
  1220. $c_volunteer_number = systemConfig("c_volunteer_number"); //团队人数要求
  1221. //董事条件
  1222. $d_volunteer_achievement = systemConfig("d_volunteer_achievement");//团队养老金要求
  1223. $d_volunteer_number = systemConfig("d_volunteer_number"); //团队人数要求
  1224. //用户列表
  1225. $userList = Db::name("User")
  1226. ->field("uid")
  1227. ->select();
  1228. foreach ($userList as $key => $value) {
  1229. $volunteer = $this->volunteer($value['uid']);
  1230. //本人养老金小于志愿者要求
  1231. if ($volunteer['self_yanglao'] < $volunteer_achievement) {
  1232. $this->grade($value['uid'], 0, $volunteer);
  1233. }
  1234. //满足志愿者要求
  1235. if ($volunteer['self_yanglao'] >= $volunteer_achievement) {
  1236. //志愿者
  1237. if ($volunteer['team'] < $a_volunteer_number || $volunteer['yanglao'] < $a_volunteer_achievement) {
  1238. $this->grade($value['uid'], 1, $volunteer);
  1239. }
  1240. //一星
  1241. if ($volunteer['team'] >= $a_volunteer_number && $volunteer['yanglao'] >= $a_volunteer_achievement//满足一星条件
  1242. &&
  1243. ($volunteer['team'] < $b_volunteer_number || $volunteer['yanglao'] < $b_volunteer_achievement)//未满足二星条件
  1244. ) {
  1245. $this->grade($value['uid'], 2, $volunteer);
  1246. }
  1247. //二星
  1248. if ($volunteer['team'] >= $b_volunteer_number && $volunteer['yanglao'] >= $b_volunteer_achievement//满足二星条件
  1249. &&
  1250. ($volunteer['team'] < $c_volunteer_number || $volunteer['yanglao'] < $c_volunteer_achievement)//未满足三星条件
  1251. ) {
  1252. $this->grade($value['uid'], 3, $volunteer);
  1253. }
  1254. //三星
  1255. if ($volunteer['team'] >= $c_volunteer_number && $volunteer['yanglao'] >= $c_volunteer_achievement//满足三星条件
  1256. &&
  1257. ($volunteer['team'] < $d_volunteer_number || $volunteer['yanglao'] < $d_volunteer_achievement)//未满足董事条件
  1258. ) {
  1259. $this->grade($value['uid'], 4, $volunteer);
  1260. }
  1261. //董事
  1262. if ($volunteer['team'] >= $d_volunteer_number && $volunteer['yanglao'] >= $d_volunteer_achievement) {
  1263. $this->grade($value['uid'], 5, $volunteer);
  1264. }
  1265. }
  1266. //团队各等级数量统计
  1267. $this->statistics($value['uid']);
  1268. }
  1269. } catch (Exception $e) {
  1270. Log::info('志愿者升级:' . $e->getMessage());
  1271. }
  1272. }
  1273. //志愿者信息
  1274. public function volunteer($uid)
  1275. {
  1276. if (!$uid) {
  1277. return false;
  1278. }
  1279. //本人养老金
  1280. $data['self_yanglao'] = $this->getYanglao($uid);
  1281. //团队人数
  1282. $data['team'] = $this->volunteer_number($uid);
  1283. //团队养老金
  1284. $data['yanglao'] = $this->volunteer_achievement($uid);
  1285. //直推人数
  1286. $data['extension'] = Db::name("user_identity_log")->where(["uid" => $uid])->count();
  1287. //直推商户数量
  1288. $data['shop'] = Db::name("user_identity_log")->where(["uid" => $uid, 'identity' => 4])->whereNotIn("identity", "0")->count();
  1289. return $data;
  1290. }
  1291. //团队人数
  1292. public function volunteer_number($uid)
  1293. {
  1294. $number = 0;
  1295. $number1 = Db::name("user_identity_log")->where(["uid" => $uid])->field("link_id")->select();
  1296. $number += count($number1);
  1297. foreach ($number1 as $key => $value) {
  1298. $number += Db::name("user_identity_log")->where(["uid" => $value['link_id']])->field("link_id")->count();
  1299. }
  1300. return $number;
  1301. }
  1302. //团队养老金
  1303. public function volunteer_achievement($uid)
  1304. {
  1305. $yanglao = 0;
  1306. $number1 = Db::name("user_identity_log")->where(["uid" => $uid])->field("link_id")->select();
  1307. foreach ($number1 as $key => $value) {
  1308. $yanglao += $this->getYanglao($value['link_id']);
  1309. $number2 = Db::name("user_identity_log")->where(["uid" => $value['link_id']])->field("link_id")->select();
  1310. foreach ($number2 as $k => $v) {
  1311. $yanglao += $this->getYanglao($v['link_id']);
  1312. }
  1313. unset($number2);
  1314. }
  1315. return $yanglao;
  1316. }
  1317. //用户养老金
  1318. public function getYanglao($uid)
  1319. {
  1320. return Db::name("UserBill")
  1321. ->where([
  1322. 'uid' => $uid,
  1323. 'commission_type' => 5,
  1324. 'status' => 1,
  1325. 'pm' => 1
  1326. ])
  1327. ->sum("number");
  1328. }
  1329. //升级
  1330. public function grade($uid, $grade, $volunteer)
  1331. {
  1332. $exist = Db::name("Volunteer")->where(["uid" => $uid])->find();
  1333. if ($exist) {
  1334. Db::name("Volunteer")
  1335. ->where(["uid" => $uid])
  1336. ->update([
  1337. "grade" => $grade,
  1338. "team" => $volunteer['team'],
  1339. "yanglao" => $volunteer['yanglao'],
  1340. "extension" => $volunteer['extension'],
  1341. "shop" => $volunteer['shop'],
  1342. "time" => time()
  1343. ]);
  1344. return true;
  1345. }
  1346. Db::name("Volunteer")
  1347. ->insert([
  1348. "uid" => $uid,
  1349. "grade" => $grade,
  1350. "team" => $volunteer['team'],
  1351. "yanglao" => $volunteer['yanglao'],
  1352. "extension" => $volunteer['extension'],
  1353. "shop" => $volunteer['shop'],
  1354. "time" => time()
  1355. ]
  1356. );
  1357. return true;
  1358. }
  1359. //下级各等级数量统计
  1360. public function statistics($uid)
  1361. {
  1362. $data = [
  1363. 'v' => 0,
  1364. 'v1' => 0,
  1365. 'v2' => 0,
  1366. 'v3' => 0,
  1367. 'v4' => 0
  1368. ];
  1369. $fns = function ($uid) use (&$fns, &$data) {
  1370. $identity = Db::name("user_identity_log")
  1371. ->alias("u")
  1372. ->join("Volunteer v", "u.link_id = v.uid")
  1373. ->where(["u.uid" => $uid])
  1374. ->field("u.link_id,v.grade")
  1375. ->select();
  1376. if ($identity) {
  1377. foreach ($identity as $key => $value) {
  1378. if ($value['grade'] == 1) {
  1379. $data['v']++;
  1380. }
  1381. if ($value['grade'] == 2) {
  1382. $data['v1']++;
  1383. }
  1384. if ($value['grade'] == 3) {
  1385. $data['v2']++;
  1386. }
  1387. if ($value['grade'] == 4) {
  1388. $data['v3']++;
  1389. }
  1390. if ($value['grade'] == 5) {
  1391. $data['v4']++;
  1392. }
  1393. $fns($value['link_id']);
  1394. }
  1395. }
  1396. };
  1397. $fns($uid);
  1398. Db::name("Volunteer")
  1399. ->where(["uid" => $uid])
  1400. ->update([
  1401. "v" => $data['v'],
  1402. "v1" => $data['v1'],
  1403. "v2" => $data['v2'],
  1404. "v3" => $data['v3'],
  1405. "v4" => $data['v4'],
  1406. "time" => time()
  1407. ]);
  1408. return $data;
  1409. }
  1410. }