同步库存增加库存记录
This commit is contained in:
@@ -5,6 +5,7 @@ declare(strict_types=1);
|
||||
namespace App\Command;
|
||||
|
||||
use App\Model\Product;
|
||||
use App\Model\ProductAmountRecord;
|
||||
use App\Model\ProductPlatformAmount;
|
||||
use Extend\Prescription\Prescription;
|
||||
use Hyperf\Command\Command as HyperfCommand;
|
||||
@@ -93,6 +94,9 @@ class getProductStockCommand extends HyperfCommand
|
||||
try {
|
||||
Db::beginTransaction();
|
||||
|
||||
// 当前库存数量
|
||||
$stock = 0;
|
||||
|
||||
$params = array();
|
||||
$params['product_platform_id'] = $product_platform_id;
|
||||
$params['product_platform_code'] = $product_platform_code;
|
||||
@@ -109,6 +113,8 @@ class getProductStockCommand extends HyperfCommand
|
||||
$this->line("商品库存更新失败,无法新增库存数据" . json_encode($data, JSON_UNESCAPED_UNICODE));
|
||||
}
|
||||
}else{
|
||||
$stock = $product_platform_amount['stock'];
|
||||
|
||||
// 存在库存数据,修改
|
||||
$data = array();
|
||||
$data['stock'] = $resultData['quantity'];
|
||||
@@ -118,8 +124,27 @@ class getProductStockCommand extends HyperfCommand
|
||||
ProductPlatformAmount::edit($params,$data);
|
||||
}
|
||||
|
||||
// 获取商品数据
|
||||
$params = array();
|
||||
$params['product_platform_id'] = $product_platform_id;
|
||||
$product = Product::getOne($params);
|
||||
if (!empty($product)){
|
||||
// 增加库存记录
|
||||
$data = array();
|
||||
$data['product_id'] = $product['product_id'];
|
||||
$data['change_quantity'] = $resultData['quantity'] - $stock; // 库存变动的数量 变动的库存-原库存
|
||||
$data['quantity'] = $resultData['quantity']; // 变动后库存数量
|
||||
$data['change_time'] = date('Y-m-d H:i:s',time());
|
||||
$data['remark'] = "库存同步";
|
||||
$product_amount_record = ProductAmountRecord::addProductAmountRecord($data);
|
||||
if (empty($product_amount_record)){
|
||||
Db::rollBack();
|
||||
$this->line("商品库存更新失败,增加库存记录失败" . json_encode($data, JSON_UNESCAPED_UNICODE));
|
||||
}
|
||||
}
|
||||
|
||||
Db::commit();
|
||||
} catch (\Exception $e) {
|
||||
} catch (\Throwable $e) {
|
||||
Db::rollBack();
|
||||
$this->line("商品库存更新失败:" . $e->getMessage());
|
||||
return false;
|
||||
|
||||
Reference in New Issue
Block a user