修改商品改价列表

This commit is contained in:
lewis 2025-03-18 15:20:56 +08:00
parent 4be97abe72
commit 98815747f5
6 changed files with 95 additions and 53 deletions

View File

@ -34,7 +34,7 @@ class LocalController extends BaseAdminController
$warehouseOrders = WarehouseOrder::field('id,warehouse_id')->whereIn('id', $warehousingIds)->where('financial_pm', 1)->select()->toArray();
$productSourceLinkInfo = [];
foreach ($warehouseOrders as $order) {
$products = WarehouseProduct::field('id,product_id,nums,purchase')->where('oid', $order['id'])->select()->toArray();
$products = WarehouseProduct::field('id,product_id,nums,purchase,create_time')->where('oid', $order['id'])->select()->toArray();
foreach ($products as $product) {
$productSourceLink = ProductSourceLink::where('product_id', $product['product_id'])->where('purchase_uid', 20)->where('warehouse_id', $order['warehouse_id'])->find();
if (empty($productSourceLink)) {
@ -55,7 +55,7 @@ class LocalController extends BaseAdminController
'link_id' => $product['id'],
'price' => $product['purchase'],
'total_price' => bcmul($product['purchase'], $product['nums'], 2),
'create_time' => time(),
'create_time' => strtotime($product['create_time']),
];
}
}
@ -64,16 +64,17 @@ class LocalController extends BaseAdminController
public function outbound()
{
$warehousingIds = BeforehandOrder::whereIn('id', $this->ids)->where('outbound_id', '>', 0)->column('outbound_id');
$warehouseOrders = WarehouseOrder::field('id,warehouse_id,store_id')->whereIn('id', $warehousingIds)->where('financial_pm', 0)->select()->toArray();
foreach ($warehouseOrders as $order) {
$products = WarehouseProduct::field('id,product_id,nums,purchase')->where('oid', $order['id'])->select()->toArray();
$outboundIds = BeforehandOrder::whereIn('id', $this->ids)->where('outbound_id', '>', 0)->column('outbound_id');
$outboundOrders = WarehouseOrder::field('id,warehouse_id,store_id')->whereIn('id', $outboundIds)->where('financial_pm', 0)->select()->toArray();
foreach ($outboundOrders as $order) {
$products = WarehouseProduct::field('id,product_id,nums,purchase,create_time')->where('oid', $order['id'])->select()->toArray();
foreach ($products as $product) {
ProductSourceLinkLogic::outbound([
'product' => ['product_id' => $product['product_id'], 'nums' => $product['nums']],
'warehouse_id' => $order['warehouse_id'],
'store_id' => $order['store_id'],
'link_id' => $product['id'],
'create_time' => strtotime($product['create_time']),
]);
}
}

View File

@ -4,9 +4,11 @@ namespace app\admin\lists\store_product_price;
use app\admin\lists\BaseAdminDataLists;
use app\admin\service\ProductPriceService;
use app\common\model\store_product_price\StoreProductPrice;
use app\common\lists\ListsSearchInterface;
use app\common\model\store_product\StoreProduct;
use app\common\model\StoreProductPriceList;
use app\common\model\warehouse\Warehouse;
/**
@ -54,7 +56,7 @@ class StoreProductPriceLists extends BaseAdminDataLists implements ListsSearchIn
if (!empty($this->params['end_time'])) {
$this->searchWhere[] = ['create_time', '<=', strtotime($this->params['end_time'])];
}
return StoreProductPrice::where($this->searchWhere)
$list = StoreProductPrice::where($this->searchWhere)
->field(['id','bhoid','offer_id', 'product_id', 'purchase_price', 'purchase_lv', 'purchase', 'cost_lv', 'cost', 'price_lv', 'price', 'vip_lv', 'vip_price', 'price_config', 'status','create_time','mark', 'warehouse_id'])
->limit($this->limitOffset, $this->limitLength)
->order(['id' => 'desc'])
@ -71,6 +73,19 @@ class StoreProductPriceLists extends BaseAdminDataLists implements ListsSearchIn
$item['status_name']=$item['status']==0?"未设置":"已设置";
})
->toArray();
$productIds = array_unique(array_column($list, 'product_id'));
$priceList = StoreProductPriceList::whereIn('product_id', $productIds)->select()->toArray();
$priceList = reset_index($priceList, 'product_id');
$productService = new ProductPriceService();
foreach ($list as &$item) {
$productPrice = $priceList[$item['product_id']] ?? [];
if (empty($productPrice) || $item['status'] == 1) {
continue;
}
$priceArray = $productService->setProductPrice($item['purchase_price'], $productPrice);
$item = array_merge($item, $priceArray);
}
return $list;
}

View File

@ -178,7 +178,7 @@ class ProductSourceLinkLogic extends BaseLogic
'current_nums' => $needNum,
'price' => $item['price'],
'total_price' => bcmul($item['price'], $needNum, 2),
'create_time' => $time,
'create_time' => !empty($info['create_time']) ? $info['create_time'] : $time,
'update_time' => $time,
];
}

View File

@ -3,6 +3,7 @@
namespace app\admin\logic\purchase_product_offer;
use app\admin\service\ProductPriceService;
use app\common\model\purchase_product_offer\PurchaseProductOffer;
use app\common\logic\BaseLogic;
use app\common\model\auth\Admin;
@ -403,24 +404,9 @@ class PurchaseProductOfferLogic extends BaseLogic
];
$productPriceRate = self::getProductPriceRate($product);
if (!empty($productPriceRate)) {
$data['purchase_lv'] = bcdiv($productPriceRate['supply_rate'], 100, 2);
$data['purchase'] = bcmul($params['purchase'], $data['purchase_lv'], 2);
$data['cost_lv'] = bcdiv($productPriceRate['merchant_rate'], 100, 2);
$data['cost'] = bcmul($data['purchase'], $data['cost_lv'], 2);
$data['vip_lv'] = bcdiv($productPriceRate['vip_rate'], 100, 2);
$data['vip_price'] = bcmul($data['purchase'], $data['vip_lv'], 2);
$data['price_lv'] = bcdiv($productPriceRate['price_rate'], 100, 2);
$data['price'] = bcmul($data['purchase'], $data['price_lv'], 2);
$lastNum = substr($data['price'], -1);
if ($lastNum > 0) {
$data['price'] = ceil($data['price'] * 10);
$data['price'] = bcdiv($data['price'], 10, 2);
}
$lastNum = substr($data['vip_price'], -1);
if ($lastNum > 0) {
$data['vip_price'] = ceil($data['vip_price'] * 10);
$data['vip_price'] = bcdiv($data['vip_price'], 10, 2);
}
$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();

View File

@ -3,6 +3,7 @@
namespace app\admin\logic\store_product_price;
use app\admin\service\ProductPriceService;
use app\common\model\store_product_group_price\StoreProductGroupPrice;
use app\common\model\store_product_price\StoreProductPrice;
use app\common\logic\BaseLogic;
@ -57,6 +58,7 @@ class StoreProductPriceLogic extends BaseLogic
{
Db::startTrans();
try {
$postData = $params;
$find = StoreProductPrice::where('id', $params['id'])->find();
if ($find) {
$changePurchase = false;
@ -78,26 +80,29 @@ class StoreProductPriceLogic extends BaseLogic
if ($find['price_lv'] != $params['price_lv']) {
$params = self::updateProductPriceList2($find['product_id'], 'price_rate', $params['price_lv'], $params, 'price', $params['purchase']);
}
$lastNum = substr($params['price'], -1);
if ($lastNum > 0) {
$params['price'] = ceil($params['price'] * 10);
$params['price'] = bcdiv($params['price'], 10, 2);
}
$lastNum = substr($params['vip_price'], -1);
if ($lastNum > 0) {
$params['vip_price'] = ceil($params['vip_price'] * 10);
$params['vip_price'] = bcdiv($params['vip_price'], 10, 2);
}
$params['supply_rate'] = bcmul($params['purchase_lv'], 100);
$params['merchant_rate'] = bcmul($params['cost_lv'], 100);
$params['vip_rate'] = bcmul($params['vip_lv'], 100);
$params['price_rate'] = bcmul($params['price_lv'], 100);
$productService = new ProductPriceService();
$priceArray = $productService->setProductPrice($find['purchase_price'], $params);
// 计算出的价格与提交价格不同时,以提交价格为准
$priceArray['purchase'] = $postData['purchase'] != $priceArray['pxurchase'] ? $postData['purchase'] : $priceArray['purchase'];
$priceArray['cost'] = $postData['cost'] != $priceArray['cost'] ? $postData['cost'] : $priceArray['cost'];
$priceArray['vip_price'] = $postData['vip_price'] != $priceArray['vip_price'] ? $postData['vip_price'] : $priceArray['vip_price'];
$priceArray['price'] = $postData['price'] != $priceArray['price'] ? $postData['price'] : $priceArray['price'];
$find->save([
'status' => 1,
'purchase' => $params['purchase'],
'purchase_lv' => $params['purchase_lv'],
'cost' => $params['cost'],
'cost_lv' => $params['cost_lv'],
'vip_price' => $params['vip_price'],
'vip_lv' => $params['vip_lv'],
'price' => $params['price'],
'price_lv' => $params['price_lv'],
'purchase' => $priceArray['purchase'],
'purchase_lv' => $priceArray['purchase_lv'],
'cost' => $priceArray['cost'],
'cost_lv' => $priceArray['cost_lv'],
'vip_price' => $priceArray['vip_price'],
'vip_lv' => $priceArray['vip_lv'],
'price' => $priceArray['price'],
'price_lv' => $priceArray['price_lv'],
'price_config' => $params['price_config'],
]);
StoreProduct::where('id', $find['product_id'])->update([
@ -167,16 +172,12 @@ class StoreProductPriceLogic extends BaseLogic
try {
$find = StoreProductPrice::where('id', $params['id'])->find();
if ($find) {
$productService = new ProductPriceService();
$productPriceRate = StoreProductPriceList::whereIn('product_id', $find['product_id'])->findOrEmpty()->toArray();
$update = ['status' => 1];
$lastNum = substr($find['price'], -1);
if ($lastNum > 0) {
$update['price'] = ceil($find['price'] * 10);
$update['price'] = bcdiv($update['price'], 10, 2);
}
$lastNum = substr($find['vip_price'], -1);
if ($lastNum > 0) {
$update['vip_price'] = ceil($find['vip_price'] * 10);
$update['vip_price'] = bcdiv($update['vip_price'], 10, 2);
if (!empty($productPriceRate)) {
$update = $productService->setProductPrice($find['purchase_price'], $productPriceRate);
$update['status'] = 1;
}
$find->save($update);
StoreProduct::where('id', $find['product_id'])->update([

View File

@ -0,0 +1,39 @@
<?php
namespace app\admin\service;
class ProductPriceService
{
/**
* 设置商品价格
* @param $purchasePrice float 采购价
* @param $productPriceRate array 价格比例
* @return array
*/
public function setProductPrice(float $purchasePrice, array $productPriceRate)
{
$result = [];
$result['purchase_lv'] = bcdiv($productPriceRate['supply_rate'], 100, 2);
$result['purchase'] = bcmul($purchasePrice, $result['purchase_lv'], 2);
$result['cost_lv'] = bcdiv($productPriceRate['merchant_rate'], 100, 2);
$result['cost'] = bcmul($result['purchase'], $result['cost_lv'], 2);
$result['vip_lv'] = bcdiv($productPriceRate['vip_rate'], 100, 2);
$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);
$result['vip_price'] = bcdiv($result['vip_price'], 10, 2);
}
return $result;
}
}