From 4d55c6f19f205ca5ba2495acadf9507970a190c1 Mon Sep 17 00:00:00 2001 From: shengchanzhe <179998674@qq.com> Date: Fri, 27 Oct 2023 16:26:40 +0800 Subject: [PATCH 01/12] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E5=88=86=E9=A1=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/common/repositories/store/product/SpuRepository.php | 1 - 1 file changed, 1 deletion(-) diff --git a/app/common/repositories/store/product/SpuRepository.php b/app/common/repositories/store/product/SpuRepository.php index 4ae0c9f2..74211a68 100644 --- a/app/common/repositories/store/product/SpuRepository.php +++ b/app/common/repositories/store/product/SpuRepository.php @@ -202,7 +202,6 @@ class SpuRepository extends BaseRepository } $where['product_id'] = $randPidList; unset($where['mer_rand_id'], $where['page']); - $page = 1; } $entryMerId = $where['entry_mer_id'] ?? ''; unset($where['entry_mer_id']); From 11dff348e7181b4257982cfe32d047d6504f4a7d Mon Sep 17 00:00:00 2001 From: shengchanzhe <179998674@qq.com> Date: Fri, 27 Oct 2023 19:04:56 +0800 Subject: [PATCH 02/12] =?UTF-8?q?=E6=9B=B4=E6=96=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../community/CommunityRepository.php | 56 ++++++++++--------- 1 file changed, 30 insertions(+), 26 deletions(-) diff --git a/app/common/repositories/community/CommunityRepository.php b/app/common/repositories/community/CommunityRepository.php index 29e139e5..18ea9a83 100644 --- a/app/common/repositories/community/CommunityRepository.php +++ b/app/common/repositories/community/CommunityRepository.php @@ -682,35 +682,39 @@ class CommunityRepository extends BaseRepository $entrustInfo->update($value); continue; } - $purchaseRecord = PurchaseRecord::where('unique', $value['product_attr_unique'])->find(); - $totalNumber = PurchaseRecord::where('unique', $value['product_attr_unique'])->sum('number'); - $totalSalesVolume = PurchaseRecord::where('unique', $value['product_attr_unique'])->sum('sales_volume'); - if (empty($purchaseRecord) || ($totalNumber - $totalSalesVolume) <= 0) { - throw new ValidateException('进货记录不存在或已售罄'); - } - if (($totalNumber - $totalSalesVolume) < $value['number']) { - throw new ValidateException('库存不足'); - } + + // $purchaseRecord = PurchaseRecord::where('unique', $value['product_attr_unique'])->find(); + // $totalNumber = PurchaseRecord::where('unique', $value['product_attr_unique'])->sum('number'); + // $totalSalesVolume = PurchaseRecord::where('unique', $value['product_attr_unique'])->sum('sales_volume'); + // if (empty($purchaseRecord) || ($totalNumber - $totalSalesVolume) <= 0) { + // throw new ValidateException('进货记录不存在或已售罄'); + // } + // if (($totalNumber - $totalSalesVolume) < $value['number']) { + // throw new ValidateException('库存不足'); + // } if ($value) { - $insert[] = [ - 'community_id' => $id, - 'purchase_record_id' => $purchaseRecord['id'], - 'product_id' => $purchaseRecord['product_id'], - 'product_attr_unique' => $purchaseRecord['unique'], - 'mer_id' => $purchaseRecord['mer_id'], - 'entrust_mer_id' => $entrustMerId, - 'entrust_day' => $entrustDay, - 'number' => $value['number'], - 'price' => $value['price'], - 'update_time' => date('Y-m-d H:i:s'), - ]; + $attrValue = ProductAttrValue::where('unique', $value['product_attr_unique'])->find(); + if($attrValue){ + $insert[] = [ + 'community_id' => $id, + 'purchase_record_id' => 0,//$purchaseRecord['id'], + 'product_id' => $attrValue['product_id'], + 'product_attr_unique' => $attrValue['unique'], + 'mer_id' => $attrValue['mer_id'], + 'entrust_mer_id' => $entrustMerId, + 'entrust_day' => $entrustDay, + 'number' => $value['number'], + 'price' => $value['price'], + 'update_time' => date('Y-m-d H:i:s'), + ]; + $attrValue->stock -= $value['number']; + $attrValue->save(); + } } - $purchaseRecord->product->stock -= $value['number']; - $purchaseRecord->product->save(); - $attrValue = ProductAttrValue::where('product_id', $purchaseRecord['product_id'])->where('unique', $purchaseRecord['unique'])->find(); - $attrValue->stock -= $value['number']; - $attrValue->save(); + // $purchaseRecord->product->stock -= $value['number']; + // $purchaseRecord->product->save(); + } if ($insert) { Entrust::getInstance()->insertAll($insert); From dac2051f3d239316283e83cfbc665bafaa4913c4 Mon Sep 17 00:00:00 2001 From: shengchanzhe <179998674@qq.com> Date: Fri, 27 Oct 2023 19:26:10 +0800 Subject: [PATCH 03/12] =?UTF-8?q?=E6=9B=B4=E6=96=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controller/api/store/merchant/MerchantIntention.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/controller/api/store/merchant/MerchantIntention.php b/app/controller/api/store/merchant/MerchantIntention.php index cb89c21e..8d7a202d 100644 --- a/app/controller/api/store/merchant/MerchantIntention.php +++ b/app/controller/api/store/merchant/MerchantIntention.php @@ -195,7 +195,7 @@ class MerchantIntention extends BaseController 'city' => $areaInfo['city_code'] ?? '', 'area' => $merInfo['area_id'] ?? '', 'street' => $merInfo['street_id'] ?? '', - 'address' => $merInfo['address'] ?? '', + 'address' => $intenInfo['address'] ?? '', 'bank_username' => $data['bank_username'] ?? '', 'bank_opening' => $data['bank_opening'] ?? '', 'bank_front' => $data['bank_front'] ?? '', From 79109e7f04fb6eefe1c5dd5c63d10ece62097244 Mon Sep 17 00:00:00 2001 From: shengchanzhe <179998674@qq.com> Date: Fri, 27 Oct 2023 20:14:24 +0800 Subject: [PATCH 04/12] =?UTF-8?q?=E6=9B=B4=E6=96=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/common/repositories/store/product/ProductRepository.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/common/repositories/store/product/ProductRepository.php b/app/common/repositories/store/product/ProductRepository.php index 4889122b..503115ae 100644 --- a/app/common/repositories/store/product/ProductRepository.php +++ b/app/common/repositories/store/product/ProductRepository.php @@ -2370,8 +2370,8 @@ class ProductRepository extends BaseRepository if ($stockIn <= 0) { throw new ValidateException('入库数量不能小于等于0'); } - $attrValue->stock = $attrValue->stock + $stockIn; - $attrValue->save(); + ProductAttrValue::where('mer_id', $merId)->where('product_id', $product['product_id'])->where('sku', $sku)->update(['stock'=>$attrValue->stock + $stockIn]); + $product->stock = $stockIn + $product->stock; if (!$product->save()) { throw new \Exception('商品库存保存失败', 500); From bcd574a3e24a25945a0e8ef15d7857182e8188e7 Mon Sep 17 00:00:00 2001 From: shengchanzhe <179998674@qq.com> Date: Fri, 27 Oct 2023 20:31:21 +0800 Subject: [PATCH 05/12] =?UTF-8?q?=E5=86=8D=E6=AC=A1=E6=9B=B4=E6=96=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/common/repositories/store/product/ProductRepository.php | 1 + 1 file changed, 1 insertion(+) diff --git a/app/common/repositories/store/product/ProductRepository.php b/app/common/repositories/store/product/ProductRepository.php index 503115ae..e7364bc1 100644 --- a/app/common/repositories/store/product/ProductRepository.php +++ b/app/common/repositories/store/product/ProductRepository.php @@ -2370,6 +2370,7 @@ class ProductRepository extends BaseRepository if ($stockIn <= 0) { throw new ValidateException('入库数量不能小于等于0'); } + //111 ProductAttrValue::where('mer_id', $merId)->where('product_id', $product['product_id'])->where('sku', $sku)->update(['stock'=>$attrValue->stock + $stockIn]); $product->stock = $stockIn + $product->stock; From 6d7edcd628118aec4d9ab9c664aea72372f8aa27 Mon Sep 17 00:00:00 2001 From: shengchanzhe <179998674@qq.com> Date: Fri, 27 Oct 2023 20:41:32 +0800 Subject: [PATCH 06/12] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E5=85=A5=E5=BA=93?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../store/product/ProductRepository.php | 31 +++++++++++++++---- 1 file changed, 25 insertions(+), 6 deletions(-) diff --git a/app/common/repositories/store/product/ProductRepository.php b/app/common/repositories/store/product/ProductRepository.php index e7364bc1..1e0966d7 100644 --- a/app/common/repositories/store/product/ProductRepository.php +++ b/app/common/repositories/store/product/ProductRepository.php @@ -2352,12 +2352,33 @@ class ProductRepository extends BaseRepository } $stockIn = $params['number'] ?? 0; $price = $params['price'] ?? 0; + $model = new PurchaseRecord(); if (!empty($params['order_id'])) { //采购、委托订单导入 $orderMerId = StoreOrder::where('order_id', $params['order_id'])->value('mer_id'); $orderProduct = StoreOrderProduct::where('order_id', $params['order_id'])->where('product_id', $params['order_product_id'])->where('product_sku', $params['order_unique'])->find(); - if (empty($orderProduct) || $orderProduct->is_imported == 1) { - throw new ValidateException('订单商品不存在或已入库'); + if (empty($orderProduct)) { + throw new ValidateException('订单商品不存在'); + } + if( $orderProduct->is_imported == 1){ + ProductAttrValue::where('mer_id', $merId) + ->where('product_id', $params['product_id'])->where('unique', $params['unique']) + ->update(['stock'=>$attrValue->stock + $stockIn]); + $data = [ + 'order_id' => $params['order_id'] ?? 0, + 'order_product_id' => $params['order_product_id'] ?? 0, + 'product_id' => $product->product_id, + 'number' => $stockIn, + 'order_unique' => $params['order_unique'] ?? '', + 'unique' => $attrValue['unique'], + 'price' => $price, + 'mer_id' => $product->mer_id, + 'supplier_mer_id' => $supplierMerId, + ]; + if (!$model->save($data)) { + throw new \Exception('入库失败', 500); + } + return true; } $stockIn = $orderProduct['product_num'] ?? 0; $price = $orderProduct['product_price'] ?? 0; @@ -2370,14 +2391,12 @@ class ProductRepository extends BaseRepository if ($stockIn <= 0) { throw new ValidateException('入库数量不能小于等于0'); } - //111 - ProductAttrValue::where('mer_id', $merId)->where('product_id', $product['product_id'])->where('sku', $sku)->update(['stock'=>$attrValue->stock + $stockIn]); - + $attrValue->stock = $attrValue->stock + $stockIn; + $attrValue->save(); $product->stock = $stockIn + $product->stock; if (!$product->save()) { throw new \Exception('商品库存保存失败', 500); } - $model = new PurchaseRecord(); $data = [ 'order_id' => $params['order_id'] ?? 0, 'order_product_id' => $params['order_product_id'] ?? 0, From 41b2df4a81632165edb4a15f2bca8cd71198a099 Mon Sep 17 00:00:00 2001 From: shengchanzhe <179998674@qq.com> Date: Fri, 27 Oct 2023 20:49:08 +0800 Subject: [PATCH 07/12] =?UTF-8?q?=E6=9B=B4=E6=96=B0=E9=BB=98=E8=AE=A4?= =?UTF-8?q?=E5=80=BC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/common/repositories/store/product/ProductRepository.php | 3 +++ 1 file changed, 3 insertions(+) diff --git a/app/common/repositories/store/product/ProductRepository.php b/app/common/repositories/store/product/ProductRepository.php index 1e0966d7..289e4f31 100644 --- a/app/common/repositories/store/product/ProductRepository.php +++ b/app/common/repositories/store/product/ProductRepository.php @@ -2361,6 +2361,9 @@ class ProductRepository extends BaseRepository throw new ValidateException('订单商品不存在'); } if( $orderProduct->is_imported == 1){ + if($stockIn==0){ + $stockIn=1; + } ProductAttrValue::where('mer_id', $merId) ->where('product_id', $params['product_id'])->where('unique', $params['unique']) ->update(['stock'=>$attrValue->stock + $stockIn]); From 79d4d3adb97cdddcfd8062122dbc4af6ff0dd46d Mon Sep 17 00:00:00 2001 From: shengchanzhe <179998674@qq.com> Date: Fri, 27 Oct 2023 21:11:25 +0800 Subject: [PATCH 08/12] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E9=87=87=E8=B4=AD?= =?UTF-8?q?=E5=85=A5=E5=BA=93?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../store/product/ProductRepository.php | 91 +++++++++---------- 1 file changed, 45 insertions(+), 46 deletions(-) diff --git a/app/common/repositories/store/product/ProductRepository.php b/app/common/repositories/store/product/ProductRepository.php index 289e4f31..7d7a6145 100644 --- a/app/common/repositories/store/product/ProductRepository.php +++ b/app/common/repositories/store/product/ProductRepository.php @@ -2328,20 +2328,60 @@ class ProductRepository extends BaseRepository Db::startTrans(); try { $supplierMerId = 0; + $model = new PurchaseRecord(); if (empty($params['product_id']) && !empty($params['order_product_id'])) { //有商品无规格或者无商品无规格,导入商品和规格 $product = $this->getWhere(['source_product_id' => $params['order_product_id'], 'mer_id' => $merId]); + $sku = ProductAttrValue::where('product_id', $params['order_product_id'])->where('unique', $params['order_unique'])->value('sku'); + $attrValue = ProductAttrValue::where('mer_id', $merId)->where('product_id', $product['product_id'])->where('sku', $sku)->find(); if (!empty($product)) { - $unique = $this->importAttrValue($params['order_product_id'], $product->toArray(), $params['order_unique']); - if (!$unique) { - throw new \Exception('商品规格导入出错', 500); + $stockIn = $params['number'] ?? 0; + $price = $params['price'] ?? 0; + if (!empty($params['order_id'])) { + //采购、委托订单导入 + $orderMerId = StoreOrder::where('order_id', $params['order_id'])->value('mer_id'); + $orderProduct = StoreOrderProduct::where('order_id', $params['order_id'])->where('product_id', $params['order_product_id'])->where('product_sku', $params['order_unique'])->find(); + if (empty($orderProduct)) { + $unique = $this->importAttrValue($params['order_product_id'], $product->toArray(), $params['order_unique']); + if (!$unique) { + throw new \Exception('商品规格导入出错', 500); + } + } + if( $orderProduct->is_imported == 1){ + if($stockIn==0){ + $stockIn=1; + } + ProductAttrValue::where('mer_id', $merId) + ->where('product_id', $params['product_id'])->where('unique', $params['unique']) + ->update(['stock'=>$attrValue->stock + $stockIn]); + $data = [ + 'order_id' => $params['order_id'] ?? 0, + 'order_product_id' => $params['order_product_id'] ?? 0, + 'product_id' => $product->product_id, + 'number' => $stockIn, + 'order_unique' => $params['order_unique'] ?? '', + 'unique' => $attrValue['unique'], + 'price' => $price, + 'mer_id' => $product->mer_id, + 'supplier_mer_id' => $supplierMerId, + ]; + if (!$model->save($data)) { + throw new \Exception('入库失败', 500); + } + return true; + } + $stockIn = $orderProduct['product_num'] ?? 0; + $price = $orderProduct['product_price'] ?? 0; + $supplierMerId = $orderMerId ?? 0; + // 如果是委托商品入库后就成为供应链商家的采购类型商品 + if ($orderProduct['product_type'] == 99) { + $product->product_type = 98; + } } } else { $productId = $this->import($params['order_product_id'], request()->userInfo()); $product = $this->get($productId); } - $sku = ProductAttrValue::where('product_id', $params['order_product_id'])->where('unique', $params['order_unique'])->value('sku'); - $attrValue = ProductAttrValue::where('mer_id', $merId)->where('product_id', $product['product_id'])->where('sku', $sku)->find(); } else { //有商品有规格 $product = $this->get($params['product_id']); @@ -2350,47 +2390,6 @@ class ProductRepository extends BaseRepository if (!$product || !$attrValue) { throw new DataNotFoundException('商品或规格不存在'); } - $stockIn = $params['number'] ?? 0; - $price = $params['price'] ?? 0; - $model = new PurchaseRecord(); - if (!empty($params['order_id'])) { - //采购、委托订单导入 - $orderMerId = StoreOrder::where('order_id', $params['order_id'])->value('mer_id'); - $orderProduct = StoreOrderProduct::where('order_id', $params['order_id'])->where('product_id', $params['order_product_id'])->where('product_sku', $params['order_unique'])->find(); - if (empty($orderProduct)) { - throw new ValidateException('订单商品不存在'); - } - if( $orderProduct->is_imported == 1){ - if($stockIn==0){ - $stockIn=1; - } - ProductAttrValue::where('mer_id', $merId) - ->where('product_id', $params['product_id'])->where('unique', $params['unique']) - ->update(['stock'=>$attrValue->stock + $stockIn]); - $data = [ - 'order_id' => $params['order_id'] ?? 0, - 'order_product_id' => $params['order_product_id'] ?? 0, - 'product_id' => $product->product_id, - 'number' => $stockIn, - 'order_unique' => $params['order_unique'] ?? '', - 'unique' => $attrValue['unique'], - 'price' => $price, - 'mer_id' => $product->mer_id, - 'supplier_mer_id' => $supplierMerId, - ]; - if (!$model->save($data)) { - throw new \Exception('入库失败', 500); - } - return true; - } - $stockIn = $orderProduct['product_num'] ?? 0; - $price = $orderProduct['product_price'] ?? 0; - $supplierMerId = $orderMerId ?? 0; - // 如果是委托商品入库后就成为供应链商家的采购类型商品 - if ($orderProduct['product_type'] == 99) { - $product->product_type = 98; - } - } if ($stockIn <= 0) { throw new ValidateException('入库数量不能小于等于0'); } From 31b4169b4598f15c8e8000fccf71cc537f10c5f4 Mon Sep 17 00:00:00 2001 From: shengchanzhe <179998674@qq.com> Date: Fri, 27 Oct 2023 21:26:53 +0800 Subject: [PATCH 09/12] =?UTF-8?q?=E6=9B=B4=E6=96=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/common/repositories/store/product/ProductRepository.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/common/repositories/store/product/ProductRepository.php b/app/common/repositories/store/product/ProductRepository.php index 7d7a6145..f61fda95 100644 --- a/app/common/repositories/store/product/ProductRepository.php +++ b/app/common/repositories/store/product/ProductRepository.php @@ -2352,7 +2352,7 @@ class ProductRepository extends BaseRepository $stockIn=1; } ProductAttrValue::where('mer_id', $merId) - ->where('product_id', $params['product_id'])->where('unique', $params['unique']) + ->where('product_id', $params['product_id']) ->update(['stock'=>$attrValue->stock + $stockIn]); $data = [ 'order_id' => $params['order_id'] ?? 0, @@ -2363,7 +2363,7 @@ class ProductRepository extends BaseRepository 'unique' => $attrValue['unique'], 'price' => $price, 'mer_id' => $product->mer_id, - 'supplier_mer_id' => $supplierMerId, + 'supplier_mer_id' => $orderMerId??0, ]; if (!$model->save($data)) { throw new \Exception('入库失败', 500); From 64ed1355bc389b219c01443205860c0063401f65 Mon Sep 17 00:00:00 2001 From: shengchanzhe <179998674@qq.com> Date: Fri, 27 Oct 2023 21:33:17 +0800 Subject: [PATCH 10/12] =?UTF-8?q?=E6=9B=B4=E6=96=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/common/repositories/store/product/ProductRepository.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/common/repositories/store/product/ProductRepository.php b/app/common/repositories/store/product/ProductRepository.php index f61fda95..26f0d172 100644 --- a/app/common/repositories/store/product/ProductRepository.php +++ b/app/common/repositories/store/product/ProductRepository.php @@ -2352,7 +2352,7 @@ class ProductRepository extends BaseRepository $stockIn=1; } ProductAttrValue::where('mer_id', $merId) - ->where('product_id', $params['product_id']) + ->where('product_id', $product['product_id']) ->update(['stock'=>$attrValue->stock + $stockIn]); $data = [ 'order_id' => $params['order_id'] ?? 0, From 251a7bb1c3ac2324f6d5ee1f6910d8bf9ee48351 Mon Sep 17 00:00:00 2001 From: shengchanzhe <179998674@qq.com> Date: Fri, 27 Oct 2023 21:38:02 +0800 Subject: [PATCH 11/12] =?UTF-8?q?=E6=9B=B4=E6=96=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/common/repositories/store/product/ProductRepository.php | 1 + 1 file changed, 1 insertion(+) diff --git a/app/common/repositories/store/product/ProductRepository.php b/app/common/repositories/store/product/ProductRepository.php index 26f0d172..bd76734e 100644 --- a/app/common/repositories/store/product/ProductRepository.php +++ b/app/common/repositories/store/product/ProductRepository.php @@ -2368,6 +2368,7 @@ class ProductRepository extends BaseRepository if (!$model->save($data)) { throw new \Exception('入库失败', 500); } + Db::commit(); return true; } $stockIn = $orderProduct['product_num'] ?? 0; From e1c15d7eeab62232f55733827c987dae385c5159 Mon Sep 17 00:00:00 2001 From: shengchanzhe <179998674@qq.com> Date: Fri, 27 Oct 2023 21:43:46 +0800 Subject: [PATCH 12/12] =?UTF-8?q?=E6=8F=90=E4=BA=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/common/repositories/store/product/ProductRepository.php | 1 + 1 file changed, 1 insertion(+) diff --git a/app/common/repositories/store/product/ProductRepository.php b/app/common/repositories/store/product/ProductRepository.php index bd76734e..3c5303a6 100644 --- a/app/common/repositories/store/product/ProductRepository.php +++ b/app/common/repositories/store/product/ProductRepository.php @@ -2325,6 +2325,7 @@ class ProductRepository extends BaseRepository */ public function stockIn($merId, $params) { + /**感觉有问题 最好在优化一下结构 */ Db::startTrans(); try { $supplierMerId = 0;