| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196 |
- <?php
- //员工相关
- namespace bizGhs\shop\classes;
- use biz\admin\classes\AdminClass;
- use bizGhs\admin\classes\AdminRoleClass;
- use common\components\dict;
- use common\components\sms;
- use common\components\util;
- use Yii;
- use bizHd\base\classes\BaseClass;
- class ShopAdminClass extends BaseClass
- {
- public static $baseFile = '\bizGhs\shop\models\ShopAdmin';
- 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');
- }
- }
|