This commit is contained in:
chenbo 2024-01-13 15:27:35 +08:00
parent 485197c75c
commit 249c59f701
4 changed files with 12 additions and 12 deletions

View File

@ -44,8 +44,8 @@
<el-table-column label="产品编号" prop="code" show-overflow-tooltip /> <el-table-column label="产品编号" prop="code" show-overflow-tooltip />
<el-table-column label="所属栏舍" width="200"> <el-table-column label="所属栏舍" width="200">
<template #default="{ row }"> <template #default="{ row }">
<el-tag class="mr-2" v-if="row.fence_house_id != null" type="info">ID: {{ row.land_id }}</el-tag> <el-tag class="mr-2" v-if="row.fence_house_id != null" type="info">ID: {{ row.fence_house_id }}</el-tag>
<el-tag class="mr-2" v-if="row.title != null" type="info">名称: {{ row.title }}</el-tag> <el-tag class="mr-2" v-if="row.fenceHouse.fence_house_name != null" type="info">名称: {{ row.fenceHouse.fence_house_name}}</el-tag>
</template> </template>
</el-table-column> </el-table-column>
<el-table-column label="产品状态" align="center" prop="status"> <el-table-column label="产品状态" align="center" prop="status">

View File

@ -86,11 +86,10 @@ class DeviceLists extends BaseAdminDataLists implements ListsSearchInterface
return Db::name('device')->alias('d') return Db::name('device')->alias('d')
->where($this->searchWhere)->where($this->userSearch())->where($this->querySearch()) ->where($this->searchWhere)->where($this->userSearch())->where($this->querySearch())
->leftJoin('user u','u.id = d.user_id') ->leftJoin('user u','u.id = d.user_id')
->leftJoin('farm f','f.user_id = u.id')
->leftJoin('product_device pd','pd.device_id = d.id') ->leftJoin('product_device pd','pd.device_id = d.id')
->leftJoin('product p','p.id = pd.product_id') ->leftJoin('product p','p.id = pd.product_id')
->leftJoin('land_product lp','lp.product_id = pd.product_id') ->field('d.*, u.account, pd.product_id, p.name as product_name, f.id as farm_id, f.farm_name')
->leftJoin('land l','l.id = lp.land_id')
->field('d.*, u.account, pd.product_id, p.name as product_name, lp.land_id, l.title as land_title')
->limit($this->limitOffset, $this->limitLength) ->limit($this->limitOffset, $this->limitLength)
->order(['d.id' => 'desc']) ->order(['d.id' => 'desc'])
->select()->each(function($item, $key){ ->select()->each(function($item, $key){

View File

@ -83,12 +83,11 @@ class ProductLists extends BaseAdminDataLists implements ListsSearchInterface
*/ */
public function lists(): array public function lists(): array
{ {
return Db::name('product')->alias('p') return Product::alias('p')
->where($this->searchWhere)->where($this->userSearch())->where($this->querySearch()) ->where($this->searchWhere)->where($this->userSearch())->where($this->querySearch())
->with(['fenceHouse'])
->leftJoin('user u','u.id = p.user_id') ->leftJoin('user u','u.id = p.user_id')
->leftJoin('land_product lp','lp.product_id = p.id') ->field('p.*, u.account')
->leftJoin('land l','l.id = lp.land_id')
->field('p.*, lp.land_id, l.title, u.account')
->limit($this->limitOffset, $this->limitLength) ->limit($this->limitOffset, $this->limitLength)
->order(['p.id' => 'desc']) ->order(['p.id' => 'desc'])
->select() ->select()
@ -107,8 +106,6 @@ class ProductLists extends BaseAdminDataLists implements ListsSearchInterface
return Db::name('product')->alias('p') return Db::name('product')->alias('p')
->where($this->searchWhere)->where($this->userSearch())->where($this->querySearch()) ->where($this->searchWhere)->where($this->userSearch())->where($this->querySearch())
->leftJoin('user u','u.id = p.user_id') ->leftJoin('user u','u.id = p.user_id')
->leftJoin('land_product lp','lp.product_id = p.id')
->leftJoin('land l','l.id = lp.land_id')
->count(); ->count();
} }

View File

@ -16,7 +16,7 @@ namespace app\common\model\land;
use app\common\model\BaseModel; use app\common\model\BaseModel;
use app\common\model\fence_house\FenceHouse;
/** /**
@ -42,4 +42,8 @@ class Product extends BaseModel
return $this->hasOne(\app\common\model\user\User::class, 'id', 'user_id'); return $this->hasOne(\app\common\model\user\User::class, 'id', 'user_id');
} }
public function fenceHouse()
{
return $this->hasOne(FenceHouse::class, 'id', 'fence_house_id');
}
} }