PensionTasks.php 67 KB

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