Browse Source

演示入口

shish 5 years ago
parent
commit
9e15393679

+ 32 - 25
app-ghs/controllers/AuthController.php

@@ -8,6 +8,7 @@ use bizGhs\shop\services\ShopAdminService;
 use bizGhs\admin\services\AdminService;
 use bizHd\user\classes\UserClass;
 use bizHd\wx\classes\WxOpenClass;
+use common\components\dict;
 use common\components\httpUtil;
 use common\components\imgUtil;
 use common\components\jwt;
@@ -176,33 +177,37 @@ class AuthController extends PublicController
     {
         //供货商平台
         Yii::$app->params['ptStyle'] = 2;
-
         $code = Yii::$app->request->get('code', '');
         if (empty($code)) {
-            util::fail('没有CODE信息');
-        }
-        $wxMiniBase = WxOpenClass::getGhsWxInfo();
-        $appId = $wxMiniBase['miniAppId'];
-        $appSecret = $wxMiniBase['miniAppSecret'];
-        if (empty($appSecret)) {
-            util::fail('没有找到小程序的密钥');
-        }
-        $url = "https://api.weixin.qq.com/sns/jscode2session?appid={$appId}&secret={$appSecret}&js_code={$code}&grant_type=authorization_code";
-        $curl = new curl\Curl();
-        $result = $curl->get($url);
-        $arr = Json::decode($result);
-        $sessionKey = isset($arr['session_key']) ? $arr['session_key'] : '';
-        $openid = $arr['openid'] ?? '';
-        $unionId = $arr['unionid'] ?? '';
-        if (empty($openid)) {
-            Yii::info(json_encode($arr));
-            util::fail('没有获取到小程序openId');
-        }
-        $cacheKey = 'GHS_SHOP_MINI_SESSION_KEY_' . $openid;
-        Yii::$app->redis->executeCommand('SET', [$cacheKey, $sessionKey]);
-        //用户来源
-        $userSource = UserClass::$userSourceId['mini']['name'];
-        $admin = AdminService::getByMiniOpenId($openid);
+            $demoId = dict::getDict('ghsDemoAdminId');
+            $admin = AdminClass::getById($demoId);
+            if (empty($admin)) {
+                util::fail('没有演示权限');
+            }
+        } else {
+            $wxMiniBase = WxOpenClass::getGhsWxInfo();
+            $appId = $wxMiniBase['miniAppId'];
+            $appSecret = $wxMiniBase['miniAppSecret'];
+            if (empty($appSecret)) {
+                util::fail('没有找到小程序的密钥');
+            }
+            $url = "https://api.weixin.qq.com/sns/jscode2session?appid={$appId}&secret={$appSecret}&js_code={$code}&grant_type=authorization_code";
+            $curl = new curl\Curl();
+            $result = $curl->get($url);
+            $arr = Json::decode($result);
+            $sessionKey = isset($arr['session_key']) ? $arr['session_key'] : '';
+            $openid = $arr['openid'] ?? '';
+            $unionId = $arr['unionid'] ?? '';
+            if (empty($openid)) {
+                Yii::info(json_encode($arr));
+                util::fail('没有获取到小程序openId');
+            }
+            $cacheKey = 'GHS_SHOP_MINI_SESSION_KEY_' . $openid;
+            Yii::$app->redis->executeCommand('SET', [$cacheKey, $sessionKey]);
+            //用户来源
+            $userSource = UserClass::$userSourceId['mini']['name'];
+            $admin = AdminService::getByMiniOpenId($openid);
+        }
         if (empty($admin)) {
             $adminInfo = ['miniOpenId' => $openid, 'style' => 2, 'unionId' => $unionId];
             $admin = AdminService::replaceAdmin($adminInfo, $userSource);
@@ -222,6 +227,7 @@ class AuthController extends PublicController
         }
         $admin['avatar'] = imgUtil::getPrefix() . '/retail/default-img.png';
         $token = jwt::getNewToken($adminId);
+        $showDemo = dict::getDict('showDemo');
         util::success([
             'token' => $token,
             'admin' => $admin,
@@ -229,6 +235,7 @@ class AuthController extends PublicController
             'shopId' => $currentShopId,
             'switchShop' => $switchShop,
             'openShop' => $openShop,
+            'showDemo' => $showDemo,
         ]);
     }
 

+ 38 - 24
app-hd/controllers/AuthController.php

@@ -8,6 +8,7 @@ use bizHd\admin\services\ShopAdminService;
 use bizHd\admin\services\AdminService;
 use bizHd\user\classes\UserClass;
 use bizHd\wx\services\WxOpenService;
+use common\components\dict;
 use common\components\httpUtil;
 use common\components\imgUtil;
 use common\components\jwt;
