Square.php 15.3 KB
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442
<?php
/**
 * Created by PhpStorm.
 * auther: sgj
 * Date: 2019/10/8
 * Time: 17:56
 */

namespace app\api\controller;


use app\admin\model\CheckDiary;
use app\admin\model\DiaryLike;
use app\admin\model\Group;
use app\admin\model\PriceStatus;
use app\admin\model\SearchLog;
use app\admin\model\ShareLog;
use app\common\controller\Api;
use app\common\model\ScoreLog;
use think\Db;
use think\Request;

/**
 * 广场接口
 */
class Square extends Api
{
    protected $noNeedLogin = ['listMissionType','index'];
    protected $noNeedRight = ['*'];
    protected $Daily;


    /**
     * @ApiTitle    (广场首页)
     * @ApiSummary  (广场首页)
     * @ApiMethod (POST)
     * @ApiParams   (name="id", type="integer", required=true, description="任务id mission_id")
     * @ApiReturnParams   (name="code", type="integer", required=true, description="状态码")
     * @ApiReturnParams   (name="msg", type="string", required=true, description="提示语")
     * @ApiReturnParams   (name="data", type="object", description="扩展数据返回")
     * @ApiReturn   ({
    "code": 1,
    "msg": "",
    "time": "1570362684",
    "data": {
    "mission": {
    "mission_name": "测试",
    "cycle": 3,
    "start_time": "15:00",
    "fee": 2,
    "id": 1
    },
    "diary": {
    "total": 1,
    "per_page": 10,
    "current_page": 1,
    "last_page": 1,
    "data": [
    {
    "id": 8,
    "mission_id": 1,
    "log_id": 1,
    "user_id": 3,
    "content": "今天天气真好",
    "createtime": 1570355949,
    "showswitch": 1,
    "join_id": 1,
    "avatar": "https://wx.qlogo.cn/mmopen/vi_32/zfOxrj8b1evyHibtaVmibKqnSNu4w8HSF935K7OEywnJibK7NqInYarXHxibo2GrIuG6zliceW5AdTGpmo7TV3ChKtQ/132",
    "user_name": "宋国杰",
    "comment": [
    {
    "id": 1,
    "diary_id": 8,
    "comment_user_id": 3,
    "reply_id": 0,
    "comment_user_avatar": null,
    "comment_user_name": "宋国杰",
    "reply_user_name": "",
    "content": "今天天气真好",
    "createtime": 1570357654,
    "show_switch": 1,
    "date": "2019-10-06"
    },
    {
    "id": 2,
    "diary_id": 8,
    "comment_user_id": 3,
    "reply_id": 0,
    "comment_user_avatar": null,
    "comment_user_name": "宋国杰",
    "reply_user_name": "",
    "content": "今天天气真好",
    "createtime": 1570357677,
    "show_switch": 1,
    "date": "2019-10-06"
    },
    {
    "id": 3,
    "diary_id": 8,
    "comment_user_id": 3,
    "reply_id": 2,
    "comment_user_avatar": null,
    "comment_user_name": "宋国杰",
    "reply_user_name": "测试",
    "content": "今天天气真好",
    "createtime": 1570357707,
    "show_switch": 1,
    "date": "2019-10-06"
    },
    {
    "id": 4,
    "diary_id": 8,
    "comment_user_id": 3,
    "reply_id": 2,
    "comment_user_avatar": "https://wx.qlogo.cn/mmopen/vi_32/zfOxrj8b1evyHibtaVmibKqnSNu4w8HSF935K7OEywnJibK7NqInYarXHxibo2GrIuG6zliceW5AdTGpmo7TV3ChKtQ/132",
    "comment_user_name": "宋国杰",
    "reply_user_name": "测试",
    "content": "今天天气真好",
    "createtime": 1570357887,
    "show_switch": 1,
    "date": "2019-10-06"
    }
    ],
    "images": [
    "http://pyffam7jw.bkt.clouddn.com/uploads/20191006/FlacV2rtDNhzEZrV4bb60KH_9s9u.jpg",
    "http://pyffam7jw.bkt.clouddn.com/uploads/20191006/FvIpuOq8FTabglbusZEE9aPAWaI8.png"
    ]
    }
    ]
    }
    }
    }})
     */
    public function index(){
        $Diary=new CheckDiary();
        $user_id=$this->auth->id;
        $where=[];
        $list=$Diary->diaryList($where,$user_id);
        $this->success('',$list);
    }

