| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103 | <?phpnamespace app\api\controller;use app\common\controller\Api;use think\Db;/** * 打招呼 */class Greet extends Api{    // 无需登录的接口,*表示全部    protected $noNeedLogin = [];    // 无需鉴权的接口,*表示全部    protected $noNeedRight = [];    //常用语,系统的    public function get_greet_sys(){        $where = [];        if($this->auth->gender == 0){            $where['gender'] = ['IN',[0,2]];        }else{            $where['gender'] = ['IN',[1,2]];        }        $list = Db::name('greet_sys')->field('id,title')->where($where)->order('weigh desc')->select();        $this->success(1,$list);    }    //我的打招呼列表    public function get_greet(){        $type = input('type',1);        $list = Db::name('user_greet')->where('user_id',$this->auth->id)->where('type',$type)->where('status',1)->select();        $list = list_domain_image($list,['image']);        $this->success(1,$list);    }    //添加打招呼    public function add_greet(){        $type = input('type',1);        $title = input('title','');        $image = input('image','');        if($type == 1){            $image = '';        }else{            $title = '';        }        $data = [            'user_id' => $this->auth->id,            'type' => $type,            'title' => $title,            'image' => $image,            'status' => 0,        ];        Db::name('user_greet')->insertGetId($data);        $this->success('添加成功');    }    //删除招呼    public function del_greet(){        $id = input('id',0);        Db::name('user_greet')->where('id',$id)->where('user_id',$this->auth->id)->delete();        $this->success();    }    //女性打个招呼    public function once_greet(){        $type1 = Db::name('user_greet')->where('user_id',$this->auth->id)->where('type',1)->orderRaw('rand()')->find();        $type2 = Db::name('user_greet')->where('user_id',$this->auth->id)->where('type',2)->orderRaw('rand()')->find();        $type2 = info_domain_image($type2,['image']);        $result = [            'chat' => !empty($type1) ? $type1['title'] : '',            'image' => !empty($type2) ? $type2['image'] : '',        ];        if($this->auth->gender == 1){            $result['image'] = '';        }        $this->success(1,$result);    }    //首页一键搭讪    public function onekey_greet(){    }}
 |