Kaynağa Gözat

盘点订单详情, 经营概况

林琦海 5 yıl önce
ebeveyn
işleme
4044da8773

+ 81 - 29
app-ghs/controllers/MainController.php

@@ -2,6 +2,10 @@
 
 namespace ghs\controllers;
 
+use biz\shop\classes\ShopClass;
+use bizGhs\product\classes\ProductClass;
+use bizHd\stat\classes\StatIncomeClass;
+use bizHd\stat\classes\StatOrderClass;
 use common\components\imgUtil;
 use common\components\util;
 use Yii;
@@ -59,50 +63,98 @@ class MainController extends BaseController
     //经营概况 ssh 2021.1.27
     public function actionProfile()
     {
+
+        //余额
+        $shopInfo = ShopClass::getById($this->shopId);
+        //库存情况
+        $stockInfo = ProductClass::getProductStockByShopId($this->sjId,$this->shopId);
+        //今日销售金额
+        $today = StatIncomeClass::getAmountToday($this->shopId);
+        //近七天销售金额
+        $latestSeven = StatIncomeClass::getAmountWeek($this->shopId);
+        //30天销售金额
+        $latestThirty = StatIncomeClass::getAmountThirty($this->shopId);
         $base = [
-            'balance' => 5020.00,
-            'mayGathering' => 10,
-            'mayPay' => 20,
-            'stockCost' => 2000,
-            'stockNum' => 100,
-            'stockWarning' => 5,
-            'today' => 90,
-            'todayCompareYesterday' => -5,
-            'latestSeven' => 9000,
-            'latestSevenSameTerm' => 10,
-            'latestThirty' => 8000,
-            'latestThirtySameTerm' => -9,
+            'balance' => $shopInfo['balance'],
+            'mayGathering' => $shopInfo['mayGathering'],
+            'mayPay' => 0,
+            'stockCost' => $stockInfo['stockCost'],
+            'stockNum' => 0,
+            'stockBigNum' => $stockInfo['stockBigNum'],
+            'stockSmallNum' => $stockInfo['stockSmallNum'],
+            'stockWarning' => $stockInfo['stockWarning'],
+            'today' => $today,
+            'todayCompareYesterday' => 0,
+            'latestSeven' => $latestSeven,
+            'latestSevenSameTerm' => 0,
+            'latestThirty' => $latestThirty,
+            'latestThirtySameTerm' => 0,
         ];
+
+        //今日订单数
+        $saleNum = StatOrderClass::getRiseNumToday($this->shopId);
+        //今日销售金额
+        $saleAmount =$today;
+
+        //昨日订单数
+        $ySaleNum = StatOrderClass::getRiseNumYesterday($this->shopId);
+        //昨日销售金额
+        $ySaleAmount = StatIncomeClass::getAmountYesterday($this->shopId);
+
+        //7天订单数
+        $sevenSaleNum = StatOrderClass::getRiseNumWeek($this->shopId);
+
+        //7天销售金额
+        $sevenSaleAmount = $latestSeven;
+        //30天订单数
+        $thirtySaleNum =  StatOrderClass::getRiseNumThirty($this->shopId);
+        //30天销售金额
+        $thirtySaleAmount = $latestThirty;
+
+
+        //采购相关信息
+        //今日采购数
+        //今日采购金额
+
+        //昨日采购数
+        //昨日采购金额
+
+        //7日采购数
+        //7日采购金额
+
+        //30日采购数
+        //30日采购金额
+
         $more = [
             'today' => [
-                'income' => 10,
-                'expend' => 2,
-                'saleNum' => 1,
-                'saleAmount' => 100,
+                'income' => 0,
+                'expend' => 0,
+                'saleNum' => $saleNum,
+                'saleAmount' => $saleAmount,
                 'purchaseNum' => 2,
                 'purchaseAmount' => 3,
             ],
             'yesterday' => [
-                'income' => 10,
-                'expend' => 2,
-                'saleNum' => 1,
-                'saleAmount' => 100,
+                'income' => 0,
+                'expend' => 0,
+                'saleNum' => $ySaleNum,
+                'saleAmount' => $ySaleAmount,
                 'purchaseNum' => 2,
                 'purchaseAmount' => 3,
             ],
             'latestSeven' => [
-                'income' => 10,
-                'expend' => 2,
-                'saleNum' => 1,
-                'saleAmount' => 100,
+                'income' => 0,
+                'expend' => 0,
+                'saleNum' => $sevenSaleNum,
+                'saleAmount' => $sevenSaleAmount,
                 'purchaseNum' => 2,
                 'purchaseAmount' => 3,
             ],
             'latestThirty' => [
-                'income' => 10,
-                'expend' => 2,
-                'saleNum' => 1,
-                'saleAmount' => 100,
+                'income' => 0,
+                'expend' => 0,
+                'saleNum' => $thirtySaleNum,
+                'saleAmount' => $thirtySaleAmount,
                 'purchaseNum' => 2,
                 'purchaseAmount' => 3,
             ],
@@ -142,4 +194,4 @@ class MainController extends BaseController
         util::success($data);
     }
 
-}
+}