    /**
     * @ApiTitle    (获取养生群)
     * @ApiSummary  (获取养生群)
     * @ApiMethod (POST)
     * @ApiReturnParams   (name="code", type="integer", required=true, description="状态码")
     * @ApiReturnParams   (name="msg", type="string", required=true, description="提示语")
     * @ApiReturnParams   (name="group_image", type="string", required=true, description="群头像地址")
     * @ApiReturnParams   (name="name", type="string", required=true, description="养生群名称")
     * @ApiReturnParams   (name="intro", type="string", required=true, description="养生群介绍")
     * @ApiReturnParams   (name="data", type="object", description="扩展数据返回")
     * @ApiReturn   ({
    "code": 1,
    "msg": "",
    "time": "1571035960",
    "data": {
    "recommend": [
    {
    "id": 1,
    "group_image": "/uploads/20191014/FiwnVkUbW5J-3I0n9AMKALsc83LF.jpg",
    "name": "养生群",
    "intro": "这个是群介绍",
    "area_id": 1,
    "group_image_url": "http://pyffam7jw.bkt.clouddn.com/uploads/20191014/FiwnVkUbW5J-3I0n9AMKALsc83LF.jpg"
    }
    ],
    "same_city": [
    {
    "id": 1,
    "group_image": "/uploads/20191014/FiwnVkUbW5J-3I0n9AMKALsc83LF.jpg",
    "name": "养生群",
    "intro": "这个是群介绍",
    "area_id": 1,
    "group_image_url": "http://pyffam7jw.bkt.clouddn.com/uploads/20191014/FiwnVkUbW5J-3I0n9AMKALsc83LF.jpg"
    }
    ]
    }
    })
     */
    public function getGroup(){
        $Group=new Group();
        $group['recommend']=$Group->getGropuList();
        $user_id=$this->auth->id;
        $area_id=\app\admin\model\User::get($user_id)->area_id;
        $where['area_id']=$area_id;
        $group['same_city']=$Group->getGropuList($where);
        $this->success('',$group);
    }

    /**
     * @ApiTitle    (获取养生群详情)
     * @ApiSummary  (获取养生群详情)
     * @ApiMethod (POST)
     * @ApiParams   (name="id", type="integer", required=true, description="群id")
     * @ApiReturnParams   (name="msg", type="string", required=true, description="提示语")
     * @ApiReturnParams   (name="group_image", type="string", required=true, description="群头像地址")
     * @ApiReturnParams   (name="name", type="string", required=true, description="养生群名称")
     * @ApiReturnParams   (name="intro", type="string", required=true, description="养生群介绍")
     * @ApiReturnParams   (name="data", type="object", description="扩展数据返回")
     * @ApiReturn   ({
    "code": 1,
    "msg": "",
    "time": "1571035960",
    "data": {
    "id": 1,
    "group_image": "/uploads/20191014/FiwnVkUbW5J-3I0n9AMKALsc83LF.jpg",
    "name": "养生群",
    "intro": "这个是群介绍",
    "area_id": 1,
    "group_image_url": "http://pyffam7jw.bkt.clouddn.com/uploads/20191014/FiwnVkUbW5J-3I0n9AMKALsc83LF.jpg"
    }
    })
     */
    public function groupInfo(){
        $id=input('id');
        $Group=new Group();
        $group_info=$Group->where('id',$id)->find();
        if (empty($group_info)){
            $this->error('没有找到对应的群');
        }
        $this->success('',$group_info);
    }
    /**
     * @ApiTitle    (存储养生群记录)
     * @ApiSummary  (存储养生群记录)
     * @ApiMethod (POST)
     * @ApiParams   (name="group_id", type="integer", required=true, description="群id")
     * @ApiParams   (name="user_id", type="integer", required=true, description="用户id")
     * @ApiReturnParams   (name="data", type="object", description="扩展数据返回")
     * @ApiReturn   ({
    })
     */
    public function saveGroupLog(){
        $user_id=$this->auth->id;
        $group_id=input('group_id');
        $add['user_id']=$user_id;
        $add['group_id']=$group_id;
        $log=\db('group_log')->where('user_id',$user_id)->find();
        if (empty($log)){
            \db('group_log')->insert($add);
            $this->success('编辑成功!');
        }
        $update['group_id']=$group_id;
        \db('group_log')->where('id',$log['id'])->update($update);
        $this->success('编辑成功!');
    }


