Merge branch 'master' of https://gitea.lihaink.cn/mkm/erp
This commit is contained in:
commit
8c0cd34fa8
95
app/admin/controller/bank/BankController.php
Normal file
95
app/admin/controller/bank/BankController.php
Normal file
@ -0,0 +1,95 @@
|
||||
<?php
|
||||
|
||||
namespace app\admin\controller\bank;
|
||||
|
||||
|
||||
use app\admin\controller\BaseAdminController;
|
||||
use app\admin\lists\bank\BankLists;
|
||||
use app\admin\logic\bank\BankLogic;
|
||||
use app\admin\validate\bank\BankValidate;
|
||||
|
||||
|
||||
/**
|
||||
* Bank控制器
|
||||
* Class BankController
|
||||
* @package app\admin\controller\bank
|
||||
*/
|
||||
class BankController extends BaseAdminController
|
||||
{
|
||||
|
||||
|
||||
/**
|
||||
* @notes 获取列表
|
||||
* @return \think\response\Json
|
||||
* @author likeadmin
|
||||
* @date 2024/05/13 11:09
|
||||
*/
|
||||
public function lists()
|
||||
{
|
||||
return $this->dataLists(new BankLists());
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @notes 添加
|
||||
* @return \think\response\Json
|
||||
* @author likeadmin
|
||||
* @date 2024/05/13 11:09
|
||||
*/
|
||||
public function add()
|
||||
{
|
||||
$params = (new BankValidate())->post()->goCheck('add');
|
||||
$result = BankLogic::add($params);
|
||||
if (true === $result) {
|
||||
return $this->success('添加成功', [], 1, 1);
|
||||
}
|
||||
return $this->fail(BankLogic::getError());
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @notes 编辑
|
||||
* @return \think\response\Json
|
||||
* @author likeadmin
|
||||
* @date 2024/05/13 11:09
|
||||
*/
|
||||
public function edit()
|
||||
{
|
||||
$params = (new BankValidate())->post()->goCheck('edit');
|
||||
$result = BankLogic::edit($params);
|
||||
if (true === $result) {
|
||||
return $this->success('编辑成功', [], 1, 1);
|
||||
}
|
||||
return $this->fail(BankLogic::getError());
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @notes 删除
|
||||
* @return \think\response\Json
|
||||
* @author likeadmin
|
||||
* @date 2024/05/13 11:09
|
||||
*/
|
||||
public function delete()
|
||||
{
|
||||
$params = (new BankValidate())->post()->goCheck('delete');
|
||||
BankLogic::delete($params);
|
||||
return $this->success('删除成功', [], 1, 1);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @notes 获取详情
|
||||
* @return \think\response\Json
|
||||
* @author likeadmin
|
||||
* @date 2024/05/13 11:09
|
||||
*/
|
||||
public function detail()
|
||||
{
|
||||
$params = (new BankValidate())->goCheck('detail');
|
||||
$result = BankLogic::detail($params);
|
||||
return $this->data($result);
|
||||
}
|
||||
|
||||
|
||||
}
|
24
app/admin/controller/merchat/MerchantBankController.php
Normal file
24
app/admin/controller/merchat/MerchantBankController.php
Normal file
@ -0,0 +1,24 @@
|
||||
<?php
|
||||
|
||||
namespace app\admin\controller\merchat;
|
||||
|
||||
use app\admin\controller\BaseAdminController;
|
||||
use app\admin\lists\merchant\MerchantBankLists;
|
||||
use app\admin\logic\merchant\MerchantBankLogic;
|
||||
use app\admin\validate\merchant\MerchantBankValidate;
|
||||
|
||||
class MerchantBankController extends BaseAdminController
|
||||
{
|
||||
public function lists() {
|
||||
return $this->dataLists(new MerchantBankLists());
|
||||
}
|
||||
|
||||
public function check(){
|
||||
$params = (new MerchantBankValidate())->post()->goCheck('check');
|
||||
$result = MerchantBankLogic::check($params,$this->adminId);
|
||||
if (true === $result) {
|
||||
return $this->success('审核成功', [], 1, 1);
|
||||
}
|
||||
return $this->fail(MerchantBankLogic::getError());
|
||||
}
|
||||
}
|
@ -7,6 +7,9 @@ use app\admin\controller\BaseAdminController;
|
||||
use app\admin\lists\merchant\MerchantLists;
|
||||
use app\admin\logic\merchant\MerchantLogic;
|
||||
use app\admin\validate\merchant\MerchantValidate;
|
||||
use app\common\model\goods\Goods;
|
||||
use app\common\model\goods\GoodsLabel;
|
||||
use think\facade\Db;
|
||||
|
||||
|
||||
/**
|
||||
@ -99,4 +102,27 @@ class MerchantController extends BaseAdminController
|
||||
}
|
||||
return $this->fail(MerchantLogic::getError());
|
||||
}
|
||||
|
||||
public function bind_goods_lists(){
|
||||
$mer_id = $this->request->get('mer_id');
|
||||
$page_no = $this->request->get('page_no',1);
|
||||
$page_size = $this->request->get('page_size',15);
|
||||
if(empty($mer_id)){
|
||||
return $this->fail('参数错误');
|
||||
}
|
||||
$data = Db::name('merchant_bind_goods')->where('mer_id',$mer_id)->page($page_no,$page_size)->select()->each(function($item){
|
||||
$item['goods_info'] = Goods::where('id',$item['goods_id'])->with(['className','brandName','unitName','warehouseName'])->findOrEmpty();
|
||||
if(!empty($item['goods_info']['sys_labels'])){
|
||||
$goodslabel = GoodsLabel::where('id','in',trim($item['goods_info']['sys_labels'],','))->column('name');
|
||||
$item['goods_info']['sys_labels_text'] = implode(',',$goodslabel);
|
||||
}else{
|
||||
$item['goods_info']['sys_labels_text'] = '';
|
||||
}
|
||||
return $item;
|
||||
})->toArray();
|
||||
$count = Db::name('merchant_bind_goods')->where('mer_id',$mer_id)->count();
|
||||
return $this->success('请求成功',['lists'=>$data,'count'=>$count,'page_no'=>$page_no,'page_size'=>$page_size]);
|
||||
}
|
||||
|
||||
|
||||
}
|
65
app/admin/lists/bank/BankLists.php
Normal file
65
app/admin/lists/bank/BankLists.php
Normal file
@ -0,0 +1,65 @@
|
||||
<?php
|
||||
|
||||
namespace app\admin\lists\bank;
|
||||
|
||||
|
||||
use app\admin\lists\BaseAdminDataLists;
|
||||
use app\common\lists\ListsSearchInterface;
|
||||
use app\common\model\bank\Bank;
|
||||
|
||||
|
||||
/**
|
||||
* Bank列表
|
||||
* Class BankLists
|
||||
* @package app\admin\listsbank
|
||||
*/
|
||||
class BankLists extends BaseAdminDataLists implements ListsSearchInterface
|
||||
{
|
||||
|
||||
|
||||
/**
|
||||
* @notes 设置搜索条件
|
||||
* @return \string[][]
|
||||
* @author likeadmin
|
||||
* @date 2024/05/13 11:09
|
||||
*/
|
||||
public function setSearch(): array
|
||||
{
|
||||
return [
|
||||
'%like%' => ['name'],
|
||||
];
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @notes 获取列表
|
||||
* @return array
|
||||
* @throws \think\db\exception\DataNotFoundException
|
||||
* @throws \think\db\exception\DbException
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
* @author likeadmin
|
||||
* @date 2024/05/13 11:09
|
||||
*/
|
||||
public function lists(): array
|
||||
{
|
||||
return Bank::where($this->searchWhere)
|
||||
->field(['id', 'name', 'image'])
|
||||
->limit($this->limitOffset, $this->limitLength)
|
||||
->order(['id' => 'desc'])
|
||||
->select()
|
||||
->toArray();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @notes 获取数量
|
||||
* @return int
|
||||
* @author likeadmin
|
||||
* @date 2024/05/13 11:09
|
||||
*/
|
||||
public function count(): int
|
||||
{
|
||||
return Bank::where($this->searchWhere)->count();
|
||||
}
|
||||
|
||||
}
|
75
app/admin/lists/merchant/MerchantBankLists.php
Normal file
75
app/admin/lists/merchant/MerchantBankLists.php
Normal file
@ -0,0 +1,75 @@
|
||||
<?php
|
||||
|
||||
namespace app\admin\lists\merchant;
|
||||
|
||||
|
||||
use app\admin\lists\BaseAdminDataLists;
|
||||
use app\common\lists\ListsSearchInterface;
|
||||
use app\common\model\auth\Admin;
|
||||
use app\common\model\bank\Bank;
|
||||
use app\common\model\merchant\MerchantBank;
|
||||
|
||||
|
||||
/**
|
||||
* MerchantBank列表
|
||||
* Class MerchantBankLists
|
||||
* @package app\admin\listsmerchant
|
||||
*/
|
||||
class MerchantBankLists extends BaseAdminDataLists implements ListsSearchInterface
|
||||
{
|
||||
|
||||
|
||||
/**
|
||||
* @notes 设置搜索条件
|
||||
* @return \string[][]
|
||||
* @author likeadmin
|
||||
* @date 2024/05/13 15:06
|
||||
*/
|
||||
public function setSearch(): array
|
||||
{
|
||||
return [
|
||||
'=' => ['mer_id', 'bank_id', 'is_own', 'is_check'],
|
||||
'%like%' => ['bank_code', 'bank_branch', 'name'],
|
||||
];
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @notes 获取列表
|
||||
* @return array
|
||||
* @throws \think\db\exception\DataNotFoundException
|
||||
* @throws \think\db\exception\DbException
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
* @author likeadmin
|
||||
* @date 2024/05/13 15:06
|
||||
*/
|
||||
public function lists(): array
|
||||
{
|
||||
return MerchantBank::where($this->searchWhere)
|
||||
->field(['id', 'mer_id', 'bank_id', 'bank_code', 'bank_branch', 'name', 'id_card', 'phone', 'financial_img', 'is_own', 'is_check', 'fail_msg', 'admin_id'])
|
||||
->limit($this->limitOffset, $this->limitLength)
|
||||
->order(['id' => 'desc'])
|
||||
->select()->each(function($data){
|
||||
$admin = Admin::field('name')->where('id',$data['admin_id'])->findOrEmpty();
|
||||
$bank = Bank::field('name,image')->where('id',$data['bank_id'])->findOrEmpty();
|
||||
$data['admin_name'] = !$admin->isEmpty() ? $admin['name'] : '';
|
||||
$data['bank_info'] = $bank;
|
||||
$data['is_own_text'] = $data['is_own'] == 0 ? '个人账户' : '对公账户';
|
||||
$data['is_check_text'] = $data->is_check_text;
|
||||
})
|
||||
->toArray();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @notes 获取数量
|
||||
* @return int
|
||||
* @author likeadmin
|
||||
* @date 2024/05/13 15:06
|
||||
*/
|
||||
public function count(): int
|
||||
{
|
||||
return MerchantBank::where($this->searchWhere)->count();
|
||||
}
|
||||
|
||||
}
|
@ -4,6 +4,7 @@ namespace app\admin\lists\operation;
|
||||
|
||||
|
||||
use app\admin\lists\BaseAdminDataLists;
|
||||
use app\common\model\merchant\Merchant;
|
||||
use app\common\model\operation\Opurchaseclass;
|
||||
use app\common\lists\ListsSearchInterface;
|
||||
|
||||
@ -46,7 +47,10 @@ class OpurchaseclassLists extends BaseAdminDataLists implements ListsSearchInter
|
||||
->field(['id', 'merchant', 'order_arr', 'cart_id', 'number', 'total', 'deduction_price', 'actual', 'money', 'paid'])
|
||||
->limit($this->limitOffset, $this->limitLength)
|
||||
->order(['id' => 'desc'])
|
||||
->select()
|
||||
->select()->each(function($data){
|
||||
$merchant = Merchant::field('mer_name')->where('mer_id',$data['merchant'])->findOrEmpty();
|
||||
$data['merchant_name'] = !$merchant->isEmpty() ? $merchant['mer_name'] : '';
|
||||
})
|
||||
->toArray();
|
||||
}
|
||||
|
||||
|
96
app/admin/logic/bank/BankLogic.php
Normal file
96
app/admin/logic/bank/BankLogic.php
Normal file
@ -0,0 +1,96 @@
|
||||
<?php
|
||||
|
||||
namespace app\admin\logic\bank;
|
||||
|
||||
|
||||
use app\common\logic\BaseLogic;
|
||||
use app\common\model\bank\Bank;
|
||||
use think\facade\Db;
|
||||
|
||||
|
||||
/**
|
||||
* Bank逻辑
|
||||
* Class BankLogic
|
||||
* @package app\admin\logic\bank
|
||||
*/
|
||||
class BankLogic extends BaseLogic
|
||||
{
|
||||
|
||||
|
||||
/**
|
||||
* @notes 添加
|
||||
* @param array $params
|
||||
* @return bool
|
||||
* @author likeadmin
|
||||
* @date 2024/05/13 11:09
|
||||
*/
|
||||
public static function add(array $params): bool
|
||||
{
|
||||
Db::startTrans();
|
||||
try {
|
||||
Bank::create([
|
||||
'name' => $params['name'],
|
||||
'image' => $params['image']
|
||||
]);
|
||||
|
||||
Db::commit();
|
||||
return true;
|
||||
} catch (\Exception $e) {
|
||||
Db::rollback();
|
||||
self::setError($e->getMessage());
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @notes 编辑
|
||||
* @param array $params
|
||||
* @return bool
|
||||
* @author likeadmin
|
||||
* @date 2024/05/13 11:09
|
||||
*/
|
||||
public static function edit(array $params): bool
|
||||
{
|
||||
Db::startTrans();
|
||||
try {
|
||||
Bank::where('id', $params['id'])->update([
|
||||
'name' => $params['name'],
|
||||
'image' => $params['image']
|
||||
]);
|
||||
|
||||
Db::commit();
|
||||
return true;
|
||||
} catch (\Exception $e) {
|
||||
Db::rollback();
|
||||
self::setError($e->getMessage());
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @notes 删除
|
||||
* @param array $params
|
||||
* @return bool
|
||||
* @author likeadmin
|
||||
* @date 2024/05/13 11:09
|
||||
*/
|
||||
public static function delete(array $params): bool
|
||||
{
|
||||
return Bank::destroy($params['id']);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @notes 获取详情
|
||||
* @param $params
|
||||
* @return array
|
||||
* @author likeadmin
|
||||
* @date 2024/05/13 11:09
|
||||
*/
|
||||
public static function detail($params): array
|
||||
{
|
||||
return Bank::findOrEmpty($params['id'])->toArray();
|
||||
}
|
||||
}
|
77
app/admin/logic/merchant/MerchantBankLogic.php
Normal file
77
app/admin/logic/merchant/MerchantBankLogic.php
Normal file
@ -0,0 +1,77 @@
|
||||
<?php
|
||||
|
||||
namespace app\admin\logic\merchant;
|
||||
|
||||
|
||||
use app\common\logic\BaseLogic;
|
||||
use app\common\model\auth\Admin;
|
||||
use app\common\model\bank\Bank;
|
||||
use app\common\model\merchant\MerchantBank;
|
||||
use think\facade\Db;
|
||||
|
||||
|
||||
/**
|
||||
* MerchantBank逻辑
|
||||
* Class MerchantBankLogic
|
||||
* @package app\admin\logic\merchant
|
||||
*/
|
||||
class MerchantBankLogic extends BaseLogic
|
||||
{
|
||||
/**
|
||||
* @notes 审核
|
||||
* @param array $params
|
||||
* @return bool
|
||||
* @author likeadmin
|
||||
* @date 2024/05/13 15:06
|
||||
*/
|
||||
public static function check($params,$admin_id){
|
||||
Db::startTrans();
|
||||
try {
|
||||
MerchantBank::where('id',$params['id'])->update([
|
||||
'is_check' => $params['is_check'],
|
||||
'fail_msg' => $params['fail_msg'],
|
||||
'admin_id' => $admin_id,
|
||||
'update_time' => time()
|
||||
]);
|
||||
Db::commit();
|
||||
return true;
|
||||
} catch (\Exception $e) {
|
||||
Db::rollback();
|
||||
self::setError($e->getMessage());
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @notes 删除
|
||||
* @param array $params
|
||||
* @return bool
|
||||
* @author likeadmin
|
||||
* @date 2024/05/13 15:06
|
||||
*/
|
||||
public static function delete(array $params): bool
|
||||
{
|
||||
return MerchantBank::destroy($params['id']);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @notes 获取详情
|
||||
* @param $params
|
||||
* @return array
|
||||
* @author likeadmin
|
||||
* @date 2024/05/13 15:06
|
||||
*/
|
||||
public static function detail($params): array
|
||||
{
|
||||
$data = MerchantBank::findOrEmpty($params['id']);
|
||||
$admin = Admin::field('name')->where('id',$data['admin_id'])->findOrEmpty();
|
||||
$bank = Bank::field('name,image')->where('id',$data['bank_id'])->findOrEmpty();
|
||||
$data['admin_name'] = !$admin->isEmpty() ? $admin['name'] : '';
|
||||
$data['bank_info'] = $bank;
|
||||
$data['is_own_text'] = $data['is_own'] == 0 ? '个人账户' : '对公账户';
|
||||
$data['is_check_text'] = $data->is_check_text;
|
||||
return $data->toArray();
|
||||
}
|
||||
}
|
@ -129,15 +129,19 @@ class MerchantLogic extends BaseLogic
|
||||
{
|
||||
Db::startTrans();
|
||||
try {
|
||||
$data = [];
|
||||
foreach ($params['bind_data'] as $v){
|
||||
$data[] = [
|
||||
$data = [
|
||||
'mer_id' => $params['mer_id'],
|
||||
'goods_id' => $v['goods_id'],
|
||||
'nums' => $v['nums']
|
||||
];
|
||||
$has = Db::name('merchant_bind_goods')->where('mer_id',$params['mer_id'])->where('goods_id',$v['goods_id'])->findOrEmpty();
|
||||
if(!empty($has)){
|
||||
Db::name('merchant_bind_goods')->where('id',$has['id'])->update($data);
|
||||
}else{
|
||||
Db::name('merchant_bind_goods')->insert($data);
|
||||
}
|
||||
}
|
||||
Db::name('merchant_bind_goods')->insertAll($data);
|
||||
Db::commit();
|
||||
return true;
|
||||
} catch (\Exception $e) {
|
||||
|
86
app/admin/validate/bank/BankValidate.php
Normal file
86
app/admin/validate/bank/BankValidate.php
Normal file
@ -0,0 +1,86 @@
|
||||
<?php
|
||||
|
||||
namespace app\admin\validate\bank;
|
||||
|
||||
|
||||
use app\common\validate\BaseValidate;
|
||||
|
||||
|
||||
/**
|
||||
* Bank验证器
|
||||
* Class BankValidate
|
||||
* @package app\admin\validate\bank
|
||||
*/
|
||||
class BankValidate extends BaseValidate
|
||||
{
|
||||
|
||||
/**
|
||||
* 设置校验规则
|
||||
* @var string[]
|
||||
*/
|
||||
protected $rule = [
|
||||
'id' => 'require',
|
||||
'name' => 'require',
|
||||
'image' => 'require',
|
||||
];
|
||||
|
||||
|
||||
/**
|
||||
* 参数描述
|
||||
* @var string[]
|
||||
*/
|
||||
protected $field = [
|
||||
'id' => 'id',
|
||||
'name' => '银行名称',
|
||||
'image' => '银行图片',
|
||||
];
|
||||
|
||||
|
||||
/**
|
||||
* @notes 添加场景
|
||||
* @return BankValidate
|
||||
* @author likeadmin
|
||||
* @date 2024/05/13 11:09
|
||||
*/
|
||||
public function sceneAdd()
|
||||
{
|
||||
return $this->only(['name','image']);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @notes 编辑场景
|
||||
* @return BankValidate
|
||||
* @author likeadmin
|
||||
* @date 2024/05/13 11:09
|
||||
*/
|
||||
public function sceneEdit()
|
||||
{
|
||||
return $this->only(['id','name','image']);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @notes 删除场景
|
||||
* @return BankValidate
|
||||
* @author likeadmin
|
||||
* @date 2024/05/13 11:09
|
||||
*/
|
||||
public function sceneDelete()
|
||||
{
|
||||
return $this->only(['id']);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @notes 详情场景
|
||||
* @return BankValidate
|
||||
* @author likeadmin
|
||||
* @date 2024/05/13 11:09
|
||||
*/
|
||||
public function sceneDetail()
|
||||
{
|
||||
return $this->only(['id']);
|
||||
}
|
||||
|
||||
}
|
75
app/admin/validate/merchant/MerchantBankValidate.php
Normal file
75
app/admin/validate/merchant/MerchantBankValidate.php
Normal file
@ -0,0 +1,75 @@
|
||||
<?php
|
||||
|
||||
namespace app\admin\validate\merchant;
|
||||
|
||||
|
||||
use app\common\validate\BaseValidate;
|
||||
|
||||
|
||||
/**
|
||||
* MerchantBank验证器
|
||||
* Class MerchantBankValidate
|
||||
* @package app\admin\validate\merchant
|
||||
*/
|
||||
class MerchantBankValidate extends BaseValidate
|
||||
{
|
||||
|
||||
/**
|
||||
* 设置校验规则
|
||||
* @var string[]
|
||||
*/
|
||||
protected $rule = [
|
||||
'id' => 'require',
|
||||
'is_check' => 'require|in:1,2',
|
||||
'fail_msg' => 'requireIf:is_check,2'
|
||||
|
||||
];
|
||||
|
||||
|
||||
/**
|
||||
* 参数描述
|
||||
* @var string[]
|
||||
*/
|
||||
protected $field = [
|
||||
'id' => 'id',
|
||||
'is_check' => '审核状态',
|
||||
'fail_msg' => '失败原因'
|
||||
];
|
||||
|
||||
|
||||
/**
|
||||
* @notes 编辑场景
|
||||
* @return MerchantBankValidate
|
||||
* @author likeadmin
|
||||
* @date 2024/05/13 15:06
|
||||
*/
|
||||
public function sceneEdit()
|
||||
{
|
||||
return $this->only(['id','is_check','fail_msg']);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @notes 删除场景
|
||||
* @return MerchantBankValidate
|
||||
* @author likeadmin
|
||||
* @date 2024/05/13 15:06
|
||||
*/
|
||||
public function sceneDelete()
|
||||
{
|
||||
return $this->only(['id']);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @notes 详情场景
|
||||
* @return MerchantBankValidate
|
||||
* @author likeadmin
|
||||
* @date 2024/05/13 15:06
|
||||
*/
|
||||
public function sceneDetail()
|
||||
{
|
||||
return $this->only(['id']);
|
||||
}
|
||||
|
||||
}
|
20
app/api/controller/bank/BankController.php
Normal file
20
app/api/controller/bank/BankController.php
Normal file
@ -0,0 +1,20 @@
|
||||
<?php
|
||||
|
||||
namespace app\api\controller\bank;
|
||||
|
||||
use app\admin\lists\bank\BankLists;
|
||||
use app\api\controller\BaseApiController;
|
||||
|
||||
class BankController extends BaseApiController
|
||||
{
|
||||
/**
|
||||
* @notes 获取列表
|
||||
* @return \think\response\Json
|
||||
* @author likeadmin
|
||||
* @date 2024/05/13 11:09
|
||||
*/
|
||||
public function lists()
|
||||
{
|
||||
return $this->dataLists(new BankLists());
|
||||
}
|
||||
}
|
@ -5,6 +5,10 @@ namespace app\api\controller\merchant;
|
||||
use app\api\lists\merchant\MerchantLists;
|
||||
|
||||
use app\api\controller\BaseApiController;
|
||||
use app\api\validate\MerchantBankValidate;
|
||||
use app\common\service\ThinkApi;
|
||||
use support\Cache;
|
||||
use think\facade\Db;
|
||||
|
||||
|
||||
class MerchantController extends BaseApiController
|
||||
@ -12,4 +16,62 @@ class MerchantController extends BaseApiController
|
||||
public function lists(){
|
||||
return $this->dataLists(new MerchantLists());
|
||||
}
|
||||
|
||||
public function add_bank(){
|
||||
$params = (new MerchantBankValidate())->post()->goCheck('add');
|
||||
$has = Db::name('merchant_bank')->where('is_own',$params['is_own'])->where('is_check','<>',2)->findOrEmpty();
|
||||
if(!empty($has)){
|
||||
return $this->fail('已提交审核请勿重复提交');
|
||||
}
|
||||
$expireAt = strtotime(date('Y-m-d 23:59:59')); // 当天结束时间戳
|
||||
$totalKey = $params['mer_id'].$params['bank_code'];
|
||||
$checkKey = $params['mer_id'].'check';
|
||||
$check = Cache::get($totalKey) ?? 0;
|
||||
if ($check && $check > 9) {
|
||||
return $this->fail('超出绑定限制请明日再绑定');
|
||||
}
|
||||
$wrongNum = Cache::get($checkKey) ?? 0;
|
||||
if($wrongNum && $wrongNum > 2){
|
||||
return $this->fail('当日认证次数已超限制,请勿重复提交,请次日后再试');
|
||||
}
|
||||
Cache::set($totalKey, (int)($check+1),$expireAt);
|
||||
if($params['is_own'] == 0){
|
||||
$info = [
|
||||
'name'=>$params['name'],
|
||||
'idNum'=>$params['id_card'],
|
||||
'cardNo'=>$params['bank_code'],
|
||||
'mobile'=>$params['phone'],
|
||||
];
|
||||
$thinkApi = new ThinkApi();
|
||||
$result = $thinkApi->request('bankcard/auth',$info);
|
||||
if($result['code'] != 0 || empty($result['data'])){
|
||||
return $this->fail($result['message']);
|
||||
}
|
||||
//认证结果。01:一致 02:不一致 03:认证不确定 04:认证失败。01、02收费
|
||||
if($result['data']['result'] == 4 || $result['data']['result'] == 2){
|
||||
Cache::set($checkKey, (int)($wrongNum+1),$expireAt);
|
||||
}
|
||||
if($result['data']['result'] == 4 || $result['data']['result'] == 2){
|
||||
$wrongNum = Cache::get($checkKey);
|
||||
$numMsg = ',当日剩余认证次数'.(3-$wrongNum);
|
||||
return $this->fail('认证失败,请检查姓名,身份证,银行卡,银行预留手机号码是否正确'.$numMsg);
|
||||
}
|
||||
}
|
||||
$save_data = [
|
||||
'mer_id' => $params['mer_id'],
|
||||
'name' => $params['name'],
|
||||
'bank_id' => $params['bank_id'],
|
||||
'bank_code' => $params['bank_code'],
|
||||
'bank_branch' => $params['bank_branch'],
|
||||
'phone' => $params['phone'] ?? '',
|
||||
'id_card' => $params['id_card'] ?? '',
|
||||
'financial_img' => $params['financial_img'] ?? '',
|
||||
'is_own' => $params['is_own'],
|
||||
'is_check' => 0,
|
||||
'create_time' => time()
|
||||
];
|
||||
//写入数据
|
||||
$res = Db::name('merchant_bank')->insert($save_data);
|
||||
return $res ? $this->success('添加成功') : $this->fail('添加失败');
|
||||
}
|
||||
}
|
43
app/api/validate/MerchantBankValidate.php
Normal file
43
app/api/validate/MerchantBankValidate.php
Normal file
@ -0,0 +1,43 @@
|
||||
<?php
|
||||
|
||||
namespace app\api\validate;
|
||||
|
||||
use app\common\validate\BaseValidate;
|
||||
use think\facade\Db;
|
||||
|
||||
class MerchantBankValidate extends BaseValidate
|
||||
{
|
||||
protected $rule = [
|
||||
'is_own|账号类型' => 'require|in:0,1',
|
||||
'mer_id|商户id' => 'require|checkMerchant',
|
||||
'name|姓名' => 'require',
|
||||
'bank_id|开户银行' => 'require|checkBank',
|
||||
'bank_code|银行账号' => 'require|integer',
|
||||
'bank_branch|开户网点' => 'require|max:32',
|
||||
'id_card|身份证' => 'requireIf:is_own,0|idCard',
|
||||
'phone|手机号' => 'requireIf:is_own,0|mobile',
|
||||
// 'financial_img|相关凭证' => 'require'
|
||||
];
|
||||
|
||||
|
||||
public function sceneAdd()
|
||||
{
|
||||
return $this->only(['mer_id','is_own','bank_id','name','bank_code','bank_branch','id_card','phone','financial_img']);
|
||||
}
|
||||
|
||||
public function checkBank($value){
|
||||
$data = Db::name('bank')->where('id',$value)->findOrEmpty();
|
||||
if(empty($data)){
|
||||
return '开户银行不存在';
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public function checkMerchant($value){
|
||||
$data = Db::name('merchant')->where('mer_id',$value)->findOrEmpty();
|
||||
if(empty($data)){
|
||||
return '商户不存在';
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
22
app/common/model/bank/Bank.php
Normal file
22
app/common/model/bank/Bank.php
Normal file
@ -0,0 +1,22 @@
|
||||
<?php
|
||||
|
||||
namespace app\common\model\bank;
|
||||
|
||||
|
||||
use app\common\model\BaseModel;
|
||||
use think\model\concern\SoftDelete;
|
||||
|
||||
|
||||
/**
|
||||
* Bank模型
|
||||
* Class Bank
|
||||
* @package app\common\model\bank
|
||||
*/
|
||||
class Bank extends BaseModel
|
||||
{
|
||||
use SoftDelete;
|
||||
protected $name = 'bank';
|
||||
protected $deleteTime = 'delete_time';
|
||||
|
||||
|
||||
}
|
25
app/common/model/merchant/MerchantBank.php
Normal file
25
app/common/model/merchant/MerchantBank.php
Normal file
@ -0,0 +1,25 @@
|
||||
<?php
|
||||
|
||||
namespace app\common\model\merchant;
|
||||
|
||||
|
||||
use app\common\model\BaseModel;
|
||||
use think\model\concern\SoftDelete;
|
||||
|
||||
|
||||
/**
|
||||
* MerchantBank模型
|
||||
* Class MerchantBank
|
||||
* @package app\common\model\merchant
|
||||
*/
|
||||
class MerchantBank extends BaseModel
|
||||
{
|
||||
use SoftDelete;
|
||||
protected $name = 'merchant_bank';
|
||||
protected $deleteTime = 'delete_time';
|
||||
|
||||
public function getIsCheckTextAttr($value,$data){
|
||||
$arr = [0=>'待审核', 1=>'审核通过', 2=>'审核未通过'];
|
||||
return $arr[$data['is_check']];
|
||||
}
|
||||
}
|
329
app/common/service/Curl.php
Normal file
329
app/common/service/Curl.php
Normal file
@ -0,0 +1,329 @@
|
||||
<?php
|
||||
|
||||
namespace app\common\service;
|
||||
|
||||
class Curl
|
||||
{
|
||||
// Default options from config.php
|
||||
public $options = array();
|
||||
|
||||
// request specific options - valid only for single request
|
||||
public $request_options = array();
|
||||
|
||||
|
||||
private $header;
|
||||
private $headerMap;
|
||||
private $error;
|
||||
private $status;
|
||||
private $info;
|
||||
|
||||
// default config
|
||||
private $config = array(
|
||||
CURLOPT_RETURNTRANSFER => true,
|
||||
CURLOPT_FOLLOWLOCATION => true,
|
||||
CURLOPT_HEADER => false,
|
||||
CURLOPT_VERBOSE => true,
|
||||
CURLOPT_AUTOREFERER => true,
|
||||
CURLOPT_CONNECTTIMEOUT => 30,
|
||||
CURLOPT_TIMEOUT => 30,
|
||||
CURLOPT_SSL_VERIFYPEER => false,
|
||||
CURLOPT_SSL_VERIFYHOST => false,
|
||||
CURLOPT_USERAGENT => 'Mozilla/5.0 (compatible; Googlebot/2.1; +http://www.google.com/bot.html)'
|
||||
);
|
||||
|
||||
public static function mergeArray()
|
||||
{
|
||||
$args = func_get_args();
|
||||
$res = array_shift($args);
|
||||
while (!empty($args)) {
|
||||
$next = array_shift($args);
|
||||
foreach ($next as $k => $v) {
|
||||
if (is_array($v) && isset($res[$k]) && is_array($res[$k])) {
|
||||
$res[$k] = self::mergeArray($res[$k], $v);
|
||||
} elseif (is_numeric($k)) {
|
||||
isset($res[$k]) ? $res[] = $v : $res[$k] = $v;
|
||||
} else {
|
||||
$res[$k] = $v;
|
||||
}
|
||||
}
|
||||
}
|
||||
return $res;
|
||||
}
|
||||
|
||||
public function getOptions()
|
||||
{
|
||||
$options = self::mergeArray($this->request_options, $this->options, $this->config);
|
||||
return $options;
|
||||
}
|
||||
|
||||
public function setOption($key, $value, $default = false)
|
||||
{
|
||||
if ($default) {
|
||||
$this->options[$key] = $value;
|
||||
} else {
|
||||
$this->request_options[$key] = $value;
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Clears Options
|
||||
* This will clear only the request specific options. Default options cannot be cleared.
|
||||
*/
|
||||
|
||||
public function resetOptions()
|
||||
{
|
||||
$this->request_options = array();
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Resets the Option to Default option
|
||||
* @param $key
|
||||
* @return $this
|
||||
*/
|
||||
public function resetOption($key)
|
||||
{
|
||||
if (isset($this->request_options[$key])) {
|
||||
unset($this->request_options[$key]);
|
||||
}
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function setOptions($options, $default = false)
|
||||
{
|
||||
if ($default) {
|
||||
$this->options = $options + $this->request_options;
|
||||
} else {
|
||||
$this->request_options = $options + $this->request_options;
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function buildUrl($url, $data = array())
|
||||
{
|
||||
$parsed = parse_url($url);
|
||||
|
||||
isset($parsed['query']) ? parse_str($parsed['query'], $parsed['query']) : $parsed['query'] = array();
|
||||
|
||||
$params = isset($parsed['query']) ? $data + $parsed['query'] : $data;
|
||||
$parsed['query'] = ($params) ? '?' . http_build_query($params) : '';
|
||||
if (!isset($parsed['path'])) {
|
||||
$parsed['path']='/';
|
||||
}
|
||||
|
||||
$parsed['port'] = isset($parsed['port'])?':'.$parsed['port']:'';
|
||||
return $parsed['scheme'].'://'.$parsed['host'].$parsed['port'].$parsed['path'].$parsed['query'];
|
||||
}
|
||||
|
||||
public function exec($url, $options, $debug = false)
|
||||
{
|
||||
$this->error = null;
|
||||
$this->header = null;
|
||||
$this->headerMap = null;
|
||||
$this->info = null;
|
||||
$this->status = null;
|
||||
|
||||
$ch = curl_init($url);
|
||||
curl_setopt_array($ch, $options);
|
||||
|
||||
$output = curl_exec($ch);
|
||||
|
||||
$this->status = curl_getinfo($ch, CURLINFO_HTTP_CODE);
|
||||
|
||||
if (!$output) {
|
||||
$this->error = curl_error($ch);
|
||||
$this->info = curl_getinfo($ch);
|
||||
} elseif ($debug) {
|
||||
$this->info = curl_getinfo($ch);
|
||||
}
|
||||
|
||||
if (@$options[CURLOPT_HEADER] == true) {
|
||||
list($header, $output) = $this->processHeader($output, curl_getinfo($ch, CURLINFO_HEADER_SIZE));
|
||||
$this->header = $header;
|
||||
}
|
||||
curl_close($ch);
|
||||
|
||||
return $output;
|
||||
}
|
||||
|
||||
public function processHeader($response, $header_size)
|
||||
{
|
||||
return array(substr($response, 0, $header_size), substr($response, $header_size));
|
||||
}
|
||||
|
||||
public function get($url, $params = array(), $debug = false)
|
||||
{
|
||||
$exec_url = $this->buildUrl($url, $params);
|
||||
$options = $this->getOptions();
|
||||
return $this->exec($exec_url, $options, $debug);
|
||||
}
|
||||
|
||||
public function post($url, $data, $params = array(), $debug = false, $flag = false)
|
||||
{
|
||||
$url = $this->buildUrl($url, $params);
|
||||
// if ($flag) {
|
||||
// $this->setOption(CURLOPT_HTTPHEADER, Yii::app()->params['host']);
|
||||
// }
|
||||
$options = $this->getOptions();
|
||||
$options[CURLOPT_POST] = true;
|
||||
$options[CURLOPT_POSTFIELDS] = $data;
|
||||
|
||||
return $this->exec($url, $options, $debug);
|
||||
}
|
||||
|
||||
public function postJson($url, $data, $params = array(), $debug = false, $flag = false)
|
||||
{
|
||||
$url = $this->buildUrl($url, $params);
|
||||
// if ($flag) {
|
||||
// $this->setOption(CURLOPT_HTTPHEADER, Yii::app()->params['host']);
|
||||
// }
|
||||
$options = $this->getOptions();
|
||||
$options[CURLOPT_POST] = true;
|
||||
$options[CURLOPT_POSTFIELDS] = $data;
|
||||
$options[CURLOPT_HEADER] = 0;
|
||||
$options[CURLOPT_HTTPHEADER] =
|
||||
array('Content-Type: application/json; charset=utf-8', 'Content-Length:' . strlen($data));
|
||||
|
||||
return $this->exec($url, $options, $debug);
|
||||
}
|
||||
|
||||
public function put($url, $data = null, $params = array(), $debug = false)
|
||||
{
|
||||
$url = $this->buildUrl($url, $params);
|
||||
|
||||
$f = fopen('php://temp', 'rw+');
|
||||
fwrite($f, $data);
|
||||
rewind($f);
|
||||
|
||||
$options = $this->getOptions();
|
||||
$options[CURLOPT_PUT] = true;
|
||||
$options[CURLOPT_INFILE] = $f;
|
||||
$options[CURLOPT_INFILESIZE] = strlen($data);
|
||||
|
||||
return $this->exec($url, $options, $debug);
|
||||
}
|
||||
|
||||
public function patch($url, $data = array(), $params = array(), $debug = false)
|
||||
{
|
||||
$url = $this->buildUrl($url, $params);
|
||||
|
||||
$options = $this->getOptions();
|
||||
$options[CURLOPT_CUSTOMREQUEST] = 'PATCH';
|
||||
$options[CURLOPT_POSTFIELDS] = $data;
|
||||
|
||||
return $this->exec($url, $options, $debug);
|
||||
}
|
||||
|
||||
public function delete($url, $params = array(), $debug = false)
|
||||
{
|
||||
$url = $this->buildUrl($url, $params);
|
||||
|
||||
$options = $this->getOptions();
|
||||
$options[CURLOPT_CUSTOMREQUEST] = 'DELETE';
|
||||
|
||||
return $this->exec($url, $options, $debug);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets header of the last curl call if header was enabled
|
||||
*/
|
||||
public function getHeaders()
|
||||
{
|
||||
if (!$this->header) {
|
||||
return array();
|
||||
}
|
||||
|
||||
if (!$this->headerMap) {
|
||||
$headers = explode("\r\n", trim($this->header));
|
||||
$output = array();
|
||||
$output['http_status'] = array_shift($headers);
|
||||
|
||||
foreach ($headers as $line) {
|
||||
$params = explode(':', $line, 2);
|
||||
|
||||
if (!isset($params[1])) {
|
||||
$output['http_status'] = $params[0];
|
||||
} else {
|
||||
$output[trim($params[0])] = trim($params[1]);
|
||||
}
|
||||
}
|
||||
|
||||
$this->headerMap = $output;
|
||||
}
|
||||
return $this->headerMap;
|
||||
}
|
||||
|
||||
public function addHeader($header = array())
|
||||
{
|
||||
$h = isset($this->request_options[CURLOPT_HTTPHEADER]) ? $this->request_options[CURLOPT_HTTPHEADER] : array();
|
||||
foreach ($header as $k => $v) {
|
||||
$h[] = $k . ': ' . $v;
|
||||
}
|
||||
|
||||
$this->setHeaders($h);
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getHeader($key)
|
||||
{
|
||||
$headers = array_change_key_case($this->getHeaders(), CASE_LOWER);
|
||||
$key = strtolower($key);
|
||||
|
||||
return @$headers[$key];
|
||||
}
|
||||
|
||||
public function setHeaders($header = array(), $default = false)
|
||||
{
|
||||
if ($this->isAssoc($header)) {
|
||||
$out = array();
|
||||
foreach ($header as $k => $v) {
|
||||
$out[] = $k .': '.$v;
|
||||
}
|
||||
$header = $out;
|
||||
}
|
||||
|
||||
$this->setOption(CURLOPT_HTTPHEADER, $header, $default);
|
||||
return $this;
|
||||
}
|
||||
|
||||
private function isAssoc($arr)
|
||||
{
|
||||
return array_keys($arr) !== range(0, count($arr) - 1);
|
||||
}
|
||||
|
||||
public function getError()
|
||||
{
|
||||
return $this->error;
|
||||
}
|
||||
|
||||
public function getInfo()
|
||||
{
|
||||
return $this->info;
|
||||
}
|
||||
|
||||
public function getStatus()
|
||||
{
|
||||
return $this->status;
|
||||
}
|
||||
|
||||
public function init()
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
public function download($fileUrl, $localFileName)
|
||||
{
|
||||
$ch = curl_init($fileUrl);
|
||||
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
|
||||
$result = curl_exec($ch);
|
||||
curl_close($ch);
|
||||
$fp = fopen($localFileName, 'a');
|
||||
fwrite($fp, $result);
|
||||
fclose($fp);
|
||||
|
||||
return $localFileName;
|
||||
}
|
||||
}
|
17
app/common/service/ThinkApi.php
Normal file
17
app/common/service/ThinkApi.php
Normal file
@ -0,0 +1,17 @@
|
||||
<?php
|
||||
|
||||
namespace app\common\service;
|
||||
|
||||
class ThinkApi
|
||||
{
|
||||
private $domain = 'https://api.topthink.com/';
|
||||
private $appCode = 'b1eb52b9-0379-4c56-b795-47d90a73ca6a';
|
||||
|
||||
public function request($route, $param = [], $method = 'get')
|
||||
{
|
||||
$curl = new Curl();
|
||||
$param['appCode'] = $this->appCode;
|
||||
$data = $curl->$method($this->domain . $route, $param);
|
||||
return json_decode($data, true);
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user