From b0ee504c5c9de9b48196c713ad7753f274fe2085 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=82=B9=E6=99=AF=E7=AB=8B?= Date: Tue, 9 Mar 2021 15:45:02 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E5=87=AD=E8=AF=81=E6=94=AF?= =?UTF-8?q?=E4=BB=98=EF=BC=8C=E5=AE=A1=E6=A0=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/data/controller/ShopOrder.php | 5 ++- app/data/controller/api/News.php | 6 +-- app/data/controller/api/Notify.php | 4 +- app/data/service/PaymentService.php | 36 +++++++++++---- .../service/payment/EmptyPaymentService.php | 2 +- ...tService.php => JoinpayPaymentService.php} | 8 ++-- .../service/payment/VoucherPaymentService.php | 44 +++++++++++++++++++ .../service/payment/WechatPaymentService.php | 2 +- 8 files changed, 86 insertions(+), 21 deletions(-) rename app/data/service/payment/{JoinPaymentService.php => JoinpayPaymentService.php} (96%) create mode 100644 app/data/service/payment/VoucherPaymentService.php diff --git a/app/data/controller/ShopOrder.php b/app/data/controller/ShopOrder.php index 710ff8b21..fb94ffd82 100644 --- a/app/data/controller/ShopOrder.php +++ b/app/data/controller/ShopOrder.php @@ -28,6 +28,9 @@ class ShopOrder extends Controller */ protected $payments = []; + /** + * 控制器初始化 + */ protected function initialize() { parent::initialize(); @@ -46,7 +49,7 @@ class ShopOrder extends Controller { $this->title = '订单数据管理'; // 状态数据统计 - $this->total = ['t0' => 0, 't1' => 0, 't2' => 0, 't3' => 0, 't4' => 0, 't5' => 0, 'ta' => 0]; + $this->total = ['t0' => 0, 't1' => 0, 't2' => 0, 't3' => 0, 't4' => 0, 't5' => 0, 't6' => 0, 'ta' => 0]; $this->app->db->name($this->table)->fieldRaw('status,count(1) total')->group('status')->select()->map(function ($vo) { $this->total["t{$vo['status']}"] = $vo['total']; $this->total["ta"] += $vo['total']; diff --git a/app/data/controller/api/News.php b/app/data/controller/api/News.php index 927e44614..b4f3211b2 100644 --- a/app/data/controller/api/News.php +++ b/app/data/controller/api/News.php @@ -22,7 +22,7 @@ class News extends Controller { $query = $this->_query('DataNewsMark')->like('name'); $query->where(['status' => 1, 'deleted' => 0])->withoutField('sort,status,deleted'); - $this->success('获取文章标签列表', $query->order('sort desc,id desc')->page(false, false)); + $this->success('获取文章标签', $query->order('sort desc,id desc')->page(false, false)); } /** @@ -47,7 +47,7 @@ class News extends Controller $query->where(['deleted' => 0, 'status' => 1])->withoutField('sort,status,deleted'); $result = $query->order('sort desc,id desc')->page(true, false, false, 15); NewsService::instance()->buildListState($result['list'], input('uid', 0)); - $this->success('获取列表成功!', $result); + $this->success('获取文章内容', $result); } /** @@ -62,7 +62,7 @@ class News extends Controller $query = $this->_query('DataNewsXCollect')->where(['type' => 4, 'status' => 2]); $result = $query->where($map)->order('id desc')->page(true, false, false, 15); NewsService::instance()->buildListByUidAndCode($result['list']); - $this->success('获取评论成功!', $result); + $this->success('获取评论成功', $result); } } \ No newline at end of file diff --git a/app/data/controller/api/Notify.php b/app/data/controller/api/Notify.php index c10dd03a2..14510e13d 100644 --- a/app/data/controller/api/Notify.php +++ b/app/data/controller/api/Notify.php @@ -3,7 +3,7 @@ namespace app\data\controller\api; use app\data\service\payment\AlipayPaymentService; -use app\data\service\payment\JoinPaymentService; +use app\data\service\payment\JoinpayPaymentService; use app\data\service\payment\WechatPaymentService; use think\admin\Controller; @@ -68,7 +68,7 @@ class Notify extends Controller public function joinpay(string $scene = 'order', string $param = ''): string { if (strtolower($scene) === 'order') { - return JoinPaymentService::instance($param)->notify(); + return JoinpayPaymentService::instance($param)->notify(); } else { return 'success'; } diff --git a/app/data/service/PaymentService.php b/app/data/service/PaymentService.php index 98c3bbe2f..2fd14310a 100644 --- a/app/data/service/PaymentService.php +++ b/app/data/service/PaymentService.php @@ -5,7 +5,8 @@ namespace app\data\service; use app\data\service\payment\AlipayPaymentService; use app\data\service\payment\BalancePyamentService; use app\data\service\payment\EmptyPaymentService; -use app\data\service\payment\JoinPaymentService; +use app\data\service\payment\JoinpayPaymentService; +use app\data\service\payment\VoucherPaymentService; use app\data\service\payment\WechatPaymentService; use think\App; use think\Container; @@ -22,6 +23,7 @@ abstract class PaymentService // 用户余额支付 const PAYMENT_EMPTY = 'empty'; const PAYMENT_BALANCE = 'balance'; + const PAYMENT_VOUCHER = 'voucher'; // 汇聚支付参数 const PAYMENT_JOINPAY_GZH = 'joinpay_gzh'; @@ -56,6 +58,15 @@ abstract class PaymentService UserService::APITYPE_IOSAPP, UserService::APITYPE_ANDROID, ], ], + self::PAYMENT_VOUCHER => [ + 'type' => 'VOUCHER', + 'name' => '凭证单据支付', + 'bind' => [ + UserService::APITYPE_WAP, UserService::APITYPE_WEB, + UserService::APITYPE_WXAPP, UserService::APITYPE_WECHAT, + UserService::APITYPE_IOSAPP, UserService::APITYPE_ANDROID, + ], + ], self::PAYMENT_WECHAT_WAP => [ 'type' => 'MWEB', 'name' => '微信WAP支付', @@ -155,8 +166,8 @@ abstract class PaymentService /** * 根据配置实例支付服务 - * @param string $code 支付参数编号 - * @return JoinPaymentService|WechatPaymentService|AlipayPaymentService + * @param string $code 支付配置编号 + * @return JoinpayPaymentService|WechatPaymentService|AlipayPaymentService|BalancePyamentService|VoucherPaymentService|EmptyPaymentService * @throws Exception */ public static function instance(string $code): PaymentService @@ -171,12 +182,14 @@ abstract class PaymentService // 实例化具体支付参数类型 if (stripos($type, 'balance') === 0) { return static::$driver[$code] = Container::getInstance()->make(BalancePyamentService::class, $vars); + } elseif (stripos($type, 'voucher') === 0) { + return static::$driver[$code] = Container::getInstance()->make(VoucherPaymentService::class, $vars); } elseif (stripos($type, 'alipay_') === 0) { return static::$driver[$code] = Container::getInstance()->make(AlipayPaymentService::class, $vars); } elseif (stripos($type, 'wechat_') === 0) { return static::$driver[$code] = Container::getInstance()->make(WechatPaymentService::class, $vars); } elseif (stripos($type, 'joinpay_') === 0) { - return static::$driver[$code] = Container::getInstance()->make(JoinPaymentService::class, $vars); + return static::$driver[$code] = Container::getInstance()->make(JoinpayPaymentService::class, $vars); } else { throw new Exception(sprintf('支付驱动[%s]未定义', $type)); } @@ -211,7 +224,7 @@ abstract class PaymentService * 获取通道配置参数 * @param string $code * @param array $payment - * @return array [code,type,params] + * @return array [code, type, params] * @throws Exception */ public static function config(string $code, array $payment = []): array @@ -238,7 +251,7 @@ abstract class PaymentService } /** - * 订单更新操作 + * 订单支付更新操作 * @param string $orderNo 订单单号 * @param string $paymentTrade 交易单号 * @param string $paymentAmount 支付金额 @@ -250,13 +263,18 @@ abstract class PaymentService */ public function updateOrder(string $orderNo, string $paymentTrade, string $paymentAmount, $paymentRemark = '在线支付'): bool { - // 检查订单支付状态 - $map = ['order_no' => $orderNo, 'payment_status' => 0, 'status' => 2]; + $map = ['status' => 2, 'order_no' => $orderNo, 'payment_status' => 0]; $order = $this->app->db->name('ShopOrder')->where($map)->find(); if (empty($order)) return false; + // 检查订单支付状态 + if ($this->type === self::PAYMENT_VOUCHER) { + $status = 3; + } else { + $status = 4; + } // 更新订单支付状态 $data = [ - 'status' => 3, + 'status' => $status, 'payment_type' => $this->type, 'payment_code' => $this->code, 'payment_trade' => $paymentTrade, diff --git a/app/data/service/payment/EmptyPaymentService.php b/app/data/service/payment/EmptyPaymentService.php index db731cf68..22f403a25 100644 --- a/app/data/service/payment/EmptyPaymentService.php +++ b/app/data/service/payment/EmptyPaymentService.php @@ -56,6 +56,6 @@ class EmptyPaymentService extends PaymentService $this->createPaymentAction($orderNo, $paymentTitle, $paymentAmount); // 更新支付行为 $this->updatePaymentAction($orderNo, CodeExtend::uniqidDate(20), $paymentAmount, '无需支付'); - return ['info' => '无需支付']; + return ['info' => '无需支付', 'status' => 1]; } } \ No newline at end of file diff --git a/app/data/service/payment/JoinPaymentService.php b/app/data/service/payment/JoinpayPaymentService.php similarity index 96% rename from app/data/service/payment/JoinPaymentService.php rename to app/data/service/payment/JoinpayPaymentService.php index ff4fdf141..91bc97bb9 100644 --- a/app/data/service/payment/JoinPaymentService.php +++ b/app/data/service/payment/JoinpayPaymentService.php @@ -8,10 +8,10 @@ use think\admin\Exception; /** * 汇聚支付基础服务 - * Class JoinPaymentService + * Class JoinpayPaymentService * @package app\store\service\payment */ -class JoinPaymentService extends PaymentService +class JoinpayPaymentService extends PaymentService { /** * 请求地址 @@ -45,9 +45,9 @@ class JoinPaymentService extends PaymentService /** * 汇聚支付服务初始化 - * @return JoinPaymentService + * @return JoinpayPaymentService */ - protected function initialize(): JoinPaymentService + protected function initialize(): JoinpayPaymentService { $this->appid = $this->params['joinpay_appid']; $this->trade = $this->params['joinpay_trade'];; diff --git a/app/data/service/payment/VoucherPaymentService.php b/app/data/service/payment/VoucherPaymentService.php new file mode 100644 index 000000000..36099f99a --- /dev/null +++ b/app/data/service/payment/VoucherPaymentService.php @@ -0,0 +1,44 @@ + $openid, 'attach' => $this->code, 'out_trade_no' => $orderNo, - 'total_fee' => $paymentAmount * 100, 'trade_type' => $tradeType ?: '', + 'total_fee' => $paymentAmount * 100, 'notify_url' => sysuri("@data/api.notify/wxpay/scene/order/param/{$this->code}", [], false, true), 'spbill_create_ip' => $this->app->request->ip(), ];