ResourceController.php 26.0 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 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809
<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2019/9/2
 * Time: 9:23
 */

namespace api\index\controller;

use api\index\model\JobModel;
use cmf\controller\RestBaseController;
use think\Db;
use think\Request;
use think\Validate;


/**
 * @title 首页
 * @description
 */
class ResourceController extends RestBaseController
{
    /**
     * @title 首页图片
     * @description
     * @author GuoSheng
     * @url /index/Resource/homePage
     * @method GET
     *
     * @return id:图片id
     * @return thumbnail:图片地址
     *
     */
    public function homePage()
    {
        $data = Db::name('picture')
            ->field('id,thumbnail')
            ->where('delete_time',0)
            ->where('status',1)
            ->order('id desc')
            ->select()
            ->toArray();
        foreach ($data as &$v){
            $v['thumbnail'] =  cmf_get_image_url($v['thumbnail']);
        }
        $this->success('SUCCESS',$data);
    }

    /**
     * @title 上传文件
     * @description 接口说明
     * @author 开发者
     * @url /index/Resource/uploadFile
     * @method POST
     * @header name:XX-Token require:1 default: desc:token
     * @param name:image type:file require:1 default: other: desc:文件
     * @return image_url:图片路径
     */
    public function uploadFile(){
        $files = request()->file('image');
        if (empty($files)) {
            $this->error('未检出文件上传');
        }
        if($files){
            $info = $files->move(ROOT_PATH . 'public' . DS . 'uploads');
            if($info){
                $request = Request::instance();
                $a = $request->domain().'/'.'uploads/'.$info->getSaveName();
               $this->success('SUCCESS',$a);
            }else{
                $this->error($files->getError());
            }
        }
//        foreach($files as $k=>$file){
//            //移动到框架应用根目录/public/uploads/ 目录下
//            $moveUrl = ROOT_PATH . 'public' . DS . 'uploads';
//            //允许文件大小200k
//            $info = $file->validate(['size'=>2048000,'ext'=>'jpg,png,gif,mp3,pcm,wma,wav,mp4,avi,wmv,rm,rmvb,mkv,mov'])->move($moveUrl);
//            if($info){
//                //上传至七牛云
//                $url = str_replace('//', '/', str_replace('\\', '/', $info->getSaveName())); //20190602/1214564654.jpg目录
//                $filePath = $moveUrl.DS.$url;//本地磁盘路径
//                //上传至七牛云文件路径
//                $qiniu_file = 'uploads/'.$url;
//                $storage = new Storage();
//                $qi_res = $storage->upload($qiniu_file, $filePath, 'image');
//                if($qi_res){
//                    $arr[$k]['image_url'] = $host.DS.$qiniu_file;
//                }else{
//                    $this->error('上传七牛云出错!');
//                }
//            }else{
//                // 上传失败获取错误信息
//                $this->error($file->getError());
//            }
//        }
//        $this->success('上传成功',['data'=>$arr]);
    }

    /**
     * @title 全部省份信息
     * @description 全部省份信息
     * @author GuoSheng
     * @url /index/Resource/area
     * @method GET
     *
     * @header name:XX-Token require:1 default: desc:token
     *
     * @return id:城市ID
     * @return name:城市名称
     * @return sign_id:标识ID
     */
    public function area()
    {
        $user_id = $this->getUserId();
        $data = Db::name('area')
            ->field('id,name,sign_id')
            ->where('pid',0)
            ->select();
        $this->success('SUCCESS',$data);
    }

    /**
     * @title 市级信息
     * @description 市级信息
     * @author GuoSheng
     * @url /index/Resource/city
     * @method GET
     *
     * @param name:sign_id type:int require:1 other:desc:省份的标识id
     *
     * @return id:城市ID
     * @return name:城市名称
     */
    public function city()
    {
        $id = $this->request->param('sign_id');
        if(empty($id)){
            $data = Db::name('area')
                ->field('id,name')
                ->where('level',2)
                ->select();
            $this->success('SUCCESS',$data);
        }else{
            $data = Db::name('area')
                ->field('id,name')
                ->where('pid',$id)
                ->select();
            $this->success('SUCCESS',$data);
        }

    }

