123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101 |
- <?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;
- /**
- * 会员接口
- */
- class User extends Api
- {
- protected $noNeedLogin = ['login', 'mobilelogin', 'register', 'registercheck', 'resetpwd', 'changeemail', 'changemobile', 'third'];
- 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]);
- }
- /**
- * 会员登录
- *
- * @ApiMethod (POST)
- * @param string $account 账号
- * @param string $password 密码
- */
- 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());
- }
- }
- /**
- * 手机验证码登录
- *
- * @ApiMethod (POST)
- * @param string $mobile 手机号
- * @param string $captcha 验证码
- */
- 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) {
- 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());
- }
- }
- /**
- * 注册会员
- *
- * @ApiMethod (POST)
- * @param string $username 用户名
- * @param string $password 密码
- * @param string $email 邮箱
- * @param string $mobile 手机号
- * @param string $code 验证码
- */
- public function register()
- {
- $mobile = $this->request->post('mobile', '', 'trim'); //手机号
- $code = $this->request->post('code', '', 'trim'); //验证码
- $password = $this->request->post('password', '' , 'trim'); //密码
- $repassword = $this->request->post('repassword', '' , 'trim'); //确认密码
- $nickname = $this->request->post('nickname', '', 'trim'); //姓名
- $idcard = $this->request->post('idcard', '', 'trim,strip_tags,htmlspecialchars'); //身份证号
- $province = $this->request->post('province', '', 'trim'); //省
- $city = $this->request->post('city', '', 'trim'); //市
- $area = $this->request->post('area', '', 'trim'); //区
- $address = $this->request->post('address', '', 'trim'); //详细地址
- $recommender = $this->request->post('recommender', '', 'trim'); //推荐人姓名
- $recommender_mobile = $this->request->post('recommender_mobile', '', 'trim'); //推荐人手机号
- $zimage = $this->request->post('zimage', '', 'trim,strip_tags,htmlspecialchars'); //身份证正面照
- $fimage = $this->request->post('fimage', '', 'trim,strip_tags,htmlspecialchars'); //身份证反面照
- 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('两次密码不一致');
- }
- if (!$nickname) {
- $this->error('请输入姓名');
- }
- if (iconv_strlen($nickname, 'utf-8') > 30) {
- $this->error('姓名最多30位');
- }
- if (!$idcard) {
- $this->error('请输入身份证号');
- }
- if (iconv_strlen($idcard, 'utf-8') != 18) {
- $this->error('身份证号错误');
- }
- if (!$province || !$city || !$area) {
- $this->error('请选择养殖场地址');
- }
- if (!$address) {
- $this->error('请输入详细地址');
- }
- if (iconv_strlen($address, 'utf-8') > 255) {
- $this->error('详细地址最多255位');
- }
- if (!$recommender) {
- $this->error('请输入推荐人姓名');
- }
- if (iconv_strlen($recommender, 'utf-8') > 30) {
- $this->error('推荐人姓名最多30位');
- }
- if (!$recommender_mobile || !is_mobile($recommender_mobile)) {
- $this->error('请输入正确推荐人手机号');
- }
- if (!$zimage || !$fimage) {
- $this->error('请上传身份证相关照片');
- }
- $ip = request()->ip();
- $time = time();
- $data = [
- 'nickname' => $nickname,
- 'province' => $province,
- 'city' => $city,
- 'area' => $area,
- 'address' => $address,
- 'createtime' => $time
- ];
- $params = array_merge($data, [
- 'mobile' => $mobile,
- 'password' => $password,
- 'avatar' => '/assets/img/avatar.png',
- 'salt' => Random::alnum(),
- 'jointime' => $time,
- 'joinip' => $ip,
- 'logintime' => $time,
- 'loginip' => $ip,
- 'prevtime' => $time,
- 'is_auth' => 1
- ]);
- $params['password'] = md5(md5($password) . $params['salt']);
- //开启事务
- Db::startTrans();
- $rs = Db::name('user')->insertGetId($params);
- if (!$rs) {
- Db::rollback();
- $this->error('注册失败');
- }
- $data['user_id'] = $rs;
- $data['idcard'] = $idcard;
- $data['zimage'] = $zimage;
- $data['fimage'] = $fimage;
- $data['recommender'] = $recommender;
- $data['recommender_mobile'] = $recommender_mobile;
- $rt = Db::name('user_auth')->insertGetId($data);
- if (!$rt) {
- Db::rollback();
- $this->error('注册失败');
- }
- Db::commit();
- $ret = $this->auth->login($mobile, $password);
- if ($ret) {
- $data = ['userinfo' => $this->auth->getUserinfo()];
- $this->success(__('Sign up 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('验证通过');
- }
- /**
- * 退出登录
- * @ApiMethod (POST)
- */
- public function logout()
- {
- if (!$this->request->isPost()) {
- $this->error(__('Invalid parameters'));
- }
- $this->auth->logout();
- $this->success(__('Logout successful'));
- }
- //查询会员信息
- public function getinfo()
- {
- $data['nickname'] = $this->auth->nickname; //姓名
- $data['avatar'] = one_domain_image($this->auth->avatar); //头像
- $data['mobile'] = $this->auth->mobile; //手机号
- $data['province'] = $this->auth->province; //省
- $data['city'] = $this->auth->city; //市
- $data['area'] = $this->auth->area; //区
- $data['address'] = $this->auth->address; //详细地址
- $data['is_auth'] = $this->auth->is_auth; //认证状态:0=未申请,1=待审核,2=已通过,3=拒绝
- $data['auth_info'] = [];
- $auth_info = Db::name('user_auth')->field('nickname, idcard, zimage, fimage, province, city, area, address, recommender, recommender_mobile')
- ->where(['user_id' => $this->auth->id])->find();
- $data['auth_info'] = info_domain_image($auth_info, ['zimage', 'fimage']);
- $this->success('会员信息', $data);
- }
- /**
- * 修改会员个人信息
- *
- * @ApiMethod (POST)
- * @param string $avatar 头像地址
- * @param string $username 用户名
- * @param string $nickname 昵称
- * @param string $bio 个人简介
- */
- public function profile()
- {
- if ($this->auth->is_auth == 1) {
- $this->error('认证正在审核,不能修改');
- }
- if ($this->auth->is_auth == 2) {
- $this->error('认证已通过审核,不能修改');
- }
- $nickname = $this->request->post('nickname', '', 'trim'); //姓名
- $idcard = $this->request->post('idcard', '', 'trim,strip_tags,htmlspecialchars'); //身份证号
- $province = $this->request->post('province', '', 'trim'); //省
- $city = $this->request->post('city', '', 'trim'); //市
- $area = $this->request->post('area', '', 'trim'); //区
- $address = $this->request->post('address', '', 'trim'); //详细地址
- $recommender = $this->request->post('recommender', '', 'trim'); //推荐人姓名
- $recommender_mobile = $this->request->post('recommender_mobile', '', 'trim'); //推荐人手机号
- $zimage = $this->request->post('zimage', '', 'trim,strip_tags,htmlspecialchars'); //身份证正面照
- $fimage = $this->request->post('fimage', '', 'trim,strip_tags,htmlspecialchars'); //身份证反面照
- if (!$nickname) {
- $this->error('请输入姓名');
- }
- if (iconv_strlen($nickname, 'utf-8') > 30) {
- $this->error('姓名最多30位');
- }
- if (!$idcard) {
- $this->error('请输入身份证号');
- }
- if (iconv_strlen($idcard, 'utf-8') != 18) {
- $this->error('身份证号错误');
- }
- if (!$province || !$city || !$area) {
- $this->error('请选择养殖场地址');
- }
- if (!$address) {
- $this->error('请输入详细地址');
- }
- if (iconv_strlen($address, 'utf-8') > 255) {
- $this->error('详细地址最多255位');
- }
- if (!$recommender) {
- $this->error('请输入推荐人姓名');
- }
- if (iconv_strlen($recommender, 'utf-8') > 30) {
- $this->error('推荐人姓名最多30位');
- }
- if (!$recommender_mobile || !is_mobile($recommender_mobile)) {
- $this->error('请输入正确推荐人手机号');
- }
- if (!$zimage || !$fimage) {
- $this->error('请上传身份证相关照片');
- }
- // $avatar = $this->request->post('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;
- // }
- // if ($nickname) {
- // $exists = \app\common\model\User::where('nickname', $nickname)->where('id', '<>', $this->auth->id)->find();
- // if ($exists) {
- // $this->error(__('Nickname already exists'));
- // }
- // $user->nickname = $nickname;
- // }
- // $user->avatar = $avatar;
- $data = [
- 'nickname' => $nickname,
- 'province' => $province,
- 'city' => $city,
- 'area' => $area,
- 'address' => $address,
- 'updatetime' => time()
- ];
- //开启事务
- Db::startTrans();
- //修改用户表
- $data['is_auth'] = 1;
- $rt = Db::name('user')->where(['id' => $this->auth->id])->setField($data);
- if ($rt === false) {
- Db::rollback();
- $this->error('修改失败');
- }
- //修改认证表
- unset($data['is_auth']);
- $data['idcard'] = $idcard;
- $data['zimage'] = $zimage;
- $data['fimage'] = $fimage;
- $data['recommender'] = $recommender;
- $data['recommender_mobile'] = $recommender_mobile;
- $data['status'] = 0;
- $rs = Db::name('user_auth')->where(['user_id' => $this->auth->id])->setField($data);
- if (!$rs) {
- Db::rollback();
- $this->error('修改失败');
- }
- Db::commit();
- $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('修改成功');
- }
- /**
- * 修改邮箱
- *
- * @ApiMethod (POST)
- * @param string $email 邮箱
- * @param string $captcha 验证码
- */
- 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();
- }
- /**
- * 修改手机号
- *
- * @ApiMethod (POST)
- * @param string $mobile 手机号
- * @param string $captcha 验证码
- */
- public function changemobile()
- {
- $user = $this->auth->getUser();
- $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 (\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();
- }
- /**
- * 第三方登录
- *
- * @ApiMethod (POST)
- * @param string $platform 平台名称
- * @param string $code Code码
- */
- 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);
- //通过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);
- }
- /**
- * 重置密码
- *
- * @ApiMethod (POST)
- * @param string $mobile 手机号
- * @param string $newpassword 新密码
- * @param string $captcha 验证码
- */
- public function resetpwd()
- {
- $type = 'mobile';//$this->request->post("type");
- $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'));
- }
- //验证Token
- 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());
- }
- }
- /**
- * 修改密码
- *
- * @ApiMethod (POST)
- * @param string $captcha 验证码
- * @param string $newpassword 新密码
- * @param string $repassword 确认密码
- */
- 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('两次密码不一致');
- }
- // $user = \app\common\model\User::getById($this->auth->id);
- // if (!$user) {
- // $this->error(__('User not found'));
- // }
- $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);
- }
- /**
- * 添加猪车信息
- *
- *$data = [
- [
- 'carnumber' => '123',
- 'carframenumber' => '344',
- 'images' => '123.jpg,234.jpg,345.jpg'
- ],
- [
- 'carnumber' => '123',
- 'carframenumber' => '344',
- 'images' => '123.jpg,234.jpg,345.jpg'
- ],
- [
- 'carnumber' => '123',
- 'carframenumber' => '344',
- 'images' => '123.jpg,234.jpg,345.jpg'
- ]
- ];
- *
- */
- public function addpigcar()
- {
- $pig_car = input('pig_car', '', 'trim'); //猪车信息json串: carnumber车牌号 carframenumber车架号 images车辆照片
- 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'); //猪车id
- 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'); //招标id
- $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'); //公司id
- $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);
- }
- }
|