diff --git a/app/adminapi/controller/informationg/UserInformationgController.php b/app/adminapi/controller/informationg/UserInformationgController.php new file mode 100644 index 000000000..e7a9879ff --- /dev/null +++ b/app/adminapi/controller/informationg/UserInformationgController.php @@ -0,0 +1,108 @@ +dataLists(new UserInformationgLists()); + } + + + /** + * @notes 添加 + * @return \think\response\Json + * @author likeadmin + * @date 2023/08/01 15:00 + */ + public function add() + { + $params = (new UserInformationgValidate())->post()->goCheck('add'); + $result = UserInformationgLogic::add($params); + if (true === $result) { + return $this->success('添加成功', [], 1, 1); + } + return $this->fail(UserInformationgLogic::getError()); + } + + + /** + * @notes 编辑 + * @return \think\response\Json + * @author likeadmin + * @date 2023/08/01 15:00 + */ + public function edit() + { + $params = (new UserInformationgValidate())->post()->goCheck('edit'); + $result = UserInformationgLogic::edit($params); + if (true === $result) { + return $this->success('编辑成功', [], 1, 1); + } + return $this->fail(UserInformationgLogic::getError()); + } + + + /** + * @notes 删除 + * @return \think\response\Json + * @author likeadmin + * @date 2023/08/01 15:00 + */ + public function delete() + { + $params = (new UserInformationgValidate())->post()->goCheck('delete'); + UserInformationgLogic::delete($params); + return $this->success('删除成功', [], 1, 1); + } + + + /** + * @notes 获取详情 + * @return \think\response\Json + * @author likeadmin + * @date 2023/08/01 15:00 + */ + public function detail() + { + $params = (new UserInformationgValidate())->goCheck('detail'); + $result = UserInformationgLogic::detail($params); + return $this->data($result); + } + + +} \ No newline at end of file diff --git a/app/adminapi/lists/informationg/UserInformationgLists.php b/app/adminapi/lists/informationg/UserInformationgLists.php new file mode 100644 index 000000000..3975154a6 --- /dev/null +++ b/app/adminapi/lists/informationg/UserInformationgLists.php @@ -0,0 +1,77 @@ + ['create_user_id', 'user_id', 'area_id', 'street_id', 'village_id', 'brigade_id', 'address', 'name', 'phone', 'sex', 'age', 'wechat', 'family', 'child', 'child_arr', 'highway', 'smart_phone', 'status'], + ]; + } + + + /** + * @notes 获取列表 + * @return array + * @throws \think\db\exception\DataNotFoundException + * @throws \think\db\exception\DbException + * @throws \think\db\exception\ModelNotFoundException + * @author likeadmin + * @date 2023/08/01 15:00 + */ + public function lists(): array + { + $lists = UserInformationg::where($this->searchWhere) + ->field(['id', 'area_id','area_id area_name','street_id','street_id street_name','village_id','village_id village_name', 'brigade_id','brigade_id brigade_name', 'address', 'name', 'phone', 'sex', 'age', 'status']) + ->order(['id' => 'desc']) + ->select() + ->toArray(); + return $lists; + } + + + /** + * @notes 获取数量 + * @return int + * @author likeadmin + * @date 2023/08/01 15:00 + */ + public function count(): int + { + return UserInformationg::where($this->searchWhere)->count(); + } + +} \ No newline at end of file diff --git a/app/adminapi/logic/informationg/UserInformationgLogic.php b/app/adminapi/logic/informationg/UserInformationgLogic.php new file mode 100644 index 000000000..84658e658 --- /dev/null +++ b/app/adminapi/logic/informationg/UserInformationgLogic.php @@ -0,0 +1,162 @@ + $params['create_user_id'], + 'user_id' => $params['user_id'], + 'area_id' => $params['area_id'], + 'street_id' => $params['street_id'], + 'village_id' => $params['village_id'], + 'brigade_id' => $params['brigade_id'], + 'address' => $params['address'], + 'name' => $params['name'], + 'phone' => $params['phone'], + 'sex' => $params['sex'], + 'age' => $params['age'], + 'wechat' => $params['wechat'], + 'family' => $params['family'], + 'child' => $params['child'], + 'child_arr' => $params['child_arr'], + 'highway' => $params['highway'], + 'smart_phone' => $params['smart_phone'], + 'status' => $params['status'] + ]); + + Db::commit(); + return true; + } catch (\Exception $e) { + Db::rollback(); + self::setError($e->getMessage()); + return false; + } + } + + + /** + * @notes 编辑 + * @param array $params + * @return bool + * @author likeadmin + * @date 2023/08/01 15:00 + */ + public static function edit(array $params): bool + { + Db::startTrans(); + try { + UserInformationg::where('id', $params['id'])->update([ + 'create_user_id' => $params['create_user_id'], + 'user_id' => $params['user_id'], + 'area_id' => $params['area_id'], + 'street_id' => $params['street_id'], + 'village_id' => $params['village_id'], + 'brigade_id' => $params['brigade_id'], + 'address' => $params['address'], + 'name' => $params['name'], + 'phone' => $params['phone'], + 'sex' => $params['sex'], + 'age' => $params['age'], + 'wechat' => $params['wechat'], + 'family' => $params['family'], + 'child' => $params['child'], + 'child_arr' => $params['child_arr'], + 'highway' => $params['highway'], + 'smart_phone' => $params['smart_phone'], + 'status' => $params['status'] + ]); + + Db::commit(); + return true; + } catch (\Exception $e) { + Db::rollback(); + self::setError($e->getMessage()); + return false; + } + } + + + /** + * @notes 删除 + * @param array $params + * @return bool + * @author likeadmin + * @date 2023/08/01 15:00 + */ + public static function delete(array $params): bool + { + return UserInformationg::destroy($params['id']); + } + + + /** + * @notes 获取详情 + * @param $params + * @return array + * @author likeadmin + * @date 2023/08/01 15:00 + */ + public static function detail($params): array + { + $item = UserInformationg::where('id', $params['id'])->field('*,area_id area_name,street_id street_name,village_id village_name,brigade_id brigade_name')->find(); + $item['family'] = json_decode($item['family'], true); + $item['child_arr'] = json_decode($item['child_arr'], true); + $data = UserInformationgDemand::where('information_id', $params['id'])->order('id', 'desc')->select(); + $item['datas'] = []; + $datas = []; + if ($data) { + foreach ($data as $k => $v) { + $a = json_decode($v['data'], true); + $arr = [ + 'id' => $v['id'], + 'category_id' => $v['category_id'], + 'category_child' => $v['category_child'], + 'datas' => $a + ]; + if ($a) { + array_push($datas, $arr); + } + } + $item['datas'] = $datas; + } + return $item->toArray(); + } +} \ No newline at end of file diff --git a/app/adminapi/validate/informationg/UserInformationgValidate.php b/app/adminapi/validate/informationg/UserInformationgValidate.php new file mode 100644 index 000000000..7634329f1 --- /dev/null +++ b/app/adminapi/validate/informationg/UserInformationgValidate.php @@ -0,0 +1,102 @@ + 'require', + 'user_id' => 'require', + 'name' => 'require', + 'phone' => 'require', + 'wechat' => 'require', + ]; + + + /** + * 参数描述 + * @var string[] + */ + protected $field = [ + 'id' => 'id', + 'user_id' => '用户id', + 'name' => '姓名', + 'phone' => '联系电话', + 'wechat' => '微信', + ]; + + + /** + * @notes 添加场景 + * @return UserInformationgValidate + * @author likeadmin + * @date 2023/08/01 15:00 + */ + public function sceneAdd() + { + return $this->only(['user_id','name','phone','wechat']); + } + + + /** + * @notes 编辑场景 + * @return UserInformationgValidate + * @author likeadmin + * @date 2023/08/01 15:00 + */ + public function sceneEdit() + { + return $this->only(['id','user_id','name','phone','wechat']); + } + + + /** + * @notes 删除场景 + * @return UserInformationgValidate + * @author likeadmin + * @date 2023/08/01 15:00 + */ + public function sceneDelete() + { + return $this->only(['id']); + } + + + /** + * @notes 详情场景 + * @return UserInformationgValidate + * @author likeadmin + * @date 2023/08/01 15:00 + */ + public function sceneDetail() + { + return $this->only(['id']); + } + +} \ No newline at end of file diff --git a/app/api/controller/InformationController.php b/app/api/controller/InformationController.php index 233c198ee..4ae4a7a0c 100644 --- a/app/api/controller/InformationController.php +++ b/app/api/controller/InformationController.php @@ -2,7 +2,7 @@ namespace app\api\controller; -use app\common\model\information\UserInformationg; +use app\common\model\informationg\UserInformationg; use app\common\logic\BaseLogic; class InformationController extends BaseApiController diff --git a/app/common/model/information/UserInformationg.php b/app/common/model/informationg/UserInformationg.php similarity index 50% rename from app/common/model/information/UserInformationg.php rename to app/common/model/informationg/UserInformationg.php index 929b2a9da..ff27c9940 100644 --- a/app/common/model/information/UserInformationg.php +++ b/app/common/model/informationg/UserInformationg.php @@ -1,6 +1,6 @@ hasOne(\app\common\model\informationg\UserInformationgDemand::class, 'information_id', 'id'); + } - public static function list($param,$page=1,$size=10){ + public static function list($param, $page = 1, $size = 10) + { return self::where($param)->with('company') - ->field('id,area_id,area_id as area_name,street_id,street_id as street_name,village_id,village_id as village_name, street_id as street_name,brigade_id,brigade_id as brigade_name,name,phone,age,address,create_time,update_time') - ->page($page)->limit($size)->select(); + ->field('id,area_id,area_id as area_name,street_id,street_id as street_name,village_id,village_id as village_name, street_id as street_name,brigade_id,brigade_id as brigade_name,name,phone,age,address,create_time,update_time') + ->order('id','desc') + ->page($page)->limit($size)->select(); } public static function add($param) @@ -24,7 +36,7 @@ class UserInformationg extends BaseModel $child_arr_json = json_encode($param['child_arr']); // 插入数据 $data = [ - 'create_user_id'=>$param['admin_id'], + 'create_user_id' => $param['admin_id'], 'name' => $param['name'], 'phone' => $param['phone'], 'age' => $param['age'], @@ -39,10 +51,10 @@ class UserInformationg extends BaseModel 'child_arr' => $child_arr_json, ]; Db::startTrans(); - try{ + try { $result = self::create($data); - foreach($param['datas'] as $k=>$v){ - self::informationg_demand($v,$result['id'],$param['admin_id']); + foreach ($param['datas'] as $k => $v) { + self::informationg_demand($v, $result['id'], $param['admin_id']); } // switch($param['data_type']){ // case 1: @@ -50,7 +62,7 @@ class UserInformationg extends BaseModel // break; // } Db::commit(); - }catch(\Exception $e){ + } catch (\Exception $e) { Db::rollback(); BaseLogic::setError($e->getMessage()); return false; @@ -58,50 +70,51 @@ class UserInformationg extends BaseModel return true; } - public static function informationg_demand($param,$id,$admin_id){ - - $data=[ - 'create_user_id'=>$admin_id, - 'category_id'=>$param['category_id']??0, - 'category_child'=>$param['category_child']??0, - 'data'=>json_encode($param['datas']), - 'create_time'=>time(), - 'update_time'=>time(), - 'status'=>1, - 'information_id'=>$id, + public static function informationg_demand($param, $id, $admin_id) + { + + $data = [ + 'create_user_id' => $admin_id, + 'category_id' => $param['category_id'] ?? 0, + 'category_child' => $param['category_child'] ?? 0, + 'data' => json_encode($param['datas']), + 'create_time' => time(), + 'update_time' => time(), + 'status' => 1, + 'information_id' => $id, ]; UserInformationgDemand::create($data); } - public static function details($id){ - $item=self::where('id',$id)->field('*,area_id area_name,street_id street_name,village_id village_name,brigade_id brigade_name')->find(); - $item['family'] = json_decode($item['family'],true); - $item['child_arr'] = json_decode($item['child_arr'],true); - $data=UserInformationgDemand::where('information_id',$id)->order('id','desc')->select(); - $item['datas']=[]; - $datas=[]; - if($data){ - foreach($data as $k=>$v){ - $a=json_decode($v['data'],true); - $arr=[ - 'id'=>$v['id'], - 'category_id'=>$v['category_id'], - 'category_child'=>$v['category_child'], - 'datas'=>$a + public static function details($id) + { + $item = self::where('id', $id)->field('*,area_id area_name,street_id street_name,village_id village_name,brigade_id brigade_name')->find(); + $item['family'] = json_decode($item['family'], true); + $item['child_arr'] = json_decode($item['child_arr'], true); + $data = UserInformationgDemand::where('information_id', $id)->order('id', 'desc')->select(); + $item['datas'] = []; + $datas = []; + if ($data) { + foreach ($data as $k => $v) { + $a = json_decode($v['data'], true); + $arr = [ + 'id' => $v['id'], + 'category_id' => $v['category_id'], + 'category_child' => $v['category_child'], + 'datas' => $a ]; - if($a){ - array_push($datas,$arr); + if ($a) { + array_push($datas, $arr); } } - $item['datas']=$datas; + $item['datas'] = $datas; } return $item; - } public function company() { - return $this->hasOne(Company::class, 'id', 'company_id')->field(['id','company_name','admin_id']); + return $this->hasOne(Company::class, 'id', 'company_id')->field(['id', 'company_name', 'admin_id']); } public function getCityNameAttr($value) diff --git a/app/common/model/information/UserInformationgDemand.php b/app/common/model/informationg/UserInformationgDemand.php similarity index 69% rename from app/common/model/information/UserInformationgDemand.php rename to app/common/model/informationg/UserInformationgDemand.php index 71749342d..dd135562f 100644 --- a/app/common/model/information/UserInformationgDemand.php +++ b/app/common/model/informationg/UserInformationgDemand.php @@ -1,6 +1,6 @@