| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293 |
- <?php
- namespace app\seller\controller;
- use app\common\controller\SellerController;
- use app\http\IResponse;
- class Index extends SellerController
- {
- /**
- *
- * @author 许祖兴 < zuxing.xu@lettered.cn>
- * @date 2020/7/16 17:54
- *
- * @return mixed
- * @throws \Lettered\Support\Exceptions\FailedException
- */
- public function setting()
- {
- //
- return IResponse::success($this->seller);
- }
- /**
- *
- * @author 许祖兴 < zuxing.xu@lettered.cn>
- * @date 2020/7/16 18:08
- *
- * @return mixed
- * @throws \think\db\exception\DataNotFoundException
- * @throws \think\db\exception\ModelNotFoundException
- * @throws \think\exception\DbException
- */
- public function getAgentStat()
- {
- // 接收数据
- $where = [];
- $where['seller_id'] = $this->seller->id;
- // 消费总额包含 商品、接单、技能、摩的
- // 直接读取支付记录表吧
- $coun = [
- 'total' => db('goods_order')->where($where)->sum('pay_price'),
- 'days' => db('goods_order')->where($where)->whereTime('created_at','d')->sum('pay_price'),
- 'month' => db('goods_order')->where($where)->whereTime('created_at','m')->sum('pay_price'),
- 'year' => db('goods_order')->where($where)->whereTime('created_at','y')->sum('pay_price')
- ];
- // 商品订单统计
- // 摩的订单统计
- // 配送订单统计
- // 技能订单统计
- $sdata = [
- 'goods' => [
- 'total' => db('goods_order')->where($where)->count(),
- 'days' => db('goods_order')->whereTime('created_at','d')->where($where)->count(),
- 'month' => db('goods_order')->whereTime('created_at','m')->where($where)->count(),
- 'year' => db('goods_order')->whereTime('created_at','y')->where($where)->count(),
- ]
- ];
- // 统计
- $order = [ 'total' => 0, 'days' => 0, 'month' => 0, 'year' => 0, ];
- foreach ($sdata as $item){
- $order['total'] += $item['total'];
- $order['days'] += $item['days'];
- $order['month'] += $item['month'];
- $order['year'] += $item['year'];
- }
- $data['order'] = $order;
- // 统计图
- $list = model('common/GoodsOrder')->where($where)
- ->field("COUNT(*) as total,FROM_UNIXTIME(created_at,'%m') as month")
- ->group('month')
- ->order('month desc')
- ->select();
- $res = [];
- for ($month = 1; $month <=12 ; $month ++){
- foreach ($list as $key => $value){
- if ($month == intval($value['month'])){
- $res[] = $value['total'];
- }else {
- $res[] = 0;
- }
- }
- }
- $data['coun'] = $coun;
- $data['chart'] = $res;
- return IResponse::success($data,"加载数据成功");
- }
- }
|