diff --git a/app/Console/Commands/couponReport.php b/app/Console/Commands/couponReport.php index 1af974f..f5e29f1 100644 --- a/app/Console/Commands/couponReport.php +++ b/app/Console/Commands/couponReport.php @@ -4,7 +4,6 @@ namespace App\Console\Commands; use Illuminate\Console\Command; use Illuminate\Support\Facades\DB; -use Illuminate\Support\Collection; class couponReport extends Command { @@ -13,7 +12,7 @@ class couponReport extends Command * * @var string */ - protected $signature = 'command:couponReport'; + protected $signature = 'command:couponReport {start?} {end?} {--ret=0}'; /** * The console command description. @@ -39,7 +38,13 @@ class couponReport extends Command */ public function handle() { - $where = ['1597248000','1597334399']; + $start = $this->argument('start'); + $end = $this->argument('end'); + $return = $this->option('ret'); + + $start = $start ? $start : date('Y-m-d',time()); + $end = $end ? $end : date('Y-m-d',time()); + $where = [strtotime($start.' 00:00:00'),strtotime($end.' 23:59:59')]; // 统计优惠券订单数据-金额 $orderTotal = DB::select("SELECT @@ -75,25 +80,25 @@ class couponReport extends Command $where ); // 查询优惠券订单用户数据 - $orderList = DB::select("SELECT - uu.id AS 序号 - ,IF(uu.status=1,'已使用','已退回') AS 使用状态 - ,user.id AS 用户ID - ,main.order_num AS 订单号 - ,main.money AS 订单金额 - ,conpon.title AS 优惠券种类 - ,user.`name` AS 用户昵称 - ,main.`name` AS 用户姓名 - ,main.tel AS 用户电话 - ,main.address AS 用户地址 - FROM ims_system_coupon_user_use uu - INNER JOIN ims_system_coupon_user conpon ON conpon.id=uu.system_coupon_id - INNER JOIN ims_cjdc_user user ON user.id=uu.user_id - INNER JOIN ims_cjdc_order_main main ON main.id=uu.order_main_id - WHERE main.time_add BETWEEN ? AND ? - ORDER BY uu.`status` ASC", - $where - ); + // $orderList = DB::select("SELECT + // uu.id AS 序号 + // ,IF(uu.status=1,'已使用','已退回') AS 使用状态 + // ,user.id AS 用户ID + // ,main.order_num AS 订单号 + // ,main.money AS 订单金额 + // ,conpon.title AS 优惠券种类 + // ,user.`name` AS 用户昵称 + // ,main.`name` AS 用户姓名 + // ,main.tel AS 用户电话 + // ,main.address AS 用户地址 + // FROM ims_system_coupon_user_use uu + // INNER JOIN ims_system_coupon_user conpon ON conpon.id=uu.system_coupon_id + // INNER JOIN ims_cjdc_user user ON user.id=uu.user_id + // INNER JOIN ims_cjdc_order_main main ON main.id=uu.order_main_id + // WHERE main.time_add BETWEEN ? AND ? + // ORDER BY uu.`status` ASC", + // $where + // ); $orderArray = []; foreach($orderTotal as $value){ @@ -104,13 +109,15 @@ class couponReport extends Command $receiveArray[] = (array)$value; } $listArray = []; - foreach($orderList as $value){ - $listArray[] = (array)$value; + // foreach($orderList as $value){ + // $listArray[] = (array)$value; + // } + if($return){ + return json_encode(compact($orderTotal,$receiveCoupon,$orderList)); + }else{ + $this->table(['优惠券标题','使用优惠券消费总额(实付总金额)','订单总额(不包含配送费,含包装费)','配送费','优惠总金额','总订单数量'],$orderArray); + $this->table(['ID','优惠券标题','满足金额','优惠金额','发放数量','已领取数量','使用数量'],$receiveArray); + // $this->table(['序号','使用状态','用户ID','订单号','订单金额','优惠券种类','用户昵称','用户姓名','用户电话','用户地址'],$listArray); } - - $this->table(['优惠券标题','使用优惠券消费总额(实付总金额)','订单总额(不包含配送费,含包装费)','配送费','优惠总金额','总订单数量'],$orderArray); - $this->table(['ID','优惠券标题','满足金额','优惠金额','发放数量','已领取数量','使用数量'],$receiveArray); - $this->table(['序号','使用状态','用户ID','订单号','订单金额','优惠券种类','用户昵称','用户姓名','用户电话','用户地址'],$listArray); - return 0; } } diff --git a/app/Console/Kernel.php b/app/Console/Kernel.php index 69914e9..cb268b6 100644 --- a/app/Console/Kernel.php +++ b/app/Console/Kernel.php @@ -14,6 +14,7 @@ class Kernel extends ConsoleKernel */ protected $commands = [ // + Commands\couponReport::class, ]; /**