    /**
     * @title 最新发布
     * @description 全部最新发布信息
     * @author GuoSheng
     * @url /index/Resource/index
     * @method GET
     *
     * @param name:page type:int require:0 other: desc:当前页(默认1)
     * @param name:pageNum type:int require:0 other: desc:每页显示数据个数(默认10)
     * @param name:city_id type:id require:0 other: desc:市级城市ID
     *
     * @return id:信息ID
     * @return job_type:信息标签类型
     * @return job_title:信息标题
     * @return create_time:发布日期
     *
     */
      public function index()
      {
          $param = $this->request->param();
          $page = $this->request->param('page',1,'intval');
          $pageNum = $this->request->param('pageNum',10,'intval');
          if(!empty($param['city_id'])){
              $city_id = ','.$param['city_id'].',';
              $where['city'] = ['like',"%$city_id%"];
          }
          $where['delete_time'] = ['eq',0];
          $where['job_type'] = ['in',[1,2,3,4]];
          $where['status'] = ['eq',1];
          $where['end_time'] = ['>= time',time()];
          $list = Db::name('job')
              ->where($where)
              ->field('id,job_type,job_title,create_time')
              ->order('stick desc,create_time desc')
              ->page($page,$pageNum)
              ->select()
              ->toArray();
          foreach ($list as $k=>$v){
              $list[$k]['create_time'] = date('Y-m-d',$v['create_time']);
          }

          $this->success('SUCCESS',array('data'=>$list));
      }

    /**
     * @title 分类信息
     * @description 各类信息
     * @author GuoSheng
     * @url /index/Resource/type_info
     * @method GET
     *
     * @header name:XX-Token require:1 default: desc:token
     *
     * @param name:job_type type:int require:1 other: desc:类型 (供给信息为1,需求信息为2,同城活动为3,招商加盟为4)
     * @param name:city_id type:int require:0 other: desc:当前城市ID(默认为当前城市,如果不授权默认为全国)
     * @param name:page type:int require:0 other: desc:当前页(默认1)
     * @param name:pageNum type:int require:0 other: desc:每页显示数据个数(默认10)
     *
     * @return id:信息ID
     * @return job_type:信息标签类型
     * @return job_title:信息标题
     * @return create_time:发布日期
     *
     */
    public function type_info()
    {
        $user_id = $this->getUserId();
        $page = $this->request->param('page',1,'intval');
        $pageNum = $this->request->param('pageNum',10,'intval');
        $city_id = $this->request->param('city_id');
        $job_type = $this->request->param('job_type');

        if(!empty($city_id)){
            $city_id = ','.$city_id.',';
            $where['city'] = ['like',"%$city_id%"];
        }
        if(empty($job_type)){
            $this->error(['code'=>40002,'msg'=>'缺少必要参数']);
        }
        $where['delete_time'] = ['eq',0];
        $where['job_type'] = ['eq',$job_type];
        $where['end_time'] = ['>= time',time()];
        $where['status'] = ['eq',1];
        $list = Db::name('job')
            ->where($where)
            ->field('id,job_type,job_title,create_time,stick')
            ->order('stick desc,create_time desc')
            ->limit(30)
            ->page($page,$pageNum)
            ->select()
            ->toArray();
        foreach ($list as $k=>$v){
            $list[$k]['create_time'] = date('Y-m-d',$v['create_time']);
        }

        $this->success('SUCCESS',$list);
    }

