multi-store/app/queue/redis/StoreStorageSend.php

53 lines
1.7 KiB
PHP

<?php
namespace app\queue\redis;
use app\admin\logic\store_product\StoreProductLogic;
use app\admin\logic\warehouse_product\WarehouseProductLogic;
use app\common\model\store_branch_product\StoreBranchProduct;
use app\common\model\store_branch_product_attr_value\StoreBranchProductAttrValue;
use app\common\model\store_branch_product_exchange\StoreBranchProductExchange;
use app\common\model\store_product\StoreProduct;
use app\common\model\store_product_attr_value\StoreProductAttrValue;
use app\common\model\system_store_storage\SystemStoreStorage;
use Webman\RedisQueue\Consumer;
use support\Log;
use think\facade\Db;
/**
* 门店库存记录商品
*/
class StoreStorageSend implements Consumer
{
// 要消费的队列名
public $queue = 'store-storage';
// 连接名,对应 plugin/webman/redis-queue/redis.php 里的连接`
public $connection = 'default';
// 消费
public function consume($data)
{
$product_arr = $data['product_arr'];
$store_id = $data['store_id'];
$stock_type = $data['stock_type'];
$admin_id = $data['admin_id'];
$warehouse_id = $data['warehouse_id']??0;
$find = StoreProduct::where('id', $product_arr['id'])->findOrEmpty()->toArray();
if($stock_type == 1){
StoreProductLogic::ordinary($product_arr,$store_id,$admin_id,$find,$warehouse_id);
}elseif($stock_type == 2){
StoreProductLogic::exchange($product_arr,$store_id,$admin_id,$find,$warehouse_id);
}
}
public function onConsumeFailure(\Throwable $e, $package)
{
$package['max_attempts'] = 0;
Log::error('store-storage队列消费失败: ' . $e->getMessage() . ',line:' . $e->getLine() . ',file:' . $e->getFile());
return $package;
}
}