CommissionCron.php 78 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721
  1. <?php
  2. namespace app\controller\api\cron;
  3. use app\common\model\store\order\StoreOrder;
  4. use app\common\repositories\user\UserBillRepository;
  5. use app\common\model\user\UserCertification;
  6. use AdaPaySdk\Drawcash;
  7. use AdaPaySdk\PaymentConfirm;
  8. use AdaPaySdk\SettleAccount;
  9. use app\common\dao\store\order\StoreOrderDao;
  10. use app\common\repositories\merchant\order\OrderGzcRepository;
  11. use app\common\repositories\merchant\order\OrderMerchantRepository;
  12. use app\common\repositories\store\order\StoreOrderRepository;
  13. use app\common\repositories\store\order\StoreOrderStatusRepository;
  14. use app\common\repositories\user\UserRepository;
  15. use app\controller\api\Common;
  16. use app\controller\merchant\finance\Reconciliation;
  17. use app\traits\GongApiRequest;
  18. use app\traits\ShouxinyiApiRequest;
  19. use Carbon\Carbon;
  20. use Exception;
  21. use PHPMailer\PHPMailer\PHPMailer;
  22. use think\db\exception\DataNotFoundException;
  23. use think\db\exception\DbException;
  24. use think\db\exception\ModelNotFoundException;
  25. use think\facade\Cache;
  26. use think\facade\Db;
  27. use think\facade\Log;
  28. use function GuzzleHttp\Psr7\str;
  29. use app\traits\HuiPay;
  30. class CommissionCron
  31. {
  32. /**
  33. * @var false|string
  34. */
  35. private $startMonth;
  36. /**
  37. * @var false|string
  38. */
  39. private $endMonth;
  40. /**
  41. * @var false|string
  42. */
  43. private $month;
  44. public function __construct()
  45. {
  46. // $this->startMonth = date('Y-m-01 00:00:00', strtotime('-1 month'));
  47. // $this->endMonth = date("Y-m-d 23:59:59", strtotime(-date('d') . 'day'));
  48. // $this->month = date('Y-m', strtotime('-1 month'));
  49. $this->startMonth = date('Y-m-01 00:00:00');
  50. $this->endMonth = date("Y-m-d 23:59:59");
  51. $this->month = date('Y-m');
  52. }
  53. /**
  54. * 奖金
  55. */
  56. public function bonus()
  57. {
  58. //创客补贴
  59. $this->real_subsidy_money();
  60. // 跨店奖励
  61. $this->stride_shop_money();
  62. //推荐创客收益
  63. $this->invite_shop_money();
  64. //大V经理分享奖
  65. $this->big_vip_money();
  66. //大V升级奖
  67. $this->big_vip_up_money();
  68. echo '执行成功';
  69. }
  70. public function stride_shop_money()
  71. {
  72. $StoreOrderRepository = app()->make(StoreOrderRepository::class);
  73. $sql = "select stride_shop_mer_id,sum(stride_shop_money) stride_shop_money from rrx_store_order o
  74. left join rrx_store_order_extend od on od.order_id=o.order_id
  75. where o.paid=1 and o.is_settlement=1 and settlement_time between '$this->startMonth' and '$this->endMonth' and od.stride_shop_mer_id>0 and od.stride_shop_money>0
  76. group by od.stride_shop_mer_id";
  77. $mer_bonus_list = Db::query($sql);
  78. Db::name('log')->insert(['data' => "跨店奖励 mer_bonus_list:" . json_encode($mer_bonus_list)]);
  79. foreach ($mer_bonus_list as $mer_bonus) {
  80. $mer_id = $mer_bonus['stride_shop_mer_id'];
  81. $money = $mer_bonus['stride_shop_money'];
  82. if ($money < 0.01) {
  83. Db::name('log')->insert(['data' => "跨店奖励:mer_id:{$mer_id} 跨店奖励低于0.01无法入库 特此记录!"]);
  84. continue;
  85. }
  86. $merchant = Db::name('merchant')->where('mer_id', $mer_id)->find();
  87. $mark = "跨店奖励" . $money;
  88. $title = "跨店奖励({$this->month}月)";
  89. $commission_type = 7;
  90. $StoreOrderRepository->add_bill_gongfu($title, $money, $merchant['uid'] ?? 0, $mark, $commission_type, null, 0, $mer_id, 0, 1, 8, 'commission', $this->month, true);
  91. }
  92. }
  93. public function invite_shop_money()
  94. {
  95. $StoreOrderRepository = app()->make(StoreOrderRepository::class);
  96. $sql = "select od.share_uid,sum(invite_shop_money) invite_shop_money from rrx_store_order o
  97. left join rrx_store_order_extend od on od.order_id=o.order_id
  98. where o.paid=1 and o.is_settlement=1 and settlement_time between '$this->startMonth' and '$this->endMonth' and od.share_uid>0 and od.invite_shop_money>0 group by od.share_uid";
  99. $user_bonus_list = Db::query($sql);
  100. Db::name('log')->insert(['data' => "推荐创客奖励 user_bonus_list:" . json_encode($user_bonus_list)]);
  101. foreach ($user_bonus_list as $user_bonus) {
  102. $bonus_uid = $user_bonus['share_shop_uid'];
  103. $money = $user_bonus['invite_shop_money'];
  104. if ($money < 0.01) {
  105. Db::name('log')->insert(['data' => "推荐创客:bonus_uid:{$bonus_uid} 推荐创客低于0.01无法入库 特此记录!"]);
  106. continue;
  107. }
  108. $mark = "推荐创客收益" . $money;
  109. $title = "推荐创客收益({$this->month}月)";
  110. $commission_type = 10;
  111. $StoreOrderRepository->add_bill_gongfu($title, $money, $bonus_uid, $mark, $commission_type, null, 0, $mer_id, 0, 1, 8, 'commission', $this->month);
  112. }
  113. }
  114. public function big_vip_money()
  115. {
  116. $StoreOrderRepository = app()->make(StoreOrderRepository::class);
  117. $sql = "select od.share_uid,sum(big_vip_money) big_vip_money from rrx_store_order o
  118. left join rrx_store_order_extend od on od.order_id=o.order_id
  119. where o.paid=1 and o.is_settlement=1 and settlement_time between '$this->startMonth' and '$this->endMonth' and od.share_uid>0 and od.big_vip_money>0 group by od.share_uid";
  120. $user_bonus_list = Db::query($sql);
  121. Db::name('log')->insert(['data' => "大v奖励 user_bonus_list:" . json_encode($user_bonus_list)]);
  122. foreach ($user_bonus_list as $user_bonus) {
  123. $bonus_uid = $user_bonus['share_uid'];
  124. $money = $user_bonus['big_vip_money'];
  125. if ($money < 0.01) {
  126. Db::name('log')->insert(['data' => "大v分享奖:bonus_uid:{$bonus_uid} 大v分享奖低于0.01无法入库 特此记录!"]);
  127. continue;
  128. }
  129. $mark = "大V经理分享奖" . $money;
  130. $title = "大V经理分享奖({$this->month})";
  131. $commission_type = 16;
  132. $StoreOrderRepository->add_bill_gongfu($title, $money, $bonus_uid, $mark, $commission_type, null, 0, $mer_id, 0, 1, 8, 'commission', $this->month);
  133. }
  134. }
  135. public function real_subsidy_money()
  136. {
  137. $StoreOrderRepository = app()->make(StoreOrderRepository::class);
  138. $sql = "select o.mer_id mer_id,sum(real_subsidy_money) real_subsidy_money from rrx_store_order o
  139. left join rrx_store_order_extend od on od.order_id=o.order_id
  140. where o.paid=1 and o.is_settlement=1 and settlement_time between '$this->startMonth' and '$this->endMonth' and od.real_subsidy_money>0
  141. group by o.mer_id";
  142. $mer_bonus_list = Db::query($sql);
  143. Db::name('log')->insert(['data' => "创客补贴 mer_bonus_list:" . json_encode($mer_bonus_list)]);
  144. foreach ($mer_bonus_list as $mer_bonus) {
  145. $mer_id = $mer_bonus['mer_id'];
  146. $money = $mer_bonus['real_subsidy_money'];
  147. if ($money < 0.01) {
  148. Db::name('log')->insert(['data' => "创客补贴:mer_id:{$mer_id} 创客补贴低于0.01无法入库 特此记录!"]);
  149. continue;
  150. }
  151. $merchant = Db::name('merchant')->where('mer_id', $mer_id)->find();
  152. $mark = "创客补贴" . $money;
  153. $title = "创客补贴({$this->month}月)";
  154. $commission_type = 19;
  155. $StoreOrderRepository->add_bill_gongfu($title, $money, $merchant['uid'] ?? 0, $mark, $commission_type, null, 0, $mer_id, 0, 1, 8, 'commission', $this->month, true);
  156. }
  157. }
  158. /**
  159. * 大V升级奖
  160. * 1. 查询大V经理列表
  161. * 2. 查询团队列表
  162. * 3. 查询团队这个月的总流水的百分之一分给大V经理
  163. * @return void
  164. */
  165. public function big_vip_up_money()
  166. {
  167. $StoreOrderRepository = app()->make(StoreOrderRepository::class);
  168. $user_list = Db::name("user")->field('uid')->where("user_group", 3)->select()->toArray();
  169. foreach ($user_list as $user) {
  170. $mer_id = 0;
  171. $user_id = $user['uid'];
  172. $sql = "select getUserSpreadId($user_id) as uids";
  173. $spread_user_list = Db::query($sql);
  174. $spread_user_list = trim($spread_user_list[0]['uids'],'$,');
  175. //查询可以分到的钱
  176. $sql = "select sum(big_vip_up_money) big_vip_up_money from rrx_store_order o
  177. left join rrx_store_order_extend od on od.order_id=o.order_id
  178. where o.paid=1 and o.is_settlement=1 and settlement_time between '$this->startMonth' and '$this->endMonth' and o.uid in ($spread_user_list)";
  179. $big_vip_up = Db::query($sql)[0];
  180. $money = $big_vip_up['big_vip_up_money'] ?? 0;
  181. Db::name('log')->insert(['data' => "大V升级奖 big_vip_up_money {$user_id}:{$money}"]);
  182. if ($money < 0.01) {
  183. Db::name('log')->insert(['data' => "大v分享奖:big_vip_up_money:{$money} 大v分享奖低于0.01无法入库 特此记录!"]);
  184. continue;
  185. }
  186. $mark = "大V升级奖" . $money;
  187. $title = "大V升级奖({$this->month}月)";
  188. $commission_type = 10;
  189. $StoreOrderRepository->add_bill_gongfu($title, $money, $user_id, $mark, $commission_type, null, 0, $mer_id, 0, 1, 8, 'commission', $this->month);
  190. }
  191. }
  192. /**
  193. * 用户升级
  194. * @throws DbException
  195. */
  196. public function member_up()
  197. {
  198. $uid_list = Db::name('store_order')
  199. ->where('mer_id', systemConfig('mer_365'))
  200. ->where('paid', 1)
  201. ->whereIn('status', [0, 1, 2, 3])
  202. ->group('uid')
  203. ->column('uid');
  204. Log::info('升级:' . json_encode($uid_list));
  205. foreach ($uid_list as $uid) {
  206. $pay_price = Db::name('store_order')
  207. ->where('mer_id', systemConfig('mer_365'))
  208. ->where('uid', $uid)
  209. ->where('paid', 1)
  210. ->where('is_settlement', 1)
  211. ->whereIn('status', [0, 1, 2, 3])
  212. ->sum('pay_price');
  213. if ($pay_price >= 365) {
  214. // 有没有直推20个经理
  215. $invite_count = Db::name('user')->where('spread_uid', $uid)->field('uid,user_group')->where('user_group', 2)->count();
  216. print_r("uid:{$uid}," . Db::name('user')->where('uid', $uid)->value('phone') . "邀请365经理人数{$invite_count} <br>");
  217. if ($invite_count >= 20) {
  218. $res = Db::name('user')->where('uid', $uid)->whereNotIn('user_group', [4, 5, 6])->update([
  219. 'user_group' => 3
  220. ]);
  221. if ($res) var_dump("uid:{$uid},升级大V经理");
  222. } else {
  223. $res = Db::name('user')->where('uid', $uid)->whereNotIn('user_group', [3, 4, 5, 6])->update([
  224. 'user_group' => 2
  225. ]);
  226. if ($res) var_dump("uid:{$uid},升级365会员");
  227. }
  228. }
  229. }
  230. }
  231. /**
  232. * 创客合伙人收益
  233. */
  234. private function partner_award()
  235. {
  236. //1. 被创客设置成创客合伙人,获得该项收益
  237. //已结算订单金额的
  238. //2%
  239. //1. 按月统计并结算
  240. //2. 计算公式:
  241. //所属创客店补贴*2%/创客合伙人总数
  242. // 推荐创客收益设置
  243. $commission_rate = systemConfig('commission_rate');
  244. Db::name('log')->insert(['data' => 'commission_rate:' . json_encode($commission_rate)]);
  245. $rate = $commission_rate['chuangkehehuoren_rate'];
  246. // 查询全部订单
  247. $sql = "select mer_id,sum(pay_price) pay_price,sum(total_price) total_price from rrx_store_order where paid=1 and status in (2,3) and is_settlement=1 and settlement_time between '$this->startMonth' and '$this->endMonth' group by mer_id";
  248. $mer_order_list = Db::query($sql);
  249. Db::name('log')->insert(['data' => "创客合伙人收益 user_order_list:" . json_encode($mer_order_list)]);
  250. $StoreOrderRepository = app()->make(StoreOrderRepository::class);
  251. $mer_out_list = [];
  252. foreach ($mer_order_list as $mer_order) {
  253. $mer_id = $mer_order['mer_id'];
  254. $hehuo_user_list = Db::name('user')->field('uid')->where('mer_id', $mer_id)->where('is_shop_partner', 1)->select()->toArray();
  255. $money = decimal2($mer_order['total_price'] * $rate / 100);
  256. foreach ($hehuo_user_list as $hehuo_user) {
  257. $user_money = decimal2($money / count($hehuo_user_list));
  258. Db::name('log')->insert(['data' => "创客补贴:uid:{$hehuo_user['uid']} 创客合伙人人数:" . count($hehuo_user_list) . " 创客补贴比例{$rate}% 创客店铺订单流水:{$mer_order['total_price']} 获取创客推荐收益:{$money}!"]);
  259. if ($money == 0) {
  260. Db::name('log')->insert(['data' => "创客补贴:uid:{$hehuo_user['uid']} 创客补贴低于0.01无法入库 特此记录!"]);
  261. continue;
  262. }
  263. $mark = "创客合伙人收益" . $user_money;
  264. $title = "创客合伙人收益({$this->month}月)";
  265. $commission_type = 17;
  266. $StoreOrderRepository->add_bill_gongfu($title, $money, $hehuo_user['uid'], $mark, $commission_type, null, 0, $mer_id, 0, 1, 8, 'commission', $this->month);
  267. }
  268. $money = decimal2($mer_order['total_price'] * $rate / 100);
  269. $mer_out_list[] = [
  270. $mer_order['mer_id'] => $money
  271. ];
  272. }
  273. Db::name('log')->insert(['data' => '跨店奖励 商户支出:' . json_encode($mer_out_list)]);
  274. return $mer_out_list;
  275. }
  276. /**
  277. * 代理区域收益
  278. */
  279. public function area_manage_details()
  280. {
  281. //1. 代理区域内已结算订单总额的百分
  282. //比;
  283. //2. 按照收货地址统计;
  284. //3. 奖励对象:省代、区县代;
  285. //区县代 5%
  286. //省代 2%
  287. //1. 按月结算:每月 1 号 0 点
  288. //统计上月已结算的订单金额
  289. //并对应发放佣金
  290. //2. 计算公式:
  291. //(1)无运费:收货地为该区域的已结算订单金额*对应比例
  292. //(2)有运费:(收货地为该区域的已结算订单金额-运费)*对应比例
  293. set_time_limit(0);
  294. ini_set('memory_limit', '-1');
  295. $commission_rate = systemConfig('commission_rate');
  296. Db::name('log')->insert(['data' => '代理区域收益 commission_rate:' . json_encode($commission_rate)]);
  297. $area_agency_rate = $commission_rate['area_agency_rate'] ?? 0;
  298. $province_agency_rate = $commission_rate['province_agency_rate'] ?? 0;
  299. $bonus_list = [];
  300. $bonus_user_list = Db::name('user')->field('uid,user_group,manage_address,spread_uid')->whereIn('user_group', [5, 6])->select()->toArray();
  301. $StoreOrderRepository = app()->make(StoreOrderRepository::class);
  302. foreach ($bonus_user_list as $bonus_user) {
  303. $manage_address = $bonus_user['manage_address'];
  304. if (empty($manage_address))
  305. continue;
  306. $sql = "select sum(pay_price) pay_price,sum(total_price) total_price from rrx_store_order where paid=1 and status in (2,3) and is_settlement=1 and settlement_time between '$this->startMonth' and '$this->endMonth' and user_address_ids like '$manage_address%'";
  307. $total_price = Db::query($sql)[0]['total_price'] ?? 0;
  308. $rate = $bonus_user['user_group'] == 6 ? $province_agency_rate : $area_agency_rate;
  309. $money = decimal2($total_price * $rate / 100);
  310. Db::name('log')->insert(['data' => "代理区域收益:uid:{$bonus_user['uid']} 代理区域收益比例{$rate}% 流水:{$total_price} 收益:{$money} sql:" . $sql]);
  311. $mark = "代理区域收益" . $money;
  312. $title = "代理区域收益({$this->month}月)";
  313. $commission_type = 12;
  314. $StoreOrderRepository->add_bill_gongfu($title, $money, $bonus_user['uid'], $mark, $commission_type, null, 0, 0, 0, 1, 8, 'commission', $this->month);
  315. $bonus_list[] = [
  316. 'uid' => $bonus_user['uid'],
  317. 'money' => $money,
  318. 'spread_uid' => $bonus_user['spread_uid'],
  319. ];
  320. }
  321. $this->invite_agency_award($bonus_list);
  322. echo '执行成功';
  323. }
  324. /**
  325. * 推荐代理收益
  326. * @param $bonus_list
  327. */
  328. private function invite_agency_award($bonus_list)
  329. {
  330. // 1. 推荐的代理收益的百分比
  331. //2. 奖励对象:所有用户
  332. //1. 按月结算:每个月 1 号 0点统计上月的代理收益并对应发放佣金
  333. //2. 计算公式:
  334. //推荐代理总收益*推荐代理收益百分比
  335. $StoreOrderRepository = app()->make(StoreOrderRepository::class);
  336. $this->month = date('Y-m', strtotime('-1 month'));
  337. $commission_rate = systemConfig('commission_rate');
  338. $rate = $commission_rate['tuijiandaili_rate'] ?? 0;
  339. foreach ($bonus_list as $bonus) {
  340. $money = decimal2($bonus['money'] * $rate / 100);
  341. $mark = "推荐代理收益" . $money;
  342. $title = "推荐代理收益({$this->month}月)";
  343. $commission_type = 15;
  344. $StoreOrderRepository->add_bill_gongfu($title, $money, $bonus['spread_uid'], $mark, $commission_type, null, 0, 0, 0, 1, 8, 'commission', $this->month, $this->month);
  345. }
  346. }
  347. /**
  348. * 生成商品图片缓存(最好用命令行执行)
  349. * @return \think\response\Json
  350. * @throws DataNotFoundException
  351. * @throws DbException
  352. * @throws ModelNotFoundException
  353. */
  354. public function make_product_share_cache()
  355. {
  356. set_time_limit(0);
  357. ini_set('memory_limit', '-1');
  358. $redis = Cache::store('redis')->handler();
  359. $key = 'make_product_share_cache';
  360. // $redis->del($key);
  361. // if (!$redis->setnx($key, 1))
  362. // return json(['code' => 400, 'msg' => '现在有正在执行的任务' ]);
  363. $redis->expire($key, 5 * 60);
  364. $product_share_ids = Db::name('product_share')
  365. // ->where('`url` is not null')
  366. ->group('product_id')
  367. ->column('product_id');
  368. $list = Db::name('store_product')
  369. ->whereNotIn('product_id', $product_share_ids)
  370. ->where('is_show', 1)
  371. ->limit(3)
  372. ->order('create_time desc')
  373. ->select()
  374. ->toArray();
  375. var_dump($list);
  376. $header = [
  377. 'X-Token: eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpc3MiOiJ0ZXN0LmJqdGRiYS5jb20iLCJhdWQiOiJ0ZXN0LmJqdGRiYS5jb20iLCJpYXQiOjE2OTI0MjQ4MTEsIm5iZiI6MTY5MjQyNDgxMSwiZXhwIjoxNzAzMjI0ODExLCJqdGkiOls5NzIwLCJ1c2VyIl19.YtYf1ssMTz6fOO2rZVX-jb48L7AqXSKezQcbTHR3sCk'
  378. ];
  379. foreach ($list as $store_product) {
  380. $res1 = Common::sendCurl("http://127.0.0.1:8324/api/product_share?pid={$store_product['product_id']}&type=1", null, 'get', $header);
  381. $res2 = Common::sendCurl("http://127.0.0.1:8324/api/product_share?pid={$store_product['product_id']}&type=2", null, 'get', $header);
  382. var_dump($res1, $res2);
  383. }
  384. $redis->del($key);
  385. return json(['code' => 200, 'msg' => '生成商品分享缓存定时任务执行成功']);
  386. }
  387. /**
  388. * 梳理每个人的公排人数
  389. * @throws \think\db\exception\DataNotFoundException
  390. * @throws \think\db\exception\DbException
  391. * @throws \think\db\exception\ModelNotFoundException
  392. */
  393. public function tease_user_count()
  394. {
  395. $list = Db::name('user')->where('is_del', 0)->select()->toArray();
  396. foreach ($list as $item) {
  397. $level_number = Db::name('user')->where('level_id', $item['uid'])->count();
  398. $user_count = Db::name('user_count')->where('uid', $item['uid'])->find();
  399. if ($level_number >= 5) {
  400. $res = Db::name('user_count')->where('uid', $item['uid'])->delete();
  401. if ($res) echo "{$item['uid']}公排人数已删除\r\n";
  402. continue;
  403. }
  404. if ($user_count) {
  405. if ($level_number == $user_count['level_number']) continue;
  406. Db::name('user_count')->where('uid', $item['uid'])->update([
  407. 'level_number' => $level_number
  408. ]);
  409. } else {
  410. Db::name('user_count')->insert([
  411. 'uid' => $item['uid'],
  412. 'level_number' => 0
  413. ]);
  414. $user_count['level_number'] = 0;
  415. }
  416. echo "{$item['uid']}公排人数从{$user_count['level_number']}调整到{$level_number}人\r\n";
  417. Log::info("{$item['uid']}公排人数从{$user_count['level_number']}调整到{$level_number}人\r\n");
  418. }
  419. return json(['code' => 200, 'msg' => '生成商品分享缓存定时任务执行成功']);
  420. }
  421. /**
  422. * 下架微唯宝已下架的商品
  423. * @return mixed
  424. * @throws \think\db\exception\DbException
  425. */
  426. public function downGongProduct()
  427. {
  428. $start = input('start');
  429. $where = [
  430. 'is_used' => 1,
  431. 'mer_status' => 1,
  432. // 'type' => 5,
  433. // 'is_show' => 1,
  434. 'is_hide' => 0,
  435. // 'is_del' => 0
  436. ];
  437. if (!$start) {
  438. $product_data_count = Db::name('store_product')
  439. ->where($where)
  440. ->where("spu_id != '' or spu_id is not null")
  441. ->count();
  442. $start = mt_rand(0, $product_data_count);
  443. }
  444. $product_data = Db::name('store_product')
  445. ->where($where)
  446. ->where("spu_id != '' or spu_id is not null")
  447. ->where('product_id', '>', $start)
  448. ->order('product_id asc')
  449. ->limit(0, 50)
  450. ->select()
  451. ->toArray();
  452. foreach ($product_data as $item) {
  453. $spuIds = $item['spu_id'];
  454. $goods_status = GongApiRequest::goods_status($spuIds);
  455. $status = $goods_status[0]['status'] ?? 1;
  456. $goods_info = GongApiRequest::get_goods_info($spuIds);
  457. if ($status == 0 || (isset($goods_info['error_msg']) && $goods_info['error_msg'] == '没有查询到商品信息')) {
  458. Db::startTrans();
  459. try {
  460. // 删除选品库对应的数据
  461. Db::name('douhuomall')->whereIn('spu_id', $spuIds)->update([
  462. 'status' => 9,
  463. 'update_time' => date('Y-m-d H:i:s')
  464. ]);
  465. // 删除商品管理对应的数据
  466. Db::name('store_product')->whereIn('spu_id', $spuIds)->update([
  467. 'is_del' => 1,
  468. 'is_show' => 0
  469. ]);
  470. Db::commit();
  471. } catch (Exception $e) {
  472. Db::rollback();
  473. Log::channel("gong")->error('供应链取消商品失败:' . $e->getMessage());
  474. return app('json')->fail($e->getMessage());
  475. }
  476. } else if ($status == 1 || !isset($goods_info['error_msg'])) {
  477. Db::startTrans();
  478. try {
  479. // 选品库对应的数据
  480. Db::name('douhuomall')->whereIn('spu_id', $spuIds)->update([
  481. 'status' => 1,
  482. 'update_time' => date('Y-m-d H:i:s')
  483. ]);
  484. // 商品管理对应的数据
  485. Db::name('store_product')->whereIn('spu_id', $spuIds)->update([
  486. 'is_del' => 0,
  487. 'is_show' => 1
  488. ]);
  489. Db::commit();
  490. } catch (Exception $e) {
  491. Db::rollback();
  492. Log::channel("gong")->error('供应链取消商品失败:' . $e->getMessage());
  493. return app('json')->fail($e->getMessage());
  494. }
  495. }
  496. }
  497. return app('json')->success('操作成功');
  498. }
  499. //定时任务写日账单,月账单
  500. public function cron($day,$mer_id=496)
  501. {
  502. // $day=date('Y-m-d', strtotime('-1 days'));
  503. // $enterprise_bill_item=[];
  504. // $order= $order_query->select();
  505. // foreach ($order as $v) {
  506. // $arr = [];
  507. // $arr['mer_id'] = $mer_id;
  508. // $arr['transaction_time'] = $v['pay_time'];
  509. // $arr['money'] = $v['pay_price'];
  510. // $arr['uid'] = $v['uid'];
  511. // $arr['order_sn'] = $v['order_sn'];
  512. // $arr['type'] = 1;
  513. // $enterprise_bill_item[] = $arr;
  514. // }
  515. // if ($enterprise_bill_item) {
  516. // Db::name('enterprise_bill_item')->insertAll($enterprise_bill_item);
  517. // }
  518. Db::name('enterprise_day_bill')->where('mer_id', $mer_id)->where('day', $day)->delete();
  519. $day_flow_query = Db::name('enterprise_platform_income_detail')
  520. ->where('mer_id', $mer_id)
  521. ->when($mer_id, function ($query) use ($mer_id) {
  522. $query->where('deal_type', -1);//没有流水
  523. }, function ($query) use ($mer_id) {
  524. $query->whereIn('deal_type', [3]);
  525. })
  526. ->where('deal_type', 4)
  527. ->where('pm', 1);
  528. $day_flow_query_month = clone $day_flow_query;
  529. // 日订单流水
  530. $day_flow = $day_flow_query->where("DATE(deal_time) = '" . $day . "'")->sum('money');
  531. $accounting_query = Db::name('enterprise_platform_income_detail')
  532. ->where('mer_id', $mer_id)
  533. ->when($mer_id, function ($query) use ($mer_id) {
  534. $query->where('deal_type', 1);
  535. }, function ($query) use ($mer_id) {
  536. $query->whereIn('deal_type', [6,7]);
  537. })
  538. ->where('pm', 1);
  539. $accounting_query_month = clone $accounting_query;
  540. // 入账金额
  541. $day_accounting = $accounting_query->where("DATE(deal_time) = '" . $day . "'")->sum('money');
  542. $expenditure_query = Db::name('enterprise_platform_income_detail')
  543. ->when($mer_id, function ($query) use ($mer_id) {
  544. $query->where('mer_id', $mer_id)
  545. ->where('deal_type', -1);//没有流水
  546. }, function ($query) use ($mer_id) {
  547. $query->whereIn('deal_type', [4,5]);
  548. });
  549. $expenditure_query_month = clone $expenditure_query;
  550. // 日支出总额
  551. $day_expenditure = 0;
  552. if($mer_id==0){
  553. $day_expenditure = $expenditure_query->where("DATE(deal_time) = '" . $day . "'")
  554. ->whereIn('deal_type', [4,5])
  555. ->where('mer_id',0)
  556. ->sum('money');
  557. }
  558. $insert = [];
  559. $insert['mer_id'] = $mer_id;
  560. $insert['day'] = $day;
  561. $insert['flow'] = $day_flow;
  562. $insert['expenditure'] = $day_expenditure;
  563. $insert['accounting'] = $day_accounting;
  564. $previousDate = date('Y-m-d', strtotime($day . ' -1 day'));
  565. $balance_zuotian = Db::name('enterprise_day_bill')->where('day', $previousDate)->where('mer_id', $mer_id)->value('balance');
  566. $balance = $balance_zuotian ? $balance_zuotian : 0;
  567. if($mer_id){
  568. $tixian = Db::name('user_extract')->where("DATE(status_time) = '" . $day . "'")->where('mer_id', $mer_id)->where('status', 1)->sum('extract_price');
  569. $service_money = Db::name('user_extract')->where("DATE(status_time) = '" . $day . "'")->where('mer_id', $mer_id)->where('status', 1)->sum('service_money');
  570. $tixian -= $service_money;
  571. $ylj = Db::name('user_bill')->where('mer_id', $mer_id)->where('status', 1)->where("DATE(take_time) = '" . $day . "'")->sum('number');
  572. $insert['balance'] = $day_accounting - $tixian + $balance - $ylj;
  573. }else{
  574. $tixian = Db::name('enterprise_platform_income_detail')
  575. ->where("deal_time >'$day'")
  576. ->where("deal_time <'$day 23:59:59'")
  577. ->where('deal_type', 5)
  578. ->sum('money');
  579. $insert['balance'] = $day_accounting - $tixian + $balance ;
  580. }
  581. Db::name('enterprise_day_bill')->insertGetId($insert);
  582. $month_list[] = date('Y-m', strtotime('-4 month'));
  583. $month_list[] = date('Y-m', strtotime('-3 month'));
  584. $month_list[] = date('Y-m', strtotime('-2 month'));
  585. $month_list[] = date('Y-m', strtotime('-1 month'));
  586. $month_list[] = date('Y-m');
  587. foreach ($month_list as $month) {
  588. Db::name('enterprise_month_bill')->where('mer_id',$mer_id)->where('month', $month)->delete();
  589. $flow_query_month_clone = clone $day_flow_query_month;
  590. $accounting_query_month_clone = clone $accounting_query_month;
  591. $expenditure_query_month_clone = clone $expenditure_query_month;
  592. $startDate = date('Y-m-01 00:00:00', strtotime($month));
  593. $endDate = date("Y-m-d 00:00:00", strtotime('+1 month', strtotime($month)));
  594. // 月订单流水
  595. $money_flow = $flow_query_month_clone->whereBetween('deal_time', [$startDate, $endDate])->sum('money');
  596. // 月入账总额
  597. $money_accounting = $accounting_query_month_clone->whereBetween('deal_time', [$startDate, $endDate])->sum('money');
  598. // 月支出总额
  599. $money_expenditure = $expenditure_query_month_clone->whereBetween('deal_time', [$startDate, $endDate])->sum('money');
  600. $insert2 = [];
  601. $insert2['month'] = $month;
  602. $insert2['mer_id'] = $mer_id;
  603. $insert2['flow'] = $money_flow;
  604. $insert2['expenditure'] = $money_expenditure;
  605. $insert2['accounting'] = $money_accounting;
  606. Db::name('enterprise_month_bill')->insertGetId($insert2);
  607. }
  608. }
  609. /**
  610. * 定时获取 交易类型 1订单入账 2佣金提现支出 3养老金(红积分兑换订单)
  611. */
  612. public function platform_income_detail_get()
  613. {
  614. // 1、获取所有 商户 商户名称非空, 状态为正常、商户状态为开启
  615. $merchant_list = Db::name('merchant')
  616. ->where('status', 1)
  617. ->where('mer_state', 1)
  618. ->where("mer_name != ''")
  619. ->column('mer_id');
  620. // 2、插入日账单、月账单
  621. // $Reconciliation = app()->make(Reconciliation::class);
  622. $Reconciliation = $this;
  623. // 3、获取 已有的 平台收支明细,并创建 唯一的 key
  624. $unique_list = [];
  625. $enterprise_platform_income_detail_list = Db::name('enterprise_platform_income_detail')
  626. ->select()
  627. ->toArray();
  628. foreach ($enterprise_platform_income_detail_list as $item) {
  629. // deal_type : '交易类型 1自营订单入账(商户) 2佣金提现到账(商户) 3订单支付 4商户佣金提现 5用户佣金提现 6订单入账 7 创客自营订单让利 '
  630. // user_extra_id : 提现表id
  631. $unique_list[] = $item['deal_type'] . $item['uid'] . $item['order_sn'] . $item['order_id'] . $item['user_extra_id'] . $item['mer_id'];
  632. }
  633. // 4、循环所有商户ID
  634. foreach ($merchant_list as $mer_id) {
  635. /** @var OrderMerchantRepository $OrderMerchantRepository */
  636. $OrderMerchantRepository = app()->make(OrderMerchantRepository::class);
  637. $is_first = empty($enterprise_platform_income_detail_list);
  638. // 1自营订单入账金额=已结算订单金额-运费-养老金-汇付通道服务费; 订单结算的时候才统计
  639. // 查询 该商户 所有的 平台订单(已支付、平台订单、已结算)
  640. $store_order_list = Db::name('store_order')
  641. ->where('mer_id', $mer_id)
  642. ->where('paid', 1)
  643. ->where('douhuomall', 0)
  644. ->where('is_settlement', 1)
  645. ->order('order_id', 'desc')
  646. // ->limit(500)
  647. ->select()
  648. ->toArray();
  649. foreach ($store_order_list as $store_order) {
  650. // 判断该笔订单是否已 存在 平台收支明细表 的记录中
  651. if (in_array('1' . $store_order['uid'] . $store_order['order_sn'] . $store_order['order_id'] . '0' . $mer_id, $unique_list)) continue;
  652. // 支付方式,有疑问??
  653. $pay_type = $store_order['pay_type'];
  654. if (!in_array($pay_type, [0, 1])) continue;
  655. // 用户订单表
  656. $group_order = Db::name('store_group_order')
  657. ->alias('sgo')
  658. ->where('sgo.group_order_id', $store_order['group_order_id'])
  659. ->find();
  660. if (empty($group_order)) continue;
  661. // 获取 店铺奖金设置
  662. $shop_bonus_setting = merchantConfig($store_order['mer_id'], 'shop_bonus_setting') ?: [
  663. 'shop_bonus_rate' => 30,
  664. 'yanglao_rate' => 5,
  665. ];
  666. // 获取这笔订单发放的养老金 TODO 这里查询应该不对,有可能查询出多列
  667. $yanglao = Db::name('user_bill')
  668. ->where('order_sn', $store_order['order_sn'])
  669. ->where('commission_type', 5)
  670. ->value('number');
  671. $ru_money = 0;
  672. // 如果pay_type 不是 0 ??
  673. if ($pay_type != 0) {
  674. // 根据订单编号 查询 订单分账表 状态是 已分账成功的数据
  675. $store_split_order = Db::name('store_split_order')
  676. ->where('group_order_id', $group_order['group_order_sn'])
  677. ->where('status', 1)
  678. ->find();
  679. if (empty($store_split_order)) continue;
  680. if ($pay_type == 1) {
  681. //微信
  682. if ($group_order['pay_wx'] == 3) {
  683. $api_key = 'api_live_b0a687ec-5450-4ada-a0e4-65bac0f46871';
  684. } else {
  685. $api_key = 'api_live_90ef02e4-54ac-41ee-adf1-e4927d23d58f';
  686. }
  687. } else {
  688. //支付宝
  689. $api_key = 'api_live_b23537ed-64b8-45d6-832e-fb228aa9e0a9';
  690. }
  691. // 汇付支付id
  692. $params['payment_confirm_id'] = $store_split_order['hf_pay_id'];
  693. $params['api_key'] = $api_key;
  694. //查询支付确认对象
  695. Db::name("log")->insert(array('data' => '汇付查询支付确认对象参数-----' . json_encode($params)));//日志记录
  696. $res = $this->payment_confirm_query_traits($params);
  697. Db::name("log")->insert(array('data' => '汇付查询支付确认对象返回-----' . json_encode($res)));//日志记录
  698. // 获取分账后一个工作日时间
  699. $close_time = $this->getNextWorkday(date('Y-m-d H:i:s', strtotime('+1 days', strtotime($store_order['pay_time']))));
  700. // 如果成功查询到 分账信息 则更新订单的 汇付通道服务费 汇付分账成功时间
  701. if (isset($res['status'])) {
  702. Db::name('store_order')->where('order_id', $store_order['order_id'])->update([
  703. 'hf_fee_amt' => $res['fee_amt'],
  704. 'hf_clear_time' => $close_time
  705. ]);
  706. }
  707. //
  708. if (isset($res['status']) && time() > strtotime($close_time)) {
  709. if ($store_order['mer_id'] == 496) {
  710. $ru_money = $store_order['pay_price'] - $yanglao - $res['fee_amt'];
  711. } else {
  712. $ru_money = $store_order['pay_price'] * (1 - $shop_bonus_setting['shop_bonus_rate'] / 100) - $res['fee_amt'] + +$store_order['pay_postage'];
  713. }
  714. $store_order['pay_time'] = '';//线上支付的
  715. } else {
  716. continue;
  717. }
  718. } else {
  719. // 订单金额+运费
  720. if ($store_order['mer_id'] == 496) {
  721. $ru_money = $store_order['pay_price'] - $yanglao;
  722. } else {
  723. $ru_money = $store_order['pay_price'] * (1 - $shop_bonus_setting['shop_bonus_rate'] / 100) + $store_order['pay_postage'];
  724. }
  725. }
  726. Db::name('enterprise_platform_income_detail')
  727. ->insert([
  728. 'mer_id' => $mer_id,
  729. 'uid' => $store_order['uid'],
  730. 'title' => '自营订单入账',
  731. 'deal_order_sn' => $OrderMerchantRepository->getNewOrderId('jy2'),
  732. 'deal_time' => isset($close_time) ? $close_time : ((isset($store_order['pay_time']) && $store_order['pay_time']) ? $store_order['pay_time'] : date('Y-m-d H:i:s')),
  733. 'money' => $ru_money,
  734. 'deal_type' => 1,
  735. 'order_id' => $store_order['order_id'],
  736. 'order_sn' => $store_order['order_sn'],
  737. 'user_extra_id' => '',
  738. 'pm' => 1,
  739. 'create_time' => date('Y-m-d H:i:s'),
  740. ]);
  741. unset($close_time);
  742. }
  743. //2佣金提现到账 提现成功统计
  744. // $user_extract_list = Db::name('user_extract')
  745. // ->field('extract_id,uid,extract_type,extract_price,service_money,order_sn,status_time')
  746. // ->where('status', 1)
  747. // ->where('withdrawal_type', 3)
  748. // ->where('extract_type', '<>', 4)
  749. // ->when($uids, function ($query) use ($uids) {
  750. // $query->whereIn('uid', $uids);
  751. // })
  752. // ->order('extract_id', 'desc')
  753. //// ->limit(100)
  754. // ->select()
  755. // ->toArray();
  756. // foreach ($user_extract_list as $user_extract) {
  757. // if (in_array('2' . $user_extract['uid'] . $user_extract['order_sn'] . '0' . $user_extract['extract_id'], $unique_list)) continue;
  758. // $enterprise_platform_income_detail = Db::name('enterprise_platform_income_detail')
  759. // ->where('deal_type', 2)
  760. // ->where('user_extra_id', $user_extract['extract_id'])
  761. // ->find();
  762. // if (!$enterprise_platform_income_detail) {
  763. // Db::name('enterprise_platform_income_detail')
  764. // ->insert([
  765. // 'mer_id' => $mer_id,
  766. // 'uid' => $user_extract['uid'],
  767. // 'title' => '佣金提现支出',
  768. // 'deal_order_sn' => $OrderMerchantRepository->getNewOrderId('jy2'),
  769. // 'deal_time' => $user_extract['status_time'],
  770. // 'money' => bcsub($user_extract['extract_price'], $user_extract['service_money'], 2),
  771. // 'deal_type' => 2,
  772. // 'order_id' => '',
  773. // 'order_sn' => $user_extract['order_sn'],
  774. // 'user_extra_id' => $user_extract['extract_id'],
  775. // 'pm' => 1,
  776. // 'create_time' => date('Y-m-d H:i:s'),
  777. // ]);
  778. // }
  779. // }
  780. $start_time = '2024-04-01';
  781. for ($i = 0; $i < 1000; $i++) {
  782. $day = date('Y-m-d', strtotime("+{$i} days", strtotime($start_time)));
  783. if (strtotime($day) > time()) {
  784. break;
  785. }
  786. $Reconciliation->cron($day, $mer_id);
  787. }
  788. }
  789. // 计算平台
  790. //交易类型 1自营订单入账(商户) 2佣金提现到账(商户) 3订单支付 4商户佣金提现 5用户佣金提现 6订单入账 7 创客自营订单让利
  791. $mer_id = 0;
  792. // 3 订单支付 供应链订单结算后入账到平台的金额
  793. $store_order_list = Db::name('store_order')
  794. ->where('paid', 1)
  795. ->order('order_id', 'desc')
  796. // ->limit(500)
  797. ->select()
  798. ->toArray();
  799. foreach ($store_order_list as $store_order) {
  800. if (in_array('3' . $store_order['uid'] . $store_order['order_sn'] . $store_order['order_id'] . '0' . $mer_id, $unique_list)) continue;
  801. $group_order = Db::name('store_group_order')
  802. ->alias('sgo')
  803. ->where('sgo.group_order_id', $store_order['group_order_id'])
  804. ->find();
  805. if (empty($group_order)) continue;
  806. $store_split_order = Db::name('store_split_order')
  807. ->where('group_order_id', $group_order['group_order_sn'])
  808. ->where('status', 1)
  809. ->find();
  810. if (empty($store_split_order)) continue;
  811. $close_time = $this->getNextWorkday(date('Y-m-d H:i:s', strtotime('+1 days', strtotime($store_order['pay_time']))));
  812. Db::name('enterprise_platform_income_detail')
  813. ->insert([
  814. 'mer_id' => $mer_id,
  815. 'uid' => $store_order['uid'],
  816. 'title' => '订单支付',
  817. 'deal_order_sn' => $OrderMerchantRepository->getNewOrderId('jy4'),
  818. 'deal_time' => isset($close_time) ? $close_time : ((isset($store_order['pay_time']) && $store_order['pay_time']) ? $store_order['pay_time'] : date('Y-m-d H:i:s')),
  819. 'money' => $store_order['pay_price'] + $store_order['pay_postage'],
  820. 'deal_type' => 3,
  821. 'order_id' => $store_order['order_id'],
  822. 'order_sn' => $store_order['order_sn'],
  823. 'user_extra_id' => '',
  824. 'pm' => 1,
  825. 'create_time' => date('Y-m-d H:i:s'),
  826. ]);
  827. }
  828. //5用户佣金提现
  829. $user_extract_list = Db::name('user_extract')
  830. ->field('extract_id,uid,extract_type,extract_price,service_money,order_sn,status_time')
  831. ->where('status', 1)
  832. ->order('extract_id', 'desc')
  833. // ->limit(100)
  834. ->select()
  835. ->toArray();
  836. foreach ($user_extract_list as $user_extract) {
  837. if (in_array('5' . $user_extract['uid'] . $user_extract['order_sn'] . '0' . $user_extract['extract_id'] . $mer_id, $unique_list)) continue;
  838. Db::name('enterprise_platform_income_detail')
  839. ->insert([
  840. 'mer_id' => $mer_id,
  841. 'uid' => $user_extract['uid'],
  842. 'title' => '用户佣金提现',
  843. 'deal_order_sn' => $OrderMerchantRepository->getNewOrderId('jy2'),
  844. 'deal_time' => $user_extract['status_time'],
  845. 'money' => bcsub($user_extract['extract_price'], $user_extract['service_money'], 2),
  846. 'deal_type' => 5,
  847. 'order_id' => '',
  848. 'order_sn' => $user_extract['order_sn'],
  849. 'user_extra_id' => $user_extract['extract_id'],
  850. 'pm' => 0,
  851. 'create_time' => date('Y-m-d H:i:s'),
  852. ]);
  853. }
  854. // 6订单入账:支付成功的订单数据 供应链订单
  855. $store_order_list = Db::name('store_order')
  856. ->where('paid', 1)
  857. ->where('douhuomall', 1)
  858. ->where('is_settlement', 1)
  859. ->order('order_id', 'desc')
  860. // ->limit(500)
  861. ->select()
  862. ->toArray();
  863. foreach ($store_order_list as $store_order) {
  864. if (in_array('6' . $store_order['uid'] . $store_order['order_sn'] . $store_order['order_id'] . '0' . $mer_id, $unique_list)) continue;
  865. $pay_type = $store_order['pay_type'];
  866. if (!in_array($pay_type, [0, 1])) continue;
  867. $group_order = Db::name('store_group_order')
  868. ->alias('sgo')
  869. ->where('sgo.group_order_id', $store_order['group_order_id'])
  870. ->find();
  871. if (empty($group_order)) continue;
  872. $yanglao = Db::name('user_bill')
  873. ->where('order_sn', $store_order['order_sn'])
  874. ->where('commission_type', 5)
  875. ->value('number');
  876. $ru_money = 0;
  877. $shop_bonus_setting = merchantConfig($store_order['mer_id'], 'shop_bonus_setting') ?: [
  878. 'shop_bonus_rate' => 30,
  879. 'yanglao_rate' => 5,
  880. ];
  881. if ($pay_type != 0) {
  882. $store_split_order = Db::name('store_split_order')
  883. ->where('group_order_id', $group_order['group_order_sn'])
  884. ->find();
  885. if (empty($store_split_order)) continue;
  886. if (!$store_order['hf_fee_amt']) {
  887. if ($pay_type == 1) {
  888. //微信
  889. if ($group_order['pay_wx'] == 3) {
  890. $api_key = 'api_live_b0a687ec-5450-4ada-a0e4-65bac0f46871';
  891. } else {
  892. $api_key = 'api_live_90ef02e4-54ac-41ee-adf1-e4927d23d58f';
  893. }
  894. } else {
  895. //支付宝
  896. $api_key = 'api_live_b23537ed-64b8-45d6-832e-fb228aa9e0a9';
  897. }
  898. $params['payment_confirm_id'] = $store_split_order['hf_pay_id'];
  899. $params['api_key'] = $api_key;
  900. //查询支付确认对象
  901. Db::name("log")->insert(array('data' => '汇付查询支付确认对象参数-----' . json_encode($params)));//日志记录
  902. $res = $this->payment_confirm_query_traits($params);
  903. Db::name("log")->insert(array('data' => '汇付查询支付确认对象返回-----' . json_encode($res)));//日志记录
  904. if (isset($res['status'])) {
  905. Db::name('store_order')->where('order_id', $store_order['order_id'])->update([
  906. 'hf_fee_amt' => $res['fee_amt'],
  907. 'hf_clear_time' => $close_time
  908. ]);
  909. $store_order['hf_fee_amt'] = $res['fee_amt'];
  910. }
  911. }
  912. // 获取分账后一个工作日时间
  913. $close_time = $this->getNextWorkday(date('Y-m-d H:i:s', strtotime('+1 days', strtotime($store_order['pay_time']))));
  914. if (isset($res['status']) && time() > strtotime($close_time)) {
  915. if ($store_order['mer_id'] == 496) {
  916. $ru_money = $store_order['pay_price'] - $yanglao - $store_order['hf_fee_amt'];
  917. } else {
  918. $ru_money = $store_order['pay_price'] - $yanglao;
  919. }
  920. $store_order['pay_time'] = '';//线上支付的
  921. } else {
  922. continue;
  923. }
  924. } else {
  925. // 订单金额+运费
  926. if ($store_order['mer_id'] == 496) {
  927. $ru_money = $store_order['pay_price'] - $yanglao;
  928. } else {
  929. $ru_money = $store_order['pay_price'] - $yanglao;
  930. }
  931. }
  932. Db::name('enterprise_platform_income_detail')
  933. ->insert([
  934. 'mer_id' => $mer_id,
  935. 'uid' => $store_order['uid'],
  936. 'title' => '订单入账',
  937. 'deal_order_sn' => $OrderMerchantRepository->getNewOrderId('jy2'),
  938. 'deal_time' => isset($close_time) ? $close_time : ((isset($store_order['pay_time']) && $store_order['pay_time']) ? $store_order['pay_time'] : date('Y-m-d H:i:s')),
  939. 'money' => $ru_money,
  940. 'deal_type' => 6,
  941. 'order_id' => $store_order['order_id'],
  942. 'order_sn' => $store_order['order_sn'],
  943. 'user_extra_id' => '',
  944. 'pm' => 1,
  945. 'create_time' => date('Y-m-d H:i:s'),
  946. ]);
  947. unset($close_time);
  948. }
  949. //7 创客自营订单让利=创客自营订单金额*分润比例-(创客自营订单金额-运费)*养老金比例
  950. $store_order_list = Db::name('store_order')
  951. ->where('paid', 1)
  952. ->where('is_settlement', 1)
  953. ->where('douhuomall', 0)
  954. ->order('order_id', 'desc')
  955. // ->limit(500)
  956. ->select()
  957. ->toArray();
  958. foreach ($store_order_list as $store_order) {
  959. if (in_array('7' . $store_order['uid'] . $store_order['order_sn'] . $store_order['order_id'] . '0' . $mer_id, $unique_list)) continue;
  960. $shop_bonus_setting = merchantConfig($store_order['mer_id'], 'shop_bonus_setting') ?: [
  961. 'shop_bonus_rate' => 30,
  962. 'yanglao_rate' => 5,
  963. ];
  964. $pay_type = $store_order['pay_type'];
  965. if ($pay_type != 0) {
  966. $group_order = Db::name('store_group_order')
  967. ->alias('sgo')
  968. ->where('sgo.group_order_id', $store_order['group_order_id'])
  969. ->find();
  970. if (empty($group_order)) continue;
  971. $store_split_order = Db::name('store_split_order')
  972. ->where('group_order_id', $group_order['group_order_sn'])
  973. ->find();
  974. if (empty($store_split_order)) continue;
  975. $close_time = $this->getNextWorkday(date('Y-m-d H:i:s', strtotime('+1 days', strtotime($store_order['pay_time']))));
  976. if (!$store_order['hf_fee_amt']) {
  977. $store_split_order = Db::name('store_split_order')
  978. ->where('group_order_id', $group_order['group_order_sn'])
  979. ->where('status', 1)
  980. ->find();
  981. if (empty($store_split_order)) continue;
  982. if ($pay_type == 1) {
  983. //微信
  984. if ($group_order['pay_wx'] == 3) {
  985. $api_key = 'api_live_b0a687ec-5450-4ada-a0e4-65bac0f46871';
  986. } else {
  987. $api_key = 'api_live_90ef02e4-54ac-41ee-adf1-e4927d23d58f';
  988. }
  989. } else {
  990. //支付宝
  991. $api_key = 'api_live_b23537ed-64b8-45d6-832e-fb228aa9e0a9';
  992. }
  993. $params['payment_confirm_id'] = $store_split_order['hf_pay_id'];
  994. $params['api_key'] = $api_key;
  995. //查询支付确认对象
  996. Db::name("log")->insert(array('data' => '汇付查询支付确认对象参数-----' . json_encode($params)));//日志记录
  997. $res = $this->payment_confirm_query_traits($params);
  998. Db::name("log")->insert(array('data' => '汇付查询支付确认对象返回-----' . json_encode($res)));//日志记录
  999. // 获取分账后一个工作日时间
  1000. $close_time = $this->getNextWorkday(date('Y-m-d H:i:s', strtotime('+1 days', strtotime($store_order['pay_time']))));
  1001. if (isset($res['status'])) {
  1002. Db::name('store_order')->where('order_id', $store_order['order_id'])->update([
  1003. 'hf_fee_amt' => $res['fee_amt'],
  1004. 'hf_clear_time' => $close_time
  1005. ]);
  1006. $store_order['hf_fee_amt'] = $res['fee_amt'];
  1007. }
  1008. }
  1009. $yanglao = Db::name('user_bill')
  1010. ->where('order_sn', $store_order['order_sn'])
  1011. ->where('commission_type', 5)
  1012. ->value('number');
  1013. if (isset($res['status']) && time() > strtotime($close_time)) {
  1014. if ($store_order['mer_id'] == 496) {
  1015. $ru_money = $store_order['pay_price'] - $yanglao - $store_order['hf_fee_amt'];
  1016. } else {
  1017. $ru_money = ($store_order['pay_price'] * $shop_bonus_setting['shop_bonus_rate'] / 100) - $yanglao;
  1018. }
  1019. $store_order['pay_time'] = '';//线上支付的
  1020. } else {
  1021. continue;
  1022. }
  1023. }else{
  1024. if ($store_order['mer_id'] == 496) {
  1025. $ru_money = $store_order['pay_price'] - $yanglao;
  1026. } else {
  1027. $ru_money = ($store_order['pay_price'] * $shop_bonus_setting['shop_bonus_rate'] / 100) - $yanglao;
  1028. }
  1029. }
  1030. Db::name('enterprise_platform_income_detail')
  1031. ->insert([
  1032. 'mer_id' => $mer_id,
  1033. 'uid' => $store_order['uid'],
  1034. 'title' => '创客自营订单让利',
  1035. 'deal_order_sn' => $OrderMerchantRepository->getNewOrderId('jy4'),
  1036. 'deal_time' => isset($close_time) ? $close_time : ((isset($store_order['pay_time']) && $store_order['pay_time']) ? $store_order['pay_time'] : date('Y-m-d H:i:s')),
  1037. 'money' => $ru_money,
  1038. 'deal_type' => 7,
  1039. 'order_id' => $store_order['order_id'],
  1040. 'order_sn' => $store_order['order_sn'],
  1041. 'user_extra_id' => '',
  1042. 'pm' => 1,
  1043. 'create_time' => date('Y-m-d H:i:s'),
  1044. ]);
  1045. unset($close_time);
  1046. }
  1047. $start_time = '2024-04-01';
  1048. for ($i = 0; $i < 1000; $i++) {
  1049. $day = date('Y-m-d', strtotime("+{$i} days", strtotime($start_time)));
  1050. if (strtotime($day) > time()) {
  1051. break;
  1052. }
  1053. $Reconciliation->cron($day, 0);
  1054. }
  1055. return app('json')->success('获取平台收支明细成功');
  1056. }
  1057. public function clear_platform_income_detail()
  1058. {
  1059. Db::name('enterprise_platform_income_detail')->where('id', '>', 0)
  1060. ->delete();
  1061. }
  1062. function getNextWorkday($date)
  1063. {
  1064. // 设置工作日数组
  1065. $workdays = array(1, 2, 3, 4, 5); // 默认为周一到周五
  1066. // 将日期字符串转换为时间戳
  1067. $timestamp = strtotime($date);
  1068. // 获取该日期的星期几
  1069. $weekday = date('N', $timestamp);
  1070. // 如果不是工作日,则增加一天直到是工作日
  1071. while (!in_array($weekday, $workdays)) {
  1072. $timestamp += (24 * 3600); // 增加一天
  1073. $weekday = date('N', $timestamp); // 更新星期几
  1074. }
  1075. // 返回下一个工作日的日期字符串
  1076. return date('Y-m-d H:i:s', $timestamp);
  1077. }
  1078. /**
  1079. * @param $paymnet_params
  1080. * @return array
  1081. * 查询支付确认对象
  1082. */
  1083. public
  1084. function payment_confirm_query_traits($paymnet_params)
  1085. {
  1086. $merber = new PaymentConfirm();
  1087. $merber->query($paymnet_params);
  1088. # 返回查询结果
  1089. $merber->isError();
  1090. return $merber->result;
  1091. }
  1092. //服务器配置,一般是默认配置
  1093. private $CharSet = "UTF-8"; //设定邮件编码
  1094. private $SMTPDebug = 0; // 调试模式输出
  1095. private $isSMTP = true; // 使用SMTP
  1096. private $Host = 'smtp.163.com'; // SMTP服务器
  1097. private $SMTPAuth = true; // 允许 SMTP 认证
  1098. private $Username = 'username'; // SMTP 用户名 即邮箱的用户名
  1099. private $Password = 'MHIKZOXVPTGNVOMU'; // SMTP 密码 部分邮箱是授权码(例如163邮箱)
  1100. private $SMTPSecure = 'ssl'; // 允许 TLS 或者ssl协议
  1101. private $Port = 465; // 服务器端口 25 或者465 具体要看邮箱服务器支持
  1102. //修改成自己的邮箱
  1103. private $From = 'formalverification@163.com'; //发件人邮箱
  1104. private $FromName = 'makalo'; //发件人的用户昵称
  1105. //邮件对象
  1106. private $mail;
  1107. //一般只有用户名和密码还有端口会变动, 所以这三个参数可以创建对象动态指定,也可以直接写死
  1108. public function mallInit($Username = '', $Password = '', $Port = '')
  1109. {
  1110. if (!empty($Username)) {
  1111. $this->Username = $Username;
  1112. }
  1113. if (!empty($Password)) {
  1114. $this->Password = $Password;
  1115. }
  1116. if (!empty($Port)) {
  1117. $this->Port = $Port;
  1118. }
  1119. //为true表示启用异常
  1120. $mail = new PHPMailer(true);
  1121. //服务器配置
  1122. $mail->CharSet = $this->CharSet; //设定邮件编码
  1123. $mail->SMTPDebug = $this->SMTPDebug; // 调试模121212 1式输出
  1124. if ($this->isSMTP === true) {
  1125. $mail->isSMTP(); // 使用SMTP
  1126. }
  1127. $mail->Host = $this->Host; // SMTP服务器
  1128. $mail->SMTPAuth = $this->SMTPAuth; // 允许 SMTP 认证
  1129. $mail->Username = $this->Username; // SMTP 用户名 即邮箱的用户名
  1130. $mail->Password = $this->Password; // SMTP 密码 部分邮箱是授权码(例如163邮箱)
  1131. $mail->SMTPSecure = $this->SMTPSecure; // 允许 TLS 或者ssl协议
  1132. $mail->Port = $this->Port; // 服务器端口 25 或者465 具体要看邮箱服务器支持
  1133. $mail->setFrom($this->From, $this->FromName); //发件人
  1134. $this->mail = $mail;
  1135. }
  1136. /**
  1137. * 发送邮件
  1138. * @param array $sendAddress 收件人地址数组, 如果为单值数组则只写入收件地址,如果为键值数组则还写入收件人名称
  1139. * @param array $Attachment 附件数组,如果为单值数组则为添加附件,如果为键值数组则添加附件并且重命名
  1140. * @param bool $isHtml 是否以html文档格式发送
  1141. * @param string $Subject 邮件主题
  1142. * @param string $Body 邮件内容,如果以html格式可以写入html
  1143. * @param string $AltBody 如果为单值数组则只写入收件地址,如果为键值数组则还写入收件人名称
  1144. * @param array $CC 抄送地址数组, 如果为单值数组则只写入收件地址,如果为键值数组则还写入收件人名称
  1145. * @param array $BCC 密送地址数组,如果为单值数组则只写入收件地址,如果为键值数组则还写入收件人名称
  1146. * @return bool 是否发送成功
  1147. */
  1148. public function sendEMail($sendAddress = [], $Subject = '', $Body = '', $AltBody = '', $Attachment = [], $isHtml = true, $CC = [], $BCC = [])
  1149. {
  1150. try {
  1151. //必填参数校验
  1152. if (empty($sendAddress) || empty($Subject) || empty($Body)) {
  1153. return false;
  1154. }
  1155. //收件人
  1156. foreach ($sendAddress as $key => $value) {
  1157. if (is_int($key)) {
  1158. // 处理单值
  1159. $this->mail->addAddress($value);
  1160. } else {
  1161. // 处理键值
  1162. $this->mail->addAddress($value, $key);
  1163. }
  1164. }
  1165. //附件
  1166. if (!empty($Attachment)) {
  1167. foreach ($Attachment as $key => $value) {
  1168. if (is_int($key)) {
  1169. // 处理单值
  1170. $this->mail->addAttachment($value);
  1171. } else {
  1172. // 处理键值
  1173. $this->mail->addAttachment($value, $key);
  1174. }
  1175. }
  1176. }
  1177. //抄送
  1178. if (!empty($CC)) {
  1179. //抄送不为空
  1180. foreach ($CC as $key => $value) {
  1181. if (is_int($key)) {
  1182. // 处理单值
  1183. $this->mail->addCC($value);
  1184. } else {
  1185. // 处理键值
  1186. $this->mail->addCC($value, $key);
  1187. }
  1188. }
  1189. }
  1190. //密送
  1191. if (!empty($BCC)) {
  1192. //密送不为空
  1193. foreach ($BCC as $key => $value) {
  1194. if (is_int($key)) {
  1195. // 处理单值
  1196. $this->mail->addBCC($value);
  1197. } else {
  1198. // 处理键值
  1199. $this->mail->addBCC($value, $key);
  1200. }
  1201. }
  1202. }
  1203. //回复的时候回复给哪个邮箱 建议和发件人一致
  1204. $this->mail->addReplyTo($this->From, $this->FromName);
  1205. //Content
  1206. // 是否以HTML文档格式发送 发送后客户端可直接显示对应HTML内容
  1207. $this->mail->isHTML($isHtml);
  1208. //邮件主题
  1209. $this->mail->Subject = $Subject;
  1210. //邮件内容
  1211. $this->mail->Body = $Body;
  1212. //如果邮件客户端不支持HTML则显示此内容
  1213. $this->mail->AltBody = $AltBody;
  1214. //发送
  1215. $this->mail->send();
  1216. return [
  1217. 'code' => 200,
  1218. ];
  1219. } catch (\Exception $e) {
  1220. return [
  1221. 'code' => 400,
  1222. 'message' => $this->mail->ErrorInfo
  1223. ];
  1224. }
  1225. }
  1226. public function take()
  1227. {
  1228. set_time_limit(0);
  1229. $this->mallInit('formalverification@163.com', 'SYECAWFLLTUPMDRP');
  1230. $this->sendEMail(['389123492@qq.com', '420132441@qq.com'], '结算定时', "开始执行" . date('Y-m-d H:i:s'), '如果邮件客户端不支持HTML则显示此内容');
  1231. $mallStr = '';
  1232. // Log::info('执行一次1 '.date('H:i') );
  1233. // return ;
  1234. // $storeOrderRepository = app()->make(StoreOrderRepository::class);
  1235. $key_list = [
  1236. 1 => 'api_live_b23537ed-64b8-45d6-832e-fb228aa9e0a9',
  1237. 2 => 'api_live_90ef02e4-54ac-41ee-adf1-e4927d23d58f',
  1238. 3 => 'api_live_b0a687ec-5450-4ada-a0e4-65bac0f46871'
  1239. ];
  1240. $appid_list = [
  1241. 1 => 'app_44108546-d27a-48ee-88c1-84b45b75114f',
  1242. 2 => 'app_0827b960-b932-45ec-b800-4e850091b419',
  1243. 3 => 'app_383a75dd-c03d-44ab-8f58-92c60fe9b9d0'
  1244. ];
  1245. //
  1246. // $payment_id = ShouxinyiApiRequest::getOrderNumber('split');
  1247. // $insertData = [
  1248. // [
  1249. // 'mid' => 0,
  1250. // 'requestId' => $payment_id,
  1251. // 'group_order_id' => 'WX171955791230553863',
  1252. // 'splitAmount' => 0.25,
  1253. // 'status' => 0
  1254. // ],
  1255. // ];
  1256. // $div_members[] = [
  1257. // 'member_id' => 'member_personal_16704641278422',
  1258. // 'amount' => '1.00',
  1259. // 'fee_flag' => 'Y'
  1260. // ];
  1261. // //////分账表
  1262. // Db::name("store_split_order")->insertAll($insertData);
  1263. // /// 分账表end
  1264. //
  1265. // $params = [
  1266. // 'payment_id' => '002212024062814583210652657343702200320',
  1267. // 'order_no' => $payment_id,
  1268. // 'confirm_amt' => '1.00',
  1269. // 'div_members' => $div_members
  1270. // ];
  1271. //
  1272. // $params['api_key'] = $key_list[3];
  1273. //
  1274. // var_dump($params);
  1275. // Db::name("log")->insert(array('data' => '汇付延时分账参数-----' . json_encode($params)));//日志记录
  1276. // $res = $storeOrderRepository->payment_confirm_create_traits($params);
  1277. // Db::name("log")->insert(array('data' => '汇付延时分账-----' . json_encode($res)));//日志记录
  1278. // var_dump($res);
  1279. // // 分账
  1280. // return;
  1281. $merchant_member_list = Db::name('merchant_member')
  1282. // ->where('member_id', 'member_personal_16704641278422')
  1283. ->column('mer_id,type,member_id,settle_account_id');
  1284. foreach ($merchant_member_list as $merchant_member) {
  1285. $mer_id = $merchant_member['mer_id'];
  1286. if (empty($mer_id))
  1287. continue;
  1288. if (empty($merchant_member['settle_account_id']))
  1289. continue;
  1290. $params = [
  1291. 'app_id' => $appid_list[$merchant_member['type']],
  1292. 'member_id' => $merchant_member['member_id'],
  1293. 'settle_account_id' => $merchant_member['settle_account_id'],
  1294. 'api_key' => $key_list[$merchant_member['type']]
  1295. ];
  1296. $merber = new SettleAccount();
  1297. $merber->balance($params);
  1298. $merber->result;
  1299. // var_dump($merber->result);
  1300. if (isset($merber->result[1])) {
  1301. $result = json_decode($merber->result[1], true);
  1302. $result = json_decode($result['data'], true);
  1303. $result['avl_balance'] = $result['avl_balance'] ?? 0;
  1304. if ($result['avl_balance'] > 0) {
  1305. $payment_id = ShouxinyiApiRequest::getOrderNumber('split');
  1306. $params = [
  1307. 'order_no' => $payment_id,
  1308. 'app_id' => $appid_list[$merchant_member['type']],
  1309. 'cash_type' => 'T1',
  1310. 'cash_amt' => sprintf("%01.2f", $result['avl_balance']),
  1311. 'member_id' => $merchant_member['member_id'],
  1312. 'api_key' => $key_list[$merchant_member['type']]
  1313. ];
  1314. $yanglao_member_ids = ['jsdk_member_wx21710232183139', 'jsdk_member_ali1710232187326'];
  1315. if (in_array($merchant_member['member_id'], $yanglao_member_ids)) {
  1316. $params['remark'] = '天地博爱科技~养老金';
  1317. }
  1318. Db::name("log")->insert(array('data' => '汇付取现参数-----' . json_encode($params)));//日志记录
  1319. $merber = new Drawcash();
  1320. $merber->create($params);
  1321. # 返回查询结果
  1322. $merber->isError();
  1323. $res = $merber->result;
  1324. Db::name("log")->insert(array('data' => '汇付延时分账-----' . json_encode($res))); //日志记录
  1325. Db::name("log")->insert(array('data' => "mer_id {$mer_id} 请求分账{$result['avl_balance']}元-----"));//日志记录
  1326. var_dump("mer_id {$mer_id} 请求分账{$result['avl_balance']}元-----");
  1327. $mallStr = $mallStr . "-----mer_id {$mer_id} 请求分账{$result['avl_balance']}元-----<br/>";
  1328. }
  1329. }
  1330. }
  1331. echo date('Y-m-d H:i:s') . '执行结束' . "\r\n";
  1332. $this->sendEMail(['389123492@qq.com', '420132441@qq.com'], '结算定时', "执行结束<br/>" . $mallStr . date('Y-m-d H:i:s'), '如果邮件客户端不支持HTML则显示此内容');
  1333. }
  1334. use HuiPay;
  1335. public function cesexx(){
  1336. // $store_product = Db::name('store_product')->where('mer_id', 439)->select();
  1337. // foreach ($store_product as $key=>$online) {
  1338. // $spu_id = $online['spu_id'];
  1339. // $product_id = $online['product_id'];
  1340. // $data = Db::name('douhuomall')->where('spu_id', $spu_id)->find();
  1341. // if(!$data) continue;
  1342. // //商品主图
  1343. // $spuId_info=json_decode($data['spuId_info'],true);
  1344. // $slider_image=$spuId_info['detail_img_list']??'';
  1345. // $image=$spuId_info['cover_url']??'';
  1346. // try {
  1347. // $slider_image = implode(',',json_decode($slider_image,true));
  1348. // }catch (\Exception $exception){
  1349. // $slider_image = $image;
  1350. // }
  1351. // //更新产品图片数据
  1352. // $product_insert_data=[
  1353. // 'image'=>$image,
  1354. // 'slider_image'=>$slider_image,
  1355. // ];
  1356. // Db::name('store_product')->where('product_id',$product_id)->update($product_insert_data);
  1357. // echo '更新产品图片数据成功'.json_encode($product_insert_data);
  1358. // echo '产品id:'.$product_id;
  1359. // $detail = $spuId_info['detail'];
  1360. // if(!is_null(json_decode($detail))){
  1361. // $detail_list = json_decode($detail);
  1362. // $detail = '';
  1363. // foreach($detail_list as $value){
  1364. // $detail .= "<img src='".$value."' referrerpolicy='no-referrer' /></img>";
  1365. // }
  1366. // }
  1367. // Db::name('store_product_content')->where('product_id',$product_id)->update(['content'=>$detail]);
  1368. // }
  1369. // $cursor = Db::name('store_order')->where('mer_id', 439)->select();
  1370. // foreach ($cursor as $key=>$online) {
  1371. // // if($key != 0) continue;
  1372. // $order_id = $online['order_id'];
  1373. // $orderProduct = Db::name('store_order')->alias('so')->where('so.order_id',$order_id)->leftJoin('store_order_product sop','so.order_id=sop.order_id')->field('sop.*')->select()->toArray();
  1374. // foreach ($orderProduct as $_k=>&$_vv){
  1375. // $_vv['cart_info'] = json_decode($_vv['cart_info'],true);
  1376. // if(isset($_vv['cart_info']['product']['product_id'])){
  1377. // $image = Db::name('store_product')->where('product_id', $_vv['cart_info']['product']['product_id'])->value('image');
  1378. // if($image){
  1379. // $_vv['cart_info']['product']['image'] = $image;
  1380. // }
  1381. // }
  1382. // Db::name('store_order_product')->where('order_id', $order_id)->update(['cart_info'=> json_encode($_vv['cart_info'], true)]);
  1383. // }
  1384. // }
  1385. // 普通订单
  1386. // $cursor = Db::table('rrx_store_order')->where('paid', 1)->where('gzc', 0)->where('mer_id', 496)->where('pay_type', 'in', [0,1,2,4])->select();
  1387. // $StoreOrderStatusRepository = app()->make(StoreOrderStatusRepository::class);
  1388. // $OrderMerchantRepository = app()->make(OrderMerchantRepository::class);
  1389. // $OrderGzcRepository = app()->make(OrderGzcRepository::class);
  1390. // foreach ($cursor as $online) {
  1391. // if ($online['mer_id'] == 496) {
  1392. // if (!in_array($online['status'], [0, 1, 2, 3])) {
  1393. // continue;
  1394. // }
  1395. // }
  1396. // $certification = UserCertification::getInstance()->where('uid', $online['uid'])->find();
  1397. // if (!$certification) {
  1398. // Log::info($online['uid'] . '没有实名认证');
  1399. // // echo '没有实名认证';
  1400. // continue;
  1401. // }
  1402. // //查询养老金金额
  1403. // $UserBillRepository = app()->make(UserBillRepository::class);
  1404. // $bill = $UserBillRepository->getWhere(['uid' => $online['uid'], 'link_id' => $online['order_id'], 'commission_type' => 5]);
  1405. // $pension = $bill->number ?? 0;
  1406. // if ($pension <= 0) {
  1407. // echo '金额为为0:'.$online['order_sn'];
  1408. // Log::info($online['order_sn'] . 'pension' . $pension);
  1409. // continue;
  1410. // }
  1411. // Db::transaction(function () use ($certification, $online, $pension, $OrderGzcRepository, $OrderMerchantRepository) {
  1412. // //新增入账明细记录
  1413. // $orderId = $OrderMerchantRepository->getNewOrderId('IN10');
  1414. // $create = [
  1415. // 'uid' => $online['uid'],
  1416. // 'platform_no' => $orderId,
  1417. // 'account_type' => $online['pay_type'] == 1 ? 3 : 2,
  1418. // 'user_name' => $certification['user_name'],
  1419. // 'mobile' => $certification['mobile'],
  1420. // 'user_card' => $certification['user_card'],
  1421. // 'pension' => $pension,
  1422. // 'order_type' => 2,
  1423. // 'out_trade_no' => $online['order_sn']
  1424. // ];
  1425. // $test_user = Db::name('user')->where('uid', $online['uid'])->value('test_user');
  1426. // $check = Db::name("gzc_logs")->where("out_trade_no", $online['order_sn'])->where("order_type", 2)->count();
  1427. // if ($test_user == 0 && $check <= 0) {
  1428. // $OrderGzcRepository->create($create);
  1429. // }
  1430. // $order = StoreOrder::getInstance()->find($online['order_id']);
  1431. // $order->gzc = 1;
  1432. // $order->save();
  1433. // });
  1434. // $bill->gzc = 1;
  1435. // $bill->is_gzc = 1;
  1436. // $bill->save();
  1437. // }
  1438. //18995126502
  1439. //会员直推荐佣金补1800,复购金补200,贡献值补4900,积分补4900,养老金补350
  1440. // $user = Db::name("user")->where('uid', 910)->find();
  1441. // $order_sn = 0;
  1442. // $order_id = 0;
  1443. // $order["mer_id"] = 0;
  1444. // //sat存养老金
  1445. // $tuiguanyanglaojin = '350';
  1446. // $tuimark = "推荐消费获得养老金" . $tuiguanyanglaojin;
  1447. // $tuititle = "养老金";
  1448. // $commission_type = 5;
  1449. // if ($tuiguanyanglaojin >= 0.01) {
  1450. // $this->add_bill($tuititle, $tuiguanyanglaojin, $user["uid"], $tuimark, $commission_type, $order_sn, $order_id, $order["mer_id"], 0, 0, 0);
  1451. // } else {
  1452. // Db::name('log')->insert(['data' => '订单号:' . $order_sn . '付款额度较低,推荐养老金低于0.01无法入库 特此记录!']);
  1453. // }
  1454. // $tuiguanyongjin = '1800';
  1455. // $tuiYongmark = "推荐消费获得佣金" . $tuiguanyongjin;
  1456. // $tuiYongzhoutitle = "推广佣金";
  1457. // $commission_yong_type = 3;
  1458. // if ($tuiguanyongjin >= 0.01) {
  1459. // $this->add_bill($tuiYongzhoutitle, $tuiguanyongjin, $user["uid"], $tuiYongmark, $commission_yong_type, $order_sn, $order_id, $order["mer_id"], 0, 0, 0);
  1460. // } else {
  1461. // Db::name('log')->insert(['data' => '订单号:' . $order_sn . '付款额度较低或 商家、平台设置的返佣比例较低,佣金低于0.01无法入库 特此记录!']);
  1462. // }
  1463. // $merchant_member_list = Db::name('order_merchant')
  1464. // ->where('status', 0)->where('paid', 0)->where('create_time', '>', '2025-01-01 00:00:00')
  1465. // ->column('id,mer_id,uid,out_trade_no,hf_pay_id,create_time');
  1466. // $out_trade_no_list = [];
  1467. // foreach ($merchant_member_list as $key => $value) {
  1468. // if (strpos($value['out_trade_no'], 'ALI') !== false) {
  1469. // //支付宝
  1470. // $api_key = 'api_live_b23537ed-64b8-45d6-832e-fb228aa9e0a9';
  1471. // } else {
  1472. // //微信
  1473. // $api_key = 'api_live_b0a687ec-5450-4ada-a0e4-65bac0f46871';
  1474. // }
  1475. // $params = [
  1476. // 'api_key' => $api_key,
  1477. // 'payment_id' => $value['hf_pay_id'],
  1478. // ];
  1479. // $res = $this->Payment_query_traits($params);
  1480. // if (isset($res['status']) && $res['status'] == 'succeeded') {
  1481. // $params['out_trade_no'] = $value['out_trade_no'];
  1482. // // echo json_encode($params);
  1483. // $out_trade_no_list[] = $value['out_trade_no'];
  1484. // }
  1485. // echo json_encode($res);
  1486. // $params['out_trade_no'] = $value['out_trade_no'];
  1487. // echo json_encode($params);
  1488. // }
  1489. // echo json_encode($out_trade_no_list);
  1490. // $api_key = 'api_live_b0a687ec-5450-4ada-a0e4-65bac0f46871';
  1491. // $params = [
  1492. // 'api_key' => $api_key,
  1493. // 'payment_id' => '002212025031014345810745060317006163968'
  1494. // ];
  1495. // $res = $this->Payment_query_traits($params);
  1496. // echo json_encode($res);
  1497. // $params['out_trade_no'] = $value['out_trade_no'];
  1498. // echo json_encode($params);
  1499. // echo json_encode($merchant_member_list);
  1500. // echo 'xxx';
  1501. }
  1502. /**
  1503. * 佣金加入账单
  1504. * @param $title
  1505. * @param $number
  1506. * @param $uid
  1507. * @param $mark
  1508. * @param $commission_type
  1509. * @param $order_sn
  1510. */
  1511. public function add_bill($title, $number, $uid, $mark, $commission_type, $order_sn, $order_id = 0, $mer_id = 0, $source = 0, $status = 1, $type_shop = 0)
  1512. {
  1513. log::info("====进入add——bill");
  1514. log::info("==uid==={$uid}");
  1515. if ($uid == 0 || $number == 0) {
  1516. return;
  1517. }
  1518. $number = sprintf('%.2f', $number);
  1519. $data = [
  1520. 'link_id' => $order_id,
  1521. "uid" => $uid,
  1522. "pm" => 1,
  1523. "title" => $title,
  1524. "category" => "now_money",
  1525. "type" => "commission",
  1526. "number" => $number,
  1527. "balance" => 0,
  1528. "mark" => $mark,
  1529. // "create_time"=>date("Y-m-d H:i:s"),
  1530. "status" => $status,
  1531. "commission_type" => $commission_type,
  1532. "order_sn" => $order_sn,
  1533. "mer_id" => $mer_id,
  1534. "source" => $source,
  1535. "type_shop" => $type_shop
  1536. ];
  1537. log::info("开始添加user——bills");
  1538. log::info($data);
  1539. Db::name("user_bill")->insert($data);
  1540. if ($type_shop == 0) {
  1541. if ($commission_type == 5) {
  1542. Db::name("user")->where("uid", $uid)->inc('annuity', $number)->update();
  1543. Db::name("user")->where("uid", $uid)->inc('annuity_num', 1)->update();
  1544. } else {
  1545. Db::name("user")->where("uid", $uid)->inc('brokerage_price', $number)->update();
  1546. }
  1547. }
  1548. }
  1549. }