Bladeren bron

中央化开始

shish 4 jaren geleden
bovenliggende
commit
663abf9c7b

+ 3 - 2
app-ghs/controllers/BaseController.php

@@ -17,7 +17,7 @@ use common\components\util;
 class BaseController extends PublicController
 {
     public $admin, $adminId, $adminAvatar, $account;
-    public $sjId = 0, $sj = [], $sjExtend = [], $signPackage, $shop = [], $shopExt = [], $shopId = 0, $lookShopId = 0, $shopAdminId = 0, $shopAdmin = [];
+    public $sjId = 0, $sj = [], $sjExtend = [], $signPackage, $shop = [], $shopExt = [], $shopId = 0, $mainId = 0, $lookShopId = 0, $shopAdminId = 0, $shopAdmin = [];
     public $appId;
     public $isWx = false;
     public $isLogin = false;
@@ -58,10 +58,11 @@ class BaseController extends PublicController
         } else {
             $this->shopId = $currentShopId;
             $shop = ShopClass::getById($currentShopId, true);
-            $this->shop = $shop;
             if (empty($shop)) {
                 util::fail('没有找到您的门店');
             }
+            $this->shop = $shop;
+            $this->mainId = $shop->mainId ?? 0;
             $shopExt = ShopExtClass::getByCondition(['shopId' => $currentShopId], true);
             if (empty($shopExt)) {
                 util::fail('门店信息有问题,请联系管理员');

+ 5 - 18
app-ghs/controllers/ConsoleController.php

@@ -34,38 +34,25 @@ class ConsoleController extends BaseController
         }
 
         //今天客户与粉丝数
-        $userData = StatUserService::getTodayNum($this->shopId);
+        $userData = StatUserService::getTodayNum($this->mainId);
         $customNum = isset($userData['riseUserNum']) ? $userData['riseUserNum'] : 0;
 
         //今天销售
-        $sale = StatSaleClass::getByCondition(['shopId' => $this->shopId, 'time' => date('Ymd')]);
+        $sale = StatSaleClass::getByCondition(['mainId' => $this->mainId, 'time' => date('Ymd')]);
         $todaySale = $sale['amount'] ?? 0;
         $orderNum = $sale['num'] ?? 0;
 
         //2021.4.14 linqh 今日支出
-        $outData = StatOutService::getTodayNum($this->shopId);
+        $outData = StatOutService::getTodayNum($this->mainId);
         $todayOut = $outData['amount'] ?? '0.00';
 
         //访客数
-        $visitCustom = StatVisitClass::getVisitNum($this->shop);
+        $visitCustom = StatVisitClass::getVisitNum($this->mainId);
 
         $todayData = ['income' => $todaySale, 'order' => $orderNum, 'custom' => $customNum, 'expend' => $todayOut, 'visitCustom' => $visitCustom];
 
         $incomeStat = [];
-        if (httpUtil::isMiniProgram() == false) {
-            //当月的收入
-            $currentMonthIncome = StatIncomeMonthService::getCurrentMonthIncome($this->shopId);
-            //上个月收入
-            $previousMonthIncome = StatIncomeMonthService::getPreviousMonthIncome($this->shopId);
-            //最近7天收入变化趋势
-            $latestIncome = StatIncomeService::getLatestSevenDay($this->shopId);
-            $incomeStat = [
-                'month' => $currentMonthIncome,
-                'week' => 999,
-                'previousMonth' => $previousMonthIncome,
-                'list' => $latestIncome,
-            ];
-        }
+
         $shopInfo = isset($this->shop) && !empty($this->shop) ? $this->shop->attributes : [];
 
         $menu = [

+ 3 - 2
app-hd/controllers/BaseController.php

@@ -18,7 +18,7 @@ class BaseController extends PublicController
 {
 
     public $admin, $adminId, $adminAvatar, $account, $customId = 0, $custom;
-    public $sjId = 0, $sj = [], $sjExtend = [], $signPackage, $shopId = 0, $shop = [], $shopAdminId = 0, $shopAdmin = [];
+    public $sjId = 0, $sj = [], $sjExtend = [], $signPackage, $shopId = 0, $mainId = 0, $shop = [], $shopAdminId = 0, $shopAdmin = [];
     public $appId;
     public $isWx = false;
     public $isLogin = false;
@@ -60,10 +60,11 @@ class BaseController extends PublicController
         } else {
             $this->shopId = $currentShopId;
             $shop = ShopService::getById($currentShopId, true);
-            $this->shop = $shop;
             if (empty($shop)) {
                 util::fail('没有找到店铺');
             }
+            $this->shop = $shop;
+            $this->mainId = $shop->mainId ?? 0;
             $shopAdmin = ShopAdminClass::getByCondition(['shopId' => $currentShopId, 'adminId' => $adminId], true);
             if (empty($shopAdmin)) {
                 util::logout('没有找到员工信息');

+ 2 - 3
biz-hd/stat/classes/StatVisitClass.php

@@ -99,11 +99,10 @@ class StatVisitClass extends BaseClass
     }
 
     //获取访客数 ssh 2020.2.2
-    public static function getVisitNum($shop, $date = null)
+    public static function getVisitNum($mainId, $date = null)
     {
-        $shopId = $shop->id ?? 0;
         $date = isset($date) == false ? date("Ymd") : $date;
-        $cacheKey = 'ghs_mall_visit_' . $shopId . '_' . $date;
+        $cacheKey = 'ghs_mall_visit_' . $mainId . '_' . $date;
         $num = Yii::$app->redis->executeCommand('SCARD', [$cacheKey]);
         return !empty($num) ? $num : 0;
     }

+ 2 - 2
biz-hd/stat/services/StatUserService.php

@@ -11,10 +11,10 @@ class StatUserService extends BaseService
 
 	public static $baseFile = '\bizHd\stat\classes\StatUserClass';
 
-	public static function getTodayNum($shopId)
+	public static function getTodayNum($id)
 	{
 		$today = date("Ymd");
-		return StatUserClass::getByCondition(['shopId' => $shopId, 'time' => $today]);
+		return StatUserClass::getByCondition(['mainId' => $id, 'time' => $today]);
 	}
 
 }

+ 14 - 0
biz/shop/classes/MainIdClass.php

@@ -0,0 +1,14 @@
+<?php
+
+namespace biz\shop\classes;
+
+use common\components\util;
+use Yii;
+use biz\base\classes\BaseClass;
+
+class MainIdClass extends BaseClass
+{
+
+    public static $baseFile = '\biz\shop\models\MainId';
+
+}

+ 13 - 0
biz/shop/models/MainId.php

@@ -0,0 +1,13 @@
+<?php
+namespace biz\shop\models;
+use biz\base\models\Base;
+
+class MainId extends Base
+{
+
+	public static function tableName()
+	{
+		return 'xhMainId';
+	}
+
+}

+ 2 - 2
biz/stat/services/StatOutService.php

@@ -14,9 +14,9 @@ class StatOutService extends BaseService
     public static $baseFile = '\biz\stat\classes\StatOutClass';
 
     //取今天的数据 linqh 2021.4.14
-    public static function getTodayNum($shopId)
+    public static function getTodayNum($id)
     {
         $today = date("Ymd");
-        return StatOutClass::getByCondition([ 'time' => $today,'shopId'=>$shopId]);
+        return StatOutClass::getByCondition(['time' => $today, 'mainId' => $id]);
     }
 }

+ 62 - 74
console/controllers/InitController.php

@@ -2,93 +2,81 @@
 
 namespace console\controllers;
 
-use bizHd\user\services\UserService;
-use bizHd\wx\services\WxOpenService;
-use common\services\xhMerchantAssetService;
-use common\services\xhWxMenuService;
+use biz\pt\classes\PtYeChangeClass;
+use biz\recharge\classes\RechargeClass;
+use biz\shop\classes\MainIdClass;
+use biz\shop\classes\ShopAdminClass;
+use biz\shop\classes\ShopCapitalClass;
+use biz\shop\classes\ShopClass;
+use biz\shop\classes\ShopYeChangeClass;
+use biz\sj\classes\CashClass;
+use biz\stat\classes\StatOutClass;
+use biz\stat\classes\StatOutMonthClass;
+use biz\stat\classes\StatSaleClass;
+use biz\stat\classes\StatSaleMonthClass;
+use bizGhs\stat\classes\StatYjClass;
+use bizGhs\stat\classes\StatYjMonthClass;
+use bizHd\stat\classes\StatUserClass;
+use bizHd\stat\classes\StatUserMonthClass;
+use bizHd\stat\classes\StatVisitClass;
+use bizHd\stat\classes\StatVisitMonthClass;
 use Yii;
 use yii\console\Controller;
-use common\services\xhTMessageService;
-use common\services\xhMerchantService;
 
-/**
- * 脚本
- */
 class InitController extends Controller
 {
 
-    //微信菜单初始化 shish 20210526
-    // yii init/menu-init
-    public function actionMenuInit()
+    //执行供货商资产中央化 ./yii init/ghs-center
+    // shish 20220313
+    public function actionGhsCenter()
     {
-        xhWxMenuService::menuInit();
-    }
-
-    //接入一个商家需要的操作 ssh 2019.9.7
-    //  yii init/join-one 12358 更新某个商家公众号
-    //  yii init/join-one 更新平台公众号
-    public function actionJoinOne($id = 0)
-    {
-        //初始化微信菜单
-        if ($id == 0) {
-            $isOpen = 1;
-            $merchant = WxOpenService::getWxInfo();
-            $merchant['id'] = 0;
-        } else {
-            $isOpen = 0;
-            $merchant = xhMerchantService::getById($id);
+        $shopList = ShopClass::getAllByCondition(['ptStyle' => 2], null, '*', null, true);
+        if (empty($shopList)) {
+            return false;
         }
-        //xhWxMenuService::applyInit($merchant);
-        //模板消息
-        $r = xhTMessageService::supplement($merchant, $isOpen);
-        print_r($r);
-    }
+        foreach ($shopList as $shop) {
+            $mainId = $shop->mainId ?? 0;
+            if (empty($mainId)) {
+                $main = MainIdClass::add(['id' => null], true);
+                $mainId = $main->id ?? 0;
+                if (empty($mainId)) {
+                    echo "mainId没有生成 \n";
+                    exit();
+                }
+                $shop->mainId = $mainId;
+                $shop->save();
+            }
 
+            $shopId = $shop->id ?? 0;
 
-    //yii init/sub
-    public function actionSub()
-    {
-        $name = 'redis_shi';
-        $redisPubSub = \Yii::$app->redisPubSub;
-        $redisPubSub->setOptReadTimeout(-1);
-        $redisPubSub->subscribe($name, function ($instance, $channelName, $message) {
-            $a = 123;
-        });
-    }
+            StatSaleClass::updateByCondition(['shopId' => $shopId], ['mainId' => $mainId]);
+            StatSaleMonthClass::updateByCondition(['shopId' => $shopId], ['mainId' => $mainId]);
 
-    public function actionPub()
-    {
-        $name = 'redis_shi';
-        $time = 'nihao1123';
-        $redisPubSub = \Yii::$app->redisPubSub;
-        $redisPubSub->publish($name, $time);
-    }
+            StatUserClass::updateByCondition(['shopId' => $shopId], ['mainId' => $mainId]);
+            StatUserMonthClass::updateByCondition(['shopId' => $shopId], ['mainId' => $mainId]);
 
-    public function actionPullUser()
-    {
-        //拉取用户
-        $this->actionPullUser();
-    }
+            StatVisitClass::updateByCondition(['shopId' => $shopId], ['mainId' => $mainId]);
+            StatVisitMonthClass::updateByCondition(['shopId' => $shopId], ['mainId' => $mainId]);
 
-    // 拉取微信用户 ssh 2019.9.9
-    public function actionPullUser2()
-    {
-        $sjId = 12359;
-        $return = UserService::syncWxAllUser($sjId);
-        $total = isset($return['data']['total']) ? $return['data']['total'] : 0;
-        xhMerchantAssetService::updateBySjId($sjId, ['totalFans' => $total]);
-    }
+            StatOutClass::updateByCondition(['shopId' => $shopId], ['mainId' => $mainId]);
+            StatOutMonthClass::updateByCondition(['shopId' => $shopId], ['mainId' => $mainId]);
 
-    //更新用户名称
-    public function actionUpdateName()
-    {
-        $sjId = 12362;
-        UserService::syncWxAllUser($sjId);
-    }
+            PtYeChangeClass::updateByCondition(['shopId' => $shopId], ['mainId' => $mainId]);
+            ShopYeChangeClass::updateByCondition(['shopId' => $shopId], ['mainId' => $mainId]);
+
+            CashClass::updateByCondition(['shopId' => $shopId], ['mainId' => $mainId]);
+
+            ShopCapitalClass::updateByCondition(['shopId' => $shopId], ['mainId' => $mainId]);
+
+            RechargeClass::updateByCondition(['shopId' => $shopId], ['mainId' => $mainId]);
+
+            StatYjClass::updateByCondition(['shopId' => $shopId], ['mainId' => $mainId]);
+            StatYjMonthClass::updateByCondition(['shopId' => $shopId], ['mainId' => $mainId]);
+
+            ShopAdminClass::updateByCondition(['shopId' => $shopId], ['mainId' => $mainId]);
+
+        }
 
-    //消息模板初始化 linqh ./yii init/t-message
-    public function actionTMessage()
-    {
-        xhTMessageService::initTMessage();
     }
-}
+
+}

+ 23 - 1
sql.txt

@@ -4,4 +4,26 @@ CREATE TABLE `xhMainId` (
   PRIMARY KEY (`id`)
 ) COMMENT='中央id库';
 
-=== shish 20220311
+=== shish 20220311
+
+ALTER TABLE xhStatSale ADD mainId INT NOT NULL DEFAULT 0 COMMENT '中央id' AFTER `shopId`;
+ALTER TABLE xhStatSaleMonth ADD mainId INT NOT NULL DEFAULT 0 COMMENT '中央id' AFTER `shopId`;
+ALTER TABLE xhStatUser ADD mainId INT NOT NULL DEFAULT 0 COMMENT '中央id' AFTER `shopId`;
+ALTER TABLE xhStatUserMonth ADD mainId INT NOT NULL DEFAULT 0 COMMENT '中央id' AFTER `shopId`;
+ALTER TABLE xhStatOut ADD mainId INT NOT NULL DEFAULT 0 COMMENT '中央id' AFTER `shopId`;
+ALTER TABLE xhStatOutMonth ADD mainId INT NOT NULL DEFAULT 0 COMMENT '中央id' AFTER `shopId`;
+ALTER TABLE xhPtYeChange ADD mainId INT NOT NULL DEFAULT 0 COMMENT '中央id' AFTER `shopId`;
+ALTER TABLE xhShopYeChange ADD mainId INT NOT NULL DEFAULT 0 COMMENT '中央id' AFTER `shopId`;
+ALTER TABLE xhShopCapital ADD mainId INT NOT NULL DEFAULT 0 COMMENT '中央id' AFTER `shopId`;
+ALTER TABLE xhCash ADD mainId INT NOT NULL DEFAULT 0 COMMENT '中央id' AFTER `shopId`;
+ALTER TABLE xhRecharge ADD mainId INT NOT NULL DEFAULT 0 COMMENT '中央id' AFTER `shopId`;
+ALTER TABLE xhStaff ADD mainId INT NOT NULL DEFAULT 0 COMMENT '中央id' AFTER `shopId`;
+ALTER TABLE xhGhsStatYj ADD mainId INT NOT NULL DEFAULT 0 COMMENT '中央id' AFTER `shopId`;
+ALTER TABLE xhGhsStatYjMonth ADD mainId INT NOT NULL DEFAULT 0 COMMENT '中央id' AFTER `shopId`;
+ALTER TABLE xhStatVisit ADD mainId INT NOT NULL DEFAULT 0 COMMENT '中央id' AFTER `shopId`;
+ALTER TABLE xhStatVisitMonth ADD mainId INT NOT NULL DEFAULT 0 COMMENT '中央id' AFTER `shopId`;
+
+=== 资产相关表中央化 shish 20220313
+
+
+执行供货商资产中央化 ./yii init/ghs-center 【库存也要中央化处理,要加入时来】