Merge pull request 'dev' () from dev into main

Reviewed-on: 
This commit is contained in:
mkm 2025-03-18 16:15:08 +08:00
commit a20a7eb8b4
9 changed files with 115 additions and 58 deletions
app/admin
controller
lists
beforehand_order
beforehand_order_cart_info
store_product_price
warehouse_product
logic
product_source_link
purchase_product_offer
store_product_price
service

@ -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']),
]);
}
}

@ -34,7 +34,7 @@ class BeforehandOrderLists extends BaseAdminDataLists implements ListsSearchInte
public function setSearch(): array
{
return [
'=' => ['store_id', 'paid', 'status', 'order_type', 'admin_id'],
'=' => ['id', 'store_id', 'paid', 'status', 'order_type', 'admin_id'],
'%like' => ['order_id','order_sn'],
'%like%' => ['mark'],
'between_time' => 'create_time'

@ -76,6 +76,10 @@ class BeforehandOrderCartInfoLists extends BaseAdminDataLists implements ListsSe
$this->searchWhere[] = ['product_id', 'in', $ids];
}
}
if (!empty($this->params['store_id'])) {
$orderIds = BeforehandOrder::where('store_id', $this->params['store_id'])->column('id');
$this->searchWhere[] = ['bhoid', 'in', $orderIds];
}
$list = BeforehandOrderCartInfo::where($this->searchWhere)
->field(['id', 'bhoid', 'package', 'store_info', 'marques', 'gross_weight', 'net_weight', 'accept_num', 'after_sales', 'loss', 'uid', 'pay_price', 'is_buyer', 'buyer_uid', 'product_id', 'attr_value_id', 'purchase', 'price', 'total_price', 'cart_num', 'mark','create_time', 'procurement_order_id', 'store_sale'])
->limit($this->limitOffset, $this->limitLength)
@ -137,6 +141,10 @@ class BeforehandOrderCartInfoLists extends BaseAdminDataLists implements ListsSe
*/
public function count(): int
{
if (!empty($this->params['store_id'])) {
$orderIds = BeforehandOrder::where('store_id', $this->params['store_id'])->column('id');
$this->searchWhere[] = ['bhoid', 'in', $orderIds];
}
return BeforehandOrderCartInfo::where($this->searchWhere)->count();
}

@ -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;
}

@ -76,9 +76,12 @@ class WarehouseProductLists extends BaseAdminDataLists implements ListsSearchInt
}
$query = WarehouseProduct::where($this->searchWhere);
if (isset($this->params['is_group']) && $this->params['is_group'] == 1) {
$query->group('product_id')->field(['id', 'code','pay_type','oid','admin_id','supplier_id', 'store_id', 'warehouse_id', 'product_id', 'financial_pm', 'batch', 'sum(nums) nums', 'price', 'purchase', 'cost', 'sum(total_price) total_price', 'manufacture', 'expiration_date', 'status', 'mark', 'create_time','is_pay', 'order_type','vip_price']);
$query->group('product_id')->field(['id', 'code','pay_type','oid','admin_id','supplier_id', 'store_id', 'warehouse_id', 'product_id', 'financial_pm', 'batch', 'sum(nums) nums', 'price', 'purchase', 'cost', 'sum(total_price) total_price', 'manufacture', 'expiration_date', 'status', 'mark', 'create_time','is_pay', 'order_type','vip_price', 'delete_time']);
} else {
$query->field(['id', 'code','pay_type','oid','admin_id','supplier_id', 'store_id', 'warehouse_id', 'product_id', 'financial_pm', 'batch', 'nums', 'price', 'purchase', 'cost', 'total_price', 'manufacture', 'expiration_date', 'status', 'mark', 'create_time','is_pay', 'order_type','vip_price']);
$query->field(['id', 'code','pay_type','oid','admin_id','supplier_id', 'store_id', 'warehouse_id', 'product_id', 'financial_pm', 'batch', 'nums', 'price', 'purchase', 'cost', 'total_price', 'manufacture', 'expiration_date', 'status', 'mark', 'create_time','is_pay', 'order_type','vip_price', 'delete_time']);
}
if (!empty($this->params['product_status'])) {
$query->onlyTrashed();
}
return $query
->limit($this->limitOffset, $this->limitLength)
@ -168,10 +171,14 @@ class WarehouseProductLists extends BaseAdminDataLists implements ListsSearchInt
*/
public function count(): int
{
$query = WarehouseProduct::where($this->searchWhere);
if (!empty($this->params['product_status'])) {
$query->onlyTrashed();
}
if ($this->ids) {
return WarehouseProduct::whereIn('id', $this->ids)->where($this->searchWhere)->count();
return $query->whereIn('id', $this->ids)->count();
} else {
return WarehouseProduct::where($this->searchWhere)->count();
return $query->count();
}
}
/**

@ -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,
];
}

@ -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();

@ -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([

@ -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;
}
}