PensionTasks.php 85 KB

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