封装取消支付订单
This commit is contained in:
parent
e97538a34a
commit
9bdb1e850c
@ -13,6 +13,8 @@ use App\Model\OrderProductItem;
|
||||
use App\Model\Product;
|
||||
use App\Model\ProductPlatformAmount;
|
||||
use App\Model\UserCoupon;
|
||||
use App\Services\InquiryService;
|
||||
use App\Services\OrderProductService;
|
||||
use App\Utils\Log;
|
||||
use Hyperf\Amqp\Message\ConsumerDelayedMessageTrait;
|
||||
use Hyperf\Amqp\Message\ProducerDelayedMessageTrait;
|
||||
@ -50,22 +52,26 @@ class CancelUnpayOrdersDelayDirectConsumer extends ConsumerMessage
|
||||
Db::beginTransaction();
|
||||
|
||||
try {
|
||||
if ($data['order_type'] == 1){
|
||||
if ($data['order_type'] == 1) {
|
||||
// 问诊订单取消
|
||||
$result = $this->cancelUnpayInquiryOrder($data['order_no']);
|
||||
}elseif ($data['order_type'] == 2){
|
||||
$InquiryService = new InquiryService();
|
||||
$result = $InquiryService->cancelUnpayInquiryOrder($data['order_no'], 5, "支付超时");
|
||||
|
||||
} elseif ($data['order_type'] == 2) {
|
||||
// 药品订单取消
|
||||
$result = $this->cancelUnpayProductOrder($data['order_no']);
|
||||
}else{
|
||||
$OrderProductService = new OrderProductService();
|
||||
$result = $OrderProductService->cancelUnpayProductOrder($data['order_no'], 3, "支付超时");
|
||||
|
||||
} else {
|
||||
Log::getInstance()->error("取消未支付订单失败:order_type类型错误");
|
||||
return Result::DROP;// 销毁
|
||||
}
|
||||
|
||||
if ($result['status'] == 0){
|
||||
if ($result['status'] == 0) {
|
||||
Db::rollBack();
|
||||
Log::getInstance()->error("取消未支付订单失败:" . $result['message']);
|
||||
return Result::DROP;// 销毁
|
||||
}elseif ($result['status'] == 2){
|
||||
} elseif ($result['status'] == 2) {
|
||||
Db::rollBack();
|
||||
Log::getInstance()->error("取消未支付订单失败:" . $result['message']);
|
||||
return Result::ACK;// 销毁
|
||||
@ -81,229 +87,5 @@ class CancelUnpayOrdersDelayDirectConsumer extends ConsumerMessage
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 取消未支付的问诊订单
|
||||
* @param string|int $order_no 系统订单编号
|
||||
* @return array
|
||||
*/
|
||||
public function cancelUnpayInquiryOrder(string|int $order_no): array
|
||||
{
|
||||
$result = array();
|
||||
$result['status'] = 1;
|
||||
$result['message'] = "成功";
|
||||
|
||||
// 获取订单数据
|
||||
$params = array();
|
||||
$params['inquiry_no'] = $order_no;
|
||||
$order_inquiry = OrderInquiry::getOne($params);
|
||||
if (empty($order_inquiry)) {
|
||||
$result['status'] = 0;
|
||||
$result['message'] = "取消未支付的问诊订单失败:未查询到对应订单数据";
|
||||
return $result;
|
||||
}
|
||||
|
||||
// 检测订单状态
|
||||
if ($order_inquiry['inquiry_status'] == 7) {
|
||||
// 问诊订单状态(1:待支付 2:待分配 3:待接诊 4:已接诊 5:已完成 6:已结束 7:已取消)
|
||||
$result['status'] = 2;
|
||||
$result['message'] = "取消未支付的问诊订单:订单已取消";
|
||||
return $result;
|
||||
}
|
||||
|
||||
if ($order_inquiry['inquiry_status'] != 1) {
|
||||
// 问诊订单状态(1:待支付 2:待分配 3:待接诊 4:已接诊 5:已完成 6:已结束 7:已取消)
|
||||
$result['status'] = 0;
|
||||
$result['message'] = "取消未支付的问诊订单:订单状态为" . $order_inquiry['inquiry_status'] . "无法执行";
|
||||
return $result;
|
||||
}
|
||||
|
||||
if (!in_array($order_inquiry['inquiry_refund_status'],[0,4,5])) {
|
||||
// 问诊订单退款状态(0:无退款 1:申请退款 2:退款中 3:退款成功 4:拒绝退款 5:退款关闭)
|
||||
$result['status'] = 0;
|
||||
$result['message'] = "取消未支付的问诊订单:订单正在退款中";
|
||||
return $result;
|
||||
}
|
||||
|
||||
if ($order_inquiry['inquiry_pay_status'] == 2) {
|
||||
// 支付状态(1:未支付 2:已支付 3:支付中 4:支付失败 5:支付超时 6:支付关闭 7:已撤销 8:转入退款)
|
||||
$result['status'] = 2;
|
||||
$result['message'] = "取消未支付的问诊订单:订单已支付";
|
||||
return $result;
|
||||
}
|
||||
|
||||
// 检测订单删除状态
|
||||
if ($order_inquiry['is_delete'] == 1) {
|
||||
// 删除状态(0:否 1:是)
|
||||
$result['status'] = 2;
|
||||
$result['message'] = "取消未支付的问诊订单:订单已被删除";
|
||||
return $result;
|
||||
}
|
||||
|
||||
// 取消问诊订单
|
||||
$data = array();
|
||||
$data['inquiry_status'] = 7;
|
||||
$data['inquiry_pay_status'] = 5;
|
||||
$data['cancel_time'] = date("Y-m-d H:i:s",time());
|
||||
$data['cancel_reason'] = 5; // 取消订单原因(1:医生未接诊 2:主动取消 3:无可分配医生 4:客服取消 5:支付超时)
|
||||
$data['updated_at'] = date("Y-m-d H:i:s",time());
|
||||
|
||||
$params = array();
|
||||
$params['order_inquiry_id'] = $order_inquiry['order_inquiry_id'];
|
||||
OrderInquiry::edit($params,$data);
|
||||
|
||||
// 处理订单优惠卷
|
||||
if (!empty($order_inquiry['coupon_amount_total']) && $order_inquiry['coupon_amount_total'] > 0){
|
||||
// 获取用户优惠卷信息
|
||||
$params = array();
|
||||
$params['order_inquiry_id'] = $order_inquiry['order_inquiry_id'];
|
||||
$order_inquiry_coupon = OrderInquiryCoupon::getOne($params);
|
||||
if (!empty($order_inquiry_coupon)){
|
||||
// 恢复优惠卷
|
||||
$data = array();
|
||||
$data['user_coupon_status'] = 0;
|
||||
$data['coupon_use_date'] = date('Y-m-d H:i:s',time());
|
||||
|
||||
$params = array();
|
||||
$params['user_coupon_id'] = $order_inquiry_coupon['user_coupon_id'];
|
||||
UserCoupon::edit($params,$data);
|
||||
}
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* 取消未支付的药品订单
|
||||
* @param string|int $order_no 系统订单编号
|
||||
* @return array
|
||||
*/
|
||||
public function cancelUnpayProductOrder(string|int $order_no): array
|
||||
{
|
||||
$result = array();
|
||||
$result['status'] = 1;
|
||||
$result['message'] = "成功";
|
||||
|
||||
// 获取药品订单数据
|
||||
$params = array();
|
||||
$params['order_product_no'] = $order_no;
|
||||
$order_product = OrderProduct::getOne($params);
|
||||
if (empty($order_product)){
|
||||
$result['status'] = 0;
|
||||
$result['message'] = "取消未支付的问诊订单失败:未查询到对应订单数据";
|
||||
return $result;
|
||||
}
|
||||
|
||||
// 检测订单状态
|
||||
if ($order_product['order_product_status'] == 5){
|
||||
// 订单状态(1:待支付 2:待发货 3:已发货 4:已签收 5:已取消)
|
||||
$result['status'] = 2;
|
||||
$result['message'] = "取消未支付的问诊订单:订单已取消";
|
||||
return $result;
|
||||
}
|
||||
|
||||
if ($order_product['order_product_status'] != 1){
|
||||
// 订单状态(1:待支付 2:待发货 3:已发货 4:已签收 5:已取消)
|
||||
$result['status'] = 0;
|
||||
$result['message'] = "取消未支付的问诊订单:订单状态为" . $order_product['order_product_status'] . "无法执行";
|
||||
return $result;
|
||||
}
|
||||
|
||||
if (!in_array($order_product['refund_status'],[0,4,5])) {
|
||||
// 商品订单退款状态(0:无退款 1:申请退款 2:退款中 3:退款成功 4:拒绝退款 5:退款关闭)
|
||||
$result['status'] = 0;
|
||||
$result['message'] = "取消未支付的问诊订单:订单正在退款中";
|
||||
return $result;
|
||||
}
|
||||
|
||||
if ($order_product['inquiry_pay_status'] == 2) {
|
||||
// 支付状态(1:未支付 2:已支付 3:支付中 4:支付失败 5:支付超时 6:支付关闭 7:已撤销 8:转入退款)
|
||||
$result['status'] = 2;
|
||||
$result['message'] = "取消未支付的问诊订单:订单已支付";
|
||||
return $result;
|
||||
}
|
||||
|
||||
// 取消药品订单
|
||||
$data = array();
|
||||
$data['order_product_status'] = 5;
|
||||
$data['cancel_time'] = date("Y-m-d H:i:s",time());
|
||||
$data['cancel_reason'] = 3; // 订单取消原因(1:主动取消 2:复核失败/库存不足 3:支付超时
|
||||
$data['cancel_remarks'] = 5; // 取消订单原因(1:医生未接诊 2:主动取消 3:无可分配医生 4:客服取消 5:支付超时)
|
||||
$data['updated_at'] = date("Y-m-d H:i:s",time());
|
||||
|
||||
$params = array();
|
||||
$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;
|
||||
}
|
||||
}
|
||||
|
||||
@ -736,5 +736,98 @@ class InquiryService extends BaseService
|
||||
OrderInquiry::edit($params, $data);
|
||||
}
|
||||
|
||||
/**
|
||||
* 取消未支付的问诊订单
|
||||
* @param string|int $order_no 系统订单编号
|
||||
* @param string|int $cancel_reason 取消订单原因(1:医生未接诊 2:主动取消 3:无可分配医生 4:客服取消 5:支付超时)
|
||||
* @param string|int $cancel_remarks 取消订单备注
|
||||
* @return array
|
||||
*/
|
||||
public function cancelUnpayInquiryOrder(string|int $order_no,string|int $cancel_reason,string|int $cancel_remarks): array
|
||||
{
|
||||
$result = array();
|
||||
$result['status'] = 1;
|
||||
$result['message'] = "成功";
|
||||
|
||||
// 获取订单数据
|
||||
$params = array();
|
||||
$params['inquiry_no'] = $order_no;
|
||||
$order_inquiry = OrderInquiry::getOne($params);
|
||||
if (empty($order_inquiry)) {
|
||||
$result['status'] = 0;
|
||||
$result['message'] = "取消未支付的问诊订单失败:未查询到对应订单数据";
|
||||
return $result;
|
||||
}
|
||||
|
||||
// 检测订单状态
|
||||
if ($order_inquiry['inquiry_status'] == 7) {
|
||||
// 问诊订单状态(1:待支付 2:待分配 3:待接诊 4:已接诊 5:已完成 6:已结束 7:已取消)
|
||||
$result['status'] = 2;
|
||||
$result['message'] = "取消未支付的问诊订单:订单已取消";
|
||||
return $result;
|
||||
}
|
||||
|
||||
if ($order_inquiry['inquiry_status'] != 1) {
|
||||
// 问诊订单状态(1:待支付 2:待分配 3:待接诊 4:已接诊 5:已完成 6:已结束 7:已取消)
|
||||
$result['status'] = 0;
|
||||
$result['message'] = "取消未支付的问诊订单:订单状态为" . $order_inquiry['inquiry_status'] . "无法执行";
|
||||
return $result;
|
||||
}
|
||||
|
||||
if (!in_array($order_inquiry['inquiry_refund_status'],[0,4,5])) {
|
||||
// 问诊订单退款状态(0:无退款 1:申请退款 2:退款中 3:退款成功 4:拒绝退款 5:退款关闭)
|
||||
$result['status'] = 0;
|
||||
$result['message'] = "取消未支付的问诊订单:订单正在退款中";
|
||||
return $result;
|
||||
}
|
||||
|
||||
if ($order_inquiry['inquiry_pay_status'] == 2) {
|
||||
// 支付状态(1:未支付 2:已支付 3:支付中 4:支付失败 5:支付超时 6:支付关闭 7:已撤销 8:转入退款)
|
||||
$result['status'] = 2;
|
||||
$result['message'] = "取消未支付的问诊订单:订单已支付";
|
||||
return $result;
|
||||
}
|
||||
|
||||
// 检测订单删除状态
|
||||
if ($order_inquiry['is_delete'] == 1) {
|
||||
// 删除状态(0:否 1:是)
|
||||
$result['status'] = 2;
|
||||
$result['message'] = "取消未支付的问诊订单:订单已被删除";
|
||||
return $result;
|
||||
}
|
||||
|
||||
// 取消问诊订单
|
||||
$data = array();
|
||||
$data['inquiry_status'] = 7;
|
||||
$data['inquiry_pay_status'] = 5;
|
||||
$data['cancel_time'] = date("Y-m-d H:i:s",time());
|
||||
$data['cancel_reason'] = $cancel_reason; // 取消订单原因(1:医生未接诊 2:主动取消 3:无可分配医生 4:客服取消 5:支付超时)
|
||||
$data['cancel_remarks'] = $cancel_remarks; // 取消订单备注
|
||||
$data['updated_at'] = date("Y-m-d H:i:s",time());
|
||||
|
||||
$params = array();
|
||||
$params['order_inquiry_id'] = $order_inquiry['order_inquiry_id'];
|
||||
OrderInquiry::edit($params,$data);
|
||||
|
||||
// 处理订单优惠卷
|
||||
if (!empty($order_inquiry['coupon_amount_total']) && $order_inquiry['coupon_amount_total'] > 0){
|
||||
// 获取用户优惠卷信息
|
||||
$params = array();
|
||||
$params['order_inquiry_id'] = $order_inquiry['order_inquiry_id'];
|
||||
$order_inquiry_coupon = OrderInquiryCoupon::getOne($params);
|
||||
if (!empty($order_inquiry_coupon)){
|
||||
// 恢复优惠卷
|
||||
$data = array();
|
||||
$data['user_coupon_status'] = 0;
|
||||
$data['coupon_use_date'] = date('Y-m-d H:i:s',time());
|
||||
|
||||
$params = array();
|
||||
$params['user_coupon_id'] = $order_inquiry_coupon['user_coupon_id'];
|
||||
UserCoupon::edit($params,$data);
|
||||
}
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
}
|
||||
@ -2,7 +2,12 @@
|
||||
|
||||
namespace App\Services;
|
||||
|
||||
use App\Model\OrderPrescription;
|
||||
use App\Model\OrderPrescriptionProduct;
|
||||
use App\Model\OrderProduct;
|
||||
use App\Model\OrderProductItem;
|
||||
use App\Model\Product;
|
||||
use App\Model\ProductPlatformAmount;
|
||||
|
||||
class OrderProductService extends BaseService
|
||||
{
|
||||
@ -19,4 +24,142 @@ class OrderProductService extends BaseService
|
||||
$params['order_product_status'] = $order_product_status;
|
||||
return OrderProduct::getCount($params);
|
||||
}
|
||||
|
||||
/**
|
||||
* 取消未支付的药品订单
|
||||
* 外层需加事物
|
||||
* @param string|int $order_no 系统订单编号
|
||||
* @param string|int $cancel_reason 订单取消原因(1:主动取消 2:复核失败/库存不足 3:支付超时
|
||||
* @param string $cancel_remarks 订单取消原因
|
||||
* @return array
|
||||
*/
|
||||
public function cancelUnpayProductOrder(string|int $order_no,string|int $cancel_reason,string $cancel_remarks): array
|
||||
{
|
||||
$result = array();
|
||||
$result['status'] = 1;
|
||||
$result['message'] = "成功";
|
||||
|
||||
// 获取药品订单数据
|
||||
$params = array();
|
||||
$params['order_product_no'] = $order_no;
|
||||
$order_product = OrderProduct::getOne($params);
|
||||
if (empty($order_product)){
|
||||
$result['status'] = 0;
|
||||
$result['message'] = "取消未支付的问诊订单失败:未查询到对应订单数据";
|
||||
return $result;
|
||||
}
|
||||
|
||||
// 检测订单状态
|
||||
if ($order_product['order_product_status'] == 5){
|
||||
// 订单状态(1:待支付 2:待发货 3:已发货 4:已签收 5:已取消)
|
||||
$result['status'] = 2;
|
||||
$result['message'] = "取消未支付的问诊订单:订单已取消";
|
||||
return $result;
|
||||
}
|
||||
|
||||
if ($order_product['order_product_status'] != 1){
|
||||
// 订单状态(1:待支付 2:待发货 3:已发货 4:已签收 5:已取消)
|
||||
$result['status'] = 0;
|
||||
$result['message'] = "取消未支付的问诊订单:订单状态为" . $order_product['order_product_status'] . "无法执行";
|
||||
return $result;
|
||||
}
|
||||
|
||||
if (!in_array($order_product['refund_status'],[0,4,5])) {
|
||||
// 商品订单退款状态(0:无退款 1:申请退款 2:退款中 3:退款成功 4:拒绝退款 5:退款关闭)
|
||||
$result['status'] = 0;
|
||||
$result['message'] = "取消未支付的问诊订单:订单正在退款中";
|
||||
return $result;
|
||||
}
|
||||
|
||||
if ($order_product['inquiry_pay_status'] == 2) {
|
||||
// 支付状态(1:未支付 2:已支付 3:支付中 4:支付失败 5:支付超时 6:支付关闭 7:已撤销 8:转入退款)
|
||||
$result['status'] = 2;
|
||||
$result['message'] = "取消未支付的问诊订单:订单已支付";
|
||||
return $result;
|
||||
}
|
||||
|
||||
// 取消药品订单
|
||||
$data = array();
|
||||
$data['order_product_status'] = 5;
|
||||
$data['cancel_time'] = date("Y-m-d H:i:s",time());
|
||||
$data['cancel_reason'] = $cancel_reason; // 订单取消原因(1:主动取消 2:复核失败/库存不足 3:支付超时
|
||||
$data['cancel_remarks'] = $cancel_remarks; // 取消订单原因(1:医生未接诊 2:主动取消 3:无可分配医生 4:客服取消 5:支付超时)
|
||||
$data['updated_at'] = date("Y-m-d H:i:s",time());
|
||||
|
||||
$params = array();
|
||||
$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;
|
||||
}
|
||||
}
|
||||
@ -347,6 +347,9 @@ class PatientOrderService extends BaseService
|
||||
|
||||
$order_inquiry_id = $this->request->route('order_inquiry_id');
|
||||
|
||||
Db::beginTransaction();
|
||||
|
||||
try {
|
||||
// 获取订单数据
|
||||
$params = array();
|
||||
$params['patient_id'] = $user_info['client_user_id'];
|
||||
@ -357,29 +360,20 @@ class PatientOrderService extends BaseService
|
||||
return fail();
|
||||
}
|
||||
|
||||
// 检测订单状态
|
||||
if ($order_inquiry['inquiry_status'] != 1) {
|
||||
// 问诊订单状态(1:待支付 2:待分配 3:待接诊 4:已接诊 5:已完成 6:已结束 7:已取消)
|
||||
return fail(HttpEnumCode::HTTP_ERROR, "订单无法取消支付");
|
||||
$InquiryService = new InquiryService();
|
||||
$result = $InquiryService->cancelUnpayInquiryOrder($order_inquiry['inquiry_no'], 2, "主动取消");
|
||||
|
||||
if ($result['status'] != 1){
|
||||
Db::rollBack();
|
||||
return fail();
|
||||
}
|
||||
|
||||
if (!in_array($order_inquiry['inquiry_refund_status'], [0, 4, 5])) {
|
||||
// 问诊订单退款状态(0:无退款 1:申请退款 2:退款中 3:退款成功 4:拒绝退款 5:退款关闭)
|
||||
return fail(HttpEnumCode::HTTP_ERROR, "订单正在退款中");
|
||||
Db::commit();
|
||||
} catch (\Exception $e) {
|
||||
Db::rollBack();
|
||||
return fail(HttpEnumCode::HTTP_ERROR, $e->getMessage());
|
||||
}
|
||||
|
||||
// 修改订单状态
|
||||
$data = array();
|
||||
$data['inquiry_status'] = 7;
|
||||
$data['cancel_time'] = date("Y-m-d H:i:s", time());
|
||||
$data['cancel_reason'] = 2; // 取消订单原因(1:医生未接诊 2:主动取消 3:无可分配医生 4:客服取消 5:支付超时)
|
||||
$data['cancel_remarks'] = "主动取消";
|
||||
$data['updated_at'] = date("Y-m-d H:i:s", time());
|
||||
|
||||
$params = array();
|
||||
$params['order_inquiry_id'] = $order_inquiry['order_inquiry_id'];
|
||||
OrderInquiry::edit($params, $data);
|
||||
|
||||
return success();
|
||||
}
|
||||
|
||||
@ -526,38 +520,14 @@ class PatientOrderService extends BaseService
|
||||
Db::rollBack();
|
||||
return fail();
|
||||
}
|
||||
$OrderProductService = new OrderProductService();
|
||||
|
||||
// 检测订单状态
|
||||
if ($order_product['order_product_status'] != 1) {
|
||||
$result = $OrderProductService->cancelUnpayProductOrder($order_product['order_product_no'],1,"主动取消");
|
||||
if ($result['status'] != 1){
|
||||
Db::rollBack();
|
||||
// 订单状态(1:待支付 2:待发货 3:已发货 4:已签收 5:已取消)
|
||||
return fail(HttpEnumCode::HTTP_ERROR, "订单无法删除");
|
||||
return fail();
|
||||
}
|
||||
|
||||
if ($order_product['pay_status'] != 1) {
|
||||
Db::rollBack();
|
||||
// 订单状态(1:待支付 2:待发货 3:已发货 4:已签收 5:已取消)
|
||||
return fail(HttpEnumCode::HTTP_ERROR, "订单无法删除");
|
||||
}
|
||||
|
||||
if (!in_array($order_product['refund_status'], [0, 4, 5])) {
|
||||
Db::rollBack();
|
||||
// 商品订单退款状态(0:无退款 1:申请退款 2:退款中 3:退款成功 4:拒绝退款 5:退款关闭)
|
||||
return fail(HttpEnumCode::HTTP_ERROR, "订单正在退款中");
|
||||
}
|
||||
|
||||
// 修改订单状态
|
||||
$data = array();
|
||||
$data['order_product_status'] = 5;
|
||||
$data['cancel_time'] = date("Y-m-d H:i:s", time());
|
||||
$data['cancel_reason'] = 1; // 订单取消原因(1:主动取消 2:复核失败/库存不足 3:支付超时
|
||||
$data['cancel_remarks'] = 2; // 取消订单原因(1:医生未接诊 2:主动取消 3:无可分配医生 4:客服取消 5:支付超时)
|
||||
$data['updated_at'] = date("Y-m-d H:i:s", time());
|
||||
|
||||
$params = array();
|
||||
$params['order_inquiry_id'] = $order_product['order_inquiry_id'];
|
||||
OrderProduct::edit($params, $data);
|
||||
|
||||
Db::commit();
|
||||
} catch (\Exception $e) {
|
||||
Db::rollBack();
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user