PensionTasks.php 66 KB

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