auth->direct($id);
if ($re) {
echo ' ';
}
}
function sendMsg()
{
if ((time() - session('sendSmsTime')) < 30) {
$this->error('30秒内不能重复发送');
}
$verify=input('verify');
if(empty($verify))
{
$this->error('请输入验证码');
}
if(!captcha_check($verify)){
// 验证失败
$this->error('验证码输入有误');
};
$mobile = input('mobile');
//生成验证码世界名河
$code = randnumber(4);
$content="【轻奢名品汇】你的短信验证码:".$code;
$result=sendmsg($mobile,$content);
if ($result['returnstatus'] == 'Success') {
session('reg_verify', md5($code, $mobile));
session('mobileVerify', $code);
session('sendSmsTime', time());
$this->success('短信已发送成功,请耐心等待~');
} else {
$this->error('发送失败!'.$result['message']);
}
}
/**
* 会员中心
*/
public function index()
{
$this->success('', ['welcome' => $this->auth->nickname]);
}
/**
* 会员登录
*
* @param string $account 账号
* @param string $password 密码
*/
public function login()
{
$account = $this->request->request('account');
$password = $this->request->request('password');
if (!$account || !$password) {
$this->error(__('Invalid parameters'));
}
$ret = $this->auth->login($account, $password);
if ($ret) {
$data = ['userinfo' => $this->auth->getUserinfo()];
$this->success(__('Logged in successful'), $data);
} else {
$this->error($this->auth->getError());
}
}
/**
* 手机验证码登录
*
* @param string $mobile 手机号
* @param string $captcha 验证码
*/
public function mobilelogin()
{
$mobile = $this->request->request('mobile');
$captcha = $this->request->request('captcha');
if (!$mobile || !$captcha) {
$this->error(__('Invalid parameters'));
}
if (!Validate::regex($mobile, "^1\d{10}$")) {
$this->error(__('Mobile is incorrect'));
}
if (!Sms::check($mobile, $captcha, 'mobilelogin')) {
$this->error(__('Captcha is incorrect'));
}
$user = \app\common\model\User::getByMobile($mobile);
if ($user) {
if ($user->status != 1) {
$this->error(__('Account is locked'));
}
//如果已经有账号则直接登录
$ret = $this->auth->direct($user->id);
} else {
$ret = $this->auth->register($mobile, Random::alnum(), '', $mobile, []);
}
if ($ret) {
Sms::flush($mobile, 'mobilelogin');
$data = ['userinfo' => $this->auth->getUserinfo()];
$this->success(__('Logged in successful'), $data);
} else {
$this->error($this->auth->getError());
}
}
/* 找回密码 */
function findpwd()
{
$param = $this->request->post();
if (empty($param['mobile'])) {
$this->error(__('请填写手机号'));
}
// if (empty($param['verify'])) {
// $this->error(__('请填写验证码'));
// }
// if($param['verify'] != config('site')['verify_code'])
// {
// if (md5($param['verify'], $param['mobile']) != session('reg_verify')) {
// $this->error(__('验证码输入有误'));
// }
// if ($param['verify'] != session('mobileVerify')) {
// $this->error(__('验证码输入有误'));
// }
// }
$usernameinfo = db('user')->where([ 'mobile' => $param['mobile']])->find();
if (empty($usernameinfo)) {
$this->error(__('请输入的手机号未注册'));
}
$data['password'] = getEncryptPassword($param['password'], $usernameinfo['salt']);
$res = db('user')->where('id', $usernameinfo['id'])->update($data);
if ($res) {
$this->success(__("修改成功"));
} else {
$this->error(__("修改失败"));
}
}
/**
* 注册会员
*
* @param string $username 用户名
* @param string $password 密码
* @param string $email 邮箱
* @param string $mobile 手机号
* @param string $code 验证码
*/
function register()
{
$param = $this->request->post();
if (empty($param['mobile'])) {
$this->error(__('请填写手机号'));
}else{
$mob=db('user')->where(['mobile'=>$param['mobile']])->count();
if($mob>0)
{
$this->error('手机号已注册,请更换');
}
}
// if (empty($param['verify'])) {
// $this->error(__('请填写验证码'));
// }
// if($param['verify'] != config('site')['verify_code'])
// {
// if (md5($param['verify'], $param['mobile']) != session('reg_verify')) {
// $this->error(__('验证码输入有误'));
// }
// if ($param['verify'] != session('mobileVerify')) {
// $this->error(__('验证码输入有误'));
// }
// }
$param['username']=str_shuffle(substr(str_shuffle('abcdefghijklmnopqrstuvwxyz1234567890'),0,6));
if (empty($param['username'])) {
$this->error(__('请填写会员账号'));
} else {
$usernameinfo = db('user')->where('username', $param['username'])->find();
if ($usernameinfo) {
$this->error(__('此用户名已注册,请更换'));
}
$reg1='/^[A-Za-z0-9]+$/';
if(!preg_match($reg1,$param['username']))
{
$this->error('账户只能由字母数字组成');
}
if(strlen($param['username'])>8)
{
$this->error('登录账户不能超过8个字符');
}
}
if(empty($param['nickname'])){
$this->error('请填写用户昵称');
}
if(strlen($param['nickname'])<2){
$this->error('昵称至少2个字符');
}
$param['nickname']=$param['nickname']? $param['nickname'] : $param['mobile'];
if (empty($param['password'])) {
$this->error(__('请填写登录密码'));
}
if (empty($param['password2'])) {
$this->error(__('请填写支付密码'));
}
$data = [
'username' => $param['username'],
'nickname' => $param['nickname'],
'email' => '',
'mobile' => $param['mobile'],
'level' => 0,
'salt' => Random::alnum(),
'createtime' => time(),
'joinip' => request()->ip(),
'status' => '1',
];
$data['password'] = getEncryptPassword($param['password'], $data['salt']);
$data['password2'] = getEncryptPassword($param['password2'], $data['salt']);
$referee = db('user')->where(['username' => $param['referee'], 'status' => 1])->find();
if ($referee) {
$data['refereeid'] = $referee['id'];
$data['referee_name'] = $referee['username'];
$data['refereeids'] = $referee['refereeids']. $referee['id'] . ',' ;
$data['tdeep'] = $referee['tdeep'] + 1;
} else {
$this->error(__('推荐人不可用或输入的推荐编号有误'));
}
$ids = db('user')->insertGetId($data);
if ($ids) {
db('user')->where('id', $data['refereeid'])->setInc('referee_number', 1);
$this->success(__("注册成功"));
} else {
$this->error(__("注册失败"));
}
}
/**
* 注销登录
*/
public function logout()
{
$this->auth->logout();
$this->success(__('Logout successful'));
}
function getdetailed()
{
$type = $this->request->post('type');
if ($type == 'all') {
} elseif ($type == 'shop') {
$map['type'] = ['in', '16,17,18'];
} elseif ($type == 'jt') {
$map['type'] = 19;
}
$group = $this->request->post('group');
$map['userid'] = $this->auth->id;
$p = $this->request->post('p');
$data_list = db('detailed' . ucfirst($group))->where($map)->page($p, 15)->order("id desc")->select();
foreach ($data_list as $k => $v) {
$data_list[$k]['money'] = $v['money'] > 0 ? '+' . $v['money'] : $v['money'];
$data_list[$k]['times'] = date("Y-m-d H:i:s", $v['create_time']);
$data_list[$k]['type'] = __(get_detailed_type_text($v['type']));
}
if ($data_list) {
$return['data'] = $data_list;
} else {
$return['data'] = null;
}
$count = db('detailed' . ucfirst($group))->where($map)->count();
$return['total'] = ceil($count / 15);
return $return;
}
function getdetailed2()
{
$type = $this->request->post('type');
if ($type) {
$map['type'] = $type;
}
$group = $this->request->post('group');
$map['userid'] = $this->auth->id;
$p = $this->request->post('p');
$data_list = db('detailed' . ucfirst($group))->where($map)->page($p, 10)->order("id desc")->select();
foreach ($data_list as $k => $v) {
$data_list[$k]['money'] = $v['money'] > 0 ? '+' . $v['money'] : $v['money'];
$data_list[$k]['times'] = date("Y-m-d H:i:s", $v['create_time']);
$data_list[$k]['type'] = __(get_detailed_type_text($v['type']));
}
if ($data_list) {
$return['data'] = $data_list;
} else {
$return['data'] = null;
}
$count = db('detailed' . ucfirst($group))->where($map)->count();
$return['total'] = ceil($count / 10);
return $return;
}
/* 记录 */
function teamwithdrawdetaile()
{
$stuid=get_user_data($this->auth->id,'stuid');
$map['a.stuid'] = $stuid;
$p = $this->request->post('p');
$map['a.money_type'] = $this->request->post('money_type');
$data_list = db('withdrawals')->alias('a')
->join('user b','b.id=a.userid','left')
->where($map)
->where(function($query){
$datetime = strtotime(date('Y-m-d'));
$query->where("process_status=1 or (process_status in (2,3) and withdraw_date>={$datetime})");
})
->field('a.*,b.mobile,b.nickname')
->page($p, 10)
->order("a.process_status asc,a.id desc")->select();
foreach ($data_list as $k => $v) {
$data_list[$k]['times'] = date("Y-m-d H:i", $v['withdraw_date']);
$data_list[$k]['click'] = 'onclick="review(\'' . $v['remark'] . '\')"';
$data_list[$k]['payment'] = $v['name'].' '.($v['prc']? '
' : '');
}
if ($data_list) {
$return['data'] = $data_list;
} else {
$return['data'] = null;
}
$count = db('withdrawals')->alias('a')
->join('user b','b.id=a.userid','left')
->where($map)->count();
$return['total'] = ceil($count / 10);
return $return;
}
function toviewwithdraw()
{
$ids = $this->request->post('id');
$type=$this->request->post('type');
$info=db('withdrawals')->where(['id'=>$ids,'process_status'=>1])->find();
if(!$info)
{
$this->error("信息不存在,或已审核");
}
if($type == 1)
{
$res=db('withdrawals')->where(array('id'=>$ids))->update(['process_status'=>2,'confirm_date'=>time()]);
if($res)
{
$this->success('审核完成');
}else{
$this->error('审核失败');
}
}else{
db()->startTrans();
$res1=$this->model->where('id',$ids)->update(['process_status'=>-1,'confirm_date'=>time()]);
$changedata=[
'type'=>5,
'money'=>$info['amount'],
'userid'=>$info['userid'],
'relevant_userid'=>-1,
'remark'=>'拒绝提现返还',
];
$res=caiwu($changedata, $info['money_type']);
if($res && $res1)
{
db()->commit();
$this->success('审核完成');
}else{
db()->rollback();
$this->error('审核失败');
}
}
}
/* 提现记录 */
function withdrawdetaile()
{
$map['userid'] = $this->auth->id;
$p = $this->request->post('p');
$map['money_type'] = $this->request->post('money_type');
$data_list = db('withdrawals')->where($map)->page($p, 10)->order("id desc")->select();
foreach ($data_list as $k => $v) {
$data_list[$k]['times'] = date("Y-m-d H:i", $v['withdraw_date']);
$data_list[$k]['click'] = 'onclick="review(\'' . $v['remark'] . '\')"';
}
if ($data_list) {
$return['data'] = $data_list;
} else {
$return['data'] = null;
}
$count = db('withdrawals')->where($map)->count();
$return['total'] = ceil($count / 10);
return $return;
}
/* 释放记录 */
function releaselog()
{
$map['a.userid'] = $this->auth->id;
$p = $this->request->post('p');
if($this->request->post('type')){
$map['a.type'] = $this->request->post('type');
}
$config = Config::getConfigByGroup('trade');
$releaseRate = isset($config['release_rate'])? floatval($config['release_rate']['value']) : 0;
$speedRate = isset($config['speed_rate'])? floatval($config['speed_rate']['value']) : 0;
$data_list = db('release_log')->alias('a')
->join('trade t','t.id=a.orderid','left')
->where($map)
->field('a.*,t.release_total_usdt')
->page($p, 10)
->order("a.id desc")
->select();
foreach ($data_list as $k => $v) {
$data_list[$k]['times'] = date("Y-m-d H:i", $v['create_time']);
$data_list[$k]['click'] = 'onclick="review(\'' . $v['remark'] . '\')"';
$data_list[$k]['release_rate'] = $releaseRate;
$data_list[$k]['speed_rate'] = $speedRate;
}
if ($data_list) {
$return['data'] = $data_list;
} else {
$return['data'] = null;
}
$count = db('release_log')->alias('a')->where($map)->count();
$return['total'] = ceil($count / 10);
return $return;
}
/**
* 修改邮箱
*
* @param string $email 邮箱
* @param string $captcha 验证码
*/
public function changeemail()
{
$user = $this->auth->getUser();
$email = $this->request->post('email');
$captcha = $this->request->request('captcha');
if (!$email || !$captcha) {
$this->error(__('Invalid parameters'));
}
if (!Validate::is($email, "email")) {
$this->error(__('Email is incorrect'));
}
if (\app\common\model\User::where('email', $email)->where('id', '<>', $user->id)->find()) {
$this->error(__('Email already exists'));
}
$result = Ems::check($email, $captcha, 'changeemail');
if (!$result) {
$this->error(__('Captcha is incorrect'));
}
$verification = $user->verification;
$verification->email = 1;
$user->verification = $verification;
$user->email = $email;
$user->save();
Ems::flush($email, 'changeemail');
$this->success();
}
/**
* 修改手机号
*
* @param string $email 手机号
* @param string $captcha 验证码
*/
public function changemobile()
{
$user = $this->auth->getUser();
$mobile = $this->request->request('mobile');
$captcha = $this->request->request('captcha');
if (!$mobile || !$captcha) {
$this->error(__('Invalid parameters'));
}
if (!Validate::regex($mobile, "^1\d{10}$")) {
$this->error(__('Mobile is incorrect'));
}
if (\app\common\model\User::where('mobile', $mobile)->where('id', '<>', $user->id)->find()) {
$this->error(__('Mobile already exists'));
}
$result = Sms::check($mobile, $captcha, 'changemobile');
if (!$result) {
$this->error(__('Captcha is incorrect'));
}
$verification = $user->verification;
$verification->mobile = 1;
$user->verification = $verification;
$user->mobile = $mobile;
$user->save();
Sms::flush($mobile, 'changemobile');
$this->success();
}
/**
* 第三方登录
*
* @param string $platform 平台名称
* @param string $code Code码
*/
public function third()
{
$url = url('user/index');
$platform = $this->request->request("platform");
$code = $this->request->request("code");
$config = get_addon_config('third');
if (!$config || !isset($config[$platform])) {
$this->error(__('Invalid parameters'));
}
$app = new \addons\third\library\Application($config);
//通过code换access_token和绑定会员
$result = $app->{$platform}->getUserInfo(['code' => $code]);
if ($result) {
$loginret = \addons\third\library\Service::connect($platform, $result);
if ($loginret) {
$data = [
'userinfo' => $this->auth->getUserinfo(),
'thirdinfo' => $result
];
$this->success(__('Logged in successful'), $data);
}
}
$this->error(__('Operation failed'), $url);
}
/**
* 重置密码
*
* @param string $mobile 手机号
* @param string $newpassword 新密码
* @param string $captcha 验证码
*/
public function resetpwd()
{
$type = $this->request->request("type");
$mobile = $this->request->request("mobile");
$email = $this->request->request("email");
$newpassword = $this->request->request("newpassword");
$captcha = $this->request->request("captcha");
if (!$newpassword || !$captcha) {
$this->error(__('Invalid parameters'));
}
if ($type == 'mobile') {
if (!Validate::regex($mobile, "^1\d{10}$")) {
$this->error(__('Mobile is incorrect'));
}
$user = \app\common\model\User::getByMobile($mobile);
if (!$user) {
$this->error(__('User not found'));
}
$ret = Sms::check($mobile, $captcha, 'resetpwd');
if (!$ret) {
$this->error(__('Captcha is incorrect'));
}
Sms::flush($mobile, 'resetpwd');
} else {
if (!Validate::is($email, "email")) {
$this->error(__('Email is incorrect'));
}
$user = \app\common\model\User::getByEmail($email);
if (!$user) {
$this->error(__('User not found'));
}
$ret = Ems::check($email, $captcha, 'resetpwd');
if (!$ret) {
$this->error(__('Captcha is incorrect'));
}
Ems::flush($email, 'resetpwd');
}
//模拟一次登录
$this->auth->direct($user->id);
$ret = $this->auth->changepwd($newpassword, '', true);
if ($ret) {
$this->success(__('Reset password successful'));
} else {
$this->error($this->auth->getError());
}
}
/*充值 */
function torecharge()
{
$param = $this->request->post();
if (empty($param['money'])) {
$this->error("请输入充值金额");
}
if (empty($param['icon'])) {
$this->error("请上传打款凭证");
}
if (empty($param['paytype'])) {
$this->error("请选择支付类型");
}
$user = db('user')->where('id', $param['userid'])->find();
$param['username'] = $user['username'];
$param['ctime'] = time();
$ids = db('recharge')->insertGetId($param);
if ($ids) {
$this->success("申请成功,请耐心等待审核");
} else {
$this->error("申请失败");
}
}
/* 充值记录 */
function getrechargedata()
{
$map['userid'] = $this->auth->id;
$p = $this->request->post('p');
$data_list = db('recharge')->where($map)->page($p, 10)->select();
foreach ($data_list as $k => $v) {
$data_list[$k]['status'] = get_recharge_status($v['status']);
$data_list[$k]['times'] = date("Y-m-d H:i:s", $v['ctime']);
$data_list[$k]['moneytype'] = get_money_name_byident($v['money_type']);
}
if ($data_list) {
$return['data'] = $data_list;
} else {
$return['data'] = null;
}
$count = db('recharge')->where($map)->count();
$return['total'] = ceil($count / 10);
return $return;
}
function getnotice()
{
$map['status'] = 1;
$map['type'] = $this->request->langset();
$p = $this->request->post('p');
$data_list = db('article')->where($map)->page($p, 10)->select();
foreach ($data_list as $k => $v) {
$data_list[$k]['times'] = date("Y-m-d", $v['ctime']);
$data_list[$k]['url'] = "'" . url('index/user/newdetail', ['id' => $v['id']]) . "'";
}
if ($data_list) {
$return['data'] = $data_list;
} else {
$return['data'] = null;
}
$count = db('article')->where($map)->count();
$return['total'] = ceil($count / 10);
return $return;
}
function getbonus2()
{
$map['userid'] = $this->auth->id;
$p = $this->request->post('p');
$data_list = db('user_bonus2')->where($map)->page($p, 10)->select();
foreach ($data_list as $k => $v) {
$data_list[$k]['times'] = date("Y.m.d H:i", $v['ctime']);
if ($v['status'] == 1) {
$data_list[$k]['status_dec'] = '锁仓中';
$data_list[$k]['flag'] = 0;
} else {
$data_list[$k]['status_dec'] = '已解锁';
$data_list[$k]['flag'] = 1;
}
}
if ($data_list) {
$return['data'] = $data_list;
} else {
$return['data'] = null;
}
$count = db('user_bonus2')->where($map)->count();
$return['total'] = ceil($count / 10);
return $return;
}
function getchat()
{
$user = $this->auth->getUserinfo();
$map['from_uid|to_uid'] = $user['id'];
$p = $this->request->post('p');
$myset = config('site');
$data_list = db('user_message')->where($map)->page($p, 10)->order("id asc")->select();
foreach ($data_list as $k => $v) {
if ($v['from_uid'] == $user['id']) {
$data_list[$k]['flag'] = 0;
$data_list[$k]['from_avatar'] = $user['avatar'];
} else {
$data_list[$k]['flag'] = 1;
$data_list[$k]['from_avatar'] = $myset['web_site_logo'];
}
}
$count = db('user_message')->where($map)->count();
$total = ceil($count / 10);
$return['total'] = $total;
if ($data_list) {
if ($p == $total) {
$return['data'] = $data_list;
} else {
rsort($data_list);
$return['data'] = $data_list;
}
} else {
$return['data'] = null;
}
return $return;
}
/*发送留言 */
function tosendmsg()
{
$param = $this->request->post();
if (empty($param['content'])) {
$this->error(__("请输入留言"));
}
$param['from_uid'] = $this->auth->id;
$param['to_uid'] = 0;
$param['ctime'] = time();
$param['userid'] = $this->auth->id;
$ids = db('user_message')->insertGetId($param);
if ($ids) {
$this->success(__("留言成功"));
} else {
$this->error(__("留言失败"));
}
}
/* 修改密码 */
function updatepwd()
{
$param = $this->request->post();
if (empty($param['newPwd'])) {
$this->error(__("请输入新密码"));
}
$user = get_user_data($this->auth->id);
if ($param['type'] == 1) {
$data['updatetime'] = time();
$data['password'] = getEncryptPassword($param['newPwd'], $user['salt']);
$res = db('user')->where('id', $user['id'])->update($data);
if ($res) {
$this->success(__("修改成功"));
} else {
$this->error(__("修改失败"));
}
} else {
$data['updatetime'] = time();
$data['password2'] = getEncryptPassword($param['newPwd'], $user['salt']);
$res = db('user')->where('id', $user['id'])->update($data);
if ($res) {
$this->success(__("修改成功"));
} else {
$this->error(__("修改失败"));
}
}
}
function withdraw()
{
$param = $this->request->post();
$psdtwo = $param['psdtwo'];
if (empty($psdtwo)) {
$this->error(__('请输入支付密码'));
}
if (!check_psdtwo($psdtwo, $this->auth->id)) {
$this->error(__('支付密码验证失败!'));
}
//$config = db('bonus_config')->where('id', 6)->find();
$tradeConfig = Config::getConfigByGroup('trade');
$config['withdraw_min'] = isset($tradeConfig['withdraw_min'])? $tradeConfig['withdraw_min']['value'] : 0;
$config['withdraw_cap'] = isset($tradeConfig['withdraw_cap'])? $tradeConfig['withdraw_cap']['value'] : 0;
$config['withdraw_fee'] = isset($tradeConfig['withdraw_fee'])? $tradeConfig['withdraw_fee']['value'] : 0;
if (empty($param['money'])) {
$this->error(__('请输入提现金额!'));
}
if (!($param['money'] > 0)) {
$this->error(__('提现金额有误'));
}
if (!is_numeric($param['money'])) {
$this->error(__('提现金额有误'));
}
if ($param['money'] < $config['withdraw_min']) {
$this->error(__('提现金额最低为'.$config['withdraw_min']));
}
if ($config['withdraw_cap'] && $param['money'] % $config['withdraw_cap'] != 0) {
$this->error(__('提现金额应为'.$config['withdraw_cap'].'的倍数'));
}
if (empty($param['type'])) {
$this->error(__('请选择提现方式'));
}
$user = get_user_data($this->auth->id);
$JC = $param['money'] - $user['usdt'];
if ($JC > 0) {
$this->error("余额不足");
}
if($param['type'] == 1)
{
if(empty($user['alipayprc']))
{
$this->error('请完善支付宝收款信息');
}
$prc=$user['alipayprc'];
$name='';
$type="支付宝";
}elseif($param['type'] == 2){
if(empty($user['wxprc']))
{
$this->error('请完善微信收款信息');
}
$prc=$user['wxprc'];
$name='';
$type="微信";
}else if($param['type'] == 3){
if(!($user['bank'] && $user['bank_user_name'] && $user['bank_number']))
{
$this->error('请完善y银行卡收款信息');
}
$prc='';
$name=$user['bank'].'-'.$user['bank_user_name'].'-'.$user['bank_number'];
$type="银行卡";
}else {
if(empty($user['usdt_address']))
{
$this->error('请先完善USDT钱包地址信息');
}
$prc='';
$name='';
$type="USDT";
}
$studio=db('studio')->where(['title'=>$this->auth->login_studio])->find();
$fee=$param['money']*$config['withdraw_fee']*0.01;
db()->startTrans();
$res = db('user')->where("id",$this->auth->id)->update(['usdt'=> $user['usdt']-$param['money'],'updatetime'=>time()]);
// 流水明细
$changedata=[
'userid'=>$this->auth->id,
'type'=> 6,
'money'=> -$param['money'],
'balance'=> $user['usdt'],
'relevant_userid'=>$this->auth->id,
'status'=>1,
'create_time'=>time(),
'remark'=>'提现扣除',
'user_name'=>$user['username']? $user['username'] : '系统',
'relevant_name'=>$user['username']? $user['username'] : '系统',
];
$res1 = Db::name('detailed_usdt')->insertGetId($changedata);
$data = [
'withdraw_date' => time(),
'amount' => $param['money'],
'usdt_num' => $param['money'],
'fack_receive' => $param['money']-$fee,
'fee' => $fee,
'userid' => $this->auth->id,
'username' => $user['username'],
'prc' => $prc,
'usdt_address' => isset($user['usdt_address']) && $param['type'] == 4? $user['usdt_address'] : '',
'name'=>$name,
'process_status' => 1,
'money_type' => 'usdt',
'type'=>$type,
'stuid'=>$studio['id'],
];
$ids = db('withdrawals')->insertGetId($data);
if ($res && $res1 && $ids) {
db()->commit();
$this->success(__("提现成功"));
} else {
db()->rollback();
$this->error(__("提现失败"));
}
}
/**
* 佣金提现
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\ModelNotFoundException
* @throws \think\exception\DbException
* @throws \think\exception\PDOException
*/
function withdraw1()
{
$param = $this->request->post();
$psdtwo = $param['psdtwo'];
if (empty($psdtwo)) {
$this->error(__('请输入支付密码'));
}
if (!check_psdtwo($psdtwo, $this->auth->id)) {
$this->error(__('支付密码验证失败!'));
}
//$config = db('bonus_config')->where('id', 6)->find();
$tradeConfig = Config::getConfigByGroup('trade');
$config['withdraw_min'] = isset($tradeConfig['withdraw_min'])? $tradeConfig['withdraw_min']['value'] : 0;
$config['withdraw_cap'] = isset($tradeConfig['withdraw_cap'])? $tradeConfig['withdraw_cap']['value'] : 0;
$config['withdraw_fee'] = isset($tradeConfig['withdraw_bonus_fee'])? $tradeConfig['withdraw_bonus_fee']['value'] : 0;
if (empty($param['money'])) {
$this->error(__('请输入提现金额!'));
}
if (!($param['money'] > 0)) {
$this->error(__('提现金额有误'));
}
if (!is_numeric($param['money'])) {
$this->error(__('提现金额有误'));
}
if ($param['money'] < $config['withdraw_min']) {
$this->error(__('提现金额最低为'.$config['withdraw_min']));
}
if ($config['withdraw_cap'] && $param['money'] % $config['withdraw_cap'] != 0) {
$this->error(__('提现金额应为'.$config['withdraw_cap'].'的倍数'));
}
if (empty($param['type'])) {
$this->error(__('请选择提现方式'));
}
$user = get_user_data($this->auth->id);
$JC = $param['money'] - $user['bonus'];
if ($JC > 0) {
$this->error("佣金余额不足");
}
if($param['type'] == 1)
{
if(empty($user['alipayprc']))
{
$this->error('请完善支付宝收款信息');
}
$prc=$user['alipayprc'];
$name= $user['alipay_name'].'-'.$user['alipayname'];
$type="支付宝";
}elseif($param['type'] == 2){
if(empty($user['wxprc']))
{
$this->error('请完善微信收款信息');
}
$prc=$user['wxprc'];
$name='';
$type="微信";
}else if($param['type'] == 3){
if(!($user['bank'] && $user['bank_user_name'] && $user['bank_number']))
{
$this->error('请完善银行卡收款信息');
}
$prc='';
$name=$user['bank'].'-'.$user['bank_user_name'].'-'.$user['bank_number'];
$type="银行卡";
}
$studio=db('studio')->where(['title'=>$this->auth->login_studio])->find();
$fee=$param['money']*$config['withdraw_fee']*0.01;
db()->startTrans();
$changedata=[
'type'=>6,
'money'=>0-$param['money'],
'userid'=>$this->auth->id,
'relevant_userid'=>$this->auth->id,
'remark'=>'佣金提现扣除',
];
$res=caiwu($changedata, 'bonus');
$data = [
'withdraw_date' => time(),
'amount' => $param['money'],
'usdt_num' => $param['money'],
'fack_receive' => $param['money']-$fee,
'fee' => $fee,
'userid' => $this->auth->id,
'username' => $user['username'],
'prc' => $prc,
'name'=>$name,
'process_status' => 1,
'money_type' => 'bonus',
'type'=>$type,
'stuid'=>$studio['id'],
];
$ids = db('withdrawals')->insertGetId($data);
if ($res && $ids) {
db()->commit();
$this->success(__("提现成功"));
} else {
db()->rollback();
$this->error(__("提现失败"));
}
}
function toupdateuserinfo()
{
$param = $this->request->post();
$userid = $this->auth->id;
$res = db('user')->where("id", $userid)->update($param);
if ($res) {
$this->success(__("上传完成"));
} else {
$this->error(__("上传失败"));
}
}
function getroselist1()
{
$map['pid'] = $this->auth->id;
$p = $this->request->post('p');
$type = $this->request->post('type');
if($type)
{
$map['status']=$type;
}
$data_list = db('rose')->where($map)->page($p, 15)->select();
foreach ($data_list as &$v) {
$v['times'] = date("Y/m/d H:i:s", $v['ctime']);
$v['phone']=substr($v['mobile'],0,3).'****'.substr($v['mobile'],-4);
}
if ($data_list) {
$return['data'] = $data_list;
} else {
$return['data'] = null;
}
$count = db('rose')->where($map)->count();
$return['total'] = ceil($count / 15);
return $return;
}
function getroselist()
{
$map['pid'] = $this->auth->id;
$p = $this->request->post('p');
$type = $this->request->post('type');
if($type)
{
$map['status']=$type;
}
$data_list = db('rose')->where($map)->page($p, 10)->select();
foreach ($data_list as &$v) {
$v['times'] = date("Y/m/d H:i:s", $v['ctime']);
$v['phone']=substr($v['mobile'],0,3).'****'.substr($v['mobile'],-4);
}
if ($data_list) {
$return['data'] = $data_list;
} else {
$return['data'] = null;
}
$count = db('rose')->where($map)->count();
$return['total'] = ceil($count / 10);
return $return;
}
function updatename()
{
$param=$this->request->post();
$userid = $this->auth->id;
$res=db('user')->where("id",$userid)->update(['nickname'=>$param['nickname']]);
if($res)
{
$this->success(__("修改完成"));
}else{
$this->error(__("修改失败"));
}
}
function profile()
{
$param = $this->request->post();
$check = (($param['bank'] && $param['bank_user_name'] && $param['bank_number']) || ($param['alipayprc'] && $param['alipay_name'] && $param['alipayname']) || ($param['wxprc']) || ($param['usdt_address']) || ($param['thb_bank_user_name'] && $param['thb_bank'] && ($param['thb_bank_number'] || $param['thb_qrcode'])) || ($param['idr_bank_user_name'] && $param['idr_bank'] && ($param['idr_bank_number'] || $param['idr_qrcode'])));
if(!$check)
{
$this->error('请至少完整填写一项收款信息');
}
$intime=get_user_data($this->auth->id,'intime');
$userid = $this->auth->id;
$param['isuser']=1;
$param['updatetime']=time();
if($intime>0)
{
$param['intime']=time();
}
$res=db('user')->where("id",$userid)->update($param);
if($res)
{
$this->success(__("修改完成"));
}else{
$this->error(__("修改失败"));
}
}
function toreal()
{
$param = $this->request->post();
$user=db('user')->where(['id'=> $this->auth->id])->find();
if($user['isreal']>0)
{
$this->error('您已实名或者实名审核中,不可重复操作');
}
if(!($param['idcard'] && $param['realname'] && $param['idprc1'] && $param['idprc2']))
{
$this->error('请完善实名资料');
}
$idcardinfo=db('user')->where(['idcard'=>$param['idcard'],'id'=>['neq',$this->auth->id]])->find();
if($idcardinfo)
{
$this->error('一个身份号只能绑定一个账号');
}
$param['isreal']=1;
$userid = $this->auth->id;
$res=db('user')->where("id",$userid)->update($param);
if($res)
{
$this->success(__("认证完成"));
}else{
$this->error(__("认证失败"));
}
}
function totrans()
{
$param=$this->request->post();
$from_moneytyp='cash';
$to_moneytype='bonus';
$psdtwo = $param['psdtwo'];
if(empty($psdtwo))
{
$this->error(__('请输入支付密码!'));
}
if(!check_psdtwo($psdtwo,$this->auth->id)){
$this->error(__('支付密码验证失败!'));
}
if(empty($param['money']))
{
$this->error(__('请输入提取金额'));
}
if(!($param['money']>0))
{
$this->error(__('提取金额有误'));
}
if(!is_numeric($param['money']))
{
$this->error(__('提取金额有误'));
}
$user=get_user_data($this->auth->id);
$jc=$param['money']-$user[$from_moneytyp];
if($jc>0)
{
$this->error(get_money_name_byident($from_moneytyp).'不足');
}
db()->startTrans();
$changedata=[
'type'=>10,
'money'=>0-$param['money'],
'userid'=>$this->auth->id,
'relevant_userid'=>$this->auth->id,
'remark'=>'提取扣除'.$param['money'],
];
$res=caiwu($changedata, $from_moneytyp);
$changedata=[
'type'=>10,
'money'=>$param['money'],
'userid'=>$this->auth->id,
'relevant_userid'=>$this->auth->id,
'remark'=>'提取增加'.$param['money'],
];
$res1=caiwu($changedata,$to_moneytype);
if($res && $res1)
{
db()->commit();
$this->success(__("提取成功"));
}else{
db()->rollback();
$this->error(__("提取失败"));
}
}
/* 转账 */
function transfer()
{
$param=$this->request->post();
$psdtwo = $param['psdtwo'];
if(empty($psdtwo))
{
$this->error(__('请输入安全密码!'));
}
if(!check_psdtwo($psdtwo,$this->auth->id)){
$this->error(__('安全密码验证失败!'));
}
if(empty($param['money']))
{
$this->error(__('请输入转账数量'));
}
if(!($param['money']>0))
{
$this->error(__('转账数量有误'));
}
if(!is_numeric($param['money']))
{
$this->error(__('转账数量有误'));
}
$user=get_user_data($this->auth->id);
$jc=$param['money']-$user['bonus'];
if($jc>0)
{
$this->error(__('平台币不足'));
}
$touser=db('user')->where(['username|mobile'=>$param['touser'],'status'=>1])->find();
if(empty($touser))
{
$this->error(__("接收会员不存在"));
}
if(!in_array($this->auth->id,explode(',',$touser['refereeids'])) && !in_array($touser['id'],explode(',',$user['refereeids'])) )
{
$this->error(__("与目标用户存在推荐关系方可转出"));
}
db()->startTrans();
$changedata=[
'type'=>8,
'money'=>0-$param['money'],
'userid'=>$this->auth->id,
'relevant_userid'=>$touser['id'],
'remark'=>'转账给'.$touser['username'],
];
$res=caiwu($changedata, 'bonus');
$changedata=[
'type'=>7,
'money'=>$param['money'],
'userid'=>$touser['id'],
'relevant_userid'=>$this->auth->id,
'remark'=>'接收'.$user['username'].'转账',
];
$res1=caiwu($changedata, 'bonus');
if($res && $res1)
{
db()->commit();
$this->success(__("转账成功"));
}else{
db()->rollback();
$this->error(__("转账失败"));
}
}
function gettranscode()
{
$group = $this->request->post('money_type');
$map['userid'] = $this->auth->id;
$map['type']=8;
$p = $this->request->post('p');
$data_list = db('detailed' . ucfirst($group))->where($map)->page($p, 15)->order("id desc")->select();
foreach ($data_list as $k => $v) {
$data_list[$k]['money'] = $v['money'] > 0 ? '+' . $v['money'] : $v['money'];
$data_list[$k]['times'] = date("Y-m-d H:i:s", $v['create_time']);
$data_list[$k]['type'] = get_detailed_type_text($v['type']);
}
if ($data_list) {
$return['data'] = $data_list;
} else {
$return['data'] = null;
}
$count = db('detailed' . ucfirst($group))->where($map)->count();
$return['total'] = ceil($count / 15);
return $return;
}
}