Explorar o código

添加员工与员工列表

shish %!s(int64=6) %!d(string=hai) anos
pai
achega
123f8f541b

+ 10 - 4
app/business/controllers/AdminController.php

@@ -19,8 +19,8 @@ class AdminController extends BaseController
 		$auth = AdminService::getAuth();
 		util::success($auth);
 	}
-
-	//员工列表 shish 2019.12.9
+	
+	//员工列表 shish 2019.12.8
 	public function actionList()
 	{
 		$get = Yii::$app->request->get();
@@ -28,10 +28,16 @@ class AdminController extends BaseController
 		$list = AdminService::getAdminList($where);
 		util::success($list);
 	}
-
+	
+	//添加员工 shish 2019.12.8
 	public function actionAdd()
 	{
-	
+		$post = Yii::$app->request->post();
+		$post['merchantId'] = $this->merchantId;
+		$admin = AdminService::addAdmin($post);
+		$id = $admin['id'];
+		$info = AdminService::getDetail($id);
+		util::success($info);
 	}
 
 }

+ 66 - 67
app/business/controllers/BaseController.php

@@ -20,12 +20,12 @@ class BaseController extends PublicController
 	public $isLogin = false;
 	public $withoutLogin = [];//不需要登陆的方法名
 	public $validate = true;
-
+	
 	// Service 模型实例
-    protected $service;
-    // 设置允许与不允许方法 shizq 2019-12-05
-    protected $allowActions = [];
-    protected $notAllowActions = [];
+	protected $service;
+	// 设置允许与不允许方法 shizq 2019-12-05
+	protected $allowActions = [];
+	protected $notAllowActions = [];
 	
 	public function beforeAction($action)
 	{
@@ -35,12 +35,12 @@ class BaseController extends PublicController
 		if (empty($adminId)) {
 			$this->validate = false;
 		}
-
+		
 		//方法开放设置 shizq 2019-12-05
-        if (in_array($action->id, $this->notAllowActions)) {
-            util::fail($action->id . ' not allow');
-        }
-
+		if (in_array($action->id, $this->notAllowActions)) {
+			util::fail($action->id . ' not allow');
+		}
+		
 		//游客可以访问的方法
 		if (in_array($action->id, $this->withoutLogin)) {
 			$this->validate = true;
@@ -52,8 +52,7 @@ class BaseController extends PublicController
 		if (empty($admin)) {
 			util::fail('没有找到管理员');
 		}
-		$merchantId = 12358;
-		//$merchantId = AdminToMerchantService::getDefaultMerchant($adminId);
+		$merchantId = $admin['merchantId'];
 		if (empty($merchantId)) {
 			util::fail('没有找到商家信息');
 		}
@@ -74,59 +73,59 @@ class BaseController extends PublicController
 		$this->merchantAsset = $merchantAsset;
 		return parent::beforeAction($action);
 	}
-
-    public function actionList()
-    {
-        $numargs = func_num_args();
-        $select = $numargs >= 1 ? func_get_arg(0) : '*';
-        $where = $numargs >= 2 ? func_get_arg(1) : null;
-        $order = $numargs >= 3 ? func_get_arg(2) : '';
-        $with = $numargs >= 4 ? func_get_arg(3) : '';
-
-        $service = $this->service;
-        $list = $service::getList($select, $where, $order, $with);
-        util::success($list);
-    }
-
-    public function actionAdd()
-    {
-        $data = Yii::$app->request->post();
-        $service = $this->service;
-        $re = $service::add($data);
-        util::success($re);
-    }
-
-    public function actionDetail()
-    {
-        $id = Yii::$app->request->get('id');
-        $service = $this->service;
-        $data = $service::getById($id);
-        if(!empty($data)){
-            util::success($data);
-        }
-
-        util::fail('');
-    }
-
-    public function actionUpdate()
-    {
-        $data = Yii::$app->request->post();
-        $id = $data['id'];
-        $service = $this->service;
-        $re = $service::updateById($id, $data);
-        if($re['status'] === true){
-            util::success($re);
-        }
-
-        util::fail();
-    }
-
-    public function actionDelete()
-    {
-        $id = Yii::$app->request->get('id');
-        $service = $this->service;
-        $service::deleteById($id);
-        util::success([],'删除成功');
-    }
-
+	
+	public function actionList()
+	{
+		$numargs = func_num_args();
+		$select = $numargs >= 1 ? func_get_arg(0) : '*';
+		$where = $numargs >= 2 ? func_get_arg(1) : null;
+		$order = $numargs >= 3 ? func_get_arg(2) : '';
+		$with = $numargs >= 4 ? func_get_arg(3) : '';
+		
+		$service = $this->service;
+		$list = $service::getList($select, $where, $order, $with);
+		util::success($list);
+	}
+	
+	public function actionAdd()
+	{
+		$data = Yii::$app->request->post();
+		$service = $this->service;
+		$re = $service::add($data);
+		util::success($re);
+	}
+	
+	public function actionDetail()
+	{
+		$id = Yii::$app->request->get('id');
+		$service = $this->service;
+		$data = $service::getById($id);
+		if (!empty($data)) {
+			util::success($data);
+		}
+		
+		util::fail('');
+	}
+	
+	public function actionUpdate()
+	{
+		$data = Yii::$app->request->post();
+		$id = $data['id'];
+		$service = $this->service;
+		$re = $service::updateById($id, $data);
+		if ($re['status'] === true) {
+			util::success($re);
+		}
+		
+		util::fail();
+	}
+	
+	public function actionDelete()
+	{
+		$id = Yii::$app->request->get('id');
+		$service = $this->service;
+		$service::deleteById($id);
+		util::success([], '删除成功');
+	}
+	
 }

