From def064d6451556eefd15e9c7c5088f50f37b3fb8 Mon Sep 17 00:00:00 2001 From: yaooo <272523191@qq.com> Date: Sat, 9 Dec 2023 11:49:01 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9B=B4=E6=96=B0=E6=8A=A5=E4=BB=B7=E5=8D=95?= =?UTF-8?q?=E6=A8=A1=E5=9D=97?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../lists/quotation/QuotationLists.php | 1 + .../logic/quotation/QuotationLogic.php | 33 ++++++++++++++++--- .../validate/quotation/QuotationValidate.php | 18 +++++++++- app/common/model/quotation/Quotation.php | 11 +++++++ 4 files changed, 58 insertions(+), 5 deletions(-) diff --git a/app/adminapi/lists/quotation/QuotationLists.php b/app/adminapi/lists/quotation/QuotationLists.php index 8ffdbc8dc..31e7ee1f4 100644 --- a/app/adminapi/lists/quotation/QuotationLists.php +++ b/app/adminapi/lists/quotation/QuotationLists.php @@ -55,6 +55,7 @@ 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']) ->limit($this->limitOffset, $this->limitLength) ->order(['id' => 'desc']) diff --git a/app/adminapi/logic/quotation/QuotationLogic.php b/app/adminapi/logic/quotation/QuotationLogic.php index 50e41e124..28c91e8b5 100644 --- a/app/adminapi/logic/quotation/QuotationLogic.php +++ b/app/adminapi/logic/quotation/QuotationLogic.php @@ -16,6 +16,7 @@ namespace app\adminapi\logic\quotation; use app\common\model\quotation\Quotation; +use app\common\model\quotation\QuotationDetail; use app\common\logic\BaseLogic; use think\facade\Db; @@ -40,8 +41,9 @@ class QuotationLogic extends BaseLogic { Db::startTrans(); try { - Quotation::create([ + $quotation = Quotation::create([ 'customer_id' => $params['customer_id'], + 'approve_id' => $params['approve_id'], 'quotation_date' => $params['quotation_date'], 'contacts' => $params['contacts'], 'contacts_phone' => $params['contacts_phone'], @@ -55,7 +57,16 @@ class QuotationLogic extends BaseLogic 'remark' => $params['remark'], 'annex' => $params['annex'] ]); - + foreach ($params['product'] as $item) + { + QuotationDetail::create([ + 'quotation_id' => $quotation->id, + 'product_id' => $item['product_id'], + 'product_num' => $item['product_num'], + 'tax_rate' => $item['tax_rate'], + 'remark' => $item['remark'] ?? '' + ]); + } Db::commit(); return true; } catch (\Exception $e) { @@ -79,6 +90,7 @@ class QuotationLogic extends BaseLogic try { Quotation::where('id', $params['id'])->update([ 'customer_id' => $params['customer_id'], + 'approve_id' => $params['approve_id'], 'quotation_date' => $params['quotation_date'], 'contacts' => $params['contacts'], 'contacts_phone' => $params['contacts_phone'], @@ -92,7 +104,17 @@ class QuotationLogic extends BaseLogic 'remark' => $params['remark'], 'annex' => $params['annex'] ]); - + QuotationDetail::where('quotation_id', $params['id'])->delete(); + foreach ($params['product'] as $item) + { + QuotationDetail::create([ + 'quotation_id' => $params['id'], + 'product_id' => $item['product_id'], + 'product_num' => $item['product_num'], + 'tax_rate' => $item['tax_rate'], + 'remark' => $item['remark'] ?? '' + ]); + } Db::commit(); return true; } catch (\Exception $e) { @@ -112,6 +134,7 @@ class QuotationLogic extends BaseLogic */ public static function delete(array $params): bool { + QuotationDetail::where('quotation_id', $params['id'])->update(['delete_time'=>time()]); return Quotation::destroy($params['id']); } @@ -125,6 +148,8 @@ class QuotationLogic extends BaseLogic */ public static function detail($params): array { - return Quotation::findOrEmpty($params['id'])->toArray(); + $quotation = Quotation::findOrEmpty($params['id']); + $quotation->product = $quotation->product; + return $quotation->toArray(); } } \ No newline at end of file diff --git a/app/adminapi/validate/quotation/QuotationValidate.php b/app/adminapi/validate/quotation/QuotationValidate.php index 0240d91c5..620b0a1dc 100644 --- a/app/adminapi/validate/quotation/QuotationValidate.php +++ b/app/adminapi/validate/quotation/QuotationValidate.php @@ -32,6 +32,7 @@ class QuotationValidate extends BaseValidate */ protected $rule = [ 'id' => 'require', + 'product' => 'require|array|checkProduct', ]; @@ -64,7 +65,7 @@ class QuotationValidate extends BaseValidate */ public function sceneEdit() { - return $this->only(['id']); + return $this->only(['id', 'product']); } @@ -91,4 +92,19 @@ class QuotationValidate extends BaseValidate return $this->only(['id']); } + public function checkProduct($value, $rule, $data) + { + $firstData = $value[0]; + if (empty($firstData['product_id'])) { + return '产品ID不能为空!'; + } + if (empty($firstData['product_num'])) { + return '产品数量不能为空!'; + } + if (empty($firstData['tax_rate'])) { + return '产品税率不能为空!'; + } + return true; + } + } \ No newline at end of file diff --git a/app/common/model/quotation/Quotation.php b/app/common/model/quotation/Quotation.php index 908553f48..ae42977b6 100644 --- a/app/common/model/quotation/Quotation.php +++ b/app/common/model/quotation/Quotation.php @@ -30,5 +30,16 @@ class Quotation extends BaseModel protected $name = 'quotation'; protected $deleteTime = 'delete_time'; + /** + * @notes 关联device + * @return \think\model\relation\HasOne + * @author likeadmin + * @date 2023/11/24 16:34 + */ + public function product() + { + return $this->hasMany(\app\common\model\quotation\QuotationDetail::class, 'quotation_id', 'id'); + } + } \ No newline at end of file