    /**
     * @title 供给详情
     * @description 供给详情
     * @author GuoSheng
     * @url /index/Resource/provide
     * @method GET
     *
     * @header name:XX-Token require:1 default: desc:token
     * @param name:id type:int require:1 other: desc:供给信息ID
     *
     * @return id:信息ID
     * @return job_title:信息标题
     * @return look_num:阅读数
     * @return good_num:收藏数
     * @return share_num:分享数
     * @return create_time:发布日期
     * @return end_time:有效日期
     * @return linkman:联系人
     * @return linkman_tel:联系人电话
     * @return needpeople:需求人数
     * @return city:城市
     * @return company_name:公司名称
     * @return content:项目详情
     * @return status:0  未收藏   1已收藏
     * @return image:详情图片
     */
    public function provide()
    {
        $user_id = $this->getUserId();
        //供给信息ID
        $id = $this->request->param('id',0,'intval');
        if(empty($id)){
            $this -> error(['code'=>40005,'msg'=>'缺少必要参数']);
        }
        $res = Db::name('job')
            ->where('id',$id)
            ->find();
        Db::name('job')
            ->where('id',$id)
            ->update(['look_num'=>$res['look_num']+1]);

        $is_collect = Db::name('collect')
            ->where('user_id',$user_id)
            ->where('job_id',$id)
            ->find();
        if($is_collect){
            $data['status'] = 1;
        }else{
            $data['status'] = 0;
        }
        $jobModel = new JobModel();
        $where['id'] = ['eq',$id];
        $info = $jobModel->getOne($where);
        $data['id'] = $info['id'];
        $data['job_title'] = $info['job_title'];
        $data['create_time'] = date('Y-m-d H:i:s',$info['create_time']);
        $data['end_time'] = date('Y-m-d',$info['end_time']);
        $data['look_num'] = $info['look_num'];
        $data['share_num'] = $info['share_num'];
        $data['needpeople'] = $info['needpeople'];
        $data['linkman'] = $info['linkman'];
        $data['linkman_tel'] = $info['linkman_tel'];
        $city = explode(',',trim($info['city'],','));
        $data['city'] = Db::name('area')->whereIn('id',$city)->column('name');
        $data['company_name'] = $info['company_name'];
        $data['content'] = cmf_replace_content_file_url(htmlspecialchars_decode($info['content']));
        $data['image'] = $info['image'];
        $this->success('SUCCESS',$data);
    }

    /**
     * @title 需求详情
     * @description 需求详情
     * @author GuoSheng
     * @url /index/Resource/demand
     * @method GET
     *
     * @header name:XX-Token require:1 default: desc:token
     * @param name:id type:int require:1 other: desc:需求信息ID
     *
     * @return id:信息ID
     * @return job_title:信息标题
     * @return look_num:阅读数
     * @return good_num:收藏数
     * @return share_num:分享数
     * @return create_time:发布日期
     * @return end_time:有效日期
     * @return linkman:联系人
     * @return linkman_tel:联系人电话
     * @return workplace:工作地点
     * @return sex:性别 (0女 1男 2不限)
     * @return needpeople:需求人数
     * @return min_age:最小年龄
     * @return max_age:最大年龄
     * @return education:最低学历
     * @return company_name:公司名称
     * @return empoying:用工单位
     * @return content:项目详情
     * @return status:0  未收藏   1已收藏
     * @return image:详情图片
     */
    public function demand()
    {
        $user_id = $this->getUserId();
        $id = $this->request->param('id',0,'intval');
        if(empty($id)){
            $this -> error(['code'=>40005,'msg'=>'缺少必要参数']);
        }
        $res = Db::name('job')
            ->where('id',$id)
            ->find();
        Db::name('job')
            ->where('id',$id)
            ->update(['look_num'=>$res['look_num']+1]);

        $is_collect = Db::name('collect')
            ->where('user_id',$user_id)
            ->where('job_id',$id)
            ->find();
        if($is_collect){
            $data['status'] = 1;
        }else{
            $data['status'] = 0;
        }

        $jobModel = new JobModel();
        $where['id'] = ['eq',$id];
        $info = $jobModel->getOne($where);
        $data['id'] = $info['id'];
        $data['job_title'] = $info['job_title'];
        $data['create_time'] = date('Y-m-d H:i:s',$info['create_time']);
        $data['end_time'] = date('Y-m-d',$info['end_time']);
        $data['look_num'] = $info['look_num']+1;
        $data['share_num'] = $info['share_num'];
        $data['linkman'] = $info['linkman'];
        $data['linkman_tel'] = $info['linkman_tel'];
        $data['workplace'] = $info['workplace'];
        $data['sex'] = $info['sex'];
        $data['city'] = $info['city'];
        $city = explode(',',trim($info['city'],','));
        $data['city_name'] = Db::name('area')->whereIn('id',$city)->column('name');
        $data['needpeople'] = $info['needpeople'];
        $data['min_age'] = $info['min_age'];
        $data['max_age'] = $info['max_age'];
        $data['education'] = $info['education'];
        $data['company_name'] = $info['company_name'];
        $data['empoying'] = $info['empoying'];
        $data['content'] = cmf_replace_content_file_url(htmlspecialchars_decode($info['content']));
        $data['image'] = $info['image'];
        $this->success('SUCCESS',$data);
    }

