Index.php 3.1 KB

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