+ 66 - 3
biz/admin/classes/AdminClass.php

@@ -3,7 +3,9 @@
 namespace biz\admin\classes;
 
 use biz\admin\services\AdminRoleService;
+use biz\user\classes\UserClass;
 use biz\user\services\UserService;
+use common\components\util;
 use Yii;
 use biz\base\classes\BaseClass;
 
@@ -19,7 +21,7 @@ class AdminClass extends BaseClass
 		//花美灵
 		'wx84d95afcb7b594eb' => ['oTFbYvsjwgVwXggwtlM2ESAKwuN8', 'oTFbYvqP6qwdCCkdFB9GYnlzDIUg'],
 	];
-
+	
 	//组合员工基本信息 shish 2019.12.9
 	public static function groupAdminBaseInfo($list)
 	{
@@ -33,10 +35,71 @@ class AdminClass extends BaseClass
 			$list[$key]['roleName'] = isset($roleInfo[$roleId]['roleName']) ? $roleInfo[$roleId]['roleName'] : '';
 			$userId = $val['userId'];
 			$list[$key]['nickName'] = isset($userInfo[$userId]['userName']) ? $userInfo[$userId]['userName'] : '';
-			$list[$key]['avatarUrl'] = isset($userInfo[$userId]['avatar']) ? $prefix . $userInfo[$userId]['avatar'] : '';
+			$list[$key]['avatarUrl'] = isset($userInfo[$userId]['avatar']) ? $prefix . $userInfo[$userId]['avatar'] : $prefix . '/none.jpg';
 			$list[$key]['mobile'] = isset($userInfo[$userId]['mobile']) ? $prefix . $userInfo[$userId]['mobile'] : '';
+			$list[$key]['addDate'] = date("Y-m-d H:i", $val['addTime']);
+			$list[$key]['lastLoginTime'] = date("Y-m-d H:i", $val['loginTime']);
 		}
 		return $list;
 	}
-
+	
+	//获取员工详情 shish 2019.12.9
+	public static function getDetail($id)
+	{
+		$detail = AdminClass::getById($id);
+		if (empty($detail)) {
+			util::fail('没有找到员工信息');
+		}
+		$list = self::groupAdminBaseInfo([$detail]);
+		return current($list);
+	}
+	
+	//添加员工 shish 2019.12.9
+	public static function addAdmin($data)
+	{
+		$merchantId = $data['merchantId'];
+		
+		//验证角色
+		$roleId = $data['roleId'];
+		$role = AdminRoleClass::getById($roleId);
+		AdminRoleClass::valid($role, $merchantId);
+		
+		//验证关联的微信
+		$userId = $data['userId'];
+		$user = UserClass::getById($userId);
+		UserClass::valid($user, $merchantId);
+		
+		$adminName = $data['adminName'];
+		$adminNameList = self::getAdminNameList($merchantId);
+		if (in_array($adminName, $adminNameList)) {
+			util::fail('名字已被使用');
+		}
+		$relateUserIdList = self::getAdminRelateUserId($merchantId);
+		if (in_array($userId, $relateUserIdList)) {
+			util::fail('您选择的微信已经绑定别的帐号');
+		}
+		$respond = self::add($data);
+		return $respond;
+	}
+	
+	//获取商家的所有员工 shish 2019.12.9
+	public static function getAdminList($merchantId)
+	{
+		return self::getAllByCondition(['merchantId' => $merchantId], null, '*');
+	}
+	
+	//获取员工的名字 shish 2019.12.9
+	public static function getAdminNameList($merchantId)
+	{
+		$list = self::getAdminList($merchantId);
+		return !empty($list) ? array_column($list, 'adminName') : [];
+	}
+	
+	//员工已经关联微信的userId
+	public static function getAdminRelateUserId($merchantId)
+	{
+		$list = self::getAdminList($merchantId);
+		return !empty($list) ? array_column($list, 'userId') : [];
+	}
+	
 }