@@ -176,30 +177,35 @@ class AuthController extends PublicController
 
         $code = Yii::$app->request->get('code', '');
         if (empty($code)) {
-            util::fail('没有CODE信息');
-        }
-        $wxMiniBase = WxOpenService::getWxMiniBase();
-        $appId = $wxMiniBase['miniAppId'];
-        $appSecret = $wxMiniBase['miniAppSecret'];
-        if (empty($appSecret)) {
-            util::fail('没有找到小程序的密钥');
-        }
-        $url = "https://api.weixin.qq.com/sns/jscode2session?appid={$appId}&secret={$appSecret}&js_code={$code}&grant_type=authorization_code";
-        $curl = new curl\Curl();
-        $result = $curl->get($url);
-        $arr = Json::decode($result);
-        $sessionKey = isset($arr['session_key']) ? $arr['session_key'] : '';
-        $openid = $arr['openid'] ?? '';
-        $unionId = $arr['unionid'] ?? '';
-        $cacheKey = 'SHOP_MINI_SESSION_KEY_' . $openid;
-        Yii::$app->redis->executeCommand('SET', [$cacheKey, $sessionKey]);
-        if (empty($openid)) {
-            Yii::info(json_encode($arr));
-            util::fail('没有获取到小程序openId');
+            $demoId = dict::getDict('hdDemoAdminId');
+            $admin = AdminClass::getById($demoId);
+            if (empty($admin)) {
+                util::fail('没有演示权限');
+            }
+        } else {
+            $wxMiniBase = WxOpenService::getWxMiniBase();
+            $appId = $wxMiniBase['miniAppId'];
+            $appSecret = $wxMiniBase['miniAppSecret'];
+            if (empty($appSecret)) {
+                util::fail('没有找到小程序的密钥');
+            }
+            $url = "https://api.weixin.qq.com/sns/jscode2session?appid={$appId}&secret={$appSecret}&js_code={$code}&grant_type=authorization_code";
+            $curl = new curl\Curl();
+            $result = $curl->get($url);
+            $arr = Json::decode($result);
+            $sessionKey = isset($arr['session_key']) ? $arr['session_key'] : '';
+            $openid = $arr['openid'] ?? '';
+            $unionId = $arr['unionid'] ?? '';
+            $cacheKey = 'SHOP_MINI_SESSION_KEY_' . $openid;
+            Yii::$app->redis->executeCommand('SET', [$cacheKey, $sessionKey]);
+            if (empty($openid)) {
+                Yii::info(json_encode($arr));
+                util::fail('没有获取到小程序openId');
+            }
+            //用户来源
+            $userSource = UserClass::$userSourceId['mini']['name'];
+            $admin = AdminService::getByMiniOpenId($openid);
         }
-        //用户来源
-        $userSource = UserClass::$userSourceId['mini']['name'];
-        $admin = AdminService::getByMiniOpenId($openid);
         if (empty($admin)) {
             $adminInfo = ['miniOpenId' => $openid, 'style' => 1, 'unionId' => $unionId];
             $admin = AdminService::replaceAdmin($adminInfo, $userSource);
@@ -221,7 +227,15 @@ class AuthController extends PublicController
         $avatar = isset($admin['avatar']) && !empty($admin['avatar']) ? $prefix . $admin['avatar'] : $prefix . '/retail/default-img.png';
         $admin['avatar'] = $avatar;
         $token = jwt::getNewToken($adminId);
-        util::success(['token' => $token, 'admin' => $admin, 'shopId' => $shopId, 'shopAdminId' => $shopAdminId, 'switchShop' => $switchShop]);
+        $showDemo = dict::getDict('showDemo');
+        util::success([
+            'token' => $token,
+            'admin' => $admin,
+            'shopId' => $shopId,
+            'shopAdminId' => $shopAdminId,
+            'switchShop' => $switchShop,
+            'showDemo' => $showDemo
+        ]);
     }
 
 }

+ 0 - 9
app-mall/controllers/PayController.php

@@ -6,22 +6,13 @@ use bizMall\goods\services\CategoryRelateService;
 use bizMall\goods\services\UsageRelationService;
 use bizMall\order\services\OrderService;
 use bizMall\promote\services\CouponService;
-use bizMall\user\services\UserAssetService;
-use bizMall\wx\services\WxSceneService;
-use common\components\qrCodeUtil;
-use common\models\xhOrder;
 use common\models\xhShop;
 use common\services\xhMerchantExtendService;
-use Faker\Provider\Base;
 use Yii;
-use yii\helpers\Json;
 use common\services\xhUserAssetService;
 use common\services\xhUserService;
 use common\services\xhCouponService;
-use common\services\xhPayToolService;
 use common\services\xhOrderService;
-use common\services\xhActiveService;
-use common\services\xhActiveTicketClassService;
 use common\components\util;
 use common\components\stringUtil;
 use common\components\dict;

+ 3 - 1
app-mall/controllers/UserController.php

