| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122 |
- <?php
- namespace biz\shop\classes;
- use bizHd\user\classes\UserClass;
- use common\components\util;
- use Yii;
- use biz\base\classes\BaseClass;
- class ShopAdminClass extends BaseClass
- {
-
- public static $baseFile = '\biz\shop\models\ShopAdmin';
-
- const GENERATE_ADMIN_DATA = 'generate_admin_data_';//创建管理员需要的数据
-
- //添加客户 shish 2021.3.1
- public static function addShopAdmin($data)
- {
- return self::add($data);
- }
-
- //创建管理准备数据key shish 2020.4.17
- public static function getGenerateAdminDataKey($shopId, $adminId)
- {
- return self::GENERATE_ADMIN_DATA . $shopId . '_' . $adminId;
- }
-
- //创建管理员数据准备 shish 2020.4.17
- public static function prepareBindAdmin($data)
- {
- $adminId = $data['adminId'];
- $shopId = $data['shopId'];
- $cacheKey = self::getGenerateAdminDataKey($shopId, $adminId);
- $params = [$cacheKey];
- if (!empty($data)) {
- foreach ($data as $key => $val) {
- if (!is_array($val)) {
- $params[] = $key;
- $params[] = $val;
- }
- }
- }
- Yii::$app->redis->executeCommand('HMSET', $params);
- }
-
- //获取创建管理员需要的信息 shish 2020.4.20
- public static function getBindAdminData($shopId, $adminId)
- {
- $cacheKey = self::getGenerateAdminDataKey($shopId, $adminId);
- $cacheData = Yii::$app->redis->executeCommand('HGETALL', [$cacheKey]);
- $data = [];
- if (!empty($cacheData)) {
- $data = [];
- $list = [];
- $x = 0;
- foreach ($cacheData as $cKey => $cVal) {
- if ($cKey % 2 == 0) {
- $list[$x]['key'] = $cVal;
- } else {
- $list[$x]['value'] = $cVal;
- $x++;
- }
- }
- foreach ($list as $lKey => $lVal) {
- $data[$lVal['key']] = $lVal['value'];
- }
- }
- return $data;
- }
-
- //删除创建管理员需要的信息 shish 2020.4.20
- public static function delBindAdminData($shopId, $adminId)
- {
- $cacheKey = self::getGenerateAdminDataKey($shopId, $adminId);
- $keyNameList = Yii::$app->redis->executeCommand('HKEYS', [$cacheKey]);
- if (!empty($keyNameList)) {
- $data = array_merge([$cacheKey], $keyNameList);
- $cacheData = Yii::$app->redis->executeCommand('HDEL', $data);
- }
- }
-
- //取店长 shish 2021.1.8
- public static function getManager($shopId)
- {
- $relate = self::getByCondition(['shopId' => $shopId]);
- $adminId = isset($relate['adminId']) ? $relate['adminId'] : 0;
- $info = [];
- if (!empty($adminId)) {
- $info = AdminClass::getById($adminId);
- }
- return $info;
- }
-
- public static function valid($adminInfo, $merchantId)
- {
- if (isset($adminInfo['merchantId']) && $adminInfo['merchantId'] == $merchantId) {
- return true;
- }
- util::fail('此员工您没有权限操作');
- }
-
- //切换门店时增加员工关系 shish 2021.3.1
- public static function toggleShopAddRelate($originShopAdmin, $toggleShopId)
- {
- $adminId = $originShopAdmin['adminId'];
- $roleId = $originShopAdmin['roleId'];
- $sjId = $originShopAdmin['merchantId'];
- $has = self::getCount(['shopId' => $toggleShopId, 'adminId' => $adminId, 'delStatus' => 0]);
- if ($has) {
- return $has;
- }
- $data = [
- 'roleId' => $roleId,
- 'adminId' => $adminId,
- 'shopId' => $toggleShopId,
- 'merchantId' => $sjId,
- ];
- return self::addShopAdmin($data);
- }
- }
|