Skip to content

Commit

Permalink
订单逻辑修改
Browse files Browse the repository at this point in the history
  • Loading branch information
shirne committed Aug 11, 2024
1 parent 328adaf commit 7e87eb6
Show file tree
Hide file tree
Showing 7 changed files with 103 additions and 52 deletions.
33 changes: 25 additions & 8 deletions src/application/admin/controller/member/PaylogController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down Expand Up @@ -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('充值单不存在');
Expand Down Expand Up @@ -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);
Expand All @@ -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)
));
}
Expand Down
8 changes: 4 additions & 4 deletions src/application/admin/view/member/paylog/index.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@
<div class="btn-group">
<button type="button" class="btn btn-secondary dropdown-toggle" data-toggle="dropdown"
aria-haspopup="true" aria-expanded="false">
订单类型 {$orderTypes[$ordertype]} <span class="caret"></span>
订单类型 {$orderTypes[$ordertype]['title']} <span class="caret"></span>
</button>
<div class="dropdown-menu">
{foreach $orderTypes as $k => $t}
<a class="dropdown-item" href="{:url('index',searchKey('ordertype',$k))}">{$t}</a>
<a class="dropdown-item" href="{:url('index',searchKey('ordertype',$k))}">{$t.title}</a>
{/foreach}
</div>
</div>
Expand Down Expand Up @@ -58,7 +58,7 @@
<th class="text-center">\</th>
{foreach $orderTypes as $k => $t}
{if $k != 'all'}
<th>{$t}</th>
<th>{$t.title}</th>
{/if}
{/foreach}
<th>合计</th>
Expand Down Expand Up @@ -127,7 +127,7 @@
<td class="text-success">¥{$v.pay_amount|showmoney}</td>
<td>{$payTypes[$v['pay_type']]}</td>
<td><a href="{:url($orderDetails[$v['order_type']],['id'=>$v['order_id']])}"
target="_blank">{$orderTypes[$v['order_type']]}</a></td>
target="_blank">{$orderTypes[$v['order_type']]['title']}</a></td>
<td>{$v.create_time|showdate}</td>
<td>{if $v['is_refund'] > 0}
<span class="badge badge-warning">{$v['is_refund']}次 共¥{$v['refund_fee']}</span>
Expand Down
5 changes: 5 additions & 0 deletions src/application/common/core/BaseOrderModel.php
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down
10 changes: 10 additions & 0 deletions src/application/common/model/MemberLevelLogModel.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
11 changes: 11 additions & 0 deletions src/application/common/model/MemberRechargeModel.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
86 changes: 47 additions & 39 deletions src/application/common/model/PayOrderModel.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

use EasyWeChat\Factory;
use app\common\core\BaseModel;
use modules\credit\model\CreditOrderModel;
use think\Db;
use think\facade\Log;

Expand All @@ -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');
Expand All @@ -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)) {
Expand Down Expand Up @@ -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');
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/application/common/model/PayOrderRefundModel.php
Original file line number Diff line number Diff line change
Expand Up @@ -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'],
Expand Down

0 comments on commit 7e87eb6

Please sign in to comment.