商品下单后增加进货记录的销量,取消和退款后减销量
This commit is contained in:
parent
5e9b8d6968
commit
be67eb8df9
@ -0,0 +1,63 @@
|
||||
<?php
|
||||
|
||||
namespace app\common\repositories\store\order;
|
||||
|
||||
use app\common\model\store\product\PurchaseRecord;
|
||||
use app\common\repositories\BaseRepository;
|
||||
|
||||
class PurchaseRecordRepository extends BaseRepository
|
||||
{
|
||||
|
||||
/**
|
||||
* 扣销量
|
||||
* @param $productId
|
||||
* @param $unique
|
||||
* @param $desc
|
||||
* @return void
|
||||
*/
|
||||
public function descSalesVolume($productId, $unique, $desc)
|
||||
{
|
||||
while ($desc > 0) {
|
||||
$purchaseRecord = $this->getPurchaseRecord2($productId, $unique);
|
||||
if (!$purchaseRecord) {
|
||||
break;
|
||||
}
|
||||
$number = min($desc, $purchaseRecord->sales_volume);
|
||||
$purchaseRecord->sales_volume -= $number;
|
||||
$purchaseRecord->save();
|
||||
$desc -= $number;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 加销量
|
||||
* @param $productId
|
||||
* @param $unique
|
||||
* @param $inc
|
||||
* @return void
|
||||
*/
|
||||
public function incSalesVolume($productId, $unique, $inc)
|
||||
{
|
||||
while ($inc > 0) {
|
||||
$purchaseRecord = $this->getPurchaseRecord($productId, $unique);
|
||||
if (!$purchaseRecord) {
|
||||
break;
|
||||
}
|
||||
$stock = $purchaseRecord->number - $purchaseRecord->sales_volume;
|
||||
$purchaseRecord->sales_volume += min($inc, $stock);
|
||||
$purchaseRecord->save();
|
||||
$inc -= $stock;
|
||||
}
|
||||
}
|
||||
|
||||
public function getPurchaseRecord($productId, $unique)
|
||||
{
|
||||
return PurchaseRecord::where('product_id', $productId)->where('unique', $unique)->whereRaw('sales_volume<number')->order('id asc')->find();
|
||||
}
|
||||
|
||||
public function getPurchaseRecord2($productId, $unique)
|
||||
{
|
||||
return PurchaseRecord::where('product_id', $productId)->where('unique', $unique)->where('sales_volume', '>', 0)->order('id desc')->find();
|
||||
}
|
||||
|
||||
}
|
@ -1169,6 +1169,9 @@ class StoreOrderCreateRepository extends StoreOrderRepository
|
||||
} else {
|
||||
$attrValueRepository->descStock($cart['productAttr']['product_id'], $cart['productAttr']['unique'], $cart['cart_num']);
|
||||
$productRepository->descStock($cart['product']['product_id'], $cart['cart_num']);
|
||||
/** @var PurchaseRecordRepository $purchaseRecordRepo */
|
||||
$purchaseRecordRepo = app()->make(PurchaseRecordRepository::class);
|
||||
$purchaseRecordRepo->incSalesVolume($cart['product']['product_id'], $cart['productAttr']['unique'], $cart['cart_num']);
|
||||
if ($cart['integral'] && $cart['integral']['use'] > 0) {
|
||||
$productRepository->incIntegral($cart['product']['product_id'], $cart['integral']['use'], $cart['integral']['price']);
|
||||
}
|
||||
|
@ -25,6 +25,7 @@ use app\common\repositories\store\coupon\StoreCouponRepository;
|
||||
use app\common\repositories\store\GuaranteeRepository;
|
||||
use app\common\repositories\store\GuaranteeTemplateRepository;
|
||||
use app\common\repositories\store\GuaranteeValueRepository;
|
||||
use app\common\repositories\store\order\PurchaseRecordRepository;
|
||||
use app\common\repositories\store\order\StoreCartRepository;
|
||||
use app\common\repositories\store\order\StoreOrderProductRepository;
|
||||
use app\common\repositories\store\order\StoreOrderRepository;
|
||||
@ -77,8 +78,8 @@ class ProductRepository extends BaseRepository
|
||||
['svip_price_type',0],
|
||||
['params',[]],
|
||||
];
|
||||
protected $admin_filed = 'Product.product_id,Product.mer_id,brand_id,spec_type,unit_name,mer_status,rate,reply_count,store_info,cate_id,Product.image,slider_image,Product.store_name,Product.keyword,Product.sort,U.rank,Product.is_show,Product.sales,Product.price,extension_type,refusal,cost,ot_price,stock,is_gift_bag,Product.care_count,Product.status,is_used,Product.create_time,Product.product_type,old_product_id,star,ficti,integral_total,integral_price_total,sys_labels,param_temp_id,mer_svip_status,svip_price,svip_price_type,update_time';
|
||||
protected $filed = 'Product.bar_code,Product.product_id,Product.mer_id,brand_id,unit_name,spec_type,mer_status,rate,reply_count,store_info,cate_id,Product.image,slider_image,Product.store_name,Product.keyword,Product.sort,Product.is_show,Product.sales,Product.price,extension_type,refusal,cost,ot_price,stock,is_gift_bag,Product.care_count,Product.status,is_used,Product.create_time,Product.product_type,old_product_id,integral_total,integral_price_total,mer_labels,Product.is_good,Product.is_del,type,param_temp_id,mer_svip_status,svip_price,svip_price_type,update_time';
|
||||
protected $admin_filed = 'Product.product_id,Product.mer_id,brand_id,spec_type,unit_name,mer_status,rate,reply_count,store_info,cate_id,Product.image,slider_image,Product.store_name,Product.keyword,Product.sort,U.rank,Product.is_show,Product.sales,Product.price,extension_type,refusal,cost,ot_price,stock,is_gift_bag,Product.care_count,Product.status,is_used,Product.create_time,Product.product_type,old_product_id,star,ficti,integral_total,integral_price_total,sys_labels,param_temp_id,mer_svip_status,svip_price,svip_price_type,update_time,source_product_id';
|
||||
protected $filed = 'Product.bar_code,Product.product_id,Product.mer_id,brand_id,unit_name,spec_type,mer_status,rate,reply_count,store_info,cate_id,Product.image,slider_image,Product.store_name,Product.keyword,Product.sort,Product.is_show,Product.sales,Product.price,extension_type,refusal,cost,ot_price,stock,is_gift_bag,Product.care_count,Product.status,is_used,Product.create_time,Product.product_type,old_product_id,integral_total,integral_price_total,mer_labels,Product.is_good,Product.is_del,type,param_temp_id,mer_svip_status,svip_price,svip_price_type,update_time,source_product_id';
|
||||
|
||||
const NOTIC_MSG = [
|
||||
1 => [
|
||||
@ -1782,6 +1783,9 @@ class ProductRepository extends BaseRepository
|
||||
$this->dao->incStock($oldId, $productNum);
|
||||
} else {
|
||||
$productAttrValueRepository->incStock($cart['product_id'], $cart['cart_info']['productAttr']['unique'], $productNum);
|
||||
/** @var PurchaseRecordRepository $purchaseRecordRepo */
|
||||
$purchaseRecordRepo = app()->make(PurchaseRecordRepository::class);
|
||||
$purchaseRecordRepo->descSalesVolume($cart['product_id'], $cart['cart_info']['productAttr']['unique'], $productNum);
|
||||
$this->dao->incStock($cart['product_id'], $productNum);
|
||||
}
|
||||
if ($cart->integral > 0) {
|
||||
@ -2271,7 +2275,7 @@ class ProductRepository extends BaseRepository
|
||||
$supplierMerId = 0;
|
||||
if (empty($params['product_id']) && !empty($params['order_product_id'])) {
|
||||
//有商品无规格或者无商品无规格,导入商品和规格
|
||||
$product = Db::name('store_product')->where('old_product_id', $params['order_product_id'])->where('mer_id', $merId)->find();
|
||||
$product = Db::name('store_product')->where('source_product_id', $params['order_product_id'])->where('mer_id', $merId)->find();
|
||||
if (!empty($product)) {
|
||||
$unique = $this->importAttrValue($params['order_product_id'], $product, $params['order_unique']);
|
||||
if (!$unique) {
|
||||
@ -2356,7 +2360,7 @@ class ProductRepository extends BaseRepository
|
||||
if (!in_array($find['product_type'], [0, 98])) {
|
||||
throw new \Exception('该商品不是普通商品');
|
||||
}
|
||||
$exist = Db::name('store_product')->where('old_product_id', $product_id)->where('mer_id', $mer_id)->find();
|
||||
$exist = Db::name('store_product')->where('source_product_id', $product_id)->where('mer_id', $mer_id)->find();
|
||||
if ($exist) {
|
||||
throw new \Exception('已经导入过该商品了');
|
||||
}
|
||||
@ -2382,7 +2386,7 @@ class ProductRepository extends BaseRepository
|
||||
$find['is_used'] = 1;
|
||||
$find['status'] = 1;
|
||||
$find['mer_status'] = 1;
|
||||
$find['old_product_id'] = $product_id;
|
||||
$find['source_product_id'] = $product_id;
|
||||
$find['slider_image'] = explode(',', $find['slider_image']);
|
||||
unset($find['product_id'], $find['create_time']);
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user