完善后台供应链小组提现业务逻辑

This commit is contained in:
monanxiao 2023-03-20 18:00:08 +08:00
parent a5132285c7
commit ace97330b3
5 changed files with 551 additions and 2 deletions

View File

@ -0,0 +1,209 @@
<?php
/**
* @copyright Copyright (c) 2021 勾股工作室
* @license https://opensource.org/licenses/Apache-2.0
* @link https://www.gougucms.com
*/
namespace app\admin\controller\supplychain;
use app\admin\BaseController;
use think\facade\Db;
use think\facade\View;
use app\admin\model\Merchant; // 商户模型
use app\admin\model\GeoCity; // 省市模型
use app\admin\model\GeoArea; // 区域模型
use app\admin\model\GeoStreet; // 街道模型
use app\admin\model\SupplyChain; // 供应链模型
use app\api\model\Area as AreaModel; // 市场区域模型
use app\api\model\AreaManager as AreaManagerModel; // 区域负责人模型
use app\common\model\SupplyExtract; // 供应链小组服务提现模型
use app\admin\model\SupplyAccount as SupplyAccountModel;
use app\admin\model\SupplyTeam;
// 供应链提现记录
class Extract extends BaseController
{
public function __construct()
{
$this->adminInfo = get_login_admin();
$this->category_id = 354;
$this->url=[
'/admin/supplychain.extract/index?category_id='.$this->category_id,
'/admin/supplychain.extract/add',
'/admin/supplychain.extract/cancel',
'/admin/supplychain.extract/accountInfo',
];
}
/**
*
* 数据列表
*
*/
public function index()
{
if (request()->isAjax())
{
$params= get_params();
$where[]= ['status','=',0];
if (isset($params['keywords']) && !empty($params['keywords'])){
$where[]= ['name','like','%'.$params['keywords'].'%'];
}
if($this->adminInfo['position_id'] != 1){ //不是超级管理员
$www['admin_id'] = $this->adminInfo['id'];
$user_address = Db::table('fa_szxc_information_useraddress')->where($www)->find();
if ($user_address){
if($user_address['auth_range'] == 1){
$where[] = ['village_id','=',$user_address['village_id']];
}elseif ($user_address['auth_range'] == 2){
$where[] = ['street_id','=',$user_address['street_id']];
}elseif ($user_address['auth_range'] == 3){
$where[] = ['area_id','=',$user_address['area_id']];
}else{
$where[] = ['village_id','=',$user_address['village_id']];
}
}else{
$where[] = ['village_id','=',''];
}
}
$total = SupplyExtract::where($where)->count();
$list = SupplyExtract::with(['user', 'adminUser'])->order('id desc')->select();
$result = ['total' => $total, 'data' => $list];
return table_assign(0, '', $result);
}else{
$list = SupplyExtract::with(['user', 'adminUser'])->select();
View::assign('list', $list);
View::assign('teamId', 12);
View::assign('url', $this->url);
return view();
}
}
/**
*
* 申请提现
*
*/
public function add()
{
$params = get_params();
if (request()->isAjax())
{
// 取出供应链小组信息
$team = SupplyTeam::find($params['teamId']);
// 取出账号信息
$accountInfo = SupplyAccountModel::where('fa_supply_team_id', $params['teamId'])->find();
// 验证金额
if($team['brokerage'] < $params['extract_price'])
{
return to_assign(1, '操作失败,可提现余额不足');
}
// 开启事务,处理提现
Db::startTrans();
try {
// 1、减去余额
SupplyTeam::where('id', $params['teamId'])
->dec('brokerage', $params['extract_price'])
->update();
// 2、写入提现记录
$data = [
'uid' => $this->adminInfo['id'],
'extract_sn' => $this->build_order_no(), // 流水号
'real_name' => $accountInfo['name'], // 姓名
'extract_type' => 0, // 提现类型,目前只支持银行卡,默认 0
'bank_code' => $accountInfo['account'], // 银行卡号
'bank_address' => $accountInfo['bank'], // 开户地址
// 'alipay_code' => ,
// 'wechat' => ,
// 'extract_pic' => ,
'extract_price' => $params['extract_price'], // 提现金额
'balance' => $team['brokerage'],
'mark' => '当前金额:' . $team['brokerage'] . ',申请提现金额:' . $params['extract_price'],
'create_time' => date('Y-m-d H:i:s'), // 申请时间
'bank_name' => $accountInfo['bank'], // 银行名称
'source' => 1, // 提现来源 1 供应链服务商团队
'fa_supply_team_id' => $accountInfo['fa_supply_team_id'], // 提现团队ID
];
// 写入提现记录
$status = SupplyExtract::create($data);
// 提交事务
Db::commit();
} catch (\Exception $e) {
// 回滚事务
Db::rollback();
return to_assign(1, '操作失败,原因:' . $e->getMessage());
}
return to_assign(0, '操作成功');
}else{
// 取出账号信息
$accountInfo = SupplyAccountModel::where('fa_supply_team_id', $params['teamId'])->find();
$team = SupplyTeam::find($params['teamId']);
if(!$accountInfo) // 验证是否有提现账户
{
return redirect('/admin/supply_account/add');
}
View::assign('teamId', $params['teamId']);
View::assign('team', $team);
View::assign('accountInfo', $accountInfo);
View::assign('url', $this->url);
View::assign('mer_id', 123);
return view();
}
}
/**
*
* 撤回提现
*
*/
public function cancel()
{
}
/**
*
* 提现账户信息 多提现账户预留
*
*/
public function accountInfo()
{
$params = get_params();
$teamId = $params['teamId'];
return json($accountInfo);
}
public function build_order_no() {
return date('Ymd').substr(implode(NULL, array_map('ord', str_split(substr(uniqid(), 7, 13), 1))), 0, 8);
}
}

