| 
									
										
										
										
											2023-08-14 17:51:34 +08:00
										 |  |  | <?php | 
					
						
							|  |  |  | namespace app\admin\logic\user; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | use app\common\basics\Logic; | 
					
						
							|  |  |  | use app\common\model\BusinessTeam; | 
					
						
							|  |  |  | use think\facade\Db; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | class BusinessTeamLogic extends Logic | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     public static function lists($get) | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         $count = BusinessTeam::count(); | 
					
						
							|  |  |  |         $lists = BusinessTeam::order('id', 'desc')->page($get['page'], $get['limit'])->select()->toArray(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         return ['count' => $count, 'lists' => $lists]; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     public static function add($post) | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         try{ | 
					
						
							|  |  |  |             $userLevel = BusinessTeam::where(['name'=>trim($post['name'])])->findOrEmpty(); | 
					
						
							|  |  |  |             if(!$userLevel->isEmpty()) { | 
					
						
							|  |  |  |                 throw new \think\Exception('名称已被使用,请更换后重试'); | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  |             $time = time(); | 
					
						
							|  |  |  |             $data = [ | 
					
						
							|  |  |  |                 'name' => trim($post['name']), | 
					
						
							|  |  |  |                 'phone' => trim($post['phone']), | 
					
						
							|  |  |  |                 'create_time' => $time, | 
					
						
							|  |  |  |             ]; | 
					
						
							|  |  |  |             BusinessTeam::create($data); | 
					
						
							|  |  |  |             return true; | 
					
						
							|  |  |  |         }catch(\Exception $e) { | 
					
						
							|  |  |  |             self::$error = $e->getMessage(); | 
					
						
							|  |  |  |             return false; | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     public static function edit($post) | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         try{ | 
					
						
							|  |  |  |             $userLevel = BusinessTeam::where([ | 
					
						
							|  |  |  |                 ['name', '=', trim($post['name'])], | 
					
						
							|  |  |  |                 ['id', '<>', $post['id']] | 
					
						
							|  |  |  |             ])->findOrEmpty(); | 
					
						
							|  |  |  |             if(!$userLevel->isEmpty()) { | 
					
						
							|  |  |  |                 throw new \think\Exception('名称已被使用,请更换后重试'); | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  |             $data = [ | 
					
						
							|  |  |  |                 'id' => $post['id'], | 
					
						
							|  |  |  |                 'name' => trim($post['name']), | 
					
						
							|  |  |  |                 'phone' => trim($post['phone']), | 
					
						
							|  |  |  |             ]; | 
					
						
							|  |  |  |             BusinessTeam::update($data); | 
					
						
							|  |  |  |             return true; | 
					
						
							|  |  |  |         }catch(\Exception $e) { | 
					
						
							|  |  |  |             self::$error = $e->getMessage(); | 
					
						
							|  |  |  |             return false; | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     public static function del($id) | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         try{ | 
					
						
							|  |  |  |             BusinessTeam::where('id', $id)->delete(); | 
					
						
							|  |  |  |             return true; | 
					
						
							|  |  |  |         }catch(\Exception $e) { | 
					
						
							|  |  |  |             self::$error = $e->getMessage(); | 
					
						
							|  |  |  |             return false; | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-08-16 16:19:10 +08:00
										 |  |  |     public static function getBusinessTeamList($selected = []) | 
					
						
							| 
									
										
										
										
											2023-08-14 17:51:34 +08:00
										 |  |  |     { | 
					
						
							|  |  |  |         $levelArr = BusinessTeam::field('id,name,phone') | 
					
						
							| 
									
										
										
										
											2023-08-16 16:19:10 +08:00
										 |  |  |             ->order('id desc') | 
					
						
							| 
									
										
										
										
											2023-08-14 17:51:34 +08:00
										 |  |  |             ->select() | 
					
						
							|  |  |  |             ->toArray(); | 
					
						
							| 
									
										
										
										
											2023-08-16 16:19:10 +08:00
										 |  |  |         foreach ($levelArr as &$item) { | 
					
						
							|  |  |  |             if (in_array($item['id'], $selected)) { | 
					
						
							|  |  |  |                 $item['selected'] = true; | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  |         } | 
					
						
							| 
									
										
										
										
											2023-08-14 17:51:34 +08:00
										 |  |  |         return $levelArr; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     public static function getBusinessTeam($id){ | 
					
						
							|  |  |  |         $detail = BusinessTeam::where(['id'=>$id])->findOrEmpty(); | 
					
						
							|  |  |  |         if($detail->isEmpty()) { | 
					
						
							|  |  |  |             return []; | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |         $detail = $detail->toArray(); | 
					
						
							|  |  |  |         return $detail; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | } |