新增模拟支付接口
This commit is contained in:
parent
cff132c5d4
commit
f2450cbcd5
@ -6,6 +6,7 @@ use App\Request\InquiryRequest;
|
|||||||
use App\Request\PatientOrderRequest;
|
use App\Request\PatientOrderRequest;
|
||||||
use App\Services\InquiryService;
|
use App\Services\InquiryService;
|
||||||
use App\Services\PatientOrderService;
|
use App\Services\PatientOrderService;
|
||||||
|
use GuzzleHttp\Exception\GuzzleException;
|
||||||
use Psr\Container\ContainerExceptionInterface;
|
use Psr\Container\ContainerExceptionInterface;
|
||||||
use Psr\Container\NotFoundExceptionInterface;
|
use Psr\Container\NotFoundExceptionInterface;
|
||||||
use Psr\Http\Message\ResponseInterface;
|
use Psr\Http\Message\ResponseInterface;
|
||||||
@ -142,6 +143,22 @@ class PatientOrderController extends AbstractController
|
|||||||
return $this->response->json($data);
|
return $this->response->json($data);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 模拟支付成功-金额为0时使用
|
||||||
|
* @return ResponseInterface
|
||||||
|
* @throws ContainerExceptionInterface
|
||||||
|
* @throws NotFoundExceptionInterface|GuzzleException
|
||||||
|
*/
|
||||||
|
public function addPatientOrderPay(): ResponseInterface
|
||||||
|
{
|
||||||
|
$request = $this->container->get(PatientOrderRequest::class);
|
||||||
|
$request->scene('addPatientOrderPay')->validateResolved();
|
||||||
|
|
||||||
|
$PatientOrderService = new PatientOrderService();
|
||||||
|
$data = $PatientOrderService->addPatientOrderPay();
|
||||||
|
return $this->response->json($data);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 创建药品订单
|
* 创建药品订单
|
||||||
* @return ResponseInterface
|
* @return ResponseInterface
|
||||||
|
|||||||
@ -22,6 +22,9 @@ class PatientOrderRequest extends FormRequest
|
|||||||
"order_type", // 订单类型(1:问诊订单 2:药品订单)
|
"order_type", // 订单类型(1:问诊订单 2:药品订单)
|
||||||
"order_no"// 订单编号
|
"order_no"// 订单编号
|
||||||
],
|
],
|
||||||
|
'addPatientOrderPay' => [ // 模拟支付成功-金额为0时使用
|
||||||
|
"order_no"// 订单编号
|
||||||
|
],
|
||||||
'addPatientProductOrder' => [ // 创建药品订单
|
'addPatientProductOrder' => [ // 创建药品订单
|
||||||
"order_prescription_id",
|
"order_prescription_id",
|
||||||
"address_id",
|
"address_id",
|
||||||
|
|||||||
@ -2,6 +2,7 @@
|
|||||||
|
|
||||||
namespace App\Services;
|
namespace App\Services;
|
||||||
|
|
||||||
|
use App\Amqp\Producer\AssignDoctorProducer;
|
||||||
use App\Amqp\Producer\CancelUnpayOrdersDelayDirectProducer;
|
use App\Amqp\Producer\CancelUnpayOrdersDelayDirectProducer;
|
||||||
use App\Constants\DoctorTitleCode;
|
use App\Constants\DoctorTitleCode;
|
||||||
use App\Constants\HttpEnumCode;
|
use App\Constants\HttpEnumCode;
|
||||||
@ -16,10 +17,12 @@ use App\Model\Product;
|
|||||||
use App\Model\ProductPlatformAmount;
|
use App\Model\ProductPlatformAmount;
|
||||||
use App\Model\UserDoctor;
|
use App\Model\UserDoctor;
|
||||||
use App\Model\UserShipAddress;
|
use App\Model\UserShipAddress;
|
||||||
|
use App\Utils\Log;
|
||||||
use Extend\Wechat\WechatPay;
|
use Extend\Wechat\WechatPay;
|
||||||
use Hyperf\Amqp\Producer;
|
use Hyperf\Amqp\Producer;
|
||||||
use Hyperf\DbConnection\Db;
|
use Hyperf\DbConnection\Db;
|
||||||
use Hyperf\Snowflake\IdGeneratorInterface;
|
use Hyperf\Snowflake\IdGeneratorInterface;
|
||||||
|
use Hyperf\Utils\ApplicationContext;
|
||||||
use Psr\Container\ContainerExceptionInterface;
|
use Psr\Container\ContainerExceptionInterface;
|
||||||
use Psr\Container\NotFoundExceptionInterface;
|
use Psr\Container\NotFoundExceptionInterface;
|
||||||
|
|
||||||
@ -593,6 +596,17 @@ class PatientOrderService extends BaseService
|
|||||||
$order_type = $this->request->input('order_type');
|
$order_type = $this->request->input('order_type');
|
||||||
$order_no = $this->request->input('order_no');
|
$order_no = $this->request->input('order_no');
|
||||||
|
|
||||||
|
// 获取订单金额
|
||||||
|
$result = array();
|
||||||
|
$result['amount_total'] = 0; // 订单金额
|
||||||
|
$result['payment_amount_total'] = 0; // 实际订单金额
|
||||||
|
$result['coupon_amount_total'] = 0; // 优惠金额
|
||||||
|
$result['order_no'] = $order_no; // 订单编号
|
||||||
|
$result['order_id'] = ""; // 订单主键id(问诊订单:order_inquiry_id 药品订单:order_product_id)
|
||||||
|
$result['created_at'] = ""; // 创建时间
|
||||||
|
$result['inquiry_type'] = 0; // 订单类型(1:专家问诊 2:快速问诊 3:公益问诊 4:问诊购药)
|
||||||
|
$result['pay_config'] = []; // 小程序支付配置
|
||||||
|
|
||||||
if ($order_type == 1) {
|
if ($order_type == 1) {
|
||||||
// 问诊订单
|
// 问诊订单
|
||||||
$params = array();
|
$params = array();
|
||||||
@ -619,27 +633,26 @@ class PatientOrderService extends BaseService
|
|||||||
return fail(HttpEnumCode::HTTP_ERROR, "订单已过期");
|
return fail(HttpEnumCode::HTTP_ERROR, "订单已过期");
|
||||||
}
|
}
|
||||||
|
|
||||||
$order_id = $order_inquiry['order_inquiry_id'];
|
$result['order_id'] = $order_inquiry['order_inquiry_id'];
|
||||||
$created_at = $order_inquiry['created_at'];
|
$result['created_at'] = $order_inquiry['created_at'];
|
||||||
$inquiry_type = $order_inquiry['inquiry_type'];
|
$result['inquiry_type'] = $order_inquiry['inquiry_type'];
|
||||||
|
|
||||||
// 获取订单金额
|
// 获取订单金额
|
||||||
$amount_total = $order_inquiry['amount_total'];
|
$result['amount_total'] = $order_inquiry['amount_total']; // 订单金额
|
||||||
$payment_amount_total = $order_inquiry['payment_amount_total'];
|
$result['payment_amount_total'] = $order_inquiry['payment_amount_total']; // 实际订单金额
|
||||||
$coupon_amount_total = $order_inquiry['coupon_amount_total'];
|
$result['coupon_amount_total'] = $order_inquiry['coupon_amount_total'];; // 优惠金额
|
||||||
|
|
||||||
// 发起支付
|
// 发起支付
|
||||||
$WechatPay = new WechatPay(1,1);
|
$WechatPay = new WechatPay(1,1);
|
||||||
|
|
||||||
// 获取预支付交易会话标识
|
// 获取预支付交易会话标识
|
||||||
$prepay = $WechatPay->getJsapiPrepayId($order_no, $payment_amount_total * 100, $user_info['open_id']);
|
$prepay = $WechatPay->getJsapiPrepayId($order_no, $order_inquiry['payment_amount_total'] * 100, $user_info['open_id']);
|
||||||
if (empty($prepay)) {
|
if (empty($prepay)) {
|
||||||
return fail(HttpEnumCode::SERVER_ERROR);
|
return fail(HttpEnumCode::SERVER_ERROR);
|
||||||
}
|
}
|
||||||
|
|
||||||
// 获取小程序支付配置
|
// 获取小程序支付配置
|
||||||
$pay_config = $WechatPay->getAppletsPayConfig($prepay['prepay_id']);
|
$result['pay_config'] = $WechatPay->getAppletsPayConfig($prepay['prepay_id']);
|
||||||
|
|
||||||
} elseif ($order_type == 2) {
|
} elseif ($order_type == 2) {
|
||||||
// 药品订单
|
// 药品订单
|
||||||
$params = array();
|
$params = array();
|
||||||
@ -656,7 +669,7 @@ class PatientOrderService extends BaseService
|
|||||||
}
|
}
|
||||||
|
|
||||||
// 验证订单支付状态
|
// 验证订单支付状态
|
||||||
if ($order_product['inquiry_pay_status'] != 1) {
|
if ($order_product['pay_status'] != 1) {
|
||||||
return fail(HttpEnumCode::HTTP_ERROR, "订单支付状态错误");
|
return fail(HttpEnumCode::HTTP_ERROR, "订单支付状态错误");
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -666,43 +679,128 @@ class PatientOrderService extends BaseService
|
|||||||
return fail(HttpEnumCode::HTTP_ERROR, "订单已过期");
|
return fail(HttpEnumCode::HTTP_ERROR, "订单已过期");
|
||||||
}
|
}
|
||||||
|
|
||||||
$order_id = $order_product['order_product_id'];
|
$result['order_id'] = $order_product['order_product_id'];
|
||||||
$created_at = $order_product['created_at'];
|
$result['created_at'] = $order_product['created_at'];
|
||||||
$inquiry_type = 0;
|
|
||||||
|
|
||||||
// 获取订单金额
|
// 获取订单金额
|
||||||
$amount_total = $order_product['amount_total'];
|
$result['amount_total'] = $order_product['amount_total']; // 订单金额
|
||||||
$payment_amount_total = $order_product['payment_amount_total'];
|
$result['payment_amount_total'] = $order_product['payment_amount_total']; // 实际订单金额
|
||||||
$coupon_amount_total = 0;
|
$result['coupon_amount_total'] = 0; // 优惠金额
|
||||||
|
|
||||||
// 发起支付
|
// 发起支付
|
||||||
$WechatPay = new WechatPay(1,2);
|
$WechatPay = new WechatPay(1,2);
|
||||||
|
|
||||||
// 获取预支付交易会话标识
|
// 获取预支付交易会话标识
|
||||||
$prepay = $WechatPay->getJsapiPrepayId($order_no, $payment_amount_total * 100, $user_info['open_id']);
|
$prepay = $WechatPay->getJsapiPrepayId($order_no, $order_product['payment_amount_total'] * 100, $user_info['open_id']);
|
||||||
if (empty($prepay)) {
|
if (empty($prepay)) {
|
||||||
return fail(HttpEnumCode::SERVER_ERROR);
|
return fail(HttpEnumCode::SERVER_ERROR);
|
||||||
}
|
}
|
||||||
|
|
||||||
// 获取小程序支付配置
|
// 获取小程序支付配置
|
||||||
$pay_config = $WechatPay->getAppletsPayConfig($prepay['prepay_id']);
|
$result['pay_config'] = $WechatPay->getAppletsPayConfig($prepay['prepay_id']);
|
||||||
} else {
|
} else {
|
||||||
return fail();
|
return fail();
|
||||||
}
|
}
|
||||||
|
|
||||||
$result = array();
|
|
||||||
$result['amount_total'] = $amount_total; // 订单金额
|
|
||||||
$result['payment_amount_total'] = $payment_amount_total; // 实际订单金额
|
|
||||||
$result['coupon_amount_total'] = $coupon_amount_total; // 优惠金额
|
|
||||||
$result['order_no'] = $order_no; // 订单编号
|
|
||||||
$result['order_id'] = $order_id; // 订单主键id(问诊订单:order_inquiry_id 药品订单:order_product_id)
|
|
||||||
$result['created_at'] = $created_at; // 创建时间
|
|
||||||
$result['inquiry_type'] = $inquiry_type; // 订单类型(1:专家问诊 2:快速问诊 3:公益问诊 4:问诊购药)
|
|
||||||
$result['pay_config'] = $pay_config; // 小程序支付配置
|
|
||||||
|
|
||||||
return success($result);
|
return success($result);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 模拟支付成功-金额为0时使用
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @return array
|
||||||
|
* @throws ContainerExceptionInterface
|
||||||
|
* @throws NotFoundExceptionInterface
|
||||||
|
* @throws \GuzzleHttp\Exception\GuzzleException
|
||||||
|
*/
|
||||||
|
public function addPatientOrderPay(): array
|
||||||
|
{
|
||||||
|
$user_info = $this->request->getAttribute("userInfo") ?? [];
|
||||||
|
|
||||||
|
$order_no = $this->request->input('order_no');
|
||||||
|
|
||||||
|
Db::beginTransaction();
|
||||||
|
try {
|
||||||
|
// 问诊订单
|
||||||
|
$params = array();
|
||||||
|
$params['inquiry_no'] = $order_no;
|
||||||
|
$params['patient_id'] = $user_info['client_user_id'];
|
||||||
|
$order_inquiry = OrderInquiry::getOne($params);
|
||||||
|
if (empty($order_inquiry)) {
|
||||||
|
Db::rollBack();
|
||||||
|
return fail(HttpEnumCode::HTTP_ERROR, "非法订单");
|
||||||
|
}
|
||||||
|
|
||||||
|
// 验证订单状态
|
||||||
|
if ($order_inquiry['inquiry_status'] != 1){
|
||||||
|
Db::rollBack();
|
||||||
|
// 问诊订单状态(1:待支付 2:待分配 3:待接诊 4:已接诊 5:已完成 6:已结束 7:已取消)
|
||||||
|
return fail(HttpEnumCode::HTTP_ERROR, "支付失败");
|
||||||
|
}
|
||||||
|
|
||||||
|
// 验证支付金额
|
||||||
|
if ($order_inquiry['payment_amount_total'] != 0){
|
||||||
|
Db::rollBack();
|
||||||
|
return fail(HttpEnumCode::HTTP_ERROR, "支付失败");
|
||||||
|
}
|
||||||
|
|
||||||
|
// 修改支付状态
|
||||||
|
$data = array();
|
||||||
|
$data['inquiry_pay_status'] = 2;
|
||||||
|
if ($order_inquiry['inquiry_type'] == 1 || $order_inquiry['inquiry_type'] == 3){
|
||||||
|
// 专家-公益
|
||||||
|
$data['inquiry_status'] = 3;// 3:待接诊
|
||||||
|
}elseif ($order_inquiry['inquiry_type'] == 2 || $order_inquiry['inquiry_type'] == 4){
|
||||||
|
// 快速-购药
|
||||||
|
$data['inquiry_status'] = 2;// 2:待分配
|
||||||
|
}
|
||||||
|
|
||||||
|
$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 ($order_inquiry['inquiry_type'] == 2 || $order_inquiry['inquiry_type'] == 4){
|
||||||
|
// 快速-购药
|
||||||
|
// 加入分配医生队列
|
||||||
|
$data = array();
|
||||||
|
$data['order_inquiry_id'] = $order_inquiry['order_inquiry_id'];
|
||||||
|
|
||||||
|
$message = new AssignDoctorProducer($data);
|
||||||
|
$producer = ApplicationContext::getContainer()->get(Producer::class);
|
||||||
|
$result = $producer->produce($message);
|
||||||
|
if (!$result) {
|
||||||
|
Db::rollBack();
|
||||||
|
return fail(HttpEnumCode::HTTP_ERROR, "分配医生失败");
|
||||||
|
}
|
||||||
|
}elseif ($order_inquiry['inquiry_type'] == 1 || $order_inquiry['inquiry_type'] == 3){
|
||||||
|
// 专家-公益,发送im消息
|
||||||
|
$ImService = new ImService();
|
||||||
|
|
||||||
|
// 获取订单医生数据
|
||||||
|
$params = array();
|
||||||
|
$params['doctor_id'] = $order_inquiry['doctor_id'];
|
||||||
|
$user_doctor = UserDoctor::getOne($params);
|
||||||
|
if (empty($user_doctor)){
|
||||||
|
Db::rollBack();
|
||||||
|
return fail(HttpEnumCode::HTTP_ERROR, "医生数据错误");
|
||||||
|
}
|
||||||
|
|
||||||
|
// 发送消息
|
||||||
|
$ImService->sendTextMessage($user_doctor['user_id'],$order_inquiry['user_id'],"等待医生接诊",$order_inquiry['order_inquiry_id'],$order_inquiry['inquiry_type']);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Db::commit();
|
||||||
|
} catch (\Exception $e) {
|
||||||
|
Db::rollBack();
|
||||||
|
return fail(HttpEnumCode::SERVER_ERROR,$e->getMessage());
|
||||||
|
}
|
||||||
|
|
||||||
|
return success();
|
||||||
|
}
|
||||||
|
|
||||||
// 创建药品订单
|
// 创建药品订单
|
||||||
public function addPatientProductOrder(): array
|
public function addPatientProductOrder(): array
|
||||||
{
|
{
|
||||||
|
|||||||
@ -335,6 +335,9 @@ Router::addGroup('/patient', function () {
|
|||||||
|
|
||||||
// 获取患者订单支付数据
|
// 获取患者订单支付数据
|
||||||
Router::get('/pay', [PatientOrderController::class, 'getPatientOrderPayInfo']);
|
Router::get('/pay', [PatientOrderController::class, 'getPatientOrderPayInfo']);
|
||||||
|
|
||||||
|
// 模拟支付成功-金额为0时使用
|
||||||
|
Router::post('/pay', [PatientOrderController::class, 'addPatientOrderPay']);
|
||||||
});
|
});
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user