123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671 |
- <?php
- namespace app\api\controller;
- use app\common\controller\Api;
- use app\common\library\Ems;
- use app\common\library\Sms;
- use fast\Random;
- use think\Config;
- use think\Validate;
- use think\Db;
- use wxpay;
- class User extends Api
- {
- protected $noNeedLogin = ['login', 'mobilelogin', 'register', 'registercheck', 'resetpwd', 'changeemail', 'changemobile', 'third', 'getopenid', 'getagreement', 'wxlogin'];
- protected $noNeedRight = '*';
- public function _initialize()
- {
- parent::_initialize();
- if (!Config::get('fastadmin.usercenter')) {
- $this->error(__('User center already closed'));
- }
- }
-
- public function index()
- {
- $this->success('', ['welcome' => $this->auth->nickname]);
- }
-
- public function login()
- {
- $account = $this->request->post('account');
- $password = $this->request->post('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());
- }
- }
-
- public function mobilelogin()
- {
- $mobile = $this->request->post('mobile');
- $captcha = $this->request->post('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) {
- $this->error('用户尚未注册');
- }
- if ($user['status'] != 1) {
- $this->error(__('Account is locked'));
- }
- $ret = $this->auth->direct($user->id);
- if ($ret) {
- Sms::flush($mobile, 'mobilelogin');
- $data = ['userinfo' => $this->auth->getUserinfo()];
- $this->success(__('Logged in successful'), $data);
- } else {
- $this->error($this->auth->getError());
- }
- }
-
-
-
- public function registercheck()
- {
- $mobile = $this->request->post('mobile');
- $code = $this->request->post('code');
- $password = $this->request->post('password');
- $repassword = $this->request->post('repassword', '' , 'trim');
- if (!Validate::regex($mobile, "^1\d{10}$")) {
- $this->error(__('Mobile is incorrect'));
- }
- $count = Db::name('user')->where(['mobile' => $mobile])->count('id');
- if (!$count) {
- $this->error('手机号已被注册');
- }
- if (iconv_strlen($code, 'utf-8') != config('alisms.length')) {
- $this->error(__('Captcha is incorrect'));
- }
- $ret = Sms::check($mobile, $code, 'register');
- if (!$ret) {
- $this->error(__('Captcha is incorrect'));
- }
- if (!$password) {
- $this->error('请输入新密码');
- }
-
- if (!Validate::make()->check(['newpassword' => $password], ['newpassword' => 'require|regex:\S{6,30}'])) {
- $this->error(__('Password must be 6 to 30 characters'));
- }
- if (!$repassword) {
- $this->error('请再次输入密码');
- }
- if ($repassword != $password) {
- $this->error('两次密码不一致');
- }
- $this->success('验证通过');
- }
-
- public function logout()
- {
- if (!$this->request->isPost()) {
- $this->error(__('Invalid parameters'));
- }
- $this->auth->logout();
- $this->success(__('Logout successful'));
- }
-
- public function getinfo()
- {
-
- $this->checklogingrowth($this->auth->id);
-
- $this->checkviplevel($this->auth->id);
- $user = Db::name('user')->find($this->auth->id);
- $data['nickname'] = $user['nickname'];
- $data['username'] = $user['username'];
- $data['avatar'] = cdnurl($user['avatar']);
- $data['mobile'] = $user['mobile'];
- $data['money'] = $user['money'];
- $data['realname'] = $user['realname'];
- $data['gender'] = $user['gender'];
- $data['birthday'] = date('Y-m-d', $user['birthday']);
- $data['idcard'] = $user['idcard'];
- $data['passport'] = $user['passport'];
- $data['emergencycontact'] = $user['emergencycontact'];
- $data['contactmobile'] = $user['contactmobile'];
- $data['outdoorduration'] = $user['outdoorduration'];
- $data['maxlevel'] = $user['maxlevel'];
- $data['viplevel'] = Db::name('vip')->where(['id' => $user['maxlevel']])->value('level');
- $data['active_count'] = Db::name('active_order')->where(['user_id' => $this->auth->id, 'status' => 2])->count('id');
- $data['freenumber'] = $user['freenumber'];
- $this->success('会员信息', $data);
- }
-
- public function profile()
- {
- $avatar = $this->request->post('avatar', '', 'trim,strip_tags,htmlspecialchars');
- $nickname = $this->request->post('nickname', '', 'trim');
- $realname = $this->request->post('realname', '', 'trim');
- $idcard = $this->request->post('idcard', '', 'trim,strip_tags,htmlspecialchars');
- $passport = $this->request->post('passport', '', 'trim,strip_tags,htmlspecialchars');
- $emergencycontact = $this->request->post('emergencycontact', '', 'trim');
- $contactmobile = $this->request->post('contactmobile', '', 'trim');
- $outdoorduration = $this->request->post('outdoorduration', '', 'trim');
- $birthday = $this->request->post('birthday', '', 'strtotime');
- $gender = $this->request->post('gender', 0, 'intval');
- $data = [];
- if ($avatar) {
- if (iconv_strlen($avatar, 'utf-8') > 255) {
- $this->error('图片超出范围');
- }
- $data['avatar'] = $avatar;
- }
- if ($nickname) {
- if (iconv_strlen($nickname, 'utf-8') > 30) {
- $this->error('昵称最多30字');
- }
- $data['nickname'] = $nickname;
- }
- if ($realname) {
- if(iconv_strlen($realname, 'utf-8') > 30) {
- $this->error('真实姓名最多30字');
- }
- $data['realname'] = $realname;
- }
- if ($idcard) {
- if (iconv_strlen($idcard, 'utf-8') != 18) {
- $this->error('身份证号错误');
- }
- $data['idcard'] = $idcard;
- }
- if ($passport) {
- if (iconv_strlen($passport, 'utf-8') > 30) {
- $this->error('护照号错误');
- }
- $data['passport'] = $passport;
- }
- if ($emergencycontact) {
- if(iconv_strlen($emergencycontact, 'utf-8') > 30) {
- $this->error('紧急联系人最多30字');
- }
- $data['emergencycontact'] = $emergencycontact;
- }
- if ($contactmobile) {
- if(!is_mobile($contactmobile)) {
- $this->error('请输入正确紧急联系方式');
- }
- $data['contactmobile'] = $contactmobile;
- }
- if ($outdoorduration) {
- if(iconv_strlen($outdoorduration, 'utf-8') > 50) {
- $this->error('户外时长最多50字');
- }
- $data['outdoorduration'] = $outdoorduration;
- }
- if ($birthday) {
- $data['birthday'] = $birthday;
- }
- if (in_array($gender, [1, 2])) {
- $data['gender'] = $gender;
- }
- if (!$data) {
- $this->error('暂无修改内容');
- }
-
- $rt = Db::name('user')->where(['id' => $this->auth->id])->setField($data);
- if ($rt === false) {
- $this->error('修改失败');
- }
- $this->success('修改成功');
- }
-
-
- public function changeavatar()
- {
- $avatar = input('avatar', '', 'trim');
- if (!$avatar) {
- $this->error('请上传头像');
- }
- if (iconv_strlen($avatar, 'utf-8') > 255) {
- $this->error('头像长度超出限制');
- }
- $rs = Db::name('user')->where(['id' => $this->auth->id])->setField('avatar', $avatar);
- if (!$rs) {
- $this->error('修改失败');
- }
- $this->success('修改成功');
- }
-
- public function changeemail()
- {
- $user = $this->auth->getUser();
- $email = $this->request->post('email');
- $captcha = $this->request->post('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();
- }
-
- public function changemobile()
- {
- $user = $this->auth->getUser();
- $code = $this->request->post('code');
- $mobile = $this->request->post('mobile');
- $captcha = $this->request->post('captcha');
- if (!$code || !$mobile || !$captcha) {
- $this->error(__('Invalid parameters'));
- }
- if ($mobile == $user->mobile) {
- $this->error('手机号没有改变');
- }
- $result = Sms::check($user->mobile, $code, 'changemobile');
- if (!$result) {
- $this->error(__('Captcha is incorrect'));
- }
- 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(__('手机号已存在'));
- }
- $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($user->mobile, 'changemobile');
- Sms::flush($mobile, 'changemobile');
- $this->success('修改成功');
- }
-
- public function third()
- {
- $url = url('user/index');
- $platform = $this->request->post("platform");
- $code = $this->request->post("code");
- $config = get_addon_config('third');
- if (!$config || !isset($config[$platform])) {
- $this->error(__('Invalid parameters'));
- }
- $app = new \addons\third\library\Application($config);
-
- $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);
- }
-
- public function resetpwd()
- {
- $type = 'mobile';
- $mobile = $this->request->post("mobile");
- $email = $this->request->post("email");
- $newpassword = $this->request->post("newpassword");
- $repassword = $this->request->post('repassword', '' , 'trim');
- $captcha = $this->request->post("captcha");
- if (!$newpassword || !$captcha || !$repassword) {
- $this->error(__('Invalid parameters'));
- }
-
- if (!Validate::make()->check(['newpassword' => $newpassword], ['newpassword' => 'require|regex:\S{6,30}'])) {
- $this->error(__('Password must be 6 to 30 characters'));
- }
- if ($repassword != $newpassword) {
- $this->error('两次密码不一致');
- }
- 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 editpwd()
- {
- $captcha = $this->request->post("captcha", '', 'trim');
- $newpassword = $this->request->post("newpassword", '' , 'trim');
- $repassword = $this->request->post('repassword', '' , 'trim');
- if (iconv_strlen($captcha, 'utf-8') != config('alisms.length')) {
- $this->error(__('Captcha is incorrect'));
- }
- if (!$newpassword) {
- $this->error('请输入新密码');
- }
-
- if (!Validate::make()->check(['newpassword' => $newpassword], ['newpassword' => 'require|regex:\S{6,30}'])) {
- $this->error(__('Password must be 6 to 30 characters'));
- }
- if (!$repassword) {
- $this->error('请再次输入密码');
- }
- if ($repassword != $newpassword) {
- $this->error('两次密码不一致');
- }
- $ret = Sms::check($this->auth->mobile, $captcha, 'changepwd');
- if (!$ret) {
- $this->error(__('Captcha is incorrect'));
- }
-
- $this->auth->direct($this->auth->id);
- $ret = $this->auth->changepwd($newpassword, '', true);
- if ($ret) {
- Sms::flush($this->auth->mobile, 'changepwd');
- $this->success(__('Reset password successful'));
- } else {
- $this->error($this->auth->getError());
- }
- }
-
-
- public function get_businessinfo()
- {
- $data = Db::name('user_business_info')->field('manage, mobile, province, city, area, distribution_channel')
- ->where(['user_id' => $this->auth->id])->find();
- $this->success('经营信息', $data);
- }
-
- public function editbusinessinfo()
- {
- $manage = $this->request->post('manage', '', 'trim');
- $mobile = $this->request->post('mobile', '', 'trim');
- $province = $this->request->post('province', '', 'trim');
- $city = $this->request->post('city', '', 'trim');
- $area = $this->request->post('area', '', 'trim');
- $distribution_channel = $this->request->post('distribution_channel', '', 'trim');
- $data = [];
- if ($manage) {
- if (iconv_strlen($manage, 'utf-8') > 50) {
- $this->error('采购负责人最多50字');
- }
- $data['manage'] = $manage;
- }
- if ($mobile) {
- if (!Validate::regex($mobile, "^1\d{10}$")) {
- $this->error(__('Mobile is incorrect'));
- }
- $data['mobile'] = $mobile;
- }
- if ($province && $city && $area) {
- $data['province'] = $province;
- $data['city'] = $city;
- $data['area'] = $area;
- }
- if ($distribution_channel) {
- if (iconv_strlen($distribution_channel, 'utf-8') > 255) {
- $this->error('销售渠道说明最多50字');
- }
- $data['distribution_channel'] = $distribution_channel;
- }
- if (!$data) {
- $this->error('暂无修改内容');
- }
- $count = Db::name('user_business_info')->where(['user_id' => $this->auth->id])->count();
- if ($count) {
- $data['updatetime'] = time();
- $rs = Db::name('user_business_info')->where(['user_id' => $this->auth->id])->setField($data);
- } else {
- $data['user_id'] = $this->auth->id;
- $data['createtime'] = time();
- $rs = Db::name('user_business_info')->insertGetId($data);
- }
- if (!$rs) {
- $this->error('修改失败');
- }
- $this->success('修改成功');
- }
-
- public function getpigcar()
- {
- $data = Db::name('user_pig_car')->where(['user_id' => $this->auth->id])->select();
- $data = list_domain_image($data, ['images']);
- $this->success('查询猪车信息', $data);
- }
-
- public function addpigcar()
- {
- $pig_car = input('pig_car', '', 'trim');
- if (!$pig_car) {
- $this->error('请添加猪车信息');
- }
- $pig_car = json_decode($pig_car, true);
- if (!$pig_car) {
- $this->error('请添加猪车信息');
- }
- if (count($pig_car) > 9) {
- $this->error('一次最多添加9条记录');
- }
- $_data = [];
- foreach ($pig_car as &$v) {
- $data = [];
- if (!$v['carnumber']) {
- $this->error('请输入车牌号');
- break;
- }
- if (iconv_strlen($v['carnumber'], 'utf-8') > 50) {
- $this->error('车牌号最多50字');
- break;
- }
- if (!$v['carframenumber']) {
- $this->error('请输入车架号');
- break;
- }
- if (iconv_strlen($v['carframenumber'], 'utf-8') > 50) {
- $this->error('车架号最多50字');
- break;
- }
- if ($v['images']) {
- $image_arr = explode(',', $v['images']);
- if (count($image_arr) > 9) {
- $this->error('每辆车照片最多9张');
- break;
- }
- $data['images'] = $v['images'];
- }
- $data['user_id'] = $this->auth->id;
- $data['carnumber'] = $v['carnumber'];
- $data['carframenumber'] = $v['carframenumber'];
- $data['createtime'] = time();
- array_push($_data, $data);
- }
- $rs = Db::name('user_pig_car')->insertAll($_data);
- if (!$rs) {
- $this->error('添加失败');
- }
- $this->success('添加成功');
- }
-
- public function delpigcar()
- {
- $id = input('id', 0, 'intval');
- if (!$id) {
- $this->error('请选择要删除的猪车');
- }
- $info = Db::name('user_pig_car')->where(['id' => $id, 'user_id' => $this->auth->id])->find();
- if (!$info) {
- $this->error('这不是您的车');
- }
- $rs = Db::name('user_pig_car')->where(['id' => $id, 'user_id' => $this->auth->id])->delete();
- if (!$rs) {
- $this->error('删除失败');
- }
- $this->success('删除成功');
- }
-
- public function getabout()
- {
- $info = Db::name('platform_info')->field('title, content')->where(['type' => 1])->find();
- $this->success('平台介绍', $info);
- }
-
- public function problem()
- {
- $list = Db::name('problem')->field('id, title, content')
- ->page($this->page, config('paginate.list_rows'))->order('weigh', 'desc')->select();
- $this->success('常见问题', $list);
- }
-
- public function complainttype()
- {
- $list = Db::name('complaint_type')->field('id, name')->where(['pid' => 0])->order('weigh', 'desc')->select();
- $list = $this->getchildtype($list);
- $this->success('常见问题', $list);
- }
-
- public function getchildtype($list = [])
- {
- $complaint_type = Db::name('complaint_type');
- foreach ($list as &$v) {
- $child = $complaint_type->field('id, name')->where(['pid' => $v['id']])->order('weigh', 'desc')->select();
- if ($child) {
- $child = $this->getchildtype($child);
- }
- $v['child'] = $child;
- }
- return $list;
- }
-
- public function complaint()
- {
- $complaint_type = input('complaint_type', '', 'trim');
- $order_sn = input('order_sn', '', 'trim');
- $be_complaint_user = input('be_complaint_user', '', 'trim');
- $complaint_user = input('complaint_user', '', 'trim');
- $mobile = input('mobile', '', 'trim');
- $code = input('code', '', 'trim');
- $content = input('content', '', 'trim');
- $images = input('images', '', 'trim');
- $data = [];
- if (!$complaint_type) {
- $this->error('请选择投诉类型');
- }
- if ($order_sn) {
- if (iconv_strlen($order_sn, 'utf-8') > 255) {
- $this->error('订单号最多255位');
- }
-
- $count = Db::name('mark_bid')->where(['user_id' => $this->auth->id, 'order_sn' => $order_sn, 'status' => 1])->count();
- if (!$count) {
- $this->error('请输入正确中标订单号');
- }
- }
- if (!$be_complaint_user) {
- $this->error('请输入被投诉人/单位');
- }
- if (iconv_strlen($be_complaint_user, 'utf-8') > 50) {
- $this->error('被投诉人/单位最多50字');
- }
- if (!$complaint_user) {
- $this->error('请输入投诉人');
- }
- if (iconv_strlen($complaint_user, 'utf-8') > 50) {
- $this->error('投诉人最多50字');
- }
- if (!is_mobile($mobile)) {
- $this->error('请输入正确联系电话');
- }
- if (iconv_strlen($code, 'utf-8') != config('alisms.length')) {
- $this->error(__('Captcha is incorrect'));
- }
- $ret = Sms::check($mobile, $code, 'complaint');
- if (!$ret) {
- $this->error(__('Captcha is incorrect'));
- }
- if (!$content) {
- $this->error('请输入情况说明');
- }
- if (iconv_strlen($content, 'utf-8') > 3000) {
- $this->error('情况说明最多3000字');
- }
- if ($images) {
- $image_arr = explode(',', $images);
- if (count($image_arr) > 9) {
- $this->error('附件照片最多9张');
- }
- $data['images'] = $images;
- }
- $data['user_id'] = $this->auth->id;
- $data['complaint_type'] = $complaint_type;
- $data['order_sn'] = $order_sn;
- $data['be_complaint_user'] = $be_complaint_user;
- $data['complaint_user'] = $complaint_user;
- $data['mobile'] = $mobile;
- $data['content'] = $content;
- $data['images'] = $images;
- $data['createtime'] = time();
- $rs = Db::name('complaint')->insertGetId($data);
- if (!$rs) {
- $this->error('投诉失败');
- }
- Sms::flush($this->auth->mobile, 'complaint');
- $this->success('投诉成功');
- }
-
- public function getmarkcomment()
- {
- $list = Db::name('mark_bid_comment')->where(['user_id' => $this->auth->id])
- ->page($this->page, config('paginate.list_rows'))->order('createtime', 'desc')->select();
- $list = list_domain_image($list, ['images']);
- $mark = Db::name('mark');
- $mark_bid = Db::name('mark_bid');
- foreach ($list as &$v) {
- $v['mark'] = $mark->find($v['mark_id']);
- $v['mark'] = info_domain_image($v['mark'], ['image', 'video', 'defective_images', 'road_images', 'pig_out_images']);
- $v['order_sn'] = $mark_bid->where(['id' => $v['mark_bid_id']])->value('order_sn');
- }
- $this->success('评论列表', $list);
- }
-
- public function markcomment()
- {
- $mark_id = input('mark_id', 0, 'intval');
- $content = input('content', '', 'trim');
- $images = input('images', '', 'trim');
- $data = [];
- if (!$mark_id) {
- $this->error('请选择要评价的数据');
- }
- $info = Db::name('mark')->find($mark_id);
- if (!$info) {
- $this->error('招标信息不存在');
- }
- $bid_id = Db::name('mark_bid')->where(['user_id' => $this->auth->id, 'mark_id' => $mark_id, 'status' => 1])->value('id');
- if (!$bid_id) {
- $this->error('您未中标,暂不能评价');
- }
- if (!$content) {
- $this->error('请输入评价内容');
- }
- if (iconv_strlen($content, 'utf-8') > 3000) {
- $this->error('评价内容最多3000字');
- }
- if ($images) {
- $image_arr = explode(',', $images);
- if (count($image_arr) > 9) {
- $this->error('照片最多9张');
- }
- $data['images'] = $images;
- }
- $data['user_id'] = $this->auth->id;
- $data['mark_id'] = $mark_id;
- $data['mark_bid_id'] = $bid_id;
- $data['content'] = $content;
- $data['images'] = $images;
- $data['createtime'] = time();
- $rs = Db::name('mark_bid_comment')->insertGetId($data);
- if (!$rs) {
- $this->error('评价失败');
- }
- $this->success('评价成功');
- }
-
- public function getcompanymoney()
- {
- $list = Db::name('company')->field('id, name')->page($this->page, config('paginate.list_rows'))->select();
- $company_money_log = Db::name('company_money_log');
- foreach ($list as &$v) {
- $log = $company_money_log->where(['company_id' => $v['id'], 'user_id' => $this->auth->id])->order('id', 'desc')->find();
- if ($log) {
- $v['money'] = $log['after'];
- $v['can_money'] = $log['after'];
- } else {
- $v['money'] = '0';
- $v['can_money'] = '0';
- }
- }
- $this->success('个人账单列表', $list);
- }
-
- public function getcompanymoneydetail()
- {
- $company_id = input('company_id', 0, 'intval');
- $start_time = input('start_time', 0, 'strtotime');
- $end_time = input('end_time', 0, 'strtotime');
- if (!$company_id) {
- $this->error('参数缺失');
- }
- $where['company_id'] = $company_id;
- $where['user_id'] = $this->auth->id;
- if ($start_time && $end_time) {
- $where['createtime'] = ['between', [$start_time, $end_time]];
- }
- $list = Db::name('company_money_log')->field('id, money, memo, createtime')
- ->where($where)->page($this->page, config('paginate.list_rows'))->order('id', 'desc')->select();
- foreach ($list as &$v) {
- $v['createtime'] = date('Y-m-d H:i:s', $v['createtime']);
- }
- $data['income'] = Db::name('company_money_log')->where($where)->where(['money' => ['gt', 0]])->sum('money');
- $data['expend'] = Db::name('company_money_log')->where($where)->where(['money' => ['lt', 0]])->sum('money');
- $data['list'] = $list;
- $this->success('个人账单明细', $data);
- }
-
- public function getagreement()
- {
- $type = input('type', 0, 'intval');
- if (!in_array($type, [1, 2, 3, 4])) {
- $this->error('参数错误');
- }
- $info = Db::name('platform_info')->field('title, content')->where(['type' => $type])->find();
- $this->success('协议', $info);
- }
-
- public function getopenid() {
-
- $code = $this->request->param('code', '', 'trim');
- if (!$code) {
- $this->error(__('Invalid parameters'));
- }
- $config = config('wxchatpay');
- $getopenid_url = 'https://api.weixin.qq.com/sns/jscode2session?appid='.$config['app_id'].'&secret='.$config['app_secret'].'&js_code='.$code.'&grant_type=authorization_code';
- $openidInfo = httpRequest($getopenid_url, 'GET');
- $openidInfo = json_decode($openidInfo,true);
- if(!isset($openidInfo['openid'])) {
- $this->error('用户openid获取失败', $openidInfo);
- }
- $this->success('success', $openidInfo);
- }
-
- public function wxlogin() {
- $openid = input('openid', '', 'trim');
- if (!$openid) {
- $this->error('参数缺失');
- }
- $user = \app\common\model\User::getByOpenid($openid);
- if (!$user) {
- $this->success('用户尚未注册', ['code' => 5]);
- }
- if ($user['status'] != 1) {
- $this->error(__('Account is locked'));
- }
- $ret = $this->auth->direct($user->id);
- if ($ret) {
- $data = ['userinfo' => $this->auth->getUserinfo()];
- $this->success(__('Logged in successful'), $data);
- } else {
- $this->error($this->auth->getError());
- }
- }
-
- public function register()
- {
- $mobile = $this->request->post('mobile', '', 'trim');
- $code = $this->request->post('code', '', 'trim');
- $birthday = $this->request->post('birthday', '', 'strtotime');
- $gender = $this->request->post('gender', 0, 'intval');
- $invite_no = $this->request->post('invite_no', '', 'trim');
- $openid = $this->request->post('openid', '', 'trim');
- $nickname = $this->request->post('nickname', '', 'trim');
- $avatar = $this->request->post('avatar', '', 'trim,strip_tags,htmlspecialchars');
- $openidcount = Db::name('user')->where(['openid' => $openid])->count('id');
- if ($openidcount) {
- $this->error('微信已经注册,请直接登录');
- }
- if (!Validate::regex($mobile, "^1\d{10}$")) {
- $this->error(__('Mobile is incorrect'));
- }
- $count = Db::name('user')->where(['mobile' => $mobile])->count('id');
- if ($count) {
- $this->error('手机号已被注册');
- }
- if (iconv_strlen($code, 'utf-8') != config('alisms.length')) {
- $this->error(__('Captcha is incorrect'));
- }
- $ret = Sms::check($mobile, $code, 'register');
- if (!$ret) {
- $this->error(__('Captcha is incorrect'));
- }
- if (!$birthday || $birthday >= time()) {
- $this->error('请选择正确生日');
- }
- if (!in_array($gender, [1, 2])) {
- $this->error('请选择性别');
- }
- if ($invite_no) {
- $invite_info = Db::name('user')->where(['invite_no' => $invite_no])->find();
- if (!$invite_info) {
- $this->error('邀请码不存在');
- }
- }
- if (!$nickname || !$avatar) {
- $this->error('参数缺失');
- }
- if (iconv_strlen($nickname, 'utf-8') > 30 || iconv_strlen($avatar, 'utf-8') > 255) {
- $this->error('参数错误');
- }
- $ip = request()->ip();
- $time = time();
- $data = [
- 'nickname' => $nickname,
- 'salt' => Random::alnum(),
- 'mobile' => $mobile,
- 'avatar' => $avatar,
- 'joinip' => $ip,
- 'jointime' => $time,
- 'logintime' => $time,
- 'loginip' => $ip,
- 'prevtime' => $time,
- 'createtime' => $time,
- 'gender' => $gender,
- 'birthday' => $birthday,
- 'openid' => $openid,
- 'invite_no' => $this->myinvite(),
- 'pre_user_id' => isset($invite_info) ? $invite_info['id'] : 0,
- 'invite_time' => $time,
- ];
-
- Db::startTrans();
- $rs = Db::name('user')->insertGetId($data);
- if (!$rs) {
- Db::rollback();
- $this->error('注册失败');
- }
-
- $username = $this->myuid($rs);
- $rt = Db::name('user')->where(['id' => $rs])->setField('username', $username);
- if (!$rt) {
- Db::rollback();
- $this->error('注册失败');
- }
-
- $register_coupon = Db::name('coupon')->where(['purpose' => 1, 'status' => 1])->order('weigh desc, id desc')->find();
- if ($register_coupon) {
- $register_coupon_data = [
- 'user_id' => $rs,
- 'coupon_id' => $register_coupon['id'],
- 'title' => $register_coupon['title'],
- 'desc' => $register_coupon['desc'],
- 'type' => $register_coupon['type'],
- 'money' => $register_coupon['money'],
- 'minmoney' => $register_coupon['minmoney'],
- 'purpose' => $register_coupon['purpose'],
- 'starttime' => time(),
- 'endtime' => time() + $register_coupon['effectiveday'] * 86400,
- 'createtime' => time()
- ];
- $register_coupon_rs = Db::name('user_coupon')->insertGetId($register_coupon_data);
- if (!$register_coupon_rs) {
- Db::rollback();
- $this->error('注册失败');
- }
- }
-
- if (isset($invite_info)) {
-
- $last_coupon = Db::name('user_coupon')->where(['user_id' => $invite_info['id'], 'purpose' => 2])->order('id', 'desc')->find();
- $last_coupon_time = $last_coupon ? $last_coupon['createtime'] : 0;
-
- $invitepersonnum = (int)config('site.invitepersonnum');
-
- $invite_count = Db::name('user')->where(['pre_user_id' => $invite_info['id'], 'createtime' => ['gt', $last_coupon_time]])->count();
- if ($invite_count >= $invitepersonnum && $invitepersonnum > 0) {
-
-
- $invite_coupon = Db::name('coupon')->where(['purpose' => 2, 'status' => 1])->order('weigh desc, id desc')->find();
- if ($invite_coupon) {
- $invite_coupon_data = [
- 'user_id' => $invite_info['id'],
- 'coupon_id' => $invite_coupon['id'],
- 'title' => $invite_coupon['title'],
- 'desc' => $invite_coupon['desc'],
- 'type' => $invite_coupon['type'],
- 'money' => $invite_coupon['money'],
- 'minmoney' => $invite_coupon['minmoney'],
- 'purpose' => $invite_coupon['purpose'],
- 'starttime' => time(),
- 'endtime' => time() + $invite_coupon['effectiveday'] * 86400,
- 'createtime' => time()
- ];
- $invite_coupon_rs = Db::name('user_coupon')->insertGetId($invite_coupon_data);
- if (!$invite_coupon_rs) {
- Db::rollback();
- $this->error('注册失败');
- }
- }
- }
- }
- Db::commit();
- $ret = $this->auth->direct($rs);
- if ($ret) {
- $data = ['userinfo' => $this->auth->getUserinfo()];
- $this->success(__('Sign up successful'), $data);
- } else {
- $this->error($this->auth->getError());
- }
- }
-
- public function myinvite() {
- $invite = Random::alnum(7);
- $count = Db::name('user')->where(['invite_no' => $invite])->count('id');
- if ($count) {
- $this->myinvite();
- }
- return $invite;
- }
-
- public function myuid($id = 0) {
- if (strlen($id) < 8) {
- $username_len = 8 - strlen($id);
- $username = $id . Random::numeric($username_len);
- } else {
- $username = $id;
- }
- $count = Db::name('user')->where(['username' => $username])->count('id');
- if ($count) {
- $this->myuid($id);
- }
- return $username;
- }
-
-
- public function sysmsg() {
- $list = Db::name('sys_msg')->field('id, title, content, createtime')->where(['user_id' => $this->auth->id])
- ->page($this->page, $this->pagenum)->order('id desc')->select();
- foreach ($list as &$v) {
- $v['createtime'] = date('Y-m-d H:i', $v['createtime']);
- }
- $this->success('消息列表', $list);
- }
-
- public function uservip() {
-
- $this->checkviplevel($this->auth->id);
-
- $user = Db::name('user')->find($this->auth->id);
-
- $vip_info = Db::name('vip')->find($user['maxlevel']);
-
- $next_vip = Db::name('vip')->where(['id' => ['gt', $user['maxlevel']]])->find();
- if (!$next_vip) {
-
- $vip_info['vip_desc'] = '已是最高会员';
-
- $vip_info['growthvalue_percentage'] = 100;
- } else {
-
- $need_growthvalue = $next_vip['growthvalue'] - $user['growthvalue'];
- $vip_info['vip_desc'] = $vip_info['title'] . '还需' . $need_growthvalue . '成长值成为' . $next_vip['title'];
-
- $vip_info['growthvalue_percentage'] = ceil($user['growthvalue'] / $next_vip['growthvalue'] * 100);
- }
-
- $vip_info['experiencetime'] = $user['experiencetime'] > time() ? date('Y-m-d', $user['experiencetime']) : '';
-
- $vip_info['is_birth'] = date('md', time()) == date('md', strtotime($this->auth->birthday)) ? 1: 0;
- $this->success('查询当前会员等级信息', $vip_info);
- }
-
- public function vip() {
-
- $this->checkviplevel($this->auth->id);
-
- $user = Db::name('user')->find($this->auth->id);
-
- $vip_info = Db::name('vip')->find($user['growthlevel']);
-
- $next_vip = Db::name('vip')->where(['id' => ['gt', $user['growthlevel']]])->find();
- if (!$next_vip) {
-
- $vip_info['vip_desc'] = '已是最高会员';
-
- $vip_info['growthvalue_percentage'] = 100;
- } else {
-
- $need_growthvalue = $next_vip['growthvalue'] - $user['growthvalue'];
- $vip_info['vip_desc'] = $vip_info['title'] . '还需' . $need_growthvalue . '成长值成为' . $next_vip['title'];
-
- $vip_info['growthvalue_percentage'] = ceil($user['growthvalue'] / $next_vip['growthvalue'] * 100);
- }
-
- $list = Db::name('vip')->select();
- $vip_privilege = Db::name('vip_privilege');
- foreach ($list as $k => &$v) {
- $v['vip_desc'] = '';
- $v['growthvalue_percentage'] = 0;
- $v['experiencetime'] = '';
- if ($v['id'] == $user['maxlevel']) {
- $v['now_level'] = 1;
- if ($user['maxlevel'] == $user['experiencelevel'] && $user['experiencetime'] > time()) {
-
- $v['experiencetime'] = date('Y-m-d', $user['experiencetime']);
- }
- } else {
- $v['now_level'] = 0;
- }
- if ($v['id'] == $user['growthlevel']) {
- $v = array_merge($v, $vip_info);
- }
- $v['vip_privilege'] = $vip_privilege->field('id, title, desc')
- ->where(['vip_id' => $v['id']])->order('weigh desc')->select();
- }
- $this->success('查询所有会员', $list);
- }
-
- public function feedback() {
- $content = input('content', '', 'trim');
- $images = input('images', '', 'trim');
- $mobile = input('mobile', '', 'trim');
- $data = [];
- if (!$content) {
- $this->error('请输入情况说明');
- }
- if (iconv_strlen($content, 'utf-8') > 3000) {
- $this->error('情况说明最多3000字');
- }
- if ($images) {
- $image_arr = explode(',', $images);
- if (count($image_arr) > 9) {
- $this->error('附件照片最多9张');
- }
- $data['images'] = $images;
- }
- if (!is_mobile($mobile)) {
- $this->error('请输入正确联系电话');
- }
- $data['user_id'] = $this->auth->id;
- $data['content'] = $content;
- $data['images'] = $images;
- $data['mobile'] = $mobile;
- $data['createtime'] = time();
- $rs = Db::name('feedback')->insertGetId($data);
- if (!$rs) {
- $this->error('反馈失败');
- }
- $this->success('反馈成功');
- }
-
- public function mycoupon() {
- $type = input('type', 0, 'intval');
- if (!in_array($type, [1, 2, 3])) {
- $this->error('参数错误');
- }
- $where['user_id'] = $this->auth->id;
- if ($type == 1) {
- $where['endtime'] = ['egt', time()];
- $where['status'] = 0;
- } elseif ($type == 2) {
- $where['status'] = 1;
- } elseif ($type == 3) {
- $where['endtime'] = ['lt', time()];
- $where['status'] = 0;
- }
- $list = Db::name('user_coupon')->field('id, title, desc, type, money, minmoney, endtime')->where($where)->select();
- foreach ($list as &$v) {
- $v['endtime'] = date('Y-m-d', $v['endtime']);
- }
- $this->success('我的优惠券', $list);
- }
-
- public function rechargelist() {
- $list = Db::name('recharge')->field('id, title, price, couponnum')->order('weigh desc')->select();
- $this->success('充值列表', $list);
- }
-
-
- public function usermoneylog() {
- $list = Db::name('user_money_log')->field('id, money, memo, createtime')
- ->where(['user_id' => $this->auth->id])
- ->page($this->page, $this->pagenum)
- ->order('id desc')->select();
- foreach ($list as &$v) {
- $v['createtime'] = date('Y-m-d H:i:s', $v['createtime']);
- }
- $this->success('资金明细', $list);
- }
-
- public function recharge() {
- $id = input('id', 0, 'intval');
- if (!$id) {
- $this->error('参数缺失');
- }
- $info = Db::name('recharge')->where(['id' => $id])->find();
- if (!$info) {
- $this->error('充值金额不存在');
- }
- if ($info['price'] <= 0) {
- $this->error('充值价格异常');
- }
-
- $rechar_order['user_id'] = $this->auth->id;
- $rechar_order['order_no'] = date('YmdHis', time()) . rand(10000000, 99999999);
- $rechar_order['money'] = $info['price'];
- $rechar_order['purpose'] = 2;
- $rechar_order['pay_type'] = 'wechat';
- $rechar_order['relation_id'] = $id;
- $rechar_order['createtime'] = time();
-
- $result = Db::name('rechar_order')->insertGetId($rechar_order);
- if (!$result) {
- $this->error('网络延迟,请稍后再试');
- }
-
- $wxData['body'] = '充值';
- $wxData['out_trade_no'] = $rechar_order['order_no'];
- $wxData['total_fee'] = $info['price'];
- $wxData['openid'] = $this->auth->openid;
- $wxPay = new wxpay\WxPay(config('wxchatpay'));
- $doResult = $wxPay->WxPayJs($wxData);
- $this->success('微信支付参数返回成功', $doResult);
- }
-
- public function invitetop() {
- $data['invite_no'] = $this->auth->invite_no;
- $data['invite_count'] = Db::name('user')->where(['pre_user_id' => $this->auth->id])->count('id');
- $data['coupon_count'] = Db::name('user_coupon')->where(['user_id' => $this->auth->id, 'purpose' => 2])->count('id');
- $this->success('邀请好友顶部信息', $data);
- }
-
- public function invitebottom() {
- $type = input('type', 0, 'intval');
- if (!in_array($type, [1, 2])) {
- $this->error('参数错误');
- }
- if ($type == 1) {
- $list = Db::name('user')->field('id, avatar, nickname, invite_time')
- ->where(['pre_user_id' => $this->auth->id])->page($this->page, $this->pagenum)->order('id desc')->select();
- } else {
- $invite_ids = Db::name('user')->where(['pre_user_id' => $this->auth->id])->column('id');
- if (!$invite_ids) {
- $this->success('报名好友列表', []);
- }
- $list = Db::name('user')->field('id, avatar, nickname, invite_time')
- ->where(['id' => ['in', $invite_ids]])->page($this->page, $this->pagenum)->order('id desc')->select();
- }
- $list = list_domain_image($list, ['avatar']);
- foreach ($list as &$v) {
- $v['invite_time'] = date('Y-m-d', $v['invite_time']);
- }
- $this->success('邀请好友底部列表', $list);
- }
-
- public function myorder() {
- $type = input('type', 0, 'intval');
- if (!in_array($type, [0, 1, 2, 3])) {
- $this->error('参数错误');
- }
- $list = Db::name('active_order')->where(['user_id' => $this->auth->id])->page($this->page, $this->pagenum)->order('id desc')->select();
- $active = Db::name('active');
- foreach ($list as &$v) {
- $v['active'] = $active->find($v['active_id']);
- $v['active'] = info_domain_image($v['active'], ['image']);
- }
- $this->success('我的订单', $list);
- }
-
- public function myorderinfo() {
- $id = input('id', 0, 'intval');
- if (!$id) {
- $this->error('参数缺失');
- }
- $info = Db::name('active_order')->find($id);
- if (!$info) {
- $this->error('数据不存在');
- }
- $info = info_domain_image($info, ['image']);
- $info['starttime'] = date('Y-m-d H:i', $info['starttime']);
- $info['endtime'] = date('Y-m-d H:i', $info['endtime']);
- $info['collectiontime'] = date('Y-m-d H:i', $info['collectiontime']);
- $info['signupendtime'] = date('Y-m-d H:i', $info['signupendtime']);
- $info['refundendtime'] = date('Y-m-d H:i', $info['refundendtime']);
-
- $active_people = Db::name('active_people')->where(['active_id' => $id])->field('user_id, name, createtime')->select();
- $user = Db::name('user');
- foreach ($active_people as &$v) {
- $v['avatar'] = $user->where(['id' => $v['user_id']])->value('avatar');
- $v['createtime'] = date('Y-m-d H:i:s', $v['createtime']);
- }
- $info['active_people'] = $active_people;
- $info['customer_service'] = config('site.customer_service') ? config('site.customer_service') : '';
- $this->success('招标详情', $info);
- }
- }
|