CommissionCron.php 48 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038
  1. <?php
  2. namespace app\controller\api\cron;
  3. use AdaPaySdk\PaymentConfirm;
  4. use app\common\dao\store\order\StoreOrderDao;
  5. use app\common\repositories\merchant\order\OrderGzcRepository;
  6. use app\common\repositories\merchant\order\OrderMerchantRepository;
  7. use app\common\repositories\store\order\StoreOrderRepository;
  8. use app\common\repositories\store\order\StoreOrderStatusRepository;
  9. use app\common\repositories\user\UserRepository;
  10. use app\controller\api\Common;
  11. use app\controller\merchant\finance\Reconciliation;
  12. use app\traits\GongApiRequest;
  13. use Carbon\Carbon;
  14. use Exception;
  15. use think\db\exception\DataNotFoundException;
  16. use think\db\exception\DbException;
  17. use think\db\exception\ModelNotFoundException;
  18. use think\facade\Cache;
  19. use think\facade\Db;
  20. use think\facade\Log;
  21. use function GuzzleHttp\Psr7\str;
  22. class CommissionCron
  23. {
  24. /**
  25. * @var false|string
  26. */
  27. private $startMonth;
  28. /**
  29. * @var false|string
  30. */
  31. private $endMonth;
  32. /**
  33. * @var false|string
  34. */
  35. private $month;
  36. public function __construct()
  37. {
  38. // $this->startMonth = date('Y-m-01 00:00:00', strtotime('-1 month'));
  39. // $this->endMonth = date("Y-m-d 23:59:59", strtotime(-date('d') . 'day'));
  40. // $this->month = date('Y-m', strtotime('-1 month'));
  41. $this->startMonth = date('Y-m-01 00:00:00');
  42. $this->endMonth = date("Y-m-d 23:59:59");
  43. $this->month = date('Y-m');
  44. }
  45. /**
  46. * 奖金
  47. */
  48. public function bonus()
  49. {
  50. //创客补贴
  51. $this->real_subsidy_money();
  52. // 跨店奖励
  53. $this->stride_shop_money();
  54. //推荐创客收益
  55. $this->invite_shop_money();
  56. //大V经理分享奖
  57. $this->big_vip_money();
  58. //大V升级奖
  59. $this->big_vip_up_money();
  60. echo '执行成功';
  61. }
  62. public function stride_shop_money()
  63. {
  64. $StoreOrderRepository = app()->make(StoreOrderRepository::class);
  65. $sql = "select stride_shop_mer_id,sum(stride_shop_money) stride_shop_money from rrx_store_order o
  66. left join rrx_store_order_extend od on od.order_id=o.order_id
  67. 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
  68. group by od.stride_shop_mer_id";
  69. $mer_bonus_list = Db::query($sql);
  70. Db::name('log')->insert(['data' => "跨店奖励 mer_bonus_list:" . json_encode($mer_bonus_list)]);
  71. foreach ($mer_bonus_list as $mer_bonus) {
  72. $mer_id = $mer_bonus['stride_shop_mer_id'];
  73. $money = $mer_bonus['stride_shop_money'];
  74. if ($money < 0.01) {
  75. Db::name('log')->insert(['data' => "跨店奖励:mer_id:{$mer_id} 跨店奖励低于0.01无法入库 特此记录!"]);
  76. continue;
  77. }
  78. $merchant = Db::name('merchant')->where('mer_id', $mer_id)->find();
  79. $mark = "跨店奖励" . $money;
  80. $title = "跨店奖励({$this->month}月)";
  81. $commission_type = 7;
  82. $StoreOrderRepository->add_bill_gongfu($title, $money, $merchant['uid'] ?? 0, $mark, $commission_type, null, 0, $mer_id, 0, 1, 8, 'commission', $this->month, true);
  83. }
  84. }
  85. public function invite_shop_money()
  86. {
  87. $StoreOrderRepository = app()->make(StoreOrderRepository::class);
  88. $sql = "select od.share_uid,sum(invite_shop_money) invite_shop_money from rrx_store_order o
  89. left join rrx_store_order_extend od on od.order_id=o.order_id
  90. 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";
  91. $user_bonus_list = Db::query($sql);
  92. Db::name('log')->insert(['data' => "推荐创客奖励 user_bonus_list:" . json_encode($user_bonus_list)]);
  93. foreach ($user_bonus_list as $user_bonus) {
  94. $bonus_uid = $user_bonus['share_shop_uid'];
  95. $money = $user_bonus['invite_shop_money'];
  96. if ($money < 0.01) {
  97. Db::name('log')->insert(['data' => "推荐创客:bonus_uid:{$bonus_uid} 推荐创客低于0.01无法入库 特此记录!"]);
  98. continue;
  99. }
  100. $mark = "推荐创客收益" . $money;
  101. $title = "推荐创客收益({$this->month}月)";
  102. $commission_type = 10;
  103. $StoreOrderRepository->add_bill_gongfu($title, $money, $bonus_uid, $mark, $commission_type, null, 0, $mer_id, 0, 1, 8, 'commission', $this->month);
  104. }
  105. }
  106. public function big_vip_money()
  107. {
  108. $StoreOrderRepository = app()->make(StoreOrderRepository::class);
  109. $sql = "select od.share_uid,sum(big_vip_money) big_vip_money from rrx_store_order o
  110. left join rrx_store_order_extend od on od.order_id=o.order_id
  111. 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";
  112. $user_bonus_list = Db::query($sql);
  113. Db::name('log')->insert(['data' => "大v奖励 user_bonus_list:" . json_encode($user_bonus_list)]);
  114. foreach ($user_bonus_list as $user_bonus) {
  115. $bonus_uid = $user_bonus['share_uid'];
  116. $money = $user_bonus['big_vip_money'];
  117. if ($money < 0.01) {
  118. Db::name('log')->insert(['data' => "大v分享奖:bonus_uid:{$bonus_uid} 大v分享奖低于0.01无法入库 特此记录!"]);
  119. continue;
  120. }
  121. $mark = "大V经理分享奖" . $money;
  122. $title = "大V经理分享奖({$this->month})";
  123. $commission_type = 16;
  124. $StoreOrderRepository->add_bill_gongfu($title, $money, $bonus_uid, $mark, $commission_type, null, 0, $mer_id, 0, 1, 8, 'commission', $this->month);
  125. }
  126. }
  127. public function real_subsidy_money()
  128. {
  129. $StoreOrderRepository = app()->make(StoreOrderRepository::class);
  130. $sql = "select o.mer_id mer_id,sum(real_subsidy_money) real_subsidy_money from rrx_store_order o
  131. left join rrx_store_order_extend od on od.order_id=o.order_id
  132. where o.paid=1 and o.is_settlement=1 and settlement_time between '$this->startMonth' and '$this->endMonth' and od.real_subsidy_money>0
  133. group by o.mer_id";
  134. $mer_bonus_list = Db::query($sql);
  135. Db::name('log')->insert(['data' => "创客补贴 mer_bonus_list:" . json_encode($mer_bonus_list)]);
  136. foreach ($mer_bonus_list as $mer_bonus) {
  137. $mer_id = $mer_bonus['mer_id'];
  138. $money = $mer_bonus['real_subsidy_money'];
  139. if ($money < 0.01) {
  140. Db::name('log')->insert(['data' => "创客补贴:mer_id:{$mer_id} 创客补贴低于0.01无法入库 特此记录!"]);
  141. continue;
  142. }
  143. $merchant = Db::name('merchant')->where('mer_id', $mer_id)->find();
  144. $mark = "创客补贴" . $money;
  145. $title = "创客补贴({$this->month}月)";
  146. $commission_type = 19;
  147. $StoreOrderRepository->add_bill_gongfu($title, $money, $merchant['uid'] ?? 0, $mark, $commission_type, null, 0, $mer_id, 0, 1, 8, 'commission', $this->month, true);
  148. }
  149. }
  150. /**
  151. * 大V升级奖
  152. * 1. 查询大V经理列表
  153. * 2. 查询团队列表
  154. * 3. 查询团队这个月的总流水的百分之一分给大V经理
  155. * @return void
  156. */
  157. public function big_vip_up_money()
  158. {
  159. $StoreOrderRepository = app()->make(StoreOrderRepository::class);
  160. $user_list = Db::name("user")->field('uid')->where("user_group", 3)->select()->toArray();
  161. foreach ($user_list as $user) {
  162. $mer_id = 0;
  163. $user_id = $user['uid'];
  164. $sql = "select getUserSpreadId($user_id) as uids";
  165. $spread_user_list = Db::query($sql);
  166. $spread_user_list = trim($spread_user_list[0]['uids'],'$,');
  167. //查询可以分到的钱
  168. $sql = "select sum(big_vip_up_money) big_vip_up_money from rrx_store_order o
  169. left join rrx_store_order_extend od on od.order_id=o.order_id
  170. 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)";
  171. $big_vip_up = Db::query($sql)[0];
  172. $money = $big_vip_up['big_vip_up_money'] ?? 0;
  173. Db::name('log')->insert(['data' => "大V升级奖 big_vip_up_money {$user_id}:{$money}"]);
  174. if ($money < 0.01) {
  175. Db::name('log')->insert(['data' => "大v分享奖:big_vip_up_money:{$money} 大v分享奖低于0.01无法入库 特此记录!"]);
  176. continue;
  177. }
  178. $mark = "大V升级奖" . $money;
  179. $title = "大V升级奖({$this->month}月)";
  180. $commission_type = 10;
  181. $StoreOrderRepository->add_bill_gongfu($title, $money, $user_id, $mark, $commission_type, null, 0, $mer_id, 0, 1, 8, 'commission', $this->month);
  182. }
  183. }
  184. /**
  185. * 用户升级
  186. * @throws DbException
  187. */
  188. public function member_up()
  189. {
  190. $uid_list = Db::name('store_order')
  191. ->where('mer_id', systemConfig('mer_365'))
  192. ->where('paid', 1)
  193. ->whereIn('status', [0, 1, 2, 3])
  194. ->group('uid')
  195. ->column('uid');
  196. Log::info('升级:' . json_encode($uid_list));
  197. foreach ($uid_list as $uid) {
  198. $pay_price = Db::name('store_order')
  199. ->where('mer_id', systemConfig('mer_365'))
  200. ->where('uid', $uid)
  201. ->where('paid', 1)
  202. ->where('is_settlement', 1)
  203. ->whereIn('status', [0, 1, 2, 3])
  204. ->sum('pay_price');
  205. if ($pay_price >= 365) {
  206. // 有没有直推20个经理
  207. $invite_count = Db::name('user')->where('spread_uid', $uid)->field('uid,user_group')->where('user_group', 2)->count();
  208. print_r("uid:{$uid}," . Db::name('user')->where('uid', $uid)->value('phone') . "邀请365经理人数{$invite_count} <br>");
  209. if ($invite_count >= 20) {
  210. $res = Db::name('user')->where('uid', $uid)->whereNotIn('user_group', [4, 5, 6])->update([
  211. 'user_group' => 3
  212. ]);
  213. if ($res) var_dump("uid:{$uid},升级大V经理");
  214. } else {
  215. $res = Db::name('user')->where('uid', $uid)->whereNotIn('user_group', [3, 4, 5, 6])->update([
  216. 'user_group' => 2
  217. ]);
  218. if ($res) var_dump("uid:{$uid},升级365会员");
  219. }
  220. }
  221. }
  222. }
  223. /**
  224. * 创客合伙人收益
  225. */
  226. private function partner_award()
  227. {
  228. //1. 被创客设置成创客合伙人,获得该项收益
  229. //已结算订单金额的
  230. //2%
  231. //1. 按月统计并结算
  232. //2. 计算公式:
  233. //所属创客店补贴*2%/创客合伙人总数
  234. // 推荐创客收益设置
  235. $commission_rate = systemConfig('commission_rate');
  236. Db::name('log')->insert(['data' => 'commission_rate:' . json_encode($commission_rate)]);
  237. $rate = $commission_rate['chuangkehehuoren_rate'];
  238. // 查询全部订单
  239. $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";
  240. $mer_order_list = Db::query($sql);
  241. Db::name('log')->insert(['data' => "创客合伙人收益 user_order_list:" . json_encode($mer_order_list)]);
  242. $StoreOrderRepository = app()->make(StoreOrderRepository::class);
  243. $mer_out_list = [];
  244. foreach ($mer_order_list as $mer_order) {
  245. $mer_id = $mer_order['mer_id'];
  246. $hehuo_user_list = Db::name('user')->field('uid')->where('mer_id', $mer_id)->where('is_shop_partner', 1)->select()->toArray();
  247. $money = decimal2($mer_order['total_price'] * $rate / 100);
  248. foreach ($hehuo_user_list as $hehuo_user) {
  249. $user_money = decimal2($money / count($hehuo_user_list));
  250. Db::name('log')->insert(['data' => "创客补贴:uid:{$hehuo_user['uid']} 创客合伙人人数:" . count($hehuo_user_list) . " 创客补贴比例{$rate}% 创客店铺订单流水:{$mer_order['total_price']} 获取创客推荐收益:{$money}!"]);
  251. if ($money == 0) {
  252. Db::name('log')->insert(['data' => "创客补贴:uid:{$hehuo_user['uid']} 创客补贴低于0.01无法入库 特此记录!"]);
  253. continue;
  254. }
  255. $mark = "创客合伙人收益" . $user_money;
  256. $title = "创客合伙人收益({$this->month}月)";
  257. $commission_type = 17;
  258. $StoreOrderRepository->add_bill_gongfu($title, $money, $hehuo_user['uid'], $mark, $commission_type, null, 0, $mer_id, 0, 1, 8, 'commission', $this->month);
  259. }
  260. $money = decimal2($mer_order['total_price'] * $rate / 100);
  261. $mer_out_list[] = [
  262. $mer_order['mer_id'] => $money
  263. ];
  264. }
  265. Db::name('log')->insert(['data' => '跨店奖励 商户支出:' . json_encode($mer_out_list)]);
  266. return $mer_out_list;
  267. }
  268. /**
  269. * 代理区域收益
  270. */
  271. public function area_manage_details()
  272. {
  273. //1. 代理区域内已结算订单总额的百分
  274. //比;
  275. //2. 按照收货地址统计;
  276. //3. 奖励对象:省代、区县代;
  277. //区县代 5%
  278. //省代 2%
  279. //1. 按月结算:每月 1 号 0 点
  280. //统计上月已结算的订单金额
  281. //并对应发放佣金
  282. //2. 计算公式:
  283. //(1)无运费:收货地为该区域的已结算订单金额*对应比例
  284. //(2)有运费:(收货地为该区域的已结算订单金额-运费)*对应比例
  285. set_time_limit(0);
  286. ini_set('memory_limit', '-1');
  287. $commission_rate = systemConfig('commission_rate');
  288. Db::name('log')->insert(['data' => '代理区域收益 commission_rate:' . json_encode($commission_rate)]);
  289. $area_agency_rate = $commission_rate['area_agency_rate'] ?? 0;
  290. $province_agency_rate = $commission_rate['province_agency_rate'] ?? 0;
  291. $bonus_list = [];
  292. $bonus_user_list = Db::name('user')->field('uid,user_group,manage_address,spread_uid')->whereIn('user_group', [5, 6])->select()->toArray();
  293. $StoreOrderRepository = app()->make(StoreOrderRepository::class);
  294. foreach ($bonus_user_list as $bonus_user) {
  295. $manage_address = $bonus_user['manage_address'];
  296. if (empty($manage_address))
  297. continue;
  298. $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%'";
  299. $total_price = Db::query($sql)[0]['total_price'] ?? 0;
  300. $rate = $bonus_user['user_group'] == 6 ? $province_agency_rate : $area_agency_rate;
  301. $money = decimal2($total_price * $rate / 100);
  302. Db::name('log')->insert(['data' => "代理区域收益:uid:{$bonus_user['uid']} 代理区域收益比例{$rate}% 流水:{$total_price} 收益:{$money} sql:" . $sql]);
  303. $mark = "代理区域收益" . $money;
  304. $title = "代理区域收益({$this->month}月)";
  305. $commission_type = 12;
  306. $StoreOrderRepository->add_bill_gongfu($title, $money, $bonus_user['uid'], $mark, $commission_type, null, 0, 0, 0, 1, 8, 'commission', $this->month);
  307. $bonus_list[] = [
  308. 'uid' => $bonus_user['uid'],
  309. 'money' => $money,
  310. 'spread_uid' => $bonus_user['spread_uid'],
  311. ];
  312. }
  313. $this->invite_agency_award($bonus_list);
  314. echo '执行成功';
  315. }
  316. /**
  317. * 推荐代理收益
  318. * @param $bonus_list
  319. */
  320. private function invite_agency_award($bonus_list)
  321. {
  322. // 1. 推荐的代理收益的百分比
  323. //2. 奖励对象:所有用户
  324. //1. 按月结算:每个月 1 号 0点统计上月的代理收益并对应发放佣金
  325. //2. 计算公式:
  326. //推荐代理总收益*推荐代理收益百分比
  327. $StoreOrderRepository = app()->make(StoreOrderRepository::class);
  328. $this->month = date('Y-m', strtotime('-1 month'));
  329. $commission_rate = systemConfig('commission_rate');
  330. $rate = $commission_rate['tuijiandaili_rate'] ?? 0;
  331. foreach ($bonus_list as $bonus) {
  332. $money = decimal2($bonus['money'] * $rate / 100);
  333. $mark = "推荐代理收益" . $money;
  334. $title = "推荐代理收益({$this->month}月)";
  335. $commission_type = 15;
  336. $StoreOrderRepository->add_bill_gongfu($title, $money, $bonus['spread_uid'], $mark, $commission_type, null, 0, 0, 0, 1, 8, 'commission', $this->month, $this->month);
  337. }
  338. }
  339. /**
  340. * 生成商品图片缓存(最好用命令行执行)
  341. * @return \think\response\Json
  342. * @throws DataNotFoundException
  343. * @throws DbException
  344. * @throws ModelNotFoundException
  345. */
  346. public function make_product_share_cache()
  347. {
  348. set_time_limit(0);
  349. ini_set('memory_limit', '-1');
  350. $redis = Cache::store('redis')->handler();
  351. $key = 'make_product_share_cache';
  352. // $redis->del($key);
  353. // if (!$redis->setnx($key, 1))
  354. // return json(['code' => 400, 'msg' => '现在有正在执行的任务' ]);
  355. $redis->expire($key, 5 * 60);
  356. $product_share_ids = Db::name('product_share')
  357. // ->where('`url` is not null')
  358. ->group('product_id')
  359. ->column('product_id');
  360. $list = Db::name('store_product')
  361. ->whereNotIn('product_id', $product_share_ids)
  362. ->where('is_show', 1)
  363. ->limit(3)
  364. ->order('create_time desc')
  365. ->select()
  366. ->toArray();
  367. var_dump($list);
  368. $header = [
  369. 'X-Token: eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpc3MiOiJ0ZXN0LmJqdGRiYS5jb20iLCJhdWQiOiJ0ZXN0LmJqdGRiYS5jb20iLCJpYXQiOjE2OTI0MjQ4MTEsIm5iZiI6MTY5MjQyNDgxMSwiZXhwIjoxNzAzMjI0ODExLCJqdGkiOls5NzIwLCJ1c2VyIl19.YtYf1ssMTz6fOO2rZVX-jb48L7AqXSKezQcbTHR3sCk'
  370. ];
  371. foreach ($list as $store_product) {
  372. $res1 = Common::sendCurl("http://127.0.0.1:8324/api/product_share?pid={$store_product['product_id']}&type=1", null, 'get', $header);
  373. $res2 = Common::sendCurl("http://127.0.0.1:8324/api/product_share?pid={$store_product['product_id']}&type=2", null, 'get', $header);
  374. var_dump($res1, $res2);
  375. }
  376. $redis->del($key);
  377. return json(['code' => 200, 'msg' => '生成商品分享缓存定时任务执行成功']);
  378. }
  379. /**
  380. * 梳理每个人的公排人数
  381. * @throws \think\db\exception\DataNotFoundException
  382. * @throws \think\db\exception\DbException
  383. * @throws \think\db\exception\ModelNotFoundException
  384. */
  385. public function tease_user_count()
  386. {
  387. $list = Db::name('user')->where('is_del', 0)->select()->toArray();
  388. foreach ($list as $item) {
  389. $level_number = Db::name('user')->where('level_id', $item['uid'])->count();
  390. $user_count = Db::name('user_count')->where('uid', $item['uid'])->find();
  391. if ($level_number >= 5) {
  392. $res = Db::name('user_count')->where('uid', $item['uid'])->delete();
  393. if ($res) echo "{$item['uid']}公排人数已删除\r\n";
  394. continue;
  395. }
  396. if ($user_count) {
  397. if ($level_number == $user_count['level_number']) continue;
  398. Db::name('user_count')->where('uid', $item['uid'])->update([
  399. 'level_number' => $level_number
  400. ]);
  401. } else {
  402. Db::name('user_count')->insert([
  403. 'uid' => $item['uid'],
  404. 'level_number' => 0
  405. ]);
  406. $user_count['level_number'] = 0;
  407. }
  408. echo "{$item['uid']}公排人数从{$user_count['level_number']}调整到{$level_number}人\r\n";
  409. Log::info("{$item['uid']}公排人数从{$user_count['level_number']}调整到{$level_number}人\r\n");
  410. }
  411. return json(['code' => 200, 'msg' => '生成商品分享缓存定时任务执行成功']);
  412. }
  413. /**
  414. * 下架微唯宝已下架的商品
  415. * @return mixed
  416. * @throws \think\db\exception\DbException
  417. */
  418. public function downGongProduct()
  419. {
  420. $start = input('start');
  421. $where = [
  422. 'is_used' => 1,
  423. 'mer_status' => 1,
  424. // 'type' => 5,
  425. // 'is_show' => 1,
  426. 'is_hide' => 0,
  427. // 'is_del' => 0
  428. ];
  429. if (!$start) {
  430. $product_data_count = Db::name('store_product')
  431. ->where($where)
  432. ->where("spu_id != '' or spu_id is not null")
  433. ->count();
  434. $start = mt_rand(0, $product_data_count);
  435. }
  436. $product_data = Db::name('store_product')
  437. ->where($where)
  438. ->where("spu_id != '' or spu_id is not null")
  439. ->where('product_id', '>', $start)
  440. ->order('product_id asc')
  441. ->limit(0, 50)
  442. ->select()
  443. ->toArray();
  444. foreach ($product_data as $item) {
  445. $spuIds = $item['spu_id'];
  446. $goods_status = GongApiRequest::goods_status($spuIds);
  447. $status = $goods_status[0]['status'] ?? 1;
  448. $goods_info = GongApiRequest::get_goods_info($spuIds);
  449. if ($status == 0 || (isset($goods_info['error_msg']) && $goods_info['error_msg'] == '没有查询到商品信息')) {
  450. Db::startTrans();
  451. try {
  452. // 删除选品库对应的数据
  453. Db::name('douhuomall')->whereIn('spu_id', $spuIds)->update([
  454. 'status' => 9,
  455. 'update_time' => date('Y-m-d H:i:s')
  456. ]);
  457. // 删除商品管理对应的数据
  458. Db::name('store_product')->whereIn('spu_id', $spuIds)->update([
  459. 'is_del' => 1,
  460. 'is_show' => 0
  461. ]);
  462. Db::commit();
  463. } catch (Exception $e) {
  464. Db::rollback();
  465. Log::channel("gong")->error('供应链取消商品失败:' . $e->getMessage());
  466. return app('json')->fail($e->getMessage());
  467. }
  468. } else if ($status == 1 || !isset($goods_info['error_msg'])) {
  469. Db::startTrans();
  470. try {
  471. // 选品库对应的数据
  472. Db::name('douhuomall')->whereIn('spu_id', $spuIds)->update([
  473. 'status' => 1,
  474. 'update_time' => date('Y-m-d H:i:s')
  475. ]);
  476. // 商品管理对应的数据
  477. Db::name('store_product')->whereIn('spu_id', $spuIds)->update([
  478. 'is_del' => 0,
  479. 'is_show' => 1
  480. ]);
  481. Db::commit();
  482. } catch (Exception $e) {
  483. Db::rollback();
  484. Log::channel("gong")->error('供应链取消商品失败:' . $e->getMessage());
  485. return app('json')->fail($e->getMessage());
  486. }
  487. }
  488. }
  489. return app('json')->success('操作成功');
  490. }
  491. /**
  492. * 定时获取 交易类型 1订单入账 2佣金提现支出 3养老金(红积分兑换订单)
  493. */
  494. public function platform_income_detail_get()
  495. {
  496. $merchant_list = Db::name('merchant')
  497. ->where('status', 1)
  498. ->where('mer_state', 1)
  499. ->where("mer_name != ''")
  500. ->column('mer_id');
  501. $Reconciliation = app()->make(Reconciliation::class);
  502. $unique_list = [];
  503. $enterprise_platform_income_detail_list = Db::name('enterprise_platform_income_detail')
  504. ->select()
  505. ->toArray();
  506. foreach ($enterprise_platform_income_detail_list as $item) {
  507. $unique_list[] = $item['deal_type'] . $item['uid'] . $item['order_sn'] . $item['order_id'] . $item['user_extra_id'] . $item['mer_id'];
  508. }
  509. foreach ($merchant_list as $mer_id) {
  510. $OrderMerchantRepository = app()->make(OrderMerchantRepository::class);
  511. $is_first = empty($enterprise_platform_income_detail_list);
  512. // 1自营订单入账金额=已结算订单金额-运费-养老金-汇付通道服务费; 订单结算的时候才统计
  513. $store_order_list = Db::name('store_order')
  514. ->where('mer_id', $mer_id)
  515. ->where('paid', 1)
  516. ->where('douhuomall', 0)
  517. ->where('is_settlement', 1)
  518. ->order('order_id', 'desc')
  519. // ->limit(500)
  520. ->select()
  521. ->toArray();
  522. foreach ($store_order_list as $store_order) {
  523. if (in_array('1' . $store_order['uid'] . $store_order['order_sn'] . $store_order['order_id'] . '0' . $mer_id, $unique_list)) continue;
  524. $pay_type = $store_order['pay_type'];
  525. if (!in_array($pay_type, [0, 1])) continue;
  526. $group_order = Db::name('store_group_order')
  527. ->alias('sgo')
  528. ->where('sgo.group_order_id', $store_order['group_order_id'])
  529. ->find();
  530. if (empty($group_order)) continue;
  531. $shop_bonus_setting = merchantConfig($store_order['mer_id'], 'shop_bonus_setting') ?: [
  532. 'shop_bonus_rate' => 30,
  533. 'yanglao_rate' => 5,
  534. ];
  535. $yanglao = Db::name('user_bill')
  536. ->where('order_sn', $store_order['order_sn'])
  537. ->where('commission_type', 5)
  538. ->value('number');
  539. $ru_money = 0;
  540. if ($pay_type != 0) {
  541. $store_split_order = Db::name('store_split_order')
  542. ->where('group_order_id', $group_order['group_order_sn'])
  543. ->where('status', 1)
  544. ->find();
  545. if (empty($store_split_order)) continue;
  546. if ($pay_type == 1) {
  547. //微信
  548. if ($group_order['pay_wx'] == 3) {
  549. $api_key = 'api_live_b0a687ec-5450-4ada-a0e4-65bac0f46871';
  550. } else {
  551. $api_key = 'api_live_90ef02e4-54ac-41ee-adf1-e4927d23d58f';
  552. }
  553. } else {
  554. //支付宝
  555. $api_key = 'api_live_b23537ed-64b8-45d6-832e-fb228aa9e0a9';
  556. }
  557. $params['payment_confirm_id'] = $store_split_order['hf_pay_id'];
  558. $params['api_key'] = $api_key;
  559. //查询支付确认对象
  560. Db::name("log")->insert(array('data' => '汇付查询支付确认对象参数-----' . json_encode($params)));//日志记录
  561. $res = $this->payment_confirm_query_traits($params);
  562. Db::name("log")->insert(array('data' => '汇付查询支付确认对象返回-----' . json_encode($res)));//日志记录
  563. // 获取分账后一个工作日时间
  564. $close_time = $this->getNextWorkday(date('Y-m-d H:i:s', strtotime('+1 days', strtotime($store_order['pay_time']))));
  565. if (isset($res['status'])) {
  566. Db::name('store_order')->where('order_id', $store_order['order_id'])->update([
  567. 'hf_fee_amt' => $res['fee_amt'],
  568. 'hf_clear_time' => $close_time
  569. ]);
  570. }
  571. if (isset($res['status']) && time() > strtotime($close_time)) {
  572. if ($store_order['mer_id'] == 496) {
  573. $ru_money = $store_order['pay_price'] - $yanglao - $res['fee_amt'];
  574. } else {
  575. $ru_money = $store_order['pay_price'] * (1 - $shop_bonus_setting['shop_bonus_rate'] / 100) - $res['fee_amt'] + +$store_order['pay_postage'];
  576. }
  577. $store_order['pay_time'] = '';//线上支付的
  578. } else {
  579. continue;
  580. }
  581. } else {
  582. // 订单金额+运费
  583. if ($store_order['mer_id'] == 496) {
  584. $ru_money = $store_order['pay_price'] - $yanglao;
  585. } else {
  586. $ru_money = $store_order['pay_price'] * (1 - $shop_bonus_setting['shop_bonus_rate'] / 100) + $store_order['pay_postage'];
  587. }
  588. }
  589. Db::name('enterprise_platform_income_detail')
  590. ->insert([
  591. 'mer_id' => $mer_id,
  592. 'uid' => $store_order['uid'],
  593. 'title' => '自营订单入账',
  594. 'deal_order_sn' => $OrderMerchantRepository->getNewOrderId('jy2'),
  595. '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')),
  596. 'money' => $ru_money,
  597. 'deal_type' => 1,
  598. 'order_id' => $store_order['order_id'],
  599. 'order_sn' => $store_order['order_sn'],
  600. 'user_extra_id' => '',
  601. 'pm' => 1,
  602. 'create_time' => date('Y-m-d H:i:s'),
  603. ]);
  604. unset($close_time);
  605. }
  606. //2佣金提现到账 提现成功统计
  607. // $user_extract_list = Db::name('user_extract')
  608. // ->field('extract_id,uid,extract_type,extract_price,service_money,order_sn,status_time')
  609. // ->where('status', 1)
  610. // ->where('withdrawal_type', 3)
  611. // ->where('extract_type', '<>', 4)
  612. // ->when($uids, function ($query) use ($uids) {
  613. // $query->whereIn('uid', $uids);
  614. // })
  615. // ->order('extract_id', 'desc')
  616. //// ->limit(100)
  617. // ->select()
  618. // ->toArray();
  619. // foreach ($user_extract_list as $user_extract) {
  620. // if (in_array('2' . $user_extract['uid'] . $user_extract['order_sn'] . '0' . $user_extract['extract_id'], $unique_list)) continue;
  621. // $enterprise_platform_income_detail = Db::name('enterprise_platform_income_detail')
  622. // ->where('deal_type', 2)
  623. // ->where('user_extra_id', $user_extract['extract_id'])
  624. // ->find();
  625. // if (!$enterprise_platform_income_detail) {
  626. // Db::name('enterprise_platform_income_detail')
  627. // ->insert([
  628. // 'mer_id' => $mer_id,
  629. // 'uid' => $user_extract['uid'],
  630. // 'title' => '佣金提现支出',
  631. // 'deal_order_sn' => $OrderMerchantRepository->getNewOrderId('jy2'),
  632. // 'deal_time' => $user_extract['status_time'],
  633. // 'money' => bcsub($user_extract['extract_price'], $user_extract['service_money'], 2),
  634. // 'deal_type' => 2,
  635. // 'order_id' => '',
  636. // 'order_sn' => $user_extract['order_sn'],
  637. // 'user_extra_id' => $user_extract['extract_id'],
  638. // 'pm' => 1,
  639. // 'create_time' => date('Y-m-d H:i:s'),
  640. // ]);
  641. // }
  642. // }
  643. $start_time = '2024-04-01';
  644. for ($i = 0; $i < 1000; $i++) {
  645. $day = date('Y-m-d', strtotime("+{$i} days", strtotime($start_time)));
  646. if (strtotime($day) > time()) {
  647. break;
  648. }
  649. $Reconciliation->cron($day, $mer_id);
  650. }
  651. }
  652. // 计算平台
  653. //交易类型 1自营订单入账(商户) 2佣金提现到账(商户) 3订单支付 4商户佣金提现 5用户佣金提现 6订单入账 7 创客自营订单让利
  654. $mer_id = 0;
  655. // 3 订单支付 供应链订单结算后入账到平台的金额
  656. $store_order_list = Db::name('store_order')
  657. ->where('paid', 1)
  658. ->order('order_id', 'desc')
  659. // ->limit(500)
  660. ->select()
  661. ->toArray();
  662. foreach ($store_order_list as $store_order) {
  663. if (in_array('3' . $store_order['uid'] . $store_order['order_sn'] . $store_order['order_id'] . '0' . $mer_id, $unique_list)) continue;
  664. $group_order = Db::name('store_group_order')
  665. ->alias('sgo')
  666. ->where('sgo.group_order_id', $store_order['group_order_id'])
  667. ->find();
  668. if (empty($group_order)) continue;
  669. $store_split_order = Db::name('store_split_order')
  670. ->where('group_order_id', $group_order['group_order_sn'])
  671. ->where('status', 1)
  672. ->find();
  673. if (empty($store_split_order)) continue;
  674. $close_time = $this->getNextWorkday(date('Y-m-d H:i:s', strtotime('+1 days', strtotime($store_order['pay_time']))));
  675. Db::name('enterprise_platform_income_detail')
  676. ->insert([
  677. 'mer_id' => $mer_id,
  678. 'uid' => $store_order['uid'],
  679. 'title' => '订单支付',
  680. 'deal_order_sn' => $OrderMerchantRepository->getNewOrderId('jy4'),
  681. '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')),
  682. 'money' => $store_order['pay_price'] + $store_order['pay_postage'],
  683. 'deal_type' => 3,
  684. 'order_id' => $store_order['order_id'],
  685. 'order_sn' => $store_order['order_sn'],
  686. 'user_extra_id' => '',
  687. 'pm' => 1,
  688. 'create_time' => date('Y-m-d H:i:s'),
  689. ]);
  690. }
  691. //5用户佣金提现
  692. $user_extract_list = Db::name('user_extract')
  693. ->field('extract_id,uid,extract_type,extract_price,service_money,order_sn,status_time')
  694. ->where('status', 1)
  695. ->order('extract_id', 'desc')
  696. // ->limit(100)
  697. ->select()
  698. ->toArray();
  699. foreach ($user_extract_list as $user_extract) {
  700. if (in_array('5' . $user_extract['uid'] . $user_extract['order_sn'] . '0' . $user_extract['extract_id'] . $mer_id, $unique_list)) continue;
  701. Db::name('enterprise_platform_income_detail')
  702. ->insert([
  703. 'mer_id' => $mer_id,
  704. 'uid' => $user_extract['uid'],
  705. 'title' => '用户佣金提现',
  706. 'deal_order_sn' => $OrderMerchantRepository->getNewOrderId('jy2'),
  707. 'deal_time' => $user_extract['status_time'],
  708. 'money' => bcsub($user_extract['extract_price'], $user_extract['service_money'], 2),
  709. 'deal_type' => 5,
  710. 'order_id' => '',
  711. 'order_sn' => $user_extract['order_sn'],
  712. 'user_extra_id' => $user_extract['extract_id'],
  713. 'pm' => 0,
  714. 'create_time' => date('Y-m-d H:i:s'),
  715. ]);
  716. }
  717. // 6订单入账:支付成功的订单数据 供应链订单
  718. $store_order_list = Db::name('store_order')
  719. ->where('paid', 1)
  720. ->where('douhuomall', 1)
  721. ->where('is_settlement', 1)
  722. ->order('order_id', 'desc')
  723. // ->limit(500)
  724. ->select()
  725. ->toArray();
  726. foreach ($store_order_list as $store_order) {
  727. if (in_array('6' . $store_order['uid'] . $store_order['order_sn'] . $store_order['order_id'] . '0' . $mer_id, $unique_list)) continue;
  728. $pay_type = $store_order['pay_type'];
  729. if (!in_array($pay_type, [0, 1])) continue;
  730. $group_order = Db::name('store_group_order')
  731. ->alias('sgo')
  732. ->where('sgo.group_order_id', $store_order['group_order_id'])
  733. ->find();
  734. if (empty($group_order)) continue;
  735. $yanglao = Db::name('user_bill')
  736. ->where('order_sn', $store_order['order_sn'])
  737. ->where('commission_type', 5)
  738. ->value('number');
  739. $ru_money = 0;
  740. $shop_bonus_setting = merchantConfig($store_order['mer_id'], 'shop_bonus_setting') ?: [
  741. 'shop_bonus_rate' => 30,
  742. 'yanglao_rate' => 5,
  743. ];
  744. if ($pay_type != 0) {
  745. $store_split_order = Db::name('store_split_order')
  746. ->where('group_order_id', $group_order['group_order_sn'])
  747. ->find();
  748. if (empty($store_split_order)) continue;
  749. if (!$store_order['hf_fee_amt']) {
  750. if ($pay_type == 1) {
  751. //微信
  752. if ($group_order['pay_wx'] == 3) {
  753. $api_key = 'api_live_b0a687ec-5450-4ada-a0e4-65bac0f46871';
  754. } else {
  755. $api_key = 'api_live_90ef02e4-54ac-41ee-adf1-e4927d23d58f';
  756. }
  757. } else {
  758. //支付宝
  759. $api_key = 'api_live_b23537ed-64b8-45d6-832e-fb228aa9e0a9';
  760. }
  761. $params['payment_confirm_id'] = $store_split_order['hf_pay_id'];
  762. $params['api_key'] = $api_key;
  763. //查询支付确认对象
  764. Db::name("log")->insert(array('data' => '汇付查询支付确认对象参数-----' . json_encode($params)));//日志记录
  765. $res = $this->payment_confirm_query_traits($params);
  766. Db::name("log")->insert(array('data' => '汇付查询支付确认对象返回-----' . json_encode($res)));//日志记录
  767. if (isset($res['status'])) {
  768. Db::name('store_order')->where('order_id', $store_order['order_id'])->update([
  769. 'hf_fee_amt' => $res['fee_amt'],
  770. 'hf_clear_time' => $close_time
  771. ]);
  772. $store_order['hf_fee_amt'] = $res['fee_amt'];
  773. }
  774. }
  775. // 获取分账后一个工作日时间
  776. $close_time = $this->getNextWorkday(date('Y-m-d H:i:s', strtotime('+1 days', strtotime($store_order['pay_time']))));
  777. if (isset($res['status']) && time() > strtotime($close_time)) {
  778. if ($store_order['mer_id'] == 496) {
  779. $ru_money = $store_order['pay_price'] - $yanglao - $store_order['hf_fee_amt'];
  780. } else {
  781. $ru_money = $store_order['pay_price'] - $yanglao;
  782. }
  783. $store_order['pay_time'] = '';//线上支付的
  784. } else {
  785. continue;
  786. }
  787. } else {
  788. // 订单金额+运费
  789. if ($store_order['mer_id'] == 496) {
  790. $ru_money = $store_order['pay_price'] - $yanglao;
  791. } else {
  792. $ru_money = $store_order['pay_price'] - $yanglao;
  793. }
  794. }
  795. Db::name('enterprise_platform_income_detail')
  796. ->insert([
  797. 'mer_id' => $mer_id,
  798. 'uid' => $store_order['uid'],
  799. 'title' => '订单入账',
  800. 'deal_order_sn' => $OrderMerchantRepository->getNewOrderId('jy2'),
  801. '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')),
  802. 'money' => $ru_money,
  803. 'deal_type' => 6,
  804. 'order_id' => $store_order['order_id'],
  805. 'order_sn' => $store_order['order_sn'],
  806. 'user_extra_id' => '',
  807. 'pm' => 1,
  808. 'create_time' => date('Y-m-d H:i:s'),
  809. ]);
  810. unset($close_time);
  811. }
  812. //7 创客自营订单让利=创客自营订单金额*分润比例-(创客自营订单金额-运费)*养老金比例
  813. $store_order_list = Db::name('store_order')
  814. ->where('paid', 1)
  815. ->where('is_settlement', 1)
  816. ->where('douhuomall', 0)
  817. ->order('order_id', 'desc')
  818. // ->limit(500)
  819. ->select()
  820. ->toArray();
  821. foreach ($store_order_list as $store_order) {
  822. if (in_array('7' . $store_order['uid'] . $store_order['order_sn'] . $store_order['order_id'] . '0' . $mer_id, $unique_list)) continue;
  823. $shop_bonus_setting = merchantConfig($store_order['mer_id'], 'shop_bonus_setting') ?: [
  824. 'shop_bonus_rate' => 30,
  825. 'yanglao_rate' => 5,
  826. ];
  827. $pay_type = $store_order['pay_type'];
  828. if ($pay_type != 0) {
  829. $group_order = Db::name('store_group_order')
  830. ->alias('sgo')
  831. ->where('sgo.group_order_id', $store_order['group_order_id'])
  832. ->find();
  833. if (empty($group_order)) continue;
  834. $store_split_order = Db::name('store_split_order')
  835. ->where('group_order_id', $group_order['group_order_sn'])
  836. ->find();
  837. if (empty($store_split_order)) continue;
  838. $close_time = $this->getNextWorkday(date('Y-m-d H:i:s', strtotime('+1 days', strtotime($store_order['pay_time']))));
  839. if (!$store_order['hf_fee_amt']) {
  840. $store_split_order = Db::name('store_split_order')
  841. ->where('group_order_id', $group_order['group_order_sn'])
  842. ->where('status', 1)
  843. ->find();
  844. if (empty($store_split_order)) continue;
  845. if ($pay_type == 1) {
  846. //微信
  847. if ($group_order['pay_wx'] == 3) {
  848. $api_key = 'api_live_b0a687ec-5450-4ada-a0e4-65bac0f46871';
  849. } else {
  850. $api_key = 'api_live_90ef02e4-54ac-41ee-adf1-e4927d23d58f';
  851. }
  852. } else {
  853. //支付宝
  854. $api_key = 'api_live_b23537ed-64b8-45d6-832e-fb228aa9e0a9';
  855. }
  856. $params['payment_confirm_id'] = $store_split_order['hf_pay_id'];
  857. $params['api_key'] = $api_key;
  858. //查询支付确认对象
  859. Db::name("log")->insert(array('data' => '汇付查询支付确认对象参数-----' . json_encode($params)));//日志记录
  860. $res = $this->payment_confirm_query_traits($params);
  861. Db::name("log")->insert(array('data' => '汇付查询支付确认对象返回-----' . json_encode($res)));//日志记录
  862. // 获取分账后一个工作日时间
  863. $close_time = $this->getNextWorkday(date('Y-m-d H:i:s', strtotime('+1 days', strtotime($store_order['pay_time']))));
  864. if (isset($res['status'])) {
  865. Db::name('store_order')->where('order_id', $store_order['order_id'])->update([
  866. 'hf_fee_amt' => $res['fee_amt'],
  867. 'hf_clear_time' => $close_time
  868. ]);
  869. $store_order['hf_fee_amt'] = $res['fee_amt'];
  870. }
  871. }
  872. $yanglao = Db::name('user_bill')
  873. ->where('order_sn', $store_order['order_sn'])
  874. ->where('commission_type', 5)
  875. ->value('number');
  876. if (isset($res['status']) && time() > strtotime($close_time)) {
  877. if ($store_order['mer_id'] == 496) {
  878. $ru_money = $store_order['pay_price'] - $yanglao - $store_order['hf_fee_amt'];
  879. } else {
  880. $ru_money = ($store_order['pay_price'] * $shop_bonus_setting['shop_bonus_rate'] / 100) - $yanglao;
  881. }
  882. $store_order['pay_time'] = '';//线上支付的
  883. } else {
  884. continue;
  885. }
  886. }else{
  887. if ($store_order['mer_id'] == 496) {
  888. $ru_money = $store_order['pay_price'] - $yanglao;
  889. } else {
  890. $ru_money = ($store_order['pay_price'] * $shop_bonus_setting['shop_bonus_rate'] / 100) - $yanglao;
  891. }
  892. }
  893. Db::name('enterprise_platform_income_detail')
  894. ->insert([
  895. 'mer_id' => $mer_id,
  896. 'uid' => $store_order['uid'],
  897. 'title' => '创客自营订单让利',
  898. 'deal_order_sn' => $OrderMerchantRepository->getNewOrderId('jy4'),
  899. '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')),
  900. 'money' => $ru_money,
  901. 'deal_type' => 7,
  902. 'order_id' => $store_order['order_id'],
  903. 'order_sn' => $store_order['order_sn'],
  904. 'user_extra_id' => '',
  905. 'pm' => 1,
  906. 'create_time' => date('Y-m-d H:i:s'),
  907. ]);
  908. unset($close_time);
  909. }
  910. $start_time = '2024-04-01';
  911. for ($i = 0; $i < 1000; $i++) {
  912. $day = date('Y-m-d', strtotime("+{$i} days", strtotime($start_time)));
  913. if (strtotime($day) > time()) {
  914. break;
  915. }
  916. $Reconciliation->cron($day, 0);
  917. }
  918. return app('json')->success('获取平台收支明细成功');
  919. }
  920. public function clear_platform_income_detail()
  921. {
  922. Db::name('enterprise_platform_income_detail')->where('id', '>', 0)
  923. ->delete();
  924. }
  925. function getNextWorkday($date)
  926. {
  927. // 设置工作日数组
  928. $workdays = array(1, 2, 3, 4, 5); // 默认为周一到周五
  929. // 将日期字符串转换为时间戳
  930. $timestamp = strtotime($date);
  931. // 获取该日期的星期几
  932. $weekday = date('N', $timestamp);
  933. // 如果不是工作日,则增加一天直到是工作日
  934. while (!in_array($weekday, $workdays)) {
  935. $timestamp += (24 * 3600); // 增加一天
  936. $weekday = date('N', $timestamp); // 更新星期几
  937. }
  938. // 返回下一个工作日的日期字符串
  939. return date('Y-m-d H:i:s', $timestamp);
  940. }
  941. /**
  942. * @param $paymnet_params
  943. * @return array
  944. * 查询支付确认对象
  945. */
  946. public
  947. function payment_confirm_query_traits($paymnet_params)
  948. {
  949. $merber = new PaymentConfirm();
  950. $merber->query($paymnet_params);
  951. # 返回查询结果
  952. $merber->isError();
  953. return $merber->result;
  954. }
  955. }