修改自营门店价格

This commit is contained in:
lewis 2025-01-21 15:48:03 +08:00
parent 63f4285759
commit db9257518e
5 changed files with 116 additions and 48 deletions

View File

@ -258,7 +258,10 @@ class BeforehandOrderCartInfoLogic extends BaseLogic
if ($beforehandOrder['order_type'] == 7) {
$attrs['is_buying'] = 1;
}
BeforehandOrder::where('id', $params['bhoid'])->update($attrs);
$result = BeforehandOrder::where('id', $params['bhoid'])->where('warehousing_id', 0)->where('is_warehousing', 0)->update($attrs);
if (!$result) {
throw new BusinessException('出库失败,预订单更新出错');
}
Db::commit();
return true;
} catch (\Throwable $e) {

View File

@ -238,13 +238,6 @@ class WarehouseProductLogic extends BaseLogic
$datas['expiration_date'] = strtotime($params['expiration_date']);
}
$res->save($datas);
$finds = WarehouseProduct::where('oid', $params['oid'])->field('sum(nums) as nums,sum(total_price) as total_price')->find();
if ($finds) {
WarehouseOrder::where('id', $params['oid'])->update([
'nums' => $finds['nums'],
'total_price' => $finds['total_price']
]);
}
}
Db::commit();
return $res;
@ -266,22 +259,20 @@ class WarehouseProductLogic extends BaseLogic
{
$res = WarehouseProduct::where('id', $params['id'])->find();
if ($res) {
$res->delete();
if ($res['financial_pm'] == 1) {
$find = WarehouseProductStorege::where('warehouse_id', $res['warehouse_id'])->where('product_id', $res['product_id'])->dec('nums', $res['nums'])->save();
SqlChannelLog('WarehouseProductStorege', $find['id'], $res['nums'], -1, Request()->url(),$admin_id);
} elseif ($res['financial_pm'] == 0) {
$find = WarehouseProductStorege::where('warehouse_id', $res['warehouse_id'])->where('product_id', $res['product_id'])->inc('nums', $res['nums'])->save();
SqlChannelLog('WarehouseProductStorege', $find['id'], $res['nums'], 1, Request()->url(),$admin_id);
Db::startTrans();
try {
if ($res['financial_pm'] == 1) {
self::incProductDecStorege($res, $res['nums'], $admin_id);
} elseif ($res['financial_pm'] == 0) {
self::decProductIncStorege($res, $res['nums'], $admin_id);
}
$res->delete();
Db::commit();
return true;
} catch (\Throwable $th) {
Db::rollback();
throw new BusinessException($th->getMessage());
}
$find = WarehouseProduct::where('oid', $res['oid'])->field('sum(nums) as nums,sum(total_price) as total_price')->find();
if ($find) {
WarehouseOrder::where('id', $res['oid'])->update([
'nums' => $find['nums'],
'total_price' => $find['total_price']
]);
}
return true;
}
throw new BusinessException('没有查到出入库信息');
}
@ -339,12 +330,6 @@ class WarehouseProductLogic extends BaseLogic
}
$res->save($datas);
$finds = WarehouseProduct::where('oid', $res['oid'])->field('sum(nums) as nums')->find();
if ($finds) {
WarehouseOrder::where('id', $res['oid'])->update([
'nums' => $finds['nums'],
]);
}
}
Db::commit();
} catch (\Throwable $th) {
@ -370,28 +355,84 @@ class WarehouseProductLogic extends BaseLogic
}
//减少
private static function decProductIncStorege($res,$nums,$admin_id=0)
private static function decProductIncStorege($warehouseProduct,$nums,$admin_id=0)
{
$res1 = WarehouseProductStorege::where('warehouse_id', $res['warehouse_id'])
->where('product_id', $res['product_id'])->find();
$res1->nums = bcadd($res1->nums,$nums,2);
$res1->save();
SqlChannelLog('WarehouseProductStorege', $res1['id'], $nums, 1, Request()->url(),$admin_id);
WarehouseProduct::where('id',$res['id'])->update(['nums'=>bcsub($res['nums'],$nums,2)]);
SqlChannelLog('WarehouseProduct', $res['id'], $nums, -1, Request()->url(),$admin_id);
$warehouseProductStorage = WarehouseProductStorege::where('warehouse_id', $warehouseProduct['warehouse_id'])
->where('product_id', $warehouseProduct['product_id'])->find();
$warehouseProductStorage->nums = bcadd($warehouseProductStorage->nums,$nums,2);
$warehouseProductStorage->save();
SqlChannelLog('WarehouseProductStorege', $warehouseProductStorage['id'], $nums, 1, Request()->url(),$admin_id);
$update = [
'nums' => bcsub($warehouseProduct['nums'], $nums, 2),
'total_price' => bcsub($warehouseProduct['total_price'], bcmul($nums, $warehouseProduct['price'], 2), 2),
];
WarehouseProduct::where('id',$warehouseProduct['id'])->update($update);
SqlChannelLog('WarehouseProduct', $warehouseProduct['id'], $nums, -1, Request()->url(),$admin_id);
$find = WarehouseProduct::where('oid', $warehouseProduct['oid'])->field('sum(nums) as nums,sum(total_price) as total_price')->find();
if ($find) {
WarehouseOrder::where('id', $warehouseProduct['oid'])->update([
'nums' => $find['nums'],
'total_price' => $find['total_price']
]);
}
self::updateStoreStorage($warehouseProduct['oid'], $nums, 'dec');
}
//增加
private static function incProductDecStorege($res, $nums,$admin_id=0)
private static function incProductDecStorege($warehouseProduct, $nums,$admin_id=0)
{
$res1 = WarehouseProductStorege::where('warehouse_id', $res['warehouse_id'])
->where('product_id', $res['product_id'])->find();
$res1->nums = bcsub($res1->nums,$nums,2);
$res1->save();
SqlChannelLog('WarehouseProductStorege', $res1['id'], $nums, -1, Request()->url(),$admin_id);
$warehouseProductStorage = WarehouseProductStorege::where('warehouse_id', $warehouseProduct['warehouse_id'])
->where('product_id', $warehouseProduct['product_id'])->find();
$warehouseProductStorage->nums = bcsub($warehouseProductStorage->nums,$nums,2);
$warehouseProductStorage->save();
SqlChannelLog('WarehouseProductStorege', $warehouseProductStorage['id'], $nums, -1, Request()->url(),$admin_id);
WarehouseProduct::where('id',$res['id'])->update(['nums'=>bcadd($res['nums'],$nums,2)]);
SqlChannelLog('WarehouseProduct', $res['id'], $nums, 1, Request()->url(),$admin_id);
$update = [
'nums' => bcadd($warehouseProduct['nums'], $nums, 2),
'total_price' => bcadd($warehouseProduct['total_price'], bcmul($nums, $warehouseProduct['price'], 2), 2),
];
WarehouseProduct::where('id',$warehouseProduct['id'])->update($update);
SqlChannelLog('WarehouseProduct', $warehouseProduct['id'], $nums, 1, Request()->url(),$admin_id);
$find = WarehouseProduct::where('oid', $warehouseProduct['oid'])->field('sum(nums) as nums,sum(total_price) as total_price')->find();
if ($find) {
WarehouseOrder::where('id', $warehouseProduct['oid'])->update([
'nums' => $find['nums'],
'total_price' => $find['total_price']
]);
}
self::updateStoreStorage($warehouseProduct['oid'], $nums);
}
/**
* 更新门店库存和门店入库单
* @param $outboundId
* @param $nums
* @param $type
* @return void
*/
private static function updateStoreStorage($outboundId, $nums, $type = 'inc')
{
$storeStorage = SystemStoreStorage::where('outbound_id', $outboundId)->find();
if (empty($storeStorage)) {
return;
}
$storeStorage->nums = $type == 'inc' ? $storeStorage->nums + $nums : $storeStorage->nums - $nums;
$storeStorage->save();
if ($storeStorage->status == 0) {
return;
}
// 门店入库单已确认,增加/减少 门店库存
$storeBranchProduct = StoreBranchProduct::where('store_id', $storeStorage->store_id)
->where('product_id', $storeStorage->product_id)->find();
if (!empty($storeBranchProduct)) {
$storeBranchProduct->stock = $type == 'inc' ? $storeBranchProduct->stock + $nums : $storeBranchProduct->stock - $nums;
$storeBranchProduct->save();
}
}
}

