调整商品改价列表
This commit is contained in:
parent
de34b30dbc
commit
ffc0a1999e
@ -111,4 +111,33 @@ class StoreProductPriceController extends BaseAdminController
|
|||||||
return $this->data($data);
|
return $this->data($data);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function setProductPrice($params, $product, $warehouseId = 0, $warehouseProductId = 0)
|
||||||
|
{
|
||||||
|
$priceConfig = [];
|
||||||
|
$data = [
|
||||||
|
'bhoid' => $params['order_id'],
|
||||||
|
'offer_id' => $params['id'],
|
||||||
|
'product_id' => $product['id'],
|
||||||
|
'purchase_price' => $params['purchase'],
|
||||||
|
'create_time' => time(),
|
||||||
|
'update_time' => time(),
|
||||||
|
'status' => 0,
|
||||||
|
'warehouse_id' => $warehouseId,
|
||||||
|
'warehouse_product_id' => $warehouseProductId,
|
||||||
|
];
|
||||||
|
$productPriceRate = self::getProductPriceRate($product);
|
||||||
|
if (!empty($productPriceRate)) {
|
||||||
|
$productService = new ProductPriceService();
|
||||||
|
$priceArray = $productService->setProductPrice($params['purchase'], $productPriceRate);
|
||||||
|
$data = array_merge($data, $priceArray);
|
||||||
|
}
|
||||||
|
$data['price_config'] = $priceConfig;
|
||||||
|
$find = StoreProductPrice::where(['offer_id' => $params['id']])->find();
|
||||||
|
if ($find) {
|
||||||
|
$find->save($data);
|
||||||
|
} else {
|
||||||
|
StoreProductPrice::create($data);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
@ -26,40 +26,35 @@ class StoreProductPriceLogic extends BaseLogic
|
|||||||
/**
|
/**
|
||||||
* @notes 添加
|
* @notes 添加
|
||||||
* @param array $params
|
* @param array $params
|
||||||
* @return bool
|
|
||||||
* @author admin
|
* @author admin
|
||||||
* @date 2025/04/03 15:19
|
* @date 2025/04/03 15:19
|
||||||
*/
|
*/
|
||||||
public static function add(array $params): bool
|
public static function add(array $params)
|
||||||
{
|
{
|
||||||
Db::startTrans();
|
$data = [
|
||||||
try {
|
|
||||||
StoreProductPrice::create([
|
|
||||||
'bhoid' => $params['bhoid'],
|
'bhoid' => $params['bhoid'],
|
||||||
'offer_id' => $params['offer_id'],
|
'offer_id' => $params['offer_id'],
|
||||||
'warehouse_id' => $params['warehouse_id'],
|
|
||||||
'warehouse_product_id' => $params['warehouse_product_id'],
|
|
||||||
'product_id' => $params['product_id'],
|
'product_id' => $params['product_id'],
|
||||||
'purchase_price' => $params['purchase_price'],
|
'purchase_price' => $params['purchase_price'],
|
||||||
'purchase_lv' => $params['purchase_lv'],
|
'create_time' => time(),
|
||||||
'purchase' => $params['purchase'],
|
'update_time' => time(),
|
||||||
'cost_lv' => $params['cost_lv'],
|
'status' => 0,
|
||||||
'cost' => $params['cost'],
|
'warehouse_id' => $params['warehouse_id'],
|
||||||
'price_lv' => $params['price_lv'],
|
'warehouse_product_id' => $params['warehouse_product_id'],
|
||||||
'price' => $params['price'],
|
];
|
||||||
'vip_lv' => $params['vip_lv'],
|
$productPriceRate = self::getProductPriceRate($params['product_id']);
|
||||||
'vip_price' => $params['vip_price'],
|
if (!empty($productPriceRate)) {
|
||||||
'price_config' => $params['price_config'],
|
$priceArray = self::setProductPrice($params['purchase_price'], $productPriceRate);
|
||||||
'mark' => $params['mark'],
|
$data = array_merge($data, $priceArray);
|
||||||
'status' => $params['status'],
|
|
||||||
]);
|
|
||||||
|
|
||||||
Db::commit();
|
|
||||||
return true;
|
|
||||||
} catch (\Throwable $e) {
|
|
||||||
Db::rollback();
|
|
||||||
throw new Exception($e->getMessage());
|
|
||||||
}
|
}
|
||||||
|
$data['price_config'] = [];
|
||||||
|
$find = StoreProductPrice::where(['offer_id' => $params['id']])->find();
|
||||||
|
if ($find) {
|
||||||
|
$find->save($data);
|
||||||
|
} else {
|
||||||
|
StoreProductPrice::create($data);
|
||||||
|
}
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -144,6 +139,11 @@ class StoreProductPriceLogic extends BaseLogic
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 确认改价
|
||||||
|
* @param array $params
|
||||||
|
* @return bool
|
||||||
|
*/
|
||||||
public static function enterPrice(array $params): bool
|
public static function enterPrice(array $params): bool
|
||||||
{
|
{
|
||||||
Db::startTrans();
|
Db::startTrans();
|
||||||
@ -212,7 +212,7 @@ class StoreProductPriceLogic extends BaseLogic
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 设置商品价格
|
* 设置商品分组价格
|
||||||
* @param $purchasePrice float 采购价
|
* @param $purchasePrice float 采购价
|
||||||
* @param $productPriceRate array 价格比例
|
* @param $productPriceRate array 价格比例
|
||||||
* @return array
|
* @return array
|
||||||
@ -228,12 +228,6 @@ class StoreProductPriceLogic extends BaseLogic
|
|||||||
$result['vip_price'] = bcmul($result['purchase'], $result['vip_lv'], 2);
|
$result['vip_price'] = bcmul($result['purchase'], $result['vip_lv'], 2);
|
||||||
$result['price_lv'] = bcdiv($productPriceRate['price_rate'], 100, 2);
|
$result['price_lv'] = bcdiv($productPriceRate['price_rate'], 100, 2);
|
||||||
$result['price'] = bcmul($result['purchase'], $result['price_lv'], 2);
|
$result['price'] = bcmul($result['purchase'], $result['price_lv'], 2);
|
||||||
// 暂时不处理零售价,零售价使用会员价
|
|
||||||
// $lastNum = substr($result['price'], -1);
|
|
||||||
// if ($lastNum > 0) {
|
|
||||||
// $result['price'] = ceil($result['price'] * 10);
|
|
||||||
// $result['price'] = bcdiv($result['price'], 10, 2);
|
|
||||||
// }
|
|
||||||
$lastNum = substr($result['vip_price'], -1);
|
$lastNum = substr($result['vip_price'], -1);
|
||||||
if ($lastNum > 0) {
|
if ($lastNum > 0) {
|
||||||
$result['vip_price'] = ceil($result['vip_price'] * 10);
|
$result['vip_price'] = ceil($result['vip_price'] * 10);
|
||||||
@ -242,6 +236,14 @@ class StoreProductPriceLogic extends BaseLogic
|
|||||||
return $result;
|
return $result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 导出
|
||||||
|
* @param $params
|
||||||
|
* @return string
|
||||||
|
* @throws \think\db\exception\DataNotFoundException
|
||||||
|
* @throws \think\db\exception\DbException
|
||||||
|
* @throws \think\db\exception\ModelNotFoundException
|
||||||
|
*/
|
||||||
public static function export($params)
|
public static function export($params)
|
||||||
{
|
{
|
||||||
$query = StoreProductPrice::field('*');
|
$query = StoreProductPrice::field('*');
|
||||||
@ -270,6 +272,14 @@ class StoreProductPriceLogic extends BaseLogic
|
|||||||
return (new StoreProductPriceXlsx())->export($data);
|
return (new StoreProductPriceXlsx())->export($data);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 商品价格趋势
|
||||||
|
* @param $params
|
||||||
|
* @return array
|
||||||
|
* @throws \think\db\exception\DataNotFoundException
|
||||||
|
* @throws \think\db\exception\DbException
|
||||||
|
* @throws \think\db\exception\ModelNotFoundException
|
||||||
|
*/
|
||||||
public static function chart($params)
|
public static function chart($params)
|
||||||
{
|
{
|
||||||
$list = StoreProductPrice::where('product_id', $params['product_id'])
|
$list = StoreProductPrice::where('product_id', $params['product_id'])
|
||||||
@ -292,4 +302,23 @@ class StoreProductPriceLogic extends BaseLogic
|
|||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取商品价格比例
|
||||||
|
* @param $productId
|
||||||
|
* @return array|int[]
|
||||||
|
*/
|
||||||
|
public static function getProductPriceRate($productId)
|
||||||
|
{
|
||||||
|
$list = StoreProductPriceList::where('product_id', $productId)->findOrEmpty()->toArray();
|
||||||
|
if (empty($list)) {
|
||||||
|
$list = [
|
||||||
|
'supply_rate' => 110,
|
||||||
|
'merchant_rate' => 103,
|
||||||
|
'vip_rate' => 115,
|
||||||
|
'price_rate' => 120,
|
||||||
|
];
|
||||||
|
}
|
||||||
|
return $list;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
@ -20,6 +20,12 @@ class StoreProductPriceValidate extends BaseValidate
|
|||||||
*/
|
*/
|
||||||
protected $rule = [
|
protected $rule = [
|
||||||
'id' => 'require',
|
'id' => 'require',
|
||||||
|
'bhoid' => 'require',
|
||||||
|
'offer_id' => 'require',
|
||||||
|
'warehouse_id' => 'require',
|
||||||
|
'warehouse_product_id' => 'require',
|
||||||
|
'product_id' => 'require',
|
||||||
|
'purchase_price' => 'require',
|
||||||
];
|
];
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user