lizhen_gitee vor 2 Monaten
Ursprung
Commit
d207dfda0a
2 geänderte Dateien mit 32 neuen und 34 gelöschten Zeilen
  1. 31 33
      application/api/controller/Greet.php
  2. 1 1
      application/api/controller/Relation.php

+ 31 - 33
application/api/controller/Greet.php

@@ -15,35 +15,28 @@ class Greet extends Api
 
     //打招呼/搭讪
     public function greet() {
-        /*if ($this->auth->gender == 0 && $this->auth->real_status != 1 && $this->auth->idcard_status != 1) {
-            $this->error('请先完成实名认证或真人认证');
-        }*/
 
-        $other_uid = input('user_id', 0, 'intval');
-        if(!$other_uid) {
+        $other_uids = input('user_ids', '', 'trim');
+        if(!$other_uids) {
             $this->error(__('Invalid parameters'));
         }
-        if($other_uid == $this->auth->id){
-            $this->error('这是您自己');
-        }
-        $checkuser = Db::name('user')->find($other_uid);
-        if(empty($checkuser)) {
-            $this->error('此用户不存在');
+
+        $other_uids = explode(',',$other_uids);
+        if(empty($other_uids)){
+            $this->error(__('Invalid parameters'));
         }
-        $map = [
-            'user_id' => $this->auth->id,
-            'user_to_id' => $other_uid,
-        ];
-        // 取消限制 2023年12月14日 18点47分
-        // $check = Db::name('user_greet')->where($map)->find();
-        // if($check){
-        //     $this->error('已经打过招呼了');
-        // }
 
-        $map['createtime'] = time();
+        $map = [];
+        foreach($other_uids as $key => $other_uid){
+            $map[] = [
+                'user_id' => $this->auth->id,
+                'user_to_id' => $other_uid,
+                'createtime' => time(),
+            ];
+        }
 
         Db::startTrans();
-        $id = Db::name('user_greet')->insertGetId($map);
+        $id = Db::name('user_greet')->insertAll($map);
         if (!$id) {
             Db::rollback();
             $this->error('您的网络开小差了~');
@@ -58,17 +51,22 @@ class Greet extends Api
         }
         Db::commit();
 
-        //不需要送礼物了
-        /*$gift_greet = Db::name('gift_greet')->find();
-        if ($gift_greet) {
-            $gift_greet['special'] = one_domain_image($gift_greet['special']);
-            $gift_greet['image'] = one_domain_image($gift_greet['image']);
-        } else {
-            $gift_greet = (object)[];
-        }*/
-        $gift_greet = (object)[];
-
-        $this->success('操作成功', $gift_greet);
+        $greet = null;
+        if($this->auth->gender == 0){
+            $where['user_id'] = $this->auth->id;
+            $greet = Db::name('user_greet_content')->where($where)->orderRaw('rand()')->find();
+            if(!empty($greet) && $greet['type'] != 0){
+                $greet['content'] = one_domain_image($greet['content']);
+            }
+        }else{
+            $greet = Db::name('user_greet_boy')->orderRaw('rand()')->find();
+        }
+
+        $rs = [
+            'gender' => $this->auth->gender,
+            'greet'  => $greet,
+        ];
+        $this->success('操作成功', $rs);
     }
 
     //查询每天弹出搭讪框次数

+ 1 - 1
application/api/controller/Relation.php

@@ -59,7 +59,7 @@ class Relation extends Api
 
         $list = array_merge($list,$list2);*/
 
-        $this->success(1,$list);
+        $this->success('success',$list);
     }
 
     //绑定关系