| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183 |
- <?php
- namespace bizGhs\shop\services;
- use bizGhs\admin\classes\AdminClass;
- use bizGhs\admin\classes\AdminRoleClass;
- use bizGhs\shop\classes\ShopAdminClass;
- use bizHd\base\services\BaseService;
- use bizGhs\merchant\classes\ShopClass;
- use common\components\dict;
- use common\components\imgUtil;
- use common\components\miniUtil;
- use common\components\sms;
- use common\components\util;
- use Yii;
- class ShopAdminService extends BaseService
- {
- public static $baseFile = '\bizGhs\shop\classes\ShopAdminClass';
- //创建管理员生成小程序 ssh 2020.4.17
- public static function prepareBindAdmin($data)
- {
- $merchant = $data['merchant'];
- unset($data['merchant']);
- ShopAdminClass::prepareBindAdmin($data);
- $page = 'admin/shopAdmin/bind';
- $isOpen = 2;
- $adminId = $data['adminId'];
- $shopId = $data['shopId'];
- $scene = 'adminId=' . $adminId . '&shopId=' . $shopId;
- $imgUrl = miniUtil::generateUnlimitedMiniCode($merchant, $page, $scene, $isOpen);
- return ['miniCode' => $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;
- }
- }
|