Commit 6145f0de authored by wangzhengwen's avatar wangzhengwen

个人中心完善 提现

parent bb0dd94a
......@@ -2,9 +2,83 @@
namespace app\api\controller\mine;
use app\api\middleware\Auth;
use app\api\validate\CertValidate;
use app\BaseController;
use app\model\CertOrder;
use app\model\system\SystemUploadFile;
use think\Request;
class Cert extends BaseController
{
protected $middleware = [
Auth::class,
];
public function getCertList(Request $request)
{
$page = $request->param('page/d', 1);
$pageSize = $request->param('pageSize/d', 10);
$data = $request->param();
$where = ['co.user_id' => $request->userId];
if (!empty($data['status']) || $data['status'] == 0) {
$where['co.status'] = (int)$data['status'];
}
$query = CertOrder::where($where)
->alias('co')
->join('cert c', 'c.id = co.cert_id')
->field([
'co.*',
'c.title',
'c.fzjg',
'c.id as cert_id',
'c.price',
'c.sn'
]);
if (!empty($data['search_str'])) {
$searchStr = trim($data['search_str']);
$query->where(function($q) use ($searchStr) {
$q->where('c.title|c.sn', 'like', "%{$searchStr}%");
});
}
$list = $query->paginate([
'page' => $page,
'list_rows' => $pageSize
]);
return $this->returnMsg('success',1,$list);
}
public function getCertDetail(Request $request)
{
$vo = (new CertValidate())->goCheck(['cert_order_id']);
if ($vo !== true) {
return $vo;
}
$data = $request->param();
$item = CertOrder::where(['id'=>$data['cert_order_id'],'user_id'=>$request->userId])
->with(['cert','headImg','idcardQ','idcardH'])
->find();
if ($item)
{
$item['otherFiles'] = SystemUploadFile::whereIn('fileid',$item->other_file_id)
->where('isdel',0)
->field('fileid,filename,filesize,fileurl,filetype')
->select();
}
return $this->returnMsg('success',1,$item);
}
}
\ No newline at end of file
......@@ -56,8 +56,8 @@ class Project extends BaseController
$where = ['pp.user_id' => $request->userId];
if (!empty($data['status'])) {
$where['pp.status'] = $data['status'];
if (!empty($data['status']) || $data['status'] == 0) {
$where['pp.status'] = (int)$data['status'];
}
if (!empty($data['complete_status'])) {
......
......@@ -7,7 +7,9 @@ use app\api\service\UserService;
use app\api\validate\UserValidate;
use app\BaseController;
use app\model\project\UserAccount;
use app\model\project\UserMoneyLog;
use app\model\project\UserSmrz;
use app\model\project\UserWithdrawal;
use app\Request;
use app\model\project\User as UserModel;
......@@ -112,5 +114,55 @@ class User extends BaseController
}
public function withdrawal(Request $request)
{
$vo = (new UserValidate())->goCheck(['amount','txType']);
if ($vo !== true) {
return $vo;
}
$data = $request->param();
$userId = $request->userId;
$userInfo = UserModel::where(['id'=>$userId,'is_del'=>0])->find();
if ($userInfo['money']< $data['amount'])
{
return $this->returnMsg('余额不足');
}
$count = UserMoneyLog::where(['user_id'=>$userId,'type'=>1])
->whereBetween('createtime', [strtotime('today'), strtotime('tomorrow') - 1])
->count();
if ($count)
{
// return $this->returnMsg('每天只能提现一次');
}
$sum = UserMoneyLog::where(['user_id'=>$userId,'type'=>1])
->whereBetween('createtime', [strtotime('today'), strtotime('tomorrow') - 1])
->sum('money');
if ($sum > 10000)
{
return $this->returnMsg('超出每日限额');
}
$userAccount = UserAccount::where(['user_id'=>$userId,'is_del'=>0,'type'=>$data['txType']])->find();
$UserWithdrawalModel = new UserWithdrawal();
$commission = vconfig('commission') ? : 0;
halt($commission);
$res = $UserWithdrawalModel->applyWithdrawal($userId,$data['amount'],$data['txType'],$userAccount['account'],$userInfo['realname'],$commission,$userInfo['money']);
if (!$res['status'])
{
return $this->returnMsg('网络错误');
}
return $this->returnMsg('success',1);
}
}
\ No newline at end of file
......@@ -18,6 +18,7 @@ class CertValidate extends BaseValidate
'head_img_id' => 'require|number',
'other_file_id' => 'require|number',
'pay_type'=>'require|number',
'cert_order_id'=>'require|number',
];
......
......@@ -21,6 +21,8 @@ class UserValidate extends BaseValidate
'idcard'=>'require',
'idcard_q'=>'require',
'idcard_h'=>'require',
'amount'=>'require|chenckAmount',
'txType'=>'require',
];
protected $message = [
......@@ -34,10 +36,35 @@ class UserValidate extends BaseValidate
'confirm_password.checkPasswordEqual' => '两次输入的密码不一致',
'updateField.require' => '必填项不能为空',
'updateField.in' => '范围不合法',
'amount.require' => '金额不能为空',
'amount.chenckAmount' => '金额不合法',
];
protected function checkPasswordEqual($value, $rule, $data)
{
return $value === $data['password'];
}
protected function chenckAmount($value, $rule, $data)
{
$decimal = $rule['decimal'] ?? 2;
if (!is_numeric($value)) {
return false;
}
if ($value < 0) {
return false;
}
if (strpos((string)$value, '.') !== false) {
$decimalPart = explode('.', (string)$value)[1];
if (strlen($decimalPart) > $decimal) {
return false;
}
}
return true;
}
}
\ No newline at end of file
......@@ -10,6 +10,7 @@
namespace app\model;
use app\model\project\User;
use app\model\system\SystemUploadFile;
use think\Model;
/**
......@@ -83,7 +84,7 @@ class CertOrder extends Model
public function cert()
{
return $this->hasOne(Cert::class, 'id', 'cert_id')->field('id,title');
return $this->hasOne(Cert::class, 'id', 'cert_id')->field('id,title,fzjg');
}
public function getUpdatetimeTextAttr($value, $data)
......@@ -112,6 +113,28 @@ class CertOrder extends Model
}
}
public function idcardQ()
{
return $this->hasOne(SystemUploadFile::class, 'fileid', 'idcard_q')
->where('isdel',0)
->field('fileid,filename,filesize,fileurl,filetype');
}
public function idcardH()
{
return $this->hasOne(SystemUploadFile::class, 'fileid', 'idcard_h')
->where('isdel',0)
->field('fileid,filename,filesize,fileurl,filetype');
}
public function headImg()
{
return $this->hasOne(SystemUploadFile::class, 'fileid', 'head_img_id')
->where('isdel',0)
->field('fileid,filename,filesize,fileurl,filetype');
}
}
\ No newline at end of file
......@@ -112,7 +112,7 @@ class Course extends Model
public function thumb()
{
return $this->hasOne(SystemUploadFile::class, 'fileid', 'thumb')
->where('is_del',0)
->where('isdel',0)
->field('fileid,filename,filesize,fileurl,filetype');
}
......
......@@ -65,4 +65,23 @@ class UserMoneyLog extends Model
return $ranking;
}
/**添加用户资金报表
* @param $user_id
* @param $money
* @param $front_money
* @param $type
* @param $content
* @param $gl_table_id
* @return UserMoneyLog
*/
public static function addUserMoneyLog($user_id, $money,$front_money,$type, $content = '',$gl_table_id=0)
{
$after_money = $money+$front_money;
return self::create(['user_id'=>$user_id,'money'=>$after_money,'front_money'=>$front_money
,'type'=>$type,'gl_table_id'=>$gl_table_id,'createtime'=>time()
,'content'=>$content]);
}
}
\ No newline at end of file
<?php
namespace app\model\project;
use app\api\service\UtilService;
use app\model\project\User as UserModel;
use think\Model;
class UserWithdrawal extends Model
{
// 设置当前模型对应的完整数据表名称
protected $table = 'fj_user_withdrawal';
// 自动时间戳
protected $autoWriteTimestamp = true;
protected $createTime = 'createtime';
protected $updateTime = false;
// 提现状态常量
const SH_STATUS_PENDING = 0; // 待审核
const SH_STATUS_FAILED = 1; // 审核失败
const SH_STATUS_SUCCESS = 2; // 审核成功
const DK_STATUS_UNPAID = 0; // 未打款
const DK_STATUS_PROCESSING = 1; // 打款中
const DK_STATUS_FAILED = 2; // 打款失败
const DK_STATUS_PAID = 3; // 已打款
// 账号类型常量
const ACCOUNT_TYPE_ALIPAY = 0; // 支付宝
/**
* 用户提现申请
* @param int $userId 用户ID
* @param float $amount 提现金额
* @param int $accountType 账号类型
* @param string $account 提现账号
* @param string $realName 真实姓名
* @param float $commissionRate 手续费率(0-1)
* @param float $front_money 用户当前余额
* @return array
*/
public function applyWithdrawal($userId, $amount, $accountType, $account, $realName, $commissionRate = 0,$front_money = 0)
{
// 验证提现金额
if ($amount <= 0) {
return ['status' => false, 'msg' => '提现金额必须大于0'];
}
// 验证账号信息
if (empty($account) || empty($realName)) {
return ['status' => false, 'msg' => '提现账号和真实姓名不能为空'];
}
// 计算手续费和实际到账金额
$commission = bcmul($amount, $commissionRate, 2);
$actualAmount = bcsub($amount, $commission, 2);
// 生成提现单号
$withdrawalSn = UtilService::generateCompactOrderNo($userId,'tx');
try {
// 开启事务
$this->startTrans();
// 创建提现记录
$withdrawalId = $this->insertGetId([
'user_id' => $userId,
'sn' => $withdrawalSn,
'tx_money' => $amount,
'tx_commission' => $commission,
'tx_sj_money' => $actualAmount,
'sh_status' => self::SH_STATUS_PENDING,
'dk_status' => self::DK_STATUS_UNPAID,
'account_type' => $accountType,
'account' => $account,
'account_realname' => $realName,
'createtime' => time()
]);
UserModel::where(['id'=>$userId,'is_del'=>0])->dec('money',$amount)->save();
// 提交事务
$this->commit();
UserMoneyLog::addUserMoneyLog($userId,$amount,$front_money,1,'用户提现',$withdrawalId);
return [
'status' => true,
'msg' => '提现申请提交成功',
'data' => [
'sn' => $withdrawalSn,
'amount' => $amount,
'actual_amount' => $actualAmount,
'commission' => $commission
]
];
} catch (\Exception $e) {
// 回滚事务
$this->rollback();
return ['status' => false, 'msg' => '提现申请失败: ' . $e->getMessage()];
}
}
}
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment