| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116 |
- <?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')&&!input('img')) {
- $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'),
- 'img' => input('img'),
- '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;
- }
- }
|