model = new Store; } /** * 浏览 * @return Response */ public function index(): Response { return view('store/index'); } /** * 插入 * @param Request $request * @return Response * @throws BusinessException */ public function insert(Request $request): Response { if ($request->method() === 'POST') { return parent::insert($request); } return view('store/insert'); } /** * 更新 * @param Request $request * @return Response * @throws BusinessException */ public function update(Request $request): Response { if ($request->method() === 'POST') { return parent::update($request); } return view('store/update'); } /** * 更新 * @param Request $request * @return Response * @throws BusinessException */ public function list(Request $request): Response { $brand = $request->input('brand'); $channel = $request->input('channel'); $where = []; if(!empty($brand)){ $where['brand'] = $brand; } if(!empty($channel)){ $where['channel'] = $channel; } $store = Store::where($where)->get(); return util::success($store); } /** * 门店数量 * @param Request $request * @return Response * @throws BusinessException */ public function storeNum(Request $request): Response { $area = $request->input('area'); $where = []; if($area != 0){ $where['area'] = $area; } $where['area'] = $area; $store = Store::query() ->select([ 'brand', DB::raw('count(*) as count') ])->where($where) ->groupBy('brand')->get()->toArray(); // $brand = array_column($store, 'brand'); $brand = $this->brand; // $count = array_column($store, 'count'); foreach ($brand as $value) { $count[$value] = 0; } foreach ($store as $value) { $count[$value['brand']] = $value['count']; } $count = array_values($count); return util::success(['name'=>$brand,'statistics'=>$count,$store]); } /** * 营业额统计 * @param Request $request * @return Response * @throws BusinessException */ public function turnover(Request $request): Response { $area = $request->input('area'); $where = []; if($area != 0){ $where['area'] = $area; } $store = Store::query() ->select([ 'brand', DB::raw('SUM(turnover) as total') ])->where($where) ->groupBy('brand') ->get()->toArray(); // $brand = array_column($store, 'brand'); $brand = $this->brand; // $total = array_column($store, 'total'); foreach ($brand as $value) { $total[$value] = 0; } foreach ($store as $value) { $total[$value['brand']] = $value['total']; } $total = array_values($total); return util::success(['name'=>$brand,'statistics'=>$total,$store]); } /** * 渠道品牌营业额对比 * @param Request $request * @return Response * @throws BusinessException */ public function channelTurnover(Request $request): Response { $area = $request->input('area'); $where = []; if($area != 0){ $where['area'] = $area; } $store = Store::query() ->select([ 'brand','channel', DB::raw('SUM(turnover) as total') ])->where($where) ->groupBy('brand','channel')->orderBy('channel') ->get()->toArray(); // $brand = array_unique(array_column($store,'brand')); // $channel = array_unique(array_column($store,'channel')); $brand = $this->brand; $channel = $this->channel; $res = []; foreach ($this->brand as $item){ foreach ($this->channel as $key){ $res[$item][$key] = 0; } } foreach ($store as $item){ $res[$item['brand']][$item['channel']] = $item['total']; } return util::success(['brand'=>$brand,'channel'=>$channel,'statistics'=>$res,$store]); } /** * 按渠道分析品牌门店数 * @param Request $request * @return Response * @throws BusinessException */ public function storeTurnover(Request $request): Response { $area = $request->input('area'); $where = []; if($area != 0){ $where['area'] = $area; } $store = Store::query() ->select([ 'brand','channel', DB::raw('count(turnover) as count') ])->where($where) ->groupBy('channel','brand') ->orderBy('brand') ->get()->toArray(); // $brand = array_unique(array_column($store,'brand')); // $channel = array_unique(array_column($store,'channel')); $brand = $this->brand; $channel = $this->channel; $res = []; foreach ($this->channel as $item){ foreach ($this->brand as $key){ $res[$item][$key] = 0; } } foreach ($store as $item){ $res[$item['channel']][$item['brand']] = $item['count']; } return util::success(['brand'=>$brand,'channel'=>$channel,'statistics'=>$res,$store]); } /** * 按渠道统计各品牌零售 * @param Request $request * @return Response * @throws BusinessException */ public function channelStoreTurnover(Request $request): Response { $area = $request->input('area'); $where = []; if($area != 0){ $where['area'] = $area; } $store = Store::query() ->select([ 'brand','channel', DB::raw('SUM(turnover) as total') ])->where($where) ->groupBy('channel','brand')->orderBy('channel') ->get()->toArray(); // $brand = array_unique(array_column($store,'brand')); // $channel = array_unique(array_column($store,'channel')); $brand = $this->brand; $channel = $this->channel; $res = []; foreach ($this->channel as $item){ foreach ($this->brand as $key){ $res[$item][$key] = 0; } } foreach ($store as $item){ $res[$item['channel']][$item['brand']] = $item['total']; } return util::success(['brand'=>$brand,'channel'=>$channel,'statistics'=>$res,$store]); } /** * 插入 * @param Request $request * @return Response * @throws BusinessException */ public function inster(Request $request): Response { $json = []; foreach ($json as $key => $value) { $store = new Store(); $store->brand = $value['styleId']; $store->name = $value['title']; $store->lat = $value['lat']; $store->lng = $value['lng']; $store->area = 0; $store->turnover = 0; $store->channel = ''; $store->save(); } return util::success($store); } }