| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115 |
- <?php
- namespace app\api\controller;
- use app\common\controller\Api;
- use app\common\model\MoneyLog;
- use app\common\model\ScoreLog;
- use app\common\model\Txjl;
- use app\common\model\Kami;
- use app\common\library\Ems;
- use app\common\library\Sms;
- use fast\Random;
- use think\Validate;
- use think\Db;
- /**
- * 会员接口
- */
- class User extends Api
- {
- protected $noNeedLogin = ['login', 'logingzh', 'getphone', 'getOpenid', 'mobilelogin', 'register', 'reg', 'resetpwd', 'changeemail', 'changemobile', 'third'];
- protected $noNeedRight = '*';
- public function _initialize()
- {
- parent::_initialize();
- $this->Usermodel = model('User');
- }
- /**
- * 会员中心
- */
- public function index()
- {
- $site = config('site');
- $data = $this->auth->getUserinfo();
- $UserGroup = model('UserGroup')->where(['id' => $data['group_id']])->find();
- if (isset($UserGroup['name'])) {
- $data['Groupname'] = $UserGroup['name'];
- } else {
- $data['Groupname'] = '';
- }
- if ($site) {
- $data['config'] = $site;
- } else {
- $data['config'] = [];
- }
- $data['zstx'] = $site['zstx'] * 1;
- if ($data['dtime'] < time() and $data['group_id'] > 1) {
- $timediff = $data['dtime'] - time();
- $data['dqts'] = intval($timediff / 86400);
- } else {
- $timediff = $data['dtime'] - time();
- $data['dqts'] = intval($timediff / 86400);
- }
- $data['dtime'] = date('Y-m-d', $data['dtime']);
- $this->success('', $data);
- }
- public function duihuan()
- {
- $site = config('site');
- $sum = input('sum');
- if (!input('sum')) {
- $this->error('请填写提兑换数量');
- }
- if ($sum < $site['jfdhzs']) {
- $this->error($site['jfdhsm']);
- }
- Db::startTrans();
- try {
- $user = $this->auth->getUser();
- if ($user && $sum != 0) {
- $before = $user->money;
- if ($user->money < $sum) {
- $this->error('积分不够');
- }
- $after = $user->score - $sum;
- //更新会员信息
- $user->save(['score' => $after]);
- //写入日志
- ScoreLog::create(['user_id' => $user->id, 'score' => $sum, 'before' => $before, 'after' => $after, 'memo' => '积分兑换']);
- } else {
- $this->error(__('金额不对'));
- }
- $usersa = $this->auth->getUser();
- $money = $sum * $site['jfdh'];
- if ($usersa && $money != 0) {
- $before = $usersa->money;
- $after = $usersa->money + $money;
- //更新会员信息
- $usersa->save(['money' => $after]);
- //写入日志
- MoneyLog::create(['user_id' => $usersa->id, 'money' => $money, 'before' => $before, 'after' => $after, 'fid' => 0, 'sxf' => 0, 'memo' => '积分兑换']);
- } else {
- $this->error(__('兑换错误'));
- }
- Db::commit();
- $this->success(__('兑换成功'));
- } catch (Exception $e) {
- Db::rollback();
- $this->error($e->getMessage());
- }
- }
- public function mytuandui()
- {
- $configs = config('site');
- $user = $this->auth->getUser();
- $usera = \app\common\model\User::where(['pid' => $this->auth->id])->select();
- foreach ($usera as $k => $v) {
- if (isset($v['avatar'])) {
- if (strpos($v['avatar'], 'http') !== false) {
- $usera[$k]['avatar'] = $v['avatar'];
- } else {
- if ($v['avatar']) {
- $usera[$k]['avatar'] = $configs['imgurl'] . $v['avatar'];
- } else {
- $usera[$k]['avatar'] = $configs['imgurl'] . '/uploads/20200523/250b3f89b40ff3714b07cc51b4c2f63d.png';
- }
- }
- } else {
- $usera[$k]['avatar'] = $configs['imgurl'] . '/uploads/20200523/250b3f89b40ff3714b07cc51b4c2f63d.png';
- }
- }
- $this->success('success', $usera);
- }
- /**
- * 会员登录
- *
- * @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) {
- $userinfo = $this->auth->getUserinfo();
- $data = ['config' => $this->config(), 'userinfo' => $userinfo];
- $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 != 'normal') {
- $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());
- }
- }
- /**
- * 注册会员
- *
- * @param string $username 用户名
- * @param string $password 密码
- * @param string $email 邮箱
- * @param string $mobile 手机号
- * @param string $code 验证码
- */
- public function register()
- {
- $username = $this->request->request('username');
- $password = $this->request->request('password');
- $email = $this->request->request('email');
- $mobile = $this->request->request('mobile');
- $code = $this->request->request('code');
- if (!$username || !$password) {
- $this->error(__('Invalid parameters'));
- }
- if ($email && !Validate::is($email, "email")) {
- $this->error(__('Email is incorrect'));
- }
- if ($mobile && !Validate::regex($mobile, "^1\d{10}$")) {
- $this->error(__('Mobile is incorrect'));
- }
- $ret = Sms::check($mobile, $code, 'register');
- if (!$ret) {
- $this->error(__('Captcha is incorrect'));
- }
- $ret = $this->auth->register($username, $password, $email, $mobile, []);
- if ($ret) {
- $data = ['userinfo' => $this->auth->getUserinfo()];
- $this->success(__('Sign up successful'), $data);
- } else {
- $this->error($this->auth->getError());
- }
- }
- public function reg()
- {
- $username = $this->request->request('username');
- $password = $this->request->request('password');
- $email = $this->request->request('email');
- $mobile = $this->request->request('mobile');
- $code = $this->request->request('code');
- $pid = $this->request->request('pid');
- if (!$pid) {
- $pid = 1;
- }
- $usera = \app\common\model\User::getById($pid);
- if (!$usera) {
- $this->error(__('邀请码不正确'));
- }
- if (!$username || !$password) {
- $this->error(__('Invalid parameters'));
- }
- if (!$email && !$mobile) {
- $this->error(__('手机号或邮箱至少任选其一'));
- }
- if ($mobile && !Validate::regex($mobile, "^1\d{10}$")) {
- $this->error(__('Mobile is incorrect'));
- }
- if (!$email) {
- $email = $mobile . '@10068.com';
- }
- if ($email && !Validate::is($email, "email")) {
- $this->error(__('Email is incorrect'));
- }
- if ($mobile) {
- $ret = Sms::check($mobile, $code, 'register');
- if (!$ret) {
- $ret = Ems::check($email, $code, 'register');
- if (!$ret) {
- $this->error(__('Captcha is incorrect'));
- }
- }
- } else {
- $ret = Ems::check($email, $code, 'register');
- if (!$ret) {
- $this->error(__('Captcha is incorrect'));
- }
- }
- $avatar = '/uploads/face/A' . rand(1, 96) . '.jpg';
- $ret = $this->auth->register($username, $password, $email, $mobile, ['avatar' => $avatar, 'pid' => $pid]);
- if ($ret) {
- $data = ['userinfo' => $this->auth->getUserinfo()];
- $this->success(__('Sign up successful'), $data);
- } else {
- $this->error($this->auth->getError());
- }
- }
- /**
- * 注销登录
- */
- public function logout()
- {
- $this->auth->logout();
- $this->success(__('Logout successful'));
- }
- /**
- * 修改会员个人信息
- *
- * @param string $avatar 头像地址
- * @param string $username 用户名
- * @param string $nickname 昵称
- * @param string $bio 个人简介
- */
- public function profile()
- {
- $user = $this->auth->getUser();
- $username = $this->request->request('username');
- $nickname = $this->request->request('nickname');
- $bio = $this->request->request('bio');
- $avatar = $this->request->request('avatar', '', 'trim,strip_tags,htmlspecialchars');
- if ($username) {
- $exists = \app\common\model\User::where('username', $username)->where('id', '<>', $this->auth->id)->find();
- if ($exists) {
- $this->error(__('Username already exists'));
- }
- $user->username = $username;
- }
- $user->nickname = $nickname;
- $user->bio = $bio;
- $user->avatar = $avatar;
- $user->save();
- $this->success();
- }
- public function edituser()
- {
- $user = $this->auth->getUser();
- $nickname = $this->request->request('nickname');
- $birthday = $this->request->request('org');
- $gender = $this->request->request('sex');
- if ($nickname) {
- $user->nickname = $nickname;
- $user->save();
- $this->success();
- }
- if ($birthday) {
- $user->birthday = $birthday;
- $user->save();
- $this->success();
- }
- if ($gender >= 0) {
- $user->gender = $gender;
- $user->save();
- $this->success();
- }
- $this->error(__('修改失败'));
- }
- /**
- * 修改邮箱
- *
- * @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 $mobile 手机号
- * @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());
- }
- }
- public function tx()
- {
- $user = $this->auth->getUser();
- $site = config('site');
- $money = input('money');
- if ($money < $site['zstx']) {
- $this->error($site['txbz']);
- }
- if (!input('type')) {
- $this->error('请填写提现类型');
- }
- if (!input('name')) {
- $this->error('请填写提现名字');
- }
- if (!input('cord')) {
- $this->error('请填写提现帐号');
- }
- $user_id = $user['id'];
- if ($user && $money != 0) {
- if ($user->money < $money) {
- $this->error('余额不足');
- }
- $before = $user->money;
- $after = $user->money - $money;
- Db::startTrans();
- try {
- //更新会员信息
- $user->save(['money' => $after]);
- //写入日志
- MoneyLog::create(['user_id' => $user_id, 'money' => $money, 'before' => $before, 'after' => $after, 'memo' => '用户提现']);
- $site['txsxf'] = isset($site['txsxf']) ? $site['txsxf'] : 0;
- $sxf = $money * $site['txsxf'];
- $up = [
- 'uid' => $user_id,
- 'type' => input('type'),
- 'name' => input('name'),
- 'cord' => input('cord'),
- 'money' => $money,
- 'moneydz' => $money - $sxf,
- 'sxf' => $sxf,
- 'iscl' => 1,
- 'memo' => '用户提现'
- ];
- //写入提现记录
- Txjl::create($up);
- Db::commit();
- $this->success('提交成功');
- } catch (Exception $e) {
- Db::rollback();
- $this->error($e->getMessage());
- }
- } else {
- $this->error(__('金额不对'));
- }
- }
- public function txinfo()
- {
- $user = $this->auth->getUser();
- $this->relationSearch = true;
- //如果发送的来源是Selectpage,则转发到Selectpage
- if ($this->request->request('keyField')) {
- return $this->selectpage();
- }
- list($where, $sort, $order, $offset, $limit) = $this->buildparams();
- $map['uid'] = $user['id'];
- $total = Txjl::where($where)->where($map)->order($sort, $order)->count();
- $list = Txjl::where($where)->where($map)->order($sort, $order)->limit($offset, $limit)->select();
- if ($list) {
- foreach ($list as $k => $v) {
- $list[$k]['createtime'] = date('Y-m-d', $v['createtime']);
- }
- }
- $result = array("total" => $total, "rows" => $list);
- return json($result);
- }
- public function userscoreinfo()
- {
- $user = $this->auth->getUser();
- $this->relationSearch = true;
- //如果发送的来源是Selectpage,则转发到Selectpage
- if ($this->request->request('keyField')) {
- return $this->selectpage();
- }
- list($where, $sort, $order, $offset, $limit) = $this->buildparams();
- $map['user_id'] = $user['id'];
- $total = ScoreLog::where($where)->where($map)->order($sort, $order)->count();
- $list = ScoreLog::where($where)->where($map)->order($sort, $order)->limit($offset, $limit)->select();
- if ($list) {
- foreach ($list as $k => $v) {
- $list[$k]['createtime'] = date('Y-m-d H:i', $v['createtime']);
- if ($v['after'] > $v['before']) {
- $list[$k]['jzt'] = '+';
- } else if ($v['after'] == $v['before']) {
- $list[$k]['jzt'] = '';
- } else {
- $list[$k]['jzt'] = '-';
- }
- }
- }
- $result = array("total" => $total, "rows" => $list);
- return json($result);
- }
- public function usermoneyinfo()
- {
- $user = $this->auth->getUser();
- $this->relationSearch = true;
- //如果发送的来源是Selectpage,则转发到Selectpage
- if ($this->request->request('keyField')) {
- return $this->selectpage();
- }
- list($where, $sort, $order, $offset, $limit) = $this->buildparams();
- $map['user_id'] = $user['id'];
- $total = MoneyLog::where($where)->where($map)->order($sort, $order)->count();
- $list = MoneyLog::where($where)->where($map)->order($sort, $order)->limit($offset, $limit)->select();
- if ($list) {
- foreach ($list as $k => $v) {
- $list[$k]['createtime'] = date('Y-m-d H:i', $v['createtime']);
- if ($v['after'] > $v['before']) {
- $list[$k]['jzt'] = '+';
- } else if ($v['after'] == $v['before']) {
- $list[$k]['jzt'] = '';
- } else {
- $list[$k]['jzt'] = '-';
- }
- }
- }
- $result = array("total" => $total, "rows" => $list);
- return json($result);
- }
- public function userfxinfo()
- {
- $user = $this->auth->getUser();
- $this->relationSearch = true;
- //如果发送的来源是Selectpage,则转发到Selectpage
- if ($this->request->request('keyField')) {
- return $this->selectpage();
- }
- list($where, $sort, $order, $offset, $limit) = $this->buildparams();
- $map['user_id'] = $user['id'];
- $map['oid'] = ['>', 0];
- $total = MoneyLog::where($where)->where($map)->order($sort, $order)->count();
- $list = MoneyLog::where($where)->where($map)->order($sort, $order)->limit($offset, $limit)->select();
- if ($list) {
- foreach ($list as $k => $v) {
- $list[$k]['createtime'] = date('Y-m-d H:i', $v['createtime']);
- if ($v['after'] > $v['before']) {
- $list[$k]['jzt'] = '+';
- } else if ($v['after'] == $v['before']) {
- $list[$k]['jzt'] = '';
- } else {
- $list[$k]['jzt'] = '-';
- }
- }
- }
- $result = array("total" => $total, "rows" => $list);
- return json($result);
- }
- /**
- * 上传文件
- */
- public function upload()
- {
- return action('api/common/upload');
- }
- /**
- * 上传头像
- */
- public function avatar()
- {
- if (input('base64')) {
- return action('api/common/base64_image_content');
- }
- return action('api/common/uploadavatar');
- }
- public function paysj()
- {
- $site = config('site');
- $arr = [];
- if (isset($site['vipsj'])) {
- foreach ($site['vipsj'] as $k => $v) {
- //一年(¥80) num:'10',coupon:0
- $arr[] = ['num' => $k . '个月(¥' . $v . ')', 'coupon' => $k];
- }
- }
- $this->success('success', $arr);
- }
- public function taplove()
- {
- $up = [
- 'uid' => input('uid'),
- 'vid' => input('vid'),
- 'mid' => input('mid'),
- 'vtime' => 0,
- 'createtime' => time(),
- 'updatetime' => time(),
- ];
- $videolove = Db::name('videolove')->where(['uid' => input('uid'), 'vid' => input('vid'), 'mid' => input('mid')])->find();
- if ($videolove) {
- Db::name('videolove')->where(['id' => $videolove['id']])->delete();
- Db::name('videolist')->where(['id' => input('vid')])->setDec('give');
- $this->success('取消成功');
- } else {
- $id = Db::name('videolove')->insertGetId($up);
- Db::name('videolist')->where(['id' => input('vid')])->setInc('give');
- $this->success('点赞成功');
- }
- }
- public function videorecord()
- {
- $up = [
- 'uid' => input('uid'),
- 'vid' => input('vid'),
- 'mid' => input('mid'),
- 'vtime' => 0,
- 'createtime' => time(),
- 'updatetime' => time(),
- ];
- $videorecord = Db::name('videorecord')->where(['uid' => input('uid'), 'vid' => input('vid'), 'mid' => input('mid')])->find();
- if ($videorecord) {
- Db::name('videorecord')->where(['id' => $videorecord['id']])->delete();
- $this->success('取消成功');
- } else {
- $id = Db::name('videorecord')->insertGetId($up);
- $this->success('追剧成功');
- }
- }
- public function qingdao()
- {
- $times = date('Y-m-d', time());
- $qdjl = Db::name('qdjl')->where(['uid' => input('uid'), 'time' => $times])->find();
- $yesterday = date("Y-m-d", strtotime("-1 day"));
- $yesterdaydata = Db::name('qdjl')->where(['uid' => input('uid'), 'time' => $yesterday])->find();
- if ($yesterdaydata) {
- $sum = $yesterdaydata['sum'] + 1;
- $tdsy = $yesterdaydata['sy'] + 50;
- if ($sum >= 7) {//连续7天
- $sum = 1;
- }
- } else {
- $sum = 1;
- $tdsy = 100;
- }
- if ($qdjl) {
- $this->error('今日已经签到过了');
- }
- $up = [
- 'uid' => input('uid'),
- 'sy' => $tdsy,
- 'sum' => $sum,
- 'time' => $times,
- ];
- $this->qdmoney($sum);
- $id = Db::name('qdjl')->insertGetId($up);
- $this->success('签到成功');
- }
- public function vipsj()
- {
- $site = config('site');
- $num = input('num');
- if (!input('num')) {
- $this->error('请填选择会员升级期限');
- }
- if (isset($site['vipsj'])) {
- //var_dump();
- $money = $site['vipsj'][$num];
- $user = $this->auth->getUser();
- if ($user->money < $money) {
- $this->error('余额不足');
- }
- $before = $user->money;
- $after = $user->money - $money;
- Db::startTrans();
- try {
- //更新会员信息
- if ($user->dtime - time() <= 0 or $user->group_id == 1) {
- $timea = strtotime("+" . $num . " months", time());
- } else {
- $timea = strtotime("+" . $num . " months", $user->dtime);
- }
- $user->save(['money' => $after, 'group_id' => 2, 'stime' => time(), 'dtime' => $timea]);
- //写入日志
- MoneyLog::create(['user_id' => $user['id'], 'money' => $money, 'before' => $before, 'after' => $after, 'memo' => '会员升级']);
- $this->yongjin(1, $user['id'], $money, '级升级佣金结算');//佣金结算
- Db::commit();
- $this->success('升级成功', ['config' => $this->config(), 'userinfo' => $this->auth->getUserinfo()]);
- } catch (Exception $e) {
- Db::rollback();
- $this->error($e->getMessage());
- }
- }
- }
- public function kami()
- {
- $crd = input('crd');
- if (!$crd) {
- $this->error('请填写卡密');
- }
- $Kami = Kami::where(['crd' => $crd])->find();
- if (!$Kami) {
- $this->error('卡号不正确');
- }
- if ($Kami['type'] == 2) {
- $this->error('已经使用');
- }
- $money = $Kami['price'];
- $user = $this->auth->getUser();
- $before = $user->money;
- $after = $user->money + $money;
- Db::startTrans();
- try {
- //更新会员信息
- $user->save(['money' => $after]);
- //写入日志
- MoneyLog::create(['user_id' => $user['id'], 'money' => $money, 'before' => $before, 'after' => $after, 'memo' => '卡密充值']);
- Kami::where(['crd' => $crd])->update(['uid' => $user['id'], 'type' => 2, 'stime' => time()]);
- Db::commit();
- $data = ['config' => $this->config(), 'userinfo' => $this->auth->getUserinfo()];
- $this->success('充值成功', $data);
- } catch (Exception $e) {
- Db::rollback();
- $this->error($e->getMessage());
- }
- }
- public function getOpenid()
- {
- $site = config('site');
- $site['dltel'] = isset($site['dltel']) ? $site['dltel'] : -1;
- $code = input('code');//小程序传来的code值
- $appid = $site['weixinxcx']['appid'];//小程序的appid
- $appSecret = $site['weixinxcx']['appSecret'];// 小程序的$appSecret
- $wxUrl = 'https://api.weixin.qq.com/sns/jscode2session?appid=%s&secret=%s&js_code=%s&grant_type=authorization_code';
- $getUrl = sprintf($wxUrl, $appid, $appSecret, $code);//把appid,appsecret,code拼接到url里
- $result = $this->curl_get($getUrl);//请求拼接好的url
- $wxResult = json_decode($result, true);
- if (empty($wxResult)) {
- $this->error('获取openid时异常,微信内部错误');
- } else {
- $loginFail = array_key_exists('errcode', $wxResult);
- if ($loginFail) {//请求失败
- $this->error($wxResult);
- } else {//请求成功
- $openid = $wxResult['openid'];
- if ($site['dltel'] == 0) {//等于0的时候直接登录
- $users = \app\common\model\User::getByWxxopenid($openid);
- if ($users) {
- $this->auth->direct($users->id);
- $data = ['openid' => $openid, 'userinfo' => $this->auth->getUserinfo(), 'config' => $this->config()];
- $this->success(__('登录成功'), $data);
- }
- }
- $wxResult['dltel'] = $site['dltel'];
- $this->success('获取openid成功', $wxResult);
- }
- }
- }
- public function logingzh()
- {
- $openid = input('openid');
- $unionid = input('unionid');
- $users = \app\common\model\User::getByUnionid($unionid);
- //$users = \app\common\model\User::getByGzhopenid($openid);//仅仅公众号
- if ($users) {
- if ($users->status != 'normal') {
- $this->error(__('Account is locked'));
- }
- //如果已经有账号则直接登录
- $ret = $this->auth->direct($users->id);
- if ($ret) {
- \app\common\model\User::where(['id' => $users->id])->update(['gzhopenid' => $openid]);
- $data = ['userinfo' => $this->auth->getUserinfo(), 'config' => $this->config()];
- $this->success(__('Logged in successful'), $data);
- }
- } else {
- $pid = $this->request->request('pid');
- if (!$pid) {
- $pid = 1;
- }
- $usera = \app\common\model\User::getById($pid);
- if (!$usera) {
- $this->error(__('邀请码不正确'));
- }
- $mobile = $openid;
- $email = $mobile . '@100.com';
- $avatar = '/uploads/face/A' . rand(1, 96) . '.jpg';;
- $nickName = input('nickName', '公众号用户');
- $ret = $this->auth->register($mobile, '123456', $email, $mobile, ['wxxopenid' => $openid, 'unionid' => $unionid, 'nickname' => $nickName, 'avatar' => $avatar, 'pid' => $pid]);
- if ($ret) {
- $data = ['userinfo' => $this->auth->getUserinfo(), 'config' => $this->config()];
- $this->success(__('Sign up successful'), $data);
- } else {
- $this->error($this->auth->getError());
- }
- }
- }
- public function getphone()
- {
- $site = config('site');
- $dltel = isset($site['dltel']) ? $site['dltel'] : -1;
- if ($dltel == 0) {
- $openid = input('openid');
- $users = \app\common\model\User::getByWxxopenid($openid);
- if ($users) {
- $this->auth->direct($users->id);
- $data = ['userinfo' => $this->auth->getUserinfo(), 'config' => $this->config()];
- $this->success(__('登录成功'), $data);
- } else {
- $pid = $this->request->request('pid');
- if (!$pid) {
- $pid = 1;
- }
- $usera = \app\common\model\User::getById($pid);
- if (!$usera) {
- $this->error(__('邀请码不正确'));
- }
- //$number = date('ymdh', time()) . rand(10000, 99999);
- $mobile = $openid;
- $email = $mobile . '@100.com';
- $avatar = input('avatarUrl');
- $nickName = input('nickName');
- $ret = $this->auth->register($mobile, '123456', $email, $mobile, ['wxxopenid' => $openid, 'nickname' => $nickName, 'avatar' => $avatar, 'pid' => $pid]);
- if ($ret) {
- $users = $this->auth->getUserinfo();
- //var_dump($users);
- $idsa = $users['id'];
- \app\common\model\User::where(['id' => $idsa])->update(['mobile' => 'user_' . $idsa, 'email' => 'user_' . $idsa . '@100.com', 'username' => 'user_' . $idsa]);
- $data = ['userinfo' => $users, 'config' => $this->config()];
- $this->success(__('Sign up successful'), $data);
- } else {
- $this->error($this->auth->getError());
- }
- }
- }
- $APPID = $site['weixinxcx']['appid'];//小程序的appid
- $AppSecret = $site['weixinxcx']['appSecret'];// 小程序的$appSecret
- if (!input('code')) {
- $this->error('code出错');
- exit;
- }
- $code = input('code');
- $url = "https://api.weixin.qq.com/sns/jscode2session?appid=" . $APPID . "&secret=" . $AppSecret . "&js_code=" . $code . "&grant_type=authorization_code";
- $arr = $this->vget($url); // 一个使用curl实现的get方法请求
- $arr = json_decode($arr, true);
- $session_key = $arr['session_key'];
- $openid = $arr['openid'];
- $unionid = isset($arr['unionid']) ? $arr['unionid'] : null;
- Vendor("wxBizData.wxBizDataCrypt"); //加载解密文件,在官方有下载
- $pc = new \WXBizDataCrypt($APPID, $session_key);
- $iv = input('iv');
- $encryptedData = input('encryptedData');
- $errCode = $pc->decryptData($encryptedData, $iv, $data);
- if ($errCode == 0) {
- //print($data . "\n");
- //dump($arr);
- $phone = json_decode($data, true);
- if ($phone['purePhoneNumber']) {
- //$users = \app\common\model\User::getByMobile($phone['purePhoneNumber']);
- $user = \app\common\model\User::getByUnionid($unionid);
- if ($user) {
- if ($user->status != 'normal') {
- $this->error(__('Account is locked'));
- }
- //如果已经有账号则直接登录
- $ret = $this->auth->direct($user->id);
- if ($ret) {
- $data = ['userinfo' => $this->auth->getUserinfo(), 'config' => $this->config()];
- \app\common\model\User::where(['id' => $user->id])->update(['mobile' => $phone['purePhoneNumber'], 'wxxopenid' => $openid, 'unionid' => $unionid]);
- $this->success(__('Logged in successful'), $data);
- }
- } else {
- $users = \app\common\model\User::getByMobile($phone['purePhoneNumber']);
- if ($users) {
- if ($users->status != 'normal') {
- $this->error(__('Account is locked'));
- }
- //如果已经有账号则直接登录
- $ret = $this->auth->direct($users->id);
- if ($ret) {
- $data = ['userinfo' => $this->auth->getUserinfo(), 'config' => $this->config()];
- \app\common\model\User::where(['id' => $users->id])->update(['mobile' => $phone['purePhoneNumber'], 'wxxopenid' => $openid, 'unionid' => $unionid]);
- $this->success(__('Logged in successful'), $data);
- }
- } else {
- $pid = $this->request->request('pid');
- if (!$pid) {
- $pid = 1;
- }
- $usera = \app\common\model\User::getById($pid);
- if (!$usera) {
- $this->error(__('邀请码不正确'));
- }
- $mobile = $phone['purePhoneNumber'];
- $email = $mobile . '@100.com';
- $avatar = input('avatarUrl');
- $nickName = input('nickName');
- $ret = $this->auth->register($mobile, '123456', $email, $mobile, ['wxxopenid' => $openid, 'unionid' => $unionid, 'nickname' => $nickName, 'avatar' => $avatar, 'pid' => $pid]);
- if ($ret) {
- $data = ['userinfo' => $this->auth->getUserinfo(), 'config' => $this->config()];
- $this->success(__('Sign up successful'), $data);
- } else {
- $this->error($this->auth->getError());
- }
- }
- }
- }
- } else {
- $this->error($errCode);
- }
- }
- public function qdmoney($money)
- {
- $site = config('site');
- $user = $this->auth->getUser();
- if ($user && $money != 0) {
- $before = $user->money;
- $after = $user->money + $money;
- //更新会员信息
- $user->save(['score' => $after]);
- //写入日志
- ScoreLog::create(['user_id' => $user->id, 'score' => $money, 'before' => $before, 'after' => $after, 'memo' => '签到赠送']);
- } else {
- $this->error(__('金额不对'));
- }
- }
- public function admoney()
- {
- $site = config('site');
- $money = isset($site['admoney']) ? $site['admoney'] : 0.01;
- $user = $this->auth->getUser();
- if ($user && $money != 0) {
- $before = $user->money;
- $after = $user->money + $money;
- //更新会员信息
- $user->save(['money' => $after]);
- //写入日志
- MoneyLog::create(['user_id' => $user->id, 'money' => $money, 'before' => $before, 'after' => $after, 'fid' => 0, 'sxf' => 0, 'memo' => '看广告赠送']);
- $this->success('获取成功', $this->config());
- } else {
- $this->error(__('金额不对'));
- }
- }
- /**
- * @Author : kiven
- * @Description:curl模拟请求方法
- * @LastModify : kiven
- * @param $url
- * @return bool|string
- */
- public function vget($url)
- {
- $info = curl_init();
- curl_setopt($info, CURLOPT_RETURNTRANSFER, true);
- curl_setopt($info, CURLOPT_HEADER, 0);
- curl_setopt($info, CURLOPT_NOBODY, 0);
- curl_setopt($info, CURLOPT_SSL_VERIFYPEER, false);
- curl_setopt($info, CURLOPT_SSL_VERIFYHOST, false);
- curl_setopt($info, CURLOPT_URL, $url);
- $output = curl_exec($info);
- curl_close($info);
- return $output;
- }
- //php请求网络的方法
- public function curl_get($url, &$httpCode = 0)
- {
- $ch = curl_init();
- curl_setopt($ch, CURLOPT_URL, $url);
- curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
- //不做证书校验,部署在linux环境下请改为true
- curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
- curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 10);
- $file_contents = curl_exec($ch);
- $httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
- curl_close($ch);
- return $file_contents;
- }
- }
|