Merge branch 'feature/purchase_record' into dev

This commit is contained in:
luofei 2023-07-10 16:45:25 +08:00
commit f44067b12f
2 changed files with 28 additions and 26 deletions

View File

@ -2311,31 +2311,32 @@ class ProductRepository extends BaseRepository
$price = $orderProduct['product_price'] ?? 0; $price = $orderProduct['product_price'] ?? 0;
$supplierMerId = $orderMerId ?? 0; $supplierMerId = $orderMerId ?? 0;
} }
if ($stockIn > 0) { if ($stockIn <= 0) {
$attrValue->stock = $attrValue->stock + $stockIn; throw new \Exception('入库数量不能小于等于0');
$attrValue->save(); }
$product->stock = $stockIn + $product->stock; $attrValue->stock = $attrValue->stock + $stockIn;
if (!$product->save()) { $attrValue->save();
throw new \Exception('商品库存保存失败'); $product->stock = $stockIn + $product->stock;
} if (!$product->save()) {
$model = new PurchaseRecord(); throw new \Exception('商品库存保存失败');
$data = [ }
'order_id' => $params['order_id'] ?? 0, $model = new PurchaseRecord();
'order_product_id' => $params['order_product_id'] ?? 0, $data = [
'product_id' => $product->product_id, 'order_id' => $params['order_id'] ?? 0,
'number' => $stockIn, 'order_product_id' => $params['order_product_id'] ?? 0,
'order_unique' => $params['order_unique'] ?? '', 'product_id' => $product->product_id,
'unique' => $attrValue['unique'], 'number' => $stockIn,
'price' => $price, 'order_unique' => $params['order_unique'] ?? '',
'mer_id' => $product->mer_id, 'unique' => $attrValue['unique'],
'supplier_mer_id' => $supplierMerId, 'price' => $price,
]; 'mer_id' => $product->mer_id,
if (!$model->save($data)) { 'supplier_mer_id' => $supplierMerId,
throw new \Exception('入库失败'); ];
} if (!$model->save($data)) {
if (isset($orderProduct) && !$orderProduct->save(['is_imported' => 1])) { throw new \Exception('入库失败');
throw new \Exception('订单商品更新出错'); }
} if (isset($orderProduct) && !$orderProduct->save(['is_imported' => 1])) {
throw new \Exception('订单商品更新出错');
} }
Db::commit(); Db::commit();
} catch (\Exception $e) { } catch (\Exception $e) {

View File

@ -29,7 +29,8 @@ class MerchantUpdateValidate extends Validate
'mer_address|店铺地址' => 'require|max:128', 'mer_address|店铺地址' => 'require|max:128',
'long|店铺经度' => 'max:24', 'long|店铺经度' => 'max:24',
'lat|店铺纬度' => 'max:24', 'lat|店铺纬度' => 'max:24',
'interest_rate|利率' => 'max:0.05', 'interest_rate|利率' => 'min:0.01|max:0.1',
'settle_cycle|结算周期' => 'min:15|max:90',
]; ];
protected function isPhone($val) protected function isPhone($val)