新增取消药品订单队列,新增创建药品订单
This commit is contained in:
@@ -6,7 +6,12 @@ namespace App\Amqp\Consumer;
|
||||
|
||||
use App\Model\OrderInquiry;
|
||||
use App\Model\OrderInquiryCoupon;
|
||||
use App\Model\OrderPrescription;
|
||||
use App\Model\OrderPrescriptionProduct;
|
||||
use App\Model\OrderProduct;
|
||||
use App\Model\OrderProductItem;
|
||||
use App\Model\Product;
|
||||
use App\Model\ProductPlatformAmount;
|
||||
use App\Model\UserCoupon;
|
||||
use App\Utils\Log;
|
||||
use Hyperf\Amqp\Message\ConsumerDelayedMessageTrait;
|
||||
@@ -48,31 +53,23 @@ class CancelUnpayOrdersDelayDirectConsumer extends ConsumerMessage
|
||||
if ($data['order_type'] == 1){
|
||||
// 问诊订单取消
|
||||
$result = $this->cancelUnpayInquiryOrder($data['order_no']);
|
||||
if ($result['status'] == 0){
|
||||
Db::rollBack();
|
||||
Log::getInstance()->error("取消未支付订单失败:" . $result['message']);
|
||||
return Result::DROP;// 销毁
|
||||
}elseif ($result['status'] == 2){
|
||||
Db::rollBack();
|
||||
Log::getInstance()->error("取消未支付订单失败:" . $result['message']);
|
||||
return Result::ACK;// 销毁
|
||||
}
|
||||
}elseif ($data['order_type'] == 2){
|
||||
// 药品订单取消
|
||||
|
||||
$result = $this->cancelUnpayProductOrder($data['order_no']);
|
||||
}else{
|
||||
Log::getInstance()->error("取消未支付订单失败:order_type类型错误");
|
||||
return Result::DROP;// 销毁
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
if ($result['status'] == 0){
|
||||
Db::rollBack();
|
||||
Log::getInstance()->error("取消未支付订单失败:" . $result['message']);
|
||||
return Result::DROP;// 销毁
|
||||
}elseif ($result['status'] == 2){
|
||||
Db::rollBack();
|
||||
Log::getInstance()->error("取消未支付订单失败:" . $result['message']);
|
||||
return Result::ACK;// 销毁
|
||||
}
|
||||
|
||||
Db::commit();
|
||||
Log::getInstance()->error("取消未支付订单 队列执行成功");
|
||||
@@ -80,16 +77,16 @@ class CancelUnpayOrdersDelayDirectConsumer extends ConsumerMessage
|
||||
} catch (\Exception $e) {
|
||||
Db::rollBack();
|
||||
Log::getInstance()->error("取消未支付订单执行失败:" . $e->getMessage());
|
||||
return Result::REQUEUE; // 重回队列
|
||||
return Result::ACK; // 重回队列
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 取消未支付的问诊订单
|
||||
* @param string $order_no 系统订单编号
|
||||
* @param string|int $order_no 系统订单编号
|
||||
* @return array
|
||||
*/
|
||||
public function cancelUnpayInquiryOrder(string $order_no): array
|
||||
public function cancelUnpayInquiryOrder(string|int $order_no): array
|
||||
{
|
||||
$result = array();
|
||||
$result['status'] = 1;
|
||||
@@ -175,7 +172,12 @@ class CancelUnpayOrdersDelayDirectConsumer extends ConsumerMessage
|
||||
return $result;
|
||||
}
|
||||
|
||||
public function cancelUnpayProductOrder(string $order_no): array
|
||||
/**
|
||||
* 取消未支付的药品订单
|
||||
* @param string|int $order_no 系统订单编号
|
||||
* @return array
|
||||
*/
|
||||
public function cancelUnpayProductOrder(string|int $order_no): array
|
||||
{
|
||||
$result = array();
|
||||
$result['status'] = 1;
|
||||
@@ -184,7 +186,7 @@ class CancelUnpayOrdersDelayDirectConsumer extends ConsumerMessage
|
||||
// 获取药品订单数据
|
||||
$params = array();
|
||||
$params['order_product_no'] = $order_no;
|
||||
$order_product = OrderInquiry::getOne($params);
|
||||
$order_product = OrderProduct::getOne($params);
|
||||
if (empty($order_product)){
|
||||
$result['status'] = 0;
|
||||
$result['message'] = "取消未支付的问诊订单失败:未查询到对应订单数据";
|
||||
@@ -232,6 +234,76 @@ class CancelUnpayOrdersDelayDirectConsumer extends ConsumerMessage
|
||||
$params['order_inquiry_id'] = $order_product['order_inquiry_id'];
|
||||
OrderProduct::edit($params,$data);
|
||||
|
||||
//
|
||||
// 获取订单商品订单列表
|
||||
$params = array();
|
||||
$params['order_product_id'] = $order_product['order_product_id'];
|
||||
$order_product_item = OrderProductItem::getList($params);
|
||||
if (empty($order_product_item)){
|
||||
$result['status'] = 0;
|
||||
$result['message'] = "取消未支付的问诊订单失败:未查询到对应订单商品订单列表";
|
||||
return $result;
|
||||
}
|
||||
|
||||
foreach ($order_product_item as $item){
|
||||
// 释放锁定库存
|
||||
$params = array();
|
||||
$params['product_id'] = $item['product_id'];
|
||||
$product = Product::getWithAmountOne($params);
|
||||
if (empty($product)){
|
||||
$result['status'] = 0;
|
||||
$result['message'] = "取消未支付的问诊订单失败:未查询到对应订单商品订单列表";
|
||||
return $result;
|
||||
}
|
||||
|
||||
// 库存+1
|
||||
$params = array();
|
||||
$params['amount_id'] = $product['ProductPlatformAmount']['amount_id'];
|
||||
ProductPlatformAmount::inc($params, 'stock', (float)$item['amount']);
|
||||
|
||||
// 锁定库存-1
|
||||
ProductPlatformAmount::dec($params, 'lock_stock', (float)$item['amount']);
|
||||
}
|
||||
|
||||
// 获取处方数据
|
||||
$params = array();
|
||||
$params['order_prescription_id'] = $order_product['order_prescription_id'];
|
||||
$order_prescription = OrderPrescription::getOne($params);
|
||||
if (empty($order_prescription)){
|
||||
$result['status'] = 0;
|
||||
$result['message'] = "取消未支付的问诊订单失败:未查询到对应订单处方";
|
||||
return $result;
|
||||
}
|
||||
|
||||
// 修改处方状态为未使用
|
||||
if ($order_prescription['prescription_status'] == 4){
|
||||
$data = array();
|
||||
$data['prescription_status'] = 2;
|
||||
|
||||
$params = array();
|
||||
$params['order_prescription_id'] = $order_prescription['order_prescription_id'];
|
||||
OrderPrescription::edit($params, $data);
|
||||
}
|
||||
|
||||
// 获取处方商品数据
|
||||
$params = array();
|
||||
$params['order_prescription_id'] = $order_prescription['order_prescription_id'];
|
||||
$order_prescription_product = OrderPrescriptionProduct::getList($params);
|
||||
if (empty($order_prescription_product)) {
|
||||
$result['status'] = 0;
|
||||
$result['message'] = "取消未支付的问诊订单失败:未查询到对应订单处方商品数据";
|
||||
return $result;
|
||||
}
|
||||
|
||||
// 修改处方商品为未使用
|
||||
foreach ($order_prescription_product as $item){
|
||||
$data = array();
|
||||
$data['use_status'] = 0;
|
||||
|
||||
$params = array();
|
||||
$params['prescription_product_id'] = $item['prescription_product_id'];
|
||||
OrderPrescriptionProduct::edit($params, $data);
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user