Sfoglia il codice sorgente

任务大厅,首页匹配

lizhen_gitee 1 anno fa
parent
commit
9ae46038f7
2 ha cambiato i file con 173 aggiunte e 10 eliminazioni
  1. 161 0
      application/api/controller/Hire.php
  2. 12 10
      application/api/controller/Index.php

+ 161 - 0
application/api/controller/Hire.php

@@ -0,0 +1,161 @@
+<?php
+
+namespace app\api\controller;
+
+use app\common\controller\Api;
+use think\Db;
+/**
+ * 任务大厅
+ */
+class Hire extends Api
+{
+    protected $noNeedLogin = [];
+    protected $noNeedRight = ['*'];
+
+    //发布任务
+    public function add_one(){
+        $title     = input('title','','trim');
+        $info      = input('info','','trim');
+        $type      = input('type',1,'intval');
+        $goldprice = input('goldprice',0,'intval');
+
+        if(!$title || !$type || !$goldprice){
+            $this->error(__('Invalid parameters'));
+        }
+
+        $data = [
+            'user_id'    => $this->auth->id,
+            'title'      => $title,
+            'info'       => $info,
+            'type'       => $type,
+            'goldprice'  => $goldprice,
+            'createtime' => time(),
+            'status'     => 1,
+        ];
+
+        $id = Db::name('hire')->insertGetId($data);
+
+        $this->success('发布成功',$id);
+    }
+
+    //需求市场,个人服务,两个列表
+    public function hire_list(){
+        $type = input('type',1);
+
+        $list = Db::name('hire')
+            ->alias('hire')
+            ->join('user','hire.user_id = user.id','LEFT')
+            ->field('user.id as user_id,user.u_id,user.username,user.nickname,user.avatar,user.gender,hire.id,hire.title,hire.info,hire.type,hire.goldprice,hire.status')
+            ->where('hire.type',$type)
+            ->where('hire.status',1)
+            ->order('hire.id desc')
+            ->autopage()->select();
+        $list = list_domain_image($list,['avatar']);
+
+        if(!empty($list)){
+
+            $my_lingqu = Db::name('user_hire')->where('user_id',$this->auth->id)->where('hire_id','IN',array_column($list,'id'))->column('hire_id');
+
+            foreach($list as $key => &$val){
+
+                //是否领取
+                $val['is_lingqu'] = in_array($val['id'],$my_lingqu) ? 1 : 0;
+
+                //是否是我发布
+                $val['is_my'] = $val['user_id'] == $this->auth->id ? 1 : 0;
+
+            }
+        }
+
+        $this->success('success',$list);
+    }
+
+    //我领取的列表
+    public function my_join_list(){
+        $list = Db::name('user_hire')->alias('uh')
+            ->join('hire','uh.hire_id = hire.id','LEFT')
+            ->join('user','hire.user_id = user.id','LEFT')
+            ->field('user.id as user_id,user.u_id,user.username,user.nickname,user.avatar,user.gender,hire.id,hire.title,hire.info,hire.type,hire.goldprice,hire.status')
+            ->where('uh.user_id',$this->auth->id)
+            ->order('uh.id desc')
+            ->autopage()->select();
+        $list = list_domain_image($list,['avatar']);
+
+        $this->success('success',$list);
+    }
+
+    //我发布的列表
+    public function my_own_list(){
+        $list = Db::name('hire')
+            ->alias('hire')
+            ->join('user','hire.user_id = user.id','LEFT')
+            ->field('user.id as user_id,user.u_id,user.username,user.nickname,user.avatar,user.gender,hire.id,hire.title,hire.info,hire.type,hire.goldprice,hire.status')
+            ->where('hire.user_id',$this->auth->id)
+            ->order('hire.id desc')
+            ->autopage()->select();
+        $list = list_domain_image($list,['avatar']);
+
+        $this->success('success',$list);
+    }
+
+    //某任务,参与人员
+    public function hire_joinuser_list(){
+        $hire_id = input('hire_id',0);
+
+        $list = Db::name('user_hire')->alias('uh')
+            ->join('user','uh.user_id = user.id','LEFT')
+            ->field('user.id as user_id,user.u_id,user.username,user.nickname,user.avatar,user.gender,user.desc')
+            ->where('uh.hire_id',$hire_id)
+            ->select();
+        $list = list_domain_image($list,['avatar']);
+
+        $this->success('success',$list);
+    }
+
+    //领取一个任务
+    public function join_hire(){
+        $this->apiLimit();
+
+        $hire_id = input('hire_id',0);
+
+        $hire_info = Db::name('hire')->where('id',$hire_id)->find();
+        if($hire_info['status'] != 1){
+            $this->error('任务已关闭,请刷新重试');
+        }
+        if($hire_info['user_id'] == $this->auth->id){
+            $this->error('不能领取自己发布的任务');
+        }
+
+        //去重
+        $map = [
+            'user_id' => $this->auth->id,
+            'hire_id' => $hire_id
+        ];
+        $check = Db::name('user_hire')->where($map)->find();
+        if(!empty($check)){
+            $this->error('已经领取该任务,无需重复领取');
+        }
+
+        $map['createtime'] = time();
+        Db::name('user_hire')->insertGetId($map);
+
+        $this->success('领取成功');
+    }
+
+
+    //关闭我的任务
+    public function close_one(){
+        $hire_id = input('hire_id',0);
+        if(!$hire_id){
+            $this->error(__('Invalid parameters'));
+        }
+
+        $map = [
+            'user_id' => $this->auth->id,
+            'id' => $hire_id,
+        ];
+
+        $rs = Db::name('hire')->where($map)->update(['status'=>0]);
+        $this->success('操作成功');
+    }
+}

