lizhen_gitee 1 year ago
parent
commit
bb64e10424
1 changed files with 102 additions and 0 deletions
  1. 102 0
      application/api/controller/Greet.php

+ 102 - 0
application/api/controller/Greet.php

@@ -0,0 +1,102 @@
+<?php
+
+namespace 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)->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,
+        ];
+
+        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(){
+        
+    }
+
+
+}