    /**
     * @ApiTitle    (发布帖子)
     * @ApiSummary  (发布帖子)
     * @ApiMethod (POST)
     * @ApiParams   (name="content", type="integer", required=true, description="日记内容")
     * @ApiParams   (name="images", type="integer", required=true, description="图片用,号隔开")
     * @ApiReturnParams   (name="code", type="integer", required=true, description="状态码")
     * @ApiReturnParams   (name="msg", type="string", required=true, description="提示语")
     * @ApiReturnParams   (name="data", type="object", description="扩展数据返回")
     * @ApiReturn   ({
    "code":"状态码",
    "msg": "",
    "data": {
    }
    })
     */
    public function setDiary(){
        $content=input('content/s');
        $images=input('images');
        if (empty($content)){
            $this->error('内容不能为空');
        }
        $check_result=checkText($content);
        if ($check_result!='ok'){
            $this->error('发送内容涉及敏感词汇,请重新填写');
        }

        $user_id=$this->auth->id;
        $insert['user_id']=$user_id;
        $insert['content']=$content;
        if (!empty($images)){
            $insert['diaryimages']=$images;
        }
        $result=CheckDiary::create($insert)->toArray();
        if ($result>0){
            $this->success('发布成功!');
        }else{
            $this->error('发布失败!');
        }
    }
    /**
     * @ApiTitle    (获取每日任务状态)
     * @ApiSummary  (获取每日任务状态)
     * @ApiMethod (POST)
     * @ApiReturnParams   (name="one_status", type="integer", required=true, description="任务一状态0:未完成1:已完成未领取奖励2:已领取奖励")
     * @ApiReturnParams   (name="one_score", type="integer", required=true, description="任务一积分数")
     * @ApiReturnParams   (name="two_status", type="integer", required=true, description="任务二状态0:未完成1:已完成未领取奖励2:已领取奖励")
     * @ApiReturnParams   (name="two_score", type="integer", required=true, description="任务二积分数")
     * @ApiReturnParams   (name="three_status", type="integer", required=true, description="任务三状态0:未完成1:已完成未领取奖励2:已领取奖励")
     * @ApiReturnParams   (name="three_score", type="integer", required=true, description="任务三积分数")
     * @ApiReturnParams   (name="code", type="integer", required=true, description="状态码")
     * @ApiReturnParams   (name="msg", type="string", required=true, description="提示语")
     * @ApiReturnParams   (name="data", type="object", description="扩展数据返回")
     * @ApiReturn   ({
    "code":"状态码",
    "msg": "",
    "data": {
    }
    })
     */
    public function missionStatus(){
        /*判断是否有信息*/
        $map['user_id']=$this->auth->id;
        $map['date']=date('Y-m-d');
        $Price=new PriceStatus();
        $info=db('price_status')->where($map)->find();
        $site=config('site');
        if (empty($info)){
            db('price_status')->insert($map);
            $return['one_status']=0;
            $return['two_status']=0;
            $return['three_status']=0;
            $this->success('',$return);
        }else{
            if ($info['one_status']==0 && $info['one']>=1){
                $Price->changeStatus($info['id'],'one_status');
                $return['one_status']=1;
            }
            if ($info['two_status']==0 && $info['two']>=1){
                $Price->changeStatus($info['id'],'two_status');
                $return['two_status']=1;
            }
            if ($info['three_status']==0 && $info['three']>=1){
                $Price->changeStatus($info['id'],'three_status');
                $return['three_status']=1;
            }
        }
        $return['one_score']    =$site['one_score'];
        $return['two_score']    =$site['two_score'];
        $return['three_score']  =$site['three_score'];
        $return['one_status']   =$info['one_status'];
        $return['two_status']   =$info['two_status'];
        $return['three_status'] =$info['three_status'];
        $this->success('',$return);
    }

