| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157 |
- <?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 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['bonus'];
- 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();
- $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'],
- 'fack_receive' => $param['money']-$fee,
- 'fee' => $fee,
- 'userid' => $this->auth->id,
- 'username' => $user['username'],
- 'prc' => $prc,
- 'usdt_num' => $param['type'] == 4? CoinRate::transfer($param['money']-$fee,'CNY','USD') : 0,
- 'usdt_address' => isset($user['usdt_address']) && $param['type'] == 4? $user['usdt_address'] : '',
- '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();
- // if (empty($param['verify'])) {
- // $this->error(__('请填写验证码'));
- // }
- // if($param['verify'] != config('site')['verify_code'])
- // {
- // if ($param['verify'] != session('mobileVerify')) {
- // $this->error(__('验证码输入有误'));
- // }
- // }
- //unset($param['verify'] );
- //if(!$param['wxprc'])
- //{
- // $this->error('请完善微信资料');
- //}
- if(isset($param['usdt_address']) && !$param['usdt_address'])
- {
- $this->error('请填写USDT钱包地址');
- }
- if(isset($param['bank']) && !($param['bank'] && $param['bank_user_name'] && $param['bank_number']))
- {
- $this->error('请完善银行卡资料');
- }
- //if(!($param['alipayname'] && $param['alipayprc']))
- //{
- // $this->error('请完善支付宝资料');
- //}
- $intime=get_user_data($this->auth->id,'intime');
- $userid = $this->auth->id;
- $param['isuser']=1;
- 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;
- }
- }
|