From 7e87eb68edc10f698845947285989eb025c04054 Mon Sep 17 00:00:00 2001 From: shirne Date: Sun, 11 Aug 2024 15:46:30 +0800 Subject: [PATCH] =?UTF-8?q?=E8=AE=A2=E5=8D=95=E9=80=BB=E8=BE=91=E4=BF=AE?= =?UTF-8?q?=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/member/PaylogController.php | 33 +++++-- .../admin/view/member/paylog/index.tpl | 8 +- .../common/core/BaseOrderModel.php | 5 ++ .../common/model/MemberLevelLogModel.php | 10 +++ .../common/model/MemberRechargeModel.php | 11 +++ .../common/model/PayOrderModel.php | 86 ++++++++++--------- .../common/model/PayOrderRefundModel.php | 2 +- 7 files changed, 103 insertions(+), 52 deletions(-) diff --git a/src/application/admin/controller/member/PaylogController.php b/src/application/admin/controller/member/PaylogController.php index 4c0f940f..9b6a38ca 100644 --- a/src/application/admin/controller/member/PaylogController.php +++ b/src/application/admin/controller/member/PaylogController.php @@ -69,7 +69,7 @@ public function index($id = 0, $fromdate = '', $todate = '', $ordertype = 'all', $logs = $model->order('ID DESC')->paginate(15); - $all = ['all' => '全部']; + $all = ['all' => ['title' => '全部']]; $orderTypes = array_merge($all, PayOrderModel::$orderTypes); $payTypes = array_merge($all, PayOrderModel::$payTypes); @@ -178,7 +178,7 @@ public function rechargeupdate($id = '') if ($id == 0) $this->error('参数错误 '); /** - * @var $recharge MemberRechargeModel + * @var MemberRechargeModel */ $recharge = MemberRechargeModel::find($id); if (empty($recharge)) $this->error('充值单不存在'); @@ -309,9 +309,19 @@ public function export($ids = '', $status = '', $key = '') $excel = new Excel(); $excel->setHeader(array( - '编号', '会员ID', '会员账号', - '提现来源', '提现金额', '应转款', '申请时间', - '提现方式', '银行', '分行', '开户名', '卡号', '状态' + '编号', + '会员ID', + '会员账号', + '提现来源', + '提现金额', + '应转款', + '申请时间', + '提现方式', + '银行', + '分行', + '开户名', + '卡号', + '状态' )); $excel->setColumnType('A', DataType::TYPE_STRING); $excel->setColumnType('B', DataType::TYPE_STRING); @@ -321,11 +331,18 @@ public function export($ids = '', $status = '', $key = '') foreach ($rows as $row) { $excel->addRow(array( - $row['id'], $row['member_id'], $row['username'], - money_type($row['from_field'], false), showmoney($row['amount']), showmoney($row['real_amount']), + $row['id'], + $row['member_id'], + $row['username'], + money_type($row['from_field'], false), + showmoney($row['amount']), + showmoney($row['real_amount']), date('Y-m-d H:i:s', $row['create_time']), showcashtype($row['cashtype']), - $row['bank_name'], $row['bank'], $row['card_name'], $row['cardno'], + $row['bank_name'], + $row['bank'], + $row['card_name'], + $row['cardno'], audit_status($row['status'], false) )); } diff --git a/src/application/admin/view/member/paylog/index.tpl b/src/application/admin/view/member/paylog/index.tpl index f0b7c95a..2584bfce 100644 --- a/src/application/admin/view/member/paylog/index.tpl +++ b/src/application/admin/view/member/paylog/index.tpl @@ -11,11 +11,11 @@
@@ -58,7 +58,7 @@ \ {foreach $orderTypes as $k => $t} {if $k != 'all'} - {$t} + {$t.title} {/if} {/foreach} 合计 @@ -127,7 +127,7 @@ ¥{$v.pay_amount|showmoney} {$payTypes[$v['pay_type']]} {$orderTypes[$v['order_type']]} + target="_blank">{$orderTypes[$v['order_type']]['title']} {$v.create_time|showdate} {if $v['is_refund'] > 0} {$v['is_refund']}次 共¥{$v['refund_fee']} diff --git a/src/application/common/core/BaseOrderModel.php b/src/application/common/core/BaseOrderModel.php index d8640da7..feb40537 100644 --- a/src/application/common/core/BaseOrderModel.php +++ b/src/application/common/core/BaseOrderModel.php @@ -20,6 +20,11 @@ public function getInsertStatus() return $this->lastInsertStatus; } + public static function getOrder($id) + { + return static::where('order_id', $id)->find(); + } + protected function orderno_sufix() { $key = 'order_no_' . strtolower(str_replace(['/', '\\'], '_', static::class)); diff --git a/src/application/common/model/MemberLevelLogModel.php b/src/application/common/model/MemberLevelLogModel.php index 99d3a1f8..0413f186 100644 --- a/src/application/common/model/MemberLevelLogModel.php +++ b/src/application/common/model/MemberLevelLogModel.php @@ -23,6 +23,16 @@ public static function init() parent::init(); } + + public static function getOrder($id) + { + $order = static::where('id', $id)->find(); + if (!empty($order)) { + $order['order_id'] = $order['id']; + } + return $order; + } + protected function triggerStatus($item, $status, $newData = []) { parent::triggerStatus($item, $status, $newData); diff --git a/src/application/common/model/MemberRechargeModel.php b/src/application/common/model/MemberRechargeModel.php index c0367f7b..7d915009 100644 --- a/src/application/common/model/MemberRechargeModel.php +++ b/src/application/common/model/MemberRechargeModel.php @@ -22,4 +22,15 @@ protected function triggerStatus($item, $status, $newData = []) money_log($item['member_id'], $item['amount'], '订单[' . $item['id'] . ']充值成功', 'recharge'); } } + + public static function getOrder($id) + { + $order = static::where('id', $id)->find(); + if (!empty($order)) { + $order['payamount'] = $order['amount'] * .01; + $order['order_no'] = 'CZ_' . str_pad($order['id'], 6, '0', STR_PAD_LEFT); + $order['order_id'] = $order['id']; + } + return $order; + } } diff --git a/src/application/common/model/PayOrderModel.php b/src/application/common/model/PayOrderModel.php index 62b4bc92..906f2fa8 100644 --- a/src/application/common/model/PayOrderModel.php +++ b/src/application/common/model/PayOrderModel.php @@ -4,7 +4,6 @@ use EasyWeChat\Factory; use app\common\core\BaseModel; -use modules\credit\model\CreditOrderModel; use think\Db; use think\facade\Log; @@ -19,16 +18,36 @@ class PayOrderModel extends BaseModel protected $type = ['pay_data' => 'array']; public static $orderTypes = [ - 'order' => '商城订单', - 'groupbuy' => '团购订单', - 'credit' => '积分订单', - 'recharge' => '充值订单' + 'order' => [ + 'title' => '商城订单', + 'prefix' => '', + 'class' => 'app\common\model\OrderModel' + ], + 'recharge' => [ + 'title' => '充值订单', + 'prefix' => 'CZ_', + 'class' => 'app\common\model\MemberRechargeModel' + ], + 'upgrade' => [ + 'title' => '升级订单', + 'prefix' => 'UL_', + 'class' => 'app\common\model\MemberLevelLogModel' + ], ]; public static $payTypes = [ 'wechat' => '微信支付', 'alipay' => '支付宝' ]; + public static function register($type, $title, $prefix, $orderClass) + { + static::$orderTypes[$type] = [ + 'title' => $title, + 'prefix' => $prefix, + 'class' => $orderClass + ]; + } + private static function create_no() { $maxid = Db::name('payOrder')->max('id'); @@ -45,31 +64,24 @@ public function createFromOrder($payid, $paytype, $orderno, $trade_type = '') { $ordertype = ''; $orderid = 0; - if (strpos($orderno, 'CZ_') === 0) { - $ordertype = 'recharge'; - $orderno = intval(substr($orderno, 3)); - $order = Db::name('memberRecharge')->where('id', $orderno) - ->find(); - if (!empty($order)) { - $order['payamount'] = $order['amount'] * .01; - $order['order_no'] = 'CZ_' . str_pad($order['id'], 6, '0', STR_PAD_LEFT); - $orderid = $order['id']; - } - } elseif (strpos($orderno, 'UL_') === 0) { - $ordertype = 'upgrade'; - $orderno = intval(substr($orderno, 3)); - $order = MemberLevelLogModel::get($orderno); - if (!empty($order)) { - $orderid = $order['id']; - } - } elseif (strpos($orderno, 'PO_') === 0) { - $ordertype = 'credit'; - $orderno = intval(substr($orderno, 3)); - $order = CreditOrderModel::get($orderno); - if (!empty($order)) { - $orderid = $order['id']; + foreach (static::$orderTypes as $k => $oType) { + if (!empty($oType['prefix'])) { + if (strpos($orderno, $oType['prefix']) === 0) { + $ordertype = $k; + $orderno = intval(substr($orderno, strlen($oType['prefix']))); + + $order = call_user_func([$oType['class'], 'getOrder'], $orderno); + + if (empty($order)) { + $this->setError('订单已失效或不存在!'); + return false; + } + $orderid = $order['order_id']; + break; + } } - } else { + } + if (empty($k)) { $ordertype = 'order'; $order = OrderModel::get($orderno); if (!empty($order)) { @@ -196,19 +208,15 @@ protected function triggerStatus($item, $status, $newData = []) if ($status == 1) { $paytime = isset($newData['pay_time']) ? $newData['pay_time'] : 0; if (!$paytime) $paytime = time(); - switch ($item['order_type']) { - case 'recharge': - $order = MemberRechargeModel::where('id', $item['order_id'])->find(); - break; - case 'credit': - $order = CreditOrderModel::where('order_id', $item['order_id'])->find(); - break; - default: - $order = OrderModel::where('order_id', $item['order_id'])->find(); - break; + if (isset(static::$orderTypes[$item['order_type']])) { + $oType = static::$orderTypes[$item['order_type']]; + $order = call_user_func([$oType['class'], 'getOrder'], $item['order_id']); } + if (!empty($order)) { $order->onPayResult($item['pay_type'], $paytime, $item['pay_amount'] / 100); + } else { + Log::warning('order ' . $item['order_type'] . '/' . $item['order_id'] . ' error'); } } } diff --git a/src/application/common/model/PayOrderRefundModel.php b/src/application/common/model/PayOrderRefundModel.php index 0181b6d9..e6c7a25f 100644 --- a/src/application/common/model/PayOrderRefundModel.php +++ b/src/application/common/model/PayOrderRefundModel.php @@ -28,7 +28,7 @@ private static function pad_orderid($id, $len = 4) return $strlen < $len ? str_pad($id, $len, '0', STR_PAD_LEFT) : substr($id, $strlen - $len); } - public function createFromPayOrder($payOrder, $reason, $refundFee = null) + public static function createFromPayOrder($payOrder, $reason, $refundFee = null) { $refund = [ 'member_id' => $payOrder['member_id'],