diff --git a/app/api/logic/order/OrderLogic.php b/app/api/logic/order/OrderLogic.php index 9db31ea1..2e98524d 100644 --- a/app/api/logic/order/OrderLogic.php +++ b/app/api/logic/order/OrderLogic.php @@ -57,7 +57,7 @@ class OrderLogic extends BaseLogic public static $activity_price; public static $deduction_price; public static $frozen_money; //返还金额 - + public static $fresh_price; //生鲜金额 /** * @notes 获取购物车商品信息 * @param $params @@ -81,7 +81,7 @@ class OrderLogic extends BaseLogic self::$deduction_price = 0; self::$frozen_money = 0; //返还金额 $deduction_price = 0; //抵扣金额 - $fresh_price = 0; //生鲜金额 + self::$fresh_price = 0; //生鲜金额 /** 计算价格 */ $off_activity = Config::where('name', 'off_activity')->value('value'); $field = 'id branch_product_id,store_name,image,unit,price,vip_price,cost,purchase,product_id,top_cate_id'; @@ -108,7 +108,7 @@ class OrderLogic extends BaseLogic } unset($cart_select[$k]['id']); $cart_select[$k]['total_price'] = bcmul($v['cart_num'], $find['price'], 2); //订单总价 - if ($off_activity == 1 || ($user!=null &&in_array($user['user_ship'], [4, 5, 6, 7]))) { + if ($off_activity == 1 || ($user != null && in_array($user['user_ship'], [4, 5, 6, 7]))) { $price = $find['cost']; } else { $price = $find['price']; @@ -128,10 +128,6 @@ class OrderLogic extends BaseLogic $deduction_price = bcsub($cart_select[$k]['total_price'], $cart_select[$k]['pay_price'], 2); $cart_select[$k]['deduction_price'] = $deduction_price; //抵扣金额 } - //计算生鲜 - if ($createOrder == 1 && $find['top_cate_id'] == 15201) { - $fresh_price = bcadd($fresh_price, $cart_select[$k]['pay_price']); - } $cart_select[$k]['product_id'] = $find['product_id']; $cart_select[$k]['old_cart_id'] = $v['id']; $cart_select[$k]['cart_num'] = $v['cart_num']; @@ -164,6 +160,10 @@ class OrderLogic extends BaseLogic self::$store_price = bcadd(self::$store_price, $cart_select[$k]['store_price'], 2); //商户价 self::$deduction_price = bcadd(self::$deduction_price, $deduction_price, 2); //抵扣金额 self::$frozen_money = bcadd(self::$frozen_money, $cart_select[$k]['vip_frozen_price'], 2); //返还金额 + //计算生鲜 + if ($createOrder == 1 && $find['top_cate_id'] == 15201) { + self::$fresh_price = bcadd(self::$fresh_price, $cart_select[$k]['pay_price'], 2); + } // self::$profit = bcadd(self::$profit, $cart_select[$k]['profit'], 2); } //加支付方式限制 @@ -175,8 +175,8 @@ class OrderLogic extends BaseLogic $pay_price = bcsub(self::$pay_price, self::$activity_price, 2); //减去活动优惠金额 //判断生鲜是否大于200 - if ($createOrder == 1 && $fresh_price > 0) { - if ($pay_price < 200) { + if ($createOrder == 1 && self::$fresh_price > 0) { + if (self::$pay_price < 200) { self::setError('订单包含生鲜产品,订单金额必须大于200元,才能下单'); return false; } diff --git a/app/statistics/controller/IndexController.php b/app/statistics/controller/IndexController.php index 400d7243..c6884770 100644 --- a/app/statistics/controller/IndexController.php +++ b/app/statistics/controller/IndexController.php @@ -4,6 +4,9 @@ namespace app\statistics\controller; use app\admin\logic\statistic\TradeStatisticLogic; use app\common\controller\BaseLikeController; +use app\common\model\store_branch_product\StoreBranchProduct; +use app\common\model\store_order_cart_info\StoreOrderCartInfo; +use app\common\model\store_product\StoreProduct; use app\common\model\user\User; use app\common\model\user_recharge\UserRecharge; use app\statistics\logic\OrderLogic; @@ -14,12 +17,12 @@ use DateTime; class IndexController extends BaseLikeController { - public $store_id = 0; + // public $store_id = 0; public function index() { $time = $this->request->get('date', date('Y-m-d')); - $store_id = $this->store_id; + $store_id = $this->request->get('store_id', 0); if ($store_id) { $where['store_id'] = $store_id; } @@ -28,11 +31,72 @@ class IndexController extends BaseLikeController if (OrderLogic::hasError()) { return $this->fail(OrderLogic::getError()); //获取错误信息并返回错误信息 } - return $this->success('ok', ['dayPayPrice' => $res, 'title' => '百合镇农(特)产品交易大数据']); + 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(){ + $data=[ + ['street_name'=>'喻寺镇','product_count'=>1], + ['street_name'=>'立石镇','product_count'=>1], + ['street_name'=>'百和镇','product_count'=>1], + ['street_name'=>'得胜镇','product_count'=>1], + ['street_name'=>'玄滩镇','product_count'=>1], + ['street_name'=>'云锦镇','product_count'=>1], + ]; + $townProductCount=StoreProduct::count(); + $product_count=StoreBranchProduct::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 = []; // 循环输出前5天的日期 @@ -44,7 +108,6 @@ class IndexController extends BaseLikeController $date = date('Y-m-d', $timestamp); $dates[] = $date; } - $store_id = $this->store_id; $where = []; if ($store_id) { $where['store_id'] = $store_id; @@ -62,7 +125,7 @@ class IndexController extends BaseLikeController public function product_count() { $time = $this->request->get('date', date('Y-m-d')); - $store_id = $this->store_id; + $store_id = $this->request->get('store_id', 0); $where = []; if ($store_id) { $where['store_id'] = $store_id; @@ -79,23 +142,23 @@ class IndexController extends BaseLikeController public function order_user_num_count() { $time = $this->request->get('date', date('Y-m-d')); - $store_id = $this->store_id; + $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; + $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']=''; + if ($item['uid']) { + $item['nickname'] = User::where('id', $item['uid'])->value('nickname'); + } else { + $item['nickname'] = ''; } }); return $this->success('ok', $res?->toArray()); @@ -106,7 +169,7 @@ class IndexController extends BaseLikeController public function sales_ranking() { $time = $this->request->get('date'); - $store_id = $this->store_id; + $store_id = $this->request->get('store_id', 0); $where = []; if ($store_id) { $where['store_id'] = $store_id; @@ -122,9 +185,16 @@ class IndexController extends BaseLikeController */ public function user_trade_count() { + $store_id = $this->request->get('store_id', 0); + $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(['create_time' => 'today']); - $leftyestoday = $logic->getTopLeftTrade(['create_time' => 'yestoday']); + $leftToday = $logic->getTopLeftTrade($where); + $leftyestoday = $logic->getTopLeftTrade($where2); $totalleft = [$leftToday, $leftyestoday]; foreach ($totalleft as $k => $v) { $left['name'] = "当日订单金额"; @@ -141,7 +211,7 @@ class IndexController extends BaseLikeController public function street_currday_order_count() { $time = $this->request->get('date', date('Y-m-d')); - $store_id = $this->store_id; + $store_id = $this->request->get('store_id', 0); $where = []; if ($store_id) { $where['store_id'] = $store_id;