Total.php 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. <?php
  2. namespace app\command;
  3. // +----------------------------------------------------------------------
  4. // | [ WE CAN DO IT MORE SIMPLE ]
  5. // +----------------------------------------------------------------------
  6. // | Copyright (c) 2018-2020 rights reserved.
  7. // +----------------------------------------------------------------------
  8. // | Author: TABLE ME
  9. // +----------------------------------------------------------------------
  10. // | Date: 2020-09-08 16:19
  11. // +----------------------------------------------------------------------
  12. use app\model\system\Product;
  13. use app\model\system\Site;
  14. use library\utils\Qiniu;
  15. use think\console\Command;
  16. use think\console\Input;
  17. use think\console\Output;
  18. use think\facade\Db;
  19. /**
  20. * 生成业绩报表
  21. * @author huangjianfeng
  22. */
  23. class Total extends Command
  24. {
  25. protected function configure()
  26. {
  27. $this
  28. ->setName('Total')
  29. ->setDescription('每日统计分站业绩报表!')
  30. ->addArgument('action', null, "");
  31. }
  32. protected function execute(Input $input, Output $output){
  33. $time = strtotime(date('Y-m-d',strtotime('-1 day')));
  34. $this->expData($time);
  35. }
  36. private function expData($time){
  37. $siteData = (new Site)->select()->toArray();
  38. foreach ($siteData as $v) {
  39. $this->expTotal($v,$time);
  40. }
  41. }
  42. /**
  43. * 订单统计
  44. * @param $data
  45. */
  46. private function expTotal($data,$time) {
  47. $btime = $time;
  48. $etime = $time + 86400;
  49. $d = [];
  50. $d['sassid'] = $data['sassid'];
  51. //会员量
  52. $d['user_count'] = Db::name("member")
  53. ->where('sassid',$data['sassid'])
  54. ->whereRaw('regtime >= :time1 and regtime < :time2',['time1'=>$btime,'time2'=>$etime])
  55. ->count();
  56. //主订单
  57. $d['order_count'] = Db::name("order")
  58. ->where('sassid',$data['sassid'])
  59. ->where('status','>',0)
  60. ->whereRaw('time >= :time1 and time < :time2',['time1'=>$btime,'time2'=>$etime])
  61. ->count();
  62. //子订单
  63. $d['sub_order_count'] = Db::name("order_info")
  64. ->where('sassid',$data['sassid'])
  65. ->where('status','>',0)
  66. ->whereRaw('time >= :time1 and time < :time2',['time1'=>$btime,'time2'=>$etime])
  67. ->count();
  68. //订单金额
  69. $d['order_money'] = Db::name("order")
  70. ->where('sassid',$data['sassid'])
  71. ->where('status','>',0)
  72. ->whereRaw('time >= :time1 and time < :time2',['time1'=>$btime,'time2'=>$etime])
  73. ->sum('all_price');
  74. $d['order_money'] = empty($d['order_money']) ? 0 : $d['order_money'];
  75. //充值金额
  76. $d['recharge_money'] = Db::name("recharge")
  77. ->where('sassid',$data['sassid'])
  78. ->where('status',1)
  79. ->whereRaw('time >= :time1 and time < :time2',['time1'=>$btime,'time2'=>$etime])
  80. ->sum('v');
  81. $d['recharge_money'] = empty($d['recharge_money']) ? 0 : $d['recharge_money'];
  82. //佣金金额
  83. $d['commission_money'] = Db::name("site_detail")
  84. ->where('sassid',$data['sassid'])
  85. ->where('type',1)
  86. ->whereRaw('time >= :time1 and time < :time2',['time1'=>$btime,'time2'=>$etime])
  87. ->sum('v');
  88. $count = Db::name("site_total")
  89. ->where('time',$time)
  90. ->where('sassid',$data['sassid'])
  91. ->count();
  92. if($count > 0) {
  93. Db::name("site_total")
  94. ->where('time',$time)
  95. ->where('sassid',$data['sassid'])
  96. ->update($d);
  97. } else {
  98. $d['time'] = $time;
  99. $d['sassid'] = $data['sassid'];
  100. Db::name("site_total")->insert($d);
  101. }
  102. echo "[" . date('Y-m-d',$time)."]".$data['name']." 会员量" . $d['user_count'] . ",订单量:" . $d['order_count'] . ",子订单量:" .$d['sub_order_count']
  103. .",订单总额:" . $d['order_money'] . ",充值金额:" .$d['recharge_money'].
  104. ",佣金金额:" . $d['commission_money'].PHP_EOL;
  105. }
  106. }