request->get('date', date('Y-m-d')); $store_id = $this->request->get('store_id', 0); if ($store_id) { $where['store_id'] = $store_id; } $where['paid'] = 1; $res = OrderLogic::dayPayPrice($where, $time); if (OrderLogic::hasError()) { return $this->fail(OrderLogic::getError()); //获取错误信息并返回错误信息 } switch ($store_id) { case 1: $title = '喻寺镇农(特)产品交易大数据'; break; case 2: $title = '立石镇农(特)产品交易大数据'; break; case 3: $title = '百和镇农(特)产品交易大数据'; break; case 4: $title = '得胜镇农(特)产品交易大数据'; break; case 5: $title = '玄滩镇农(特)产品交易大数据'; break; case 6: $title = '牛滩镇农(特)产品交易大数据'; break; case 7: $title = '云锦镇农(特)产品交易大数据'; break; default: $title = '泸县农(特)产品交易大数据'; break; } return $this->success('ok', ['dayPayPrice' => $res, 'title' => $title]); } /** * 门店统计 */ public function sotre_count() { $data = [ ['street_name' => '喻寺镇', 'merchant_count' => 1], ['street_name' => '立石镇', 'merchant_count' => 1], ['street_name' => '百和镇', 'merchant_count' => 1], ['street_name' => '得胜镇', 'merchant_count' => 1], ['street_name' => '玄滩镇', 'merchant_count' => 1], ['street_name' => '云锦镇', 'merchant_count' => 1], ]; return $this->success('ok', ['merchatCountList' => $data, 'merchantTotalCount' => count($data)]); } /** * 地方商品数量统计 */ public function product_count_sotre_count() { $time = $this->request->get('date', date('Y-m-d')); $data = [ ['street_name' => '喻寺镇', 'product_count' => StoreBranchProduct::where('store_id',1)->where('create_time','<=',strtotime($time))->count()], ['street_name' => '立石镇', 'product_count' => StoreBranchProduct::where('store_id',2)->where('create_time','<=',strtotime($time))->count()], ['street_name' => '百和镇', 'product_count' => StoreBranchProduct::where('store_id',3)->where('create_time','<=',strtotime($time))->count()], ['street_name' => '得胜镇', 'product_count' => StoreBranchProduct::where('store_id',5)->where('create_time','<=',strtotime($time))->count()], ['street_name' => '玄滩镇', 'product_count' => StoreBranchProduct::where('store_id',6)->where('create_time','<=',strtotime($time))->count()], ['street_name' => '云锦镇', 'product_count' => StoreBranchProduct::where('store_id',7)->where('create_time','<=',strtotime($time))->count()], ]; $townProductCount = StoreProduct::where('create_time','<=',strtotime($time))->count(); $product_count = StoreBranchProduct::where('create_time','<=',strtotime($time))->group('product_id')->order('total_sales desc')->limit(20)->field('image,product_id,store_name,sum(sales) as total_sales')->select(); $productRankingTotal = 0; foreach ($product_count as $item) { $productRankingTotal += $item['total_sales']; } return $this->success('ok', ['townProductCountList' => $data, 'productRankingList' => $product_count, 'townProductCount' => $townProductCount, 'productRankingTotal' => $productRankingTotal]); } public function user() { $time = $this->request->get('date', date('Y-m-d')); $store_id = $this->request->get('store_id', 0); $today = strtotime($time); $dates = []; $dates_two=[]; // 循环输出前5天的日期 for ($i = 0; $i <= 4; $i++) { // 计算前第$i天的日期时间戳 $timestamp = $today - ($i * 86400); // 86400秒等于1天 // 将时间戳格式化为日期 $date = date('Y-m-d', $timestamp); $dates_two[] = date('n.j', $timestamp); $dates[] = $date; } $where = []; if ($store_id) { $where['store_id'] = $store_id; } $res = UserLogic::userCount($where, $dates); if (UserLogic::hasError()) { return $this->fail(UserLogic::getError()); //获取错误信息并返回错误信息 } $res['date']=$dates_two; return $this->success('ok', $res); } /** * 中间商品统计 */ public function product_count() { $time = $this->request->get('date', date('Y-m-d')); $store_id = $this->request->get('store_id', 0); $where = []; if ($store_id) { $where['store_id'] = $store_id; } $res = ProductLogic::Count($where, $time); if (ProductLogic::hasError()) { return $this->fail(ProductLogic::getError()); //获取错误信息并返回错误信息 } return $this->success('ok', $res); } /** * 订单统计 */ public function order_user_num_count() { $time = $this->request->get('date', date('Y-m-d')); $store_id = $this->request->get('store_id', 0); $where = []; if ($store_id) { $where['store_id'] = $store_id; } $where['recharge_type'] = 'INDUSTRYMEMBERS'; $where['status'] = 1; $where['paid'] = 1; // $res = OrderLogic::Count($where,$time); // if (ProductLogic::hasError()) { // return $this->fail(ProductLogic::getError()); //获取错误信息并返回错误信息 // } $res = UserRecharge::where($where)->whereTime('create_time', $time)->select()->each(function ($item) { if ($item['uid']) { $item['nickname'] = User::where('id', $item['uid'])->value('nickname'); } else { $item['nickname'] = ''; } }); return $this->success('ok', $res?->toArray()); } /** * 商品销量排行榜统计 */ public function sales_ranking() { $time = $this->request->get('date'); $store_id = $this->request->get('store_id', 0); $where = []; if ($store_id) { $where['store_id'] = $store_id; } $res = OrderLogic::sales($where, $time); if (ProductLogic::hasError()) { return $this->fail(ProductLogic::getError()); //获取错误信息并返回错误信息 } return $this->success('ok', $res); } /** * 成交用户数据 */ public function user_trade_count() { $store_id = $this->request->get('store_id', 0); $date = $this->request->get('date', ''); if($date!=''){ $where = ['create_time' =>['start_time'=>$date,'end_time'=>$date.' 23:59:59']]; $where2 = ['create_time' =>['start_time'=>$date,'end_time'=>$date. ' 23:59:59']]; }else{ $where = ['create_time' => 'today']; $where2 = ['create_time' => 'yestoday']; } if ($store_id) { $where['store_id'] = $store_id; $where2['store_id'] = $store_id; } $logic = (new TradeStatisticLogic()); $leftToday = $logic->getTopLeftTrade($where); $leftyestoday = $logic->getTopLeftTrade($where2); $totalleft = [$leftToday, $leftyestoday]; foreach ($totalleft as $k => $v) { $left['name'] = "当日订单金额"; $left['x'] = $v['curve']['x']; $left['series'][$k]['money'] = round($v['total_money'], 2); $left['series'][$k]['value'] = array_values($v['curve']['y']); } return $this->data($left); } /** * 当日订单金额 */ public function street_currday_order_count() { $time = $this->request->get('date', date('Y-m-d')); $store_id = $this->request->get('store_id', 0); $where = []; if ($store_id) { $where['store_id'] = $store_id; } $res = OrderLogic::Currday($where, $time); if (ProductLogic::hasError()) { return $this->fail(ProductLogic::getError()); //获取错误信息并返回错误信息 } return $this->success('ok', $res); } public function store_order_day() { $time = $this->request->get('date', date('Y-m')); $arr = SystemStore::where('is_show', 1)->field('id,name street_name')->select() ->each(function($item) use($time){ $res = StoreOrder::where('paid', 1)->where('refund_status', 0)->where('store_id', $item['id'])->whereDay('create_time',$time)->field('count(id) count,sum(pay_price) price')->find(); $month = StoreOrder::where('paid', 1)->where('refund_status', 0)->where('store_id', $item['id'])->whereMonth('create_time',$time)->field('count(id) count,sum(pay_price) price')->find(); $item['dayOrderAmount']=$res['price']??0; $item['dayOrderCount']=$res['count']??0; $item['monthOrderAmount']=$month['price']??0; $item['monthOrderCount']=$month['count']??0; return $item; }); return $this->success('ok', $arr?->toArray()); } public function store_order_day_two() { $arr = SystemStore::where('is_show', 1)->field('id,name street_name')->select() ->each(function($item){ $today_order_amount = StoreOrder::where('paid', 1)->where('refund_status', 0)->where('store_id', $item['id'])->whereDay('create_time')->sum('pay_price'); $yesterday_order_amount = StoreOrder::where('paid', 1)->where('refund_status', 0)->where('store_id', $item['id'])->whereMonth('create_time','yesterday')->sum('pay_price'); $item['today_order_amount']=$today_order_amount; $item['yesterday_order_amount']=$yesterday_order_amount; return $item; }); return $this->success('ok', $arr?->toArray()); } /** * 格式化时间 * @param $time * @return string */ public function getDay($time) { if (strstr($time, '-') !== false) { [$startTime, $endTime] = explode('-', $time); if (!$startTime && !$endTime) { return date("Y/m/d", strtotime("-30 days", time())) . '-' . date("Y/m/d", time()); } else { if($startTime==$endTime){ return $startTime . '-' . $endTime.' 23:59:59'; }else{ return $startTime . '-' . $endTime; } } } else { return date("Y/m/d", strtotime("-30 days", time())) . '-' . date("Y/m/d", time()); } } }