57171b2f57 feat(merchant): 添加码速达自动发卡功能
- 新增码速达自动发卡设置界面
- 实现码速达账号UID和密钥的保存和使用
- 添加消息订阅功能
- 优化自动发卡逻辑,增加错误处理和状态更新
2025-03-17 03:38:44 +08:00

182 lines
5.6 KiB
PHP
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<?php
// +----------------------------------------------------------------------
// | ThinkAdmin
// +----------------------------------------------------------------------
// | 版权所有 2014~2020 广州楚才信息科技有限公司 [ http://www.cuci.cc ]
// +----------------------------------------------------------------------
// | 官方网站: https://thinkadmin.top
// +----------------------------------------------------------------------
// | 开源协议 ( https://mit-license.org )
// +----------------------------------------------------------------------
// | gitee 代码仓库https://gitee.com/zoujingli/ThinkAdmin
// | github 代码仓库https://github.com/zoujingli/ThinkAdmin
// +----------------------------------------------------------------------
namespace app\merchant\controller;
use think\admin\Controller;
use app\merchant\service\MerchantLogService;
use app\merchant\service\MerchantService;
use app\merchant\service\OrderService;
use app\channel\service\ChannelService;
use app\channel\service\ProductService;
use app\merchant\service\MerchantLogHistoryService;
/**
* 商户资金管理
* Class Merchant
* @package app\merchant\controller
*/
class Account extends Controller
{
/**
* 绑定数据表
* @var string
*/
public $table = 'MerchantAccountLog';
/**
* 充值信息列表
* @auth true
* @menu true
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
*/
public function index()
{
$id = input('id');
$this->info = MerchantService::instance()->getInfo($id);
$this->title = '【' . $this->info['name'] . '】交易明细列表';
$data_type = input('data_type', 1);
if ($data_type == 2) {
$this->table = 'MerchantAccountLogHistory';
}
$this->data_type = $data_type;
$query = $this->_query($this->table);
$query->where(array('is_yue' => 1));
$query->equal('mid,type,oper,account_type')->like('order_id')->dateBetween('create_at,order_date');
$query->where(['mid' => $id]);
// 列表排序并显示
if (input('output') === 'json') {
$result = $query->order('id desc')->page(true, false);
$this->success('获取数据列表成功', $result);
} else {
$query->order('id desc')->page();
}
}
/**
* 表单数据处理
* @param array $data
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
*/
protected function _form_filter(&$data)
{
}
/**
* 列表数据处理
* @param array $data
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
*/
protected function _index_page_filter(array &$data)
{
$merchant = MerchantService::instance();
$this->type = $this->type();
$this->account_type = $this->account_type();
foreach ($data as $k => $v) {
$data[$k]['merchant'] = $this->info;
$data[$k]['oper_name'] = $this->type($v['type']);
if ($v['account_type'] == 2) {
$data[$k]['account_name'] = '授信账户';
} else {
$data[$k]['account_name'] = '余额账户';
}
if ($data[$k]['num'] > 0) {
if ($v['oper'] == 1) {
$data[$k]['snum'] = '+' . $data[$k]['num'];
} else {
$data[$k]['snum'] = '-' . $data[$k]['num'];
}
} else {
$data[$k]['snum'] = $data[$k]['num'];
}
$data[$k]['snum'] = $this->endsWithDoubleZero($data[$k]['snum']);
$data[$k]['qian_yue'] = $this->endsWithDoubleZero($data[$k]['qian_yue']);
$data[$k]['yue'] = $this->endsWithDoubleZero($data[$k]['yue']);
$data[$k]['product_cash'] = $this->endsWithDoubleZero($data[$k]['product_cash']);
$data[$k]['profit'] = $this->endsWithDoubleZero($data[$k]['profit']);
}
if ($this->data_type == 2) {
$this->total = MerchantLogHistoryService::instance()->total($this->info['id'], $this->info);
} else {
$this->total = MerchantLogService::instance()->total($this->info['id'], $this->info);
}
}
protected function type($type = false)
{
$config = array
(
'' => '全部',
1 => '充值',
2 => '扣减',
3 => '下单成功扣减',
4 => '下单失败返还',
5 => '满额返点',
6 => '授信',
);
if (!$type) {
return $config;
} else {
return $config[$type];
}
}
protected function account_type($type = false)
{
$config = array
(
'' => '全部',
2 => '授信账户',
1 => '余额账户',
);
if (!$type) {
return $config;
} else {
return $config[$type];
}
}
public function endsWithDoubleZero($string) {
// 获取字符串的长度
$length = strlen($string);
// 检查字符串长度是否至少为4并且最后两位是否为 '00'
if ($length >= 4 && str_ends_with($string, '00')) {
// 截去最后两位
if(str_ends_with($string, '.00')){
return $string;
}
return substr($string, 0, $length - 2);
}
// 如果最后两位不是 '00',返回原字符串
return $string;
}
}