View File

@ -10,6 +10,7 @@ use app\common\model\store_product\StoreProduct;
use app\common\lists\ListsSearchInterface;
use app\common\model\Config;
use app\common\model\store_product_group_price\StoreProductGroupPrice;
use app\common\model\system_store\SystemStore;
use app\common\model\user\User;
//use app\common\model\goods\GoodsLabel;
use think\facade\Db;
@ -104,7 +105,7 @@ class ProductLists extends BaseApiDataLists implements ListsSearchInterface, Lis
$user_ship=-1;
if ($uid > 0) {
$user_ship = User::where('id', $uid)->value('user_ship');
if (in_array($user_ship, [4, 6, 7])) {
if (in_array($user_ship, [4, 6, 7]) && !empty($this->params['store_id']) && !SystemStore::isSelfOperate($this->params['store_id'])) {
$fields = 'id,id product_id,top_cate_id,cate_id,store_name,cost,vip_price,purchase,cost price,bar_code,image,sales,store_info,delete_time,unit,batch,top_cate_id,two_cate_id,stock,is_lack';
}
}
@ -128,7 +129,7 @@ class ProductLists extends BaseApiDataLists implements ListsSearchInterface, Lis
return $item;
})
->toArray();
$list = StoreProductGroupPrice::resetProductsPrice($list, $user_ship);
$list = StoreProductGroupPrice::resetStoreProductPrice($list, $user_ship, $this->params['store_id'] ?? 0);
return $list;
}

View File

@ -4,6 +4,7 @@ namespace app\common\model\store_product_group_price;
use app\common\model\BaseModel;
use app\common\model\system_store\SystemStore;
use think\model\concern\SoftDelete;
@ -40,5 +41,17 @@ class StoreProductGroupPrice extends BaseModel
}
return $product;
}
public static function resetStoreProductPrice($productList, $userShip, $shopId)
{
if ($shopId > 0 && SystemStore::isSelfOperate($shopId) && $userShip > 0) {
foreach ($productList as &$item) {
$item['price'] = $item['vip_price'];
}
return $productList;
} else {
return self::resetProductsPrice($productList, $userShip);
}
}
}

View File

@ -48,4 +48,14 @@ class SystemStore extends BaseModel
return in_array($storeId, [5]);
}
/**
* 是否自营门店
* @param $storeId
* @return bool
*/
public static function isSelfOperate($storeId): bool
{
return !in_array($storeId, [21, 22, 15, 7]);
}
}