    /**
     * @title 活动详情
     * @description 活动详情
     * @author GuoSheng
     * @url /index/Resource/active
     * @method GET
     *
     * @header name:XX-Token require:1 default: desc:token
     * @param name:id type:int require:1 other: desc:信息ID
     *
     * @return id:信息ID
     * @return job_title:信息标题
     * @return look_num:阅读数
     * @return good_num:收藏数
     * @return share_num:分享数
     * @return create_time:发布日期
     * @return end_time:有效日期
     * @return linkman:联系人
     * @return linkman_tel:联系人电话
     * @return needpeople:人数
     * @return payroll:费用
     * @return city:城市
     * @return company_name:公司名称
     * @return adress:详细地址
     * @return content:项目详情
     * @return status:1审核中 2报名成功 3审核未通过
     * @return c_status:0  未收藏   1已收藏
     * @return image:详情图片
     * @return is_me:是否为我发布的  0不是我发布的   1是我发布的
     */
    public function active()
    {
        $user_id = $this->getUserId();

        $id = $this->request->param('id',0,'intval');
        if(empty($id)){
            $this -> error(['code'=>40005,'msg'=>'缺少必要参数']);
        }

        $res = Db::name('job')
            ->where('id',$id)
            ->find();
        Db::name('job')
            ->where('id',$id)
            ->update(['look_num'=>$res['look_num']+1]);
        $is_collect = Db::name('collect')
            ->where('user_id',$user_id)
            ->where('job_id',$id)
            ->find();
        if($is_collect){
            $data['c_status'] = 1;
        }else{
            $data['c_status'] = 0;
        }

        $arr = Db::name('apply')
            ->where('job_id',$id)
            ->where('user_id',$user_id)
            ->find();

        if(!empty($arr)){
            $data['status'] = $arr['status'];
        }else{
            $data['status'] = 0;
        }
        $where['id'] = ['eq',$id];
        if($res['user_id'] == $user_id){
            $data['is_me'] = 1;
        }else{
            $data['is_me'] = 0;
        }
        $jobModel = new JobModel();
        $info = $jobModel->getOne($where);
        $data['id'] = $info['id'];
        $data['job_title'] = $info['job_title'];
        $data['create_time'] = date('Y-m-d H:i:s',$info['create_time']);
        $data['end_time'] = date('Y-m-d',$info['end_time']);
        $data['look_num'] = $info['look_num']+1;
        $data['share_num'] = $info['share_num'];
        $data['linkman'] = $info['linkman'];
        $data['linkman_tel'] = $info['linkman_tel'];
        $data['needpeople'] = $info['needpeople'];
        $data['payroll'] = $info['payroll'];
        $city = explode(',',trim($info['city'],','));
        $data['city'] = Db::name('area')->whereIn('id',$city)->column('name');
        $data['company_name'] = $info['company_name'];
        $data['adress'] = $info['adress'];
        $data['content'] = cmf_replace_content_file_url(htmlspecialchars_decode($info['content']));
        $data['image'] = $info['image'];
        $this->success('SUCCESS',$data);
    }

