新增未开发路由
This commit is contained in:
@@ -4,16 +4,21 @@ namespace App\Services;
|
||||
|
||||
use App\Amqp\Producer\CancelUnpayOrdersDelayDirectProducer;
|
||||
use App\Constants\HttpEnumCode;
|
||||
use App\Exception\BusinessException;
|
||||
use App\Model\DiseaseClass;
|
||||
use App\Model\InquiryCaseProduct;
|
||||
use App\Model\OrderEvaluation;
|
||||
use App\Model\OrderInquiry;
|
||||
use App\Model\OrderInquiryCase;
|
||||
use App\Model\OrderInquiryCoupon;
|
||||
use App\Model\OrderInquiryRefund;
|
||||
use App\Model\PatientFamily;
|
||||
use App\Model\PatientFamilyHealth;
|
||||
use App\Model\PatientFamilyPersonal;
|
||||
use App\Model\Product;
|
||||
use App\Model\UserDoctor;
|
||||
use App\Model\UserPatient;
|
||||
use App\Utils\Mask;
|
||||
use App\Utils\PcreMatch;
|
||||
use Extend\Wechat\WechatPay;
|
||||
use Hyperf\Amqp\Producer;
|
||||
@@ -361,6 +366,116 @@ class InquiryService extends BaseService
|
||||
return success($order_inquiry_case->toArray());
|
||||
}
|
||||
|
||||
/**
|
||||
* 检测快速、购药订单分配医生状态
|
||||
* @return array
|
||||
*/
|
||||
public function getInquiryAssign(): array
|
||||
{
|
||||
$user_info = $this->request->getAttribute("userInfo") ?? [];
|
||||
$order_inquiry_id = $this->request->route('order_inquiry_id');
|
||||
|
||||
$params = array();
|
||||
$params['order_inquiry_id'] = $order_inquiry_id;
|
||||
$params['patient_id'] = $user_info['client_user_id'];
|
||||
$order_inquiry = OrderInquiry::getOne($params);
|
||||
if (empty($order_inquiry)) {
|
||||
return fail();
|
||||
}
|
||||
|
||||
if (empty($order_inquiry['doctor_id'])) {
|
||||
return success();
|
||||
}
|
||||
|
||||
// 检测订单类型
|
||||
if ($order_inquiry['inquiry_type'] != 2 && $order_inquiry['inquiry_type'] != 4) {
|
||||
return fail(HttpEnumCode::HTTP_ERROR, "订单类型不允许检测");
|
||||
}
|
||||
|
||||
// 检测订单退款状态
|
||||
if (!in_array($order_inquiry['inquiry_refund_status'], [0, 4, 5])) {
|
||||
// 问诊订单退款状态(0:无退款 1:申请退款 2:退款中 3:退款成功 4:拒绝退款 5:退款关闭)
|
||||
return fail(HttpEnumCode::HTTP_ERROR, "订单已退款");
|
||||
}
|
||||
|
||||
$result = array();
|
||||
$result['doctor_id'] = $order_inquiry['doctor_id'];
|
||||
|
||||
return success($result);
|
||||
}
|
||||
|
||||
/**
|
||||
* 新增医生评价
|
||||
* @return array
|
||||
*/
|
||||
public function addInquiryEvaluation(): array
|
||||
{
|
||||
$user_info = $this->request->getAttribute("userInfo") ?? [];
|
||||
$doctor_id = $this->request->input('doctor_id');
|
||||
$order_inquiry_id = $this->request->input('order_inquiry_id');
|
||||
$reply_quality = $this->request->input('reply_quality');
|
||||
$service_attitude = $this->request->input('service_attitude');
|
||||
$reply_progress = $this->request->input('reply_progress'); //
|
||||
$content = $this->request->input('content');
|
||||
|
||||
$params = array();
|
||||
$params['order_inquiry_id'] = $order_inquiry_id;
|
||||
$params['patient_id'] = $user_info['client_user_id'];
|
||||
$order_inquiry = OrderInquiry::getOne($params);
|
||||
if (empty($order_inquiry)) {
|
||||
return fail();
|
||||
}
|
||||
|
||||
// 检测订单状态
|
||||
if ($order_inquiry['inquiry_status'] != 5) {
|
||||
// 问诊订单状态(1:待支付 2:待分配 3:待接诊 4:已接诊 5:已完成 6:已结束 7:已取消)
|
||||
return fail(HttpEnumCode::HTTP_ERROR, "请问诊完成后进行评价");
|
||||
}
|
||||
|
||||
// 检测是否评价过
|
||||
$params = array();
|
||||
$params['doctor_id'] = $doctor_id;
|
||||
$params['patient_id'] = $user_info['client_user_id'];
|
||||
$params['order_inquiry_id'] = $order_inquiry_id;;
|
||||
$order_evaluation = OrderEvaluation::getOne($params);
|
||||
if (!empty($order_evaluation)){
|
||||
// 已评价
|
||||
return success();
|
||||
}
|
||||
|
||||
// 获取用户数据
|
||||
$params = array();
|
||||
$params['patient_id'] = $user_info['client_user_id'];
|
||||
$user_patient = UserPatient::getOne($params);
|
||||
|
||||
// 整理数据
|
||||
$reply_quality = $reply_quality * 20;
|
||||
$service_attitude = $service_attitude * 20;
|
||||
$reply_progress = $reply_progress * 20;
|
||||
|
||||
// 计算平均值 (百分制,回复质量占4、服务态度占3、回复速度占3,计算公式:每个得分 * 占比 相加)
|
||||
$avg_score = $reply_quality * 0.4 + $service_attitude * 0.3 + $reply_progress * 0.3;
|
||||
|
||||
$data = array();
|
||||
$data['doctor_id'] = $doctor_id;
|
||||
$data['patient_id'] = $user_info['client_user_id'];
|
||||
$data['order_inquiry_id'] = $order_inquiry_id;
|
||||
$data['name_mask'] = Mask::maskNameStr($user_patient['user_name']);
|
||||
$data['reply_quality'] = $reply_quality;
|
||||
$data['service_attitude'] = $service_attitude;
|
||||
$data['reply_progress'] = $reply_progress;
|
||||
$data['avg_score'] = $avg_score;
|
||||
$data['type'] = 1;
|
||||
$data['content'] = $content;
|
||||
$order_evaluation = OrderEvaluation::addOrderEvaluation($data);
|
||||
if (empty($order_evaluation)){
|
||||
return fail();
|
||||
}
|
||||
|
||||
return success();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 获取医生未接诊订单数量
|
||||
* @param string $doctor_id 医生id
|
||||
@@ -393,7 +508,7 @@ class InquiryService extends BaseService
|
||||
{
|
||||
$params = array();
|
||||
$params['doctor_id'] = $doctor_id;
|
||||
if (!empty($inquiry_type)){
|
||||
if (!empty($inquiry_type)) {
|
||||
$params['inquiry_type'] = $inquiry_type; // 订单类型(1:专家问诊 2:快速问诊 3:公益问诊 4:问诊购药)
|
||||
}
|
||||
$params['inquiry_status'] = 4; // 已接诊
|
||||
@@ -453,4 +568,107 @@ class InquiryService extends BaseService
|
||||
$params['inquiry_status'] = $inquiry_status;
|
||||
return OrderInquiry::getCount($params);
|
||||
}
|
||||
|
||||
/**
|
||||
* 订单退款接口
|
||||
* 务必外层接收异常,回滚事务
|
||||
* @param string $order_inquiry_id
|
||||
* @param string $refund_reason 退款原因
|
||||
* @throws ContainerExceptionInterface
|
||||
* @throws NotFoundExceptionInterface
|
||||
*/
|
||||
public function inquiryRefund(string $order_inquiry_id, string $refund_reason)
|
||||
{
|
||||
// 获取订单数据
|
||||
$params = array();
|
||||
$params['order_inquiry_id'] = $order_inquiry_id;
|
||||
$order_inquiry = OrderInquiry::getOne($params);
|
||||
if (empty($order_inquiry)) {
|
||||
throw new BusinessException("订单数据为空");
|
||||
}
|
||||
|
||||
// 检测问诊订单状态
|
||||
if (in_array($order_inquiry['inquiry_status'], [2, 3, 4, 5])) {
|
||||
// 问诊订单状态(1:待支付 2:待分配 3:待接诊 4:已接诊 5:已完成 6:已结束 7:已取消)
|
||||
throw new BusinessException("订单状态错误");
|
||||
}
|
||||
|
||||
// 检测订单退款状态
|
||||
if (in_array($order_inquiry['inquiry_refund_status'], [2, 3, 4, 5])) {
|
||||
// 问诊订单退款状态(0:无退款 1:申请退款 2:退款中 3:退款成功 4:拒绝退款 5:退款关闭)
|
||||
throw new BusinessException("订单退款状态错误");
|
||||
}
|
||||
|
||||
// 检测支付状态
|
||||
if (in_array($order_inquiry['inquiry_pay_status'], [2])) {
|
||||
// 支付状态(1:未支付 2:已支付 3:支付中 4:支付失败 5:支付超时 6:支付关闭 7:已撤销 8:转入退款)
|
||||
throw new BusinessException("订单支付状态错误");
|
||||
}
|
||||
|
||||
// 发起退款
|
||||
$WechatPay = new WechatPay(1);
|
||||
|
||||
$generator = $this->container->get(IdGeneratorInterface::class);
|
||||
|
||||
// 系统退款编号
|
||||
$inquiry_refund_no = $generator->generate();
|
||||
|
||||
$options = array();
|
||||
$options['transaction_id'] = $order_inquiry['escrow_trade_no'];
|
||||
$options['out_refund_no'] = $inquiry_refund_no;
|
||||
$options['reason'] = $refund_reason;
|
||||
$options['amount'] = [
|
||||
'refund' => (int)$order_inquiry['payment_amount_total'] * 100,
|
||||
'total' => (int)$order_inquiry['payment_amount_total'] * 100,
|
||||
'currency' => "CNY",
|
||||
];
|
||||
|
||||
$result = $WechatPay->refund($options);
|
||||
|
||||
// 处理订单退款状态
|
||||
// 问诊订单退款状态(0:无退款 1:申请退款 2:退款中 3:退款成功 4:拒绝退款 5:退款关闭)
|
||||
if ($result['status'] == "SUCCESS") {
|
||||
// 退款成功
|
||||
$inquiry_refund_status = 3;
|
||||
} elseif ($result['status'] == "CLOSED") {
|
||||
// 退款关闭
|
||||
$inquiry_refund_status = 5;
|
||||
} elseif ($result['status'] == "PROCESSING") {
|
||||
// 退款处理中
|
||||
$inquiry_refund_status = 2;
|
||||
} elseif ($result['status'] == "ABNORMAL") {
|
||||
// 退款异常,此情况不处理,进行短信通知
|
||||
throw new BusinessException("订单退款状态异常");
|
||||
} else {
|
||||
throw new BusinessException("订单退款状态错误");
|
||||
}
|
||||
|
||||
// 新增退款表
|
||||
$data = array();
|
||||
$data['patient_id'] = $order_inquiry['patient_id'];
|
||||
$data['order_inquiry_id'] = $order_inquiry['order_inquiry_id'];
|
||||
$data['inquiry_no'] = $order_inquiry['inquiry_no'];
|
||||
$data['inquiry_refund_no'] = $inquiry_refund_no;
|
||||
$data['refund_id'] = $result['refund_id'];
|
||||
$data['inquiry_refund_status'] = $inquiry_refund_status;
|
||||
$data['refund_total'] = $order_inquiry['payment_amount_total'];
|
||||
$data['refund_reason'] = $refund_reason;
|
||||
|
||||
if ($inquiry_refund_status == 3 && !empty($result['success_time'])) {
|
||||
$data['success_time'] = date("Y-m-d H:i:s", strtotime($result['success_time'])); // 退款成功时间
|
||||
}
|
||||
|
||||
$order_inquiry_refund = OrderInquiryRefund::addOrderInquiryRefund($data);
|
||||
if (empty($order_inquiry_refund)) {
|
||||
throw new BusinessException("添加退款表失败");
|
||||
}
|
||||
|
||||
// 修改问诊订单表状态
|
||||
$data = array();
|
||||
$data['inquiry_refund_status'] = $inquiry_refund_status;
|
||||
|
||||
$params = array();
|
||||
$params['order_inquiry_id'] = $order_inquiry['order_inquiry_id'];
|
||||
OrderInquiry::edit($params, $data);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user