+ 2 - 0
biz-ghs/order/classes/CheckOrderClass.php

@@ -121,7 +121,9 @@ class CheckOrderClass extends BaseClass
                 if(!isset($tmp['rank'])){
                     $tmp['rank']= 'B';
                 }
+
                 $tmp = array_merge($tmp,$v);
+                $tmp['id'] = $v['productId'];
                 $itemData[] = $tmp;
             }
         }

+ 6 - 0
biz-ghs/order/classes/PurchaseOrderClass.php

@@ -295,4 +295,10 @@ class PurchaseOrderClass extends BaseClass
     }
 
 
+    //采购数,采购金额统计(根据时间,今日,昨天,7天,30天)
+    public static function statOrderInfo($shopId,$start,$end)
+    {
+
+    }
+
 }

+ 27 - 1
biz-ghs/product/classes/ProductClass.php

@@ -623,8 +623,34 @@ class ProductClass extends BaseClass
     {
         $where = [
             'merchantId'=>$sjId,
-            'shopId'=>$shopId
+            'shopId'=>$shopId,
         ];
         return self::getAllByCondition($where,null,$field);
     }
+
+    //获取当前门店下所有花材的库存数量,及成本价,库存预警的花材数量  linqh 2021-04-20
+    public static function getProductStockByShopId($sjId,$shopId)
+    {
+        $productInfo = self::getAllProduct($sjId,$shopId,"*");
+        $data = [
+            'stockBigNum'=>0,
+            'stockSmallNum'=>0,
+            'stockCost'=>0,
+            'stockWarning'=>0,
+        ];
+        if($productInfo){
+            foreach ($productInfo as $v){
+                $stock = self::formatStock($v['stock'],$v['ratio']);
+                $data['stockBigNum'] = bcadd($data['stockBigNum'],$stock['bigNum']);
+                $data['stockSmallNum'] = bcadd($data['stockSmallNum'],$stock['smallNum']);
+                $data['stockCost'] = bcadd($data['stockCost'],bcmul($v['stock'],$v['cost'],2),2);
+                if($v['stock'] <= $v['stockWarning']) {
+                    $data['stockWarning'] ++;
+                }
+            }
+        }
+        return $data;
+    }
+
+
 }

+ 62 - 0
biz-hd/stat/classes/StatIncomeClass.php

@@ -3,6 +3,8 @@
 namespace bizHd\stat\classes;
 
 use bizHd\stat\models\StatIncome;
+use common\components\dateUtil;
+use common\components\noticeUtil;
 use Yii;
 use bizHd\base\classes\BaseClass;
 
@@ -42,4 +44,64 @@ class StatIncomeClass extends BaseClass
         StatIncomeMonthClass::updateOrInsert($shop, $amount);
     }
 
+    //查询当天收入金额
+    public static function getAmountToday($shopId)
+    {
+        $time = date('Ymd');
+        $res = self::getDetail($shopId,$time);
+        return $res['amount']??0;
+    }
+
+    //yesterday
+    public static function getAmountYesterday($shopId)
+    {
+        $time = date('Ymd',strtotime("-1 days"));
+        $res = self::getDetail($shopId,$time);
+        return $res['amount']??0;
+    }
+
+
+    //近七天收入金额
+    public static function getAmountWeek($shopId)
+    {
+        $end = date('Ymd');
+        $start = date('Ymd',strtotime("-7 days"));
+        return self::getAmountByTime($shopId,$start,$end);
+    }
+
+    //30天输入金额
+    public static function getAmountThirty($shopId)
+    {
+
+        $end = date('Ymd');
+        $start = date('Ymd',strtotime("-30 days"));
+        return self::getAmountByTime($shopId,$start,$end);
+    }
+
+
+    //查询某一天的信息
+    public static function getDetail($shopId,$time)
+    {
+        $where = [
+            'shopId' => $shopId,
+            'time' => $time,
+        ];
+        $model = self::getByCondition($where);
+        return $model;
+    }
+
+    public static function getAmountByTime($shopId,$start,$end)
+    {
+        $where = [];
+        $where['shopId'] = $shopId;
+        $where['time'] = ['between', [$start, $end]];
+        $res = self::getAllByCondition($where,null,"amount");
+        $amount = 0;
+        if($res){
+            foreach ($res as $v){
+                $amount = bcadd($amount,$v['amount'],2);
+            }
+        }
+        return $amount;
+    }
 }