    /**
     * @ApiTitle    (领取奖励)
     * @ApiSummary  (领取每日奖励)
     * @ApiMethod (POST)
     * @ApiParams   (name="id", type="integer", required=true, description="领取第几个")
     * @ApiReturnParams   (name="one_status", type="integer", required=true, description="任务一状态0:未完成1:已完成未领取奖励2:已领取奖励")
     * @ApiReturnParams   (name="two_status", type="integer", required=true, description="任务二状态0:未完成1:已完成未领取奖励2:已领取奖励")
     * @ApiReturnParams   (name="three_status", type="integer", required=true, description="任务三状态0:未完成1:已完成未领取奖励2:已领取奖励")
     * @ApiReturnParams   (name="code", type="integer", required=true, description="状态码")
     * @ApiReturnParams   (name="msg", type="string", required=true, description="提示语")
     * @ApiReturnParams   (name="data", type="object", description="扩展数据返回")
     * @ApiReturn   ({
    "code":"状态码",
    "msg": "",
    "data": {
    }
    })
     */
    public function getPrice(){
        $user_id=$this->auth->id;
        $id=input('id/d');
        switch ($id){
            case 1;
                $text='one';
                break;
            case 2:
                $text='two';
                break;
            case 3:
                $text='three';
                break;
            default:
                $this->error();
        }
        $field=$text.'_status';
        $map['user_id']=$this->auth->id;
        $map['date']=date('Y-m-d');
        $status=db('price_status')->where($map)->value($field);
        if ($status!=1){
            $this->error('当前状态不可以领取');
        }else{
            Db::startTrans();
            try{
                /*更改本条状态*/
                $restult=db('price_status')->where($map)->update([$field=>'2']);
                //dump($restult);
               // echo db('price_status')->getLastSql();
                /*用户添加积分*/
                $config=config('site');
                $score=$config[$text.'_score'];
                db('user')->where('id',$user_id)->setInc('score',$score);
                /*写积分日志*/
                $insert['user_id']=$user_id;
                $insert['score']=$score;
                $insert['memo']='任务获得';
                ScoreLog::create($insert);
            }catch (\Exception $e) {
                // 回滚事务
                Db::rollback();
                $this->error('操作失败');
            }
            Db::commit();
            $this->success('领取成功');
        }

    }

    /**
     * @ApiTitle    (分享记录)
     * @ApiSummary  (分享记录)
     * @ApiMethod (POST)
     * @ApiParams   (name="remark", type="integer", required=true, description="分享备注")
     * @ApiReturnParams   (name="code", type="integer", required=true, description="状态码")
     * @ApiReturnParams   (name="msg", type="string", required=true, description="提示语")
     * @ApiReturnParams   (name="share_code", type="string", required=true, description="分享积分数")
     * @ApiReturnParams   (name="data", type="object", description="扩展数据返回")
     * @ApiReturn   ({
    "code":"状态码",
    "msg": "",
    "data": {
    }
    })
     */
    public function  shareLog(){
        $user_id=$this->auth->id;
        $data['user_id']=$user_id;
        $data['addtime']=time();
        $data['date']=date('Y-m-d');
        $data['remark']=input('remark');
        $Log=new ShareLog();
        $return['share_code']=$Log->checkDailyShare($user_id);
        ShareLog::create($data);
        $Price=new PriceStatus();
        $Price->addStatus($user_id,'three');
        $this->success('编辑成功!',$return);
    }

}