商品列表添加改价
This commit is contained in:
parent
ed4d7bb3ae
commit
41264fd9a0
@ -6,6 +6,7 @@ namespace app\admin\controller\store_product_price;
|
||||
use app\admin\controller\BaseAdminController;
|
||||
use app\admin\lists\store_product_price\StoreProductPriceLists;
|
||||
use app\admin\logic\store_product_price\StoreProductPriceLogic;
|
||||
use app\admin\service\ProductPriceService;
|
||||
use app\admin\validate\store_product_price\StoreProductPriceValidate;
|
||||
|
||||
|
||||
@ -114,4 +115,21 @@ class StoreProductPriceController extends BaseAdminController
|
||||
return $this->data($data);
|
||||
}
|
||||
|
||||
public function getRate(ProductPriceService $productPriceService)
|
||||
{
|
||||
$params = $this->request->get();
|
||||
$productPriceRate = $productPriceService->getProductPriceRate($params['product_id'], true);
|
||||
return $this->data($productPriceRate);
|
||||
}
|
||||
|
||||
public function create()
|
||||
{
|
||||
$params = request()->post();
|
||||
$result = StoreProductPriceLogic::add($params);
|
||||
if (true === $result) {
|
||||
return $this->success('添加成功', [], 1, 1);
|
||||
}
|
||||
return $this->fail(StoreProductPriceLogic::getError());
|
||||
}
|
||||
|
||||
}
|
@ -4,15 +4,11 @@ namespace app\admin\logic\product_source_link;
|
||||
|
||||
|
||||
use app\admin\logic\product_source_link_info\ProductSourceLinkInfoLogic;
|
||||
use app\admin\logic\purchase_product_offer\PurchaseProductOfferLogic;
|
||||
use app\common\model\inventory_transfer\InventoryTransfer;
|
||||
use app\admin\service\ProductPriceService;
|
||||
use app\common\model\product_source_link\ProductSourceLink;
|
||||
use app\common\logic\BaseLogic;
|
||||
use app\common\model\product_source_link_info\ProductSourceLinkInfo;
|
||||
use support\exception\BusinessException;
|
||||
use think\db\exception\DataNotFoundException;
|
||||
use think\db\exception\DbException;
|
||||
use think\db\exception\ModelNotFoundException;
|
||||
use think\facade\Db;
|
||||
|
||||
|
||||
@ -57,7 +53,7 @@ class ProductSourceLinkLogic extends BaseLogic
|
||||
];
|
||||
if ($attrs['types'] == ProductSourceLinkInfo::TypeIn) {
|
||||
// 商品入库,记录采购总价和供货总价
|
||||
$priceRate = PurchaseProductOfferLogic::getProductPriceRate(['id' => $offer['product_id']]);
|
||||
$priceRate = (new ProductPriceService())->getProductPriceRate($offer['product_id']);
|
||||
$attrs['purchase_price'] = $offer['total_price'];
|
||||
$rate = bcdiv($priceRate['supply_rate'], 100, 2);
|
||||
$attrs['supply_price'] = bcmul(bcmul($offer['price'], $rate, 2), $offer['nums'], 2);
|
||||
|
@ -3,8 +3,7 @@
|
||||
namespace app\admin\logic\product_source_link_info;
|
||||
|
||||
|
||||
use app\admin\logic\product_source_link\ProductSourceLinkLogic;
|
||||
use app\admin\logic\purchase_product_offer\PurchaseProductOfferLogic;
|
||||
use app\admin\service\ProductPriceService;
|
||||
use app\common\model\inventory_transfer\InventoryTransfer;
|
||||
use app\common\model\product_source_link\ProductSourceLink;
|
||||
use app\common\model\product_source_link_info\ProductSourceLinkInfo;
|
||||
@ -151,7 +150,7 @@ class ProductSourceLinkInfoLogic extends BaseLogic
|
||||
];
|
||||
if ($attrs['types'] == ProductSourceLinkInfo::TypeIn) {
|
||||
// 商品入库,记录采购总价和供货总价
|
||||
$priceRate = PurchaseProductOfferLogic::getProductPriceRate(['id' => $this->purchaseProductOffer['product_id']]);
|
||||
$priceRate = (new ProductPriceService())->getProductPriceRate($this->purchaseProductOffer['product_id']);
|
||||
$attrs['purchase_price'] = $this->purchaseProductOffer['total_price'];
|
||||
$rate = bcdiv($priceRate['supply_rate'], 100, 2);
|
||||
$attrs['supply_price'] = bcmul(bcmul($this->purchaseProductOffer['price'], $rate, 2), $this->purchaseProductOffer['nums'], 2);
|
||||
|
@ -410,9 +410,9 @@ class PurchaseProductOfferLogic extends BaseLogic
|
||||
'warehouse_id' => $warehouseId,
|
||||
'warehouse_product_id' => $warehouseProductId,
|
||||
];
|
||||
$productPriceRate = self::getProductPriceRate($product);
|
||||
$productService = new ProductPriceService();
|
||||
$productPriceRate = $productService->getProductPriceRate($product['id']);
|
||||
if (!empty($productPriceRate)) {
|
||||
$productService = new ProductPriceService();
|
||||
$priceArray = $productService->setProductPrice($params['purchase'], $productPriceRate);
|
||||
$data = array_merge($data, $priceArray);
|
||||
}
|
||||
@ -425,6 +425,11 @@ class PurchaseProductOfferLogic extends BaseLogic
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated 已废弃,使用(new ProductPriceService())->getProductPriceRate($product['id'])
|
||||
* @param $product
|
||||
* @return array|int[]
|
||||
*/
|
||||
public static function getProductPriceRate($product)
|
||||
{
|
||||
$list = StoreProductPriceList::where('product_id', $product['id'])->findOrEmpty()->toArray();
|
||||
|
@ -37,7 +37,31 @@ class StoreProductPriceLogic extends BaseLogic
|
||||
{
|
||||
Db::startTrans();
|
||||
try {
|
||||
StoreProductPrice::create([]);
|
||||
$model = StoreProductPrice::create($params);
|
||||
|
||||
$productPrice = StoreProduct::where('id', $model['product_id'])->value('vip_price');
|
||||
if ($productPrice != $model['vip_price']) {
|
||||
SqlChannelPriceLog($model['product_id'], 43, $productPrice, $model['vip_price']);
|
||||
}
|
||||
|
||||
StoreProduct::where('id', $model['product_id'])->update([
|
||||
'purchase' => $model['purchase'],
|
||||
'cost' => $model['cost'],
|
||||
'vip_price' => $model['vip_price'],
|
||||
'price' => $model['vip_price'],
|
||||
'ot_price' => $model['price']
|
||||
]);
|
||||
StoreBranchProduct::where('product_id', $model['product_id'])->update([
|
||||
'purchase' => $model['purchase'],
|
||||
'cost' => $model['cost'],
|
||||
'vip_price' => $model['vip_price'],
|
||||
'price' => $model['vip_price'],
|
||||
'ot_price' => $model['price']
|
||||
]);
|
||||
|
||||
$productSourceLinkInfoLogic = new ProductSourceLinkInfoLogic();
|
||||
$productSourceLinkInfoLogic->storeProductPrice = $model;
|
||||
$productSourceLinkInfoLogic->updateSupplyPrice();
|
||||
|
||||
Db::commit();
|
||||
return true;
|
||||
|
@ -2,6 +2,9 @@
|
||||
|
||||
namespace app\admin\service;
|
||||
|
||||
use app\common\model\store_product\StoreProduct;
|
||||
use app\common\model\StoreProductPriceList;
|
||||
|
||||
class ProductPriceService
|
||||
{
|
||||
|
||||
@ -36,4 +39,42 @@ class ProductPriceService
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $productId int 商品id
|
||||
* @param $percent bool 是否返回百分比
|
||||
* @return array|int[]
|
||||
* @throws \think\db\exception\DataNotFoundException
|
||||
* @throws \think\db\exception\DbException
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
*/
|
||||
public function getProductPriceRate($productId, $percent = false)
|
||||
{
|
||||
$list = StoreProductPriceList::where('product_id', $productId)->findOrEmpty()->toArray();
|
||||
$product = StoreProduct::where('id', $productId)->field('id,store_name,top_cate_id,cate_id')->find();
|
||||
if (empty($list)) {
|
||||
if ($product->isSpecial()) {
|
||||
$list = [
|
||||
'supply_rate' => 102,
|
||||
'merchant_rate' => 102,
|
||||
'vip_rate' => 104,
|
||||
'price_rate' => 108,
|
||||
];
|
||||
} else {
|
||||
$list = [
|
||||
'supply_rate' => 105,
|
||||
'merchant_rate' => 105,
|
||||
'vip_rate' => 108,
|
||||
'price_rate' => 112,
|
||||
];
|
||||
}
|
||||
}
|
||||
if ($percent) {
|
||||
$list['supply_rate'] = $list['supply_rate'] / 100;
|
||||
$list['merchant_rate'] = $list['merchant_rate'] / 100;
|
||||
$list['vip_rate'] = $list['vip_rate'] / 100;
|
||||
$list['price_rate'] = $list['price_rate'] / 100;
|
||||
}
|
||||
return $list;
|
||||
}
|
||||
|
||||
}
|
@ -55,4 +55,13 @@ class StoreProduct extends BaseModel
|
||||
Log::error('product:'.$e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
public function isSpecial()
|
||||
{
|
||||
if (in_array($this->top_cate_id, [15189, 6]) || in_array($this->cate_id, [15551, 15552,15569,15570]) || mb_strpos($this->store_name, '鸡精') !== false || mb_strpos($this->store_name, '生抽') !== false || mb_strpos($this->store_name, '多宝鱼') !== false || mb_strpos($this->store_name, '小青虾') !== false) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user