| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143 |
- <?php
- namespace bizMall\admin\services;
- use bizMall\admin\classes\AdminClass;
- use bizMall\admin\classes\AdminRoleClass;
- use bizMall\admin\classes\ShopAdminClass;
- use bizMall\auth\services\AuthService;
- use bizMall\base\services\BaseService;
- use bizMall\merchant\classes\ShopClass;
- use bizMall\merchant\services\MerchantService;
- use bizMall\user\services\UserService;
- use common\components\error;
- 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 = '\bizMall\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)
- {
- $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;
- $bindData = ShopAdminClass::getBindAdminData($shopId, $recommendAdminId);
- $shop = ShopClass::getById($shopId);
- if (empty($shop)) {
- util::fail('没有找到门店83');
- }
- $sjId = isset($shop['sjId']) ? $shop['sjId'] : 0;
- if (empty($bindData)) {
- util::fail('小程序码已经失效,请重新创建员工');
- }
- $shopAdmin = ShopAdminClass::getByCondition(['adminId' => $adminId, 'shopId' => $shopId]);
- if (!empty($shopAdmin)) {
- util::fail('您已经是管理员了');
- }
- $name = isset($bindData['name']) ? $bindData['name'] : '';
- if (isset($bindData['roleId']) == false || empty($bindData['roleId'])) {
- util::fail('添加管理员时请选择角色');
- }
- $admin = AdminClass::getById($adminId);
- if (empty($admin)) {
- util::fail('没有找到管理员信息');
- }
- if (isset($admin['subscribe']) == false || $admin['subscribe'] != 1) {
- //util::fail("请关注公众号({$admin['id']})");
- }
- $roleId = $bindData['roleId'];
- $remind = isset($bindData['remind']) ? $bindData['remind'] : 0;
- $status = isset($bindData['status']) ? $bindData['status'] : 0;
- $password = isset($bindData['password']) ? password_hash($bindData['password'], PASSWORD_BCRYPT) : '';
- $remark = isset($bindData['remark']) ? $bindData['remark'] : '';
- $update = ['name' => $name, 'mobile' => $mobile, 'password' => $password, 'remark' => $remark];
- AdminClass::updateById($adminId, $update);
- $addData = [
- 'adminId' => $adminId,
- 'shopId' => $shopId,
- 'roleId' => $roleId,
- 'remind' => $remind,
- 'status' => $status,
- 'sjId' => $sjId,
- 'name' => $name,
- ];
- ShopAdminClass::delBindAdminData($shopId, $recommendAdminId);
- return ShopAdminClass::add($addData);
- }
- //获取管理员 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;
- }
- //管理员基础信息
- $ids = array_column($list, 'adminId');
- $adminInfo = AdminClass::getByIds($ids, null, 'id');
- $adminBaseInfo = AdminClass::groupAdminBaseInfo($adminInfo);
- $roleIds = array_column($list, 'roleId');
- $roleIds = array_filter(array_unique($roleIds));
- $roleList = AdminRoleClass::getByIds($roleIds, null, 'id');
- foreach ($list as $key => $val) {
- $adminId = $val['adminId'];
- $current = isset($adminBaseInfo[$adminId]) ? $adminBaseInfo[$adminId] : [];
- $list[$key]['adminBaseInfo'] = $current;
- $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, $shopId)
- {
- if (isset($shopAdmin['shopId']) == false || $shopAdmin['shopId'] != $shopId) {
- util::fail('不是您的员工');
- }
- }
- }
|