$imgUrl]; } //创建员工 ssh 2021.5.9 public static function generateAdmin($data, $admin) { $recommendAdminId = $data['recommendAdminId'] ?? 0; $mobile = $data['mobile'] ?? ''; $adminId = $data['adminId'] ?? 0; $shopId = $data['shopId'] ?? 0; $name = $data['name'] ?? '未命名'; if (isset($admin['subscribe']) == false || $admin['subscribe'] != 1) { //util::fail("请关注公众号"); } $avatar = $admin['avatar'] ?? ''; $bindData = ShopAdminClass::getBindAdminData($shopId, $recommendAdminId); if (empty($bindData)) { util::fail('小程序码已失效,请重新创建'); } $password = isset($bindData['password']) ? password_hash($bindData['password'], PASSWORD_BCRYPT) : ''; $remark = isset($bindData['remark']) ? $bindData['remark'] : ''; $status = 1; $remind = isset($bindData['remind']) ? $bindData['remind'] : 0; $roleId = $bindData['roleId'] ?? 0; $role = AdminRoleClass::getById($roleId); if (empty($role)) { util::fail('没有找到角色!!'); } $shop = ShopClass::getById($shopId); if (empty($shop)) { util::fail('没有找到门店72'); } $sjId = $shop['sjId'] ?? 0; $shopAdmin = ShopAdminClass::getByCondition(['shopId' => $shopId, 'adminId' => $adminId], true); if (!empty($shopAdmin)) { //员工已经删除的补回 if (isset($shopAdmin->delStatus) && $shopAdmin->delStatus == 1) { $shopAdmin->delStatus = 0; $shopAdmin->roleId = $roleId; $shopAdmin->remind = $remind; $shopAdmin->status = $status; $shopAdmin->remark = $remark; $shopAdmin->name = $name; $shopAdmin->avatar = $avatar; $shopAdmin->save(); $update = [ 'currentShopId' => $shopId ]; if (!empty($password)) { $update['password'] = $password; } AdminClass::updateById($adminId, $update); // 员工数+1 AdminRoleClass::counters(['num' => 1], ['id' => $roleId]); return $shopAdmin->attributes; } util::fail('您已经是员工'); } $update = [ 'currentShopId' => $shopId ]; if (!empty($password)) { $update['password'] = $password; } AdminClass::updateById($adminId, $update); $addData = [ 'adminId' => $adminId, 'shopId' => $shopId, 'roleId' => $roleId, 'remind' => $remind, 'status' => $status, 'sjId' => $sjId, 'name' => $name, 'mobile' => $mobile, 'avatar' => $avatar, ]; ShopAdminClass::delBindAdminData($shopId, $recommendAdminId); $result = ShopAdminClass::add($addData); // 员工数+1 AdminRoleClass::counters(['num' => 1], ['id' => $roleId]); return $result; } //获取管理员 ssh 2020.4.21 public static function getAdminList($where) { $data = ShopAdminClass::getList('*', $where, 'addTime DESC'); $list = isset($data['list']) && !empty($data['list']) ? $data['list'] : []; if (empty($list)) { return $data; } $roleIds = array_column($list, 'roleId'); $roleIds = array_filter(array_unique($roleIds)); $roleList = AdminRoleClass::getByIds($roleIds, null, 'id'); $prefix = imgUtil::getPrefix(); foreach ($list as $key => $val) { $roleId = $val['roleId']; $roleName = isset($roleList[$roleId]['roleName']) ? $roleList[$roleId]['roleName'] : ''; $list[$key]['roleName'] = $roleName; $avatar = $prefix . 'hhb_small.png'; if (isset($val['avatar']) && !empty($val['avatar'])) { $avatar = $prefix . $val['avatar']; } $list[$key]['avatar'] = $avatar; } $data['list'] = $list; return $data; } //获取要通知的管理员 ssh 2020.4.28 public static function getNoticeAdminList($shopId) { $where = ['shopId' => $shopId]; $respond = self::getAdminList($where); $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取员工信息,包括基本信息和角色 ssh 2021.1.13 public static function getAdminInfo($id) { $relation = ShopAdminClass::getById($id); if (empty($relation)) { util::fail('没有找到员工信息'); } return $relation; } }