| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168 |
- <?php
- namespace bizHd\admin\services;
- use bizHd\admin\classes\AdminClass;
- use bizHd\admin\classes\AdminRoleClass;
- use bizHd\admin\classes\ShopAdminClass;
- use bizHd\auth\services\AuthService;
- use bizHd\base\services\BaseService;
- use bizHd\merchant\classes\ShopClass;
- use biz\sj\services\MerchantService;
- use bizHd\user\services\UserService;
- use common\components\error;
- use common\components\imgUtil;
- use common\components\miniUtil;
- use common\components\stringUtil;
- use common\components\util;
- use common\components\wxUtil;
- use common\services\xhTMessageService;
- use Yii;
- class ShopAdminService extends BaseService
- {
- public static $baseFile = '\bizHd\admin\classes\ShopAdminClass';
- ///创建管理员生成小程序 ssh 2020.4.17
- public static function prepareBindAdmin($data)
- {
- ShopAdminClass::prepareBindAdmin($data);
- $page = 'admin/shopAdmin/bind';
- $isOpen = 1;
- $adminId = $data['adminId'];
- $shopId = $data['shopId'];
- $scene = 'adminId=' . $adminId . '&shopId=' . $shopId;
- $merchant = $data['merchant'];
- $imgUrl = miniUtil::generateUnlimitedMiniCode($merchant, $page, $scene, $isOpen);
- return ['miniCode' => $imgUrl];
- }
- public static function generateAdmin($data, $admin)
- {
- $recommendAdminId = isset($data['recommendAdminId']) ? $data['recommendAdminId'] : 0;
- $mobile = isset($data['mobile']) ? $data['mobile'] : '';
- $shopId = isset($data['shopId']) ? $data['shopId'] : 0;
- $adminId = isset($data['adminId']) ? $data['adminId'] : 0;
- $name = $data['name'] ?? '未命名';
- $mainId = $data['mainId'] ?? 0;
- $bindData = ShopAdminClass::getBindAdminData($shopId, $recommendAdminId);
- if (empty($bindData)) {
- util::fail('小程序码已失效,请重新创建员工');
- }
- $avatar = $admin['avatar'] ?? '';
- $password = isset($bindData['password']) ? password_hash($bindData['password'], PASSWORD_BCRYPT) : '';
- $remark = isset($bindData['remark']) ? $bindData['remark'] : '';
- $remind = isset($bindData['remind']) ? $bindData['remind'] : 0;
- $status = 1;
- $roleId = $bindData['roleId'] ?? 0;
- $role = AdminRoleClass::getById($roleId);
- if (empty($role)) {
- util::fail('没有找到角色。');
- }
- $shop = ShopClass::getById($shopId);
- if (empty($shop)) {
- util::fail('没有找到门店52');
- }
- $sjId = $shop['sjId'] ?? 0;
- $shopAdmin = ShopAdminClass::getByCondition(['adminId' => $adminId, 'mainId' => $mainId], true);
- if (!empty($shopAdmin)) {
- //删除员工补回
- if ($shopAdmin->delStatus == 1) {
- $shopAdmin->delStatus = 0;
- $shopAdmin->roleId = $roleId;
- $shopAdmin->remind = $remind;
- $shopAdmin->status = $status;
- $shopAdmin->avatar = $avatar;
- $shopAdmin->remark = $remark;
- $shopAdmin->name = $name;
- $shopAdmin->save();
- $update = ['currentShopId' => $shopId];
- if (!empty($password)) {
- $update['password'] = $password;
- }
- AdminClass::updateById($adminId, $update);
- AdminRoleClass::counters(['num' => 1], ['id' => $roleId]);
- return $shopAdmin->attributes;
- }
- util::fail('您已经是员工');
- } else {
- if (isset($bindData['roleId']) == false || empty($bindData['roleId'])) {
- util::fail('选择角色');
- }
- $addData = [
- 'adminId' => $adminId,
- 'shopId' => $shopId,
- 'roleId' => $roleId,
- 'remind' => $remind,
- 'status' => $status,
- 'sjId' => $sjId,
- 'mainId' => $mainId,
- 'name' => $name,
- 'mobile' => $mobile,
- 'avatar' => $avatar,
- 'remark' => $remark,
- ];
- ShopAdminClass::delBindAdminData($shopId, $recommendAdminId);
- $result = ShopAdminClass::add($addData);
- $update = ['currentShopId' => $shopId];
- if (!empty($password)) {
- $update['password'] = $password;
- }
- AdminClass::updateById($adminId, $update);
- 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');
- foreach ($list as $key => $val) {
- $list[$key]['avatar'] = imgUtil::groupImg($val['avatar']);
- $roleId = $val['roleId'];
- $roleName = isset($roleList[$roleId]['roleName']) ? $roleList[$roleId]['roleName'] : '';
- $list[$key]['roleName'] = $roleName;
- }
- $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, $mainId)
- {
- if (isset($shopAdmin['mainId']) == false || $shopAdmin['mainId'] != $mainId) {
- util::fail('不是您的员工');
- }
- }
- }
|