View File

@ -2,7 +2,7 @@
<!-- 主体 -->
{block name="body"}
<form class="layui-form p-4">
<h3 class="pb-3">新建供应链团队角色提现账户信息</h3>
<h3 class="pb-3">新建提现账户信息</h3>
<table class="layui-table layui-table-form">
<tr><td class="layui-td-gray-2">账号<font>*</font></td>
<td><input type="text" name="account" lay-verify="required" lay-reqText="请完善账号" value="" autocomplete="off" placeholder="请输入账号" class="layui-input"></td><td class="layui-td-gray-2">用户名<font>*</font></td>

View File

@ -0,0 +1,101 @@
{extend name="common/base"/}
{block name="style"}
<style type="text/css">
.editormd-code-toolbar select {
display: inline-block
}
.editormd li {
list-style: inherit;
}
.layui-td-gray {
width: 110px;
}
.addrhelper-ok-btn {
display: none;
}
</style>
{/block}
<!-- 主体 -->
{block name="body"}
<form class="layui-form p-4">
<h3 class="pb-3">关联商户</h3>
<table class="layui-table layui-table-form">
<tr>
<td colspan="4">
<div class="layui-col-md4">
<label class="layui-form-label">提现信息<font>*</font></label>
<div class="layui-input-block">
账户名:{$accountInfo.name} <br>
账号:{$accountInfo.account}<br>
开户行地址:{$accountInfo.bank}<br>
可提现金额:{$team.brokerage}<br>
冻结金额:{$team.free_brokerage}<br>
已提现金额:{$team.withdraw_brokerage}
</div>
</div>
</td>
</tr>
<tr>
<td colspan="4">
<div class="layui-col-md4">
<label class="layui-form-label">提现金额<font>*</font></label>
<div class="layui-input-block">
<input type="hidden" name="teamId" value="{$teamId}">
<input type="number" name="extract_price" min="0.01" max="{$team.brokerage}" required lay-verify="required" placeholder="请输入提现金额" autocomplete="off" class="layui-input">
</div>
</div>
</td>
</tr>
</table>
<div class="pt-3">
<button class="layui-btn layui-btn-normal" lay-submit="" lay-filter="webform">立即提交</button>
<button type="reset" class="layui-btn layui-btn-primary">重置</button>
</div>
</form>
{/block}
<!-- /主体 -->
<!-- 脚本 -->
{block name="script"}
<script src="/static/assets/js/xm-select.js"></script>
<script>
var moduleInit = ['tool','tinymce'];
function gouguInit() {
var form = layui.form, tool = layui.tool;
form.on('select(merchantAddress)', function (data) {
street(data.value);
});
//监听提交
form.on('submit(webform)', function (data) {
let callback = function (e) {
console.log(e);
layer.msg(e.msg);
if (e.code == 0) {
tool.tabRefresh(71);
tool.sideClose(1000);
}
}
tool.post('{$url[1]}', data.field, callback);
return false;
});
var group_access = "{:session('gougu_admin')['group_access']}";
}
</script>
{/block}
<!-- /脚本 -->

View File

