链街Dcat后台
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

125 lines
5.1 KiB

  1. <?php
  2. namespace App\Console\Commands;
  3. use Illuminate\Console\Command;
  4. use Illuminate\Support\Facades\DB;
  5. class couponReport extends Command
  6. {
  7. /**
  8. * The name and signature of the console command.
  9. *
  10. * @var string
  11. */
  12. protected $signature = 'command:couponReport {start?} {end?} {--ret=0}';
  13. /**
  14. * The console command description.
  15. *
  16. * @var string
  17. */
  18. protected $description = 'Command 每日优惠券统计';
  19. /**
  20. * Create a new command instance.
  21. *
  22. * @return void
  23. */
  24. public function __construct()
  25. {
  26. parent::__construct();
  27. }
  28. /**
  29. * Execute the console command.
  30. *
  31. * @return int
  32. */
  33. public function handle()
  34. {
  35. $start = $this->argument('start');
  36. $end = $this->argument('end');
  37. $return = $this->option('ret');
  38. $start = $start ? $start : date('Y-m-d',time());
  39. $end = $end ? $end : date('Y-m-d',time());
  40. $where = [strtotime($start.' 00:00:00'),strtotime($end.' 23:59:59')];
  41. // 统计优惠券订单数据-金额
  42. $orderTotal = DB::select("SELECT
  43. uses.system_coupon_id as ID
  44. ,coupon.title '优惠券标题'
  45. ,SUM(om.money) as '使用优惠券消费总额(实付总金额)'
  46. ,SUM(om.total_money) as '订单总额(不包含配送费,含包装费)'
  47. ,SUM(om.dada_fee) as '配送费'
  48. ,SUM(om.yhq_money2)as '优惠总金额'
  49. ,COUNT(om.id) as '总订单数量'
  50. FROM
  51. ims_system_coupon_user_use uses
  52. INNER JOIN ims_cjdc_order_main om ON uses.order_main_id = om.id
  53. INNER JOIN ims_system_coupon_user coupon ON coupon.id=uses.system_coupon_id
  54. WHERE uses.`status` = 1 AND om.time_add BETWEEN ? AND ?
  55. GROUP BY uses.system_coupon_id ORDER BY uses.system_coupon_id DESC",
  56. $where
  57. );
  58. // 查询领取数量和统计数量-总数
  59. $receiveCoupon = DB::select("SELECT
  60. coupon.id as ID
  61. ,title as '优惠券标题'
  62. ,full_amount as '满足金额'
  63. ,discounts as '优惠金额'
  64. ,inventory AS '发放数量'
  65. ,SUM(IFNULL(receive.number,0)) as '领取数量'
  66. ,IFNULL((SELECT SUM(IFNULL(number,0)) FROM ims_system_coupon_user_use WHERE system_coupon_id = coupon.id AND status = 1 AND use_time BETWEEN ? AND ?),0) AS 使用数量
  67. FROM
  68. ims_system_coupon_user coupon
  69. LEFT JOIN ims_system_coupon_user_receive receive ON coupon.id = receive.system_coupon_user_id
  70. WHERE receive.created_at BETWEEN ? AND ?
  71. GROUP BY coupon.id ORDER BY coupon.id DESC",
  72. array_merge($where,$where)
  73. );
  74. // 查询优惠券订单用户数据
  75. // $orderList = DB::select("SELECT
  76. // uu.id AS 序号
  77. // ,IF(uu.status=1,'已使用','已退回') AS 使用状态
  78. // ,user.id AS 用户ID
  79. // ,main.order_num AS 订单号
  80. // ,main.money AS 订单金额
  81. // ,conpon.title AS 优惠券种类
  82. // ,user.`name` AS 用户昵称
  83. // ,main.`name` AS 用户姓名
  84. // ,main.tel AS 用户电话
  85. // ,main.address AS 用户地址
  86. // FROM ims_system_coupon_user_use uu
  87. // INNER JOIN ims_system_coupon_user conpon ON conpon.id=uu.system_coupon_id
  88. // INNER JOIN ims_cjdc_user user ON user.id=uu.user_id
  89. // INNER JOIN ims_cjdc_order_main main ON main.id=uu.order_main_id
  90. // WHERE main.time_add BETWEEN ? AND ?
  91. // ORDER BY uu.`status` ASC",
  92. // $where
  93. // );
  94. $orderArray = [];
  95. foreach($orderTotal as $value){
  96. $orderArray[] = (array)$value;
  97. }
  98. $receiveArray = [];
  99. foreach($receiveCoupon as $value){
  100. $receiveArray[] = (array)$value;
  101. }
  102. $listArray = [];
  103. // foreach($orderList as $value){
  104. // $listArray[] = (array)$value;
  105. // }
  106. if($return){
  107. // return json_encode(compact($orderTotal,$receiveCoupon,$orderList));
  108. }else{
  109. $this->table(['ID','优惠券标题','使用优惠券消费总额(实付总金额)','订单总额(不包含配送费,含包装费)','配送费','优惠总金额','总订单数量'],$orderArray);
  110. $this->table(['ID','优惠券标题','满足金额','优惠金额','发放数量','已领取数量','使用数量'],$receiveArray);
  111. // $this->table(['序号','使用状态','用户ID','订单号','订单金额','优惠券种类','用户昵称','用户姓名','用户电话','用户地址'],$listArray);
  112. }
  113. }
  114. }