@@ -8,6 +8,7 @@ use bizMall\message\services\SmsService;
 use bizMall\user\classes\UserClass;
 use bizMall\user\services\UserAssetService;
 use bizMall\user\services\UserService;
+use common\components\dict;
 use common\components\imgUtil;
 use common\components\stringUtil;
 use Yii;
@@ -24,7 +25,8 @@ class UserController extends BaseController
     {
         $list = UserClass::getRecentShop($this->user);
         //0最近访问的门店 1国兰门店信息
-        util::success(['list' => $list, 'showIndex' => 0]);
+        $showMallIndex = dict::getDict('showMallIndex');
+        util::success(['list' => $list, 'showIndex' => $showMallIndex]);
     }
 
     //获取登陆客户的资产 ssh 2019.11.22

+ 54 - 30
biz-hd/purchase/classes/PurchaseClass.php

@@ -4,6 +4,7 @@ namespace bizHd\purchase\classes;
 
 use biz\ghs\classes\GhsClass;
 use biz\ghs\models\Ghs;
+use biz\shop\classes\ShopClass;
 use biz\shop\models\Shop;
 use bizGhs\admin\classes\AdminClass;
 use bizGhs\custom\classes\CustomClass;
@@ -13,6 +14,7 @@ use bizGhs\product\classes\ProductClass;
 use bizGhs\order\classes\OrderClass;
 use common\components\dict;
 use common\components\orderSn;
+use common\components\stringUtil;
 use common\components\util;
 use bizHd\base\classes\BaseClass;
 
@@ -40,7 +42,6 @@ class PurchaseClass extends BaseClass
         $orderSn = orderSn::getPurchaseSn();
         $data['orderSn'] = $orderSn;
         $prePrice = 0;
-        $actPrice = 0;
 
         $data['sendTimeWant'] = date("Y-m-d") . ' ' . $data['sendTime'];
         unset($data['sendTime']);
@@ -61,31 +62,31 @@ class PurchaseClass extends BaseClass
         $smallNum = 0; //总共多少支
         foreach ($productList as $key => $product) {
 
-            $bigNum += $product['bigNum']??0;
-            $smallNum += $product['smallNum']??0;
+            $bigNum += $product['bigNum'] ?? 0;
+            $smallNum += $product['smallNum'] ?? 0;
             $productList[$key]['orderSn'] = $orderSn;
             $productId = $product['productId'];
-            $ratio = $productData[$productId]['ratio']??0;
-            $itemId = $productData[$productId]['itemId']??0;
-            $rank = $productData[$productId]['rank']??'B';// 花材级别
-            $stock = $productData[$productId]['stock']??0;//当时库存
-            $stockFormat= ProductClass::formatStock($stock,$ratio);
+            $ratio = $productData[$productId]['ratio'] ?? 0;
+            $itemId = $productData[$productId]['itemId'] ?? 0;
+            $rank = $productData[$productId]['rank'] ?? 'B';// 花材级别
+            $stock = $productData[$productId]['stock'] ?? 0;//当时库存
+            $stockFormat = ProductClass::formatStock($stock, $ratio);
 
-            $itemNum =  ProductClass::mergeItemNum($product['bigNum'],$product['smallNum'],$ratio);//采购数量
+            $itemNum = ProductClass::mergeItemNum($product['bigNum'], $product['smallNum'], $ratio);//采购数量
             $price = $productData[$productId]['price']; //卖的单价
-            $sellPrice = bcmul($itemNum,$price,2); //采购总价
+            $sellPrice = bcmul($itemNum, $price, 2); //采购总价
             $itemInfo = [
-                'itemName'=> $productData[$productId]['name']??'',//花材名称
-                'itemCover'=> $productData[$productId]['cover']??'',//花材图片
-                'bigNum'=> $product['bigNum']??0,//采购数量(大单位)
-                'smallNum'=> $product['smallNum']??0,//采购数量(小单位)
-                'bigNumStock'=> $stockFormat['bigNum'],// 当时库存大单位数
-                'smallNumStock'=> $stockFormat['smallNum'],//当时库存 小单位数
-                'itemUnit'=> $ratio?2:1,//单位
-                'ratio'=>$ratio,// 比例
-                'rank'=>$rank,// 花材级别
-                'bigUnit'=> $productData[$productId]['bigUnit'],//大单位名称 扎
-                'smallUnit'=> $productData[$productId]['smallUnit'],//小单位名称 支
+                'itemName' => $productData[$productId]['name'] ?? '',//花材名称
+                'itemCover' => $productData[$productId]['cover'] ?? '',//花材图片
+                'bigNum' => $product['bigNum'] ?? 0,//采购数量(大单位)
+                'smallNum' => $product['smallNum'] ?? 0,//采购数量(小单位)
+                'bigNumStock' => $stockFormat['bigNum'],// 当时库存大单位数
+                'smallNumStock' => $stockFormat['smallNum'],//当时库存 小单位数
+                'itemUnit' => $ratio ? 2 : 1,//单位
+                'ratio' => $ratio,// 比例
+                'rank' => $rank,// 花材级别
+                'bigUnit' => $productData[$productId]['bigUnit'],//大单位名称 扎
+                'smallUnit' => $productData[$productId]['smallUnit'],//小单位名称 支
             ];
 
             $productList[$key]['itemInfo'] = json_encode($itemInfo);
@@ -94,9 +95,9 @@ class PurchaseClass extends BaseClass
             $productList[$key]['price'] = $price;
             $productList[$key]['ratio'] = $ratio;
             $productList[$key]['totalPrice'] = $sellPrice;
-            $prePrice = bcadd($prePrice,$sellPrice,2);
+            $prePrice = bcadd($prePrice, $sellPrice, 2);
         }
