REAPI/app/merchant/controller/Merchant.php

434 lines
15 KiB
PHP
Raw Normal View History

2024-09-29 15:43:18 +08:00
<?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;
/**
* 商户管理
* Class Merchant
* @package app\merchant\controller
*/
class Merchant extends Controller
{
/**
* 绑定数据表
* @var string
*/
public $table = 'MerchantList';
/**
* 商户列表
* @auth true
* @menu true
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
*/
public function index()
{
$this->title = '商户列表';
$query = $this->_query($this->table);
$query->equal('status')->dateBetween('create_at');
$query->like('name,phone,contacts,ip_white');
2024-09-29 15:43:18 +08:00
// 加载对应数据列表
$this->type = input('type', 'all');
$query->where(['is_deleted' => 0]);
// 列表排序并显示
$query->order('status desc,id desc')->page();
}
/**
* 添加商户
* @auth true
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
*/
public function add()
{
$this->_applyFormToken();
$this->_form($this->table, 'form');
}
/**
* 编辑商户
* @auth true
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
*/
public function edit()
{
$this->_applyFormToken();
$this->_form($this->table, 'form');
}
/**
* 列表数据处理
* @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)
{
$order = OrderService::instance();
foreach ($data as $k => $v) {
$data[$k]['order_yes'] = $order->getOrderTotal($v['id'], 2);
$data[$k]['order_no'] = $order->getOrderTotal($v['id'], 3);
/*
$where['mid'] = $v['id'];
$where['account_type'] = 1;
$where['type'] = 1;
$data[$k]['account_chongzhi_total'] = sprintf("%.2f", $this->app->db->name('MerchantAccountLog')->where($where)->sum('num'));
$where['account_type'] = 2;
$where['type'] = 6;
$xin = $this->app->db->name('MerchantAccountLog')->where($where)->find();
$data[$k]['credit_cash'] = 0.00;
if ($xin) {
$data[$k]['credit_total'] = sprintf("%.2f", $this->app->db->name('MerchantAccountLog')->where($where)->sum('num'));
}*/
if ($data[$k]['credit_total'] > 0) {
/*
$where['mid'] = $v['id'];
$where['account_type'] = 2;
$where['type'] = 1;
$result['credit_zonghuikuan'] = $this->app->db->name('MerchantAccountLog')->where($where)->sum('num');
$where['type'] = 2;
$result['credit_zonghuifu'] = $this->app->db->name('MerchantAccountLog')->where($where)->sum('num');
$result['credit_zonghuikuan'] -= $result['credit_zonghuifu'];
$where['type'] = 3;
$result['credit_kou'] = $this->app->db->name('MerchantAccountLog')->where($where)->sum('num');
$where['type'] = 4;
$result['credit_huifu'] = $this->app->db->name('MerchantAccountLog')->where($where)->sum('num');
$data[$k]['credit_huikuan'] = sprintf("%.2f", $result['credit_kou'] - $result['credit_huifu'] - $result['credit_zonghuikuan']);
*/
$data[$k]['credit_huikuan'] = $v['credit_total'] - $v['credit_surplus'];
} else {
$data[$k]['credit_huikuan'] = '0.00';
}
if ($data[$k]['account_surplus'] < 0) {
//$data[$k]['account_baitiao'] += $data[$k]['account_surplus'];
//$data[$k]['account_surplus'] = 0;
}
}
}
/**
* 表单数据处理
* @param array $data
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
*/
protected function _form_filter(&$data)
{
$this->channel = $this->app->db->name('ChannelList')->where(['is_deleted' => 0])->order('sort desc,id desc')->select();
if ($this->request->isPost()) {
if (isset($data['cids']) && $data['cids']) {
$data['cids'] = implode(',', $data['cids']);
} else {
$data['cids'] = '';
}
if (isset($data['id']) && $data['id'] > 0) {
unset($data['username']);
} else {
if (empty($data['name'])) $this->error('商户名称不能为空!');
/*
if (empty($data['username'])) $this->error('登陆账号不能为空!');
$where = ['username' => $data['username'], 'is_deleted' => 0];
if ($this->app->db->name($this->table)->where($where)->count() > 0) {
$this->error("登陆账号{$data['username']}已经存在!");
}
$data['password'] = md5($data['username']);
*/
}
// print_r($data);die;
} else {
if (isset($data['cids']) && $data['cids'] && is_string($data['cids'])) {
$data['cids'] = explode(',', $data['cids']);
} else {
$data['cids'] = array();
}
}
}
protected function _form_result($id, $data)
{
$info = $this->app->db->name($this->table)->where(['id' => $id])->find();
if ($info && !$info['appid']) {
$key = MerchantService::instance()->resetApi(1);
$data = array(
'appid' => $key['appid'],
'appsecret' => $key['appsecret'],
);
$this->app->db->name($this->table)->where(array('id' => $id))->update($data);
}
/*
$where['id'] = $id;
$info = $this->app->db->name($this->table)->where($where)->find();
MerchantService::instance()->get($info['appid'], false);
*/
}
/**
* 账户充值
* @auth true
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
*/
public function recharge()
{
$this->_applyFormToken();
$mid = input('id');
$shouxin = MerchantLogService::instance()->checkShouxin($mid);
if ($this->request->isGet()) {
# 验证当前账户是否有授信
if ($shouxin) {
$this->account_type = array('2'=>'授信账户', '1'=>'余额账户');
} else {
$this->account_type = array('1'=>'余额账户', '2' => '授信账户');
}
$this->verify = false;
$this->_form($this->table, 'recharge');
} else {
$data = $this->_vali([
'account_type.require' => '账户类型不能为空!',
'mid.require' => '商户ID不能为空',
'type.require' => '类型不能为空!',
'num.require' => '金额不能为空!',
'desc.require' => '描述不能为空!',
]);
if ($data['account_type'] == 1 && $data['type'] == 6) {
$this->error('无效操作,请选择授信账户!');
}
if ($data['account_type'] == 1 && $data['type'] == -6) {
$this->error('无效操作,请选择授信账户!');
}
if ($data['account_type'] == 2 && $data['type'] == 1 && !$shouxin) {
$this->error('无效操作,请先增加授信额度!');
}
//$account = MerchantLogService::instance()->countAccount($data['type'], $data['num'], $data['mid'], $data['account_type']);
//if ($data['type'] == 2 && $data['account_type'] == 1 && $data['num'] > $account['account_surplus']) $this->error('账户余额不足!');
if ($data['num'] < 1) $this->error('金额不能小于1元');
if ($data['type'] == -6) {
$data['type'] = 6;
$data['num'] = $data['num'] * -1;
}
if (MerchantLogService::instance()->add($data['mid'], $data['num'], $data['account_type'],$data['type'],$data['desc']) !== false) {
2024-12-04 12:33:47 +08:00
sysoplog('修改金额', '修改金额:'.$data['num'].'元,类型为:'. $data['account_type']);
2024-09-29 15:43:18 +08:00
/*
$info = MerchantService::instance()->getInfo($data['mid']);
MerchantService::instance()->get($info['appid'], false);
MerchantService::instance()->get($data['mid'], false);
*/
$this->success('操作成功!', '');
} else {
$this->error('操作失败,请稍候再试!');
}
}
}
/**
* 重置商户秘钥
* @auth true
* @throws \think\db\exception\DbException
*/
public function resetapi()
{
//$this->_applyFormToken();
if ($this->request->isPost()) {
$key = MerchantService::instance()->resetApi(1);
$data = $this->_vali([
'id.require' => '商户ID不能为空',
'appid' => $key['appid'],
'appsecret' => $key['appsecret'],
]);
if (data_save($this->table, $data , 'id')) {
# 重写缓存
MerchantService::instance()->get($key['appid'], false);
MerchantService::instance()->get($data['id'], false);
$this->success('秘钥重置成功,请通知商户使用新秘钥!', '');
} else {
$this->error('秘钥重置失败,请稍候再试!');
}
}
$this->_save($this->table);
}
/**
* 修改当前商户密码
* @login true
* @auth true
* @param integer $id
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
*/
public function pass($id = 0)
{
$this->_applyFormToken();
if ($this->app->request->isGet()) {
$this->verify = false;
$this->_form($this->table, 'pass', 'id', [], ['id' => $id]);
} else {
$data = $this->_vali([
'username.require' => '登录用户账号不能为空!',
'password.require' => '登录密码不能为空!',
'repassword.require' => '重复密码不能为空!',
//'oldpassword.require' => '旧的密码不能为空!',
'password.confirm:repassword' => '两次输入的密码不一致!',
]);
$where = ['username' => $data['username'], 'is_deleted' => 0];
if ($this->app->db->name($this->table)->where($where)->whereRaw('id != ' . $id)->count() > 0) {
$this->error("登陆账号{$data['username']}已经存在!");
}
$user = $this->app->db->name($this->table)->where(['id' => $id])->find();
/*
if (md5($data['oldpassword']) !== $user['password']) {
$this->error('旧密码验证失败,请重新输入!');
}
*/
if (data_save($this->table, ['id' => $user['id'], 'username' => $data['username'], 'show_pwd' => $data['password'], 'password' => md5($data['password'])])) {
$this->success('密码修改成功!', '');
} else {
$this->error('密码修改失败,请稍候再试!');
}
}
}
2024-09-29 15:43:18 +08:00
/**
* 商户信息查看
* @login true
* @auth true
* @param integer $id
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
*/
public function info()
{
$this->_applyFormToken();
$id = input('id');
$this->host = sysconf('api_host');
$this->doc = sysconf('system_api_host');
$this->shanghu_host = sysconf('system_shanghu_host');
$this->_form($this->table, 'info', 'id', [], ['id' => $id]);
}
/**
* 修改商户状态
* @auth true
* @throws \think\db\exception\DbException
*/
public function state()
{
//$this->_applyFormToken();
$this->_save($this->table, $this->_vali([
'status.in:0,1' => '状态值范围异常!',
'status.require' => '状态值不能为空!',
]));
}
/**
* 修改商户其他状态码
* @auth true
* @throws \think\db\exception\DbException
*/
public function otherstate()
{
//$this->_applyFormToken();
$this->_save($this->table, $this->_vali([
'other_status.in:0,1' => '状态值范围异常!',
'other_status.require' => '状态值不能为空!',
]));
}
/**
* 删除商户
* @auth true
* @throws \think\db\exception\DbException
*/
public function remove()
{
$this->_applyFormToken();
$this->_delete($this->table);
}
/**
* 修改ip白名单
* @login true
* @auth true
* @param integer $id
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
*/
public function ipWhite($id = 0)
{
if ($this->app->request->isGet()) {
$this->_applyFormToken();
$this->verify = false;
// $this->pkeylist = OrderService::instance()->getProductKeyList(true);
$this->_form($this->table, 'ipWhite','id', [], ['id' => $id]);
} else {
$id = input('id');
$ip_white = input('ip_white');
$up_ipWhite = MerchantService::instance()->update_ipWhite($id,$ip_white);
if($up_ipWhite == '添加防火墙错误'){
$this->error('添加防火墙ip错误请联系技术何时');
}else{
$this->success('IP白名单修改成功', '');
}
}
}
2024-09-29 15:43:18 +08:00
}