调整商品改价列表

This commit is contained in:
lewis 2025-04-07 10:25:38 +08:00
parent de34b30dbc
commit ffc0a1999e
3 changed files with 181 additions and 117 deletions

View File

@ -111,4 +111,33 @@ class StoreProductPriceController extends BaseAdminController
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);
}
}
}

View File

@ -26,40 +26,35 @@ class StoreProductPriceLogic extends BaseLogic
/**
* @notes 添加
* @param array $params
* @return bool
* @author admin
* @date 2025/04/03 15:19
*/
public static function add(array $params): bool
public static function add(array $params)
{
Db::startTrans();
try {
StoreProductPrice::create([
'bhoid' => $params['bhoid'],
'offer_id' => $params['offer_id'],
'warehouse_id' => $params['warehouse_id'],
'warehouse_product_id' => $params['warehouse_product_id'],
'product_id' => $params['product_id'],
'purchase_price' => $params['purchase_price'],
'purchase_lv' => $params['purchase_lv'],
'purchase' => $params['purchase'],
'cost_lv' => $params['cost_lv'],
'cost' => $params['cost'],
'price_lv' => $params['price_lv'],
'price' => $params['price'],
'vip_lv' => $params['vip_lv'],
'vip_price' => $params['vip_price'],
'price_config' => $params['price_config'],
'mark' => $params['mark'],
'status' => $params['status'],
]);
Db::commit();
return true;
} catch (\Throwable $e) {
Db::rollback();
throw new Exception($e->getMessage());
$data = [
'bhoid' => $params['bhoid'],
'offer_id' => $params['offer_id'],
'product_id' => $params['product_id'],
'purchase_price' => $params['purchase_price'],
'create_time' => time(),
'update_time' => time(),
'status' => 0,
'warehouse_id' => $params['warehouse_id'],
'warehouse_product_id' => $params['warehouse_product_id'],
];
$productPriceRate = self::getProductPriceRate($params['product_id']);
if (!empty($productPriceRate)) {
$priceArray = self::setProductPrice($params['purchase_price'], $productPriceRate);
$data = array_merge($data, $priceArray);
}
$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
{
Db::startTrans();
@ -212,7 +212,7 @@ class StoreProductPriceLogic extends BaseLogic
}
/**
* 设置商品价格
* 设置商品分组价格
* @param $purchasePrice float 采购价
* @param $productPriceRate array 价格比例
* @return array
@ -228,12 +228,6 @@ class StoreProductPriceLogic extends BaseLogic
$result['vip_price'] = bcmul($result['purchase'], $result['vip_lv'], 2);
$result['price_lv'] = bcdiv($productPriceRate['price_rate'], 100, 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);
if ($lastNum > 0) {
$result['vip_price'] = ceil($result['vip_price'] * 10);
@ -242,6 +236,14 @@ class StoreProductPriceLogic extends BaseLogic
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)
{
$query = StoreProductPrice::field('*');
@ -270,6 +272,14 @@ class StoreProductPriceLogic extends BaseLogic
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)
{
$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;
}
}

View File

@ -1,82 +1,88 @@
<?php
namespace app\psi\validate;
use app\common\validate\BaseValidate;
/**
* StoreProductPrice验证器
* Class StoreProductPriceValidate
* @package app\psi\validate
*/
class StoreProductPriceValidate extends BaseValidate
{
/**
* 设置校验规则
* @var string[]
*/
protected $rule = [
'id' => 'require',
];
/**
* 参数描述
* @var string[]
*/
protected $field = [
'id' => 'id',
];
/**
* @notes 添加场景
* @return StoreProductPriceValidate
* @author admin
* @date 2025/04/03 15:19
*/
public function sceneAdd()
{
return $this->remove('id', true);
}
/**
* @notes 编辑场景
* @return StoreProductPriceValidate
* @author admin
* @date 2025/04/03 15:19
*/
public function sceneEdit()
{
return $this->only(['id']);
}
/**
* @notes 删除场景
* @return StoreProductPriceValidate
* @author admin
* @date 2025/04/03 15:19
*/
public function sceneDelete()
{
return $this->only(['id']);
}
/**
* @notes 详情场景
* @return StoreProductPriceValidate
* @author admin
* @date 2025/04/03 15:19
*/
public function sceneDetail()
{
return $this->only(['id']);
}
<?php
namespace app\psi\validate;
use app\common\validate\BaseValidate;
/**
* StoreProductPrice验证器
* Class StoreProductPriceValidate
* @package app\psi\validate
*/
class StoreProductPriceValidate extends BaseValidate
{
/**
* 设置校验规则
* @var string[]
*/
protected $rule = [
'id' => 'require',
'bhoid' => 'require',
'offer_id' => 'require',
'warehouse_id' => 'require',
'warehouse_product_id' => 'require',
'product_id' => 'require',
'purchase_price' => 'require',
];
/**
* 参数描述
* @var string[]
*/
protected $field = [
'id' => 'id',
];
/**
* @notes 添加场景
* @return StoreProductPriceValidate
* @author admin
* @date 2025/04/03 15:19
*/
public function sceneAdd()
{
return $this->remove('id', true);
}
/**
* @notes 编辑场景
* @return StoreProductPriceValidate
* @author admin
* @date 2025/04/03 15:19
*/
public function sceneEdit()
{
return $this->only(['id']);
}
/**
* @notes 删除场景
* @return StoreProductPriceValidate
* @author admin
* @date 2025/04/03 15:19
*/
public function sceneDelete()
{
return $this->only(['id']);
}
/**
* @notes 详情场景
* @return StoreProductPriceValidate
* @author admin
* @date 2025/04/03 15:19
*/
public function sceneDetail()
{
return $this->only(['id']);
}
}