Stats.php 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  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. // 直接读取支付记录表吧
  37. $count = ['total' => 0, 'today' => 0, 'month' => 0, 'year' => 0];
  38. // 订单统计
  39. $order = ['total' => 0, 'today' => 0, 'month' => 0, 'year' => 0];
  40. foreach ($modelArray as $key => $item) {
  41. $row = $this->model->getStats(
  42. $item,
  43. $key ? 'pay_price' : 'price',
  44. 'id',
  45. [
  46. 'area_id' => $area_id,
  47. 'status' => [0,2,3,4]],
  48. [
  49. 'paylog'
  50. ]
  51. );
  52. foreach ($row as $index => $value) {
  53. $count[$index] += array_sum($row[$index]);
  54. $order[$index] += count($row[$index]);
  55. }
  56. }
  57. // 统计图
  58. $res = [];
  59. for ($month = 1; $month <=12 ; $month ++){
  60. $res[] = model('common/GoodsOrder')->whereTime('created_at', 'between', $this->model->getMonthTime($month))
  61. ->count('*');;
  62. }
  63. $data['coun'] = $count;
  64. $data['chart'] = $res;
  65. $data['order'] = $order;
  66. return IResponse::success($data,"加载数据成功");
  67. }
  68. /**
  69. * 显示创建资源表单页.
  70. *
  71. * @return \think\Response
  72. */
  73. public function create()
  74. {
  75. //
  76. }
  77. /**
  78. * 保存新建的资源
  79. *
  80. * @param \think\Request $request
  81. * @return \think\Response
  82. */
  83. public function save(Request $request)
  84. {
  85. //
  86. }
  87. /**
  88. * 显示指定的资源
  89. *
  90. * @param int $id
  91. * @return \think\Response
  92. */
  93. public function read($id)
  94. {
  95. //
  96. }
  97. /**
  98. * 显示编辑资源表单页.
  99. *
  100. * @param int $id
  101. * @return \think\Response
  102. */
  103. public function edit($id)
  104. {
  105. //
  106. }
  107. /**
  108. * 保存更新的资源
  109. *
  110. * @param \think\Request $request
  111. * @param int $id
  112. * @return \think\Response
  113. */
  114. public function update(Request $request, $id)
  115. {
  116. //
  117. }
  118. /**
  119. * 删除指定资源
  120. *
  121. * @param int $id
  122. * @return \think\Response
  123. */
  124. public function delete($id)
  125. {
  126. //
  127. }
  128. }