PensionTasks.php 85 KB

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