$adminId], null, '*', null, true); $hasMainList = []; $mayList = []; if (!empty($staffList)) { foreach ($staffList as $staff) { $mayList[] = $staff->mainId; if ($staff->super == 1) { $hasMainList[] = $staff->mainId; } } } $sameList = ProductClass::getAllByCondition(['itemId' => $ptItemId], null, 'id,itemId,mainId'); $sameMainList = array_column($sameList, 'mainId'); $hasNot = array_diff($sameMainList, $hasMainList); $hasRightChange = empty($hasNot) ? 1 : 0; $mayHasNot = array_diff($sameMainList, $mayList); $reason = '别的批发店也在用此花材,不能修改'; if (empty($mayHasNot)) { $reason = '你在某个店没有改库存改价,不能修改'; } return ['hasRightChange' => $hasRightChange, 'reason' => $reason]; } const GENERATE_ADMIN_DATA = 'generate_ghs_admin_data_';//创建管理员需要的数据 //查看财务权限 ssh 20230620 public static function lookMoneyPower($staff, $shop) { $lookMoney = 0; if (isset($staff->finance) && $staff->finance == 1) { $lookMoney = 1; } $ptAdminId = AdminClass::getPtSuperAdminId(); if (isset($staff->adminId) && $staff->adminId == $ptAdminId) { $lookMoney = 1; } return $lookMoney; } //创建员工 ssh 2021.5.9 public static function appGenerateStaff($data, $admin) { $mobile = $data['mobile'] ?? ''; $shopId = $data['shopId'] ?? 0; $name = $data['name'] ?? '未命名'; $remark = isset($data['remark']) ? $data['remark'] : ''; $status = 1; $super = $data['super'] ?? 0; $remind = isset($data['remind']) ? $data['remind'] : 0; $roleId = $data['roleId'] ?? 0; $finance = $data['finance'] ?? 0; $switchShop = $data['switchShop'] ?? 0; $role = AdminRoleClass::getById($roleId); if (empty($role)) { util::fail('没有找到角色哦'); } $shop = ShopClass::getById($shopId); if (empty($shop)) { util::fail('没有找到门店25'); } $avatar = $admin['avatar'] ?? ''; $adminId = $admin['id'] ?? 0; $mainId = $shop['mainId'] ?? 0; $shopAdmin = self::getByCondition(['mainId' => $mainId, 'adminId' => $adminId], true); if (!empty($shopAdmin)) { //已删除员工补回 if (isset($shopAdmin->delStatus) && $shopAdmin->delStatus == 1) { $shopAdmin->delStatus = 0; $shopAdmin->roleId = $roleId; $shopAdmin->remind = $remind; $shopAdmin->finance = $finance; $shopAdmin->switchShop = $switchShop; $shopAdmin->status = $status; $shopAdmin->remark = $remark; $shopAdmin->name = $name; $shopAdmin->avatar = $avatar; $shopAdmin->super = $super; $shopAdmin->save(); //AdminRoleClass::counters(['num' => 1], ['id' => $roleId]); } } else { $addData = [ 'adminId' => $adminId, 'roleId' => $roleId, 'remind' => $remind, 'finance' => $finance, 'switchShop' => $switchShop, 'status' => $status, 'name' => $name, 'mobile' => $mobile, 'avatar' => $avatar, 'super' => $super, 'mainId' => $mainId ]; $shopAdmin = ShopAdminClass::add($addData, true); //AdminRoleClass::counters(['num' => 1], ['id' => $roleId]); } $lsShopId = $shop['lsShopId'] ?? 0; $update = ['currentGhsShopId' => $shopId, 'currentShopId' => $lsShopId]; AdminClass::updateById($adminId, $update); return $shopAdmin; } //创建管理准备数据key ssh 2020.4.17 public static function getGenerateAdminDataKey($mainId, $adminId) { return self::GENERATE_ADMIN_DATA . $mainId . '_' . $adminId; } //创建管理员数据准备 ssh 2020.4.17 public static function prepareBindAdmin($data) { $adminId = $data['adminId']; $mainId = $data['mainId']; $cacheKey = self::getGenerateAdminDataKey($mainId, $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); } //获取创建管理员需要的信息 ssh 2020.4.20 public static function getBindAdminData($mainId, $adminId) { $cacheKey = self::getGenerateAdminDataKey($mainId, $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; } //删除创建管理员需要的信息 ssh 2020.4.20 public static function delBindAdminData($mainId, $adminId) { $cacheKey = self::getGenerateAdminDataKey($mainId, $adminId); $keyNameList = Yii::$app->redis->executeCommand('HKEYS', [$cacheKey]); if (!empty($keyNameList)) { $data = array_merge([$cacheKey], $keyNameList); Yii::$app->redis->executeCommand('HDEL', $data); } } //权限判断 ssh 2021.1.13 public static function valid($admin, $mainId) { if (isset($admin['mainId']) && $admin['mainId'] == $mainId) { return true; } util::fail('您无法操作'); } //获取详情 ssh 2021.3.27 public static function getInfo($id) { return self::getById($id); } //获取基本信息 ssh 2021.4.23 public static function getAdminInfo($id) { $relation = self::getById($id); if (empty($relation)) { util::fail('没有找到员工信息'); } return $relation; } //通过shopId 获取相应的需要通知的 shopAdminIds (status=1 and delStatus=0 and remind=1) public static function getRemindAdminIdsByShopId($shopId) { $where = [ 'shopId' => $shopId, 'status' => 1, 'delStatus' => 0, 'remind' => 1 ]; $data = self::getAllByCondition($where, null, "id"); return array_column($data, 'id'); } }