更新细节

This commit is contained in:
yaooo 2023-12-20 13:49:31 +08:00
parent a0c1a0eb07
commit 9165c695f5
5 changed files with 37 additions and 6 deletions

View File

@ -18,7 +18,7 @@ namespace app\adminapi\lists\cost;
use app\adminapi\lists\BaseAdminDataLists; use app\adminapi\lists\BaseAdminDataLists;
use app\common\model\cost\CostBudget; use app\common\model\cost\CostBudget;
use app\common\lists\ListsSearchInterface; use app\common\lists\ListsSearchInterface;
use think\facade\Db;
/** /**
* CostBudget列表 * CostBudget列表
@ -38,7 +38,7 @@ class CostBudgetLists extends BaseAdminDataLists implements ListsSearchInterface
public function setSearch(): array public function setSearch(): array
{ {
return [ return [
'=' => ['years', 'document_preparation_time'], '=' => ['cb.org_id', 'cb.dept_id', 'cb.years', 'cb.document_preparation_time'],
]; ];
} }
@ -54,11 +54,16 @@ class CostBudgetLists extends BaseAdminDataLists implements ListsSearchInterface
*/ */
public function lists(): array public function lists(): array
{ {
return CostBudget::where($this->searchWhere) return Db::name('CostBudget')->alias('cb')
->field(['id', 'years', 'document_preparation_time', 'total', 'remark', 'annex']) ->where($this->searchWhere)
->whereNull('cb.delete_time')
->leftJoin('orgs o','o.id = cb.org_id')
->leftJoin('dept d','d.id = cb.dept_id')
->field('cb.*, d.name as dept_name, o.name as org_name')
->limit($this->limitOffset, $this->limitLength) ->limit($this->limitOffset, $this->limitLength)
->order(['id' => 'desc']) ->order(['cb.id' => 'desc'])
->select()->each(function($item, $key){ ->select()->each(function($item, $key){
$item['year'] = date('Y', strtotime($item['document_preparation_time']));
//关联数据后续添加 //关联数据后续添加
$item['approve_no'] = '付款单号'; $item['approve_no'] = '付款单号';
$item['approve_step'] = '流程步骤'; $item['approve_step'] = '流程步骤';
@ -77,7 +82,11 @@ class CostBudgetLists extends BaseAdminDataLists implements ListsSearchInterface
*/ */
public function count(): int public function count(): int
{ {
return CostBudget::where($this->searchWhere)->count(); return Db::name('CostBudget')->alias('cb')
->where($this->searchWhere)
->whereNull('cb.delete_time')
->leftJoin('orgs o','o.id = cb.org_id')
->leftJoin('dept d','d.id = cb.dept_id')->count();
} }
} }

View File

@ -154,6 +154,12 @@ class CostBudgetLogic extends BaseLogic
{ {
$costBudget = CostBudget::findOrEmpty($params['id']); $costBudget = CostBudget::findOrEmpty($params['id']);
$costBudget->detail; $costBudget->detail;
foreach ($costBudget->detail as &$item) {
$item->subject;
}
$costBudget->org;
$costBudget->dept;
unset($item);
return $costBudget->toArray(); return $costBudget->toArray();
} }
} }

View File

@ -32,6 +32,8 @@ class CostBudgetValidate extends BaseValidate
*/ */
protected $rule = [ protected $rule = [
'id' => 'require', 'id' => 'require',
'org_id' => 'require',
'dept_id' => 'require',
'approve_id' => 'require', 'approve_id' => 'require',
'years' => 'require', 'years' => 'require',
'document_preparation_time' => 'require', 'document_preparation_time' => 'require',

View File

@ -42,4 +42,14 @@ class CostBudget extends BaseModel
return $this->hasMany(\app\common\model\cost\CostBudgetDetail::class, 'cost_budget_id', 'id'); return $this->hasMany(\app\common\model\cost\CostBudgetDetail::class, 'cost_budget_id', 'id');
} }
public function org()
{
return $this->hasOne(\app\common\model\dept\Orgs::class, 'id', 'org_id');
}
public function dept()
{
return $this->hasOne(\app\common\model\dept\Dept::class, 'id', 'dept_id');
}
} }

View File

@ -30,5 +30,9 @@ class CostBudgetDetail extends BaseModel
protected $name = 'cost_budget_detail'; protected $name = 'cost_budget_detail';
protected $deleteTime = 'delete_time'; protected $deleteTime = 'delete_time';
public function subject()
{
return $this->belongsTo(\app\common\model\cost\CostSubject::class, 'cost_subject_id');
}
} }