|
|
@@ -0,0 +1,87 @@
|
|
|
+<?php
|
|
|
+
|
|
|
+namespace app\command;
|
|
|
+
|
|
|
+use app\model\saas\SaasBillsDay;
|
|
|
+use app\model\saas\SaasOrder;
|
|
|
+use app\model\saas\SaasStore;
|
|
|
+use Symfony\Component\Console\Command\Command;
|
|
|
+use Symfony\Component\Console\Input\InputInterface;
|
|
|
+use Symfony\Component\Console\Output\OutputInterface;
|
|
|
+use Symfony\Component\Console\Input\InputArgument;
|
|
|
+
|
|
|
+class BillsDay extends Command
|
|
|
+{
|
|
|
+
|
|
|
+
|
|
|
+ protected static string $defaultName = 'bills:day';
|
|
|
+ protected static string $defaultDescription = '每日账单';
|
|
|
+
|
|
|
+
|
|
|
+ /**
|
|
|
+ * @return void
|
|
|
+ */
|
|
|
+ protected function configure()
|
|
|
+ {
|
|
|
+ $this->addArgument('day', InputArgument::OPTIONAL, 'Name description');
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ protected function execute(InputInterface $input, OutputInterface $output): int
|
|
|
+ {
|
|
|
+ try {
|
|
|
+ $output->writeln("开始统计每日账单====>" . getDateFull());
|
|
|
+ $nextPage = 1;
|
|
|
+ $day = $input->getArgument("day");
|
|
|
+ $day = $day ?: date("Y-m-d",strtotime("-1 day"));
|
|
|
+ $betweenTime = [date('Y-m-d 00:00:00',strtotime($day)), date('Y-m-d 23:59:59',strtotime($day))];
|
|
|
+ while (is_numeric($nextPage)) {
|
|
|
+ $store = (new SaasStore)->where("status",1)->page($nextPage,10)->select();
|
|
|
+ if ($store->isEmpty()) {
|
|
|
+ $output->writeln("没有任务啦==".getDateFull());
|
|
|
+ $nextPage = null;
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+ $orderModel = (new SaasOrder);
|
|
|
+ foreach ($store as $key=>$item) {
|
|
|
+ $orderDay = $orderModel->where(['poi_id' => $item['poi_id'],"status" => 2,'express_status' => 3])->whereBetween("done_at",$betweenTime)->field("sum(price * number) as total,sum(life_fee) as life_fee_total,sum(star_fee) as star_fee_total,sum(sys_fee) as sys_fee_total,count(1) as num")->findOrEmpty();
|
|
|
+ $dayData = (new SaasBillsDay)->where(['poi_id'=>$item['poi_id'],'day'=>$day])->findOrEmpty();
|
|
|
+ if ($dayData->isEmpty()) {
|
|
|
+ echo getDateFull()."==【新增】{$item['poi_id']}=={$day}==\n";
|
|
|
+ $dayData->insertGetId([
|
|
|
+ "poi_id" => $item['poi_id'],
|
|
|
+ "title" => date('m月d日',strtotime($day))."收入",
|
|
|
+ "day" => $day,
|
|
|
+ "end_day" => date("Y-m-d",strtotime("+5 day",strtotime($day))),
|
|
|
+ "order_money" => $orderDay['total']??'0',
|
|
|
+ "life_fee_total" => $orderDay['life_fee_total']??'0',
|
|
|
+ "star_fee_total" => $orderDay['star_fee_total']??'0',
|
|
|
+ "sys_fee_total" => $orderDay['sys_fee_total']??'0',
|
|
|
+ "store_money" => $orderDay['total'] - ($orderDay['life_fee_total']+$orderDay['star_fee_total']+$orderDay['sys_fee_total']),
|
|
|
+ "order_num" => $orderDay['num'],
|
|
|
+ ]);
|
|
|
+ } else {
|
|
|
+ echo getDateFull()."==【更新】{$item['poi_id']}=={$day}==\n";
|
|
|
+ $dayData->save([
|
|
|
+ "order_money" => $orderDay['total']??'0',
|
|
|
+ "life_fee_total" => $orderDay['life_fee_total']??'0',
|
|
|
+ "star_fee_total" => $orderDay['star_fee_total']??'0',
|
|
|
+ "sys_fee_total" => $orderDay['sys_fee_total']??'0',
|
|
|
+ "store_money" => $orderDay['total'] - ($orderDay['life_fee_total']+$orderDay['star_fee_total']+$orderDay['sys_fee_total']),
|
|
|
+ "order_num" => $orderDay['num'],
|
|
|
+ ]);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ $nextPage = $nextPage+1;
|
|
|
+ $output->writeln("进入下一页=={$nextPage}==".getDateFull());
|
|
|
+ }
|
|
|
+ } catch (\Throwable $throwable) {
|
|
|
+ echo getDateFull()."===每日账单错误\n";
|
|
|
+ echo $throwable->getFile()."\n";
|
|
|
+ echo $throwable->getLine()."\n";
|
|
|
+ echo $throwable->getMessage()."\n";
|
|
|
+ }
|
|
|
+ return self::SUCCESS;
|
|
|
+ }
|
|
|
+
|
|
|
+}
|