shish 6 лет назад
Родитель
Сommit
31c3581d11

+ 1 - 1
app/mall/controllers/TestController.php

@@ -11,7 +11,7 @@ class TestController extends BaseController
 	
 	public function actionRabbit()
 	{
-		InformAdminService::addInform(12358, 'goodsSold', ['price' => 20]);
+		InformAdminService::addInform(12358, 15680, 'goodsSold', ['price' => 20]);
 		util::end();
 		$producer = Yii::$app->rabbitmq->getProducer('producerCommon');
 		$msg = serialize(['user_id' => rand(111, 999)]);

+ 112 - 100
biz/admin/services/AdminShopService.php

@@ -18,104 +18,116 @@ use Yii;
 
 class AdminShopService extends BaseService
 {
-
-    public static $baseFile = '\biz\admin\classes\AdminShopClass';
-
-    ///创建管理员关联数据准备 shish 2020.4.17
-    public static function prepareBindAdmin($data)
-    {
-        AdminShopClass::prepareBindAdmin($data);
-        $page = 'admin/adminShop/bind';
-        $isOpen = 1;
-        $adminId = $data['adminId'];
-        $shopId = $data['shopId'];
-        $scene = 'adminId=' . $adminId . '&shopId=' . $shopId;
-        $merchant = $data['merchant'];
-        $imgUrl = wxUtil::generateUnlimitedMiniCode($merchant, $page, $scene, $isOpen);
-        return ['miniCode' => $imgUrl];
-    }
-
-    public static function generateAdmin($data)
-    {
-        $recommendAdminId = isset($data['recommendAdminId']) ? $data['recommendAdminId'] : 0;
-        $mobile = isset($data['mobile']) ? $data['mobile'] : '';
-        $shopId = isset($data['shopId']) ? $data['shopId'] : 0;
-        $adminId = isset($data['adminId']) ? $data['adminId'] : 0;
-        $bindData = AdminShopClass::getBindAdminData($shopId, $recommendAdminId);
-        $shop = ShopClass::getById($shopId);
-        if (empty($shop)) {
-            util::fail('没有找到门店');
-        }
-        $merchantId = isset($shop['merchantId']) ? $shop['merchantId'] : 0;
-        if (empty($bindData)) {
-            util::fail('小程序码已经失效,请重新创建员工');
-        }
-        $adminShop = AdminShopClass::getByCondition(['adminId' => $adminId, 'shopId' => $shopId]);
-        if (!empty($adminShop)) {
-            util::fail('您已经是管理员了');
-        }
-        $adminName = isset($bindData['adminName']) ? $bindData['adminName'] : '';
-        if (isset($bindData['roleId']) == false || empty($bindData['roleId'])) {
-            util::fail('添加管理员时请选择角色');
-        }
-        $admin = AdminClass::getById($adminId);
-        if (isset($admin['subscribe']) == false || $admin['subscribe'] != 1) {
-            util::fail('请关注公众号');
-        }
-        $roleId = $bindData['roleId'];
-        $remind = isset($bindData['remind']) ? $bindData['remind'] : 0;
-        $status = isset($bindData['status']) ? $bindData['status'] : 0;
-        $password = isset($bindData['password']) ? password_hash($bindData['password'], PASSWORD_BCRYPT) : '';
-        $remark = isset($bindData['remark']) ? $bindData['remark'] : '';
-        $update = ['adminName' => $adminName, 'mobile' => $mobile, 'password' => $password, 'remark' => $remark];
-        AdminClass::updateById($adminId, $update);
-        $addData = [
-            'adminId' => $adminId,
-            'shopId' => $shopId,
-            'roleId' => $roleId,
-            'remind' => $remind,
-            'status' => $status,
-            'merchantId' => $merchantId,
-        ];
-        AdminShopClass::delBindAdminData($shopId, $recommendAdminId);
-        return AdminShopClass::add($addData);
-    }
-
-    //获取管理员 shish 2020.4.21
-    public static function getAdminList($where)
-    {
-        $data = AdminShopClass::getList('*', $where, 'addTime DESC');
-        $list = isset($data['list']) && !empty($data['list']) ? $data['list'] : [];
-        if (empty($list)) {
-            return $data;
-        }
-
-        $params = [];
-        foreach ($list as $val) {
-            $adminId = $val['adminId'];
-            $params[$adminId] = ['remind' => $val['remind'], 'status' => $val['status']];
-        }
-
-        //所有的管理员
-        $ids = array_column($list, 'adminId');
-        $newList = AdminClass::getByIds($ids);
-        $newList = AdminClass::groupAdminBaseInfo($newList);
-
-        foreach ($newList as $newKey => $newVal) {
-            $adminId = $newVal['id'];
-            $newList[$newKey]['remind'] = isset($params[$adminId]['remind']) ? $params[$adminId]['remind'] : 0;
-            $newList[$newKey]['status'] = isset($params[$adminId]['status']) ? $params[$adminId]['status'] : 0;
-        }
-
-        $data['list'] = $newList;
-        return $data;
-    }
-
-    public static function valid($adminShop, $shopId)
-    {
-        if (isset($adminShop['shopId']) == false || $adminShop['shopId'] != $shopId) {
-            util::fail('不是您的员工,没有权限操作');
-        }
-    }
-
+	
+	public static $baseFile = '\biz\admin\classes\AdminShopClass';
+	
+	///创建管理员关联数据准备 shish 2020.4.17
+	public static function prepareBindAdmin($data)
+	{
+		AdminShopClass::prepareBindAdmin($data);
+		$page = 'admin/adminShop/bind';
+		$isOpen = 1;
+		$adminId = $data['adminId'];
+		$shopId = $data['shopId'];
+		$scene = 'adminId=' . $adminId . '&shopId=' . $shopId;
+		$merchant = $data['merchant'];
+		$imgUrl = wxUtil::generateUnlimitedMiniCode($merchant, $page, $scene, $isOpen);
+		return ['miniCode' => $imgUrl];
+	}
+	
+	public static function generateAdmin($data)
+	{
+		$recommendAdminId = isset($data['recommendAdminId']) ? $data['recommendAdminId'] : 0;
+		$mobile = isset($data['mobile']) ? $data['mobile'] : '';
+		$shopId = isset($data['shopId']) ? $data['shopId'] : 0;
+		$adminId = isset($data['adminId']) ? $data['adminId'] : 0;
+		$bindData = AdminShopClass::getBindAdminData($shopId, $recommendAdminId);
+		$shop = ShopClass::getById($shopId);
+		if (empty($shop)) {
+			util::fail('没有找到门店');
+		}
+		$merchantId = isset($shop['merchantId']) ? $shop['merchantId'] : 0;
+		if (empty($bindData)) {
+			util::fail('小程序码已经失效,请重新创建员工');
+		}
+		$adminShop = AdminShopClass::getByCondition(['adminId' => $adminId, 'shopId' => $shopId]);
+		if (!empty($adminShop)) {
+			util::fail('您已经是管理员了');
+		}
+		$adminName = isset($bindData['adminName']) ? $bindData['adminName'] : '';
+		if (isset($bindData['roleId']) == false || empty($bindData['roleId'])) {
+			util::fail('添加管理员时请选择角色');
+		}
+		$admin = AdminClass::getById($adminId);
+		if (isset($admin['subscribe']) == false || $admin['subscribe'] != 1) {
+			util::fail('请关注公众号');
+		}
+		$roleId = $bindData['roleId'];
+		$remind = isset($bindData['remind']) ? $bindData['remind'] : 0;
+		$status = isset($bindData['status']) ? $bindData['status'] : 0;
+		$password = isset($bindData['password']) ? password_hash($bindData['password'], PASSWORD_BCRYPT) : '';
+		$remark = isset($bindData['remark']) ? $bindData['remark'] : '';
+		$update = ['adminName' => $adminName, 'mobile' => $mobile, 'password' => $password, 'remark' => $remark];
+		AdminClass::updateById($adminId, $update);
+		$addData = [
+			'adminId' => $adminId,
+			'shopId' => $shopId,
+			'roleId' => $roleId,
+			'remind' => $remind,
+			'status' => $status,
+			'merchantId' => $merchantId,
+		];
+		AdminShopClass::delBindAdminData($shopId, $recommendAdminId);
+		return AdminShopClass::add($addData);
+	}
+	
+	//获取管理员 shish 2020.4.21
+	public static function getAdminList($where)
+	{
+		$data = AdminShopClass::getList('*', $where, 'addTime DESC');
+		$list = isset($data['list']) && !empty($data['list']) ? $data['list'] : [];
+		if (empty($list)) {
+			return $data;
+		}
+		
+		$params = [];
+		foreach ($list as $val) {
+			$adminId = $val['adminId'];
+			$params[$adminId] = ['remind' => $val['remind'], 'status' => $val['status']];
+		}
+		
+		//所有的管理员
+		$ids = array_column($list, 'adminId');
+		$newList = AdminClass::getByIds($ids);
+		$newList = AdminClass::groupAdminBaseInfo($newList);
+		
+		foreach ($newList as $newKey => $newVal) {
+			$adminId = $newVal['id'];
+			$newList[$newKey]['remind'] = isset($params[$adminId]['remind']) ? $params[$adminId]['remind'] : 0;
+			$newList[$newKey]['status'] = isset($params[$adminId]['status']) ? $params[$adminId]['status'] : 0;
+		}
+		
+		$data['list'] = $newList;
+		return $data;
+	}
+	
+	public static function getNoticeAdminList($shopId)
+	{
+		$where = ['shopId' => $shopId];
+		$list = self::getAdminList($where);
+		foreach ($list as $key => $val) {
+			if (isset($val['remind']) && $val['remind'] == 0) {
+				unset($list[$key]);
+			}
+		}
+		return $list;
+	}
+	
+	public static function valid($adminShop, $shopId)
+	{
+		if (isset($adminShop['shopId']) == false || $adminShop['shopId'] != $shopId) {
+			util::fail('不是您的员工,没有权限操作');
+		}
+	}
+	
 }

+ 5 - 4
biz/message/services/InformAdminService.php

@@ -4,6 +4,7 @@ namespace biz\message\services;
 
 use biz\admin\classes\AdminClass;
 use biz\admin\services\AdminService;
+use biz\admin\services\AdminShopService;
 use biz\base\services\BaseService;
 use biz\merchant\services\MerchantService;
 use biz\message\classes\InformAdminClass;
@@ -18,22 +19,22 @@ class InformAdminService extends BaseService
 	public static $baseFile = '\biz\message\classes\InformAdminClass';
 	
 	//通知员工 shish 2020.1.1
-	public static function addInform($merchantId, $type, $params)
+	public static function addInform($merchantId, $shopId, $type, $params)
 	{
-		$adminList = AdminClass::getAllNoticeAdmin($merchantId);
+		$adminList = AdminShopService::getNoticeAdminList($shopId);
 		if (empty($adminList)) {
 			return false;
 		}
 		//本地环境取消通知
 		if (getenv('YII_ENV') == 'local') {
-			//return false;
+			return false;
 		}
 		$TMList = xhTMessageService::getList($merchantId);
 		foreach ($adminList as $adminKey => $admin) {
 			InformAdminClass::addInform($params, $admin, $type, $TMList);
 		}
 	}
-	
+
 	//消费通知内容 shish 2020.1.1
 	public static function consumeInformQueue($data)
 	{

+ 2 - 2
common/services/xhMerchantAssetService.php

@@ -61,7 +61,7 @@ class xhMerchantAssetService
 	}
 	
 	//收入后资产变更 shish 2019.12.24
-	public static function incomeChangeAsset($merchant, $merchantAsset, $updateData, $order, $capitalType, $isRecharge = false)
+	public static function incomeChangeAsset($merchant, $merchantAsset, $shopId, $updateData, $order, $capitalType, $isRecharge = false)
 	{
 		$merchantId = $merchant['id'];
 		$openMerchant = xhWxOpenService::getMerchant();
@@ -97,7 +97,7 @@ class xhMerchantAssetService
 				//收入提醒 shish 2020.1.30
 				$params = ['sourceType' => $order['sourceType']];
 				$type = 'income';
-				InformAdminService::addInform($merchantId, $type, $params);
+				InformAdminService::addInform($merchantId, $shopId, $type, $params);
 				break;
 			default:
 		}

+ 8 - 3
common/services/xhPayToolService.php

@@ -3,6 +3,7 @@
 namespace common\services;
 
 use biz\coupon\classes\CouponClass;
+use biz\merchant\classes\ShopClass;
 use biz\order\classes\OrderSendClass;
 use biz\order\services\OrderService;
 use biz\user\classes\UserClass;
@@ -111,6 +112,10 @@ class xhPayToolService
 			$userTotalExpend = $totalExpend;
 			$merchant = xhMerchantService::getById($merchantId);
 			$merchantExtend = xhMerchantExtendService::getByMerchantId($merchantId);
+			$shopId = isset($order['shopId']) ? $order['shopId'] : 0;
+			if (empty($shopId)) {
+				$shopId = ShopClass::getDefaultShopId($merchant);
+			}
 			$now = time();
 			$date = date("Y-m-d H:i:s", $now);
 			//余额支付
@@ -162,8 +167,8 @@ class xhPayToolService
 			$mUpdateData = ['totalIncome' => $mIncome, 'usedRecharge' => $mUseRecharge, 'totalDeal' => $mTotalDeal];
 			//支付方式要转到商家资产变更里去
 			$order['payWay'] = $payWay;
-			xhMerchantAssetService::incomeChangeAsset($merchant, $mAsset, $mUpdateData, $order, $capitalType);//商家资产改变
-			
+			xhMerchantAssetService::incomeChangeAsset($merchant, $mAsset, $shopId, $mUpdateData, $order, $capitalType);//商家资产改变
+
 			$userName = isset($user['userName']) ? $user['userName'] : '游客';
 			switch ($capitalType) {
 				case $typeList['xhOrder']['id']://购买商品
@@ -225,7 +230,7 @@ class xhPayToolService
 					xhApplyOrderService::updateById($orderId, $updateData);
 					break;
 				default:
-					Yii::warning('更新订单失败,回调传过来的 capitalType 不符合要求,即订单流水类型不明确,capitalType:' . $capitalType . ' orderSn:' . $orderSn);
+					Yii::warning('更新订单失败,回调的capitalType不符合要求,capitalType:' . $capitalType . ' orderSn:' . $orderSn);
 					util::fail('订单流水类型不明确');
 			}
 			

+ 7 - 2
common/services/xhRechargeService.php

@@ -2,6 +2,7 @@
 
 namespace common\services;
 
+use biz\merchant\classes\ShopClass;
 use Yii;
 use common\components\stringUtil;
 use common\components\configDict;
@@ -47,6 +48,8 @@ class xhRechargeService
 		$merchantExtend = xhMerchantExtendService::getByMerchantId($merchantId);
 		$merchantAsset = xhMerchantAssetService::getByMerchantId($merchantId);
 		$rechargeAmount = $amount;
+		//充值暂时算到默认门店
+		$shopId = ShopClass::getDefaultShopId($merchant);
 		
 		$connection = Yii::$app->db;//事务处理
 		$transaction = $connection->beginTransaction();
@@ -87,7 +90,7 @@ class xhRechargeService
 			$mPreDeal = $merchantAsset['totalDeal'];
 			$mDeal = $mPreDeal + 1;//交易量+1
 			$upMData = ['totalDeal' => $mDeal, 'totalRecharge' => $merchantTotalRecharge];
-			xhMerchantAssetService::incomeChangeAsset($merchant, $merchantAsset, $upMData, $recharge, $capitalType);//商家资产变化
+			xhMerchantAssetService::incomeChangeAsset($merchant, $merchantAsset, $shopId, $upMData, $recharge, $capitalType);//商家资产变化
 			
 			$integralData = [
 				'userId' => $userId,
@@ -173,10 +176,12 @@ class xhRechargeService
 			$upData['totalRecharge'] = $totalRecharge;
 			xhUserAssetService::ioChangeAsset($user, $userAsset, $upData, $merchant, $merchantExtend, $order, $capitalType);//用户资产变化
 			
+			//充值暂时算到默认门店
+			$shopId = ShopClass::getDefaultShopId($merchant);
 			$mPreDeal = $merchantAsset['totalDeal'];
 			$mDeal = $mPreDeal + 1;//交易量+1
 			$upMData = ['totalDeal' => $mDeal, 'totalRecharge' => $merchantTotalRecharge];
-			xhMerchantAssetService::incomeChangeAsset($merchant, $merchantAsset, $upMData, $order, $capitalType, true);//商家资产变化
+			xhMerchantAssetService::incomeChangeAsset($merchant, $merchantAsset, $shopId, $upMData, $order, $capitalType, true);//商家资产变化
 			
 			$integralData = [
 				'userId' => $userId,