    /**
     * @title 招商详情
     * @description 招商详情
     * @author GuoSheng
     * @url /index/Resource/attract
     * @method GET
     *
     * @header name:XX-Token require:1 default: desc:token
     * @param name:id type:int require:1 other: desc:信息ID
     *
     * @return id:信息ID
     * @return job_title:信息标题
     * @return look_num:阅读数
     * @return good_num:收藏数
     * @return share_num:分享数
     * @return create_time:发布日期
     * @return end_time:有效日期
     * @return linkman:联系人
     * @return linkman_tel:联系人电话
     * @return company_name:公司名称
     * @return content:项目详情
     * @return status:0  未收藏   1已收藏
     * @return image:详情图片
     */
    public function attract()
    {
        $user_id = $this->getUserId();
        $id = $this->request->param('id',0,'intval');
        if(empty($id)){
            $this -> error(['code'=>40005,'msg'=>'缺少必要参数']);
        }
        $res = Db::name('job')
            ->where('id',$id)
            ->find();
        Db::name('job')
            ->where('id',$id)
            ->update(['look_num'=>$res['look_num']+1]);

        $is_collect = Db::name('collect')
            ->where('user_id',$user_id)
            ->where('job_id',$id)
            ->find();
        if($is_collect){
            $data['status'] = 1;
        }else{
            $data['status'] = 0;
        }
        $where['id'] = ['eq',$id];
        $jobModel = new JobModel();
        $info = $jobModel->getOne($where);
        $data['id'] = $info['id'];
        $data['job_title'] = $info['job_title'];
        $data['create_time'] = date('Y-m-d H:i:s',$info['create_time']);
        $data['end_time'] = date('Y-m-d',$info['end_time']);
        $data['look_num'] = $info['look_num']+1;
        $data['share_num'] = $info['share_num'];
        $data['linkman'] = $info['linkman'];
        $data['city'] = $info['city'];
        $city = explode(',',trim($info['city'],','));
        $data['city_name'] = Db::name('area')->whereIn('id',$city)->column('name');
        $data['linkman_tel'] = $info['linkman_tel'];
        $data['company_name'] = $info['company_name'];
        $data['content'] = cmf_replace_content_file_url(htmlspecialchars_decode($info['content']));
        $data['image'] = $info['image'];
        $this->success('SUCCESS',$data);
    }

    /**
     * @title 用户评论
     * @description 用户评论
     * @author GuoSheng
     * @url /index/Resource/comment
     * @method GET
     *
     * @header name:XX-Token require:1 default: desc:token
     *
     * @param name:id type:int require:1 other: desc:信息ID
     *
     * @return id:信息ID
     * @return user_nickname:用户昵称
     * @return avatar:用户头像
     * @return create_time:评论时间
     * @return content:评论内容
     */
    public function comment()
    {
        $user_id = $this->getUserId();
        $id = $this->request->param('id',0,'intval');
        if(empty($id)){
            $this -> error(['code'=>40005,'msg'=>'缺少必要参数']);
        }
        $data = Db::name('discuss')
            ->alias('d')
            ->join('user u','u.id=d.user_id')
            ->field('d.*,u.user_nickname,u.avatar')
            ->where('job_id',$id)
            ->select()
            ->toArray();
        foreach ($data as &$val){
            $val['create_time'] = date('Y-m-d H:i:s',$val['create_time']);
        }
        $list = $this->discuss($data);
        $this->success('SUCCESS',$list);
        foreach ($list as &$v){
            $v['create_time'] = date('Y-m-d H:i:s',$v['create_time']);
        }
        $this->success('SUCCESS',$list);
    }
    public function discuss($data)
    {
        $sub = array ();
        foreach ($data as $a) {
            if ($a['p_id'] == 0) {
                foreach ($data as $b) {
                    if ($b['to_user_id'] == $a['user_id'] && $b['p_id'] == $a['id']) {
                        foreach ($data as $c) {
                            if ($c['to_user_id'] == $b['user_id'] && $c['p_id'] == $b['p_id']) {
                                $b['children'][] = $c;
                            }
                        }
                        $a['children'][] = $b;
                    }
                }
                $sub[] = $a;
            }
        }
        return $sub;
    }

    /**
     * @title 评论
     * @description 评论
     * @author GuoSheng
     * @url /index/Resource/ping
     * @method GET
     *
     * @header name:XX-Token require:1 default: desc:token
     *
     * @param name:id type:int require:1 other: desc:信息ID
     * @param name:content type:text require:1 other:desc 评论内容
     * @param name:to_user_id type:int require:0 other:desc 被评论人id
     * @param name:p_id type:int require:0 other:desc 父级id
     *
     */
    public function ping()
    {
        $user_id = $this->getUserId();
        $data = $this->request->param();
        if(empty($data['id'])){
            $this -> error(['code'=>40005,'msg'=>'缺少必要参数']);
        }
        if(empty($data['to_user_id'])){
           $data['to_user_id'] = 0;
           $data['p_id'] = 0;
        }
        if(empty($data['content'])){
            $this->error('评论内容不能为空');
        }
        $param['p_id'] = $data['p_id'];
        $param['to_user_id'] = $data['to_user_id'];
        $param['job_id'] = $data['id'];
        $param['user_id'] = $user_id;
        $param['content'] = $data['content'];
        $param['create_time'] = time();
        $data = Db::name('discuss')
            ->insert($param);
        if($data){
            $this->success('添加成功!');
        }else{
            $this->error('sql执行错误');
        }
    }

