diff --git a/app/adminapi/lists/cost/CostBudgetLists.php b/app/adminapi/lists/cost/CostBudgetLists.php index 1b8123330..8f355430b 100644 --- a/app/adminapi/lists/cost/CostBudgetLists.php +++ b/app/adminapi/lists/cost/CostBudgetLists.php @@ -18,7 +18,7 @@ namespace app\adminapi\lists\cost; use app\adminapi\lists\BaseAdminDataLists; use app\common\model\cost\CostBudget; use app\common\lists\ListsSearchInterface; - +use think\facade\Db; /** * CostBudget列表 @@ -38,7 +38,7 @@ class CostBudgetLists extends BaseAdminDataLists implements ListsSearchInterface public function setSearch(): array { 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 { - return CostBudget::where($this->searchWhere) - ->field(['id', 'years', 'document_preparation_time', 'total', 'remark', 'annex']) + 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') + ->field('cb.*, d.name as dept_name, o.name as org_name') ->limit($this->limitOffset, $this->limitLength) - ->order(['id' => 'desc']) + ->order(['cb.id' => 'desc']) ->select()->each(function($item, $key){ + $item['year'] = date('Y', strtotime($item['document_preparation_time'])); //关联数据后续添加 $item['approve_no'] = '付款单号'; $item['approve_step'] = '流程步骤'; @@ -77,7 +82,11 @@ class CostBudgetLists extends BaseAdminDataLists implements ListsSearchInterface */ 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(); } } \ No newline at end of file diff --git a/app/adminapi/logic/cost/CostBudgetLogic.php b/app/adminapi/logic/cost/CostBudgetLogic.php index c6e41311f..0d4843564 100644 --- a/app/adminapi/logic/cost/CostBudgetLogic.php +++ b/app/adminapi/logic/cost/CostBudgetLogic.php @@ -154,6 +154,12 @@ class CostBudgetLogic extends BaseLogic { $costBudget = CostBudget::findOrEmpty($params['id']); $costBudget->detail; + foreach ($costBudget->detail as &$item) { + $item->subject; + } + $costBudget->org; + $costBudget->dept; + unset($item); return $costBudget->toArray(); } } \ No newline at end of file diff --git a/app/adminapi/validate/cost/CostBudgetValidate.php b/app/adminapi/validate/cost/CostBudgetValidate.php index 67bdcbf6c..5070ee4c0 100644 --- a/app/adminapi/validate/cost/CostBudgetValidate.php +++ b/app/adminapi/validate/cost/CostBudgetValidate.php @@ -32,6 +32,8 @@ class CostBudgetValidate extends BaseValidate */ protected $rule = [ 'id' => 'require', + 'org_id' => 'require', + 'dept_id' => 'require', 'approve_id' => 'require', 'years' => 'require', 'document_preparation_time' => 'require', diff --git a/app/common/model/cost/CostBudget.php b/app/common/model/cost/CostBudget.php index 52449b35f..71675d964 100644 --- a/app/common/model/cost/CostBudget.php +++ b/app/common/model/cost/CostBudget.php @@ -42,4 +42,14 @@ class CostBudget extends BaseModel 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'); + } + } \ No newline at end of file diff --git a/app/common/model/cost/CostBudgetDetail.php b/app/common/model/cost/CostBudgetDetail.php index 44212698b..2c0bf1a4a 100644 --- a/app/common/model/cost/CostBudgetDetail.php +++ b/app/common/model/cost/CostBudgetDetail.php @@ -30,5 +30,9 @@ class CostBudgetDetail extends BaseModel protected $name = 'cost_budget_detail'; protected $deleteTime = 'delete_time'; + public function subject() + { + return $this->belongsTo(\app\common\model\cost\CostSubject::class, 'cost_subject_id'); + } } \ No newline at end of file