Greet.php 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  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 get_greet_checked(){
  34. $type = input('type',1);
  35. $list = Db::name('user_greet')->where('user_id',$this->auth->id)->where('type',$type)->where('status',1)->select();
  36. $list = list_domain_image($list,['image']);
  37. $this->success(1,$list);
  38. }
  39. //添加打招呼
  40. public function add_greet(){
  41. if($this->auth->gender == 1 && $this->auth->idcard_status != 1){
  42. $this->error('请先完成实名认证');
  43. }
  44. if($this->auth->gender == 0 && $this->auth->real_status != 1){
  45. $this->error('请先完成真人认证');
  46. }
  47. $type = input('type',1);
  48. $title = input('title','');
  49. $image = input('image','');
  50. if($type == 1){
  51. $image = '';
  52. }else{
  53. $title = '';
  54. }
  55. $data = [
  56. 'user_id' => $this->auth->id,
  57. 'type' => $type,
  58. 'title' => $title,
  59. 'image' => $image,
  60. 'status' => 0,
  61. ];
  62. Db::name('user_greet')->insertGetId($data);
  63. $this->success('添加成功,等待审核');
  64. }
  65. //删除招呼
  66. public function del_greet(){
  67. $id = input('id',0);
  68. Db::name('user_greet')->where('id',$id)->where('user_id',$this->auth->id)->delete();
  69. $this->success();
  70. }
  71. //一键搭讪
  72. public function once_greet(){
  73. if($this->auth->gender == 1){
  74. $today = strtotime(date('Y-m-d'));
  75. $end = $today + 86399;
  76. $apiLimitTime = $end - time();
  77. $times = config('site.man_dashan_times') ?: 50;
  78. $rs = $this->apiLimit($times,$apiLimitTime*1000);
  79. if(!$rs){
  80. $this->error('今日搭讪次数已用完');
  81. }
  82. $where['gender'] = ['IN',[1,2]];
  83. $chat = Db::name('greet_sys')->field('id,title')->where($where)->orderRaw('rand()')->find();
  84. $result = [
  85. 'chat' => !empty($chat) ? $chat['title'] : '',
  86. 'image' => '',
  87. ];
  88. }else{
  89. if($this->auth->real_status != 1){
  90. $this->error('请先完成真人认证');
  91. }
  92. $type1 = Db::name('user_greet')->where('user_id',$this->auth->id)->where('status',1)->where('type',1)->orderRaw('rand()')->find();
  93. $type2 = Db::name('user_greet')->where('user_id',$this->auth->id)->where('status',1)->where('type',2)->orderRaw('rand()')->find();
  94. $type2 = info_domain_image($type2,['image']);
  95. if(empty($type1)){
  96. //未设置搭讪语,强制不让搭讪
  97. //$type2 = [];
  98. }
  99. $result = [
  100. 'chat' => !empty($type1) ? $type1['title'] : '',
  101. 'image' => !empty($type2) ? $type2['image'] : '',
  102. ];
  103. }
  104. $this->success(1,$result);
  105. }
  106. }