+ 12 - 0
biz/admin/classes/AdminRoleClass.php

@@ -2,6 +2,7 @@
 
 namespace biz\admin\classes;
 
+use common\components\util;
 use Yii;
 use biz\base\classes\BaseClass;
 
@@ -10,4 +11,15 @@ class AdminRoleClass extends BaseClass
 
 	public static $baseFile = '\biz\admin\models\AdminRole';
 
+	//验证权限 shish 2019.12.9
+	public static function valid($role, $merchantId)
+	{
+		if (empty($role)) {
+			util::fail('角色无效');
+		}
+		if ($role['merchantId'] != $merchantId) {
+			util::fail('没有权限操作');
+		}
+	}
+
 }

+ 7 - 1
biz/admin/services/AdminRoleService.php

@@ -2,6 +2,7 @@
 
 namespace biz\admin\services;
 
+use biz\admin\classes\AdminRoleClass;
 use biz\base\services\BaseService;
 use Yii;
 
@@ -9,5 +10,10 @@ class AdminRoleService extends BaseService
 {
 	
 	public static $baseFile = '\biz\admin\classes\AdminRoleClass';
-
+	
+	public static function valid($role, $merchantId)
+	{
+		return AdminRoleClass::valid($role, $merchantId);
+	}
+	
 }

+ 13 - 1
biz/admin/services/AdminService.php

@@ -90,5 +90,17 @@ class AdminService extends BaseService
 		$data['list'] = AdminClass::groupAdminBaseInfo($list);
 		return $data;
 	}
-	
+
+	//添加员工
+	public static function addAdmin($data)
+	{
+		return AdminClass::addAdmin($data);
+	}
+
+	//获取员工信息 shish 2019.12.8
+	public static function getDetail($id)
+	{
+		return AdminClass::getDetail($id);
+	}
+
 }

+ 12 - 2
biz/user/classes/UserClass.php

@@ -5,6 +5,7 @@ namespace biz\user\classes;
 use biz\merchant\classes\MerchantAssetClass;
 use biz\user\services\UserIntegralService;
 use common\components\configDict;
+use common\components\util;
 use common\services\ImageService;
 use common\services\xhMerchantExtendService;
 use common\services\xhUserCapitalService;
@@ -111,7 +112,7 @@ class UserClass extends BaseClass
 		if (empty($user['userName'])) {
 			self::updateById($userId, ['userName' => $userId]);
 		}
-
+		
 		$assetData = ['userId' => $userId, 'merchantId' => $merchantId, 'createTime' => $date];
 		//生成用户资产信息
 		UserAssetClass::add($assetData);
@@ -394,5 +395,14 @@ class UserClass extends BaseClass
 	{
 		return self::getAllByCondition(['merchantId' => $merchantId, 'unionId' => $unionId], 'addTime desc', '*');
 	}
-	
+
+	public static function valid($info, $merchantId)
+	{
+		if (empty($info)) {
+			util::fail('找不到客户');
+		}
+		if ($info['merchantId'] != $merchantId) {
+			util::fail('这个客户您没有权限操作');
+		}
+	}
 }

+ 6 - 1
biz/user/services/UserService.php

@@ -289,5 +289,10 @@ class UserService extends BaseService
 			util::fail('密码错误');
 		}
 	}
-
+	
+	//验证用户权限
+	public static function valid($info, $merchantId)
+	{
+		return UserClass::valid($info,$merchantId);
+	}
 }