diff --git a/admin/src/api/farm.ts b/admin/src/api/farm.ts new file mode 100644 index 0000000..22226e8 --- /dev/null +++ b/admin/src/api/farm.ts @@ -0,0 +1,26 @@ +import request from '@/utils/request' + +// 养殖基地列表 +export function apiFarmLists(params: any) { + return request.get({ url: '/farm.farm/lists', params }) +} + +// 添加养殖基地 +export function apiFarmAdd(params: any) { + return request.post({ url: '/farm.farm/add', params }) +} + +// 编辑养殖基地 +export function apiFarmEdit(params: any) { + return request.post({ url: '/farm.farm/edit', params }) +} + +// 删除养殖基地 +export function apiFarmDelete(params: any) { + return request.post({ url: '/farm.farm/delete', params }) +} + +// 养殖基地详情 +export function apiFarmDetail(params: any) { + return request.get({ url: '/farm.farm/detail', params }) +} \ No newline at end of file diff --git a/admin/src/views/farm/edit.vue b/admin/src/views/farm/edit.vue new file mode 100644 index 0000000..3e7f491 --- /dev/null +++ b/admin/src/views/farm/edit.vue @@ -0,0 +1,215 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/admin/src/views/farm/index.vue b/admin/src/views/farm/index.vue new file mode 100644 index 0000000..5e398f6 --- /dev/null +++ b/admin/src/views/farm/index.vue @@ -0,0 +1,172 @@ + + + + + + + + + + 查询 + 重置 + + + + + + + + + 新增 + + + 删除 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 编辑 + + + 删除 + + + + + + + + + + + + + + + diff --git a/app/adminapi/controller/farm/FarmController.php b/app/adminapi/controller/farm/FarmController.php new file mode 100644 index 0000000..2080946 --- /dev/null +++ b/app/adminapi/controller/farm/FarmController.php @@ -0,0 +1,108 @@ +dataLists(new FarmLists()); + } + + + /** + * @notes 添加 + * @return \think\response\Json + * @author likeadmin + * @date 2024/01/09 18:22 + */ + public function add() + { + $params = (new FarmValidate())->post()->goCheck('add'); + $result = FarmLogic::add($params); + if (true === $result) { + return $this->success('添加成功', [], 1, 1); + } + return $this->fail(FarmLogic::getError()); + } + + + /** + * @notes 编辑 + * @return \think\response\Json + * @author likeadmin + * @date 2024/01/09 18:22 + */ + public function edit() + { + $params = (new FarmValidate())->post()->goCheck('edit'); + $result = FarmLogic::edit($params); + if (true === $result) { + return $this->success('编辑成功', [], 1, 1); + } + return $this->fail(FarmLogic::getError()); + } + + + /** + * @notes 删除 + * @return \think\response\Json + * @author likeadmin + * @date 2024/01/09 18:22 + */ + public function delete() + { + $params = (new FarmValidate())->post()->goCheck('delete'); + FarmLogic::delete($params); + return $this->success('删除成功', [], 1, 1); + } + + + /** + * @notes 获取详情 + * @return \think\response\Json + * @author likeadmin + * @date 2024/01/09 18:22 + */ + public function detail() + { + $params = (new FarmValidate())->goCheck('detail'); + $result = FarmLogic::detail($params); + return $this->data($result); + } + + +} \ No newline at end of file diff --git a/app/adminapi/lists/farm/FarmLists.php b/app/adminapi/lists/farm/FarmLists.php new file mode 100644 index 0000000..faa47e9 --- /dev/null +++ b/app/adminapi/lists/farm/FarmLists.php @@ -0,0 +1,77 @@ + ['farm_name'], + ]; + } + + + /** + * @notes 获取列表 + * @return array + * @throws \think\db\exception\DataNotFoundException + * @throws \think\db\exception\DbException + * @throws \think\db\exception\ModelNotFoundException + * @author likeadmin + * @date 2024/01/09 18:22 + */ + public function lists(): array + { + return Farm::where($this->searchWhere) + ->field(['id', 'farm_name', 'farm_type', 'breed_type', 'form_scale', 'master', 'master_contact', 'province', 'city', 'area', 'street', 'village', 'bridge', 'address', 'image']) + ->limit($this->limitOffset, $this->limitLength) + ->order(['id' => 'desc']) + ->select() + ->toArray(); + } + + + /** + * @notes 获取数量 + * @return int + * @author likeadmin + * @date 2024/01/09 18:22 + */ + public function count(): int + { + return Farm::where($this->searchWhere)->count(); + } + +} \ No newline at end of file diff --git a/app/adminapi/logic/farm/FarmLogic.php b/app/adminapi/logic/farm/FarmLogic.php new file mode 100644 index 0000000..16c06c2 --- /dev/null +++ b/app/adminapi/logic/farm/FarmLogic.php @@ -0,0 +1,132 @@ + $params['farm_name'], + 'farm_type' => $params['farm_type'], + 'breed_type' => $params['breed_type'], + 'form_scale' => $params['form_scale'], + 'master' => $params['master'], + 'master_contact' => $params['master_contact'], + 'province' => $params['province'], + 'city' => $params['city'], + 'area' => $params['area'], + 'street' => $params['street'], + 'village' => $params['village'], + 'bridge' => $params['bridge'], + 'address' => $params['address'], + 'image' => $params['image'], + ]); + + Db::commit(); + return true; + } catch (\Exception $e) { + Db::rollback(); + self::setError($e->getMessage()); + return false; + } + } + + + /** + * @notes 编辑 + * @param array $params + * @return bool + * @author likeadmin + * @date 2024/01/09 18:22 + */ + public static function edit(array $params): bool + { + Db::startTrans(); + try { + Farm::where('id', $params['id'])->update([ + 'farm_name' => $params['farm_name'], + 'farm_type' => $params['farm_type'], + 'breed_type' => $params['breed_type'], + 'form_scale' => $params['form_scale'], + 'master' => $params['master'], + 'master_contact' => $params['master_contact'], + 'province' => $params['province'], + 'city' => $params['city'], + 'area' => $params['area'], + 'street' => $params['street'], + 'village' => $params['village'], + 'bridge' => $params['bridge'], + 'address' => $params['address'], + 'image' => $params['image'], + ]); + + Db::commit(); + return true; + } catch (\Exception $e) { + Db::rollback(); + self::setError($e->getMessage()); + return false; + } + } + + + /** + * @notes 删除 + * @param array $params + * @return bool + * @author likeadmin + * @date 2024/01/09 18:22 + */ + public static function delete(array $params): bool + { + return Farm::destroy($params['id']); + } + + + /** + * @notes 获取详情 + * @param $params + * @return array + * @author likeadmin + * @date 2024/01/09 18:22 + */ + public static function detail($params): array + { + return Farm::findOrEmpty($params['id'])->toArray(); + } +} \ No newline at end of file diff --git a/app/adminapi/validate/farm/FarmValidate.php b/app/adminapi/validate/farm/FarmValidate.php new file mode 100644 index 0000000..87182ad --- /dev/null +++ b/app/adminapi/validate/farm/FarmValidate.php @@ -0,0 +1,94 @@ + 'require', + ]; + + + /** + * 参数描述 + * @var string[] + */ + protected $field = [ + 'id' => 'id', + ]; + + + /** + * @notes 添加场景 + * @return FarmValidate + * @author likeadmin + * @date 2024/01/09 18:22 + */ + public function sceneAdd() + { + return $this->remove('id', true); + } + + + /** + * @notes 编辑场景 + * @return FarmValidate + * @author likeadmin + * @date 2024/01/09 18:22 + */ + public function sceneEdit() + { + return $this->only(['id']); + } + + + /** + * @notes 删除场景 + * @return FarmValidate + * @author likeadmin + * @date 2024/01/09 18:22 + */ + public function sceneDelete() + { + return $this->only(['id']); + } + + + /** + * @notes 详情场景 + * @return FarmValidate + * @author likeadmin + * @date 2024/01/09 18:22 + */ + public function sceneDetail() + { + return $this->only(['id']); + } + +} \ No newline at end of file diff --git a/app/common/model/farm/Farm.php b/app/common/model/farm/Farm.php new file mode 100644 index 0000000..6ef66aa --- /dev/null +++ b/app/common/model/farm/Farm.php @@ -0,0 +1,100 @@ +hasOne(\app\common\model\geo\Province::class, 'province_code', 'province'); + } + + /** + * @notes 关联city + * @return \think\model\relation\HasOne + * @author likeadmin + * @date 2024/01/09 18:22 + */ + public function city() + { + return $this->hasOne(\app\common\model\geo\City::class, 'city_code', 'city'); + } + + /** + * @notes 关联area + * @return \think\model\relation\HasOne + * @author likeadmin + * @date 2024/01/09 18:22 + */ + public function area() + { + return $this->hasOne(\app\common\model\geo\County::class, 'county_code', 'area'); + } + + /** + * @notes 关联street + * @return \think\model\relation\HasOne + * @author likeadmin + * @date 2024/01/09 18:22 + */ + public function street() + { + return $this->hasOne(\app\common\model\geo\Town::class, 'town_code', 'street'); + } + + /** + * @notes 关联village + * @return \think\model\relation\HasOne + * @author likeadmin + * @date 2024/01/09 18:22 + */ + public function village() + { + return $this->hasOne(\app\common\model\geo\Village::class, 'village_code', 'village'); + } + + /** + * @notes 关联bridge + * @return \think\model\relation\HasOne + * @author likeadmin + * @date 2024/01/09 18:22 + */ + public function bridge() + { + return $this->hasOne(\app\common\model\geo\Group::class, 'id', 'bridge'); + } + +} \ No newline at end of file