PensionTasks.php 83 KB

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