123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639 |
- <?php
- namespace app\api\controller;
- use app\api\controller\Base;
- use app\api\model\Member as MemberModel;
- use think\Db;
- use think\db\Query;
- use think\Model;
- use app\api\controller\Login;
- use app\api\controller\Area;
- use app\api\controller\Serve;
- class Member extends Base
- {
- function initialize()
- {
- $this->check_login();
- }
-
- public function member_info(){
- $uid = $this->uid;
- $field = 'phone,name,headimg,synopsis,news_switch,privacy_switch,status,background';
- $user_info = Db::name('store_member')->field($field)->where('id',$uid)->find();
- if(empty($user_info)){
- $this->error('用户信息不正确');
- }
- if($user_info['status'] == 0){
- $this->error('该用户已被禁用');
- }
-
- $user_info['news_num'] = Db::name('store_news')->where('user_id',$uid)->where('status',0)->count('id');
- unset($user_info['status']);
- $this->success('获取成功',$user_info);
- }
-
- public function edit_member_info(){
- $uid = $this->uid;
- $type = input('type');
- $headimg = input('headimg');
- $name = input('name');
- $synopsis = input('synopsis');
- if(empty($type)){
- $this->error('参数错误');
- }
- if($type == 1){
- if(empty($headimg)){
- $this->error('参数错误');
- }
- $update_data = array('headimg'=>$headimg);
- }elseif($type == 2){
- if(empty($name)){
- $this->error('参数错误');
- }
- $update_data = array('name'=>$name);
- }else{
- if(empty($synopsis)){
- $this->error('参数错误');
- }
- $update_data = array('synopsis'=>$synopsis);
- }
- Db::name('store_member')->where('id',$uid)->update($update_data);
- $this->success('编辑成功');
- }
-
- public function update_background(){
- $uid = $this->uid;
- $background = input('background');
- if(empty($background)){
- $this->error('参数错误');
- }
- Db::name('store_member')->where('id',$uid)->update(array('background'=>$background));
- $this->success('编辑成功');
- }
-
- public function update_phone(){
- $uid = $this->uid;
- $old_phone = input('old_phone');
- $old_code = input('old_code');
- $new_phone = input('new_phone');
- $new_code = input('new_code');
- if(empty($old_phone) || empty($old_code) || empty($new_phone) || empty($new_code)){
- $this->error('参数错误');
- }
- if($old_phone == $new_phone){
- $this->error('手机号一致,无需修改');
- }
- $member = Db::name('store_member')->field('id,phone')->where('id',$uid)->find();
- if($member['phone'] != $old_phone){
- $this->error('原手机号不正确');
- }
- $obj = new Login();
- $old_sms_id = $obj->verify_sms($old_phone,$old_code);
- if(empty($old_sms_id)){
- $this->error('原手机号验证码不正确');
- }
- $new_sms_id = $obj->verify_sms($new_phone,$new_code);
- if(empty($new_sms_id)){
- $this->error('新手机号验证码不正确');
- }
-
- $member_id = Db::name('store_member')->where('phone',$new_phone)->value('id');
- if($member_id){
- $this->error('新手机号已注册过');
- }
- $res = Db::name('store_member')->where('id',$uid)->update(array('phone'=>$new_phone));
- if($res !==false){
- Db::name('store_member_sms')->where('id',$old_sms_id)->update(array('used'=>1));
- Db::name('store_member_sms')->where('id',$new_sms_id)->update(array('used'=>1));
- $this->success('更换成功');
- }else{
- $this->error('更换失败');
- }
- }
-
- public function update_password(){
- $phone = input('phone');
- $code = input('code');
- $password = input('password');
- if(empty($phone) || empty($code) || empty($password)){
- $this ->error('参数错误');
- }
- $obj = new Login();
- $sms_id = $obj->verify_sms($phone,$code);
- if(empty($sms_id)){
- $this->error('验证码不正确');
- }
- $member = Db::name('store_member')->field('id,decode_password')->where('phone',$phone)->find();
- if(empty($member['id'])){
- $this ->error('该手机号未注册');
- }
- if($password == $member['decode_password']){
- $this ->error('新密码与原密码一致,无需修改');
- }
- $update_data = array(
- 'password'=>md5($password),
- 'decode_password'=>$password
- );
- Db::name('store_member')->where('phone',$phone)->update($update_data);
- Db::name('store_member_sms')->where('id',$sms_id)->update(array('used'=>1));
- $this->success('修改密码成功');
- }
-
- public function store_versions(){
- $type = input('type',1);
- $store_versions = Db::name('store_versions')->field('title,content')->where('type',$type)->find();
- $this->success('获取成功',$store_versions);
- }
-
- public function update_news_switch(){
- $uid = $this->uid;
- $news_switch = input('news_switch');
- if(!isset($news_switch)){
- $this->error('参数错误');
- }
- $old_news_switch = Db::name('store_member')->where('id',$uid)->value('news_switch');
- if($old_news_switch == $news_switch){
- $this->error('已是当前状态,无需操作');
- }
- Db::name('store_member')->where('id',$uid)->update(array('news_switch'=>$news_switch));
- $this->success('操作成功');
- }
-
- public function update_privacy_switch(){
- $uid = $this->uid;
- $privacy_switch = input('privacy_switch');
- if(!isset($privacy_switch)){
- $this->error('参数错误');
- }
- $old_privacy_switch = Db::name('store_member')->where('id',$uid)->value('privacy_switch');
- if($old_privacy_switch == $privacy_switch){
- $this->error('已是当前状态,无需操作');
- }
- Db::name('store_member')->where('id',$uid)->update(array('privacy_switch'=>$privacy_switch));
- $this->success('操作成功');
- }
-
- public function privacy_policy(){
- $this->success('获取成功',htmlspecialchars_decode(sysconf('privacy_policy')));
- }
-
- public function about_us(){
- $this->success('获取成功',htmlspecialchars_decode(sysconf('about_us')));
- }
-
- public function my_attention(){
- $uid = $this->uid;
- $page = input('page',1);
- $pageSize = input('page_size',10);
- $list = Db::name('store_attention')->field('from_user_id')->where('user_id',$uid)->where('status',1)->page($page,$pageSize)->order('id','desc')->select();
- if($list){
- foreach ($list as &$value){
- $user_type = user_type($value['from_user_id']);
- $value['user_type'] = $user_type;
- if($user_type == 1){
- $user_info = Db::name('store_member')->field('name,headimg')->where('id',$value['from_user_id'])->find();
- $value['user_name'] = $user_info['name'];
- $value['user_headimg'] = $user_info['headimg'];
- }else{
- $media_info = Db::name('store_media')->field('logo,title')->where('id',$value['from_user_id'])->find();
- $value['user_name'] = $media_info['title'];
- $value['user_headimg'] = $media_info['logo'];
- }
-
- $value['attention_num'] = Db::name('store_attention')->where('from_user_id',$value['from_user_id'])->where('status',1)->count('id');
- }
- }
- $this->success('获取成功',$list);
- }
-
- public function my_collect(){
- $uid = $this->uid;
- $type = input('type',1);
- $page = input('page',1);
- $pageSize = input('page_size',10);
- $id_arr = Db::name('store_collect')->field('forum_id')->where('user_id',$uid)->where('status',1)->where('type',$type)->page($page,$pageSize)->order('id','desc')->column('forum_id');
- if(empty($id_arr)){
- $this->success('获取成功',[]);
- }
- $list = $this->get_list($type,$id_arr,$page,$pageSize);
- $this->success('获取成功',$list);
- }
-
- public function my_browse(){
- $uid = $this->uid;
- $type = input('type',1);
- $page = input('page',1);
- $pageSize = input('page_size',10);
- $id_arr = Db::name('store_browse')->field('forum_id')->where('user_id',$uid)->where('status',1)->where('type',$type)->page($page,$pageSize)->order('id','desc')->column('forum_id');
- if(empty($id_arr)){
- $this->success('获取成功',[]);
- }
- $list = $this->get_list($type,$id_arr,$page,$pageSize);
- $this->success('获取成功',$list);
- }
-
- public function my_like(){
- $uid = $this->uid;
- $type = input('type',1);
- $page = input('page',1);
- $pageSize = input('page_size',10);
- $id_arr = Db::name('store_like')->field('forum_id')->where('user_id',$uid)->where('status',1)->where('type',$type)->page($page,$pageSize)->order('id','desc')->column('forum_id');
- if(empty($id_arr)){
- $this->success('获取成功',[]);
- }
- $list = $this->get_list($type,$id_arr,$page,$pageSize);
- $this->success('获取成功',$list);
- }
-
- public function my_comment(){
- $uid = $this->uid;
- $type = input('type',1);
- $page = input('page',1);
- $pageSize = input('page_size',10);
- $id_arr = Db::name('store_comment')->field('forum_id')->where('user_id',$uid)->where('forum_type',$type)->where('type',1)->page($page,$pageSize)->order('id','desc')->column('forum_id');
- if(empty($id_arr)){
- $this->success('获取成功',[]);
- }
- $list = $this->get_list($type,$id_arr,$page,$pageSize);
- $this->success('获取成功',$list);
- }
- public function get_list($type = 1,$id_arr = array(),$page = 1,$pageSize = 10){
- if($type == 1){
- $field = 'id,title,user_id,image,video,is_top,create_at';
- $list = Db::name('store_goods')->field($field)->where('status',1)->where('is_deleted',0)->where('id','in',$id_arr)->page($page,$pageSize)->order(['is_top'=>'desc','sort'=>'desc','id'=>'desc'])->select();
- if($list){
- foreach($list as &$value) {
-
- $value['comment_num'] = Db::name('store_comment')->where('forum_id',$value['id'])->where('type',1)->where('forum_type',1)->count('id');
- $value['image'] = image_path($value['image']);
-
- $media_info = Db::name('store_media')->field('logo,title')->where('id',$value['user_id'])->find();
- $value['media_logo'] = $media_info['logo'];
- $value['media_title'] = $media_info['title'];
- $remain_time = time() - strtotime($value['create_at']);
- $value['duration'] = get_stay_time($remain_time);
- unset($value['user_id']);
- unset($value['create_at']);
- }
- }
- }else{
- $field = 'id,user_id,type,title,content,media_id,image,video,create_at';
- $list = Db::name('store_consult')->field($field)->where('status',1)->where('is_deleted',0)->where('id','in',$id_arr)->page($page,$pageSize)->order(['sort'=>'desc','id'=>'desc'])->select();
- if($list){
- foreach($list as &$value) {
-
- $value['comment_num'] = Db::name('store_comment')->where('forum_id',$value['id'])->where('type',1)->where('forum_type',2)->count('id');
- $value['image'] = image_path($value['image']);
- if($value['type'] == 1){
-
- $media_info = Db::name('store_media')->field('logo,title')->where('id',$value['user_id'])->find();
- $value['media_logo'] = $media_info['logo'];
- $value['media_title'] = $media_info['title'];
- }else{
-
- $media_info = Db::name('store_member')->field('headimg,name')->where('id',$value['user_id'])->find();
- $value['media_logo'] = $media_info['headimg'];
- $value['media_title'] = $media_info['name'];
- }
- $remain_time = time() - strtotime($value['create_at']);
- $value['duration'] = get_stay_time($remain_time);
- unset($value['media_id']);
- unset($value['user_id']);
- unset($value['type']);
- unset($value['create_at']);
- }
- }
- }
- return $list;
- }
-
- public function news_list(){
- $uid = $this->uid;
- $page = input('page',1);
- $pageSize = input('page_size',10);
- $news_list = Db::name('store_news')->field('content,type,comment_user_id,create_at')->where('user_id',$uid)->page($page,$pageSize)->order('id','desc')->select();
- $type_arr = array('1'=>'系统消息','2'=>'用户消息');
- if($news_list){
- foreach ($news_list as &$value){
- if($value['type'] == 1){
- $value['icon'] = 'https://zjth2021.oss-cn-beijing.aliyuncs.com/164e89b793f57189/eea68607b8a59a4b.png';
- }else{
- $value['icon'] = Db::name('store_member')->where('id',$value['comment_user_id'])->value('headimg');
- }
- $value['type_name'] = $type_arr[$value['type']];
- $remain_time = time() - strtotime($value['create_at']);
- $value['duration'] = get_stay_time($remain_time);
- unset($value['comment_user_id']);
- unset($value['create_at']);
- }
- }
-
- Db::name('store_news')->where('user_id',$uid)->where('status',0)->update(array('status'=>1));
- $this->success('获取成功',$news_list);
- }
-
- public function submit_complain(){
- $uid = $this->uid;
- $explain = input('explain');
- $images = input('images');
- if(empty($explain) || empty($images)){
- $this->error('参数错误');
- }
- $data = [
- 'user_id' => $uid,
- 'question' => $explain,
- 'images' => $images,
- 'type' => 2,
- 'date' => date('Y-m-d')
- ];
- $res = Db::name('store_complain')->insert($data);
- if($res !==false){
- $this->success('提交成功');
- }else{
- $this->error('提交失败');
- }
- }
-
- public function publish_consult(){
- $uid = $this->uid;
- $cate_id = input('cate_id');
- $title = input('title');
- $content = input('content');
- $image = input('image');
- $video = input('video');
- if(empty($cate_id) || empty($title) || empty($image) || empty($content)){
- $this->error('参数错误');
- }
- $data = [
- 'user_id' => $uid,
- 'cate_id' => $cate_id,
- 'title' => $title,
- 'content' => $content,
- 'image' => $image,
- 'video' => $video,
- 'type' => 2
- ];
- $res = Db::name('store_consult')->insert($data);
- if($res !==false){
- $this->success('发布成功');
- }else{
- $this->error('发布失败');
- }
- }
- }
|