@ -0,0 +1,219 @@
{extend name="common/base"/}
<!-- 主体 -->
{block name="body"}
<div class="p-3">
<form class="layui-form gg-form-bar border-t border-x">
<div class="layui-input-inline" style="width:300px;">
<input type="text" name="keywords" placeholder="请输入供应链名称" class="layui-input" autocomplete="off" />
</div>
<button class="layui-btn layui-btn-normal" lay-submit="" lay-filter="searchform">搜索</button>
</form>
<table class="layui-hide" id="article" lay-filter="article"></table>
</div>
<script type="text/html" id="status">
<i class="layui-icon {{# if(d.status == 1){ }}layui-icon-ok{{# } else { }}layui-icon-close{{# } }}"></i>
</script>
<script type="text/html" id="is_home">
<i class="layui-icon {{# if(d.is_home == 1){ }}layui-icon-ok{{# } else { }}layui-icon-close{{# } }}"></i>
</script>
<script type="text/html" id="thumb">
</script>
<script type="text/html" id="toolbarDemo">
<div class="layui-btn-container">
{if {:auth_cache(session('gougu_admin')['id'],$url[1])}==true}
<span class="layui-btn layui-btn-sm" lay-event="add" data-title="添加">+ 添加</span>
{/if}
</div>
</script>
<script type="text/html" id="barDemo">
<div class="layui-btn-group">
{if {:auth_cache(session('gougu_admin')['id'],$url[2])}==true}
<a class="layui-btn layui-btn-xs" lay-event="edit">撤销</a>
{/if}
</div>
</script>
{/block}
<!-- /主体 -->
<!-- 脚本 -->
{block name="script"}
<script>
const moduleInit = ['tool'];
function gouguInit() {
var table = layui.table,tool = layui.tool, form = layui.form;
layui.pageTable = table.render({
elem: '#article',
title: '列表',
toolbar: '#toolbarDemo',
url: '{$url[0]}',
page: true,
limit: 20,
cols: [
[
{
fixed: 'left',
field: 'extract_sn',
title: '编号',
align: 'center',
width:180,
},{
field: 'real_name',
title: '用户信息',
align: 'center',
width:120,
},{
field: 'bank_code',
title: '账号',
align: 'center',
width:150,
},{
field: 'uid',
title: '用户UID',
align: 'center',
width:120,
templet: function (d)
{
if(d.user)
{
return d.user;
}
return '数据错误';
}
},{
field: 'real_name',
title: '户名',
align: 'center',
width:120,
},{
field: 'extract_price',
title: '提现金额',
align: 'center',
width:150,
},{
field: 'balance',
title: '当前余额',
align: 'center',
width:150,
},{
field: 'extract_type',
title: '提现方式',
align: 'center',
width:150,
templet: function (d)
{
switch (d.extract_type) {
case 0:
return '银行卡';
break;
case 1:
return '支付宝';
break;
case 2:
return '微信';
break;
case 3:
return '零钱';
break;
}
}
},{
field: 'mark',
title: '银行名称',
align: 'center',
width:150,
},{
field: 'status',
title: '审核状态',
align: 'center',
width:150,
templet: function (d)
{
switch (d.status) {
case 0:
return '审核中';
break;
case -1:
return '未通过';
break;
case 1:
return '提现完成';
break;
}
}
},{
field: 'adminUser',
title: '审核用户',
align: 'center',
width:120,
templet: function (d)
{
if(d.adminUser)
{
return d.adminUser;
}
return '数据错误';
}
},{
field: 'fail_msg',
title: '拒绝原因',
align: 'center',
width:150,
},{
field: 'create_time',
title: '添加时间',
align: 'center',
width:150,
},{
fixed: 'right',
field: 'right',
title: '操作',
toolbar: '#barDemo',
align: 'center'
}
]
]
});
//监听表头工具栏事件
table.on('toolbar(article)', function(obj){
if (obj.event === 'add') {
tool.side('{$url[1]}?teamId={$teamId}');
return false;
}
});
//监听表格行工具事件
table.on('tool(article)', function(obj) {
var data = obj.data;
if (obj.event === 'edit') {
tool.side('{$url[2]}?id='+obj.data.id);
}
return false;
});
//监听搜索提交
form.on('submit(searchform)', function(data) {
layui.pageTable.reload({
where: {
keywords: data.field.keywords,
cate_id: data.field.cate_id
},
page: {
curr: 1
}
});
return false;
});
}
</script>
{/block}
<!-- /脚本 -->

View File

@ -4,7 +4,8 @@
* @license https://opensource.org/licenses/Apache-2.0
* @link https://www.gougucms.com
*/
namespace app\admin\model;
namespace app\common\model;
use think\model;
use app\common\model\User;
use app\admin\model\ShopUser;
@ -19,4 +20,23 @@ class SupplyExtract extends Model
// 设置当前模型对应的完整数据表名称
protected $table = 'supply_extract';
/**
*
* 关联用户信息
*
*/
public function user()
{
return $this->hasOne(ShopUser::class, 'uid', 'uid');
}
/***
*
* 关联审核信息
*
*/
public function adminUser()
{
return $this->hasOne(ShopUser::class, 'uid', 'admin_id');
}
}