245 lines
7.7 KiB
PHP
245 lines
7.7 KiB
PHP
<?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()
|
|
{
|
|
$params = get_params();
|
|
|
|
// 启动事务
|
|
Db::startTrans();
|
|
try {
|
|
|
|
// 撤销提现,更新状态
|
|
$status = SupplyExtract::where('id', $params['id'])->update(['status' => 3]);
|
|
|
|
// 返回提现金额
|
|
if($status)
|
|
{
|
|
// 申请提现的金额
|
|
$extractInfo = SupplyExtract::where('id', $params['id'])->find();
|
|
$extract_price = $extractInfo['extract_price'];
|
|
$fa_supply_team_id = $extractInfo['fa_supply_team_id'];
|
|
|
|
if($extract_price)
|
|
{
|
|
// 返还提现余额
|
|
SupplyTeam::where('id', $fa_supply_team_id)
|
|
->inc('brokerage', $extract_price)
|
|
->update();
|
|
}
|
|
}
|
|
|
|
// 提交事务
|
|
Db::commit();
|
|
} catch (\Exception $e) {
|
|
|
|
// 回滚事务
|
|
Db::rollback();
|
|
|
|
return to_assign(1, '操作失败,原因:' . $e->getMessage());
|
|
}
|
|
|
|
return to_assign(0, '操作成功');
|
|
}
|
|
|
|
/**
|
|
*
|
|
* 提现账户信息 多提现账户预留
|
|
*
|
|
*/
|
|
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);
|
|
}
|
|
} |