+ 12 - 10
application/api/controller/Index.php

@@ -11,6 +11,7 @@ use Redis;
 use app\common\library\Sms as Smslib;
 use app\common\service\TenimService;
 use think\Db;
+use think\Cache;
 /**
  * 首页接口
  */
@@ -756,7 +757,7 @@ class Index extends Api
     }
 
     //匹配配置
-    public function pipei_config(){
+    /*public function pipei_config(){
         $result = [
             'index_pipei_switch' => config('site.index_pipei_switch'), //匹配开关
         ];
@@ -781,17 +782,18 @@ class Index extends Api
         $result['remain_times'] = $remain_times;
 
         $this->success(1,$result);
-    }
+    }*/
 
     //匹配
     //做防止重复处理,参照荔枝
+    //做用户在线处理,参照mita,用户不在线,用户语音视频中,用户房间内时,不能被匹配到
     public function pipei(){
 
         //首页匹配功能开关
-        $index_pipei_switch = config('site.index_pipei_switch');
+        /*$index_pipei_switch = config('site.index_pipei_switch');
         if($index_pipei_switch != 1){
             $this->error('匹配功能维护中,请稍后再试');
-        }
+        }*/
 
         //缓存,防重复
         $user_id = $this->auth->id;
@@ -799,7 +801,7 @@ class Index extends Api
         $redis_ids = json_decode(Cache::get($user_id_redis),true);
 
         //首页匹配每天每人匹配次数
-        $is_vip = $this->is_vip($this->auth->id);
+        /*$is_vip = $this->is_vip($this->auth->id);
         $times_limit = $is_vip == 1 ? config('site.pipei_oneday_vipuser_times') : config('site.index_pipei_oneday_user_times');
 
         $times_limit_redis = 'pipei_times_limit_'.$user_id;
@@ -807,7 +809,7 @@ class Index extends Api
 
         if($times_limit > -1 && $user_times >= $times_limit){
             $this->error('今日已超匹配上限'.$times_limit.'次');
-        }
+        }*/
 
         //where
         $where = [
@@ -823,7 +825,7 @@ class Index extends Api
 
         //排除黑名单的
         $where_black = [];
-        $black_ids = Db::name('user_black')->where(['uid'=>$this->auth->id])->column('black_uid');
+        $black_ids = Db::name('user_blacklist')->where(['user_id'=>$this->auth->id])->column('black_user_id');
         if(!empty($black_ids)){
             $where_black['user.id'] = ['NOTIN',$black_ids];
         }
@@ -847,8 +849,8 @@ class Index extends Api
             Cache::set($user_id_redis,json_encode($redis_ids));
 
             //设置次数
-            $second = strtotime(date('Y-m-d'))+86400 - time();
-            Cache::set($times_limit_redis,$user_times+1,$second);
+            /*$second = strtotime(date('Y-m-d'))+86400 - time();
+            Cache::set($times_limit_redis,$user_times+1,$second);*/
         }else{
             Cache::rm($user_id_redis);
         }
@@ -863,7 +865,7 @@ class Index extends Api
         }
 
         $result = Db::name('user')->alias('user')
-            ->join('user_active active' ,'user.id = active.user_id','LEFT')
+//            ->join('user_active active' ,'user.id = active.user_id','LEFT')
             ->where($where)
             ->where($where_op)
             ->where($where_black)