Greet.php 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  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)->where('status',1)->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. 'status' => 0,
  48. ];
  49. Db::name('user_greet')->insertGetId($data);
  50. $this->success('添加成功,等待审核');
  51. }
  52. //删除招呼
  53. public function del_greet(){
  54. $id = input('id',0);
  55. Db::name('user_greet')->where('id',$id)->where('user_id',$this->auth->id)->delete();
  56. $this->success();
  57. }
  58. //女性打个招呼
  59. public function once_greet(){
  60. $type1 = Db::name('user_greet')->where('user_id',$this->auth->id)->where('status',1)->where('type',1)->orderRaw('rand()')->find();
  61. $type2 = Db::name('user_greet')->where('user_id',$this->auth->id)->where('status',1)->where('type',2)->orderRaw('rand()')->find();
  62. $type2 = info_domain_image($type2,['image']);
  63. $result = [
  64. 'chat' => !empty($type1) ? $type1['title'] : '',
  65. 'image' => !empty($type2) ? $type2['image'] : '',
  66. ];
  67. if($this->auth->gender == 1){
  68. $result['image'] = '';
  69. }
  70. $this->success(1,$result);
  71. }
  72. //首页一键搭讪
  73. public function onekey_greet(){
  74. }
  75. }