新增取消药品订单队列,新增创建药品订单
This commit is contained in:
parent
a801c11121
commit
e97538a34a
@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
@ -15,6 +15,7 @@ use Hyperf\Snowflake\Concern\Snowflake;
|
||||
* @property int $prescription_product_id 主键id
|
||||
* @property int $order_prescription_id 订单-处方id
|
||||
* @property int $product_id 商品id
|
||||
* @property int $use_status 使用状态(1:已使用 0:未使用)
|
||||
* @property int $prescription_product_num 商品数量
|
||||
* @property string $product_name 商品名称
|
||||
* @property string $product_spec 商品规格
|
||||
@ -41,7 +42,7 @@ class OrderPrescriptionProduct extends Model
|
||||
/**
|
||||
* The attributes that are mass assignable.
|
||||
*/
|
||||
protected array $fillable = ['prescription_product_id', 'order_prescription_id', 'product_id', 'prescription_product_num', 'product_name', 'product_spec', 'license_number', 'manufacturer', 'single_unit', 'single_use', 'packaging_unit', 'frequency_use', 'available_days', 'created_at', 'updated_at'];
|
||||
protected array $fillable = ['prescription_product_id', 'order_prescription_id', 'product_id', 'use_status', 'prescription_product_num', 'product_name', 'product_spec', 'license_number', 'manufacturer', 'single_unit', 'single_use', 'packaging_unit', 'frequency_use', 'available_days', 'created_at', 'updated_at'];
|
||||
|
||||
protected string $primaryKey = "prescription_product_id";
|
||||
/**
|
||||
@ -149,4 +150,9 @@ class OrderPrescriptionProduct extends Model
|
||||
->where($params)->first($fields);
|
||||
|
||||
}
|
||||
|
||||
public static function edit(array $params = [], array $data = []): int
|
||||
{
|
||||
return self::where($params)->update($data);
|
||||
}
|
||||
}
|
||||
|
||||
@ -25,6 +25,8 @@ class PatientOrderRequest extends FormRequest
|
||||
'addPatientProductOrder' => [ // 创建药品订单
|
||||
"order_prescription_id",
|
||||
"address_id",
|
||||
"product_ids",
|
||||
"client_type",
|
||||
],
|
||||
'getPatientPrescriptionOrderList' => [ // 获取处方订单列表
|
||||
],
|
||||
@ -69,6 +71,7 @@ class PatientOrderRequest extends FormRequest
|
||||
|
||||
'order_prescription_id' => 'required',
|
||||
'address_id' => 'required',
|
||||
'product_ids' => 'required|array|min:1',
|
||||
];
|
||||
}
|
||||
|
||||
@ -118,6 +121,9 @@ class PatientOrderRequest extends FormRequest
|
||||
'order_no.required' => HttpEnumCode::getMessage(HttpEnumCode::CLIENT_HTTP_ERROR),
|
||||
'order_prescription_id.required' => HttpEnumCode::getMessage(HttpEnumCode::CLIENT_HTTP_ERROR),
|
||||
'address_id.required' => HttpEnumCode::getMessage(HttpEnumCode::CLIENT_HTTP_ERROR),
|
||||
'product_ids.required' => HttpEnumCode::getMessage(HttpEnumCode::CLIENT_HTTP_ERROR),
|
||||
'product_ids.array' => HttpEnumCode::getMessage(HttpEnumCode::CLIENT_HTTP_ERROR),
|
||||
'product_ids.min' => HttpEnumCode::getMessage(HttpEnumCode::CLIENT_HTTP_ERROR),
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
@ -212,15 +212,6 @@ class InquiryService extends BaseService
|
||||
return fail(HttpEnumCode::HTTP_ERROR, "意向药品错误");
|
||||
}
|
||||
|
||||
// 检测商品库存
|
||||
// if (!empty($product['ProductPlatformAmount'])) {
|
||||
// if ($item['product_num'] > $product['ProductPlatformAmount']['real_stock']) {
|
||||
// // 此处是否需要特殊返回
|
||||
// Db::rollBack();
|
||||
// return fail(HttpEnumCode::HTTP_ERROR, "意向药品库存不足");
|
||||
// }
|
||||
// }
|
||||
|
||||
// 用药意向是否和过敏史重叠
|
||||
if (!empty($request_params['allergy_history'])) {
|
||||
$res = strpos($request_params['allergy_history'], $product['product_name']);
|
||||
@ -240,15 +231,6 @@ class InquiryService extends BaseService
|
||||
Db::rollBack();
|
||||
return fail(HttpEnumCode::SERVER_ERROR, "订单创建失败");
|
||||
}
|
||||
|
||||
// 锁定库存
|
||||
// 实际库存-1
|
||||
// $params = array();
|
||||
// $params['amount_id'] = $product['ProductPlatformAmount']['amount_id'];
|
||||
// ProductPlatformAmount::dec($params,'real_stock',$item['product_num']);
|
||||
//
|
||||
// // 锁定库存+1
|
||||
// ProductPlatformAmount::inc($params,'lock_stock',$item['product_num']);
|
||||
}
|
||||
}
|
||||
|
||||
@ -284,7 +266,7 @@ class InquiryService extends BaseService
|
||||
}
|
||||
|
||||
$result = array();
|
||||
$result['inquiry_no'] = $order_inquiry['inquiry_no']; // 订单编号
|
||||
$result['inquiry_no'] = (string)$order_inquiry['inquiry_no']; // 订单编号
|
||||
$result['order_inquiry_id'] = $order_inquiry['order_inquiry_id']; // 订单主键id
|
||||
|
||||
return success($result);
|
||||
|
||||
@ -13,6 +13,7 @@ use App\Model\OrderPrescriptionProduct;
|
||||
use App\Model\OrderProduct;
|
||||
use App\Model\OrderProductItem;
|
||||
use App\Model\Product;
|
||||
use App\Model\ProductPlatformAmount;
|
||||
use App\Model\UserDoctor;
|
||||
use App\Model\UserShipAddress;
|
||||
use Extend\Wechat\WechatPay;
|
||||
@ -35,35 +36,35 @@ class PatientOrderService extends BaseService
|
||||
{
|
||||
$user_info = $this->request->getAttribute("userInfo") ?? [];
|
||||
|
||||
$inquiry_status = $this->request->input('inquiry_status',0);
|
||||
$inquiry_status = $this->request->input('inquiry_status', 0);
|
||||
$family_id = $this->request->input('family_id');
|
||||
$page = $this->request->input('page',1);
|
||||
$per_page = $this->request->input('per_page',10);
|
||||
$page = $this->request->input('page', 1);
|
||||
$per_page = $this->request->input('per_page', 10);
|
||||
|
||||
$params = array();
|
||||
$params['patient_id'] = $user_info['client_user_id'];
|
||||
if (!empty($family_id)){
|
||||
if (!empty($family_id)) {
|
||||
$params['family_id'] = $family_id;
|
||||
}
|
||||
|
||||
$inquiry_status_params = [];
|
||||
if (!empty($inquiry_status) && $inquiry_status != 0){
|
||||
if (!empty($inquiry_status) && $inquiry_status != 0) {
|
||||
// 问诊订单状态(0:全部 1:待支付 2:待接诊 3:问诊中 4:完成/取消
|
||||
// 问诊订单状态(1:待支付 2:待分配 3:待接诊 4:已接诊 5:已完成 6:已结束 7:已取消)
|
||||
if ($inquiry_status == 1){
|
||||
if ($inquiry_status == 1) {
|
||||
$inquiry_status_params = [1];
|
||||
}
|
||||
|
||||
if ($inquiry_status == 2){
|
||||
$inquiry_status_params = [2,3];
|
||||
if ($inquiry_status == 2) {
|
||||
$inquiry_status_params = [2, 3];
|
||||
}
|
||||
|
||||
if ($inquiry_status == 3){
|
||||
if ($inquiry_status == 3) {
|
||||
$inquiry_status_params = [4];
|
||||
}
|
||||
|
||||
if ($inquiry_status == 4){
|
||||
$inquiry_status_params = [5,6,7];
|
||||
if ($inquiry_status == 4) {
|
||||
$inquiry_status_params = [5, 6, 7];
|
||||
}
|
||||
}
|
||||
|
||||
@ -91,18 +92,18 @@ class PatientOrderService extends BaseService
|
||||
'patient_age',
|
||||
'created_at',
|
||||
];
|
||||
$order_inquiry = OrderInquiry::getPatientOrderInquiryPage($params,$inquiry_status_params,$fields,$page,$per_page);
|
||||
if (empty($order_inquiry['data'])){
|
||||
$order_inquiry = OrderInquiry::getPatientOrderInquiryPage($params, $inquiry_status_params, $fields, $page, $per_page);
|
||||
if (empty($order_inquiry['data'])) {
|
||||
return success();
|
||||
}
|
||||
|
||||
foreach ($order_inquiry['data'] as &$item){
|
||||
foreach ($order_inquiry['data'] as &$item) {
|
||||
$item['disease_desc'] = $item['OrderInquiryCase']['disease_desc'];
|
||||
unset($item['OrderInquiryCase']);
|
||||
|
||||
// 获取医生数据
|
||||
$item['user_doctor'] = [];
|
||||
if (!empty($item['doctor_id'])){
|
||||
if (!empty($item['doctor_id'])) {
|
||||
$fields = [
|
||||
'doctor_id',
|
||||
'user_name',
|
||||
@ -112,8 +113,8 @@ class PatientOrderService extends BaseService
|
||||
|
||||
$params = array();
|
||||
$params['doctor_id'] = $item['doctor_id'];
|
||||
$user_doctor = UserDoctor::getOne($params,$fields);
|
||||
if (empty($user_doctor)){
|
||||
$user_doctor = UserDoctor::getOne($params, $fields);
|
||||
if (empty($user_doctor)) {
|
||||
return fail(HttpEnumCode::SERVER_ERROR);
|
||||
}
|
||||
|
||||
@ -132,8 +133,8 @@ class PatientOrderService extends BaseService
|
||||
|
||||
$params = array();
|
||||
$params['hospital_id'] = $user_doctor['hospital_id'];
|
||||
$hospital = Hospital::getOne($params,$fields);
|
||||
if (!empty($hospital)){
|
||||
$hospital = Hospital::getOne($params, $fields);
|
||||
if (!empty($hospital)) {
|
||||
$user_doctor['hospital_name'] = $hospital['hospital_name'];
|
||||
$user_doctor['hospital_level_name'] = $hospital['hospital_level_name'];
|
||||
}
|
||||
@ -163,7 +164,7 @@ class PatientOrderService extends BaseService
|
||||
$params['order_inquiry_id'] = $order_inquiry_id;
|
||||
$params['is_delete'] = 0;
|
||||
$order_inquiry = OrderInquiry::getOne($params);
|
||||
if (empty($order_inquiry)){
|
||||
if (empty($order_inquiry)) {
|
||||
return fail();
|
||||
}
|
||||
|
||||
@ -174,8 +175,8 @@ class PatientOrderService extends BaseService
|
||||
];
|
||||
$params = array();
|
||||
$params['order_inquiry_id'] = $order_inquiry['order_inquiry_id'];
|
||||
$order_inquiry_case = OrderInquiryCase::getOne($params,$fields);
|
||||
if (empty($order_inquiry_case)){
|
||||
$order_inquiry_case = OrderInquiryCase::getOne($params, $fields);
|
||||
if (empty($order_inquiry_case)) {
|
||||
return fail();
|
||||
}
|
||||
|
||||
@ -183,7 +184,7 @@ class PatientOrderService extends BaseService
|
||||
|
||||
// 获取医生数据
|
||||
$order_inquiry['user_doctor'] = [];
|
||||
if (!empty($order_inquiry['doctor_id'])){
|
||||
if (!empty($order_inquiry['doctor_id'])) {
|
||||
$fields = [
|
||||
'doctor_id',
|
||||
'user_name',
|
||||
@ -194,8 +195,8 @@ class PatientOrderService extends BaseService
|
||||
|
||||
$params = array();
|
||||
$params['doctor_id'] = $order_inquiry['doctor_id'];
|
||||
$user_doctor = UserDoctor::getOne($params,$fields);
|
||||
if (empty($user_doctor)){
|
||||
$user_doctor = UserDoctor::getOne($params, $fields);
|
||||
if (empty($user_doctor)) {
|
||||
return fail(HttpEnumCode::SERVER_ERROR);
|
||||
}
|
||||
|
||||
@ -217,8 +218,8 @@ class PatientOrderService extends BaseService
|
||||
|
||||
$params = array();
|
||||
$params['hospital_id'] = $user_doctor['hospital_id'];
|
||||
$hospital = Hospital::getOne($params,$fields);
|
||||
if (!empty($hospital)){
|
||||
$hospital = Hospital::getOne($params, $fields);
|
||||
if (!empty($hospital)) {
|
||||
$user_doctor['hospital_name'] = $hospital['hospital_name'];
|
||||
$user_doctor['hospital_level_name'] = $hospital['hospital_level_name'];
|
||||
}
|
||||
@ -249,19 +250,19 @@ class PatientOrderService extends BaseService
|
||||
$params['order_inquiry_id'] = $order_inquiry_id;
|
||||
$params['is_delete'] = 0;
|
||||
$order_inquiry = OrderInquiry::getOne($params);
|
||||
if (empty($order_inquiry)){
|
||||
if (empty($order_inquiry)) {
|
||||
return fail();
|
||||
}
|
||||
|
||||
// 检测订单状态
|
||||
if (!in_array($order_inquiry['inquiry_status'],[1,2,3])) {
|
||||
if (!in_array($order_inquiry['inquiry_status'], [1, 2, 3])) {
|
||||
// 问诊订单状态(1:待支付 2:待分配 3:待接诊 4:已接诊 5:已完成 6:已结束 7:已取消)
|
||||
return fail(HttpEnumCode::HTTP_ERROR,"订单无法取消");
|
||||
return fail(HttpEnumCode::HTTP_ERROR, "订单无法取消");
|
||||
}
|
||||
|
||||
if (!in_array($order_inquiry['inquiry_refund_status'],[0,4,5])) {
|
||||
if (!in_array($order_inquiry['inquiry_refund_status'], [0, 4, 5])) {
|
||||
// 问诊订单退款状态(0:无退款 1:申请退款 2:退款中 3:退款成功 4:拒绝退款 5:退款关闭)
|
||||
return fail(HttpEnumCode::HTTP_ERROR,"订单正在退款中");
|
||||
return fail(HttpEnumCode::HTTP_ERROR, "订单正在退款中");
|
||||
}
|
||||
|
||||
// 支付状态(1:未支付 2:已支付 3:支付中 4:支付失败 5:支付超时 6:支付关闭 7:已撤销 8:转入退款)
|
||||
@ -271,19 +272,19 @@ class PatientOrderService extends BaseService
|
||||
// 修改问诊订单为取消
|
||||
$data = array();
|
||||
$data['inquiry_status'] = 7;
|
||||
$data['cancel_time'] = date("Y-m-d H:i:s",time());
|
||||
$data['cancel_time'] = date("Y-m-d H:i:s", time());
|
||||
$data['cancel_reason'] = 2; // 取消订单原因(1:医生未接诊 2:主动取消 3:无可分配医生 4:客服取消 5:支付超时)
|
||||
$data['updated_at'] = date("Y-m-d H:i:s",time());
|
||||
$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);
|
||||
OrderInquiry::edit($params, $data);
|
||||
|
||||
// 检测支付状态,判断是否需要退款处理
|
||||
if ($order_inquiry['inquiry_pay_status'] == 2){
|
||||
if ($order_inquiry['inquiry_pay_status'] == 2) {
|
||||
// 需退款
|
||||
$inquiryService = new InquiryService();
|
||||
$inquiryService->inquiryRefund($order_inquiry['order_inquiry_id'],"取消问诊");
|
||||
$inquiryService->inquiryRefund($order_inquiry['order_inquiry_id'], "取消问诊");
|
||||
}
|
||||
|
||||
Db::commit();
|
||||
@ -314,14 +315,14 @@ class PatientOrderService extends BaseService
|
||||
$params['order_inquiry_id'] = $order_inquiry_id;
|
||||
$params['is_delete'] = 0;
|
||||
$order_inquiry = OrderInquiry::getOne($params);
|
||||
if (empty($order_inquiry)){
|
||||
if (empty($order_inquiry)) {
|
||||
return fail();
|
||||
}
|
||||
|
||||
// 检测订单状态
|
||||
if (!in_array($order_inquiry['inquiry_status'],[6,7])) {
|
||||
if (!in_array($order_inquiry['inquiry_status'], [6, 7])) {
|
||||
// 问诊订单状态(1:待支付 2:待分配 3:待接诊 4:已接诊 5:已完成 6:已结束 7:已取消)
|
||||
return fail(HttpEnumCode::HTTP_ERROR,"订单无法删除");
|
||||
return fail(HttpEnumCode::HTTP_ERROR, "订单无法删除");
|
||||
}
|
||||
|
||||
// 修改订单删除状态
|
||||
@ -331,7 +332,7 @@ class PatientOrderService extends BaseService
|
||||
$params = array();
|
||||
$params['order_inquiry_id'] = $order_inquiry['order_inquiry_id'];
|
||||
|
||||
OrderInquiry::edit($params,$data);
|
||||
OrderInquiry::edit($params, $data);
|
||||
|
||||
return success();
|
||||
}
|
||||
@ -352,32 +353,32 @@ class PatientOrderService extends BaseService
|
||||
$params['order_inquiry_id'] = $order_inquiry_id;
|
||||
$params['is_delete'] = 0;
|
||||
$order_inquiry = OrderInquiry::getOne($params);
|
||||
if (empty($order_inquiry)){
|
||||
if (empty($order_inquiry)) {
|
||||
return fail();
|
||||
}
|
||||
|
||||
// 检测订单状态
|
||||
if ($order_inquiry['inquiry_status'] != 1) {
|
||||
// 问诊订单状态(1:待支付 2:待分配 3:待接诊 4:已接诊 5:已完成 6:已结束 7:已取消)
|
||||
return fail(HttpEnumCode::HTTP_ERROR,"订单无法取消支付");
|
||||
return fail(HttpEnumCode::HTTP_ERROR, "订单无法取消支付");
|
||||
}
|
||||
|
||||
if (!in_array($order_inquiry['inquiry_refund_status'],[0,4,5])) {
|
||||
if (!in_array($order_inquiry['inquiry_refund_status'], [0, 4, 5])) {
|
||||
// 问诊订单退款状态(0:无退款 1:申请退款 2:退款中 3:退款成功 4:拒绝退款 5:退款关闭)
|
||||
return fail(HttpEnumCode::HTTP_ERROR,"订单正在退款中");
|
||||
return fail(HttpEnumCode::HTTP_ERROR, "订单正在退款中");
|
||||
}
|
||||
|
||||
// 修改订单状态
|
||||
$data = array();
|
||||
$data['inquiry_status'] = 7;
|
||||
$data['cancel_time'] = date("Y-m-d H:i:s",time());
|
||||
$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());
|
||||
$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);
|
||||
OrderInquiry::edit($params, $data);
|
||||
|
||||
return success();
|
||||
}
|
||||
@ -390,19 +391,19 @@ class PatientOrderService extends BaseService
|
||||
{
|
||||
$user_info = $this->request->getAttribute("userInfo") ?? [];
|
||||
|
||||
$order_product_status = $this->request->input('order_product_status',0);
|
||||
$order_product_status = $this->request->input('order_product_status', 0);
|
||||
$family_id = $this->request->input('family_id');
|
||||
$page = $this->request->input('page',1);
|
||||
$per_page = $this->request->input('per_page',10);
|
||||
$page = $this->request->input('page', 1);
|
||||
$per_page = $this->request->input('per_page', 10);
|
||||
|
||||
|
||||
$params = array();
|
||||
$params['patient_id'] = $user_info['client_user_id'];
|
||||
if (!empty($family_id)){
|
||||
if (!empty($family_id)) {
|
||||
$params['family_id'] = $family_id;
|
||||
}
|
||||
|
||||
if (!empty($inquiry_status_params) && $inquiry_status_params != 0){
|
||||
if (!empty($inquiry_status_params) && $inquiry_status_params != 0) {
|
||||
// 入参订单状态(1:待支付 2:待发货 3:已发货 4:已签收 5:已取消)
|
||||
// 数据库订单状态(1:待支付 2:待发货 3:已发货 4:已签收 5:已取消)
|
||||
$params['inquiry_status_params'] = $order_product_status;
|
||||
@ -426,13 +427,13 @@ class PatientOrderService extends BaseService
|
||||
'created_at',
|
||||
];
|
||||
|
||||
$order_product = OrderProduct::getPatientOrderProductPage($params,$fields,$page,$per_page);
|
||||
if (empty($order_product['data'])){
|
||||
$order_product = OrderProduct::getPatientOrderProductPage($params, $fields, $page, $per_page);
|
||||
if (empty($order_product['data'])) {
|
||||
return success();
|
||||
}
|
||||
|
||||
foreach ($order_product['data'] as $item){
|
||||
foreach ($item['orderProductItem'] as &$product_item){
|
||||
foreach ($order_product['data'] as $item) {
|
||||
foreach ($item['orderProductItem'] as &$product_item) {
|
||||
$product_item['product_cover_img'] = addAliyunOssWebsite($product_item['product_cover_img']);
|
||||
}
|
||||
}
|
||||
@ -456,23 +457,23 @@ class PatientOrderService extends BaseService
|
||||
$params['order_product_id'] = $order_product_id;
|
||||
$params['is_delete'] = 0;
|
||||
$order_product = OrderProduct::getOne($params);
|
||||
if (empty($order_product)){
|
||||
if (empty($order_product)) {
|
||||
return fail();
|
||||
}
|
||||
|
||||
$params = array();
|
||||
$params['order_product_id'] = $order_product['order_product_id'];
|
||||
$order_product_item = OrderProductItem::getList($params);
|
||||
if (empty($order_product_item)){
|
||||
if (empty($order_product_item)) {
|
||||
return fail();
|
||||
}
|
||||
|
||||
// 处理商品图片
|
||||
foreach ($order_product_item as &$item){
|
||||
foreach ($order_product_item as &$item) {
|
||||
$item['product_cover_img'] = addAliyunOssWebsite($item['product_cover_img']);
|
||||
}
|
||||
|
||||
if (!empty($order_product['doctor_id'])){
|
||||
if (!empty($order_product['doctor_id'])) {
|
||||
// 获取问诊医生数据
|
||||
$fields = [
|
||||
'doctor_id',
|
||||
@ -486,8 +487,8 @@ class PatientOrderService extends BaseService
|
||||
|
||||
$params = array();
|
||||
$params['doctor_id'] = $order_product['doctor_id'];
|
||||
$user_doctor = UserDoctor::getWithHospitalOne($params,$fields);
|
||||
if (empty($user_doctor)){
|
||||
$user_doctor = UserDoctor::getWithHospitalOne($params, $fields);
|
||||
if (empty($user_doctor)) {
|
||||
return fail(HttpEnumCode::SERVER_ERROR);
|
||||
}
|
||||
|
||||
@ -521,7 +522,7 @@ class PatientOrderService extends BaseService
|
||||
$params['order_product_id'] = $order_product_id;
|
||||
$params['is_delete'] = 0;
|
||||
$order_product = OrderProduct::getOne($params);
|
||||
if (empty($order_product)){
|
||||
if (empty($order_product)) {
|
||||
Db::rollBack();
|
||||
return fail();
|
||||
}
|
||||
@ -530,32 +531,32 @@ class PatientOrderService extends BaseService
|
||||
if ($order_product['order_product_status'] != 1) {
|
||||
Db::rollBack();
|
||||
// 订单状态(1:待支付 2:待发货 3:已发货 4:已签收 5:已取消)
|
||||
return fail(HttpEnumCode::HTTP_ERROR,"订单无法删除");
|
||||
return fail(HttpEnumCode::HTTP_ERROR, "订单无法删除");
|
||||
}
|
||||
|
||||
if ($order_product['pay_status'] != 1) {
|
||||
Db::rollBack();
|
||||
// 订单状态(1:待支付 2:待发货 3:已发货 4:已签收 5:已取消)
|
||||
return fail(HttpEnumCode::HTTP_ERROR,"订单无法删除");
|
||||
return fail(HttpEnumCode::HTTP_ERROR, "订单无法删除");
|
||||
}
|
||||
|
||||
if (!in_array($order_product['refund_status'],[0,4,5])) {
|
||||
if (!in_array($order_product['refund_status'], [0, 4, 5])) {
|
||||
Db::rollBack();
|
||||
// 商品订单退款状态(0:无退款 1:申请退款 2:退款中 3:退款成功 4:拒绝退款 5:退款关闭)
|
||||
return fail(HttpEnumCode::HTTP_ERROR,"订单正在退款中");
|
||||
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_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());
|
||||
$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);
|
||||
OrderProduct::edit($params, $data);
|
||||
|
||||
Db::commit();
|
||||
} catch (\Exception $e) {
|
||||
@ -584,27 +585,27 @@ class PatientOrderService extends BaseService
|
||||
$params['order_product_id'] = $order_product_id;
|
||||
$params['is_delete'] = 0;
|
||||
$order_product = OrderProduct::getOne($params);
|
||||
if (empty($order_product)){
|
||||
if (empty($order_product)) {
|
||||
return fail();
|
||||
}
|
||||
|
||||
if (!in_array($order_product['order_product_status'],[4,5])) {
|
||||
if (!in_array($order_product['order_product_status'], [4, 5])) {
|
||||
Db::rollBack();
|
||||
// 订单状态(1:待支付 2:待发货 3:已发货 4:已签收 5:已取消)
|
||||
return fail(HttpEnumCode::HTTP_ERROR,"订单无法删除");
|
||||
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_time'] = date("Y-m-d H:i:s", time());
|
||||
$data['cancel_reason'] = 1; // 订单取消原因(1:主动取消 2:复核失败/库存不足 3:支付超时
|
||||
$data['cancel_remarks'] = "主动取消";
|
||||
$data['updated_at'] = date("Y-m-d H:i:s",time());
|
||||
$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);
|
||||
OrderProduct::edit($params, $data);
|
||||
|
||||
return success();
|
||||
}
|
||||
@ -622,24 +623,24 @@ class PatientOrderService extends BaseService
|
||||
$order_type = $this->request->input('order_type');
|
||||
$order_no = $this->request->input('order_no');
|
||||
|
||||
if ($order_type == 1){
|
||||
if ($order_type == 1) {
|
||||
// 问诊订单
|
||||
$params = array();
|
||||
$params['inquiry_no'] = $order_no;
|
||||
$params['patient_id'] = $user_info['client_user_id'];
|
||||
$order_inquiry = OrderInquiry::getOne($params);
|
||||
if (empty($order_inquiry)){
|
||||
return fail(HttpEnumCode::HTTP_ERROR,"非法订单");
|
||||
if (empty($order_inquiry)) {
|
||||
return fail(HttpEnumCode::HTTP_ERROR, "非法订单");
|
||||
}
|
||||
|
||||
// 验证订单状态
|
||||
if ($order_inquiry['inquiry_status'] != 1){
|
||||
return fail(HttpEnumCode::HTTP_ERROR,"订单状态错误");
|
||||
if ($order_inquiry['inquiry_status'] != 1) {
|
||||
return fail(HttpEnumCode::HTTP_ERROR, "订单状态错误");
|
||||
}
|
||||
|
||||
// 验证订单支付状态
|
||||
if ($order_inquiry['inquiry_pay_status'] != 1){
|
||||
return fail(HttpEnumCode::HTTP_ERROR,"订单支付状态错误");
|
||||
if ($order_inquiry['inquiry_pay_status'] != 1) {
|
||||
return fail(HttpEnumCode::HTTP_ERROR, "订单支付状态错误");
|
||||
}
|
||||
|
||||
$order_id = $order_inquiry['order_inquiry_id'];
|
||||
@ -651,24 +652,24 @@ class PatientOrderService extends BaseService
|
||||
$payment_amount_total = $order_inquiry['payment_amount_total'];
|
||||
$coupon_amount_total = $order_inquiry['coupon_amount_total'];
|
||||
|
||||
}elseif ($order_type == 2){
|
||||
} elseif ($order_type == 2) {
|
||||
// 药品订单
|
||||
$params = array();
|
||||
$params['order_product_no'] = $order_no;
|
||||
$params['patient_id'] = $user_info['client_user_id'];
|
||||
$order_product = OrderProduct::getOne($params);
|
||||
if (empty($order_product)){
|
||||
return fail(HttpEnumCode::HTTP_ERROR,"非法订单");
|
||||
if (empty($order_product)) {
|
||||
return fail(HttpEnumCode::HTTP_ERROR, "非法订单");
|
||||
}
|
||||
|
||||
// 验证订单状态
|
||||
if ($order_product['order_product_status'] != 1){
|
||||
return fail(HttpEnumCode::HTTP_ERROR,"订单状态错误");
|
||||
if ($order_product['order_product_status'] != 1) {
|
||||
return fail(HttpEnumCode::HTTP_ERROR, "订单状态错误");
|
||||
}
|
||||
|
||||
// 验证订单支付状态
|
||||
if ($order_product['inquiry_pay_status'] != 1){
|
||||
return fail(HttpEnumCode::HTTP_ERROR,"订单支付状态错误");
|
||||
if ($order_product['inquiry_pay_status'] != 1) {
|
||||
return fail(HttpEnumCode::HTTP_ERROR, "订单支付状态错误");
|
||||
}
|
||||
|
||||
$order_id = $order_product['order_product_id'];
|
||||
@ -679,7 +680,7 @@ class PatientOrderService extends BaseService
|
||||
$amount_total = $order_product['amount_total'];
|
||||
$payment_amount_total = $order_product['payment_amount_total'];
|
||||
$coupon_amount_total = 0;
|
||||
}else{
|
||||
} else {
|
||||
return fail();
|
||||
}
|
||||
|
||||
@ -715,6 +716,8 @@ class PatientOrderService extends BaseService
|
||||
|
||||
$order_prescription_id = $this->request->input('order_prescription_id');
|
||||
$address_id = $this->request->input('address_id');
|
||||
$product_ids = $this->request->input('product_ids');
|
||||
$client_type = $this->request->input('client_type');
|
||||
|
||||
// 获取处方数据
|
||||
$params = array();
|
||||
@ -722,24 +725,24 @@ class PatientOrderService extends BaseService
|
||||
$params['patient_id'] = $user_info['client_user_id'];
|
||||
$params['is_delete'] = 0;
|
||||
$order_prescription = OrderPrescription::getOne($params);
|
||||
if (empty($order_prescription)){
|
||||
if (empty($order_prescription)) {
|
||||
return fail();
|
||||
}
|
||||
|
||||
// 验证处方状态
|
||||
if ($order_prescription['prescription_status'] == 1){
|
||||
return fail(HttpEnumCode::HTTP_ERROR,"处方未审核");
|
||||
if ($order_prescription['prescription_status'] == 1) {
|
||||
return fail(HttpEnumCode::HTTP_ERROR, "处方未审核");
|
||||
}
|
||||
|
||||
if ($order_prescription['prescription_status'] == 3){
|
||||
return fail(HttpEnumCode::HTTP_ERROR,"已失效");
|
||||
if ($order_prescription['prescription_status'] == 3) {
|
||||
return fail(HttpEnumCode::HTTP_ERROR, "处方已失效");
|
||||
}
|
||||
if ($order_prescription['prescription_status'] == 4){
|
||||
return fail(HttpEnumCode::HTTP_ERROR,"已使用");
|
||||
if ($order_prescription['prescription_status'] == 4) {
|
||||
return fail(HttpEnumCode::HTTP_ERROR, "处方已使用");
|
||||
}
|
||||
|
||||
if ($order_prescription['pharmacist_audit_status'] != 1){
|
||||
return fail(HttpEnumCode::HTTP_ERROR,"处方未审核");
|
||||
if ($order_prescription['pharmacist_audit_status'] != 1) {
|
||||
return fail(HttpEnumCode::HTTP_ERROR, "处方未审核");
|
||||
}
|
||||
|
||||
// 检测是否已经存在药品订单数据
|
||||
@ -748,16 +751,8 @@ class PatientOrderService extends BaseService
|
||||
$params['order_prescription_id'] = $order_prescription['order_prescription_id'];
|
||||
$params['patient_id'] = $user_info['client_user_id'];
|
||||
$order_product = OrderProduct::getExists($params);
|
||||
if ($order_product){
|
||||
return fail(HttpEnumCode::HTTP_ERROR,"处方已使用");
|
||||
}
|
||||
|
||||
// 获取处方药品数据
|
||||
$params = array();
|
||||
$params['order_prescription_id'] = $order_prescription['order_prescription_id'];
|
||||
$order_prescription_product = OrderPrescriptionProduct::getList($params);
|
||||
if (empty($order_prescription_product)){
|
||||
return fail(HttpEnumCode::HTTP_ERROR,"处方药品错误");
|
||||
if ($order_product) {
|
||||
return fail(HttpEnumCode::HTTP_ERROR, "处方已使用");
|
||||
}
|
||||
|
||||
// 检测收货地址
|
||||
@ -765,40 +760,61 @@ class PatientOrderService extends BaseService
|
||||
$params['user_id'] = $user_info['user_id'];
|
||||
$params['address_id'] = $address_id;
|
||||
$user_ship_address = UserShipAddress::getOne($params);
|
||||
if (empty($user_ship_address)){
|
||||
return fail(HttpEnumCode::HTTP_ERROR,"收货地址错误");
|
||||
if (empty($user_ship_address)) {
|
||||
return fail(HttpEnumCode::HTTP_ERROR, "收货地址错误");
|
||||
}
|
||||
|
||||
$not_enough_product_ids = [];
|
||||
$amount_total = 0;
|
||||
$logistics_fee = 0; // 运费金额
|
||||
|
||||
// 检测药品是否存在,库存是否足够,获取订单金额
|
||||
foreach ($order_prescription_product as $value){
|
||||
foreach ($product_ids as $value) {
|
||||
// 检测药品是否存在于处方中
|
||||
$params = array();
|
||||
$params['product_id'] = $value['product_id'];
|
||||
$params['order_prescription_id'] = $order_prescription['order_prescription_id'];
|
||||
$params['product_id'] = $value;
|
||||
$order_prescription_product = OrderPrescriptionProduct::getOne($params);
|
||||
if (empty($order_prescription_product)) {
|
||||
return fail(HttpEnumCode::HTTP_ERROR, "创建订单失败");
|
||||
}
|
||||
|
||||
|
||||
$params = array();
|
||||
$params['product_id'] = $value;
|
||||
$product = Product::getWithAmountOne($params);
|
||||
if (empty($product)) {
|
||||
Db::rollBack();
|
||||
return fail(HttpEnumCode::HTTP_ERROR, "处方存在未知药品");
|
||||
}
|
||||
|
||||
// 检测商品库存
|
||||
if (!empty($product['ProductPlatformAmount'])) {
|
||||
if ($value['prescription_product_num'] > $product['ProductPlatformAmount']['real_stock']) {
|
||||
// 此处是否需要特殊返回
|
||||
Db::rollBack();
|
||||
return fail(HttpEnumCode::HTTP_ERROR, "意向药品库存不足");
|
||||
if ($order_prescription_product['prescription_product_num'] > $product['ProductPlatformAmount']['stock']) {
|
||||
// 库存不足
|
||||
$not_enough_product_ids[] = $value;
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
$amount_total += $product['product_price'];
|
||||
// 获取订单金额
|
||||
$amount_total += $product['product_price'] * $order_prescription_product['prescription_product_num'];
|
||||
}
|
||||
|
||||
if (!empty($not_enough_product_ids)) {
|
||||
return fail(HttpEnumCode::HTTP_ERROR, "存在库存不足商品", $not_enough_product_ids);
|
||||
}
|
||||
|
||||
// 获取运费金额
|
||||
$logistics_fee = 0;
|
||||
|
||||
// 实际支付金额
|
||||
$payment_amount_total = $amount_total + $logistics_fee;
|
||||
|
||||
// 确定支付渠道
|
||||
// 支付渠道(1:小程序支付 2:微信扫码支付)
|
||||
if ($client_type == 1) {
|
||||
$pay_channel = 1;
|
||||
} elseif ($client_type == 2) {
|
||||
$pay_channel = 2;
|
||||
}
|
||||
|
||||
Db::beginTransaction();
|
||||
|
||||
$generator = $this->container->get(IdGeneratorInterface::class);
|
||||
@ -813,6 +829,7 @@ class PatientOrderService extends BaseService
|
||||
$data['family_id'] = $order_prescription['family_id'];
|
||||
$data['order_product_no'] = $generator->generate();
|
||||
$data['order_product_status'] = 1; // 订单状态(1:待支付 2:待发货 3:已发货 4:已签收 5:已取消)
|
||||
$data['pay_channel'] = $pay_channel; // 支付渠道(1:小程序支付 2:微信扫码支付)
|
||||
$data['amount_total'] = $amount_total; // 订单金额
|
||||
$data['payment_amount_total'] = $payment_amount_total; // 实际付款金额
|
||||
$data['logistics_fee'] = $logistics_fee; // 运费金额
|
||||
@ -829,68 +846,99 @@ class PatientOrderService extends BaseService
|
||||
$data['consignee_tel'] = $user_ship_address['consignee_tel'];
|
||||
$data['consignee_tel_mask'] = $user_ship_address['consignee_tel_mask'];
|
||||
$order_product = OrderProduct::addOrderProduct($data);
|
||||
if (empty($order_product)){
|
||||
if (empty($order_product)) {
|
||||
Db::rollBack();
|
||||
return fail(HttpEnumCode::SERVER_ERROR);
|
||||
}
|
||||
|
||||
// 新增药品订单详情
|
||||
foreach ($order_prescription_product as $item){
|
||||
foreach ($product_ids as $product_id) {
|
||||
$params = array();
|
||||
$params['product_id'] = $item['product_id'];
|
||||
$product = Product::getOne($params);
|
||||
if (empty($product)){
|
||||
$params['order_prescription_id'] = $order_prescription['order_prescription_id'];
|
||||
$params['product_id'] = $product_id;
|
||||
$order_prescription_product = OrderPrescriptionProduct::getOne($params);
|
||||
if (empty($order_prescription_product)) {
|
||||
Db::rollBack();
|
||||
return fail(HttpEnumCode::HTTP_ERROR,"处方存在未知药品");
|
||||
return fail(HttpEnumCode::HTTP_ERROR, "创建订单失败");
|
||||
}
|
||||
|
||||
$params = array();
|
||||
$params['product_id'] = $product_id;
|
||||
$product = Product::getWithAmountOne($params);
|
||||
if (empty($product)) {
|
||||
Db::rollBack();
|
||||
return fail(HttpEnumCode::HTTP_ERROR, "处方存在未知药品");
|
||||
}
|
||||
|
||||
$data = array();
|
||||
$data['order_product_id'] = $order_product['order_product_id'];
|
||||
$data['order_inquiry_id'] = $order_prescription['order_inquiry_id'];
|
||||
$data['order_prescription_id'] = $order_prescription['orderorder_prescription_id_inquiry_id'];
|
||||
$data['product_id'] = $item['product_id'];
|
||||
$data['product_name'] = $item['product_name'];
|
||||
$data['product_price'] = $product['product_price'];
|
||||
$data['order_prescription_id'] = $order_prescription['order_prescription_id'];
|
||||
$data['product_id'] = $product_id;
|
||||
$data['product_name'] = $order_prescription_product['product_name'];
|
||||
$data['product_price'] = $product['product_price'] * $order_prescription_product['prescription_product_num'];
|
||||
$data['product_platform_code'] = $product['product_platform_code'];
|
||||
$data['amount'] = $item['prescription_product_num'];
|
||||
$data['manufacturer'] = $item['manufacturer'];
|
||||
$data['amount'] = $order_prescription_product['prescription_product_num'];
|
||||
$data['manufacturer'] = $order_prescription_product['manufacturer'];
|
||||
$data['product_cover_img'] = $product['product_cover_img'];
|
||||
$data['product_spec'] = $item['product_spec'];
|
||||
$data['product_spec'] = $order_prescription_product['product_spec'];
|
||||
$order_product_item = OrderProductItem::addOrderProductItem($data);
|
||||
if (!empty($order_product_item)){
|
||||
if (empty($order_product_item)) {
|
||||
Db::rollBack();
|
||||
return fail(HttpEnumCode::SERVER_ERROR);
|
||||
}
|
||||
|
||||
// 处方药品表标记为已使用
|
||||
$data = array();
|
||||
$data['use_status'] = 1;
|
||||
|
||||
$params = array();
|
||||
$params['prescription_product_id'] = $order_prescription_product['prescription_product_id'];
|
||||
OrderPrescriptionProduct::edit($params, $data);
|
||||
|
||||
// 锁定库存
|
||||
// 库存-1
|
||||
$params = array();
|
||||
$params['amount_id'] = $product['ProductPlatformAmount']['amount_id'];
|
||||
ProductPlatformAmount::dec($params, 'stock', $order_prescription_product['prescription_product_num']);
|
||||
|
||||
// 锁定库存+1
|
||||
ProductPlatformAmount::inc($params, 'lock_stock', $order_prescription_product['prescription_product_num']);
|
||||
}
|
||||
|
||||
// 修正处方使用状态
|
||||
// 修改处方为已使用
|
||||
$data = array();
|
||||
$data['prescription_status'] = 4;
|
||||
|
||||
$params = array();
|
||||
$params['order_prescription_id'] = $order_prescription['order_prescription_id'];
|
||||
OrderPrescription::edit($params,$data);
|
||||
OrderPrescription::edit($params, $data);
|
||||
|
||||
// 增加至取消订单延迟队列
|
||||
$data = array();
|
||||
$data['order_no'] = $order_product['order_product_no'];
|
||||
$data['order_no'] = (string)$order_product['order_product_no'];
|
||||
$data['order_type'] = 2;
|
||||
|
||||
$message = new CancelUnpayOrdersDelayDirectProducer($data);
|
||||
$message->setDelayMs(1000 * 60 * 30);
|
||||
$message->setDelayMs(1000 * 30 * 1);
|
||||
$producer = $this->container->get(Producer::class);
|
||||
$res = $producer->produce($message);
|
||||
if (!$res) {
|
||||
Db::rollBack();
|
||||
return fail(HttpEnumCode::SERVER_ERROR, "订单创建失败");
|
||||
}
|
||||
|
||||
Db::commit();
|
||||
} catch (\Exception $e) {
|
||||
Db::rollBack();
|
||||
return fail(HttpEnumCode::SERVER_ERROR, $e->getMessage());
|
||||
}
|
||||
|
||||
return success();
|
||||
$result = array();
|
||||
$result['inquiry_no'] = $order_product['order_product_no']; // 订单编号
|
||||
$result['order_product_id'] = $order_product['order_product_id']; // 订单主键id
|
||||
|
||||
return success($result);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -900,8 +948,8 @@ class PatientOrderService extends BaseService
|
||||
public function getPatientPrescriptionOrderList(): array
|
||||
{
|
||||
$user_info = $this->request->getAttribute("userInfo") ?? [];
|
||||
$page = $this->request->input('page',1);
|
||||
$per_page = $this->request->input('per_page',10);
|
||||
$page = $this->request->input('page', 1);
|
||||
$per_page = $this->request->input('per_page', 10);
|
||||
|
||||
// 获取处方数据
|
||||
$params = array();
|
||||
@ -909,10 +957,10 @@ class PatientOrderService extends BaseService
|
||||
$params['pharmacist_audit_status'] = 1;
|
||||
$params['platform_audit_status'] = 1;
|
||||
$params['is_delete'] = 0;
|
||||
$order_prescription = OrderPrescription::getWithPage($params,['*'],$page,$per_page);
|
||||
if (!empty($order_prescription['data'])){
|
||||
foreach ($order_prescription['data'] as &$item){
|
||||
if (!empty($item['UserDoctor'])){
|
||||
$order_prescription = OrderPrescription::getWithPage($params, ['*'], $page, $per_page);
|
||||
if (!empty($order_prescription['data'])) {
|
||||
foreach ($order_prescription['data'] as &$item) {
|
||||
if (!empty($item['UserDoctor'])) {
|
||||
$item['UserDoctor']['doctor_title'] = DoctorTitleCode::getMessage($item['UserDoctor']['doctor_title']);
|
||||
}
|
||||
}
|
||||
@ -943,8 +991,8 @@ class PatientOrderService extends BaseService
|
||||
$params['pharmacist_audit_status'] = 1;
|
||||
$params['platform_audit_status'] = 1;
|
||||
$params['is_delete'] = 0;
|
||||
$order_prescription = OrderPrescription::getOne($params,$fields);
|
||||
if (empty($order_prescription)){
|
||||
$order_prescription = OrderPrescription::getOne($params, $fields);
|
||||
if (empty($order_prescription)) {
|
||||
return fail();
|
||||
}
|
||||
|
||||
@ -971,36 +1019,36 @@ class PatientOrderService extends BaseService
|
||||
$params['order_prescription_id'] = $order_prescription_id;
|
||||
$params['patient_id'] = $user_info['client_user_id'];
|
||||
$params['is_delete'] = 0;
|
||||
$order_prescription = OrderPrescription::getOne($params,$fields);
|
||||
if (empty($order_prescription)){
|
||||
$order_prescription = OrderPrescription::getOne($params, $fields);
|
||||
if (empty($order_prescription)) {
|
||||
return fail();
|
||||
}
|
||||
|
||||
// 验证处方状态
|
||||
if ($order_prescription['prescription_status'] == 1){
|
||||
return fail(HttpEnumCode::HTTP_ERROR,"处方未审核");
|
||||
if ($order_prescription['prescription_status'] == 1) {
|
||||
return fail(HttpEnumCode::HTTP_ERROR, "处方未审核");
|
||||
}
|
||||
|
||||
if ($order_prescription['prescription_status'] == 3){
|
||||
return fail(HttpEnumCode::HTTP_ERROR,"处方已失效");
|
||||
if ($order_prescription['prescription_status'] == 3) {
|
||||
return fail(HttpEnumCode::HTTP_ERROR, "处方已失效");
|
||||
}
|
||||
|
||||
if ($order_prescription['prescription_status'] == 4){
|
||||
return fail(HttpEnumCode::HTTP_ERROR,"处方已使用");
|
||||
if ($order_prescription['prescription_status'] == 4) {
|
||||
return fail(HttpEnumCode::HTTP_ERROR, "处方已使用");
|
||||
}
|
||||
|
||||
// 获取处方药品信息
|
||||
$params = array();
|
||||
$params['order_prescription_id'] = $order_prescription['order_prescription_id'];
|
||||
$order_prescription_product = OrderPrescriptionProduct::getList($params);
|
||||
if (empty($order_prescription_product)){
|
||||
if (empty($order_prescription_product)) {
|
||||
return fail(HttpEnumCode::SERVER_ERROR);
|
||||
}
|
||||
|
||||
$amount_total = 0;
|
||||
$coupon_amount_total = 0;
|
||||
$logistics_fee = 0; // 运费金额
|
||||
foreach ($order_prescription_product as $item){
|
||||
foreach ($order_prescription_product as &$item) {
|
||||
$params = array();
|
||||
$params['product_id'] = $item['product_id'];
|
||||
$product = Product::getWithAmountOne($params);
|
||||
@ -1008,15 +1056,18 @@ class PatientOrderService extends BaseService
|
||||
return fail(HttpEnumCode::HTTP_ERROR, "处方存在未知药品");
|
||||
}
|
||||
|
||||
$item['status'] = 1; // 正常
|
||||
|
||||
// 检测商品库存
|
||||
if (!empty($product['ProductPlatformAmount'])) {
|
||||
if ($item['prescription_product_num'] > $product['ProductPlatformAmount']['real_stock']) {
|
||||
if ($item['prescription_product_num'] > $product['ProductPlatformAmount']['stock']) {
|
||||
// 库存不足
|
||||
$item['status'] = 2;
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
$amount_total += $product['product_price'];
|
||||
$amount_total += $product['product_price'] * $item['prescription_product_num'];
|
||||
}
|
||||
|
||||
// 获取运费金额
|
||||
@ -1029,14 +1080,15 @@ class PatientOrderService extends BaseService
|
||||
$params['user_id'] = $user_info['user_id'];
|
||||
$user_ship_addresss = UserShipAddress::getList($params);
|
||||
|
||||
foreach ($user_ship_addresss as $item){
|
||||
if ($item['is_default'] == 1){
|
||||
unset($item);
|
||||
foreach ($user_ship_addresss as $item) {
|
||||
if ($item['is_default'] == 1) {
|
||||
$user_ship_address = $item;
|
||||
}
|
||||
}
|
||||
|
||||
// 无默认地址,选择第一个
|
||||
if (empty($user_ship_address)){
|
||||
if (empty($user_ship_address)) {
|
||||
$user_ship_address = $user_ship_addresss[0] ?? [];
|
||||
}
|
||||
|
||||
@ -1046,6 +1098,7 @@ class PatientOrderService extends BaseService
|
||||
$result['payment_amount_total'] = $payment_amount_total;
|
||||
$result['logistics_fee'] = $logistics_fee;
|
||||
$result['user_ship_address'] = $user_ship_address;
|
||||
$result['order_prescription_product'] = $order_prescription_product;
|
||||
|
||||
return success($result);
|
||||
}
|
||||
@ -1064,16 +1117,16 @@ class PatientOrderService extends BaseService
|
||||
$params['order_prescription_id'] = $order_prescription_id;
|
||||
$params['patient_id'] = $user_info['client_user_id'];
|
||||
$order_prescription = OrderPrescription::getOne($params);
|
||||
if (empty($order_prescription)){
|
||||
if (empty($order_prescription)) {
|
||||
return fail();
|
||||
}
|
||||
|
||||
// 验证处方状态
|
||||
if ($order_prescription['prescription_status'] == 1){
|
||||
return fail(HttpEnumCode::HTTP_ERROR,"处方无法删除");
|
||||
if ($order_prescription['prescription_status'] == 1) {
|
||||
return fail(HttpEnumCode::HTTP_ERROR, "处方无法删除");
|
||||
}
|
||||
|
||||
if ($order_prescription['is_delete'] == 1){
|
||||
if ($order_prescription['is_delete'] == 1) {
|
||||
return success();
|
||||
}
|
||||
|
||||
@ -1082,7 +1135,7 @@ class PatientOrderService extends BaseService
|
||||
|
||||
$params = array();
|
||||
$params['order_prescription_id'] = $order_prescription['order_prescription_id'];
|
||||
OrderPrescription::edit($params,$data);
|
||||
OrderPrescription::edit($params, $data);
|
||||
|
||||
return success();
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user