PensionTasks.php 87 KB

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