shish 5 лет назад
Родитель
Сommit
4e90546e98
1 измененных файлов с 154 добавлено и 152 удалено
  1. 154 152
      biz-ghs/shop/services/ShopAdminService.php

+ 154 - 152
biz-ghs/shop/services/ShopAdminService.php

@@ -20,156 +20,158 @@ use Yii;
 
 class ShopAdminService extends BaseService
 {
-	
-	public static $baseFile = '\bizGhs\shop\classes\ShopAdminClass';
-	
-	///创建管理员生成小程序 shish 2020.4.17
-	public static function prepareBindAdmin($data)
-	{
-		$merchant = $data['merchant'];
-		unset($data['merchant']);
-		ShopAdminClass::prepareBindAdmin($data);
-		$page = 'admin/shopAdmin/bind';
-		$isOpen = 2;
-		$adminId = $data['adminId'];
-		$shopId = $data['shopId'];
-		$scene = 'adminId=' . $adminId . '&shopId=' . $shopId;
-		$imgUrl = miniUtil::generateUnlimitedMiniCode($merchant, $page, $scene, $isOpen);
-		return ['miniCode' => $imgUrl];
-	}
-	
-	public static function generateAdmin($data)
-	{
-		$recommendAdminId = $data['recommendAdminId'] ?? 0;
-		$mobile = $data['mobile'] ?? '';
-		$shopId = $data['shopId'] ?? 0;
-		$adminId = $data['adminId'] ?? 0;
-		$ghsId = $data['ghsId'] ?? 0;
-
-		$shop = ShopClass::getById($shopId);
-		Yii::info('ghsId:'.$ghsId.' shopInfo:'.json_encode($shop));
-		ShopClass::valid($shop, $ghsId);
-
-		$source = ShopAdminClass::getBindAdminData($shopId, $recommendAdminId);
-		if (empty($source)) {
-			util::fail('小程序码已失效,请重新创建');
-		}
-		$shopAdmin = ShopAdminClass::getByCondition(['ghsId' => $ghsId, 'shopId' => $shopId, 'adminId' => $adminId]);
-		if (!empty($shopAdmin)) {
-			util::fail('您已经是员工');
-		}
-		$adminName = isset($source['adminName']) ? $source['adminName'] : '';
-		
-		$roleId = $source['roleId'] ?? 0;
-		$role = AdminRoleClass::getById($roleId);
-		AdminRoleClass::valid($role, $ghsId);
-		
-		$admin = AdminClass::getById($adminId);
-		AdminClass::valid($admin,$ghsId);
-
-		if (isset($admin['subscribe']) == false || $admin['subscribe'] != 1) {
-			util::fail("请关注公众号");
-		}
-		$roleId = $source['roleId'];
-		$remind = isset($source['remind']) ? $source['remind'] : 0;
-		$status = isset($source['status']) ? $source['status'] : 0;
-		$password = isset($source['password']) ? password_hash($source['password'], PASSWORD_BCRYPT) : '';
-		$remark = isset($source['remark']) ? $source['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,
-			'ghsId' => $ghsId,
-		];
-		ShopAdminClass::delBindAdminData($shopId, $recommendAdminId);
-		return ShopAdminClass::add($addData);
-	}
-
-	//获取管理员 shish 2020.4.21
-	// $sensitive true 密码等敏感信息不显示
-	public static function getAdminList($where, $sensitive = true)
-	{
-		$data = ShopAdminClass::getList('*', $where, 'addTime DESC');
-		$list = isset($data['list']) && !empty($data['list']) ? $data['list'] : [];
-		if (empty($list)) {
-			return $data;
-		}
-		
-		//管理员基础信息
-		$ids = array_column($list, 'adminId');
-		$adminInfo = AdminClass::getByIds($ids, null, 'id');
-		$adminBaseInfo = AdminClass::groupAdminBaseInfo($adminInfo, $sensitive);
-		
-		$roleIds = array_column($list, 'roleId');
-		$roleIds = array_filter(array_unique($roleIds));
-		$roleList = AdminRoleClass::getByIds($roleIds, null, 'id');
-		
-		foreach ($list as $key => $val) {
-			$adminId = $val['adminId'];
-			$roleId = $val['roleId'];
-			$roleName = isset($roleList[$roleId]['roleName']) ? $roleList[$roleId]['roleName'] : '';
-			$list[$key]['roleName'] = $roleName;
-			$currentAdmin = isset($adminBaseInfo[$adminId]) ? $adminBaseInfo[$adminId] : [];
-			$list[$key]['adminName'] = isset($currentAdmin['adminName']) ? $currentAdmin['adminName'] : '';
-			//帐号状态
-			$status = 1;
-			if (isset($currentAdmin['accountStatus']) && $currentAdmin['accountStatus'] == 0) {
-				$status = 0;
-			}
-			if (isset($val['status']) && $val['status'] == 0) {
-				$status = 0;
-			}
-			$list[$key]['status'] = $status;
-		}
-		$data['list'] = $list;
-		return $data;
-	}
-	
-	//获取要通知的管理员 shish 2020.4.28
-	public static function getNoticeAdminList($shopId)
-	{
-		$where = ['shopId' => $shopId];
-		$respond = self::getAdminList($where, false);
-		$list = isset($respond['list']) ? $respond['list'] : [];
-		if (!empty($list)) {
-			foreach ($list as $key => $val) {
-				if (isset($val['remind']) && $val['remind'] == 0) {
-					unset($list[$key]);
-				}
-			}
-		}
-		return $list;
-	}
-	
-	public static function valid($shopAdmin, $shopId)
-	{
-		if (isset($shopAdmin['shopId']) == false || $shopAdmin['shopId'] != $shopId) {
-			util::fail('不是您的员工');
-		}
-	}
-	
-	//根据id取员工信息,包括基本信息和角色 shish 2021.1.13
-	public static function getAdminInfo($id)
-	{
-		$relation = ShopAdminClass::getById($id);
-		if (empty($relation)) {
-			util::fail('没有找到员工信息');
-		}
-		$adminId = isset($relation['adminId']) ? $relation['adminId'] : 0;
-		if (empty($adminId)) {
-			util::fail('没有找到员工');
-		}
-		$adminInfo = AdminClass::getDetail($adminId);
-		$adminInfo['shopId'] = isset($relation['shopId']) ? $relation['shopId'] : 0;
-		$adminInfo['ghsId'] = isset($relation['ghsId']) ? $relation['ghsId'] : 0;
-		$adminInfo['adminId'] = isset($relation['adminId']) ? $relation['adminId'] : 0;
-		$adminInfo['roleId'] = isset($relation['roleId']) ? $relation['roleId'] : 0;
-		$adminInfo['remind'] = isset($relation['remind']) ? $relation['remind'] : 0;
-		return $adminInfo;
-	}
-	
+
+    public static $baseFile = '\bizGhs\shop\classes\ShopAdminClass';
+
+    ///创建管理员生成小程序 shish 2020.4.17
+    public static function prepareBindAdmin($data)
+    {
+        $merchant = $data['merchant'];
+        unset($data['merchant']);
+        ShopAdminClass::prepareBindAdmin($data);
+        $page = 'admin/shopAdmin/bind';
+        $isOpen = 2;
+        $adminId = $data['adminId'];
+        $shopId = $data['shopId'];
+        $scene = 'adminId=' . $adminId . '&shopId=' . $shopId;
+        $imgUrl = miniUtil::generateUnlimitedMiniCode($merchant, $page, $scene, $isOpen);
+        return ['miniCode' => $imgUrl];
+    }
+
+    public static function generateAdmin($data)
+    {
+        $recommendAdminId = $data['recommendAdminId'] ?? 0;
+        $mobile = $data['mobile'] ?? '';
+        $shopId = $data['shopId'] ?? 0;
+        $adminId = $data['adminId'] ?? 0;
+        $ghsId = $data['ghsId'] ?? 0;
+
+        $shop = ShopClass::getById($shopId);
+        Yii::info('ghsId:' . $ghsId . ' shopInfo:' . json_encode($shop));
+        ShopClass::valid($shop, $ghsId);
+
+        $source = ShopAdminClass::getBindAdminData($shopId, $recommendAdminId);
+        if (empty($source)) {
+            util::fail('小程序码已失效,请重新创建');
+        }
+        $shopAdmin = ShopAdminClass::getByCondition(['ghsId' => $ghsId, 'shopId' => $shopId, 'adminId' => $adminId]);
+        if (!empty($shopAdmin)) {
+            util::fail('您已经是员工');
+        }
+        $adminName = isset($source['adminName']) ? $source['adminName'] : '';
+
+        $roleId = $source['roleId'] ?? 0;
+        $role = AdminRoleClass::getById($roleId);
+        AdminRoleClass::valid($role, $ghsId);
+
+        $admin = AdminClass::getById($adminId);
+        if (empty($admin)) {
+            util::fail('员工信息无效');
+        }
+
+        if (isset($admin['subscribe']) == false || $admin['subscribe'] != 1) {
+            util::fail("请关注公众号");
+        }
+        $roleId = $source['roleId'];
+        $remind = isset($source['remind']) ? $source['remind'] : 0;
+        $status = isset($source['status']) ? $source['status'] : 0;
+        $password = isset($source['password']) ? password_hash($source['password'], PASSWORD_BCRYPT) : '';
+        $remark = isset($source['remark']) ? $source['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,
+            'ghsId' => $ghsId,
+        ];
+        ShopAdminClass::delBindAdminData($shopId, $recommendAdminId);
+        return ShopAdminClass::add($addData);
+    }
+
+    //获取管理员 shish 2020.4.21
+    // $sensitive true 密码等敏感信息不显示
+    public static function getAdminList($where, $sensitive = true)
+    {
+        $data = ShopAdminClass::getList('*', $where, 'addTime DESC');
+        $list = isset($data['list']) && !empty($data['list']) ? $data['list'] : [];
+        if (empty($list)) {
+            return $data;
+        }
+
+        //管理员基础信息
+        $ids = array_column($list, 'adminId');
+        $adminInfo = AdminClass::getByIds($ids, null, 'id');
+        $adminBaseInfo = AdminClass::groupAdminBaseInfo($adminInfo, $sensitive);
+
+        $roleIds = array_column($list, 'roleId');
+        $roleIds = array_filter(array_unique($roleIds));
+        $roleList = AdminRoleClass::getByIds($roleIds, null, 'id');
+
+        foreach ($list as $key => $val) {
+            $adminId = $val['adminId'];
+            $roleId = $val['roleId'];
+            $roleName = isset($roleList[$roleId]['roleName']) ? $roleList[$roleId]['roleName'] : '';
+            $list[$key]['roleName'] = $roleName;
+            $currentAdmin = isset($adminBaseInfo[$adminId]) ? $adminBaseInfo[$adminId] : [];
+            $list[$key]['adminName'] = isset($currentAdmin['adminName']) ? $currentAdmin['adminName'] : '';
+            //帐号状态
+            $status = 1;
+            if (isset($currentAdmin['accountStatus']) && $currentAdmin['accountStatus'] == 0) {
+                $status = 0;
+            }
+            if (isset($val['status']) && $val['status'] == 0) {
+                $status = 0;
+            }
+            $list[$key]['status'] = $status;
+        }
+        $data['list'] = $list;
+        return $data;
+    }
+
+    //获取要通知的管理员 shish 2020.4.28
+    public static function getNoticeAdminList($shopId)
+    {
+        $where = ['shopId' => $shopId];
+        $respond = self::getAdminList($where, false);
+        $list = isset($respond['list']) ? $respond['list'] : [];
+        if (!empty($list)) {
+            foreach ($list as $key => $val) {
+                if (isset($val['remind']) && $val['remind'] == 0) {
+                    unset($list[$key]);
+                }
+            }
+        }
+        return $list;
+    }
+
+    public static function valid($shopAdmin, $shopId)
+    {
+        if (isset($shopAdmin['shopId']) == false || $shopAdmin['shopId'] != $shopId) {
+            util::fail('不是您的员工');
+        }
+    }
+
+    //根据id取员工信息,包括基本信息和角色 shish 2021.1.13
+    public static function getAdminInfo($id)
+    {
+        $relation = ShopAdminClass::getById($id);
+        if (empty($relation)) {
+            util::fail('没有找到员工信息');
+        }
+        $adminId = isset($relation['adminId']) ? $relation['adminId'] : 0;
+        if (empty($adminId)) {
+            util::fail('没有找到员工');
+        }
+        $adminInfo = AdminClass::getDetail($adminId);
+        $adminInfo['shopId'] = isset($relation['shopId']) ? $relation['shopId'] : 0;
+        $adminInfo['ghsId'] = isset($relation['ghsId']) ? $relation['ghsId'] : 0;
+        $adminInfo['adminId'] = isset($relation['adminId']) ? $relation['adminId'] : 0;
+        $adminInfo['roleId'] = isset($relation['roleId']) ? $relation['roleId'] : 0;
+        $adminInfo['remind'] = isset($relation['remind']) ? $relation['remind'] : 0;
+        return $adminInfo;
+    }
+
 }