add 养殖基地管理
This commit is contained in:
parent
db6a68bf77
commit
f25edd9efa
|
@ -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 })
|
||||
}
|
|
@ -0,0 +1,215 @@
|
|||
<template>
|
||||
<div class="edit-popup">
|
||||
<popup
|
||||
ref="popupRef"
|
||||
:title="popupTitle"
|
||||
:async="true"
|
||||
width="550px"
|
||||
@confirm="handleSubmit"
|
||||
@close="handleClose"
|
||||
>
|
||||
<el-form ref="formRef" :model="formData" label-width="90px" :rules="formRules">
|
||||
<el-form-item label="名称" prop="farm_name">
|
||||
<el-input v-model="formData.farm_name" clearable placeholder="请输入名称" />
|
||||
</el-form-item>
|
||||
<el-form-item label="养殖基地类型" prop="farm_type">
|
||||
<el-select class="flex-1" v-model="formData.farm_type" clearable placeholder="请选择养殖基地类型">
|
||||
<el-option
|
||||
v-for="(item, index) in dictData.farm_type"
|
||||
:key="index"
|
||||
:label="item.name"
|
||||
:value="parseInt(item.value)"
|
||||
/>
|
||||
</el-select>
|
||||
</el-form-item>
|
||||
<el-form-item label="养殖种类" prop="breed_type">
|
||||
<el-select class="flex-1" v-model="formData.breed_type" clearable placeholder="请选择养殖种类">
|
||||
<el-option
|
||||
v-for="(item, index) in dictData.breed_type"
|
||||
:key="index"
|
||||
:label="item.name"
|
||||
:value="parseInt(item.value)"
|
||||
/>
|
||||
</el-select>
|
||||
</el-form-item>
|
||||
<el-form-item label="养殖场规模" prop="form_scale">
|
||||
<el-input v-model="formData.form_scale" clearable placeholder="请输入养殖场规模" />
|
||||
</el-form-item>
|
||||
<el-form-item label="负责人" prop="master">
|
||||
<el-input v-model="formData.master" clearable placeholder="请输入负责人" />
|
||||
</el-form-item>
|
||||
<el-form-item label="联系方式" prop="master_contact">
|
||||
<el-input v-model="formData.master_contact" clearable placeholder="请输入联系方式" />
|
||||
</el-form-item>
|
||||
<el-form-item label="省" prop="province">
|
||||
<el-select class="flex-1" v-model="formData.province" clearable placeholder="请选择省">
|
||||
<el-option
|
||||
v-for="(item, index) in dictData"
|
||||
:key="index"
|
||||
:label="item.name"
|
||||
:value="item.value"
|
||||
/>
|
||||
</el-select>
|
||||
</el-form-item>
|
||||
<el-form-item label="市" prop="city">
|
||||
<el-select class="flex-1" v-model="formData.city" clearable placeholder="请选择市">
|
||||
<el-option
|
||||
v-for="(item, index) in dictData"
|
||||
:key="index"
|
||||
:label="item.name"
|
||||
:value="item.value"
|
||||
/>
|
||||
</el-select>
|
||||
</el-form-item>
|
||||
<el-form-item label="区" prop="area">
|
||||
<el-select class="flex-1" v-model="formData.area" clearable placeholder="请选择区">
|
||||
<el-option
|
||||
v-for="(item, index) in dictData"
|
||||
:key="index"
|
||||
:label="item.name"
|
||||
:value="item.value"
|
||||
/>
|
||||
</el-select>
|
||||
</el-form-item>
|
||||
<el-form-item label="镇/街" prop="street">
|
||||
<el-select class="flex-1" v-model="formData.street" clearable placeholder="请选择镇/街">
|
||||
<el-option
|
||||
v-for="(item, index) in dictData"
|
||||
:key="index"
|
||||
:label="item.name"
|
||||
:value="item.value"
|
||||
/>
|
||||
</el-select>
|
||||
</el-form-item>
|
||||
<el-form-item label="村" prop="village">
|
||||
<el-select class="flex-1" v-model="formData.village" clearable placeholder="请选择村">
|
||||
<el-option
|
||||
v-for="(item, index) in dictData"
|
||||
:key="index"
|
||||
:label="item.name"
|
||||
:value="item.value"
|
||||
/>
|
||||
</el-select>
|
||||
</el-form-item>
|
||||
<el-form-item label="小队" prop="bridge">
|
||||
<el-select class="flex-1" v-model="formData.bridge" clearable placeholder="请选择小队">
|
||||
<el-option
|
||||
v-for="(item, index) in dictData"
|
||||
:key="index"
|
||||
:label="item.name"
|
||||
:value="item.value"
|
||||
/>
|
||||
</el-select>
|
||||
</el-form-item>
|
||||
<el-form-item label="地址" prop="address">
|
||||
<el-input v-model="formData.address" clearable placeholder="请输入地址" />
|
||||
</el-form-item>
|
||||
<el-form-item label="图片" prop="image">
|
||||
<el-input v-model="formData.image" clearable placeholder="请输入图片" />
|
||||
</el-form-item>
|
||||
|
||||
</el-form>
|
||||
</popup>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script lang="ts" setup name="farmEdit">
|
||||
import type { FormInstance } from 'element-plus'
|
||||
import Popup from '@/components/popup/index.vue'
|
||||
import { apiFarmAdd, apiFarmEdit, apiFarmDetail } from '@/api/farm'
|
||||
import { timeFormat } from '@/utils/util'
|
||||
import type { PropType } from 'vue'
|
||||
defineProps({
|
||||
dictData: {
|
||||
type: Object as PropType<Record<string, any[]>>,
|
||||
default: () => ({})
|
||||
}
|
||||
})
|
||||
const emit = defineEmits(['success', 'close'])
|
||||
const formRef = shallowRef<FormInstance>()
|
||||
const popupRef = shallowRef<InstanceType<typeof Popup>>()
|
||||
const mode = ref('add')
|
||||
|
||||
|
||||
// 弹窗标题
|
||||
const popupTitle = computed(() => {
|
||||
return mode.value == 'edit' ? '编辑养殖基地' : '新增养殖基地'
|
||||
})
|
||||
|
||||
// 表单数据
|
||||
const formData = reactive({
|
||||
id: '',
|
||||
farm_name: '',
|
||||
farm_type: '',
|
||||
breed_type: '',
|
||||
form_scale: '',
|
||||
master: '',
|
||||
master_contact: '',
|
||||
province: '',
|
||||
city: '',
|
||||
area: '',
|
||||
street: '',
|
||||
village: '',
|
||||
bridge: '',
|
||||
address: '',
|
||||
image: '',
|
||||
|
||||
})
|
||||
|
||||
|
||||
// 表单验证
|
||||
const formRules = reactive<any>({
|
||||
|
||||
})
|
||||
|
||||
|
||||
// 获取详情
|
||||
const setFormData = async (data: Record<any, any>) => {
|
||||
for (const key in formData) {
|
||||
if (data[key] != null && data[key] != undefined) {
|
||||
//@ts-ignore
|
||||
formData[key] = data[key]
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
const getDetail = async (row: Record<string, any>) => {
|
||||
const data = await apiFarmDetail({
|
||||
id: row.id
|
||||
})
|
||||
setFormData(data)
|
||||
}
|
||||
|
||||
|
||||
// 提交按钮
|
||||
const handleSubmit = async () => {
|
||||
await formRef.value?.validate()
|
||||
const data = { ...formData, }
|
||||
mode.value == 'edit'
|
||||
? await apiFarmEdit(data)
|
||||
: await apiFarmAdd(data)
|
||||
popupRef.value?.close()
|
||||
emit('success')
|
||||
}
|
||||
|
||||
//打开弹窗
|
||||
const open = (type = 'add') => {
|
||||
mode.value = type
|
||||
popupRef.value?.open()
|
||||
}
|
||||
|
||||
// 关闭回调
|
||||
const handleClose = () => {
|
||||
emit('close')
|
||||
}
|
||||
|
||||
|
||||
|
||||
defineExpose({
|
||||
open,
|
||||
setFormData,
|
||||
getDetail
|
||||
})
|
||||
</script>
|
|
@ -0,0 +1,172 @@
|
|||
<template>
|
||||
<div>
|
||||
<el-card class="!border-none mb-4" shadow="never">
|
||||
<el-form
|
||||
class="mb-[-16px]"
|
||||
:model="queryParams"
|
||||
inline
|
||||
>
|
||||
<el-form-item label="名称" prop="farm_name">
|
||||
<el-input class="w-[280px]" v-model="queryParams.farm_name" clearable placeholder="请输入名称" />
|
||||
</el-form-item>
|
||||
|
||||
<el-form-item>
|
||||
<el-button type="primary" @click="resetPage">查询</el-button>
|
||||
<el-button @click="resetParams">重置</el-button>
|
||||
</el-form-item>
|
||||
</el-form>
|
||||
</el-card>
|
||||
<el-card class="!border-none" v-loading="pager.loading" shadow="never">
|
||||
<el-button v-perms="['farm.farm/add']" type="primary" @click="handleAdd">
|
||||
<template #icon>
|
||||
<icon name="el-icon-Plus" />
|
||||
</template>
|
||||
新增
|
||||
</el-button>
|
||||
<el-button
|
||||
v-perms="['farm.farm/delete']"
|
||||
:disabled="!selectData.length"
|
||||
@click="handleDelete(selectData)"
|
||||
>
|
||||
删除
|
||||
</el-button>
|
||||
<div class="mt-4">
|
||||
<el-table :data="pager.lists" @selection-change="handleSelectionChange">
|
||||
<el-table-column type="selection" width="55" />
|
||||
<el-table-column label="名称" prop="farm_name" show-overflow-tooltip />
|
||||
<el-table-column label="养殖基地类型" prop="farm_type">
|
||||
<template #default="{ row }">
|
||||
<dict-value :options="dictDatafarm_type" :value="row.farm_type" />
|
||||
</template>
|
||||
</el-table-column>
|
||||
<el-table-column label="养殖种类" prop="breed_type">
|
||||
<template #default="{ row }">
|
||||
<dict-value :options="dictDatabreed_type" :value="row.breed_type" />
|
||||
</template>
|
||||
</el-table-column>
|
||||
<el-table-column label="养殖场规模" prop="form_scale" show-overflow-tooltip />
|
||||
<el-table-column label="负责人" prop="master" show-overflow-tooltip />
|
||||
<el-table-column label="联系方式" prop="master_contact" show-overflow-tooltip />
|
||||
<el-table-column label="省" prop="province">
|
||||
<template #default="{ row }">
|
||||
<dict-value :options="dictData" :value="row.province" />
|
||||
</template>
|
||||
</el-table-column>
|
||||
<el-table-column label="市" prop="city">
|
||||
<template #default="{ row }">
|
||||
<dict-value :options="dictData" :value="row.city" />
|
||||
</template>
|
||||
</el-table-column>
|
||||
<el-table-column label="区" prop="area">
|
||||
<template #default="{ row }">
|
||||
<dict-value :options="dictData" :value="row.area" />
|
||||
</template>
|
||||
</el-table-column>
|
||||
<el-table-column label="镇/街" prop="street">
|
||||
<template #default="{ row }">
|
||||
<dict-value :options="dictData" :value="row.street" />
|
||||
</template>
|
||||
</el-table-column>
|
||||
<el-table-column label="村" prop="village">
|
||||
<template #default="{ row }">
|
||||
<dict-value :options="dictData" :value="row.village" />
|
||||
</template>
|
||||
</el-table-column>
|
||||
<el-table-column label="小队" prop="bridge">
|
||||
<template #default="{ row }">
|
||||
<dict-value :options="dictData" :value="row.bridge" />
|
||||
</template>
|
||||
</el-table-column>
|
||||
<el-table-column label="地址" prop="address" show-overflow-tooltip />
|
||||
<el-table-column label="图片" prop="image" show-overflow-tooltip />
|
||||
|
||||
<el-table-column label="操作" width="120" fixed="right">
|
||||
<template #default="{ row }">
|
||||
<el-button
|
||||
v-perms="['farm.farm/edit']"
|
||||
type="primary"
|
||||
link
|
||||
@click="handleEdit(row)"
|
||||
>
|
||||
编辑
|
||||
</el-button>
|
||||
<el-button
|
||||
v-perms="['farm.farm/delete']"
|
||||
type="danger"
|
||||
link
|
||||
@click="handleDelete(row.id)"
|
||||
>
|
||||
删除
|
||||
</el-button>
|
||||
</template>
|
||||
</el-table-column>
|
||||
</el-table>
|
||||
</div>
|
||||
<div class="flex mt-4 justify-end">
|
||||
<pagination v-model="pager" @change="getLists" />
|
||||
</div>
|
||||
</el-card>
|
||||
<edit-popup v-if="showEdit" ref="editRef" :dict-data="dictData" @success="getLists" @close="showEdit = false" />
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script lang="ts" setup name="farmLists">
|
||||
import { usePaging } from '@/hooks/usePaging'
|
||||
import { useDictData } from '@/hooks/useDictOptions'
|
||||
import { apiFarmLists, apiFarmDelete } from '@/api/farm'
|
||||
import { timeFormat } from '@/utils/util'
|
||||
import feedback from '@/utils/feedback'
|
||||
import EditPopup from './edit.vue'
|
||||
|
||||
const editRef = shallowRef<InstanceType<typeof EditPopup>>()
|
||||
// 是否显示编辑框
|
||||
const showEdit = ref(false)
|
||||
|
||||
|
||||
// 查询条件
|
||||
const queryParams = reactive({
|
||||
farm_name: '',
|
||||
})
|
||||
|
||||
// 选中数据
|
||||
const selectData = ref<any[]>([])
|
||||
|
||||
// 表格选择后回调事件
|
||||
const handleSelectionChange = (val: any[]) => {
|
||||
selectData.value = val.map(({ id }) => id)
|
||||
}
|
||||
|
||||
// 获取字典数据
|
||||
const { dictData } = useDictData('farm_type,breed_type')
|
||||
|
||||
// 分页相关
|
||||
const { pager, getLists, resetParams, resetPage } = usePaging({
|
||||
fetchFun: apiFarmLists,
|
||||
params: queryParams
|
||||
})
|
||||
|
||||
// 添加
|
||||
const handleAdd = async () => {
|
||||
showEdit.value = true
|
||||
await nextTick()
|
||||
editRef.value?.open('add')
|
||||
}
|
||||
|
||||
// 编辑
|
||||
const handleEdit = async (data: any) => {
|
||||
showEdit.value = true
|
||||
await nextTick()
|
||||
editRef.value?.open('edit')
|
||||
editRef.value?.setFormData(data)
|
||||
}
|
||||
|
||||
// 删除
|
||||
const handleDelete = async (id: number | any[]) => {
|
||||
await feedback.confirm('确定要删除?')
|
||||
await apiFarmDelete({ id })
|
||||
getLists()
|
||||
}
|
||||
|
||||
getLists()
|
||||
</script>
|
||||
|
|
@ -0,0 +1,108 @@
|
|||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | likeadmin快速开发前后端分离管理后台(PHP版)
|
||||
// +----------------------------------------------------------------------
|
||||
// | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
|
||||
// | 开源版本可自由商用,可去除界面版权logo
|
||||
// | gitee下载:https://gitee.com/likeshop_gitee/likeadmin
|
||||
// | github下载:https://github.com/likeshop-github/likeadmin
|
||||
// | 访问官网:https://www.likeadmin.cn
|
||||
// | likeadmin团队 版权所有 拥有最终解释权
|
||||
// +----------------------------------------------------------------------
|
||||
// | author: likeadminTeam
|
||||
// +----------------------------------------------------------------------
|
||||
|
||||
|
||||
namespace app\adminapi\controller\farm;
|
||||
|
||||
|
||||
use app\adminapi\controller\BaseAdminController;
|
||||
use app\adminapi\lists\farm\FarmLists;
|
||||
use app\adminapi\logic\farm\FarmLogic;
|
||||
use app\adminapi\validate\farm\FarmValidate;
|
||||
|
||||
|
||||
/**
|
||||
* Farm控制器
|
||||
* Class FarmController
|
||||
* @package app\adminapi\controller\farm
|
||||
*/
|
||||
class FarmController extends BaseAdminController
|
||||
{
|
||||
|
||||
|
||||
/**
|
||||
* @notes 获取列表
|
||||
* @return \think\response\Json
|
||||
* @author likeadmin
|
||||
* @date 2024/01/09 18:22
|
||||
*/
|
||||
public function lists()
|
||||
{
|
||||
return $this->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);
|
||||
}
|
||||
|
||||
|
||||
}
|
|
@ -0,0 +1,77 @@
|
|||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | likeadmin快速开发前后端分离管理后台(PHP版)
|
||||
// +----------------------------------------------------------------------
|
||||
// | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
|
||||
// | 开源版本可自由商用,可去除界面版权logo
|
||||
// | gitee下载:https://gitee.com/likeshop_gitee/likeadmin
|
||||
// | github下载:https://github.com/likeshop-github/likeadmin
|
||||
// | 访问官网:https://www.likeadmin.cn
|
||||
// | likeadmin团队 版权所有 拥有最终解释权
|
||||
// +----------------------------------------------------------------------
|
||||
// | author: likeadminTeam
|
||||
// +----------------------------------------------------------------------
|
||||
|
||||
namespace app\adminapi\lists\farm;
|
||||
|
||||
|
||||
use app\adminapi\lists\BaseAdminDataLists;
|
||||
use app\common\model\farm\Farm;
|
||||
use app\common\lists\ListsSearchInterface;
|
||||
|
||||
|
||||
/**
|
||||
* Farm列表
|
||||
* Class FarmLists
|
||||
* @package app\adminapi\listsfarm
|
||||
*/
|
||||
class FarmLists extends BaseAdminDataLists implements ListsSearchInterface
|
||||
{
|
||||
|
||||
|
||||
/**
|
||||
* @notes 设置搜索条件
|
||||
* @return \string[][]
|
||||
* @author likeadmin
|
||||
* @date 2024/01/09 18:22
|
||||
*/
|
||||
public function setSearch(): array
|
||||
{
|
||||
return [
|
||||
'=' => ['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();
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,132 @@
|
|||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | likeadmin快速开发前后端分离管理后台(PHP版)
|
||||
// +----------------------------------------------------------------------
|
||||
// | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
|
||||
// | 开源版本可自由商用,可去除界面版权logo
|
||||
// | gitee下载:https://gitee.com/likeshop_gitee/likeadmin
|
||||
// | github下载:https://github.com/likeshop-github/likeadmin
|
||||
// | 访问官网:https://www.likeadmin.cn
|
||||
// | likeadmin团队 版权所有 拥有最终解释权
|
||||
// +----------------------------------------------------------------------
|
||||
// | author: likeadminTeam
|
||||
// +----------------------------------------------------------------------
|
||||
|
||||
namespace app\adminapi\logic\farm;
|
||||
|
||||
|
||||
use app\common\model\farm\Farm;
|
||||
use app\common\logic\BaseLogic;
|
||||
use think\facade\Db;
|
||||
|
||||
|
||||
/**
|
||||
* Farm逻辑
|
||||
* Class FarmLogic
|
||||
* @package app\adminapi\logic\farm
|
||||
*/
|
||||
class FarmLogic extends BaseLogic
|
||||
{
|
||||
|
||||
|
||||
/**
|
||||
* @notes 添加
|
||||
* @param array $params
|
||||
* @return bool
|
||||
* @author likeadmin
|
||||
* @date 2024/01/09 18:22
|
||||
*/
|
||||
public static function add(array $params): bool
|
||||
{
|
||||
Db::startTrans();
|
||||
try {
|
||||
Farm::create([
|
||||
'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 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();
|
||||
}
|
||||
}
|
|
@ -0,0 +1,94 @@
|
|||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | likeadmin快速开发前后端分离管理后台(PHP版)
|
||||
// +----------------------------------------------------------------------
|
||||
// | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
|
||||
// | 开源版本可自由商用,可去除界面版权logo
|
||||
// | gitee下载:https://gitee.com/likeshop_gitee/likeadmin
|
||||
// | github下载:https://github.com/likeshop-github/likeadmin
|
||||
// | 访问官网:https://www.likeadmin.cn
|
||||
// | likeadmin团队 版权所有 拥有最终解释权
|
||||
// +----------------------------------------------------------------------
|
||||
// | author: likeadminTeam
|
||||
// +----------------------------------------------------------------------
|
||||
|
||||
namespace app\adminapi\validate\farm;
|
||||
|
||||
|
||||
use app\common\validate\BaseValidate;
|
||||
|
||||
|
||||
/**
|
||||
* Farm验证器
|
||||
* Class FarmValidate
|
||||
* @package app\adminapi\validate\farm
|
||||
*/
|
||||
class FarmValidate extends BaseValidate
|
||||
{
|
||||
|
||||
/**
|
||||
* 设置校验规则
|
||||
* @var string[]
|
||||
*/
|
||||
protected $rule = [
|
||||
'id' => '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']);
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,100 @@
|
|||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | likeadmin快速开发前后端分离管理后台(PHP版)
|
||||
// +----------------------------------------------------------------------
|
||||
// | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
|
||||
// | 开源版本可自由商用,可去除界面版权logo
|
||||
// | gitee下载:https://gitee.com/likeshop_gitee/likeadmin
|
||||
// | github下载:https://github.com/likeshop-github/likeadmin
|
||||
// | 访问官网:https://www.likeadmin.cn
|
||||
// | likeadmin团队 版权所有 拥有最终解释权
|
||||
// +----------------------------------------------------------------------
|
||||
// | author: likeadminTeam
|
||||
// +----------------------------------------------------------------------
|
||||
|
||||
namespace app\common\model\farm;
|
||||
|
||||
|
||||
use app\common\model\BaseModel;
|
||||
use think\model\concern\SoftDelete;
|
||||
|
||||
|
||||
/**
|
||||
* Farm模型
|
||||
* Class Farm
|
||||
* @package app\common\model\farm
|
||||
*/
|
||||
class Farm extends BaseModel
|
||||
{
|
||||
use SoftDelete;
|
||||
protected $name = 'farm';
|
||||
protected $deleteTime = 'delete_time';
|
||||
|
||||
|
||||
/**
|
||||
* @notes 关联province
|
||||
* @return \think\model\relation\HasOne
|
||||
* @author likeadmin
|
||||
* @date 2024/01/09 18:22
|
||||
*/
|
||||
public function province()
|
||||
{
|
||||
return $this->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');
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue