PensionTasks.php 83 KB

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