feat(store_product): 编辑成功,增加库存操作成功逻辑
This commit is contained in:
parent
cbf01610b6
commit
42e95677ef
@ -62,7 +62,7 @@ class StoreBranchProductController extends BaseAdminController
|
||||
return $this->fail(StoreProductLogic::getError());
|
||||
}
|
||||
}
|
||||
return $this->success('编辑成功', [], 1, 1);
|
||||
return $this->success('操作成功,等待门店确认', [], 1, 1);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -10,6 +10,8 @@ use app\common\model\store_branch_product_attr_value\StoreBranchProductAttrValue
|
||||
use app\common\model\store_category\StoreCategory;
|
||||
use app\common\model\store_product_attr_value\StoreProductAttrValue;
|
||||
use app\common\model\system_store\SystemStore;
|
||||
use app\common\model\system_store_storage\SystemStoreStorage;
|
||||
use app\Request;
|
||||
use think\facade\Db;
|
||||
use Webman\RedisQueue\Redis;
|
||||
|
||||
@ -264,7 +266,13 @@ class StoreProductLogic extends BaseLogic
|
||||
public static function stock($data){
|
||||
Db::startTrans();
|
||||
try {
|
||||
StoreBranchProduct::where(['id' => $data['id']])->inc('stock',$data['stock'])->update();
|
||||
$find=StoreBranchProduct::where(['id' => $data['id']])->find();
|
||||
SystemStoreStorage::create([
|
||||
'product_id' => $find['product_id'],
|
||||
'store_id' => $find['store_id'],
|
||||
'nums' => $data['stock'],
|
||||
'admin_id' => Request()->adminId,
|
||||
]);
|
||||
Db::commit();
|
||||
return true;
|
||||
} catch (\Exception $e) {
|
||||
|
@ -3,6 +3,8 @@
|
||||
namespace app\queue\redis;
|
||||
|
||||
use app\admin\logic\store_product\StoreProductLogic;
|
||||
use app\common\model\store_product\StoreProduct;
|
||||
use app\common\model\system_store_storage\SystemStoreStorage;
|
||||
use Webman\RedisQueue\Consumer;
|
||||
use support\Log;
|
||||
|
||||
@ -22,8 +24,19 @@ class CopyProductSend implements Consumer
|
||||
{
|
||||
$store_arr=$data['store_arr'];
|
||||
$stock=$data['stock']??0;
|
||||
$admin_id=$data['admin_id']??0;
|
||||
foreach ($store_arr as $key => $id) {
|
||||
StoreProductLogic::copy($data['product_id'],$id,$stock);
|
||||
StoreProductLogic::copy($data['product_id'],$id,0);
|
||||
if($stock>0){
|
||||
$stocks=StoreProduct::where('id',$data['product_id'])->value('stock');
|
||||
if($stocks>=$stock){
|
||||
SystemStoreStorage::create(['product_id'=>$data['product_id'],'store_id'=>$id,'nums'=>$stock,'admin_id'=>$admin_id]);//设置库存
|
||||
StoreProduct::where('id',$data['product_id'])->dec('stock',$stock)->update();//减少库存
|
||||
}else{
|
||||
SystemStoreStorage::create(['product_id'=>$data['product_id'],'store_id'=>$id,'nums'=>$stock,'admin_id'=>$admin_id,'status'=>-1,'mark'=>'库存不足']);//设置库存
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
public function onConsumeFailure(\Throwable $e, $package)
|
||||
|
34
app/queue/redis/StoreStorageSend.php
Normal file
34
app/queue/redis/StoreStorageSend.php
Normal file
@ -0,0 +1,34 @@
|
||||
<?php
|
||||
|
||||
namespace app\queue\redis;
|
||||
|
||||
use app\admin\logic\store_product\StoreProductLogic;
|
||||
use Webman\RedisQueue\Consumer;
|
||||
use support\Log;
|
||||
|
||||
/**
|
||||
* 门店库存记录商品
|
||||
*/
|
||||
class StoreStorageSend implements Consumer
|
||||
{
|
||||
// 要消费的队列名
|
||||
public $queue = 'store_storage';
|
||||
|
||||
// 连接名,对应 plugin/webman/redis-queue/redis.php 里的连接`
|
||||
public $connection = 'default';
|
||||
|
||||
// 消费
|
||||
public function consume($data)
|
||||
{
|
||||
// $product_id=$data['product_id'];
|
||||
// $store_id=$data['store_id'];
|
||||
// $store_id=$data['store_id'];
|
||||
// StoreBranchProduct::w
|
||||
}
|
||||
public function onConsumeFailure(\Throwable $e, $package)
|
||||
{
|
||||
$package['max_attempts']=0;
|
||||
Log::error('复制商品失败product_id:'.$package['data']['product_id']);
|
||||
return $package;
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user