+ 19 - 0
biz-hd/stat/classes/StatIncomeMonthClass.php

@@ -38,4 +38,23 @@ class StatIncomeMonthClass extends BaseClass
         $stat->save();
     }
 
+    //查询当天收入金额
+    public static function getAmountMonth($shopId)
+    {
+        $time = date('Ym');
+        $res = self::getDetail($shopId,$time);
+        return $res['amount']??0;
+    }
+
+    //查询某一个月的信息
+    public static function getDetail($shopId,$time)
+    {
+        $where = [
+            'shopId' => $shopId,
+            'time' => $time,
+        ];
+        $model = self::getByCondition($where);
+        return $model;
+    }
+
 }

+ 55 - 0
biz-hd/stat/classes/StatOrderClass.php

@@ -49,5 +49,60 @@ class StatOrderClass extends BaseClass
         StatOrderMonthClass::updateOrInsert($shop);
     }
 
+    public static function getRiseNumToday($shopId)
+    {
+        $time = date('Ymd');
+        $res = self::getDetail($shopId,$time);
+        return $res['riseNum']??0;
+    }
+
+    //yesterday
+    public static function getRiseNumYesterday($shopId)
+    {
+        $time = date('Ymd',strtotime("-1 days"));
+        $res = self::getDetail($shopId,$time);
+        return $res['riseNum']??0;
+    }
 
+    public static function getDetail($shopId,$time)
+    {
+        $where = [
+            'shopId' => $shopId,
+            'time' => $time,
+        ];
+        $model = self::getByCondition($where);
+        return $model;
+    }
+
+    //近7天
+    public static function getRiseNumWeek($shopId)
+    {
+        $end = date('Ymd');
+        $start = date('Ymd',strtotime("-7 days"));
+        return self::getRiseNumByTime($shopId,$start,$end);
+    }
+
+    //近30天
+    public static function getRiseNumThirty($shopId)
+    {
+        $end = date('Ymd');
+        $start = date('Ymd',strtotime("-30 days"));
+        return self::getRiseNumByTime($shopId,$start,$end);
+    }
+
+
+    public static function getRiseNumByTime($shopId,$start,$end)
+    {
+        $where = [];
+        $where['shopId'] = $shopId;
+        $where['time'] = ['between', [$start, $end]];
+        $res = self::getAllByCondition($where, null, "riseNum");
+        $riseNum = 0;
+        if ($res) {
+            foreach ($res as $v) {
+                $riseNum = bcadd($riseNum, $v['riseNum'], 2);
+            }
+        }
+        return $riseNum;
+    }
 }

+ 10 - 1
sql.sql

@@ -2159,4 +2159,13 @@ ALTER TABLE `xhStatView` ADD shopId INT NOT NULL DEFAULT 0 COMMENT '' AFTER `mer
 ALTER TABLE `xhStatViewMonth` ADD shopId INT NOT NULL DEFAULT 0 COMMENT '' AFTER `merchantId`;
 ALTER TABLE `xhStatVisit` ADD shopId INT NOT NULL DEFAULT 0 COMMENT '' AFTER `merchantId`;
 ALTER TABLE `xhStatVisitMonth` ADD shopId INT NOT NULL DEFAULT 0 COMMENT '' AFTER `merchantId`;
-ALTER TABLE xhShop ADD totalItem INT NOT NULL DEFAULT 0 COMMENT '总花材数' AFTER `totalExpend`;
+ALTER TABLE xhShop ADD totalItem INT NOT NULL DEFAULT 0 COMMENT '总花材数' AFTER `totalExpend`;
+
+============linqh  2021-4-20
+===
+ALTER TABLE `xhShop`
+ADD COLUMN `mayGathering`  decimal(9,2) NOT NULL DEFAULT 0 COMMENT '应收款' AFTER `totalPurchase`;
+
+ALTER TABLE `xhGhsPurchaseOrder`
+ADD INDEX `idx_shopId` (`shopId`) ,
+ADD INDEX `idx_addTime` (`addTime`) ;