Index.php 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. <?php
  2. namespace app\seller\controller;
  3. use app\common\controller\SellerController;
  4. use app\http\IResponse;
  5. class Index extends SellerController
  6. {
  7. /**
  8. *
  9. * @author 许祖兴 < zuxing.xu@lettered.cn>
  10. * @date 2020/7/16 17:54
  11. *
  12. * @return mixed
  13. * @throws \Lettered\Support\Exceptions\FailedException
  14. */
  15. public function setting()
  16. {
  17. //
  18. return IResponse::success($this->seller);
  19. }
  20. /**
  21. *
  22. * @author 许祖兴 < zuxing.xu@lettered.cn>
  23. * @date 2020/7/16 18:08
  24. *
  25. * @return mixed
  26. * @throws \think\db\exception\DataNotFoundException
  27. * @throws \think\db\exception\ModelNotFoundException
  28. * @throws \think\exception\DbException
  29. */
  30. public function getAgentStat()
  31. {
  32. // 接收数据
  33. $where = [];
  34. $where['seller_id'] = $this->seller->id;
  35. // 消费总额包含 商品、接单、技能、摩的
  36. // 直接读取支付记录表吧
  37. $coun = [
  38. 'total' => db('goods_order')->where($where)->sum('pay_price'),
  39. 'days' => db('goods_order')->where($where)->whereTime('created_at','d')->sum('pay_price'),
  40. 'month' => db('goods_order')->where($where)->whereTime('created_at','m')->sum('pay_price'),
  41. 'year' => db('goods_order')->where($where)->whereTime('created_at','y')->sum('pay_price')
  42. ];
  43. // 商品订单统计
  44. // 摩的订单统计
  45. // 配送订单统计
  46. // 技能订单统计
  47. $sdata = [
  48. 'goods' => [
  49. 'total' => db('goods_order')->where($where)->count(),
  50. 'days' => db('goods_order')->whereTime('created_at','d')->where($where)->count(),
  51. 'month' => db('goods_order')->whereTime('created_at','m')->where($where)->count(),
  52. 'year' => db('goods_order')->whereTime('created_at','y')->where($where)->count(),
  53. ]
  54. ];
  55. // 统计
  56. $order = [ 'total' => 0, 'days' => 0, 'month' => 0, 'year' => 0, ];
  57. foreach ($sdata as $item){
  58. $order['total'] += $item['total'];
  59. $order['days'] += $item['days'];
  60. $order['month'] += $item['month'];
  61. $order['year'] += $item['year'];
  62. }
  63. $data['order'] = $order;
  64. // 统计图
  65. $list = model('common/GoodsOrder')->where($where)
  66. ->field("COUNT(*) as total,FROM_UNIXTIME(created_at,'%m') as month")
  67. ->group('month')
  68. ->order('month desc')
  69. ->select();
  70. $res = [];
  71. for ($month = 1; $month <=12 ; $month ++){
  72. foreach ($list as $key => $value){
  73. if ($month == intval($value['month'])){
  74. $res[] = $value['total'];
  75. }else {
  76. $res[] = 0;
  77. }
  78. }
  79. }
  80. $data['coun'] = $coun;
  81. $data['chart'] = $res;
  82. return IResponse::success($data,"加载数据成功");
  83. }
  84. }