DayMoney.php 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. <?php
  2. namespace app\command;
  3. use app\extra\jhfPay\Pay;
  4. use app\model\saas\SaasOrder;
  5. use app\model\saas\SaasShop;
  6. use app\model\saas\SaasUserBuy;
  7. use app\model\system\SystemUserMoney;
  8. use Symfony\Component\Console\Command\Command;
  9. use Symfony\Component\Console\Input\InputInterface;
  10. use Symfony\Component\Console\Output\OutputInterface;
  11. class DayMoney extends Command
  12. {
  13. protected static string $defaultName = 'day:money';
  14. protected static string $defaultDescription = '每日结算金额统计';
  15. protected function execute(InputInterface $input, OutputInterface $output): int
  16. {
  17. $nextPage = 1;$done = 0;
  18. $mode = (new SaasShop);
  19. $orderMode = (new SaasOrder);
  20. $moneyMode = (new SystemUserMoney);
  21. $cardMode = (new SaasUserBuy);
  22. $day = date("Y-m-d",strtotime("-1 day"));
  23. // $respJhf = (new Pay)->config([
  24. // "appid" => sConf("wechat.jhf_appid"),
  25. // "mch_id" => sConf("wechat.jhf_mch_id"),
  26. // "aeskey" => sConf("wechat.jhf_aeskey"),
  27. // "pubkey" => sConf("wechat.jhf_pubkey"),
  28. // "prikey" => sConf("wechat.jhf_prikey"),
  29. // ]);
  30. while (is_numeric($nextPage)) {
  31. $total = $mode->count();
  32. $result = $mode->limit(($nextPage-1)*10,10)->with(['card'])->select();
  33. if ($result->isEmpty()) {
  34. $output->writeln('没有更多数据啦~==>'.getDateFull());
  35. $nextPage = null;
  36. return self::SUCCESS;
  37. }
  38. if ($done >= $total){
  39. $output->writeln('没有更多数据啦!~==>'.getDateFull());
  40. $nextPage = null;
  41. return self::SUCCESS;
  42. }
  43. $moneyData = [];
  44. foreach ($result as $key => $val)
  45. {
  46. ++$done;
  47. if (empty($val['cash_rate'])) {
  48. $rate = 0.006;
  49. } else {
  50. $rate = $val['cash_rate'] / 100;
  51. }
  52. $dayData = $moneyMode->where("agent_id",$val['shop_id'])->where("day",$day)->findOrEmpty();
  53. if ($dayData->isEmpty()) {
  54. $dayMoney = $orderMode->where("shop_id",$val['shop_id'])->whereIn("status",[1,2,3])->whereDay("create_at","yesterday")->where("pay_type",1)->sum("money");
  55. $cardMoney = $cardMode->where("shop_id",$val['shop_id'])->where("status",1)->whereDay("create_at","yesterday")->sum("money");
  56. $status = 0;
  57. $memberId = $val['card']['member_id']??'';
  58. if ($dayMoney == 0) {
  59. $status = 1;
  60. }
  61. $totalMoney = $dayMoney + $cardMoney;
  62. $rateMoney = ($totalMoney==0)?0:round($totalMoney*$rate);
  63. $endMoney = round($totalMoney - $rateMoney,0);
  64. $moneyData[$key] = [
  65. "order_sn" => strtoupper(md5($day.$val['shop_id'])),
  66. "agent_id" => $val['shop_id'],
  67. "money" => $endMoney,
  68. "re_money" => $totalMoney, // 当日金额
  69. "order_money" => $dayMoney,
  70. "user_money" => $cardMoney, // 会员卡充值金额
  71. "rate" => $rateMoney,
  72. "day" => $day,
  73. "status" => $status,
  74. "member_id" => $memberId
  75. ];
  76. // if (!empty($memberId) && $totalMoney > 0) { // 发起余额分账
  77. // $shopName = $val['shop_name']??'';
  78. // $respJhf->createBalancePay([
  79. // "app_id" => sConf("wechat.jhf_appid"),
  80. // "order_no" => strtoupper(md5($day.$val['shop_id'])),
  81. // "member_id" => $memberId,
  82. // "pay_amt" => format_money($endMoney/100,2),
  83. // "description" => "{$day}-{$shopName}-结算"
  84. // ]);
  85. // }
  86. echo getDateFull()."==={$val['shop_id']}=={$val['shop_name']}==当天营业额统计===¥{$totalMoney}====结算卡:{$memberId}==状态:{$status}===\n";
  87. } else {
  88. echo getDateFull()."==={$val['shop_id']}=={$val['shop_name']}=={$day}==已完成统计===\n";
  89. }
  90. }
  91. if (!empty($moneyData)) {
  92. $moneyMode->insertAll(array_values($moneyData));
  93. }
  94. $nextPage = $nextPage+1;
  95. $output->writeln("当前页码{$nextPage}==>".getDateFull());
  96. }
  97. return self::SUCCESS;
  98. }
  99. }