| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242 |
- <?php
- namespace biz\shop\classes;
- use biz\admin\classes\AdminClass;
- use biz\admin\classes\AdminRoleClass;
- use bizGhs\ws\services\WsService;
- use bizHd\staff\classes\StaffClass;
- use bizHd\user\classes\UserClass;
- use common\components\util;
- use Yii;
- use biz\base\classes\BaseClass;
- class ShopAdminClass extends BaseClass
- {
- public static $baseFile = '\biz\shop\models\ShopAdmin';
- const GENERATE_ADMIN_DATA = 'generate_admin_data_';//创建管理员需要的数据
- //添加客户 ssh 2021.3.1
- public static function addShopAdmin($data, $returnObj = false)
- {
- return self::add($data, $returnObj);
- }
- //创建管理准备数据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);
- $cacheData = Yii::$app->redis->executeCommand('HDEL', $data);
- }
- }
- //取店长信息 ssh 2021.1.8
- public static function getManager($mainId)
- {
- $relate = self::getByCondition(['mainId' => $mainId, 'founder' => 2]);
- $adminId = isset($relate['adminId']) ? $relate['adminId'] : 0;
- $info = [];
- if (!empty($adminId)) {
- $info = AdminClass::getById($adminId);
- }
- return $info;
- }
- public static function valid($adminInfo, $mainId)
- {
- if (isset($adminInfo['mainId']) && $adminInfo['mainId'] == $mainId) {
- return true;
- }
- util::fail('此员工您无法操作');
- }
- //切换门店时增加员工关系 ssh 2021.3.1
- public static function changeShopAddRelate($originShopAdmin, $newShop, $isPt = 0)
- {
- $newMainId = $newShop->mainId ?? 0;
- $name = $originShopAdmin->name ?? '';
- $mobile = $originShopAdmin->mobile ?? 0;
- $avatar = $originShopAdmin->avatar ?? '';
- $adminId = $originShopAdmin->adminId ?? 0;
- $roleId = $originShopAdmin->roleId ?? 0;
- $sjId = $originShopAdmin->sjId ?? 0;
- $super = $originShopAdmin->super ?? 0;
- $has = self::getByCondition(['mainId' => $newMainId, 'adminId' => $adminId], true);
- if (!empty($has)) {
- $has->delStatus = 0;
- $has->save();
- return $has;
- }
- $data = [
- 'name' => $name,
- 'mobile' => $mobile,
- 'avatar' => $avatar,
- 'roleId' => $roleId,
- 'adminId' => $adminId,
- 'sjId' => $sjId,
- 'super' => $super,
- 'mainId' => $newMainId,
- 'isPt' => $isPt,
- ];
- $return = self::addShopAdmin($data, true);
- return $return;
- }
- //员工收款通知 ssh 2021.4.19
- public static function incomeNotice($shopId, $money, $payWay = 0)
- {
- $list = self::getAllByCondition(['shopId' => $shopId, 'delStatus' => 0, 'status' => 1], null, '*');
- if (empty($list)) {
- return false;
- }
- foreach ($list as $key => $val) {
- if ($val['remind'] == 1) {
- $id = $val['id'];
- Yii::info("income notice shopAdminId:{$id} " . $money);
- WsService::arrivalNotice($id, $money, $payWay);
- }
- }
- }
- //获取基本信息 ssh 2021.4.23
- public static function getAdminInfo($id)
- {
- $relation = self::getById($id);
- if (empty($relation)) {
- util::fail('没有找到员工信息');
- }
- return $relation;
- }
- //是否有切换门店权限 0不是 1是
- public static function hasSwitchShopRight($shopAdmin)
- {
- $hasRight = 0;
- if ($shopAdmin->switchShop == 1) {
- $hasRight = 1;
- }
- $ptAdminId = AdminClass::getPtSuperAdminId();
- if ($shopAdmin->adminId == $ptAdminId) {
- $hasRight = 1;
- }
- return $hasRight;
- }
- //删除员工 ssh 2021.5.3
- public static function deleteShopAdmin($relation, $thisShopAdminId, $mainId)
- {
- $id = $relation->id ?? 0;
- if ($relation->founder == 2) {
- util::fail("不能删老板");
- }
- if ($id == $thisShopAdminId) {
- util::fail("不能删自己");
- }
- ShopAdminClass::valid($relation, $mainId);
- $adminId = $relation->adminId ?? 0;
- $admin = AdminClass::getById($adminId, true);
- if (empty($admin)) {
- util::fail('没有找到员工信息');
- }
- //员工离职,多处使用,关键词 staff_lz
- StaffClass::executeStaffResignation($admin, $relation);
- }
- //根据shopId 获取 员工的shopAdminId
- //通过shopId 获取相应的需要通知的 shopAdminIds (status=1 and delStatus=0 and remind=1)
- public static function getRemindShopAdminIdsByShopId($shopId)
- {
- $where = [
- 'shopId' => $shopId,
- 'status' => 1,
- 'delStatus' => 0,
- 'remind' => 1
- ];
- $data = self::getAllByCondition($where, null, "id");
- return array_column($data, 'id');
- }
- //通过shopId 获取相应的需要通知的 adminIds (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, "adminId");
- return array_column($data, 'adminId');
- }
- //获取需要通知的员工 ssh 20220822
- public static function getRemainAdmin($shop)
- {
- $mainId = $shop->mainId ?? 0;
- $where = ['mainId' => $mainId, 'status' => 1, 'delStatus' => 0, 'remind' => 1];
- $shopAdmin = self::getAllByCondition($where, null, 'id,adminId');
- if (empty($shopAdmin)) {
- return [];
- }
- $ids = array_column($shopAdmin, 'adminId');
- $admin = AdminClass::getByIds($ids);
- return $admin;
- }
- }
|