链街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.

116 lines
4.5 KiB

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