Browse Source

修改支付方式常量

dev
李可松 4 years ago
parent
commit
7159786d4c
  1. 6
      app/Common/PayType.php
  2. 21
      app/Http/Controllers/Api/OrderController.php
  3. 3
      app/Http/Controllers/Api/WxpayController.php

6
app/Common/PayType.php

@ -9,11 +9,11 @@ namespace App\Common;
*/ */
class PayType class PayType
{ {
const ONLINE = 0; //在线支付
const ONLINE = 0; //在线全款支付
const OFFLINE = 1; //线下支付 const OFFLINE = 1; //线下支付
const SUBSCRIPTION = 2; //订金支付 const SUBSCRIPTION = 2; //订金支付
const DEPOSIT = 3; //定金支付 const DEPOSIT = 3; //定金支付
const FULL_PAY = 4; //全款支付
const DOWN_PAYMENT = 4; //尾款/多加支付
const BALANCE_PAY = 5; //尾款/多加支付 const BALANCE_PAY = 5; //尾款/多加支付
public static function array() public static function array()
@ -23,7 +23,7 @@ class PayType
self::OFFLINE => '线下支付', self::OFFLINE => '线下支付',
self::SUBSCRIPTION => '订金支付', self::SUBSCRIPTION => '订金支付',
self::DEPOSIT => '定金支付', self::DEPOSIT => '定金支付',
self::FULL_PAY => '全款支付',
self::DOWN_PAYMENT => '首款支付',
self::BALANCE_PAY => '尾款/多加支付', self::BALANCE_PAY => '尾款/多加支付',
]; ];
} }

21
app/Http/Controllers/Api/OrderController.php

@ -2,6 +2,7 @@
namespace App\Http\Controllers\Api; namespace App\Http\Controllers\Api;
use App\Common\PayType;
use App\Http\Controllers\Controller; use App\Http\Controllers\Controller;
use App\Models\Agent; use App\Models\Agent;
use App\Models\AgentProduct; use App\Models\AgentProduct;
@ -82,11 +83,12 @@ class OrderController extends Controller
$formData = array_map(fn($v) => trim($v), $formData); //过滤,删除首尾空 $formData = array_map(fn($v) => trim($v), $formData); //过滤,删除首尾空
//表单验证 //表单验证
$pay_type_values = join(',', array_keys(PayType::array()));
$request->validate([ $request->validate([
'id' => ['required', 'regex:/^\d+$/'], 'id' => ['required', 'regex:/^\d+$/'],
'name' => ['required', 'between:2,20'], 'name' => ['required', 'between:2,20'],
'mobile' => ['required', 'regex:/^1[3-9]\d{9}$/'], 'mobile' => ['required', 'regex:/^1[3-9]\d{9}$/'],
'pay_type' => ['required', 'in:0,1,2,3'],
'pay_type' => ['required', 'in:' . $pay_type_values],
'num' => ['required', 'min:1'], 'num' => ['required', 'min:1'],
], [ ], [
'id.required' => '未指定产品ID', 'id.required' => '未指定产品ID',
@ -145,8 +147,8 @@ class OrderController extends Controller
'picture' => $ap->product->picture, 'picture' => $ap->product->picture,
'agent_product_id' => $ap->id, 'agent_product_id' => $ap->id,
'product_id' => $ap->product_id, 'product_id' => $ap->product_id,
'product_ids' => $ap->product->product_ids,
'status' => $formData['pay_type'] == 3 ? Status::OFFLINE_UNPAID : Status::UNPAID,
'product_ids' => $ap->product->product_ids ?? $ap->product_id,
'status' => $formData['pay_type'] == PayType::OFFLINE ? Status::OFFLINE_UNPAID : Status::UNPAID,
'pay_type' => $formData['pay_type'], 'pay_type' => $formData['pay_type'],
'coupon_id' => join(',', $coupon_ids), 'coupon_id' => join(',', $coupon_ids),
]); ]);
@ -157,7 +159,7 @@ class OrderController extends Controller
return $this->error($e->getMessage()); return $this->error($e->getMessage());
} }
if ($formData['pay_type'] == 3) { //线下支付
if ($formData['pay_type'] == PayType::OFFLINE) { //线下支付
return $this->success('操作成功,请及时联系客服付款'); return $this->success('操作成功,请及时联系客服付款');
} else { //在线支付或定金支付 } else { //在线支付或定金支付
$config = $this->payConfig($order, $price); $config = $this->payConfig($order, $price);
@ -231,6 +233,11 @@ class OrderController extends Controller
return $this->error('产品信息不存在'); return $this->error('产品信息不存在');
} }
//如果是线下支付,显示的价格跟在线全款支付价格一样
if ($formData['pay_type'] == PayType::OFFLINE) {
$formData['pay_type'] = PayType::ONLINE;
}
$ap->final_price = $this->calc($ap->price, $ap->coupon, $formData['num'], $formData['pay_type']); $ap->final_price = $this->calc($ap->price, $ap->coupon, $formData['num'], $formData['pay_type']);
$ap->num = $formData['num']; $ap->num = $formData['num'];
return $this->success($ap); return $this->success($ap);
@ -341,12 +348,8 @@ class OrderController extends Controller
private function calc($price, $coupon, $num, $pay_type) private function calc($price, $coupon, $num, $pay_type)
{ {
//根据支付方式计算价格 //根据支付方式计算价格
switch ($pay_type) {
case 1:
case 2:
if (in_array($pay_type, [PayType::SUBSCRIPTION, PayType::DEPOSIT, PayType::DOWN_PAYMENT])) {
return $this->earnest; return $this->earnest;
case 3:
return 0;
} }
//TODO 还要计算尾款支付金额 //TODO 还要计算尾款支付金额

3
app/Http/Controllers/Api/WxpayController.php

@ -1,6 +1,7 @@
<?php <?php
namespace App\Http\Controllers\Api; namespace App\Http\Controllers\Api;
use App\Common\PayType;
use App\Models\Agent; use App\Models\Agent;
use App\Models\AgentProduct; use App\Models\AgentProduct;
use App\Models\Order; use App\Models\Order;
@ -62,7 +63,7 @@ class WxpayController
$pay_type = $order->pay_type; $pay_type = $order->pay_type;
$money = $message['total_fee'] / 100; $money = $message['total_fee'] / 100;
//定金支付和首付款支付 //定金支付和首付款支付
if (in_array($pay_type, [1, 2])) {
if (in_array($pay_type, [PayType::SUBSCRIPTION, PayType::DEPOSIT, PayType::DOWN_PAYMENT])) {
if ($status == OrderStatus::UNPAID) { if ($status == OrderStatus::UNPAID) {
$order->status = OrderStatus::PAY_EARNEST; $order->status = OrderStatus::PAY_EARNEST;
} else if ($status == OrderStatus::PAY_EARNEST) { } else if ($status == OrderStatus::PAY_EARNEST) {

Loading…
Cancel
Save