|
@@ -21,7 +21,7 @@ class WxEmployeeService extends Service
|
|
|
{
|
|
|
|
|
|
public function setUser($data){
|
|
|
-
|
|
|
+ if(empty($data['code'])) return [false, '用户登录凭证(code)不能为空'];
|
|
|
$code = $data['code'];
|
|
|
$service = new WxService();
|
|
|
list($status,$openid) = $service->getOpenid($code);
|
|
@@ -41,11 +41,13 @@ class WxEmployeeService extends Service
|
|
|
if(empty($user->mobile) || empty($user->employee_id)) $state = 0;
|
|
|
}
|
|
|
|
|
|
- return [true,['openid'=>$openid,'state'=>$state ]];
|
|
|
+ return [true,['openid'=>$openid,'state'=> $state ]];
|
|
|
}
|
|
|
|
|
|
|
|
|
public function setMobile($data){
|
|
|
+ if(empty($data['code'])) return [false, '用户登录凭证(code)不能为空'];
|
|
|
+ if(empty($data['openid'])) return [false, 'openID不能为空'];
|
|
|
$code = $data['code'];
|
|
|
$openid = $data['openid'];
|
|
|
$service = new WxService();
|
|
@@ -62,6 +64,9 @@ class WxEmployeeService extends Service
|
|
|
}
|
|
|
|
|
|
public function login($data){
|
|
|
+ if(empty($data['account'])) return [false, '账号不能为空'];
|
|
|
+ if(empty($data['password'])) return [false, '密码不能为空'];
|
|
|
+ if(empty($data['openid'])) return [false, 'openID不能为空'];
|
|
|
$account = $data['account'];
|
|
|
$password = $data['password'];
|
|
|
$openid = $data['openid'];
|
|
@@ -74,7 +79,7 @@ class WxEmployeeService extends Service
|
|
|
if(!$status) return [false,$data];
|
|
|
$user_id = $data['id'];
|
|
|
$user = WxEmployee::where('openid',$openid)->first();
|
|
|
- if(empty($user)||empty($user->mobile)) return [false,'请先登陆'];
|
|
|
+ if(empty($user)||empty($user->mobile)) return [false,'请先登陆'];
|
|
|
|
|
|
$user->employee_id = $user_id;
|
|
|
$user->save();
|
|
@@ -100,46 +105,8 @@ class WxEmployeeService extends Service
|
|
|
$res = reset($res);
|
|
|
if(! Hash::check($data['password'], $res['password'])) return [false,'密码错误!'];
|
|
|
if($res['state'] == Employee::NOT_USE) return [false,'账号停用!'];
|
|
|
- list($status,$construction) = $this->isConstruction($res['id']);
|
|
|
- if(! $status) return [false,'账号授权的门店不存在或者过期!'];
|
|
|
-
|
|
|
- return [true, ['id'=>$res['id'], 'name'=>$res['emp_name'], 'account' => $res['account'],'construction' => $construction ?? []]];
|
|
|
- }
|
|
|
-
|
|
|
- //是否施工技师
|
|
|
- public function isConstruction($emp_id){
|
|
|
- if(empty($emp_id)) return [false,''];
|
|
|
-
|
|
|
- //管理员
|
|
|
- if(Employee::SPECIAL_ADMIN == $emp_id){
|
|
|
- $foursShop = FoursShop::where('del_time',0)
|
|
|
- ->select('id')
|
|
|
- ->get()->toArray();
|
|
|
- return [true, array_column($foursShop,'id')];
|
|
|
- }
|
|
|
-
|
|
|
- $result = EmployeeFoursShop::where('employee_id', $emp_id)
|
|
|
- ->select('four_shop_id','use','expires_time')
|
|
|
- ->where('del_time',0)
|
|
|
- ->get()->toArray();
|
|
|
-
|
|
|
- $return = [];
|
|
|
- if(! empty($result)){
|
|
|
- date_default_timezone_set("PRC");
|
|
|
- $now = date("Y-m-d");
|
|
|
- foreach ($result as $value){
|
|
|
- if($value['use']){
|
|
|
- if(($value['expires_time'] == 0) || ($value['expires_time'] > 0 && ($now <= date("Y-m-d",$value['expires_time'])))){
|
|
|
- $return[] = $value['four_shop_id'];
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- if(empty($return)) return [false,''];
|
|
|
-
|
|
|
- return [true,$return];
|
|
|
- }
|
|
|
|
|
|
- return [false,''];
|
|
|
+ return [true, ['id'=>$res['id'], 'name'=>$res['emp_name'], 'account' => $res['account']]];
|
|
|
}
|
|
|
|
|
|
public function checkWxUser($userId){
|
|
@@ -148,140 +115,6 @@ class WxEmployeeService extends Service
|
|
|
->where('state',Employee::USE)->get()->first();
|
|
|
if(empty($res)) return [false, '该账号无法登录,请联系管理员!'];
|
|
|
|
|
|
- list($status,$msg) = $this->isConstruction($userId);
|
|
|
- if(! $status) return [false,'账号授权的门店不存在或者过期!'];
|
|
|
-
|
|
|
return [true, $res];
|
|
|
}
|
|
|
-
|
|
|
- public function createTemporaryJs($data,$user){
|
|
|
- list($status,$msg) = $this->createTemporaryJsRule($data,$user);
|
|
|
- if(! $status) return [false,$msg];
|
|
|
-
|
|
|
- try {
|
|
|
- DB::beginTransaction();
|
|
|
-
|
|
|
- $emp = Employee::where('del_time',0)
|
|
|
- ->where('mobile',$data['mobile'])
|
|
|
- ->first();
|
|
|
- if(! empty($emp)){
|
|
|
- Employee::where('id',$emp->id)
|
|
|
- ->update(['state' => Employee::STATUS_ONE]);
|
|
|
- $employee_id = $emp->id;
|
|
|
- }else{
|
|
|
- $model = new Employee();
|
|
|
- $model->emp_name = '外包技师:' . $data['mobile'];
|
|
|
- $model->state = Employee::STATUS_ONE;
|
|
|
- $model->is_wb = 1;
|
|
|
- $model->crt_id = $user['id'];
|
|
|
- $model->mobile = $data['mobile'];
|
|
|
- $model->password = Hash::make(Employee::DEFAULT_PASS);
|
|
|
- $model->entry_time = date("Y-m-d");
|
|
|
- $model->save();
|
|
|
- $employee_id = $model->id;
|
|
|
-
|
|
|
- $permisson_model = new EmployeeDepartPermission();
|
|
|
- $permisson_model->employee_id = $employee_id;
|
|
|
- $permisson_model->depart_id = 72;
|
|
|
- $permisson_model->save();
|
|
|
- }
|
|
|
-
|
|
|
- EmployeeFoursShop::where('employee_id',$employee_id)->update(['del_time' => time()]);
|
|
|
- $insert = [];
|
|
|
- foreach ($data['four_shop'] as $value){
|
|
|
- $insert[] = [
|
|
|
- "employee_id" => $employee_id,
|
|
|
- "four_shop_id" => $value['four_shop_id'],
|
|
|
- "use" => 1,
|
|
|
- 'expires_time' => $value['expires_time'],
|
|
|
- 'crt_time' => time(),
|
|
|
- 'upd_time' => time(),
|
|
|
- ];
|
|
|
- }
|
|
|
- EmployeeFoursShop::insert($insert);
|
|
|
-
|
|
|
- DB::commit();
|
|
|
- }catch (\Exception $e){
|
|
|
- DB::rollBack();
|
|
|
- return [false,$e->getMessage()];
|
|
|
- }
|
|
|
-
|
|
|
- return [true, ['account' => $data['mobile'], 'password' => Employee::DEFAULT_PASS]];
|
|
|
- }
|
|
|
-
|
|
|
- public function createTemporaryJsRule($data,$user){
|
|
|
- $key = TemporaryJs::LimitationSign . $user['id'];
|
|
|
- list($status,$msg) = $this->limitingSendRequestBackg($key,10);
|
|
|
- if(! $status) return [false,$msg];
|
|
|
-
|
|
|
- if(empty($data['mobile'])) return [false, '外包技师手机号不能为空'];
|
|
|
- $bool = Employee::where('del_time',0)
|
|
|
- ->where('mobile',$data['mobile'])
|
|
|
- ->where('is_wb',0)
|
|
|
- ->exists();
|
|
|
- if($bool) return [false, '手机号已绑定内部员工!'];
|
|
|
-
|
|
|
- if(empty($data['four_shop'])) return [false, '绑定4s店信息不能为空'];
|
|
|
- //验证重复项
|
|
|
- $four_shop_id = array_column($data['four_shop'],'four_shop_id');
|
|
|
- foreach ($four_shop_id as $value){
|
|
|
- if(! $value) return [false,'4s店不能为空!'];
|
|
|
- }
|
|
|
- $four_shop_id = array_map(function($val) {
|
|
|
- return $val !== null ? $val : 0;
|
|
|
- }, $four_shop_id);
|
|
|
- $arr = array_count_values($four_shop_id);
|
|
|
- foreach ($arr as $value){
|
|
|
- if($value > 1) return [false,'4s店信息不能重复'];
|
|
|
- }
|
|
|
-
|
|
|
- if($user['id'] != Employee::SPECIAL_ADMIN){
|
|
|
- $area_manager = $this->getAreaManagerBy4S();
|
|
|
- if(! in_array($user['id'], $area_manager)) return [false,'非区域经理,操作失败'];
|
|
|
- }
|
|
|
-
|
|
|
- return [true, ''];
|
|
|
- }
|
|
|
-
|
|
|
- public function wxCheck($data,$user){
|
|
|
- return [true,''];
|
|
|
- }
|
|
|
-
|
|
|
- public function getAreaManagerBy4S(){
|
|
|
- $result = FoursShop::where('del_time',0)
|
|
|
- ->select('regional_manager')
|
|
|
- ->distinct()
|
|
|
- ->get()->toArray();
|
|
|
- return array_column($result,'regional_manager');
|
|
|
- }
|
|
|
-
|
|
|
- public function getAreaManagerByStore(){
|
|
|
- $result = StorehouseEmployee::select('employee_id')
|
|
|
- ->distinct()
|
|
|
- ->where('del_time',0)
|
|
|
- ->get()->toArray();
|
|
|
- return array_column($result,'employee_id');
|
|
|
- }
|
|
|
-
|
|
|
- public function is_area_manager($user_id){
|
|
|
- $is_area = [
|
|
|
- 'by_4s' => 0,
|
|
|
- 'by_store' => 0
|
|
|
- ];
|
|
|
- $return = $this->getAreaManagerBy4S();
|
|
|
- if(in_array($user_id,$return)) $is_area['by_4s'] = 1;
|
|
|
- $return = $this->getAreaManagerByStore();
|
|
|
- if(in_array($user_id,$return)) $is_area['by_store'] = 1;
|
|
|
-
|
|
|
- return $is_area;
|
|
|
- }
|
|
|
-
|
|
|
- public function is_check($user_id){
|
|
|
- if($user_id == Employee::SPECIAL_ADMIN) return 1;
|
|
|
-
|
|
|
- $bool = EmployeeTeamPermission::where('employee_id',$user_id)
|
|
|
- ->exists();
|
|
|
-
|
|
|
- return $bool;
|
|
|
- }
|
|
|
}
|