|
|
@@ -120,26 +120,81 @@ class StaffClass extends BaseClass
|
|
|
* @param Admin $admin 管理员模型
|
|
|
* @param Staff $staff 员工模型
|
|
|
*/
|
|
|
- public function executeStaffResignation($admin, $staff)
|
|
|
+ public static function executeStaffResignation($admin, $staff)
|
|
|
{
|
|
|
// 标记员工为已删除
|
|
|
$staff->delStatus = 1;
|
|
|
$staff->save();
|
|
|
|
|
|
+ $mobile = $admin->mobile;
|
|
|
+
|
|
|
// 检查管理员是否有自己的门店
|
|
|
- $shops = ShopClass::getAllByCondition(['adminId' => $admin->id], null, 'id', 'id');
|
|
|
- if (empty($shops)) {
|
|
|
- // 情况1:自己没有店,在别人那边当员工
|
|
|
+ $shopList = ShopClass::getAllByCondition(['mobile' => $mobile], null, '*', null, true);
|
|
|
+ if (empty($shopList)) {
|
|
|
+ // 情况1:自己没有店,在别人那边当员工,直接退出
|
|
|
$admin->currentShopId = 0;
|
|
|
+ $admin->save();
|
|
|
} else {
|
|
|
- // 情况2:自己有店,也在其他店当员工
|
|
|
- $ptStyle = dict::getDict('ptStyle', 'hd');
|
|
|
- $shop = ShopClass::getByCondition(['adminId' => $admin->id, 'ptStyle' => $ptStyle], 'id');
|
|
|
- if (empty($shop)) {
|
|
|
- util::fail('没有找到有效的门店信息');
|
|
|
+ // 情况2:自己有店,自己可能开批零店,也可能只开零售店,也在其他店当员工
|
|
|
+ $hdMainId = 0;
|
|
|
+ $ghsMainId = 0;
|
|
|
+ if (count($shopList) == 1) {
|
|
|
+ foreach ($shopList as $shop) {
|
|
|
+ if ($shop->ptStyle == 1) {
|
|
|
+ $admin->currentShopId = $shop->id;
|
|
|
+ $admin->save();
|
|
|
+ } else {
|
|
|
+ util::fail('账号异常,请联系管理员,编号266389');
|
|
|
+ }
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ foreach ($shopList as $shop) {
|
|
|
+ if ($shop->ptStyle == 2) {
|
|
|
+ $ghsMainId = $shop->mainId;
|
|
|
+ $admin->currentGhsShopId = $shop->id;
|
|
|
+ }
|
|
|
+ if ($shop->ptStyle == 1) {
|
|
|
+ $hdMainId = $shop->mainId;
|
|
|
+ $admin->currentShopId = $shop->id;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if ($ghsMainId != $hdMainId) {
|
|
|
+ util::fail('账号异常,请联系管理,编号0068');
|
|
|
+ }
|
|
|
+ if ($ghsMainId == 0) {
|
|
|
+ util::fail('账号异常,请联系管理,编号006835');
|
|
|
+ }
|
|
|
+ }
|
|
|
+ $adminId = $admin->id;
|
|
|
+ $staffList = StaffClass::getAllByCondition(['mainId' => $hdMainId, 'adminId' => $adminId], null, '*', null, true);
|
|
|
+ if (empty($staffList)) {
|
|
|
+ $role = AdminRoleClass::getByCondition(['mainId' => $hdMainId], true);
|
|
|
+ $roleId = $role->id;
|
|
|
+ $avatar = $admin->avatar;
|
|
|
+ $name = $admin->name;
|
|
|
+ $staffData = [
|
|
|
+ 'adminId' => $adminId,
|
|
|
+ 'mainId' => $hdMainId,
|
|
|
+ 'remind' => 0,
|
|
|
+ 'roleId' => $roleId,
|
|
|
+ 'avatar' => $avatar,
|
|
|
+ 'name' => $name,
|
|
|
+ 'super' => 1,
|
|
|
+ 'finance' => 0,
|
|
|
+ 'switchShop' => 0,
|
|
|
+ 'founder' => 1,
|
|
|
+ 'mobile' => $mobile,
|
|
|
+ ];
|
|
|
+ self::add($staffData);
|
|
|
+ } else {
|
|
|
+ foreach ($staffList as $myStaff) {
|
|
|
+ $myStaff->delStatus = 0;
|
|
|
+ $myStaff->save();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (count($staffList) > 1) {
|
|
|
+ util::fail('账号异常,请联系管理员56988');
|
|
|
}
|
|
|
- $admin->currentShopId = $shop['id'];
|
|
|
}
|
|
|
- $admin->save();
|
|
|
}
|
|
|
}
|