feat: 库存管理功能增强
This commit is contained in:
parent
f8a566655b
commit
2e37a6ac46
@ -5,6 +5,7 @@ namespace app\admin\logic\store_branch_product;
|
|||||||
use app\admin\logic\store_product\StoreProductLogic;
|
use app\admin\logic\store_product\StoreProductLogic;
|
||||||
use app\common\model\store_branch_product\StoreBranchProduct;
|
use app\common\model\store_branch_product\StoreBranchProduct;
|
||||||
use app\common\logic\BaseLogic;
|
use app\common\logic\BaseLogic;
|
||||||
|
use app\common\model\store_product\StoreProduct;
|
||||||
use think\facade\Db;
|
use think\facade\Db;
|
||||||
use Webman\RedisQueue\Redis;
|
use Webman\RedisQueue\Redis;
|
||||||
|
|
||||||
@ -41,7 +42,6 @@ class StoreBranchProductLogic extends BaseLogic
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @notes 编辑门店商品
|
* @notes 编辑门店商品
|
||||||
* @param array $params
|
* @param array $params
|
||||||
@ -74,6 +74,40 @@ class StoreBranchProductLogic extends BaseLogic
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
/**
|
||||||
|
* @notes 库存管理
|
||||||
|
* @param array $params
|
||||||
|
* @return bool
|
||||||
|
* @author admin
|
||||||
|
* @date 2024/06/07 13:56
|
||||||
|
*/
|
||||||
|
public static function stock(array $params,$type=1): bool
|
||||||
|
{
|
||||||
|
Db::startTrans();
|
||||||
|
try {
|
||||||
|
if($type==1){
|
||||||
|
StoreBranchProduct::where('id', $params['id'])->inc('stock',$params['nums'])->update();
|
||||||
|
$find=StoreProduct::where('id', $params['product_id'])->find();
|
||||||
|
if($find){
|
||||||
|
$stock=bcadd($find['stock'],$params['nums'],2);
|
||||||
|
$find->update(['stock'=>$stock,'total_price'=>bcmul($stock,$find['purchase'],2)]);
|
||||||
|
}
|
||||||
|
}else{
|
||||||
|
StoreBranchProduct::where('id', $params['id'])->dec('stock',$params['nums'])->update();
|
||||||
|
$find=StoreProduct::where('id', $params['product_id'])->find();
|
||||||
|
if($find){
|
||||||
|
$stock=bcsub($find['stock'],$params['nums'],2);
|
||||||
|
$find->update(['stock'=>$stock,'total_price'=>bcmul($stock,$find['purchase'],2)]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Db::commit();
|
||||||
|
return true;
|
||||||
|
} catch (\Throwable $e) {
|
||||||
|
Db::rollback();
|
||||||
|
self::setError($e->getMessage());
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
/**
|
/**
|
||||||
* @notes 删除门店商品
|
* @notes 删除门店商品
|
||||||
* @param array $params
|
* @param array $params
|
||||||
|
@ -82,7 +82,9 @@ class StoreProductLogic extends BaseLogic
|
|||||||
if ($params['is_store_all'] == 1) {
|
if ($params['is_store_all'] == 1) {
|
||||||
$store_arr = SystemStore::where('is_show', 1)->column('id');
|
$store_arr = SystemStore::where('is_show', 1)->column('id');
|
||||||
foreach ($store_arr as $store_id) {
|
foreach ($store_arr as $store_id) {
|
||||||
Redis::send('store-storage', ['product_arr' => ['id' => $res['id'], 'stock' => 0], 'store_id' => $store_id, 'stock_type' => 1, 'admin_id' => Request()->adminId]);
|
if ($store_id != 5) {
|
||||||
|
Redis::send('store-storage', ['product_arr' => ['id' => $res['id'], 'stock' => 0], 'store_id' => $store_id, 'stock_type' => 1, 'admin_id' => Request()->adminId]);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (is_array($params['store_arr']) && count($params['store_arr']) > 0) {
|
if (is_array($params['store_arr']) && count($params['store_arr']) > 0) {
|
||||||
|
@ -2,6 +2,7 @@
|
|||||||
|
|
||||||
namespace app\admin\logic\warehouse_product;
|
namespace app\admin\logic\warehouse_product;
|
||||||
|
|
||||||
|
use app\admin\logic\store_branch_product\StoreBranchProductLogic;
|
||||||
use app\admin\logic\store_product\StoreProductLogic;
|
use app\admin\logic\store_product\StoreProductLogic;
|
||||||
use app\common\model\warehouse_product\WarehouseProduct;
|
use app\common\model\warehouse_product\WarehouseProduct;
|
||||||
use app\common\logic\BaseLogic;
|
use app\common\logic\BaseLogic;
|
||||||
@ -56,7 +57,7 @@ class WarehouseProductLogic extends BaseLogic
|
|||||||
$storeBranchProduct=StoreProductLogic::ordinary(['id'=>$params['product_id']],$params['store_id'], $params['admin_id'], $storeProduct);
|
$storeBranchProduct=StoreProductLogic::ordinary(['id'=>$params['product_id']],$params['store_id'], $params['admin_id'], $storeProduct);
|
||||||
}
|
}
|
||||||
if ($params['nums'] > 0&&$type==1) {
|
if ($params['nums'] > 0&&$type==1) {
|
||||||
StoreBranchProduct::where('id', $storeBranchProduct['id'])->inc('stock',$params['nums'])->update();
|
StoreBranchProductLogic::stock(['id'=>$storeBranchProduct['id'],'product_id'=>$params['product_id'],'nums'=>$params['nums']]);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
$after_nums = $storege['nums'] + $params['nums'];
|
$after_nums = $storege['nums'] + $params['nums'];
|
||||||
|
@ -572,25 +572,22 @@ class PayNotifyLogic extends BaseLogic
|
|||||||
*/
|
*/
|
||||||
public static function afterPay($order, $transaction_id = 0)
|
public static function afterPay($order, $transaction_id = 0)
|
||||||
{
|
{
|
||||||
$updateData = [];
|
|
||||||
$updateDataTwo = [];
|
|
||||||
StoreOrderCartInfo::where('oid', $order['id'])->update(['is_pay' => 1]);
|
StoreOrderCartInfo::where('oid', $order['id'])->update(['is_pay' => 1]);
|
||||||
$arr = StoreOrderCartInfo::where('oid', $order['id'])->field('id,oid,product_id,store_id,cart_num')->select();
|
$arr = StoreOrderCartInfo::where('oid', $order['id'])->field('id,oid,product_id,store_id,cart_num')->select();
|
||||||
foreach ($arr as $k => $v) {
|
foreach ($arr as $k => $v) {
|
||||||
$updateData[] = [
|
$branchProduct=StoreBranchProduct::where('product_id', $v['product_id'])->where('store_id',$v['store_id'])->find();
|
||||||
'store_id' => $v['store_id'],
|
if($branchProduct){
|
||||||
'product_id' => $v['product_id'],
|
$stock=bcsub($branchProduct['stock'],$v['cart_num'],2);
|
||||||
'sales' => ['inc', $v['cart_num']],
|
$branchProduct->update(['stock'=>$stock,'total_price'=>bcmul($stock,$branchProduct['purchase'],2),
|
||||||
'stock' => ['dec', $v['cart_num']],
|
'sales'=>bcmul($branchProduct['sales'],$v['cart_num'],2)]);
|
||||||
];
|
}
|
||||||
|
$storeProduct=StoreProduct::where('id', $v['product_id'])->find();
|
||||||
$updateDataTwo[] = [
|
if($storeProduct){
|
||||||
'id' => $v['product_id'],
|
$stock=bcsub($storeProduct['stock'],$v['cart_num'],2);
|
||||||
'sales' => ['inc', $v['cart_num']]
|
$storeProduct->update(['stock'=>$stock,'total_price'=>bcmul($stock,$storeProduct['purchase'],2),
|
||||||
];
|
'sales'=>bcmul($storeProduct['sales'],$v['cart_num'],2)]);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
(new StoreBranchProduct())->saveAll($updateData);
|
|
||||||
(new StoreProduct())->saveAll($updateDataTwo);
|
|
||||||
$financeLogic = new StoreFinanceFlowLogic();
|
$financeLogic = new StoreFinanceFlowLogic();
|
||||||
$off_activity = Config::where('name', 'off_activity')->value('value');
|
$off_activity = Config::where('name', 'off_activity')->value('value');
|
||||||
$village_uid = 0;
|
$village_uid = 0;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user