删除锁定库存,新增同步处方平台kucun
This commit is contained in:
parent
f2450cbcd5
commit
d19a1271d3
@ -5,9 +5,11 @@ declare(strict_types=1);
|
|||||||
namespace App\Command;
|
namespace App\Command;
|
||||||
|
|
||||||
use App\Model\Product;
|
use App\Model\Product;
|
||||||
|
use App\Model\ProductPlatformAmount;
|
||||||
use Extend\Prescription\Prescription;
|
use Extend\Prescription\Prescription;
|
||||||
use Hyperf\Command\Command as HyperfCommand;
|
use Hyperf\Command\Command as HyperfCommand;
|
||||||
use Hyperf\Command\Annotation\Command;
|
use Hyperf\Command\Annotation\Command;
|
||||||
|
use Hyperf\DbConnection\Db;
|
||||||
use Psr\Container\ContainerInterface;
|
use Psr\Container\ContainerInterface;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -34,7 +36,7 @@ class getProductStockCommand extends HyperfCommand
|
|||||||
try {
|
try {
|
||||||
// 获取商品
|
// 获取商品
|
||||||
$params = array();
|
$params = array();
|
||||||
$product = Product::getPage($params);
|
$product = Product::getPage($params,['*'],1,10);
|
||||||
if (empty($product['data'])){
|
if (empty($product['data'])){
|
||||||
$this->line("商品库存更新成功,无可更新库存商品");
|
$this->line("商品库存更新成功,无可更新库存商品");
|
||||||
return;
|
return;
|
||||||
@ -44,23 +46,85 @@ class getProductStockCommand extends HyperfCommand
|
|||||||
|
|
||||||
foreach ($product['data'] as $item){
|
foreach ($product['data'] as $item){
|
||||||
if (!empty($item['product_pharmacy_code'])){
|
if (!empty($item['product_pharmacy_code'])){
|
||||||
|
$result = $prescription->getProdStock($item['product_pharmacy_code']);
|
||||||
|
$this->handleData($item['product_platform_id'],$item['product_platform_code'],$result[0]);
|
||||||
}
|
}
|
||||||
|
|
||||||
$result = $prescription->getProdStock($item['product_pharmacy_code']);
|
|
||||||
dump($result);die;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if ($product['last_page'] > 1){
|
||||||
|
for ($i = 2; $i <= $product['last_page']; $i++) {
|
||||||
|
// 获取商品
|
||||||
|
$params = array();
|
||||||
|
$product = Product::getPage($params,['*'],1,10);
|
||||||
|
if (empty($product['data'])){
|
||||||
|
$this->line("商品库存更新成功,无可更新库存商品");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
$prescription = new Prescription();
|
||||||
|
|
||||||
|
foreach ($product['data'] as $item){
|
||||||
|
if (!empty($item['product_pharmacy_code'])){
|
||||||
|
$result = $prescription->getProdStock($item['product_pharmacy_code']);
|
||||||
|
$this->handleData($item['product_platform_id'],$item['product_platform_code'],$result[0]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
} catch (\Exception $e) {
|
} catch (\Exception $e) {
|
||||||
$this->line("商品库存更新失败:" . $e->getMessage());
|
$this->line("商品库存更新失败:" . $e->getMessage());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
$this->line("商品库存更新成功");
|
$this->line("商品库存更新成功");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 入库
|
||||||
|
* @param string $product_platform_id
|
||||||
|
* @param string $product_platform_code
|
||||||
|
* @param array $resultData
|
||||||
|
* @return bool
|
||||||
|
*/
|
||||||
|
public function handleData(string $product_platform_id,string $product_platform_code,array $resultData): bool
|
||||||
|
{
|
||||||
|
if (empty($resultData['quantity'])){
|
||||||
|
$resultData['quantity'] = 0;
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
Db::beginTransaction();
|
||||||
|
|
||||||
|
$params = array();
|
||||||
|
$params['product_platform_id'] = $product_platform_id;
|
||||||
|
$params['product_platform_code'] = $product_platform_code;
|
||||||
|
$product_platform_amount = ProductPlatformAmount::getSharedLockOne($params);
|
||||||
|
if (empty($product_platform_amount)){
|
||||||
|
// 无库存数据,新增
|
||||||
|
$data = array();
|
||||||
|
$data['product_platform_id'] = $product_platform_id;
|
||||||
|
$data['product_platform_code'] = $product_platform_code;
|
||||||
|
$data['stock'] = $resultData['quantity'];
|
||||||
|
$product_platform_amount = ProductPlatformAmount::addProductPlatformAmount($data);
|
||||||
|
if (empty($product_platform_amount)){
|
||||||
|
Db::rollBack();
|
||||||
|
$this->line("商品库存更新失败,无法新增库存数据" . json_encode($data, JSON_UNESCAPED_UNICODE));
|
||||||
|
}
|
||||||
|
}else{
|
||||||
|
// 存在库存数据,修改
|
||||||
|
$data = array();
|
||||||
|
$data['stock'] = $resultData['quantity'];
|
||||||
|
|
||||||
|
$params = array();
|
||||||
|
$params['amount_id'] = $product_platform_amount['amount_id'];
|
||||||
|
ProductPlatformAmount::edit($params,$data);
|
||||||
|
}
|
||||||
|
|
||||||
|
Db::commit();
|
||||||
|
} catch (\Exception $e) {
|
||||||
|
Db::rollBack();
|
||||||
|
$this->line("商品库存更新失败:" . $e->getMessage());
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -305,7 +305,7 @@ class CallBackController extends AbstractController
|
|||||||
$server = $app->getServer();
|
$server = $app->getServer();
|
||||||
|
|
||||||
$message = $server->getRequestMessage();
|
$message = $server->getRequestMessage();
|
||||||
dump($message);
|
|
||||||
if (empty($message)){
|
if (empty($message)){
|
||||||
return $this->response->withStatus(500)->withBody(new SwooleStream(strval(json_encode(['code' => 'ERROR', 'message' => "药品微信支付回调数据为空"], JSON_UNESCAPED_UNICODE))));
|
return $this->response->withStatus(500)->withBody(new SwooleStream(strval(json_encode(['code' => 'ERROR', 'message' => "药品微信支付回调数据为空"], JSON_UNESCAPED_UNICODE))));
|
||||||
}
|
}
|
||||||
@ -391,24 +391,6 @@ class CallBackController extends AbstractController
|
|||||||
return $server->serve();
|
return $server->serve();
|
||||||
}
|
}
|
||||||
|
|
||||||
// 修改库存,去除锁定
|
|
||||||
foreach ($order_product_item as $item){
|
|
||||||
// 释放锁定库存
|
|
||||||
$params = array();
|
|
||||||
$params['product_id'] = $item['product_id'];
|
|
||||||
$product = Product::getWithAmountOne($params);
|
|
||||||
if (empty($product)){
|
|
||||||
Db::rollBack();
|
|
||||||
Log::getInstance()->info("药品微信支付回调数据处理失败,未查询到对应订单商品订单列表");
|
|
||||||
return $server->serve();
|
|
||||||
}
|
|
||||||
|
|
||||||
// 锁定库存-订单商品数量 = 实际锁定库存数量
|
|
||||||
$params = array();
|
|
||||||
$params['amount_id'] = $product['ProductPlatformAmount']['amount_id'];
|
|
||||||
ProductPlatformAmount::dec($params, 'lock_stock', (float)$item['amount']);
|
|
||||||
}
|
|
||||||
|
|
||||||
Db::commit();
|
Db::commit();
|
||||||
} catch (\Exception $e) {
|
} catch (\Exception $e) {
|
||||||
Db::rollBack();
|
Db::rollBack();
|
||||||
|
|||||||
@ -6,15 +6,14 @@ namespace App\Model;
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
use Carbon\Carbon;
|
||||||
use Hyperf\Snowflake\Concern\Snowflake;
|
use Hyperf\Snowflake\Concern\Snowflake;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @property int $amount_id 主键id
|
* @property int $amount_id 主键id
|
||||||
* @property int $product_platform_id 商品id
|
* @property int $product_platform_id 处方平台商品id
|
||||||
* @property string $product_platform_code 处方平台商品编码
|
* @property string $product_platform_code 处方平台商品编码
|
||||||
* @property int $real_stock 实际库存
|
|
||||||
* @property int $stock 现有库存
|
* @property int $stock 现有库存
|
||||||
* @property int $lock_stock 锁定库存
|
|
||||||
* @property \Carbon\Carbon $created_at 创建时间
|
* @property \Carbon\Carbon $created_at 创建时间
|
||||||
* @property \Carbon\Carbon $updated_at 修改时间
|
* @property \Carbon\Carbon $updated_at 修改时间
|
||||||
*/
|
*/
|
||||||
@ -30,12 +29,7 @@ class ProductPlatformAmount extends Model
|
|||||||
/**
|
/**
|
||||||
* The attributes that are mass assignable.
|
* The attributes that are mass assignable.
|
||||||
*/
|
*/
|
||||||
protected array $fillable = ['amount_id', 'product_platform_id', 'product_platform_code', 'real_stock', 'stock', 'lock_stock', 'created_at', 'updated_at'];
|
protected array $fillable = ['amount_id', 'product_platform_id', 'product_platform_code', 'stock', 'created_at', 'updated_at'];
|
||||||
|
|
||||||
/**
|
|
||||||
* The attributes that should be cast to native types.
|
|
||||||
*/
|
|
||||||
protected array $casts = ['amount_id' => 'integer', 'product_platform_id' => 'integer', 'real_stock' => 'integer', 'stock' => 'integer', 'lock_stock' => 'integer', 'created_at' => 'datetime', 'updated_at' => 'datetime'];
|
|
||||||
|
|
||||||
protected string $primaryKey = "amount_id";
|
protected string $primaryKey = "amount_id";
|
||||||
|
|
||||||
@ -62,4 +56,58 @@ class ProductPlatformAmount extends Model
|
|||||||
{
|
{
|
||||||
return self::where($params)->decrement($field,$numeral);
|
return self::where($params)->decrement($field,$numeral);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取信息-单条
|
||||||
|
* @param array $params
|
||||||
|
* @param array $fields
|
||||||
|
* @return object|null
|
||||||
|
*/
|
||||||
|
public static function getOne(array $params, array $fields = ['*']): object|null
|
||||||
|
{
|
||||||
|
return self::where($params)->first($fields);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取信息-单条
|
||||||
|
* @param array $params
|
||||||
|
* @param array $fields
|
||||||
|
* @return object|null
|
||||||
|
*/
|
||||||
|
public static function getSharedLockOne(array $params, array $fields = ['*']): object|null
|
||||||
|
{
|
||||||
|
return self::where($params)->sharedLock()->first($fields);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取信息-多条
|
||||||
|
* @param array $params
|
||||||
|
* @param array $fields
|
||||||
|
* @return object|null
|
||||||
|
*/
|
||||||
|
public static function getList(array $params, array $fields = ['*']): object|null
|
||||||
|
{
|
||||||
|
return self::where($params)->get($fields);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 新增
|
||||||
|
* @param array $data
|
||||||
|
* @return ProductPlatformAmount|\Hyperf\Database\Model\Model
|
||||||
|
*/
|
||||||
|
public static function addProductPlatformAmount(array $data = []): ProductPlatformAmount|\Hyperf\Database\Model\Model
|
||||||
|
{
|
||||||
|
return self::create($data);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 修改
|
||||||
|
* @param array $params
|
||||||
|
* @param array $data
|
||||||
|
* @return int
|
||||||
|
*/
|
||||||
|
public static function edit(array $params = [], array $data = []): int
|
||||||
|
{
|
||||||
|
return self::where($params)->update($data);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -2,12 +2,14 @@
|
|||||||
|
|
||||||
namespace App\Services;
|
namespace App\Services;
|
||||||
|
|
||||||
|
use App\Constants\HttpEnumCode;
|
||||||
use App\Model\OrderPrescription;
|
use App\Model\OrderPrescription;
|
||||||
use App\Model\OrderPrescriptionProduct;
|
use App\Model\OrderPrescriptionProduct;
|
||||||
use App\Model\OrderProduct;
|
use App\Model\OrderProduct;
|
||||||
use App\Model\OrderProductItem;
|
use App\Model\OrderProductItem;
|
||||||
use App\Model\Product;
|
use App\Model\Product;
|
||||||
use App\Model\ProductPlatformAmount;
|
use App\Model\ProductPlatformAmount;
|
||||||
|
use Hyperf\DbConnection\Db;
|
||||||
|
|
||||||
class OrderProductService extends BaseService
|
class OrderProductService extends BaseService
|
||||||
{
|
{
|
||||||
@ -104,20 +106,27 @@ class OrderProductService extends BaseService
|
|||||||
// 释放锁定库存
|
// 释放锁定库存
|
||||||
$params = array();
|
$params = array();
|
||||||
$params['product_id'] = $item['product_id'];
|
$params['product_id'] = $item['product_id'];
|
||||||
$product = Product::getWithAmountOne($params);
|
$product = Product::getOne($params);
|
||||||
if (empty($product)){
|
if (empty($product)){
|
||||||
$result['status'] = 0;
|
$result['status'] = 0;
|
||||||
$result['message'] = "取消未支付的问诊订单失败:未查询到对应订单商品订单列表";
|
$result['message'] = "取消未支付的问诊订单失败:未查询到对应订单商品订单列表";
|
||||||
return $result;
|
return $result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$params = array();
|
||||||
|
$params['product_platform_code'] = $product['product_platform_code'];
|
||||||
|
$product_platform_amount = ProductPlatformAmount::getSharedLockOne($params);
|
||||||
|
if (empty($product_platform_amount)){
|
||||||
|
$result['status'] = 0;
|
||||||
|
$result['message'] = "取消未支付的问诊订单失败:无商品库存数据";
|
||||||
|
return $result;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
// 库存+订单商品数量
|
// 库存+订单商品数量
|
||||||
$params = array();
|
$params = array();
|
||||||
$params['amount_id'] = $product['ProductPlatformAmount']['amount_id'];
|
$params['amount_id'] = $product_platform_amount['amount_id'];
|
||||||
ProductPlatformAmount::inc($params, 'stock', (float)$item['amount']);
|
ProductPlatformAmount::inc($params, 'stock', (float)$item['amount']);
|
||||||
|
|
||||||
// 锁定库存-订单商品数量
|
|
||||||
ProductPlatformAmount::dec($params, 'lock_stock', (float)$item['amount']);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// 获取处方数据
|
// 获取处方数据
|
||||||
|
|||||||
@ -946,12 +946,20 @@ class PatientOrderService extends BaseService
|
|||||||
|
|
||||||
$params = array();
|
$params = array();
|
||||||
$params['product_id'] = $product_id;
|
$params['product_id'] = $product_id;
|
||||||
$product = Product::getWithAmountOne($params);
|
$product = Product::getOne($params);
|
||||||
if (empty($product)) {
|
if (empty($product)) {
|
||||||
Db::rollBack();
|
Db::rollBack();
|
||||||
return fail(HttpEnumCode::HTTP_ERROR, "处方存在未知药品");
|
return fail(HttpEnumCode::HTTP_ERROR, "处方存在未知药品");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$params = array();
|
||||||
|
$params['product_platform_code'] = $product['product_platform_code'];
|
||||||
|
$product_platform_amount = ProductPlatformAmount::getSharedLockOne($params);
|
||||||
|
if (empty($product_platform_amount)){
|
||||||
|
Db::rollBack();
|
||||||
|
return fail(HttpEnumCode::HTTP_ERROR, "无商品库存数据");
|
||||||
|
}
|
||||||
|
|
||||||
$data = array();
|
$data = array();
|
||||||
$data['order_product_id'] = $order_product['order_product_id'];
|
$data['order_product_id'] = $order_product['order_product_id'];
|
||||||
$data['order_inquiry_id'] = $order_prescription['order_inquiry_id'];
|
$data['order_inquiry_id'] = $order_prescription['order_inquiry_id'];
|
||||||
@ -981,11 +989,8 @@ class PatientOrderService extends BaseService
|
|||||||
// 锁定库存
|
// 锁定库存
|
||||||
// 库存-1
|
// 库存-1
|
||||||
$params = array();
|
$params = array();
|
||||||
$params['amount_id'] = $product['ProductPlatformAmount']['amount_id'];
|
$params['amount_id'] = $product_platform_amount['amount_id'];
|
||||||
ProductPlatformAmount::dec($params, 'stock', $order_prescription_product['prescription_product_num']);
|
ProductPlatformAmount::dec($params, 'stock', $order_prescription_product['prescription_product_num']);
|
||||||
|
|
||||||
// 锁定库存+1
|
|
||||||
ProductPlatformAmount::inc($params, 'lock_stock', $order_prescription_product['prescription_product_num']);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// 修改处方为已使用
|
// 修改处方为已使用
|
||||||
|
|||||||
@ -1188,7 +1188,7 @@ class UserDoctorService extends BaseService
|
|||||||
}
|
}
|
||||||
|
|
||||||
// 检测药品库存数据
|
// 检测药品库存数据
|
||||||
if ($item['prescription_product_num'] > $product['ProductPlatformAmount']['real_stock']) {
|
if ($item['prescription_product_num'] > $product['ProductPlatformAmount']['stock']) {
|
||||||
// 库存不足
|
// 库存不足
|
||||||
Db::rollBack();
|
Db::rollBack();
|
||||||
return fail(HttpEnumCode::HTTP_ERROR, "药品" . $product['product_name'] . "库存不足");
|
return fail(HttpEnumCode::HTTP_ERROR, "药品" . $product['product_name'] . "库存不足");
|
||||||
|
|||||||
@ -378,10 +378,9 @@ Router::addGroup('/area', function () {
|
|||||||
Router::get('/county', [AreaController::class, 'getCounty']);
|
Router::get('/county', [AreaController::class, 'getCounty']);
|
||||||
});
|
});
|
||||||
|
|
||||||
// oss
|
Router::addGroup('/sign', function () {
|
||||||
Router::addGroup('/oss', function () {
|
|
||||||
// 获取oss签名数据
|
// 获取oss签名数据
|
||||||
Router::get('/sign', [SafeController::class, 'getOssSign']);
|
Router::get('/oss', [SafeController::class, 'getOssSign']);
|
||||||
});
|
});
|
||||||
|
|
||||||
// 基础数据
|
// 基础数据
|
||||||
|
|||||||
@ -114,7 +114,12 @@ class Prescription
|
|||||||
];
|
];
|
||||||
|
|
||||||
try {
|
try {
|
||||||
return $this->httpRequest($this->api_url . $this->version . '/pharmacy/pharmacyInventory', $option);
|
$response = $this->httpRequest($this->api_url . $this->version . '/pharmacy/pharmacyInventory', $option);
|
||||||
|
if (empty($response)){
|
||||||
|
// 返回值为空
|
||||||
|
throw new BusinessException(HttpEnumCode::getMessage(HttpEnumCode::SERVER_ERROR));
|
||||||
|
}
|
||||||
|
return $response;
|
||||||
} catch (GuzzleException $e) {
|
} catch (GuzzleException $e) {
|
||||||
throw new BusinessException($e->getMessage());
|
throw new BusinessException($e->getMessage());
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user