| xqd
@@ -18,6 +18,7 @@ use App\Models\Patient;
|
|
|
use App\Models\Payment;
|
|
|
use App\Models\ServicePack;
|
|
|
use App\Models\TimePeriod;
|
|
|
+use App\Models\User;
|
|
|
use App\Models\UserCoupon;
|
|
|
use App\Models\Vaccine;
|
|
|
use EasyWeChat\Factory;
|
| xqd
@@ -29,6 +30,7 @@ class OrderController extends AuthController
|
|
|
{
|
|
|
$req = request()->post();
|
|
|
$this->validate(request(), [
|
|
|
+ 'payment_type' => 'required|in:1,2',
|
|
|
'product_type' => 'required|in:1,2',
|
|
|
'docter_id' => 'required|integer',
|
|
|
'patient_id' => 'required|integer',
|
| xqd
@@ -49,9 +51,15 @@ class OrderController extends AuthController
|
|
|
$payment_amount = $req['total_amount'] - $discount_amount;
|
|
|
$payment_amount = $payment_amount < 0 ? 0 : $payment_amount;
|
|
|
|
|
|
+ if ($req['payment_type'] == 2) {
|
|
|
+ if ($user['balance'] < $payment_amount) {
|
|
|
+ return out(null, 601, '余额不足');
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
$order_status = $payment_status = 1;
|
|
|
$payment_time = 0;
|
|
|
- if ($payment_amount == 0) {
|
|
|
+ if ($payment_amount == 0 || $req['payment_type'] == 2) {
|
|
|
$order_status = $payment_status = 2;
|
|
|
$payment_time = time();
|
|
|
}
|
| xqd
@@ -62,6 +70,7 @@ class OrderController extends AuthController
|
|
|
//保存订单数据
|
|
|
$order = Order::create([
|
|
|
'user_id' => $user['id'],
|
|
|
+ 'payment_type' => $req['payment_type'],
|
|
|
'product_type' => $req['product_type'],
|
|
|
'docter_id' => $req['docter_id'],
|
|
|
'total_amount' => $req['total_amount'],
|
| xqd
@@ -87,33 +96,45 @@ class OrderController extends AuthController
|
|
|
$addPatient['medical_imgs'] = $req['medical_imgs'];
|
|
|
}
|
|
|
OrderPatient::create($addPatient);
|
|
|
- //生成支付交易单
|
|
|
- if ($payment_amount > 0) {
|
|
|
- $trade_sn = build_sn($order['id'], 3, 'T');
|
|
|
- $payBody = '超级宝妈-'.config('config.product_type_map')[$req['product_type']];
|
|
|
- Payment::create([
|
|
|
- 'user_id' => $user['id'],
|
|
|
- 'order_id' => $order['id'],
|
|
|
- 'trade_sn' => $trade_sn,
|
|
|
- 'amount' => $payment_amount,
|
|
|
- 'remark' => $payBody,
|
|
|
- ]);
|
|
|
- //请求支付
|
|
|
- $payment = Factory::payment(config('config.wechat_pay'));
|
|
|
- $result = $payment->order->unify([
|
|
|
- 'body' => $payBody,
|
|
|
- 'out_trade_no' => $trade_sn,
|
|
|
- 'total_fee' => $payment_amount,
|
|
|
- 'trade_type' => 'JSAPI',
|
|
|
- 'openid' => $user['openid'],
|
|
|
- ]);
|
|
|
-
|
|
|
- if (empty($result['prepay_id'])) {
|
|
|
- $errorMsg = !empty($result['err_code_des']) ? $result['err_code_des'] : $result['return_msg'];
|
|
|
- return out(null, 702, $errorMsg);
|
|
|
- }
|
|
|
|
|
|
- $config = $payment->jssdk->bridgeConfig($result['prepay_id'], false);
|
|
|
+ //判断是微信支付
|
|
|
+ if ($req['payment_type'] == 1) {
|
|
|
+ //生成支付交易单
|
|
|
+ if ($payment_amount > 0) {
|
|
|
+ $trade_sn = build_sn($order['id'], 3, 'T');
|
|
|
+ $payBody = '超级宝妈-'.config('config.product_type_map')[$req['product_type']];
|
|
|
+ Payment::create([
|
|
|
+ 'user_id' => $user['id'],
|
|
|
+ 'order_id' => $order['id'],
|
|
|
+ 'trade_sn' => $trade_sn,
|
|
|
+ 'amount' => $payment_amount,
|
|
|
+ 'remark' => $payBody,
|
|
|
+ ]);
|
|
|
+ //请求支付
|
|
|
+ $payment = Factory::payment(config('config.wechat_pay'));
|
|
|
+ $result = $payment->order->unify([
|
|
|
+ 'body' => $payBody,
|
|
|
+ 'out_trade_no' => $trade_sn,
|
|
|
+ 'total_fee' => $payment_amount,
|
|
|
+ 'trade_type' => 'JSAPI',
|
|
|
+ 'openid' => $user['openid'],
|
|
|
+ ]);
|
|
|
+
|
|
|
+ if (empty($result['prepay_id'])) {
|
|
|
+ $errorMsg = !empty($result['err_code_des']) ? $result['err_code_des'] : $result['return_msg'];
|
|
|
+ return out(null, 702, $errorMsg);
|
|
|
+ }
|
|
|
+
|
|
|
+ $config = $payment->jssdk->bridgeConfig($result['prepay_id'], false);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ //判断是余额支付
|
|
|
+ elseif ($req['payment_type'] == 2) {
|
|
|
+ if ($payment_amount > 0) {
|
|
|
+ //改变用户余额
|
|
|
+ $change_amount = 0 - $payment_amount;
|
|
|
+ User::changeBalance($user['id'], $change_amount, 1, $order['id'], '咨询订单消费');
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
DB::commit();
|
| xqd
@@ -129,6 +150,7 @@ class OrderController extends AuthController
|
|
|
{
|
|
|
$req = request()->post();
|
|
|
$this->validate(request(), [
|
|
|
+ 'payment_type' => 'required|in:1,2',
|
|
|
'product_type' => 'required|in:3,4,5',
|
|
|
'patient_id' => 'required|integer',
|
|
|
'organization_id' => 'required|integer',
|
| xqd
@@ -161,9 +183,15 @@ class OrderController extends AuthController
|
|
|
$payment_amount = $req['total_amount'] - $discount_amount;
|
|
|
$payment_amount = $payment_amount < 0 ? 0 : $payment_amount;
|
|
|
|
|
|
+ if ($req['payment_type'] == 2) {
|
|
|
+ if ($user['balance'] < $payment_amount) {
|
|
|
+ return out(null, 601, '余额不足');
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
$order_status = $payment_status = 1;
|
|
|
$payment_time = 0;
|
|
|
- if ($payment_amount == 0) {
|
|
|
+ if ($payment_amount == 0 || $req['payment_type'] == 2) {
|
|
|
$order_status = $payment_status = 2;
|
|
|
$payment_time = time();
|
|
|
}
|
| xqd
@@ -177,6 +205,7 @@ class OrderController extends AuthController
|
|
|
'docter_id' => $req['docter_id'] ?? 0,
|
|
|
'patient_id' => $req['patient_id'],
|
|
|
'organization_id' => $req['organization_id'],
|
|
|
+ 'payment_type' => $req['payment_type'],
|
|
|
'product_type' => $product_type,
|
|
|
'order_status' => $order_status,
|
|
|
'payment_status' => $payment_status,
|
| xqd
@@ -214,33 +243,45 @@ class OrderController extends AuthController
|
|
|
OrderNurse::create($addNurse);
|
|
|
}
|
|
|
}
|
|
|
- //生成支付交易单
|
|
|
- if ($payment_amount > 0) {
|
|
|
- $trade_sn = build_sn($order['id'], 3, 'T');
|
|
|
- $payBody = '超级宝妈-'.config('config.product_type_map')[$product_type];
|
|
|
- Payment::create([
|
|
|
- 'user_id' => $user['id'],
|
|
|
- 'order_id' => $order['id'],
|
|
|
- 'trade_sn' => $trade_sn,
|
|
|
- 'amount' => $payment_amount,
|
|
|
- 'remark' => $payBody,
|
|
|
- ]);
|
|
|
- //请求支付
|
|
|
- $payment = Factory::payment(config('config.wechat_pay'));
|
|
|
- $result = $payment->order->unify([
|
|
|
- 'body' => $payBody,
|
|
|
- 'out_trade_no' => $trade_sn,
|
|
|
- 'total_fee' => $payment_amount,
|
|
|
- 'trade_type' => 'JSAPI',
|
|
|
- 'openid' => $user['openid'],
|
|
|
- ]);
|
|
|
-
|
|
|
- if (empty($result['prepay_id'])) {
|
|
|
- $errorMsg = !empty($result['err_code_des']) ? $result['err_code_des'] : $result['return_msg'];
|
|
|
- return out(null, 702, $errorMsg);
|
|
|
- }
|
|
|
|
|
|
- $config = $payment->jssdk->bridgeConfig($result['prepay_id'], false);
|
|
|
+ //判断是微信支付
|
|
|
+ if ($req['payment_type'] == 1) {
|
|
|
+ //生成支付交易单
|
|
|
+ if ($payment_amount > 0) {
|
|
|
+ $trade_sn = build_sn($order['id'], 3, 'T');
|
|
|
+ $payBody = '超级宝妈-'.config('config.product_type_map')[$product_type];
|
|
|
+ Payment::create([
|
|
|
+ 'user_id' => $user['id'],
|
|
|
+ 'order_id' => $order['id'],
|
|
|
+ 'trade_sn' => $trade_sn,
|
|
|
+ 'amount' => $payment_amount,
|
|
|
+ 'remark' => $payBody,
|
|
|
+ ]);
|
|
|
+ //请求支付
|
|
|
+ $payment = Factory::payment(config('config.wechat_pay'));
|
|
|
+ $result = $payment->order->unify([
|
|
|
+ 'body' => $payBody,
|
|
|
+ 'out_trade_no' => $trade_sn,
|
|
|
+ 'total_fee' => $payment_amount,
|
|
|
+ 'trade_type' => 'JSAPI',
|
|
|
+ 'openid' => $user['openid'],
|
|
|
+ ]);
|
|
|
+
|
|
|
+ if (empty($result['prepay_id'])) {
|
|
|
+ $errorMsg = !empty($result['err_code_des']) ? $result['err_code_des'] : $result['return_msg'];
|
|
|
+ return out(null, 702, $errorMsg);
|
|
|
+ }
|
|
|
+
|
|
|
+ $config = $payment->jssdk->bridgeConfig($result['prepay_id'], false);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ //判断是余额支付
|
|
|
+ elseif ($req['payment_type'] == 2) {
|
|
|
+ if ($payment_amount > 0) {
|
|
|
+ //改变用户余额
|
|
|
+ $change_amount = 0 - $payment_amount;
|
|
|
+ User::changeBalance($user['id'], $change_amount, 1, $order['id'], '预约订单消费');
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
DB::commit();
|
| xqd
@@ -256,6 +297,7 @@ class OrderController extends AuthController
|
|
|
{
|
|
|
$req = request()->post();
|
|
|
$this->validate(request(), [
|
|
|
+ 'payment_type' => 'required|in:1,2',
|
|
|
'patient_id' => 'required|integer',
|
|
|
'total_amount' => 'required|integer',
|
|
|
'user_coupon_id' => 'integer',
|
| xqd
@@ -274,9 +316,15 @@ class OrderController extends AuthController
|
|
|
$payment_amount = $req['total_amount'] - $discount_amount;
|
|
|
$payment_amount = $payment_amount < 0 ? 0 : $payment_amount;
|
|
|
|
|
|
+ if ($req['payment_type'] == 2) {
|
|
|
+ if ($user['balance'] < $payment_amount) {
|
|
|
+ return out(null, 601, '余额不足');
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
$order_status = $payment_status = 1;
|
|
|
$payment_time = 0;
|
|
|
- if ($payment_amount == 0) {
|
|
|
+ if ($payment_amount == 0 || $req['payment_type'] == 2) {
|
|
|
$order_status = $payment_status = 2;
|
|
|
$payment_time = time();
|
|
|
}
|
| xqd
@@ -288,6 +336,7 @@ class OrderController extends AuthController
|
|
|
$order = Order::create([
|
|
|
'user_id' => $user['id'],
|
|
|
'patient_id' => $req['patient_id'],
|
|
|
+ 'payment_type' => $req['payment_type'],
|
|
|
'product_type' => 6,
|
|
|
'docter_id' => $req['docter_id'],
|
|
|
'total_amount' => $req['total_amount'],
|
| xqd
@@ -313,33 +362,45 @@ class OrderController extends AuthController
|
|
|
$addPack['start_time'] = time();
|
|
|
$addPack['end_time'] = time() + $addPack['effective_days']*24*3600;
|
|
|
OrderPack::create($addPack);
|
|
|
- //生成支付交易单
|
|
|
- if ($payment_amount > 0) {
|
|
|
- $trade_sn = build_sn($order['id'], 3, 'T');
|
|
|
- $payBody = '超级宝妈-'.config('config.product_type_map')[6];
|
|
|
- Payment::create([
|
|
|
- 'user_id' => $user['id'],
|
|
|
- 'order_id' => $order['id'],
|
|
|
- 'trade_sn' => $trade_sn,
|
|
|
- 'amount' => $payment_amount,
|
|
|
- 'remark' => $payBody,
|
|
|
- ]);
|
|
|
- //请求支付
|
|
|
- $payment = Factory::payment(config('config.wechat_pay'));
|
|
|
- $result = $payment->order->unify([
|
|
|
- 'body' => $payBody,
|
|
|
- 'out_trade_no' => $trade_sn,
|
|
|
- 'total_fee' => $payment_amount,
|
|
|
- 'trade_type' => 'JSAPI',
|
|
|
- 'openid' => $user['openid'],
|
|
|
- ]);
|
|
|
-
|
|
|
- if (empty($result['prepay_id'])) {
|
|
|
- $errorMsg = !empty($result['err_code_des']) ? $result['err_code_des'] : $result['return_msg'];
|
|
|
- return out(null, 702, $errorMsg);
|
|
|
- }
|
|
|
|
|
|
- $config = $payment->jssdk->bridgeConfig($result['prepay_id'], false);
|
|
|
+ //判断是微信支付
|
|
|
+ if ($req['payment_type'] == 1) {
|
|
|
+ //生成支付交易单
|
|
|
+ if ($payment_amount > 0) {
|
|
|
+ $trade_sn = build_sn($order['id'], 3, 'T');
|
|
|
+ $payBody = '超级宝妈-'.config('config.product_type_map')[6];
|
|
|
+ Payment::create([
|
|
|
+ 'user_id' => $user['id'],
|
|
|
+ 'order_id' => $order['id'],
|
|
|
+ 'trade_sn' => $trade_sn,
|
|
|
+ 'amount' => $payment_amount,
|
|
|
+ 'remark' => $payBody,
|
|
|
+ ]);
|
|
|
+ //请求支付
|
|
|
+ $payment = Factory::payment(config('config.wechat_pay'));
|
|
|
+ $result = $payment->order->unify([
|
|
|
+ 'body' => $payBody,
|
|
|
+ 'out_trade_no' => $trade_sn,
|
|
|
+ 'total_fee' => $payment_amount,
|
|
|
+ 'trade_type' => 'JSAPI',
|
|
|
+ 'openid' => $user['openid'],
|
|
|
+ ]);
|
|
|
+
|
|
|
+ if (empty($result['prepay_id'])) {
|
|
|
+ $errorMsg = !empty($result['err_code_des']) ? $result['err_code_des'] : $result['return_msg'];
|
|
|
+ return out(null, 702, $errorMsg);
|
|
|
+ }
|
|
|
+
|
|
|
+ $config = $payment->jssdk->bridgeConfig($result['prepay_id'], false);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ //判断是余额支付
|
|
|
+ elseif ($req['payment_type'] == 2) {
|
|
|
+ if ($payment_amount > 0) {
|
|
|
+ //改变用户余额
|
|
|
+ $change_amount = 0 - $payment_amount;
|
|
|
+ User::changeBalance($user['id'], $change_amount, 1, $order['id'], '购买服务包');
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
DB::commit();
|