repository = $repository; $this->areaCode = $this->request->param('areaCode', ''); $this->streetCode = $this->request->param('streetCode', ''); if ($this->areaCode == '' && $this->streetCode == '') { throw new ValidateException('请选择地区'); } } // 商户列表 public function merchantList() { [$page, $limit] = $this->getPage(); $where = $this->request->params([ 'status', 'statusTag', 'is_trader', 'category_id', 'type_id', 'area_id', 'street_id']); return app('json')->success($this->repository->lst($where, $page, $limit)); } // 商户统计 public function merchantCountMain() { $merId = $this->request->param('mer_id'); $today = $this->mainGroup('today', $merId); $yesterday = $this->mainGroup('yesterday', $merId); $lastWeek = $this->mainGroup(date('Y-m-d', strtotime('- 7day')), $merId); $lastWeekRate = []; foreach ($lastWeek as $k => $item) { if ($item == $today[$k]) $lastWeekRate[$k] = 0; else if ($item == 0) $lastWeekRate[$k] = $today[$k]; else if ($today[$k] == 0) $lastWeekRate[$k] = -$item; else $lastWeekRate[$k] = (float)bcdiv(bcsub($today[$k], $item, 4), $item, 4); } $day = date('Y-m-d'); return app('json')->success(compact('today', 'yesterday', 'lastWeekRate', 'day')); } public function mainGroup($date, $merId) { $userVisitRepository = app()->make(UserVisitRepository::class); $repository = app()->make(StoreOrderRepository::class); $relationRepository = app()->make(UserRelationRepository::class); $payPrice = (float)$repository->dayOrderPrice($date, $merId); $payUser = (float)$repository->dayOrderUserNum($date, $merId); $visitNum = (float)$userVisitRepository->dateVisitUserNum($date, $merId); $likeStore = (float)$relationRepository->dayLikeStore($date, $merId); $productNum = \think\facade\Db::name('store_product')->alias('p')->field('count(p.product_id) as think_count') ->join('merchant m', 'm.mer_id = p.mer_id') ->whereTime('p.create_time', '<=', $date) ->where('m.mer_id', $merId) ->count(); // Db::name('store_product')->where('mer_id', $merId)->count(); return compact('productNum','payPrice', 'payUser', 'visitNum', 'likeStore'); } }