6
0
Fork 0

Merge branch 'develop' of gitee.com:zi-chunsheng-e-commerce/mall-server into 1.x

release
李静 2022-02-23 17:44:44 +08:00
commit 69a295645d
13 changed files with 107 additions and 96 deletions

View File

@ -106,8 +106,8 @@ class DealerOrderController extends AdminController
}
if ((
$actions->row->isPending() //待确认
|| $actions->row->isPay() //待付款
|| $actions->row->isPaid() //待收款
|| $actions->row->isPendinged() //待付款
|| $actions->row->isPay()//待收款
) && Admin::user()->can('dcat.admin.dealer_orders.cancel')) {
$actions->append(new DealerOrderCancel());
}

View File

@ -93,14 +93,13 @@ class OrderController extends AdminController
10=>'已取消',
])
);
$grid->column('pay_way')->using(OrderModel::$payWayText)->label([
'wxpay'=>'success',
'alipay'=>'primary',
'balance'=>'warning',
'wallet'=>'warning',
'offline'=>'danger',
'none'=>'#b3b9bf',
]);
$grid->column('pay_way')->display(function ($v) {
if ($v) {
return '<i class="fa fa-circle" style="font-size: 13px;color: '.$v->color().'"></i>&nbsp;&nbsp;'.$v->getMallOrderText();
}
return '';
});
$grid->column('pay_at');
// $grid->column('consignee_name');
// $grid->column('consignee_telephone');
@ -177,14 +176,27 @@ class OrderController extends AdminController
return bcdiv($v, 100, 2);
})->prepend('¥');
$show->field('created_at');
$show->field('pay_way')->using(OrderModel::$payWayText)->showLabel([
'微信支付'=>'success',
'支付宝'=>'primary',
'钱包'=>'warning',
'余额'=>'warning',
'线下支付'=>'danger',
'无'=>'#b3b9bf',
]);
$show->html(function () {
$content = '';
if ($this->pay_way) {
$content = '<i class="fa fa-circle" style="font-size: 13px;color: '.$this->pay_way->color().'"></i>&nbsp;&nbsp;'.$this->pay_way->getMallOrderText();
}
return <<<HTML
<div class="show-field form-group row">
<div class="col-sm-2 control-label">
<span>支付方式</span>
</div>
<div class="col-sm-8">
<div class="box box-solid box-default no-margin box-show">
<div class="box-body">{$content}&nbsp;</div>
</div>
</div>
</div>
HTML;
});
$show->field('pay_at');
$show->field('tags')->as(function () {
return $this->tags->pluck('name');

View File

@ -2,10 +2,10 @@
namespace App\Admin\Services;
use App\Enums\PayWay;
use App\Exceptions\BizException;
use App\Models\Order;
use App\Models\OrderLog;
use App\Models\PayLog;
use App\Services\OrderService as EndpointOrderService;
class OrderService
@ -43,7 +43,7 @@ class OrderService
if ($order->isPending()) {
//操作订单状态-需要调整为统一支付方法
$orderService = new EndpointOrderService();
$orderService->pay($order, PayLog::PAY_WAY_OFFLINE);
$orderService->pay($order, PayWay::Offline);
//记录操作日志
OrderLog::create([

View File

@ -43,7 +43,7 @@ class OrderRefundCommand extends Command
OrderRefundLog::pending()->chunkById(200, function ($logs) use (&$page) {
foreach ($logs as $log) {
try {
$method = 'refundBy'.Str::studly($log->order->pay_way);
$method = 'refundBy'.Str::studly($log->order->pay_way->value);
if (! method_exists($this, $method)) {
throw new BizException('退款方式暂不支持');
@ -79,7 +79,7 @@ class OrderRefundCommand extends Command
* @param \App\Models\OrderRefundLog $log
* @return void
*/
protected function refundByWxpay(OrderRefundLog $log)
protected function refundByWxpayApp(OrderRefundLog $log)
{
$order = $log->order;
@ -106,7 +106,7 @@ class OrderRefundCommand extends Command
* @param \App\Models\OrderRefundLog $log
* @return void
*/
protected function refundByAlipay(OrderRefundLog $log)
protected function refundByAlipayApp(OrderRefundLog $log)
{
$order = $log->order;

View File

@ -7,6 +7,7 @@ use App\Endpoint\Api\Http\Controllers\Controller;
use App\Endpoint\Api\Http\Resources\OrderPackageResource;
use App\Endpoint\Api\Http\Resources\OrderResource;
use App\Endpoint\Api\Http\Resources\OrderResourceCollection;
use App\Enums\PayWay;
use App\Events\OrderPaid;
use App\Exceptions\BizException;
use App\Helpers\Paginator as PaginatorHelper;
@ -185,12 +186,16 @@ class OrderController extends Controller
'pay_way' => ['bail', 'required'],
]);
if (is_null($payway = PayWay::tryFrom($input['pay_way']))) {
throw new BizException('支付方式 非法');
}
$user = $request->user();
return DB::transaction(function () use ($id, $user, $input) {
return DB::transaction(function () use ($id, $user, $payway) {
$order = $user->orders()->findOrFail($id);
return (new OrderService())->pay($order, $input['pay_way']);
return (new OrderService())->pay($order, $payway);
});
}

View File

@ -10,7 +10,7 @@ enum PayWay: string {
case WxpayApp = 'wxpay_app';
case WxpayH5 = 'wxpay_h5';
case WxpayJs = 'wxpay_jsapi';
case WxpayMp = 'wxpay_mp';
case WxpayMp = 'wxpay_mini_program';
// 阿里支付
case AlipayApp = 'alipay_app';
@ -18,8 +18,10 @@ enum PayWay: string {
{
return match ($this) {
static::Offline => '#5b69bc',
static::Balance => '#dda451',
static::Wallet => '#ff8acc',
static::WxpayApp, static::WxpayH5, static::WxpayJs, static::WxpayMp => '#21b978',
static::AlipayApp => '#3085d6',
default => '#ea5455',
};
}
@ -35,6 +37,18 @@ enum PayWay: string {
};
}
public function getMallOrderText()
{
return match ($this) {
static::Offline => '线下',
static::Balance => '余额',
static::Wallet => '可提',
static::WxpayApp, static::WxpayH5, static::WxpayJs, static::WxpayMp => '微信支付',
static::AlipayApp => '支付宝',
default => 'Unknown',
};
}
public function getDealerOrderText()
{
return match ($this) {

View File

@ -0,0 +1,25 @@
<?php
namespace App\Enums;
enum WxpayTradeType: string {
case App = 'APP';
case H5 = 'MWEB';
case JSAPI = 'JSAPI';
/**
* 通过支付方式获取交易类型
*
* @param \App\Enums\PayWay $payWay
* @return static|null
*/
public static function tryFromPayWay(PayWay $payWay): ?static
{
return match ($payWay) {
PayWay::WxpayApp => static::App,
PayWay::WxpayH5 => static::H5,
PayWay::WxpayJs, PayWay::WxpayMp => static::JSAPI,
default => null,
};
}
}

View File

@ -3,6 +3,7 @@
namespace App\Models;
use App\Constants\OrderStatus;
use App\Enums\PayWay;
use Dcat\Admin\Traits\HasDateTimeFormatter;
use EloquentFilter\Filterable;
use Illuminate\Database\Eloquent\Model;
@ -51,6 +52,7 @@ class Order extends Model
* @var array
*/
protected $casts = [
'pay_way' => PayWay::class,
'pay_at' => 'datetime',
'completed_at' => 'datetime',
'auto_complete_at' => 'datetime',
@ -93,14 +95,6 @@ class Order extends Model
'is_settlable',
];
public static $payWayText = [
self::PAY_WAY_WXPAY => '微信支付',
self::PAY_WAY_ALIPAY => '支付宝',
self::PAY_WAY_WALLET => '钱包',
self::PAY_WAY_BALANCE => '余额',
self::PAY_WAY_OFFLINE => '线下支付',
];
/**
* 仅查询支付过期的订单
*/

View File

@ -2,6 +2,7 @@
namespace App\Models;
use App\Enums\PayWay;
use Illuminate\Database\Eloquent\Model;
class PayLog extends Model
@ -13,15 +14,6 @@ class PayLog extends Model
public const STATUS_SUCCESS = 1; // 成功
public const STATUS_FAILED = 2; // 失败
public const PAY_WAY_WXPAY_APP = 'wxpay_app'; // 微信支付 - App 支付
public const PAY_WAY_WXPAY_JSAPI = 'wxpay_jsapi'; // 微信支付 - JSAPI 支付
public const PAY_WAY_WXPAY_MINI = 'wxpay_mini'; // 微信支付 - 小程序支付
public const PAY_WAY_WXPAY_H5 = 'wxpay_h5'; // 微信支付 - H5 支付
public const PAY_ALIPAY_APP = 'alipay_app'; // 支付宝 - app 支付
public const PAY_WAY_WALLET = 'wallet'; // 钱包付款(可提现)
public const PAY_WAY_BALANCE = 'balance'; // 余额支付
public const PAY_WAY_OFFLINE = 'offline'; // 线下支付
/**
* @var array
*/
@ -33,6 +25,7 @@ class PayLog extends Model
* @var array
*/
protected $casts = [
'pay_way' => PayWay::class,
'pay_at' => 'datetime',
];
@ -72,10 +65,10 @@ class PayLog extends Model
public function isWxpay(): bool
{
return in_array($this->pay_way, [
static::PAY_WAY_WXPAY_APP,
static::PAY_WAY_WXPAY_JSAPI,
static::PAY_WAY_WXPAY_MINI,
static::PAY_WAY_WXPAY_H5,
PayWay::WxpayApp,
PayWay::WxpayJs,
PayWay::WxpayH5,
PayWay::WxpayMp,
]);
}
@ -87,7 +80,7 @@ class PayLog extends Model
public function isAlipay(): bool
{
return in_array($this->pay_way, [
static::PAY_ALIPAY_APP,
PayWay::AlipayApp,
]);
}
@ -98,7 +91,7 @@ class PayLog extends Model
*/
public function isOffline(): bool
{
return $this->pay_way === static::PAY_WAY_OFFLINE;
return $this->pay_way === PayWay::Offline;
}
/**
@ -108,7 +101,7 @@ class PayLog extends Model
*/
public function isWallet(): bool
{
return $this->pay_way === static::PAY_WAY_WALLET;
return $this->pay_way === PayWay::Wallet;
}
/**
@ -118,6 +111,6 @@ class PayLog extends Model
*/
public function isBalance(): bool
{
return $this->pay_way === static::PAY_WAY_BALANCE;
return $this->pay_way === PayWay::Balance;
}
}

View File

@ -12,7 +12,6 @@ use App\Models\DealerOrderAllocateLog;
use App\Models\DealerOrderProduct;
use App\Models\DealerProduct;
use App\Models\DealerUserProductLog;
use App\Models\PayLog;
use App\Models\ShippingAddress;
use App\Models\User;
use App\Services\PayService;
@ -290,7 +289,7 @@ class OrderService
try {
$payLog = $order->payLogs()->create([
'pay_sn' => serial_number(),
'pay_way' => $payWay->value,
'pay_way' => $payWay,
]);
} catch (QueryException $e) {
if (strpos($e->getMessage(), 'Duplicate entry') === false) {
@ -304,7 +303,7 @@ class OrderService
];
switch ($payLog->pay_way) {
case PayLog::PAY_WAY_OFFLINE:
case PayWay::Offline:
(new PayService())->handleSuccess($payLog, [
'pay_image' => $payImage,
'pay_info' => $order->getConsignorPayInfo() ?? null,
@ -315,7 +314,7 @@ class OrderService
break;
case PayLog::PAY_WAY_WALLET:
case PayWay::Wallet:
$walletService = new WalletService();
// 扣除打款人余额
@ -346,7 +345,7 @@ class OrderService
break;
case PayLog::PAY_WAY_WXPAY_H5:
case PayWay::WxpayH5:
$app = EasyWeChatFactory::payment(config('wechat.payment.yzk'));
$data = (new WeChatPayService($app))->pay([

View File

@ -5,12 +5,13 @@ namespace App\Services;
use App\Endpoint\Api\Http\Resources\ProductSkuSimpleResource;
use App\Endpoint\Api\Http\Resources\ShippingAddressResource;
use App\Endpoint\Api\Http\Resources\UserCouponResource;
use App\Enums\PayWay;
use App\Enums\WxpayTradeType;
use App\Exceptions\BizException;
use App\Exceptions\ShippingNotSupportedException;
use App\Models\DistributionPreIncomeJob;
use App\Models\Order;
use App\Models\OrderProduct;
use App\Models\PayLog;
use App\Models\ProductGift;
use App\Models\ProductSku;
use App\Models\ShippingAddress;
@ -145,7 +146,7 @@ class OrderService
$coupon?->markAsUse();
if ($order->total_amount === 0) {
$this->pay($order, PayLog::PAY_WAY_BALANCE);
$this->pay($order, PayWay::Balance);
$order->refresh();
}
@ -753,12 +754,12 @@ class OrderService
* 订单付款
*
* @param \App\Models\Order $order
* @param string $payWay
* @param \App\Enums\PayWay $payWay
* @return mixed
*
* @throws \App\Exceptions\WeChatPayException
*/
public function pay(Order $order, string $payWay)
public function pay(Order $order, PayWay $payWay)
{
if (! $order->isPending()) {
throw new BizException('订单状态不是待付款');
@ -791,15 +792,15 @@ class OrderService
$data = null;
} elseif ($payLog->isWxpay()) {
if (! isset(WeChatPayService::$tradeTypes[$payLog->pay_way])) {
throw new BizException('支付方式不支持');
if (is_null($tradeType = WxpayTradeType::tryFromPayWay($payLog->pay_way))) {
throw new BizException('支付方式 非法');
}
$data = (new WeChatPayService())->pay([
'body' => app_settings('app.app_name').'-商城订单',
'out_trade_no' => $payLog->pay_sn,
'total_fee' => $order->total_amount,
'trade_type' => WeChatPayService::$tradeTypes[$payLog->pay_way],
'trade_type' => $tradeType->value,
]);
} elseif ($payLog->isAlipay()) {
$data = app(AlipayService::class)->pay([

View File

@ -66,26 +66,9 @@ class PayService
throw new BizException('订单已完成');
}
// 支付方式
$payWay = $payLog->pay_way;
if ($payLog->isWxpay()) {
// 微信支付
$payWay = Order::PAY_WAY_WXPAY;
} elseif ($payLog->isWallet()) {
// 可提支付
$payWay = Order::PAY_WAY_WALLET;
} elseif ($payLog->isBalance()) {
// 余额支付
$payWay = Order::PAY_WAY_BALANCE;
} elseif ($payLog->isAlipay()) {
// 支付宝
$payWay = Order::PAY_WAY_ALIPAY;
}
$payable->update([
'pay_sn' => $payLog->pay_sn,
'pay_way' => $payWay,
'pay_way' => $payLog->pay_way,
'pay_at' => $payLog->pay_at,
'out_trade_no' => $payLog->out_trade_no,
'status' => Order::STATUS_PAID,

View File

@ -3,7 +3,6 @@
namespace App\Services;
use App\Exceptions\WeChatPayException;
use App\Models\PayLog;
use Closure;
use EasyWeChat\Factory;
use EasyWeChat\Payment\Application;
@ -20,16 +19,6 @@ class WeChatPayService
public const TRADE_TYPE_NATIVE = 'NATIVE'; // Native支付
public const TRADE_TYPE_H5 = 'MWEB'; // H5支付
/**
* @var array
*/
public static $tradeTypes = [
PayLog::PAY_WAY_WXPAY_APP => self::TRADE_TYPE_APP,
PayLog::PAY_WAY_WXPAY_JSAPI => self::TRADE_TYPE_JSAPI,
PayLog::PAY_WAY_WXPAY_MINI => self::TRADE_TYPE_JSAPI,
PayLog::PAY_WAY_WXPAY_H5 => self::TRADE_TYPE_H5,
];
/**
* @var \EasyWeChat\Payment\Application
*/
@ -66,10 +55,6 @@ class WeChatPayService
$params['trade_type'] = static::TRADE_TYPE_APP;
}
if (! in_array($params['trade_type'], static::$tradeTypes)) {
throw new WeChatPayException(sprintf('交易类型 [%s] 暂不支持', $params['trade_type']), $params);
}
$result = $this->app->order->unify($params);
if (data_get($result, 'return_code') !== 'SUCCESS') {