PensionTasks.php 86 KB

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