| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149 |
- <?php
- namespace app\api\controller;
- use app\common\controller\Api;
- use app\common\library\CoinRate;
- use app\common\library\Ems;
- use app\common\library\Sms;
- use app\common\model\Config;
- use think\Db;
- use function EasyWeChat\Payment\get_server_ip;
- use fast\Random;
- use think\Validate;
- /**
- * 会员接口
- */
- class User extends Api
- {
- protected $noNeedLogin = ['login', 'syslogin', 'register', 'findpwd', 'sendMsg', 'mobilelogin', 'resetpwd', 'changeemail', 'changemobile', 'third'];
- protected $noNeedRight = '*';
- public function _initialize()
- {
- parent::_initialize();
- }
- function syslogin()
- {
- $id = input('uid');
- //直接登录会员
- $re = $this->auth->direct($id);
- if ($re) {
- echo ' <script language="javascript">
- window.location.href="/index/index/index";
- </script>';
- }
- }
- 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个字符');
- }
- }
- $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['stuid'] = $stuid;
- $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 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['userid'] = $this->auth->id;
- $p = $this->request->post('p');
- if($this->request->post('type')){
- $map['type'] = $this->request->post('type');
- }
- $data_list = db('release_log')->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['create_time']);
- $data_list[$k]['click'] = 'onclick="review(\'' . $v['remark'] . '\')"';
- }
- if ($data_list) {
- $return['data'] = $data_list;
- } else {
- $return['data'] = null;
- }
- $count = db('release_log')->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_bonus')->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(__("提现失败"));
- }
- }
- 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;
- }
- }
|