Stats.php 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  1. <?php
  2. namespace app\agent\controller\finance;
  3. use app\common\controller\AgentController;
  4. use app\common\model\GoodsOrder;
  5. use app\common\model\MissionOrder;
  6. use app\common\model\SkillOrder;
  7. use app\common\model\TaxiOrder;
  8. use app\http\IResponse;
  9. use Lettered\Support\Auth as IAuth;
  10. use think\App;
  11. use think\db\Query;
  12. use think\Request;
  13. class Stats extends AgentController
  14. {
  15. protected $model;
  16. public function __construct(App $app = null, IAuth $auth)
  17. {
  18. parent::__construct($app, $auth);
  19. $this->model = new \app\agent\model\finance\Stats();
  20. }
  21. /**
  22. * 显示资源列表
  23. *
  24. * @return \think\Response
  25. * @throws \Lettered\Support\Exceptions\FailedException
  26. */
  27. public function index()
  28. {
  29. $area_id = $this->auth->user()['area_id'];
  30. $TaxiOrder = new TaxiOrder();
  31. // $GoodsOrder = new GoodsOrder();
  32. // $SkillOrder = new SkillOrder();
  33. // $MissionOrder = new MissionOrder();
  34. $modelArray = [$TaxiOrder];
  35. // 消费总额包含 商品、接单、技能、摩的
  36. $where = [
  37. 'area_id' => $area_id,
  38. 'status' => [0,2,3,4]
  39. ];
  40. // 直接读取支付记录表吧
  41. $count = [
  42. 'total' => $TaxiOrder->where($where)->sum('price'),
  43. 'today' => $TaxiOrder->where($where)->whereTime('created_at', 'd')->sum('price'),
  44. 'month' => $TaxiOrder->where($where)->whereTime('created_at', 'm')->sum('price'),
  45. 'year' => $TaxiOrder->where($where)->whereTime('created_at', 'y')->sum('price')
  46. ];
  47. // 订单统计
  48. $order = [
  49. 'total' => $TaxiOrder->where($where)->count(),
  50. 'today' => $TaxiOrder->where($where)->whereTime('created_at', 'd')->count(),
  51. 'month' => $TaxiOrder->where($where)->whereTime('created_at', 'm')->count(),
  52. 'year' => $TaxiOrder->where($where)->whereTime('created_at', 'y')->count()
  53. ];
  54. /*foreach ($modelArray as $key => $item) {
  55. $row = $this->model->getStats(
  56. $item,
  57. $key ? 'pay_price' : 'price',
  58. 'id',
  59. [
  60. 'area_id' => $area_id,
  61. 'status' => [0,2,3,4]
  62. ],
  63. [
  64. 'paylog'
  65. ]
  66. );
  67. foreach ($row as $index => $value) {
  68. $count[$index] += array_sum($row[$index]);
  69. $order[$index] += count($row[$index]);
  70. }
  71. }*/
  72. // 统计图
  73. $res = [];
  74. for ($month = 1; $month <=12 ; $month ++){
  75. $res[] = model('common/GoodsOrder')->whereTime('created_at', 'between', $this->model->getMonthTime($month))
  76. ->count('*');;
  77. }
  78. $data['coun'] = $count;
  79. $data['chart'] = $res;
  80. $data['order'] = $order;
  81. return IResponse::success($data,"加载数据成功");
  82. }
  83. /**
  84. * 显示创建资源表单页.
  85. *
  86. * @return \think\Response
  87. */
  88. public function create()
  89. {
  90. //
  91. }
  92. /**
  93. * 保存新建的资源
  94. *
  95. * @param \think\Request $request
  96. * @return \think\Response
  97. */
  98. public function save(Request $request)
  99. {
  100. //
  101. }
  102. /**
  103. * 显示指定的资源
  104. *
  105. * @param int $id
  106. * @return \think\Response
  107. */
  108. public function read($id)
  109. {
  110. //
  111. }
  112. /**
  113. * 显示编辑资源表单页.
  114. *
  115. * @param int $id
  116. * @return \think\Response
  117. */
  118. public function edit($id)
  119. {
  120. //
  121. }
  122. /**
  123. * 保存更新的资源
  124. *
  125. * @param \think\Request $request
  126. * @param int $id
  127. * @return \think\Response
  128. */
  129. public function update(Request $request, $id)
  130. {
  131. //
  132. }
  133. /**
  134. * 删除指定资源
  135. *
  136. * @param int $id
  137. * @return \think\Response
  138. */
  139. public function delete($id)
  140. {
  141. //
  142. }
  143. }