PensionTasks.php 85 KB

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