Greet.php 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. <?php
  2. namespace app\api\controller;
  3. use app\common\controller\Api;
  4. use think\Db;
  5. /**
  6. * 打招呼
  7. */
  8. class Greet extends Api
  9. {
  10. // 无需登录的接口,*表示全部
  11. protected $noNeedLogin = [];
  12. // 无需鉴权的接口,*表示全部
  13. protected $noNeedRight = [];
  14. //常用语,系统的
  15. public function get_greet_sys(){
  16. $where = [];
  17. if($this->auth->gender == 0){
  18. $where['gender'] = ['IN',[0,2]];
  19. }else{
  20. $where['gender'] = ['IN',[1,2]];
  21. }
  22. $list = Db::name('greet_sys')->field('id,title')->where($where)->order('weigh desc')->select();
  23. $this->success(1,$list);
  24. }
  25. //我的打招呼列表
  26. public function get_greet(){
  27. $type = input('type',1);
  28. $list = Db::name('user_greet')->where('user_id',$this->auth->id)->where('type',$type)->select();
  29. $list = list_domain_image($list,['image']);
  30. $this->success(1,$list);
  31. }
  32. //添加打招呼
  33. public function add_greet(){
  34. $type = input('type',1);
  35. $title = input('title','');
  36. $image = input('image','');
  37. if($type == 1){
  38. $image = '';
  39. }else{
  40. $title = '';
  41. }
  42. $data = [
  43. 'user_id' => $this->auth->id,
  44. 'type' => $type,
  45. 'title' => $title,
  46. 'image' => $image,
  47. ];
  48. Db::name('user_greet')->insertGetId($data);
  49. $this->success('添加成功');
  50. }
  51. //删除招呼
  52. public function del_greet(){
  53. $id = input('id',0);
  54. Db::name('user_greet')->where('id',$id)->where('user_id',$this->auth->id)->delete();
  55. $this->success();
  56. }
  57. //女性打个招呼
  58. public function once_greet(){
  59. $type1 = Db::name('user_greet')->where('user_id',$this->auth->id)->where('type',1)->orderRaw('rand()')->find();
  60. $type2 = Db::name('user_greet')->where('user_id',$this->auth->id)->where('type',2)->orderRaw('rand()')->find();
  61. $type2 = info_domain_image($type2,['image']);
  62. $result = [
  63. 'chat' => !empty($type1) ? $type1['title'] : '',
  64. 'image' => !empty($type2) ? $type2['image'] : '',
  65. ];
  66. if($this->auth->gender == 1){
  67. $result['image'] = '';
  68. }
  69. $this->success(1,$result);
  70. }
  71. //首页一键搭讪
  72. public function onekey_greet(){
  73. }
  74. }