    /**
     * @title 我要报名
     * @description 报名接口
     * @author GuoSheng
     * @url /index/Resource/apply
     * @method GET
     *
     * @header name:XX-Token require:1 default: desc:token
     *
     * @param name:job_id type:int require:1 other: desc:信息ID
     * @param name:apply_name type:string require:1 desc:姓名
     * @param name:apply_phone type:string require:1 desc:电话
     * @param name:apply_company type:string require:1 desc:公司
     *
     * @return id:报名id
     * @return status:状态
     */
    public function apply()
    {
        $user_id = $this->getUserId();
        $id = $this->request->param('job_id',0,'intval');
        if(empty($id)){
            $this -> error(['code'=>40005,'msg'=>'缺少必要参数']);
        }
        $param = $this->request->param();
        $validate = new Validate([
            'apply_name' => 'require',
            'apply_company' => 'require',
            'apply_phone' => 'require',
        ]);
        if (!$validate->check($param)) {
            $this->error(['code'=>40005,'msg'=>$validate->getError()]);
        }
        $info = Db::name('apply')
            ->where('user_id',$user_id)
            ->where('job_id',$id)
            ->find();
        if($info){
            $param['status'] = 1;
            Db::name('apply')
                ->where('user_id',$user_id)
                ->where('job_id',$id)
                ->update($param);
        }else{
            $param['job_id'] = $id;
            $param['user_id'] = $user_id;
            $param['create_time'] = time();
            $param['status'] = 1;
            Db::name('apply')
                ->insert($param);
        }
        $res = Db::name('apply')
            ->field('id,status')
            ->where('user_id',$user_id)
            ->where('job_id',$id)
            ->find();
        if(empty($res)){
            $this->error(['code'=>40006,'msg'=>'sql执行失败']);
        }
        $this->success('SUCCESS',$res);
    }

    /**
     * @title 获取form_id
     * @description
     * @author GuoSheng
     * @url /index/Resource/getForm
     * @method GET
     *
     * @header name:XX-Token require:1 default: desc:token
     *
     * @param name:form_id type:int require:1 other: desc:formid
     *
     */
    public function getForm()
    {
        $data['user_id'] = $this->getUserId();
        $data['form_id'] = $this->request->param('form_id');
        if($data['form_id'] == "the formId is a mock one"){
            $this->error(['code'=>40002,'msg'=>'form_id格式错误']);
        }
        $data['create_time'] = time();
        $data['past_time'] = time()+7*24*60*60;
        Db::name('form')->insert($data);
        $this->success('SUCCESS');
    }

    /**
     * @title 是否拉黑
     * @description
     * @author GuoSheng
     * @url /index/Resource/init
     * @method GET
     *
     * @header name:XX-Token require:1 default: desc:token
     *
     * @return user_status:1正常 0拉黑
     */
    public function init()
    {
        $user_id = $this->getUserId();
        $user_status = Db::name('user')
            ->where('id',$user_id)
            ->field('user_status')
            ->find();
        if($user_status['user_status'] == 1){
            $data['user_status'] = 1;
        }else{
            $data['user_status'] = 0;
        }
        $this->success('SUCCESS',$data);
    }

    /**
     * @title 是否禁止发布
     * @description
     * @author GuoSheng
     * @url /index/Resource/issue
     * @method GET
     *
     * @header name:XX-Token require:1 default: desc:token
     *
     * @return issue:1正常 0拉黑
     */
    public function issue()
    {
        $user_id = $this->getUserId();
        $issue = Db::name('user')
            ->where('id',$user_id)
            ->field('issue')
            ->find();
        if($issue['issue'] == 1){
            $data['issue'] = 1;
        }else{
            $data['issue'] = 0;
        }
        $this->success('SUCCESS',$data);
    }

}