-        $prePrice = bcadd($prePrice,$data['sendCost'],2);
+        $prePrice = bcadd($prePrice, $data['sendCost'], 2);
         $actPrice = $prePrice;
         $data['prePrice'] = $prePrice;
         $data['actPrice'] = $actPrice;
@@ -107,7 +108,6 @@ class PurchaseClass extends BaseClass
             util::fail('请选择花材');
         }
 
-
         PurchaseItemClass::batchAdd($productList);
 
         //供货商增加订单
@@ -116,6 +116,9 @@ class PurchaseClass extends BaseClass
             util::fail('没有找到供货商');
         }
         $ghs = GhsClass::getGhsInfo($ghsId);
+        if (empty($ghs)) {
+            util::fail('还是没有找到供货商');
+        }
         $ghsSjId = $ghs['sjId'] ?? 0;
         $ghsShopId = $ghs['shopId'] ?? 0;
         $getType = $data['getType'] ?? 0;
@@ -123,7 +126,28 @@ class PurchaseClass extends BaseClass
 
         $custom = CustomClass::getByCondition(['ownSjId' => $ghsSjId, 'sjId' => $hdSjId, 'shopId' => $hdShopId]);
         if (empty($custom)) {
-            util::fail('没有找到客户');
+            $hdShop = ShopClass::getShopInfo($hdShopId);
+            $name = $hdShop['shopName'] ?? '';
+            $py = stringUtil::py($name);
+            $mobile = $hdShop['mobile'];
+            $customData = [
+                'sjId' => $hdSjId,
+                'shopId' => $hdShopId,
+                'ownSjId' => $ghsSjId,
+                'name' => $name,
+                'py' => $py,
+                'mobile' => $mobile,
+                'city' => $shop['city'] ?? '',
+                'dist' => $shop['dist'] ?? '',
+                'address' => $shop['address'] ?? '',
+                'fullAddress' => $shop['fullAddress'] ?? '',
+                'long' => $shop['long'] ?? '',
+                'lat' => $shop['lat'] ?? '',
+            ];
+            $custom = CustomClass::addCustom($customData);
+        }
+        if (empty($custom)) {
+            util::fail('还是没有找到客户');
         }
         $customId = $custom['id'] ?? 0;
         $customName = $custom['name'] ?? '';
@@ -195,18 +219,18 @@ class PurchaseClass extends BaseClass
                 $orderSn = $val['orderSn'];
                 $orderItem = PurchaseItemClass::getOrderItemDetail($orderSn);
                 $itemData = [];
-                if($orderItem) {
+                if ($orderItem) {
                     foreach ($orderItem as $v) {
-                        $info = json_decode($v['itemInfo'],true);
+                        $info = json_decode($v['itemInfo'], true);
                         $tmp = $info;
                         $tmp['cover'] = self::groupImg($info['itemCover']);
                         unset($v['itemInfo']);
                         //兼容 旧数据,没有 rank (花材等级 默认给B)
-                        if(!isset($tmp['rank'])){
-                            $tmp['rank']= 'B';
+                        if (!isset($tmp['rank'])) {
+                            $tmp['rank'] = 'B';
                         }
                         $tmp['name'] = $tmp['itemName'];
-                        $tmp = array_merge($tmp,$v);
+                        $tmp = array_merge($tmp, $v);
                         $itemData[] = $tmp;
                     }
                 }

+ 8 - 0
common/components/dict.php

@@ -9,6 +9,14 @@ class dict
 
     public static $data = [
 
+        //0最近访问的门店 1国兰门店信息
+        'showMallIndex' => 1,
+        //显示零售和供货商的演示入口
+        'showDemo' => 1,
+        //零售演示的管理员id
+        'hdDemoAdminId' => 138,
+        //供货商演示的管理员id
+        'ghsDemoAdminId' => 125,
         'expressList' => [
             [
                 "id" => 1,