PensionTasks.php 83 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927
  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. // $this->doOnlineOrderGzc($timeLimit = 30);
  46. // $this->doOnlineHuuafeiOrderGzc($timeLimit = 30);
  47. $this->onlineOrderNew($timeLimit = 30);
  48. $this->huafeiOrderNew($timeLimit = 30);
  49. $this->pddOrderNew($timeLimit = 30);
  50. $this->jdOrderNew($timeLimit = 30);
  51. $this->suOrderNew($timeLimit = 30);
  52. $this->taobaoOrderNew($timeLimit = 30);
  53. $this->vipOrderNew($timeLimit = 30);
  54. $this->dyOrderNew($timeLimit = 30);
  55. // $this->doThridPddOrderGzc($nowTime, $timeLimit = 30);
  56. // $this->doThridJdOrderGzc($nowTime, $timeLimit = 30);
  57. // $this->doThridSnOrderGzc($nowTime, $timeLimit = 30);
  58. // $this->doThridTaobaoOrderGzc($nowTime, $timeLimit = 30);
  59. // $this->doThridVipOrderGzc($nowTime, $timeLimit = 30);
  60. // $this->doThridDyOrderGzc($nowTime, $timeLimit = 30);
  61. // $this->doThridHfOrderGzc($nowTime, $timeLimit = 30);
  62. $this->billGzcAdd($nowTime);
  63. //升级
  64. // $this -> doUpgrade();
  65. } catch (\Throwable $e) {
  66. Log::info('公证处入账:' . $e->getFile() . ':' . $e->getLine() . '【' . $e->getMessage() . '】');
  67. var_dump('公证处入账:' . $e->getFile() . ':' . $e->getLine() . '【' . $e->getMessage() . '】');
  68. }
  69. // 指令输出
  70. $output->writeln('pensiontask');
  71. }
  72. /**
  73. * 线下支付订单公证处IN10入账
  74. * @param $nowTime
  75. * author: php迷途小书童
  76. * created: 2021/3/20 9:26
  77. */
  78. public function billGzcAdd($nowTime)
  79. {
  80. $OrderGzcRepository = app()->make(OrderGzcRepository::class);
  81. $OrderMerchantRepository = app()->make(OrderMerchantRepository::class);
  82. $StoreOrderRepository = app()->make(StoreOrderRepository::class);
  83. $cursor = Db::name('user_bill')
  84. ->where('status', 1)
  85. ->where('is_gzc', 0)
  86. ->where('commission_type', 5)
  87. ->select()->toArray();
  88. if($cursor) {
  89. foreach ($cursor as $bill) {
  90. $type_shop = $bill['type_shop'] ?? 0;
  91. switch ($type_shop){
  92. case "0":
  93. $online = $cursor = Db::table('rrx_store_order')->where('uid', $bill['uid'])->where('order_sn', $bill['order_sn'])->where('paid', 1)->find();
  94. break;
  95. case "1":
  96. $online = Db::table('rrx_order_pdd')->where('uid', $bill['uid'])->where('order_sn', $bill['order_sn'])->find();
  97. break;
  98. case "2":
  99. $online = Db::table('rrx_order_vip')->where('uid', $bill['uid'])->where('order_sn', $bill['order_sn'])->find();
  100. break;
  101. case "3":
  102. $online = Db::table('rrx_order_su')->where('uid', $bill['uid'])->where('order_sn', $bill['order_sn'])->find();
  103. break;
  104. case "4":
  105. $online = '';
  106. break;
  107. case "5":
  108. $online = Db::table('rrx_order_tb')->where('uid', $bill['uid'])->where('order_sn', $bill['order_sn'])->find();
  109. break;
  110. case "6":
  111. $online = Db::table('rrx_order_jd')->where('uid', $bill['uid'])->where('order_sn', $bill['order_sn'])->find();
  112. break;
  113. case "7":
  114. $online = '';
  115. break;
  116. case "8":
  117. $online = '';
  118. break;
  119. case "9":
  120. $online = Db::table('rrx_order_huafei')->where('uid', $bill['uid'])->where('order_sn', $bill['order_sn'])->find();
  121. break;
  122. default:
  123. $online = Db::table('rrx_store_order')->where('uid', $bill['uid'])->where('order_sn', $bill['order_sn'])->where('paid', 1)->find();
  124. }
  125. if (!$online) {
  126. Log::info($bill['uid'] . '查询不到订单');
  127. continue;
  128. }
  129. $certification = UserCertification::getInstance()->where('uid', $bill['uid'])->find();
  130. if (!$certification) {
  131. Log::info($online['uid'] . '没有实名认证');
  132. continue;
  133. }
  134. $pension = $bill['number'] ?? 0;
  135. if ($pension <= 0) {
  136. Log::info($online['order_sn'] . 'pension' . $pension);
  137. continue;
  138. }
  139. //新增入账明细记录
  140. $orderId = $OrderMerchantRepository->getNewOrderId('IN10');
  141. $create = [
  142. 'uid' => $online['uid'],
  143. 'platform_no' => $orderId,
  144. 'account_type' => 1,
  145. 'user_name' => $certification['user_name'],
  146. 'mobile' => $certification['mobile'],
  147. 'user_card' => $certification['user_card'],
  148. 'pension' => $pension,
  149. 'order_type' => $type_shop,
  150. 'out_trade_no' => $online['order_sn'],
  151. 'link_id'=> $bill['bill_id']
  152. ];
  153. $test_user = Db::name('user')->where('uid', $online['uid'])->value('test_user');
  154. $check = Db::name("gzc_logs")->where("link_id", $bill['bill_id'])->where("order_type", $type_shop)->count();
  155. if ($test_user == 0 && $check <= 0) {
  156. $OrderGzcRepository->create($create);
  157. Db::name('user_bill')
  158. ->where('bill_id', $bill['bill_id'])
  159. ->where('commission_type', 5)
  160. ->update([
  161. 'is_gzc' => 1,
  162. 'gzc' => 1
  163. ]);
  164. }
  165. }
  166. }
  167. }
  168. /**
  169. * 线下支付订单公证处IN10入账
  170. * @param $nowTime
  171. * @param $timeLimit
  172. * author: php迷途小书童
  173. * created: 2021/3/20 9:26
  174. */
  175. public function doOfflineOrderGzc($nowTime, $timeLimit)
  176. {
  177. $cursor = Db::table('rrx_order_merchant')
  178. ->whereNotNull('pay_time')
  179. ->where('paid', 1)
  180. ->where('gzc', 0)
  181. ->whereTime('pay_time', '<', $nowTime - bcmul((string)$timeLimit, (string)86400))
  182. ->cursor();
  183. $OrderGzcRepository = app()->make(OrderGzcRepository::class);
  184. $OrderMerchantRepository = app()->make(OrderMerchantRepository::class);
  185. $StoreOrderRepository = app()->make(StoreOrderRepository::class);
  186. foreach ($cursor as $offline) {
  187. if ($offline['mer_id'] == 496) {
  188. continue;
  189. }
  190. $uid = 0;
  191. switch ($offline['trade_type']) {
  192. case 'WX':
  193. $uid = User::getInstance()->where('wechat_user_id', $offline['pay_user_id'])->value('uid');
  194. $accountType = 3;
  195. break;
  196. case 'ALI':
  197. $uid = User::getInstance()->where('ali_user_id', $offline['pay_user_id'])->value('uid');
  198. $accountType = 2;
  199. break;
  200. default:
  201. break;
  202. }
  203. if (!$uid) {
  204. Log::info($offline['pay_user_id'] . '未绑定用户');
  205. continue;
  206. }
  207. // $certification = UserCertification::getInstance()->where('uid', $uid)->find();
  208. // if (!$certification) {
  209. // Log::info($offline['pay_user_id'] . '未实名认证');
  210. // continue;
  211. // }
  212. //查询养老金金额
  213. $UserBillRepository = app()->make(UserBillRepository::class);
  214. $bill = $UserBillRepository->getWhere(['uid' => $uid, 'link_id' => $offline['id'], 'order_sn' => $offline['out_trade_no'], 'title' => '养老金']);
  215. $pension = $bill->number ?? 0;
  216. // if ($pension <= 0) {
  217. // Log::info($offline['out_trade_no'] . 'pension' . $pension);
  218. // continue;
  219. // }
  220. // Db::transaction(function () use ($uid, $certification, $accountType, $offline, $OrderGzcRepository, $OrderMerchantRepository, $pension, $StoreOrderRepository) {
  221. Db::transaction(function () use ($uid, $accountType, $offline, $OrderGzcRepository, $OrderMerchantRepository, $pension, $StoreOrderRepository) {
  222. $order = OrderMerchant::getInstance()->find($offline['id']);
  223. $order->gzc = 1;
  224. $order->is_settlement = 1;
  225. $order->settlement_time = date('Y-m-d H:i:s');
  226. $order->save();
  227. //新增入账明细记录
  228. // $orderId = $OrderMerchantRepository->getNewOrderId('IN10');
  229. // $create = [
  230. // 'uid' => $uid,
  231. // 'platform_no' => $orderId,
  232. // 'account_type' => $accountType,
  233. // 'user_name' => $certification['user_name'],
  234. // 'mobile' => $certification['mobile'],
  235. // 'user_card' => $certification['user_card'],
  236. // 'pension' => $pension,
  237. // 'order_type' => 1,
  238. // 'out_trade_no' => $offline['out_trade_no']
  239. // ];
  240. // $test_user = Db::name('user')->where('uid', $uid)->value('test_user');
  241. // if ($test_user == 0) {
  242. // $OrderGzcRepository->create($create);
  243. // }
  244. // // 养老金区域奖励
  245. // $order_data = [
  246. // 'pay_price' => $pension,
  247. // 'user_address_ids' => $offline['user_address_ids'],
  248. // 'uid' => $offline['uid'],
  249. // 'order_sn' => $offline['out_trade_no']
  250. // ];
  251. // $StoreOrderRepository->area_manage_details($order_data, 0, 2);
  252. // 结算红包
  253. // $user_sign_hongbao_list = Db::name('user_sign_hongbao')
  254. // ->where('status', -1)
  255. // ->where('order_id', $offline['id'])
  256. // ->whereIn('type', [1, 2])
  257. // ->select()
  258. // ->toArray();
  259. // foreach ($user_sign_hongbao_list as $user_sign_hongbao) {
  260. // if($user_sign_hongbao['uid']){
  261. // // 修改红包
  262. // Db::name('user')
  263. // ->where('uid', $user_sign_hongbao['uid'])
  264. // ->inc('hongbao', (float)$user_sign_hongbao['number'])
  265. // ->update();
  266. // Db::name('user_sign_hongbao')
  267. // ->where('status', -1)
  268. // ->where('id', $user_sign_hongbao['id'])
  269. // ->update([
  270. // 'status' => 1,
  271. // 'settlement_time' => date('Y-m-d H:i:s')
  272. // ]);
  273. // }
  274. // }
  275. // // 结算积分
  276. // $user_sign_score_list = Db::name('user_sign_score')
  277. // ->where('status', -1)
  278. // ->where('order_id', $offline['id'])
  279. // ->whereIn('type', [1, 2])
  280. // ->select()
  281. // ->toArray();
  282. // foreach ($user_sign_score_list as $user_sign_score) {
  283. // if($user_sign_score['uid']){
  284. // // 修改积分
  285. // Db::name('user')
  286. // ->where('uid', $user_sign_score['uid'])
  287. // ->inc('score', (float)$user_sign_score['reward_socre'])
  288. // ->update();
  289. // Db::name('user_sign_score')
  290. // ->where('status', -1)
  291. // ->where('id', $user_sign_score['id'])
  292. // ->update([
  293. // 'status' => 1,
  294. // 'settlement_time' => date('Y-m-d H:i:s')
  295. // ]);
  296. // }
  297. // }
  298. // // 结算贡献值
  299. // $user_sign_gongxian_list = Db::name('user_sign_gongxian')
  300. // ->where('status', -1)
  301. // ->where('order_id', $offline['id'])
  302. // ->whereIn('type', [1, 2])
  303. // ->select()
  304. // ->toArray();
  305. // foreach ($user_sign_gongxian_list as $user_sign_gongxian) {
  306. // if($user_sign_gongxian['uid']){
  307. // // 修改贡献值
  308. // Db::name('user')
  309. // ->where('uid', $user_sign_gongxian['uid'])
  310. // ->inc('contribute', (float)$user_sign_gongxian['number'])
  311. // ->update();
  312. // Db::name('user_sign_gongxian')
  313. // ->where('status', -1)
  314. // ->where('id', $user_sign_gongxian['id'])
  315. // ->update([
  316. // 'status' => 1,
  317. // 'settlement_time' => date('Y-m-d H:i:s')
  318. // ]);
  319. // }
  320. // }
  321. // // 结算佣金
  322. // $user_bill_list = Db::name('user_bill')
  323. // ->where('status', 0)
  324. // ->where('commission_type','<>', 5)
  325. // ->where([ 'link_id' => $offline['id'], 'order_sn' => $offline['order_sn']])
  326. // ->select()
  327. // ->toArray();
  328. // foreach ($user_bill_list as $user_bill) {
  329. // if($user_bill['uid']){
  330. // if ($user_bill['commission_type'] != 5) {
  331. // if (in_array($user_bill['commission_type'], [7,12,19])) {
  332. // Db::name("merchant")
  333. // ->where("mer_id", $user_bill['mer_id'])
  334. // ->inc('brokerage_price', (float)$user_bill['number'])
  335. // ->update();
  336. // } else {
  337. // Db::name('user')
  338. // ->where('uid', $user_bill['uid'])
  339. // ->inc('brokerage_price', (float)$user_bill['number'])
  340. // ->update();
  341. // }
  342. // }
  343. // }
  344. // }
  345. });
  346. }
  347. }
  348. /**
  349. * 话费支付订单公证处IN10入账
  350. * @param $nowTime
  351. * @param $timeLimit
  352. * author: php迷途小书童
  353. * created: 2021/3/20 9:26
  354. */
  355. public function doOnlineHuuafeiOrderGzc($timeLimit)
  356. {
  357. // 普通订单
  358. $cursor = Db::table('rrx_order_huafei')->where('status', 3)->where('gzc', 0)->cursor();
  359. $StoreOrderStatusRepository = app()->make(StoreOrderStatusRepository::class);
  360. $OrderMerchantRepository = app()->make(OrderMerchantRepository::class);
  361. $OrderGzcRepository = app()->make(OrderGzcRepository::class);
  362. foreach ($cursor as $online) {
  363. if (time() < strtotime($online['finish_time']) + 3600 * 24) {
  364. Log::info('还没有话费到账后' . $timeLimit . '天');
  365. continue;
  366. }
  367. $certification = UserCertification::getInstance()->where('uid', $online['uid'])->find();
  368. if (!$certification) {
  369. Log::info($online['uid'] . '没有实名认证');
  370. continue;
  371. }
  372. //查询养老金金额
  373. $UserBillRepository = app()->make(UserBillRepository::class);
  374. $bill = $UserBillRepository->getWhere(['uid' => $online['uid'], 'order_sn' => $online['order_sn'], 'commission_type' => 5]);
  375. $pension = $bill->number ?? 0;
  376. if ($pension <= 0) {
  377. Log::info($online['order_sn'] . 'pension' . $pension);
  378. continue;
  379. }
  380. //首信易分账
  381. // $StoreOrderRepository = app()->make(StoreOrderRepository::class);
  382. // if ($online['pay_type'] > 0) {
  383. // $StoreOrderRepository->splitOrder($online);
  384. // }
  385. $StoreOrderRepository = [];
  386. Db::transaction(function () use ($certification, $online, $pension, $OrderGzcRepository, $OrderMerchantRepository, $StoreOrderRepository) {
  387. //新增入账明细记录
  388. $orderId = $OrderMerchantRepository->getNewOrderId('IN10');
  389. $create = [
  390. 'uid' => $online['uid'],
  391. 'platform_no' => $orderId,
  392. 'account_type' => 3,//账号类型1银行卡2支付宝3微信
  393. 'user_name' => $certification['user_name'],
  394. 'mobile' => $certification['mobile'],
  395. 'user_card' => $certification['user_card'],
  396. 'pension' => $pension,
  397. 'order_type' => 2,
  398. 'out_trade_no' => $online['order_sn']
  399. ];
  400. $test_user = Db::name('user')->where('uid', $online['uid'])->value('test_user');
  401. $check = Db::name("gzc_logs")->where("out_trade_no", $online['order_sn'])->where("order_type", 2)->count();
  402. if ($test_user == 0 && $check <= 0) {
  403. $OrderGzcRepository->create($create);
  404. }
  405. $order = StoreOrder::getInstance()->find($online['order_id']);
  406. $order->gzc = 1;
  407. $order->save();
  408. });
  409. }
  410. // 普通订单(红包,积分,京东,佣金,复购金,养老金,贡献值)
  411. $cursor = Db::table('rrx_order_huafei')->where('status', 3)->where('bill_status', 0)->cursor();
  412. $StoreOrderStatusRepository = app()->make(StoreOrderStatusRepository::class);
  413. $OrderMerchantRepository = app()->make(OrderMerchantRepository::class);
  414. $OrderGzcRepository = app()->make(OrderGzcRepository::class);
  415. foreach ($cursor as $online) {
  416. if (time() < strtotime($online['finish_time']) + 3600 * 24) {
  417. Log::info('还没有话费到账后' . $timeLimit . '天');
  418. continue;
  419. }
  420. Db::transaction(function () use ($online) {
  421. //订单状态改为已结算
  422. Db::name('rrx_order_huafei')
  423. ->where('status', 3)->where('bill_status', 0)
  424. ->where('order_sn', $online['order_sn'])
  425. ->update([
  426. 'bill_status'=> 1,
  427. 'bill_create_time' => time()
  428. ]);
  429. // 结算积分
  430. $user_sign_score_list = Db::name('user_sign_score')
  431. ->where('status', -1)
  432. ->where('order_id', $online['order_sn'])
  433. ->whereIn('type', [1, 2])
  434. ->select()
  435. ->toArray();
  436. foreach ($user_sign_score_list as $user_sign_score) {
  437. // 修改积分
  438. Db::name('user')
  439. ->where('uid', $user_sign_score['uid'])
  440. ->inc('score', (float)$user_sign_score['reward_socre'])
  441. ->update();
  442. Db::name('user_sign_score')
  443. ->where('status', -1)
  444. ->where('id', $user_sign_score['id'])
  445. ->update([
  446. 'status' => 1,
  447. 'settlement_time' => date('Y-m-d H:i:s')
  448. ]);
  449. }
  450. // 结算复购金
  451. $user_sign_fugou_list = Db::name('user_sign_fugou')
  452. ->where('status', -1)
  453. ->where('order_id', $online['order_sn'])
  454. ->whereIn('type', [1, 2])
  455. ->select()
  456. ->toArray();
  457. foreach ($user_sign_fugou_list as $user_sign_fugou) {
  458. // 修改复购金
  459. Db::name('user')
  460. ->where('uid', $user_sign_fugou['uid'])
  461. ->inc('fugou', (float)$user_sign_fugou['number'])
  462. ->update();
  463. Db::name('user_sign_fugou')
  464. ->where('status', -1)
  465. ->where('id', $user_sign_fugou['id'])
  466. ->update([
  467. 'status' => 1,
  468. 'settlement_time' => date('Y-m-d H:i:s')
  469. ]);
  470. }
  471. // 结算贡献值
  472. $user_sign_gongxian_list = Db::name('user_sign_gongxian')
  473. ->where('status', -1)
  474. ->where('order_id', $online['order_sn'])
  475. ->whereIn('type', [1, 2])
  476. ->select()
  477. ->toArray();
  478. foreach ($user_sign_gongxian_list as $user_sign_gongxian) {
  479. // 修改贡献值
  480. Db::name('user')
  481. ->where('uid', $user_sign_gongxian['uid'])
  482. ->inc('contribute', (float)$user_sign_gongxian['number'])
  483. ->update();
  484. Db::name('user_sign_gongxian')
  485. ->where('status', -1)
  486. ->where('id', $user_sign_gongxian['id'])
  487. ->update([
  488. 'status' => 1,
  489. 'settlement_time' => date('Y-m-d H:i:s')
  490. ]);
  491. /** @var UserRepository $userRepository */
  492. $userRepository = app()->make(UserRepository::class);
  493. $userRepository->setUserIdentity($user_sign_gongxian['uid']);
  494. }
  495. });
  496. }
  497. }
  498. /**
  499. * 在线支付公证处IN10入账 (红包,积分,京东,佣金,复购金,养老金,贡献值)
  500. * @param $nowTime
  501. * @param $timeLimit
  502. * author: php迷途小书童
  503. * created: 2021/3/20 9:25
  504. */
  505. public function doOnlineOrderGzc($timeLimit)
  506. {
  507. return true;
  508. // 普通订单
  509. $cursor = Db::table('rrx_store_order')->where('paid', 1)->where('gzc', 0)->where('pay_type', 'in', '0,1,2,4')->cursor();
  510. $StoreOrderStatusRepository = app()->make(StoreOrderStatusRepository::class);
  511. $OrderMerchantRepository = app()->make(OrderMerchantRepository::class);
  512. $OrderGzcRepository = app()->make(OrderGzcRepository::class);
  513. foreach ($cursor as $online) {
  514. $status = $StoreOrderStatusRepository->getWhere(['order_id' => $online['order_id'], 'change_type' => 'take']);
  515. if ($online['mer_id'] == 496) {
  516. if (!in_array($online['status'], [0, 1, 2, 3])) {
  517. continue;
  518. }
  519. // if (time() < strtotime($online['pay_time']) + 3600 * 24) {
  520. // Log::info('还没有到收货后' . $timeLimit . '天');
  521. // continue;
  522. // }
  523. } else {
  524. if (!in_array($online['status'], [2, 3])) {
  525. continue;
  526. }
  527. if (Carbon::now()->modify("-{$timeLimit} days")->lt($status->change_time ?? $status['change_time'])) {
  528. Log::info('还没有到收货后' . $timeLimit . '天');
  529. continue;
  530. }
  531. }
  532. // $certification = UserCertification::getInstance()->where('uid', $online['uid'])->find();
  533. // if (!$certification) {
  534. // Log::info($online['uid'] . '没有实名认证');
  535. // continue;
  536. // }
  537. //查询养老金金额
  538. $UserBillRepository = app()->make(UserBillRepository::class);
  539. $bill = $UserBillRepository->getWhere(['uid' => $online['uid'], 'link_id' => $online['order_id'], 'order_sn' => $online['order_sn'], 'commission_type' => 5]);
  540. $pension = $bill->number ?? 0;
  541. // if ($pension <= 0) {
  542. // Log::info($online['order_sn'] . 'pension' . $pension);
  543. // continue;
  544. // }
  545. //首信易分账
  546. // $StoreOrderRepository = app()->make(StoreOrderRepository::class);
  547. // if ($online['pay_type'] > 0) {
  548. // $StoreOrderRepository->splitOrder($online);
  549. // }
  550. Db::transaction(function () use ($online, $pension, $OrderGzcRepository, $OrderMerchantRepository, $StoreOrderRepository) {
  551. //新增入账明细记录
  552. // $orderId = $OrderMerchantRepository->getNewOrderId('IN10');
  553. // $create = [
  554. // 'uid' => $online['uid'],
  555. // 'platform_no' => $orderId,
  556. // 'account_type' => $online['pay_type'] == 1 ? 3 : 2,
  557. // 'user_name' => $certification['user_name'],
  558. // 'mobile' => $certification['mobile'],
  559. // 'user_card' => $certification['user_card'],
  560. // 'pension' => $pension,
  561. // 'order_type' => 2,
  562. // 'out_trade_no' => $online['order_sn']
  563. // ];
  564. // $test_user = Db::name('user')->where('uid', $online['uid'])->value('test_user');
  565. // $check = Db::name("gzc_logs")->where("out_trade_no", $online['order_sn'])->where("order_type", 2)->count();
  566. // if ($test_user == 0 && $check <= 0) {
  567. // $OrderGzcRepository->create($create);
  568. // }
  569. $order = StoreOrder::getInstance()->find($online['order_id']);
  570. $order->gzc = 1;
  571. $order->save();
  572. Db::name('user_bill')
  573. ->where('order_sn', $online['order_sn'])
  574. ->where('commission_type', 5)
  575. ->update(['status'=> 1]);
  576. // 养老金区域奖励
  577. // $order_data = [
  578. // 'pay_price' => $pension,
  579. // 'user_address_ids' => $online['user_address_ids'],
  580. // 'uid' => $online['uid'],
  581. // 'order_sn' => $online['order_sn']
  582. // ];
  583. // $StoreOrderRepository->area_manage_details($order_data, 8, 2);
  584. });
  585. }
  586. // 普通订单(红包,积分,京东,佣金,复购金,贡献值)
  587. $cursor = Db::table('rrx_store_order')->where('paid', 1)->where('is_settlement', 0)->where('pay_type', 'in', '0,1,2,4')->cursor();
  588. $StoreOrderStatusRepository = app()->make(StoreOrderStatusRepository::class);
  589. $OrderMerchantRepository = app()->make(OrderMerchantRepository::class);
  590. $OrderGzcRepository = app()->make(OrderGzcRepository::class);
  591. foreach ($cursor as $online) {
  592. $status = $StoreOrderStatusRepository->getWhere(['order_id' => $online['order_id'], 'change_type' => 'take']);
  593. if ($online['mer_id'] == 496) {
  594. if (!in_array($online['status'], [0, 1, 2, 3])) {
  595. continue;
  596. }
  597. if (time() < strtotime($online['pay_time']) + 3600 * 24) {
  598. Log::info('还没有到收货后' . $timeLimit . '天');
  599. continue;
  600. }
  601. } else {
  602. if (!in_array($online['status'], [2, 3])) {
  603. continue;
  604. }
  605. if (Carbon::now()->modify("-{$timeLimit} days")->lt($status->change_time ?? $status['change_time'])) {
  606. Log::info('还没有到收货后' . $timeLimit . '天');
  607. continue;
  608. }
  609. }
  610. $StoreOrderRepository = app()->make(StoreOrderRepository::class);
  611. Db::transaction(function () use ($online, $StoreOrderRepository) {
  612. $order = StoreOrder::getInstance()->find($online['order_id']);
  613. $order->is_settlement = 1;
  614. $order->settlement_time = date('Y-m-d H:i:s');
  615. $order->save();
  616. // 结算积分
  617. $user_sign_score_list = Db::name('user_sign_score')
  618. ->where('status', -1)
  619. ->where('order_id', $online['order_id'])
  620. ->whereIn('type', [1, 2])
  621. ->select()
  622. ->toArray();
  623. foreach ($user_sign_score_list as $user_sign_score) {
  624. // 修改积分
  625. Db::name('user')
  626. ->where('uid', $user_sign_score['uid'])
  627. ->inc('score', (float)$user_sign_score['reward_socre'])
  628. ->update();
  629. Db::name('user_sign_score')
  630. ->where('status', -1)
  631. ->where('id', $user_sign_score['id'])
  632. ->update([
  633. 'status' => 1,
  634. 'settlement_time' => date('Y-m-d H:i:s')
  635. ]);
  636. }
  637. // 结算红包
  638. $user_sign_hongbao_list = Db::name('user_sign_hongbao')
  639. ->where('status', -1)
  640. ->where('order_id', $online['order_id'])
  641. ->whereIn('type', [1, 2])
  642. ->select()
  643. ->toArray();
  644. foreach ($user_sign_hongbao_list as $user_sign_hongbao) {
  645. // 修改红包
  646. Db::name('user')
  647. ->where('uid', $user_sign_hongbao['uid'])
  648. ->inc('hongbao', (float)$user_sign_hongbao['number'])
  649. ->update();
  650. Db::name('user_sign_hongbao')
  651. ->where('status', -1)
  652. ->where('id', $user_sign_hongbao['id'])
  653. ->update([
  654. 'status' => 1,
  655. 'settlement_time' => date('Y-m-d H:i:s')
  656. ]);
  657. }
  658. // 结算京豆
  659. $user_sign_jingdou_list = Db::name('user_sign_jingdou')
  660. ->where('status', -1)
  661. ->where('order_id', $online['order_id'])
  662. ->whereIn('type', [1, 2])
  663. ->select()
  664. ->toArray();
  665. foreach ($user_sign_jingdou_list as $user_sign_jingdou) {
  666. // 修改京豆
  667. Db::name('user')
  668. ->where('uid', $user_sign_jingdou['uid'])
  669. ->inc('jingdou', (float)$user_sign_jingdou['number'])
  670. ->update();
  671. Db::name('user_sign_jingdou')
  672. ->where('status', -1)
  673. ->where('id', $user_sign_jingdou['id'])
  674. ->update([
  675. 'status' => 1,
  676. 'settlement_time' => date('Y-m-d H:i:s')
  677. ]);
  678. }
  679. // 结算复购金
  680. $user_sign_fugou_list = Db::name('user_sign_fugou')
  681. ->where('status', -1)
  682. ->where('order_id', $online['order_id'])
  683. ->whereIn('type', [1, 2])
  684. ->select()
  685. ->toArray();
  686. foreach ($user_sign_fugou_list as $user_sign_fugou) {
  687. // 修改复购金
  688. Db::name('user')
  689. ->where('uid', $user_sign_fugou['uid'])
  690. ->inc('fugou', (float)$user_sign_fugou['number'])
  691. ->update();
  692. Db::name('user_sign_fugou')
  693. ->where('status', -1)
  694. ->where('id', $user_sign_fugou['id'])
  695. ->update([
  696. 'status' => 1,
  697. 'settlement_time' => date('Y-m-d H:i:s')
  698. ]);
  699. }
  700. // 结算贡献值
  701. $user_sign_gongxian_list = Db::name('user_sign_gongxian')
  702. ->where('status', -1)
  703. ->where('order_id', $online['order_id'])
  704. ->whereIn('type', [1, 2])
  705. ->select()
  706. ->toArray();
  707. foreach ($user_sign_gongxian_list as $user_sign_gongxian) {
  708. // 修改贡献值
  709. Db::name('user')
  710. ->where('uid', $user_sign_gongxian['uid'])
  711. ->inc('contribute', (float)$user_sign_gongxian['number'])
  712. ->update();
  713. Db::name('user_sign_gongxian')
  714. ->where('status', -1)
  715. ->where('id', $user_sign_gongxian['id'])
  716. ->update([
  717. 'status' => 1,
  718. 'settlement_time' => date('Y-m-d H:i:s')
  719. ]);
  720. /** @var UserRepository $userRepository */
  721. $userRepository = app()->make(UserRepository::class);
  722. $userRepository->setUserIdentity($user_sign_gongxian['uid']);
  723. }
  724. // 结算PV值
  725. $user_pv_list = Db::name('user_pv_log')
  726. ->where('status', -1)
  727. ->where('order_id', $online['order_id'])
  728. ->whereIn('type', [1, 2])
  729. ->select()
  730. ->toArray();
  731. if($user_pv_list) {
  732. foreach ($user_pv_list as $user_pv) {
  733. // 修改pv
  734. Db::name('user')
  735. ->where('uid', $user_pv['uid'])
  736. ->inc('pv', (float)$user_pv['pv'])
  737. ->update();
  738. Db::name('user_pv_log')
  739. ->where('status', -1)
  740. ->where('id', $user_pv['id'])
  741. ->update([
  742. 'status' => 1,
  743. 'settlement_time' => date('Y-m-d H:i:s')
  744. ]);
  745. }
  746. }
  747. // 结算佣金
  748. $user_bill_list = Db::name('user_bill')
  749. ->where('status', 0)
  750. ->where('commission_type','<>', 5)
  751. ->where([ 'link_id' => $online['order_id'], 'order_sn' => $online['order_sn']])
  752. ->select()
  753. ->toArray();
  754. foreach ($user_bill_list as $user_bill) {
  755. if ($user_bill['commission_type'] != 5) {
  756. if (in_array($user_bill['commission_type'], [7,12,19])) {
  757. Db::name("merchant")
  758. ->where("mer_id", $user_bill['mer_id'])
  759. ->inc('brokerage_price', (float)$user_bill['number'])
  760. ->update();
  761. } else {
  762. Db::name('user')
  763. ->where('uid', $user_bill['uid'])
  764. ->inc('brokerage_price', (float)$user_bill['number'])
  765. ->update();
  766. }
  767. }
  768. if ($online['pay_type'] == 0 && $user_bill['commission_type'] == 5) {
  769. } else {
  770. // 虚拟支付的养老金不修改不结算
  771. Db::name('user_bill')
  772. ->where('status', 0)
  773. ->where('bill_id', $user_bill['bill_id'])
  774. ->update([
  775. 'status' => 1,
  776. 'take_time' => time()
  777. ]);
  778. }
  779. if ($online['pay_type'] == 0 && $user_bill['commission_type'] == 5) {
  780. } else {
  781. // 虚拟支付的养老金不修改不结算
  782. Db::name('user_bill')
  783. ->where('status', 0)
  784. ->where('bill_id', $user_bill['bill_id'])
  785. ->update([
  786. 'status' => 1,
  787. 'take_time' => time()
  788. ]);
  789. }
  790. }
  791. //按角色结算
  792. $StoreOrderRepository->close_order($online['order_id']);
  793. });
  794. }
  795. }
  796. /**
  797. * 第三方订单拼多多IN10入账
  798. * @param $nowTime
  799. * @param $timeLimit
  800. * author: php迷途小书童
  801. * created: 2021/3/20 9:26
  802. */
  803. public function doThridPddOrderGzc($nowTime, $timeLimit)
  804. {
  805. $cursor = Db::table('rrx_order_pdd')
  806. ->where('gzc', 0)
  807. ->where('bill_status', 1)
  808. ->where('commission', '>', 0)
  809. ->whereTime('bill_end_time', '<', $nowTime - bcmul((string)$timeLimit, (string)86400))
  810. ->cursor();
  811. $ProductRepository = app()->make(ProductRepository::class);
  812. $OrderGzcRepository = app()->make(OrderGzcRepository::class);
  813. $OrderMerchantRepository = app()->make(OrderMerchantRepository::class);
  814. $StoreOrderRepository = app()->make(StoreOrderRepository::class);
  815. foreach ($cursor as $thrid) {
  816. $uid = $thrid['uid'];
  817. if (!$uid)
  818. continue;
  819. // $certification = UserCertification::getInstance()->where('uid', $uid)->find();
  820. // if (!$certification) {
  821. // Log::info('用户ID' . $uid . '未实名认证');
  822. // continue;
  823. // }
  824. $pension = $ProductRepository->yanglaojin(0, sprintf('%.2f', $thrid['commission']));
  825. Db::transaction(function () use ($uid, $thrid, $pension, $OrderGzcRepository, $OrderMerchantRepository, $StoreOrderRepository) {
  826. //新增入账明细记录
  827. // $orderId = $OrderMerchantRepository->getNewOrderId('IN10');
  828. // $create = [
  829. // 'uid' => $uid,
  830. // 'platform_no' => $orderId,
  831. // 'user_name' => $certification['user_name'],
  832. // 'mobile' => $certification['mobile'],
  833. // 'user_card' => $certification['user_card'],
  834. // 'pension' => $pension,
  835. // 'order_type' => 3,
  836. // 'out_trade_no' => $thrid['order_sn']
  837. // ];
  838. // $test_user = Db::name('user')->where('uid', $uid)->value('test_user');
  839. // if ($test_user == 0) {
  840. // $OrderGzcRepository->create($create);
  841. // }
  842. // $OrderGzcRepository->create($create);
  843. Db::table('rrx_order_pdd')
  844. ->update(['gzc' => 1, 'order_pdd_id' => $thrid['order_pdd_id']]);
  845. Db::name('user_bill')
  846. ->where('order_sn', $thrid['order_sn'])
  847. ->where('commission_type', 5)
  848. ->update(['status'=> 1]);
  849. // 养老金区域奖励
  850. $order_data = [
  851. 'pay_price' => $pension,
  852. 'user_address_ids' => $thrid['user_address_ids'],
  853. 'uid' => $thrid['uid'],
  854. 'order_sn' => $thrid['order_sn']
  855. ];
  856. // $StoreOrderRepository->area_manage_details($order_data, 1, 2);
  857. });
  858. }
  859. }
  860. /**
  861. * 第三方订单京东IN10入账
  862. * @param $nowTime
  863. * @param $timeLimit
  864. * author: php迷途小书童
  865. * created: 2021/3/20 9:26
  866. */
  867. public function doThridJdOrderGzc($nowTime, $timeLimit)
  868. {
  869. $cursor = Db::table('rrx_order_jd')
  870. ->where('gzc', 0)
  871. ->where('bill_status', 1)
  872. ->where('commission', '>', 0)
  873. ->whereTime('bill_end_time', '<', $nowTime - bcmul((string)$timeLimit, (string)86400))
  874. ->cursor();
  875. // Db::name('log')->insert(['data'=>'abbbb入库语句'.$nowTime - bcmul((string)$timeLimit, (string)86400)]);
  876. // Db::name('log')->insert(['data'=>'abbbb'.json_encode($cursor)]);
  877. $ProductRepository = app()->make(ProductRepository::class);
  878. $OrderGzcRepository = app()->make(OrderGzcRepository::class);
  879. $OrderMerchantRepository = app()->make(OrderMerchantRepository::class);
  880. $StoreOrderRepository = app()->make(StoreOrderRepository::class);
  881. foreach ($cursor as $thrid) {
  882. $uid = $thrid['uid'];
  883. if (!$uid)
  884. continue;
  885. // $certification = UserCertification::getInstance()->where('uid', $uid)->find();
  886. // if (!$certification) {
  887. // Log::info('用户ID' . $uid . '未实名认证');
  888. // continue;
  889. // }
  890. $pension = $ProductRepository->yanglaojin(0, sprintf('%.2f', $thrid['commission']));
  891. Db::transaction(function () use ($uid, $thrid, $pension, $OrderGzcRepository, $OrderMerchantRepository, $StoreOrderRepository) {
  892. //新增入账明细记录
  893. // $orderId = $OrderMerchantRepository->getNewOrderId('IN10');
  894. // $create = [
  895. // 'uid' => $uid,
  896. // 'platform_no' => $orderId,
  897. // 'user_name' => $certification['user_name'],
  898. // 'mobile' => $certification['mobile'],
  899. // 'user_card' => $certification['user_card'],
  900. // 'pension' => $pension,
  901. // 'order_type' => 4,
  902. // 'out_trade_no' => $thrid['order_sn']
  903. // ];
  904. // $test_user = Db::name('user')->where('uid', $uid)->value('test_user');
  905. // if ($test_user == 0) {
  906. // $OrderGzcRepository->create($create);
  907. // }
  908. // $OrderGzcRepository->create($create);
  909. Db::table('rrx_order_jd')
  910. ->update(['gzc' => 1, 'order_jd_id' => $thrid['order_jd_id']]);
  911. Db::name('user_bill')
  912. ->where('order_sn', $thrid['order_sn'])
  913. ->where('commission_type', 5)
  914. ->update(['status'=> 1]);
  915. // 养老金区域奖励
  916. // $order_data = [
  917. // 'pay_price' => $pension,
  918. // 'user_address_ids' => $thrid['user_address_ids'],
  919. // 'uid' => $thrid['uid'],
  920. // 'order_sn' => $thrid['order_sn']
  921. // ];
  922. // $StoreOrderRepository->area_manage_details($order_data, 6, 2);
  923. });
  924. }
  925. }
  926. /**
  927. * 第三方订单苏宁IN10入账
  928. * @param $nowTime
  929. * @param $timeLimit
  930. * author: php迷途小书童
  931. * created: 2021/3/20 9:26
  932. */
  933. public function doThridSnOrderGzc($nowTime, $timeLimit)
  934. {
  935. $cursor = Db::table('rrx_order_su')
  936. ->where('gzc', 0)
  937. ->where('bill_status', 1)
  938. ->where('commission', '>', 0)
  939. ->whereTime('bill_end_time', '<', $nowTime - bcmul((string)$timeLimit, (string)86400))
  940. ->cursor();
  941. $ProductRepository = app()->make(ProductRepository::class);
  942. $OrderGzcRepository = app()->make(OrderGzcRepository::class);
  943. $OrderMerchantRepository = app()->make(OrderMerchantRepository::class);
  944. $StoreOrderRepository = app()->make(StoreOrderRepository::class);
  945. foreach ($cursor as $thrid) {
  946. $uid = $thrid['uid'];
  947. if (!$uid)
  948. continue;
  949. // $certification = UserCertification::getInstance()->where('uid', $uid)->find();
  950. // if (!$certification) {
  951. // Log::info('用户ID' . $uid . '未实名认证');
  952. // continue;
  953. // }
  954. $pension = $ProductRepository->yanglaojin(0, sprintf('%.2f', $thrid['commission']));
  955. Db::transaction(function () use ($uid, $thrid, $pension, $OrderGzcRepository, $OrderMerchantRepository, $StoreOrderRepository) {
  956. //新增入账明细记录
  957. // $orderId = $OrderMerchantRepository->getNewOrderId('IN10');
  958. // $create = [
  959. // 'uid' => $uid,
  960. // 'platform_no' => $orderId,
  961. // 'user_name' => $certification['user_name'],
  962. // 'mobile' => $certification['mobile'],
  963. // 'user_card' => $certification['user_card'],
  964. // 'pension' => $pension,
  965. // 'order_type' => 5,
  966. // 'out_trade_no' => $thrid['order_sn']
  967. // ];
  968. // $test_user = Db::name('user')->where('uid', $uid)->value('test_user');
  969. // if ($test_user == 0) {
  970. // $OrderGzcRepository->create($create);
  971. // }
  972. // $OrderGzcRepository->create($create);
  973. Db::table('rrx_order_su')
  974. ->update(['gzc' => 1, 'order_su_id' => $thrid['order_su_id']]);
  975. Db::name('user_bill')
  976. ->where('order_sn', $thrid['order_sn'])
  977. ->where('commission_type', 5)
  978. ->update(['status'=> 1]);
  979. // 养老金区域奖励
  980. $order_data = [
  981. 'pay_price' => $pension,
  982. 'user_address_ids' => $thrid['user_address_ids'],
  983. 'uid' => $thrid['uid'],
  984. 'order_sn' => $thrid['order_sn']
  985. ];
  986. // $StoreOrderRepository->area_manage_details($order_data, 3, 2);
  987. });
  988. }
  989. }
  990. /**
  991. * 第三方订单话费IN10入账
  992. * @param $nowTime
  993. * @param $timeLimit
  994. * author: php迷途小书童
  995. * created: 2021/3/20 9:26
  996. */
  997. public function doThridHfOrderGzc($nowTime, $timeLimit)
  998. {
  999. $cursor = Db::table('rrx_order_huafei')
  1000. ->where('gzc', 0)
  1001. ->where('bill_status', 1)
  1002. ->where('commission', '>', 0)
  1003. ->whereTime('bill_end_time', '<', $nowTime - bcmul((string)$timeLimit, (string)86400))
  1004. ->cursor();
  1005. $ProductRepository = app()->make(ProductRepository::class);
  1006. $OrderGzcRepository = app()->make(OrderGzcRepository::class);
  1007. $OrderMerchantRepository = app()->make(OrderMerchantRepository::class);
  1008. foreach ($cursor as $thrid) {
  1009. $uid = $thrid['uid'];
  1010. if (!$uid)
  1011. continue;
  1012. // $certification = UserCertification::getInstance()->where('uid', $uid)->find();
  1013. // if (!$certification) {
  1014. // Log::info('用户ID' . $uid . '未实名认证');
  1015. // continue;
  1016. // }
  1017. $pension = $ProductRepository->yanglaojin(0, sprintf('%.2f', $thrid['commission']));
  1018. Db::transaction(function () use ($uid, $thrid, $pension, $OrderGzcRepository, $OrderMerchantRepository) {
  1019. // //新增入账明细记录
  1020. // $orderId = $OrderMerchantRepository->getNewOrderId('IN10');
  1021. // $create = [
  1022. // 'uid' => $uid,
  1023. // 'platform_no' => $orderId,
  1024. // 'user_name' => $certification['user_name'],
  1025. // 'mobile' => $certification['mobile'],
  1026. // 'user_card' => $certification['user_card'],
  1027. // 'pension' => $pension,
  1028. // 'order_type' => 6,
  1029. // 'out_trade_no' => $thrid['order_sn']
  1030. // ];
  1031. // $test_user = Db::name('user')->where('uid', $uid)->value('test_user');
  1032. // if ($test_user == 0) {
  1033. // $OrderGzcRepository->create($create);
  1034. // }
  1035. Db::table('rrx_order_huafei')->update(['gzc' => 1, 'order_tb_id' => $thrid['order_tb_id']]);
  1036. Db::name('user_bill')
  1037. ->where('order_sn', $thrid['order_sn'])
  1038. ->where('commission_type', 5)
  1039. ->update(['status'=> 1]);
  1040. });
  1041. }
  1042. }
  1043. /**
  1044. * 第三方订单淘宝IN10入账
  1045. * @param $nowTime
  1046. * @param $timeLimit
  1047. * author: php迷途小书童
  1048. * created: 2021/3/20 9:26
  1049. */
  1050. public function doThridTaobaoOrderGzc($nowTime, $timeLimit)
  1051. {
  1052. $cursor = Db::table('rrx_order_tb')
  1053. ->where('gzc', 0)
  1054. ->where('bill_status', 1)
  1055. ->where('commission', '>', 0)
  1056. ->whereTime('bill_end_time', '<', $nowTime - bcmul((string)$timeLimit, (string)86400))
  1057. ->cursor();
  1058. $ProductRepository = app()->make(ProductRepository::class);
  1059. $OrderGzcRepository = app()->make(OrderGzcRepository::class);
  1060. $OrderMerchantRepository = app()->make(OrderMerchantRepository::class);
  1061. $StoreOrderRepository = app()->make(StoreOrderRepository::class);
  1062. foreach ($cursor as $thrid) {
  1063. $uid = $thrid['uid'];
  1064. if (!$uid)
  1065. continue;
  1066. // $certification = UserCertification::getInstance()->where('uid', $uid)->find();
  1067. // if (!$certification) {
  1068. // Log::info('用户ID' . $uid . '未实名认证');
  1069. // continue;
  1070. // }
  1071. $pension = $ProductRepository->yanglaojin(0, sprintf('%.2f', $thrid['commission']));
  1072. Db::transaction(function () use ($uid, $thrid, $pension, $OrderGzcRepository, $OrderMerchantRepository, $StoreOrderRepository) {
  1073. //新增入账明细记录
  1074. // $orderId = $OrderMerchantRepository->getNewOrderId('IN10');
  1075. // $create = [
  1076. // 'uid' => $uid,
  1077. // 'platform_no' => $orderId,
  1078. // 'user_name' => $certification['user_name'],
  1079. // 'mobile' => $certification['mobile'],
  1080. // 'user_card' => $certification['user_card'],
  1081. // 'pension' => $pension,
  1082. // 'order_type' => 6,
  1083. // 'out_trade_no' => $thrid['order_sn']
  1084. // ];
  1085. // $test_user = Db::name('user')->where('uid', $uid)->value('test_user');
  1086. // if ($test_user == 0) {
  1087. // $OrderGzcRepository->create($create);
  1088. // }
  1089. // $OrderGzcRepository->create($create);
  1090. Db::table('rrx_order_tb')
  1091. ->update(['gzc' => 1, 'order_tb_id' => $thrid['order_tb_id']]);
  1092. Db::name('user_bill')
  1093. ->where('order_sn', $thrid['order_sn'])
  1094. ->where('commission_type', 5)
  1095. ->update(['status'=> 1]);
  1096. // 养老金区域奖励
  1097. $order_data = [
  1098. 'pay_price' => $pension,
  1099. 'user_address_ids' => $thrid['user_address_ids'],
  1100. 'uid' => $thrid['uid'],
  1101. 'order_sn' => $thrid['order_sn']
  1102. ];
  1103. // $StoreOrderRepository->area_manage_details($order_data, 5, 2);
  1104. });
  1105. }
  1106. }
  1107. /**
  1108. * 第三方订单唯品会IN10入账
  1109. * @param $nowTime
  1110. * @param $timeLimit
  1111. * author: php迷途小书童
  1112. * created: 2021/3/20 9:26
  1113. */
  1114. public function doThridVipOrderGzc($nowTime, $timeLimit)
  1115. {
  1116. $cursor = Db::table('rrx_order_vip')
  1117. ->where('gzc', 0)
  1118. ->where('bill_status', 1)
  1119. ->where('commission', '>', 0)
  1120. ->whereTime('bill_end_time', '<', $nowTime - bcmul((string)$timeLimit, (string)86400))
  1121. ->cursor();
  1122. $ProductRepository = app()->make(ProductRepository::class);
  1123. $OrderGzcRepository = app()->make(OrderGzcRepository::class);
  1124. $OrderMerchantRepository = app()->make(OrderMerchantRepository::class);
  1125. $StoreOrderRepository = app()->make(StoreOrderRepository::class);
  1126. foreach ($cursor as $thrid) {
  1127. $uid = $thrid['uid'];
  1128. if (!$uid)
  1129. continue;
  1130. // $certification = UserCertification::getInstance()->where('uid', $uid)->find();
  1131. // if (!$certification) {
  1132. // Log::info('用户ID' . $uid . '未实名认证');
  1133. // continue;
  1134. // }
  1135. $pension = $ProductRepository->yanglaojin(0, sprintf('%.2f', $thrid['commission']));
  1136. Db::transaction(function () use ($uid, $thrid, $pension, $OrderGzcRepository, $OrderMerchantRepository, $StoreOrderRepository) {
  1137. //新增入账明细记录
  1138. // $orderId = $OrderMerchantRepository->getNewOrderId('IN10');
  1139. // $create = [
  1140. // 'uid' => $uid,
  1141. // 'platform_no' => $orderId,
  1142. // 'user_name' => $certification['user_name'],
  1143. // 'mobile' => $certification['mobile'],
  1144. // 'user_card' => $certification['user_card'],
  1145. // 'pension' => $pension,
  1146. // 'order_type' => 7,
  1147. // 'out_trade_no' => $thrid['order_sn']
  1148. // ];
  1149. // $test_user = Db::name('user')->where('uid', $uid)->value('test_user');
  1150. // if ($test_user == 0) {
  1151. // $OrderGzcRepository->create($create);
  1152. // }
  1153. // $OrderGzcRepository->create($create);
  1154. Db::table('rrx_order_vip')
  1155. ->update(['gzc' => 1, 'order_vip_id' => $thrid['order_vip_id']]);
  1156. Db::name('user_bill')
  1157. ->where('order_sn', $thrid['order_sn'])
  1158. ->where('commission_type', 5)
  1159. ->update(['status'=> 1]);
  1160. // 养老金区域奖励
  1161. $order_data = [
  1162. 'pay_price' => $pension,
  1163. 'user_address_ids' => $thrid['user_address_ids'],
  1164. 'uid' => $thrid['uid'],
  1165. 'order_sn' => $thrid['order_sn']
  1166. ];
  1167. // $StoreOrderRepository->area_manage_details($order_data, 2, 2);
  1168. });
  1169. }
  1170. }
  1171. /**
  1172. * 第三方订单抖音IN10入账
  1173. * @param $nowTime
  1174. * @param $timeLimit
  1175. * author: php迷途小书童
  1176. * created: 2021/3/20 9:26
  1177. */
  1178. public function doThridDyOrderGzc($nowTime, $timeLimit)
  1179. {
  1180. $cursor = Db::table('rrx_order_dy')
  1181. ->where('gzc', 0)
  1182. ->where('bill_status', 1)
  1183. ->where('commission', '>', 0)
  1184. ->whereTime('bill_end_time', '<', $nowTime - bcmul((string)$timeLimit, (string)86400))
  1185. ->cursor();
  1186. $ProductRepository = app()->make(ProductRepository::class);
  1187. $OrderGzcRepository = app()->make(OrderGzcRepository::class);
  1188. $OrderMerchantRepository = app()->make(OrderMerchantRepository::class);
  1189. $StoreOrderRepository = app()->make(StoreOrderRepository::class);
  1190. foreach ($cursor as $thrid) {
  1191. $uid = $thrid['uid'];
  1192. if (!$uid)
  1193. continue;
  1194. // $certification = UserCertification::getInstance()->where('uid', $uid)->find();
  1195. // if (!$certification) {
  1196. // Log::info('用户ID' . $uid . '未实名认证');
  1197. // continue;
  1198. // }
  1199. $pension = $ProductRepository->yanglaojin(0, sprintf('%.2f', $thrid['commission']));
  1200. Db::transaction(function () use ($uid, $thrid, $pension, $OrderGzcRepository, $OrderMerchantRepository, $StoreOrderRepository) {
  1201. // //新增入账明细记录
  1202. // $orderId = $OrderMerchantRepository->getNewOrderId('IN10');
  1203. // $create = [
  1204. // 'uid' => $uid,
  1205. // 'platform_no' => $orderId,
  1206. // 'user_name' => $certification['user_name'],
  1207. // 'mobile' => $certification['mobile'],
  1208. // 'user_card' => $certification['user_card'],
  1209. // 'pension' => $pension,
  1210. // 'order_type' => 8,
  1211. // 'out_trade_no' => $thrid['order_sn']
  1212. // ];
  1213. // $test_user = Db::name('user')->where('uid', $uid)->value('test_user');
  1214. // if ($test_user == 0) {
  1215. // $OrderGzcRepository->create($create);
  1216. // }
  1217. Db::table('rrx_order_dy')
  1218. ->update(['gzc' => 1, 'order_dy_id' => $thrid['order_dy_id']]);
  1219. Db::name('user_bill')
  1220. ->where('order_sn', $thrid['order_sn'])
  1221. ->where('commission_type', 5)
  1222. ->update(['status'=> 1]);
  1223. // 养老金区域奖励
  1224. $order_data = [
  1225. 'pay_price' => $pension,
  1226. 'user_address_ids' => $thrid['user_address_ids'],
  1227. 'uid' => $thrid['uid'],
  1228. 'order_sn' => $thrid['order_sn']
  1229. ];
  1230. // $StoreOrderRepository->area_manage_details($order_data, 9, 2);
  1231. });
  1232. }
  1233. }
  1234. /**
  1235. * 志愿者升级
  1236. * */
  1237. public function doUpgrade()
  1238. {
  1239. set_time_limit(0);
  1240. try {
  1241. //志愿者条件
  1242. $volunteer_achievement = systemConfig("volunteer_achievement"); //volunteer_achievement:用户本人满足养老金要求可升级为志愿者
  1243. //一星条件
  1244. $a_volunteer_achievement = systemConfig("a_volunteer_achievement");//团队养老金要求
  1245. $a_volunteer_number = systemConfig("a_volunteer_number"); //团队人数要求
  1246. //二星条件
  1247. $b_volunteer_achievement = systemConfig("b_volunteer_achievement");//团队养老金要求
  1248. $b_volunteer_number = systemConfig("b_volunteer_number"); //团队人数要求
  1249. //三星条件
  1250. $c_volunteer_achievement = systemConfig("c_volunteer_achievement");//团队养老金要求
  1251. $c_volunteer_number = systemConfig("c_volunteer_number"); //团队人数要求
  1252. //董事条件
  1253. $d_volunteer_achievement = systemConfig("d_volunteer_achievement");//团队养老金要求
  1254. $d_volunteer_number = systemConfig("d_volunteer_number"); //团队人数要求
  1255. //用户列表
  1256. $userList = Db::name("User")
  1257. ->field("uid")
  1258. ->select();
  1259. foreach ($userList as $key => $value) {
  1260. $volunteer = $this->volunteer($value['uid']);
  1261. //本人养老金小于志愿者要求
  1262. if ($volunteer['self_yanglao'] < $volunteer_achievement) {
  1263. $this->grade($value['uid'], 0, $volunteer);
  1264. }
  1265. //满足志愿者要求
  1266. if ($volunteer['self_yanglao'] >= $volunteer_achievement) {
  1267. //志愿者
  1268. if ($volunteer['team'] < $a_volunteer_number || $volunteer['yanglao'] < $a_volunteer_achievement) {
  1269. $this->grade($value['uid'], 1, $volunteer);
  1270. }
  1271. //一星
  1272. if ($volunteer['team'] >= $a_volunteer_number && $volunteer['yanglao'] >= $a_volunteer_achievement//满足一星条件
  1273. &&
  1274. ($volunteer['team'] < $b_volunteer_number || $volunteer['yanglao'] < $b_volunteer_achievement)//未满足二星条件
  1275. ) {
  1276. $this->grade($value['uid'], 2, $volunteer);
  1277. }
  1278. //二星
  1279. if ($volunteer['team'] >= $b_volunteer_number && $volunteer['yanglao'] >= $b_volunteer_achievement//满足二星条件
  1280. &&
  1281. ($volunteer['team'] < $c_volunteer_number || $volunteer['yanglao'] < $c_volunteer_achievement)//未满足三星条件
  1282. ) {
  1283. $this->grade($value['uid'], 3, $volunteer);
  1284. }
  1285. //三星
  1286. if ($volunteer['team'] >= $c_volunteer_number && $volunteer['yanglao'] >= $c_volunteer_achievement//满足三星条件
  1287. &&
  1288. ($volunteer['team'] < $d_volunteer_number || $volunteer['yanglao'] < $d_volunteer_achievement)//未满足董事条件
  1289. ) {
  1290. $this->grade($value['uid'], 4, $volunteer);
  1291. }
  1292. //董事
  1293. if ($volunteer['team'] >= $d_volunteer_number && $volunteer['yanglao'] >= $d_volunteer_achievement) {
  1294. $this->grade($value['uid'], 5, $volunteer);
  1295. }
  1296. }
  1297. //团队各等级数量统计
  1298. $this->statistics($value['uid']);
  1299. }
  1300. } catch (Exception $e) {
  1301. Log::info('志愿者升级:' . $e->getMessage());
  1302. }
  1303. }
  1304. //志愿者信息
  1305. public function volunteer($uid)
  1306. {
  1307. if (!$uid) {
  1308. return false;
  1309. }
  1310. //本人养老金
  1311. $data['self_yanglao'] = $this->getYanglao($uid);
  1312. //团队人数
  1313. $data['team'] = $this->volunteer_number($uid);
  1314. //团队养老金
  1315. $data['yanglao'] = $this->volunteer_achievement($uid);
  1316. //直推人数
  1317. $data['extension'] = Db::name("user_identity_log")->where(["uid" => $uid])->count();
  1318. //直推商户数量
  1319. $data['shop'] = Db::name("user_identity_log")->where(["uid" => $uid, 'identity' => 4])->whereNotIn("identity", "0")->count();
  1320. return $data;
  1321. }
  1322. //团队人数
  1323. public function volunteer_number($uid)
  1324. {
  1325. $number = 0;
  1326. $number1 = Db::name("user_identity_log")->where(["uid" => $uid])->field("link_id")->select();
  1327. $number += count($number1);
  1328. foreach ($number1 as $key => $value) {
  1329. $number += Db::name("user_identity_log")->where(["uid" => $value['link_id']])->field("link_id")->count();
  1330. }
  1331. return $number;
  1332. }
  1333. //团队养老金
  1334. public function volunteer_achievement($uid)
  1335. {
  1336. $yanglao = 0;
  1337. $number1 = Db::name("user_identity_log")->where(["uid" => $uid])->field("link_id")->select();
  1338. foreach ($number1 as $key => $value) {
  1339. $yanglao += $this->getYanglao($value['link_id']);
  1340. $number2 = Db::name("user_identity_log")->where(["uid" => $value['link_id']])->field("link_id")->select();
  1341. foreach ($number2 as $k => $v) {
  1342. $yanglao += $this->getYanglao($v['link_id']);
  1343. }
  1344. unset($number2);
  1345. }
  1346. return $yanglao;
  1347. }
  1348. //用户养老金
  1349. public function getYanglao($uid)
  1350. {
  1351. return Db::name("UserBill")
  1352. ->where([
  1353. 'uid' => $uid,
  1354. 'commission_type' => 5,
  1355. 'status' => 1,
  1356. 'pm' => 1
  1357. ])
  1358. ->sum("number");
  1359. }
  1360. //升级
  1361. public function grade($uid, $grade, $volunteer)
  1362. {
  1363. $exist = Db::name("Volunteer")->where(["uid" => $uid])->find();
  1364. if ($exist) {
  1365. Db::name("Volunteer")
  1366. ->where(["uid" => $uid])
  1367. ->update([
  1368. "grade" => $grade,
  1369. "team" => $volunteer['team'],
  1370. "yanglao" => $volunteer['yanglao'],
  1371. "extension" => $volunteer['extension'],
  1372. "shop" => $volunteer['shop'],
  1373. "time" => time()
  1374. ]);
  1375. return true;
  1376. }
  1377. Db::name("Volunteer")
  1378. ->insert([
  1379. "uid" => $uid,
  1380. "grade" => $grade,
  1381. "team" => $volunteer['team'],
  1382. "yanglao" => $volunteer['yanglao'],
  1383. "extension" => $volunteer['extension'],
  1384. "shop" => $volunteer['shop'],
  1385. "time" => time()
  1386. ]
  1387. );
  1388. return true;
  1389. }
  1390. //下级各等级数量统计
  1391. public function statistics($uid)
  1392. {
  1393. $data = [
  1394. 'v' => 0,
  1395. 'v1' => 0,
  1396. 'v2' => 0,
  1397. 'v3' => 0,
  1398. 'v4' => 0
  1399. ];
  1400. $fns = function ($uid) use (&$fns, &$data) {
  1401. $identity = Db::name("user_identity_log")
  1402. ->alias("u")
  1403. ->join("Volunteer v", "u.link_id = v.uid")
  1404. ->where(["u.uid" => $uid])
  1405. ->field("u.link_id,v.grade")
  1406. ->select();
  1407. if ($identity) {
  1408. foreach ($identity as $key => $value) {
  1409. if ($value['grade'] == 1) {
  1410. $data['v']++;
  1411. }
  1412. if ($value['grade'] == 2) {
  1413. $data['v1']++;
  1414. }
  1415. if ($value['grade'] == 3) {
  1416. $data['v2']++;
  1417. }
  1418. if ($value['grade'] == 4) {
  1419. $data['v3']++;
  1420. }
  1421. if ($value['grade'] == 5) {
  1422. $data['v4']++;
  1423. }
  1424. $fns($value['link_id']);
  1425. }
  1426. }
  1427. };
  1428. $fns($uid);
  1429. Db::name("Volunteer")
  1430. ->where(["uid" => $uid])
  1431. ->update([
  1432. "v" => $data['v'],
  1433. "v1" => $data['v1'],
  1434. "v2" => $data['v2'],
  1435. "v3" => $data['v3'],
  1436. "v4" => $data['v4'],
  1437. "time" => time()
  1438. ]);
  1439. return $data;
  1440. }
  1441. /**
  1442. * 线上订单结算
  1443. * @param $timeLimit
  1444. * @return void
  1445. * @throws \think\db\exception\DataNotFoundException
  1446. * @throws \think\db\exception\DbException
  1447. * @throws \think\db\exception\ModelNotFoundException
  1448. */
  1449. public function onlineOrderNew($timeLimit)
  1450. {
  1451. // 普通订单
  1452. $order_data = Db::name('store_order')->where('paid', 1)->where('is_settlement', 0)->where('pay_type', 'in', '0,1,2,4')->where([['status','in','2,3']])->select();
  1453. $StoreOrderStatusRepository = app()->make(StoreOrderStatusRepository::class);
  1454. if($order_data) {
  1455. $order_data = $order_data->toArray();
  1456. foreach ($order_data as $online) {
  1457. $date = date('Y-m-d H:i:s', strtotime('-' . $timeLimit . ' days'));
  1458. if($date < $online['create_time']) continue;
  1459. Db::transaction(function () use ($online) {
  1460. $this->settleAward($online);
  1461. Db::name('store_order')->where('order_id', $online['order_id'])->update(['is_settlement' => 1 ,'settlement_time' => date('Y-m-d H:i:s')]);
  1462. });
  1463. }
  1464. }
  1465. }
  1466. /**
  1467. * 话费订单结算
  1468. * @param $timeLimit
  1469. * @return void
  1470. * @throws \think\db\exception\DataNotFoundException
  1471. * @throws \think\db\exception\DbException
  1472. * @throws \think\db\exception\ModelNotFoundException
  1473. */
  1474. public function huafeiOrderNew($timeLimit)
  1475. {
  1476. // 普通订单
  1477. $order_data = Db::name('order_huafei')->where('status', 2)->where('gzc' , 0)->select();
  1478. if($order_data) {
  1479. $order_data = $order_data->toArray();
  1480. foreach ($order_data as $online) {
  1481. $date = date('Y-m-d H:i:s', strtotime('-' . $timeLimit . ' days'));
  1482. if($date < $online['create_time']) continue;
  1483. $online['order_id'] = $online['order_huafei_id'];
  1484. Db::transaction(function () use ($online) {
  1485. $this->settleAward($online);
  1486. Db::name('order_huafei')->where('order_huafei_id', $online['order_huafei_id'])->update(['gzc' => 1]);
  1487. });
  1488. }
  1489. }
  1490. }
  1491. /**
  1492. * 拼多多订单结算
  1493. * @param $timeLimit
  1494. * @return void
  1495. * @throws \think\db\exception\DataNotFoundException
  1496. * @throws \think\db\exception\DbException
  1497. * @throws \think\db\exception\ModelNotFoundException
  1498. */
  1499. public function pddOrderNew($timeLimit)
  1500. {
  1501. // 普通订单
  1502. $order_data = Db::name('order_pdd')->where('pin_order_status', 5)->where('gzc', 0)->select();
  1503. if($order_data) {
  1504. $order_data = $order_data->toArray();
  1505. foreach ($order_data as $online) {
  1506. $date = date('Y-m-d H:i:s', strtotime('-' . $timeLimit . ' days'));
  1507. if($date < $online['create_time']) continue;
  1508. $online['order_id'] = $online['order_pdd_id'];
  1509. Db::transaction(function () use ($online) {
  1510. $this->settleAward($online);
  1511. Db::name('order_pdd')->where('order_pdd_id', $online['order_pdd_id'])->update(['gzc' => 1]);
  1512. });
  1513. }
  1514. }
  1515. }
  1516. /**
  1517. * 京东订单结算
  1518. * @param $timeLimit
  1519. * @return void
  1520. * @throws \think\db\exception\DataNotFoundException
  1521. * @throws \think\db\exception\DbException
  1522. * @throws \think\db\exception\ModelNotFoundException
  1523. */
  1524. public function jdOrderNew($timeLimit)
  1525. {
  1526. // 普通订单
  1527. $order_data = Db::name('order_jd')->where('status', 17)->where('gzc', 0)->select();
  1528. if($order_data) {
  1529. $order_data = $order_data->toArray();
  1530. foreach ($order_data as $online) {
  1531. $date = date('Y-m-d H:i:s', strtotime('-' . $timeLimit . ' days'));
  1532. if($date < $online['create_time']) continue;
  1533. $online['order_id'] = $online['order_jd_id'];
  1534. Db::transaction(function () use ($online) {
  1535. $this->settleAward($online);
  1536. Db::name('order_jd')->where('order_jd_id', $online['order_jd_id'])->update(['gzc' => 1]);
  1537. });
  1538. }
  1539. }
  1540. }
  1541. /**
  1542. * 苏宁订单结算
  1543. * @param $timeLimit
  1544. * @return void
  1545. * @throws \think\db\exception\DataNotFoundException
  1546. * @throws \think\db\exception\DbException
  1547. * @throws \think\db\exception\ModelNotFoundException
  1548. */
  1549. public function suOrderNew($timeLimit)
  1550. {
  1551. // 普通订单
  1552. $order_data = Db::name('order_su')->where('status', '确认收货')->where('gzc', 0)->select();
  1553. if($order_data) {
  1554. $order_data = $order_data->toArray();
  1555. foreach ($order_data as $online) {
  1556. $date = date('Y-m-d H:i:s', strtotime('-' . $timeLimit . ' days'));
  1557. if($date < $online['create_time']) continue;
  1558. $online['order_id'] = $online['order_su_id'];
  1559. Db::transaction(function () use ($online) {
  1560. $this->settleAward($online);
  1561. Db::name('order_su')->where('order_su_id', $online['order_su_id'])->update(['gzc' => 1]);
  1562. });
  1563. }
  1564. }
  1565. }
  1566. /**
  1567. * 淘宝订单结算
  1568. * @param $timeLimit
  1569. * @return void
  1570. * @throws \think\db\exception\DataNotFoundException
  1571. * @throws \think\db\exception\DbException
  1572. * @throws \think\db\exception\ModelNotFoundException
  1573. */
  1574. public function taobaoOrderNew($timeLimit)
  1575. {
  1576. // 普通订单
  1577. $order_data = Db::name('order_tb')->where('tk_status', 3)->where('gzc', 0)->select();
  1578. if($order_data) {
  1579. $order_data = $order_data->toArray();
  1580. foreach ($order_data as $online) {
  1581. $date = date('Y-m-d H:i:s', strtotime('-' . $timeLimit . ' days'));
  1582. if($date < $online['create_time']) continue;
  1583. $online['order_id'] = $online['order_tb_id'];
  1584. Db::transaction(function () use ($online) {
  1585. $this->settleAward($online);
  1586. Db::name('order_tb')->where('order_tb_id', $online['order_tb_id'])->update(['gzc' => 1]);
  1587. });
  1588. }
  1589. }
  1590. }
  1591. /**
  1592. * 唯品会订单结算
  1593. * @param $timeLimit
  1594. * @return void
  1595. * @throws \think\db\exception\DataNotFoundException
  1596. * @throws \think\db\exception\DbException
  1597. * @throws \think\db\exception\ModelNotFoundException
  1598. */
  1599. public function vipOrderNew($timeLimit)
  1600. {
  1601. // 普通订单
  1602. $order_data = Db::name('order_vip')->where('status', 2)->where('gzc', 0)->select();
  1603. if($order_data) {
  1604. $order_data = $order_data->toArray();
  1605. foreach ($order_data as $online) {
  1606. $date = date('Y-m-d H:i:s', strtotime('-' . $timeLimit . ' days'));
  1607. if($date < $online['create_time']) continue;
  1608. $online['order_id'] = $online['order_vip_id'];
  1609. Db::transaction(function () use ($online) {
  1610. $this->settleAward($online);
  1611. Db::name('order_vip')->where('order_vip_id', $online['order_vip_id'])->update(['gzc' => 1]);
  1612. });
  1613. }
  1614. }
  1615. }
  1616. /**
  1617. * 抖音订单结算
  1618. * @param $timeLimit
  1619. * @return void
  1620. * @throws \think\db\exception\DataNotFoundException
  1621. * @throws \think\db\exception\DbException
  1622. * @throws \think\db\exception\ModelNotFoundException
  1623. */
  1624. public function dyOrderNew($timeLimit)
  1625. {
  1626. // 普通订单
  1627. $order_data = Db::name('order_dy')->where('flow_point', 'SETTLE')->where('gzc', 0)->select();
  1628. if($order_data) {
  1629. $order_data = $order_data->toArray();
  1630. foreach ($order_data as $online) {
  1631. $date = date('Y-m-d H:i:s', strtotime('-' . $timeLimit . ' days'));
  1632. if($date < $online['create_time']) continue;
  1633. $online['order_id'] = $online['order_dy_id'];
  1634. Db::transaction(function () use ($online) {
  1635. $this->settleAward($online);
  1636. Db::name('order_dy')->where('order_dy_id', $online['order_dy_id'])->update(['gzc' => 1]);
  1637. });
  1638. }
  1639. }
  1640. }
  1641. /**
  1642. * 结算奖励
  1643. * @param $online
  1644. * @return void
  1645. * @throws \think\db\exception\DataNotFoundException
  1646. * @throws \think\db\exception\DbException
  1647. * @throws \think\db\exception\ModelNotFoundException
  1648. */
  1649. public function settleAward($online)
  1650. {
  1651. // 结算积分
  1652. $user_sign_score_list = Db::name('user_sign_score')
  1653. ->where('status', -1)
  1654. ->where('order_id', $online['order_id'])
  1655. ->where('pm', 1)
  1656. ->select()
  1657. ->toArray();
  1658. if($user_sign_score_list){
  1659. foreach ($user_sign_score_list as $user_sign_score) {
  1660. // 修改积分
  1661. Db::name('user')
  1662. ->where('uid', $user_sign_score['uid'])
  1663. ->inc('score', floatval($user_sign_score['reward_socre']))
  1664. ->update();
  1665. Db::name('user_sign_score')
  1666. ->where('id', $user_sign_score['id'])
  1667. ->update([
  1668. 'status' => 1,
  1669. 'settlement_time' => date('Y-m-d H:i:s')
  1670. ]);
  1671. }
  1672. }
  1673. // 结算红包
  1674. $user_sign_hongbao_list = Db::name('user_sign_hongbao')
  1675. ->where('status', -1)
  1676. ->where('order_id', $online['order_id'])
  1677. ->where('type', 1)
  1678. ->select()
  1679. ->toArray();
  1680. if($user_sign_hongbao_list){
  1681. foreach ($user_sign_hongbao_list as $user_sign_hongbao) {
  1682. // 修改红包
  1683. Db::name('user')
  1684. ->where('uid', $user_sign_hongbao['uid'])
  1685. ->inc('hongbao', floatval($user_sign_hongbao['number']))
  1686. ->update();
  1687. Db::name('user_sign_hongbao')
  1688. ->where('id', $user_sign_hongbao['id'])
  1689. ->update([
  1690. 'status' => 1,
  1691. 'settlement_time' => date('Y-m-d H:i:s')
  1692. ]);
  1693. }
  1694. }
  1695. // 结算京豆
  1696. $user_sign_jingdou_list = Db::name('user_sign_jingdou')
  1697. ->where('status', -1)
  1698. ->where('order_id', $online['order_id'])
  1699. ->where('type', 1)
  1700. ->select()
  1701. ->toArray();
  1702. if($user_sign_jingdou_list){
  1703. foreach ($user_sign_jingdou_list as $user_sign_jingdou) {
  1704. // 修改京豆
  1705. Db::name('user')
  1706. ->where('uid', $user_sign_jingdou['uid'])
  1707. ->inc('jingdou', floatval($user_sign_jingdou['number']))
  1708. ->update();
  1709. Db::name('user_sign_jingdou')
  1710. ->where('id', $user_sign_jingdou['id'])
  1711. ->update([
  1712. 'status' => 1,
  1713. 'settlement_time' => date('Y-m-d H:i:s')
  1714. ]);
  1715. }
  1716. }
  1717. // 结算复购金
  1718. $user_sign_fugou_list = Db::name('user_sign_fugou')
  1719. ->where('status', -1)
  1720. ->where('order_id', $online['order_id'])
  1721. ->where('type', 1)
  1722. ->select()
  1723. ->toArray();
  1724. if($user_sign_fugou_list){
  1725. foreach ($user_sign_fugou_list as $user_sign_fugou) {
  1726. // 修改复购金
  1727. Db::name('user')
  1728. ->where('uid', $user_sign_fugou['uid'])
  1729. ->inc('fugou', floatval($user_sign_fugou['number']))
  1730. ->update();
  1731. Db::name('user_sign_fugou')
  1732. ->where('id', $user_sign_fugou['id'])
  1733. ->update([
  1734. 'status' => 1,
  1735. 'settlement_time' => date('Y-m-d H:i:s')
  1736. ]);
  1737. }
  1738. }
  1739. // 结算贡献值
  1740. $user_sign_gongxian_list = Db::name('user_sign_gongxian')
  1741. ->where('status', -1)
  1742. ->where('order_id', $online['order_id'])
  1743. ->where('type', 1)
  1744. ->select()
  1745. ->toArray();
  1746. if($user_sign_gongxian_list){
  1747. foreach ($user_sign_gongxian_list as $user_sign_gongxian) {
  1748. // 修改贡献值
  1749. Db::name('user')
  1750. ->where('uid', $user_sign_gongxian['uid'])
  1751. ->inc('contribute', floatval($user_sign_gongxian['number']))
  1752. ->update();
  1753. Db::name('user_sign_gongxian')
  1754. ->where('id', $user_sign_gongxian['id'])
  1755. ->update([
  1756. 'status' => 1,
  1757. 'settlement_time' => date('Y-m-d H:i:s')
  1758. ]);
  1759. /** @var UserRepository $userRepository */
  1760. $userRepository = app()->make(UserRepository::class);
  1761. $userRepository->setUserIdentity($user_sign_gongxian['uid']);
  1762. }
  1763. }
  1764. // 结算PV值
  1765. $user_pv_list = Db::name('user_pv_log')
  1766. ->where('status', -1)
  1767. ->where('order_id', $online['order_id'])
  1768. ->select()
  1769. ->toArray();
  1770. if($user_pv_list) {
  1771. foreach ($user_pv_list as $user_pv) {
  1772. // 修改pv
  1773. Db::name('user')
  1774. ->where('uid', $user_pv['uid'])
  1775. ->inc('pv', floatval($user_pv['pv']))
  1776. ->update();
  1777. Db::name('user_pv_log')
  1778. ->where('id', $user_pv['id'])
  1779. ->update([
  1780. 'status' => 1,
  1781. 'settlement_time' => date('Y-m-d H:i:s')
  1782. ]);
  1783. }
  1784. }
  1785. // 结算佣金养老金
  1786. $user_bill_list = Db::name('user_bill')
  1787. ->where('status', 0)
  1788. ->where([ 'link_id' => $online['order_id']])
  1789. ->where([ 'pm' => 1])
  1790. ->select()
  1791. ->toArray();
  1792. if($user_bill_list){
  1793. foreach ($user_bill_list as $user_bill) {
  1794. if($user_bill['commission_type'] == 5){
  1795. Db::name('user')
  1796. ->where('uid', $user_bill['uid'])
  1797. ->inc('annuity', floatval($user_bill['number']))
  1798. ->update();
  1799. }else{
  1800. Db::name('user')
  1801. ->where('uid', $user_bill['uid'])
  1802. ->inc('brokerage_price', floatval($user_bill['number']))
  1803. ->update();
  1804. }
  1805. Db::name('user_bill')
  1806. ->where('bill_id', $user_bill['bill_id'])
  1807. ->update([
  1808. 'status' => 1,
  1809. 'take_time' => date('Y-m-d H:i:s')
  1810. ]);
  1811. }
  1812. }
  1813. //按角色结算
  1814. // $StoreOrderRepository->close_order($online['order_id']);
  1815. }
  1816. }