From 3c8b0c56bb445f39f91a37edb400dc9fed4f2ded Mon Sep 17 00:00:00 2001 From: weiz <736250432@qq.com> Date: Wed, 8 May 2024 16:42:07 +0800 Subject: [PATCH] =?UTF-8?q?=E5=B0=8F=E7=A8=8B=E5=BA=8F=E4=BE=9B=E5=BA=94?= =?UTF-8?q?=E5=95=86=E6=8A=A5=E4=BB=B7=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../OpurchaseGoodsOfferController.php | 25 +++++++++++ .../operation/OpurchaseGoodsOfferList.php | 24 +++++++++-- .../operation/OpurchaseGoodsOfferLogic.php | 21 ++++++++++ .../validate/OpurchaseGoodsOfferValidate.php | 41 +++++++++++++++++++ .../model/opurchase/OpurchaseGoodsOffer.php | 11 ++++- 5 files changed, 117 insertions(+), 5 deletions(-) create mode 100644 app/api/controller/operation/OpurchaseGoodsOfferController.php create mode 100644 app/api/validate/OpurchaseGoodsOfferValidate.php diff --git a/app/api/controller/operation/OpurchaseGoodsOfferController.php b/app/api/controller/operation/OpurchaseGoodsOfferController.php new file mode 100644 index 0000000..471289a --- /dev/null +++ b/app/api/controller/operation/OpurchaseGoodsOfferController.php @@ -0,0 +1,25 @@ +dataLists(new OpurchaseGoodsOfferList()); + } + + public function offer(){ +// if(!$this->request->userInfo['supplier']) return $this->fail('非供应商用户不能报价'); + $params = (new OpurchaseGoodsOfferValidate())->post()->goCheck('offer'); + $result = OpurchaseGoodsOfferLogic::offer($params); + if (true === $result) { + return $this->success('报价成功', [], 1, 1); + } + return $this->fail(OpurchaseGoodsOfferLogic::getError()); + } + } \ No newline at end of file diff --git a/app/api/lists/operation/OpurchaseGoodsOfferList.php b/app/api/lists/operation/OpurchaseGoodsOfferList.php index 8a9a69d..a7a6d46 100644 --- a/app/api/lists/operation/OpurchaseGoodsOfferList.php +++ b/app/api/lists/operation/OpurchaseGoodsOfferList.php @@ -38,12 +38,21 @@ class OpurchaseGoodsOfferList extends BaseAdminDataLists implements ListsSearchI */ public function lists(): array { - $supplier_id=$this->request->userInfo['supplier']['id']; + $supplier_id=$this->request->userInfo['supplier']['id'] ?? 1; + $params = $this->request->get(); + if(isset($params['type']) && $params['type'] == 2){ + $where[] = ['price','<>','']; + }else{ + $where[] = ['price','=','']; + } if(!$supplier_id) return []; - return OpurchaseGoodsOffer::where($this->searchWhere)->where('supplier_id',$supplier_id) + return OpurchaseGoodsOffer::where($this->searchWhere)->where('supplier_id',$supplier_id)->where($where) + ->with('goods') ->limit($this->limitOffset, $this->limitLength) ->order(['id' => 'desc']) - ->select() + ->select()->each(function($data){ + $data['is_adopt_text'] = $data->is_adopt_text; + }) ->toArray(); } @@ -55,7 +64,14 @@ class OpurchaseGoodsOfferList extends BaseAdminDataLists implements ListsSearchI */ public function count(): int { - return OpurchaseGoodsOffer::where($this->searchWhere)->count(); + $supplier_id=$this->request->userInfo['supplier']['id'] ?? 1; + $params = $this->request->get(); + if(isset($params['type']) && $params['type'] == 2){ + $where[] = ['price','<>','']; + }else{ + $where[] = ['price','=','']; + } + return OpurchaseGoodsOffer::where($this->searchWhere)->where('supplier_id',$supplier_id)->where($where)->count(); } } \ No newline at end of file diff --git a/app/api/logic/operation/OpurchaseGoodsOfferLogic.php b/app/api/logic/operation/OpurchaseGoodsOfferLogic.php index a3016db..5486956 100644 --- a/app/api/logic/operation/OpurchaseGoodsOfferLogic.php +++ b/app/api/logic/operation/OpurchaseGoodsOfferLogic.php @@ -2,7 +2,28 @@ namespace app\api\logic\operation; use app\common\logic\BaseLogic; use app\common\model\opurchase\OpurchaseGoodsOffer; +use think\facade\Db; class OpurchaseGoodsOfferLogic extends BaseLogic{ + + public static function offer($params): bool + { + Db::startTrans(); + try { + foreach ($params['data'] as $v){ + OpurchaseGoodsOffer::where('id',$v['id'])->update([ + 'price' => $v['price'], + 'nums' => $v['num'], + 'update_time' => time() + ]); + } + Db::commit(); + return true; + } catch (\Exception $e) { + Db::rollback(); + self::setError($e->getMessage()); + return false; + } + } } diff --git a/app/api/validate/OpurchaseGoodsOfferValidate.php b/app/api/validate/OpurchaseGoodsOfferValidate.php new file mode 100644 index 0000000..4062c4f --- /dev/null +++ b/app/api/validate/OpurchaseGoodsOfferValidate.php @@ -0,0 +1,41 @@ + 'require|checkData', + ]; + + protected $message = [ + 'data.require' => '参数缺失', + ]; + + public function sceneOffer(): OpurchaseGoodsOfferValidate + { + return $this->only(['data']); + } + + public function checkData($value){ + if(!is_array($value)) return '参数数据格式错误'; + foreach($value as $k => $v){ + if(!isset($v['id']) || $v['id'] == ''){ + return '第'.($k+1).'行缺少数据主键'; + }else{ + $data = OpurchaseGoodsOffer::where('id',$v['id'])->where('is_adopt',0)->findOrEmpty(); + if($data->isEmpty()) return '第'.($k+1).'行数据信息不存在'; + } + if(!isset($v['price']) || $v['price'] == '') { + return '第'.($k+1).'行缺少价格'; + } + if(!isset($v['num']) || $v['num'] == '') { + return '第'.($k+1).'行缺少数量'; + } + } + return true; + } + } \ No newline at end of file diff --git a/app/common/model/opurchase/OpurchaseGoodsOffer.php b/app/common/model/opurchase/OpurchaseGoodsOffer.php index 4b214c6..b2b75bb 100644 --- a/app/common/model/opurchase/OpurchaseGoodsOffer.php +++ b/app/common/model/opurchase/OpurchaseGoodsOffer.php @@ -4,6 +4,7 @@ namespace app\common\model\opurchase; use app\common\model\BaseModel; +use app\common\model\goods\Goods; use think\model\concern\SoftDelete; @@ -18,5 +19,13 @@ class OpurchaseGoodsOffer extends BaseModel protected $deleteTime = 'delete_time'; protected $name = 'OpurchaseGoodsOffer'; - + public function getIsAdoptTextAttr($value,$data): string + { + return $data['is_adopt'] == 0 ? '未成交' : '已成交'; + } + + public function goods() + { + return $this->hasOne(Goods::class, 'id', 'goods_id'); + } } \ No newline at end of file