From 55368eb92ef9e0be0dd964118d2f9adafe68bc0e Mon Sep 17 00:00:00 2001 From: yaooo <272523191@qq.com> Date: Sat, 23 Dec 2023 15:11:31 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9B=B4=E6=96=B0=E7=BB=86=E8=8A=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../lists/quotation/QuotationLists.php | 29 ++++++++++++++----- .../logic/quotation/QuotationLogic.php | 6 ++++ app/common/model/quotation/Quotation.php | 22 +++++++++++++- 3 files changed, 48 insertions(+), 9 deletions(-) diff --git a/app/adminapi/lists/quotation/QuotationLists.php b/app/adminapi/lists/quotation/QuotationLists.php index 31e7ee1f4..139e3f40d 100644 --- a/app/adminapi/lists/quotation/QuotationLists.php +++ b/app/adminapi/lists/quotation/QuotationLists.php @@ -18,7 +18,7 @@ namespace app\adminapi\lists\quotation; use app\adminapi\lists\BaseAdminDataLists; use app\common\model\quotation\Quotation; use app\common\lists\ListsSearchInterface; - +use think\facade\Db; /** * 报价单列表 @@ -38,7 +38,7 @@ class QuotationLists extends BaseAdminDataLists implements ListsSearchInterface public function setSearch(): array { return [ - '=' => ['customer_id', 'contacts', 'create_user'], + '=' => ['q.customer_id', 'q.contacts', 'q.create_user'], ]; } @@ -54,12 +54,21 @@ class QuotationLists extends BaseAdminDataLists implements ListsSearchInterface */ public function lists(): array { - return Quotation::where($this->searchWhere) - ->with('product') - ->field(['id', 'customer_id', 'quotation_date', 'contacts', 'contacts_phone', 'create_user', 'invoice_type', 'amount_including_tax', 'freight', 'other_fee', 'total_amount']) + return Db::name('Quotation')->alias('q') + ->where($this->searchWhere) + ->whereNull('q.delete_time') + ->leftJoin('orgs o','o.id = q.org_id') + ->leftJoin('dept d','d.id = q.dept_id') + ->field('q.*, d.name as dept_name, o.name as org_name') ->limit($this->limitOffset, $this->limitLength) - ->order(['id' => 'desc']) - ->select() + ->order(['q.id' => 'desc']) + ->select()->each(function($item, $key){ + //关联数据后续添加 + $item['approve_no'] = '付款单号'; + $item['approve_step'] = '流程步骤'; + $item['approve_settle_status'] = 1; + return $item; + }) ->toArray(); } @@ -72,7 +81,11 @@ class QuotationLists extends BaseAdminDataLists implements ListsSearchInterface */ public function count(): int { - return Quotation::where($this->searchWhere)->count(); + return Db::name('Quotation')->alias('q') + ->where($this->searchWhere) + ->whereNull('q.delete_time') + ->leftJoin('orgs o','o.id = q.org_id') + ->leftJoin('dept d','d.id = q.dept_id')->count(); } } \ No newline at end of file diff --git a/app/adminapi/logic/quotation/QuotationLogic.php b/app/adminapi/logic/quotation/QuotationLogic.php index 698995164..af40278b3 100644 --- a/app/adminapi/logic/quotation/QuotationLogic.php +++ b/app/adminapi/logic/quotation/QuotationLogic.php @@ -42,6 +42,8 @@ class QuotationLogic extends BaseLogic Db::startTrans(); try { $quotation = Quotation::create([ + 'org_id' => $params['org_id'] ?? 0, + 'dept_id' => $params['dept_id'] ?? 0, 'customer_id' => $params['customer_id'] ?? 0, 'approve_id' => $params['approve_id'] ?? 0, 'quotation_date' => $params['quotation_date'] ?? '', @@ -89,6 +91,8 @@ class QuotationLogic extends BaseLogic Db::startTrans(); try { Quotation::where('id', $params['id'])->update([ + 'org_id' => $params['org_id'] ?? 0, + 'dept_id' => $params['dept_id'] ?? 0, 'customer_id' => $params['customer_id'] ?? 0, 'approve_id' => $params['approve_id'] ?? 0, 'quotation_date' => $params['quotation_date'] ?? '', @@ -151,6 +155,8 @@ class QuotationLogic extends BaseLogic $quotation = Quotation::findOrEmpty($params['id']); $quotation->product; $quotation->custom; + $quotation->org; + $quotation->dept; $quotation->annex = json_decode($quotation->annex, true); return $quotation->toArray(); } diff --git a/app/common/model/quotation/Quotation.php b/app/common/model/quotation/Quotation.php index bc1c18a86..c1927ea9d 100644 --- a/app/common/model/quotation/Quotation.php +++ b/app/common/model/quotation/Quotation.php @@ -46,5 +46,25 @@ class Quotation extends BaseModel return $this->belongsTo(\app\common\model\custom\Custom::class, 'customer_id'); } - + /** + * @notes 关联org + * @return \think\model\relation\HasOne + * @author likeadmin + * @date 2023/12/20 11:01 + */ + public function org() + { + return $this->hasOne(\app\common\model\dept\Orgs::class, 'id', 'org_id'); + } + + /** + * @notes 关联dept + * @return \think\model\relation\HasOne + * @author likeadmin + * @date 2023/12/20 11:01 + */ + public function dept() + { + return $this->hasOne(\app\common\model\dept\Dept::class, 'id', 'dept_id'); + } } \ No newline at end of file