PensionTasks.php 83 KB

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