审查视图

application/mobile/controller/Company.php 42.5 KB
1 2 3 4 5 6 7 8 9 10 11 12
<?php
namespace app\mobile\controller;

use think\Validate;
use think\Db;
use think\Exception;
use think\exception\PDOException;
use app\common\controller\Api;
use app\mobile\model\CompanyUser;
use app\mobile\model\CourseOrder;
use app\mobile\model\CourseAppraise;
use app\mobile\model\SecretOrder;
何书鹏 authored
13 14
use app\mobile\model\Package;
use app\mobile\model\PackageOrder;
何书鹏 authored
15 16
use app\mobile\model\PackageSpec;
use app\mobile\model\PackageCart;
何书鹏 authored
17 18 19 20
use app\mobile\model\CompanyJob;
use app\mobile\model\UserJob;
use app\mobile\model\CompanyJobResume;
use app\mobile\model\UserJobDownload;
何书鹏 authored
21
use app\mobile\model\Message;
22
use addons\epay\library\Service;
何书鹏 authored
23
use Endroid\QrCode\QrCode;
24 25 26 27 28 29 30 31 32 33 34 35 36 37

/**
 * 我的(企业)接口
 * @ApiWeigh (65)
 */
class Company extends Api
{
	protected $noNeedLogin = [''];
    protected $noNeedRight = ['*'];
    protected $company_id = 0;

    public function _initialize()
    {
        parent::_initialize();
何书鹏 authored
38
        $this->model = model('app\mobile\model\Company');
39 40 41 42 43 44 45 46 47 48
        if(!$this->company_id){
            $user = $this->auth->getUser();
            if($user['group_id'] == 0){
                $this->error('您还不是企业管理员');
            }
            $this->company_id = $this->model->where('user_id',$user['id'])->value('id');
        }
    }

    /**
何书鹏 authored
49
     * @ApiWeigh (99)
50 51 52 53 54 55 56 57 58 59 60 61 62 63 64
     * @ApiTitle    (我的密卷)
     * @ApiSummary  (我的密卷)
     * @ApiMethod   (POST)
     *
     * @ApiHeaders  (name=token, type=string, required=true, description="请求的Token")
     *
     * @ApiReturn({
        "code": 1, 
        "msg": "成功", 
        "time": "1600499807", 
        "data": [
            {
                "id": 10, //密卷订单ID
                "pay_price": "500.00", //实际支付金额
                "people_num": 20, //密卷规格人数(斜杠后数字)
何书鹏 authored
65
                "is_top": "1", //是否顶配:0=否,1=是
66
                "secret": {
何书鹏 authored
67
                    "id": 1, //密卷ID
68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88
                    "title": "测试密卷", 
                    "do_num": 20
                }, 
                "user_count": 3 //当前企业下员工含管理员数量(斜杠前数字)
            }
        ]
    })
     */
    public function mySecret(){
        // 查找所有密卷
        $list = SecretOrder::with(['secret'])
            ->where('company_id',$this->company_id)
            ->where('user_id',$this->auth->id)
            ->where('pay_status','1')
            ->select();
        $user_count = CompanyUser::where('company_id',$this->company_id)
                ->where('status','1')
                ->count();
        foreach ($list as $v) {
            // 当前企业下员工含管理员人数
            $v['user_count'] = $user_count + 1;
何书鹏 authored
89
            $v->visible(['id','pay_price','people_num','is_top','secret'])->append(['user_count']);
何书鹏 authored
90
            $v->getRelation('secret')->visible(['id','title']);
91 92 93 94 95
        }
        $this->success('成功',$list);
    }

    /**
何书鹏 authored
96
     * @ApiWeigh (97)
97 98 99 100 101 102 103 104 105 106 107
     * @ApiTitle    (我的课程)
     * @ApiSummary  (我的课程)
     * @ApiMethod   (POST)
     *
     * @ApiHeaders  (name=token, type=string, required=true, description="请求的Token")
     *
     * @ApiReturn({
        "code": 1,
        "msg": "成功",
        "time": "1600081718",
        "data": [{
何书鹏 authored
108
            "id": 9, //课程订单ID
109
            "pay_price": "50.00", //实际支付金额
何书鹏 authored
110
            "people_num": 20, //限制人数(斜杠后数字)
何书鹏 authored
111
            "is_top": "0", //是否顶配:0=否,1=是
何书鹏 authored
112
            "course": { //课程信息
何书鹏 authored
113 114 115
                "id": 1, //课程ID
                "title": "测试课程", //课程标题
                "cover": "" //课程封面图
116
            },
何书鹏 authored
117 118
            "user_count": 0 //当前企业下员工含管理员数量(斜杠前数字)
            "is_have_appraise": 0 //是否已评价:0=否,1=是
119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134
        }]
    })
     */
    public function myCourse(){
        // 查找所有密卷
        $list = CourseOrder::with(['course'])
            ->where('company_id',$this->company_id)
            ->where('user_id',$this->auth->id)
            ->where('pay_status','1')
            ->select();
        $user_count = CompanyUser::where('company_id',$this->company_id)
                ->where('status','1')
                ->count();
        foreach ($list as $v) {
            // 当前企业下员工含管理员人数
            $v['user_count'] = $user_count + 1;
何书鹏 authored
135 136 137 138 139 140 141 142
            // 是否已评价
            $have_appraise = CourseAppraise::where('user_id',$this->auth->id)
                ->where('course_id',$v['course_id'])
                ->where('course_order_id',$v['id'])
                ->field('id')
                ->find();
            $v['is_have_appraise'] = !empty($have_appraise) ? 1 : 0;
            $v->visible(['id','pay_price','people_num','is_top','course'])->append(['user_count','is_have_appraise']);
何书鹏 authored
143
            $v->getRelation('course')->visible(['id','cover','title']);
144 145 146 147 148
        }
        $this->success('成功',$list);
    }

    /**
何书鹏 authored
149
     * @ApiWeigh (95)
150 151 152 153 154 155 156
     * @ApiTitle    (企业成员管理)
     * @ApiSummary  (企业成员管理)
     * @ApiMethod   (POST)
     *
     * @ApiHeaders  (name=token, type=string, required=true, description="请求的Token")
     * @ApiParams   (name="page", type="inter", required=false, description="当前页(默认1)")
     * @ApiParams   (name="page_num", type="inter", required=false, description="每页显示数据个数(默认10)")
何书鹏 authored
157 158
     * @ApiParams   (name="status", type="string", required=false, description="0=未审核,1=已通过")
     * @ApiParams   (name="keyword", type="string", required=false, description="关键字")
159 160
     *
     * @ApiReturn({
何书鹏 authored
161 162 163
        "code": 1, 
        "msg": "成功", 
        "time": "1600511589", 
164
        "data": {
何书鹏 authored
165 166 167 168 169
            "total": 2, //数据总数
            "list": [
                {
                    "id": 1, //申请ID
                    "name": "何先生", //申请人名称
何书鹏 authored
170
                    "mobile": "15133120361", //申请人电话
何书鹏 authored
171 172 173
                    "createtime": "2020.09.12" //申请时间
                }
            ]
174 175 176 177 178 179 180
        }
    })
     */
    public function companyUser()
    {
        $page = $this->request->param('page', 1, 'intval');
        $page_num = $this->request->param('page_num', 10, 'intval');
何书鹏 authored
181 182 183 184 185 186
        $status = $this->request->param('status','0');
        $keyword = $this->request->param('keyword');
        $where['status'] = $status;
        if(!empty($keyword)){
            $where['name'] = ['like','%'.$keyword.'%'];
        }
何书鹏 authored
187
        $data = CompanyUser::where('company_id',$this->company_id)
何书鹏 authored
188
            ->where($where)
189 190 191
            ->paginate($page_num,false,['page'=>$page])
            ->each(function($v){
                $v['createtime'] = date('Y.m.d',$v['createtime']);
何书鹏 authored
192
                $v->visible(['id','name','mobile','createtime']);
193 194 195 196 197
            })->toArray();
        $this->success('成功',['total'=>$data['total'],'list'=>$data['data']]);
    }

    /**
何书鹏 authored
198
     * @ApiWeigh (93)
199 200 201 202 203 204 205 206 207 208 209
     * @ApiTitle    (企业成员管理-同意加入)
     * @ApiSummary  (企业成员管理-同意加入)
     * @ApiMethod   (POST)
     *
     * @ApiHeaders  (name=token, type=string, required=true, description="请求的Token")
     * @ApiParams   (name="company_user_id", type="string", required=false, description="申请ID")
     *
     * @ApiReturn({
        "code": 1,
        "msg": "成功",
        "time": "1600167441",
何书鹏 authored
210
        "data": null
211 212 213 214 215 216 217 218
    })
     */
    public function companyUserAgree()
    {
        $company_user_id = $this->request->param('company_user_id');
        empty($company_user_id) && $this->error('缺少必需参数');
        $info = CompanyUser::get($company_user_id);
        empty($info) && $this->error('申请信息不存在');
何书鹏 authored
219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236
        Db::startTrans();
        try {
            $info->save(['status'=>'1']);
            // 发送消息
            $company_name = $this->model->where('id',$info['company_id'])->value('name');
            Message::create([
                'user_id' => $info['user_id'],
                'title' => '加入企业-成功',
                'content' => '您的加入'.$company_name.'企业的申请已通过,该企业的学习自老您都可以免费共享了哦,快去试试吧。'
            ]);
            Db::commit();
        } catch (PDOException $e) {
            Db::rollback();
            $this->error($e->getMessage());
        } catch (Exception $e) {
            Db::rollback();
            $this->error($e->getMessage());
        }
237 238 239 240
        $this->success('同意加入成功');
    }

    /**
何书鹏 authored
241
     * @ApiWeigh (91)
242 243 244 245 246 247 248 249 250 251 252
     * @ApiTitle    (企业成员管理-拒绝加入)
     * @ApiSummary  (企业成员管理-拒绝加入)
     * @ApiMethod   (POST)
     *
     * @ApiHeaders  (name=token, type=string, required=true, description="请求的Token")
     * @ApiParams   (name="company_user_id", type="string", required=false, description="申请ID")
     *
     * @ApiReturn({
        "code": 1,
        "msg": "成功",
        "time": "1600167441",
何书鹏 authored
253
        "data": null
254 255 256 257 258 259 260 261
    })
     */
    public function companyUserRefuse()
    {
        $company_user_id = $this->request->param('company_user_id');
        empty($company_user_id) && $this->error('缺少必需参数');
        $info = CompanyUser::get($company_user_id);
        empty($info) && $this->error('申请信息不存在');
何书鹏 authored
262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279
        Db::startTrans();
        try {
            $info->save(['status'=>'2']);
            // 发送消息
            $company_name = $this->model->where('id',$info['company_id'])->value('name');
            Message::create([
                'user_id' => $info['user_id'],
                'title' => '加入企业-失败',
                'content' => '您的加入'.$company_name.'企业的申请失败了,联系企业管理员后重新申请下吧。'
            ]);
            Db::commit();
        } catch (PDOException $e) {
            Db::rollback();
            $this->error($e->getMessage());
        } catch (Exception $e) {
            Db::rollback();
            $this->error($e->getMessage());
        }
280 281 282 283
        $this->success('拒绝成功');
    }

    /**
何书鹏 authored
284
     * @ApiWeigh (89)
285 286 287 288 289 290 291 292 293 294 295
     * @ApiTitle    (企业成员管理-移出团队)
     * @ApiSummary  (企业成员管理-移出团队)
     * @ApiMethod   (POST)
     *
     * @ApiHeaders  (name=token, type=string, required=true, description="请求的Token")
     * @ApiParams   (name="company_user_id", type="string", required=false, description="申请ID")
     *
     * @ApiReturn({
        "code": 1,
        "msg": "成功",
        "time": "1600167441",
何书鹏 authored
296
        "data": null
297 298 299 300 301 302 303 304 305 306 307 308 309
    })
     */
    public function companyUserRemove()
    {
        $company_user_id = $this->request->param('company_user_id');
        empty($company_user_id) && $this->error('缺少必需参数');
        $info = CompanyUser::get($company_user_id);
        empty($info) && $this->error('申请信息不存在');
        $info->delete();
        $this->success('移出成功');
    }

    /**
何书鹏 authored
310
     * @ApiWeigh (87)
311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332
     * @ApiTitle    (企业成员管理-企业邀请码)
     * @ApiSummary  (企业成员管理-企业邀请码)
     * @ApiMethod   (POST)
     *
     * @ApiHeaders  (name=token, type=string, required=true, description="请求的Token")
     *
     * @ApiReturn({
        "code": 1,
        "msg": "成功",
        "time": "1600167441",
        "data": {
            "invite_code": 376581, //企业邀请码
        }
    })
     */
    public function inviteCode()
    {
        $invite_code = $this->model->where('id',$this->company_id)->value('invite_code');
        $this->success('成功',compact('invite_code'));
    }

    /**
何书鹏 authored
333
     * @ApiWeigh (85)
334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353
     * @ApiTitle    (企业成员管理-更新企业邀请码)
     * @ApiSummary  (企业成员管理-更新企业邀请码)
     * @ApiMethod   (POST)
     *
     * @ApiHeaders  (name=token, type=string, required=true, description="请求的Token")
     *
     * @ApiReturn({
        "code": 1,
        "msg": "成功",
        "time": "1600167441",
        "data": {
            "invite_code": 376581, //企业邀请码
        }
    })
     */
    public function setInviteCode()
    {
        $invite_code = (new User)->setInviteCode($this->company_id);
        $this->success('更新邀请码成功',compact('invite_code'));
    }
何书鹏 authored
354 355

    /**
何书鹏 authored
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
     * @ApiWeigh (85)
     * @ApiTitle    (企业成员管理-二维码邀请)
     * @ApiSummary  (企业成员管理-二维码邀请)
     * @ApiMethod   (POST)
     *
     * @ApiHeaders  (name=token, type=string, required=true, description="请求的Token")
     *
     * @ApiReturn({
        "code": 1,
        "msg": "成功",
        "time": "1600167441",
        "data": {
            "invite_qrcode": "http://www.enterprise.top/qrcode/20201017/52b77af2efe121e124c1b26d4d0d7f43.png", //二维码地址
        }
    })
     */
    public function inviteQrcode()
    {
        $company = $this->model->get($this->company_id);
        if(empty($company['invite_qrcode'])){
            $qrCode = new QrCode();
            $qrCode
                ->setText($this->company_id)
                ->setSize(300)
                ->setPadding(10)
                ->setErrorCorrection('high')
                ->setForegroundColor(['r' => 0, 'g' => 0, 'b' => 0, 'a' => 0])
                ->setBackgroundColor(['r' => 255, 'g' => 255, 'b' => 255, 'a' => 0])
                ->setLabelFontSize(16)
何书鹏 authored
385
                ->setImageType(QrCode::IMAGE_TYPE_PNG);
何书鹏 authored
386
            $dir = 'uploads/company';
何书鹏 authored
387 388 389
            if (!file_exists($dir)){
                mkdir($dir,0777,true);
            }
何书鹏 authored
390
            $url = $dir.'/qrcode_'.$this->company_id.'.png';
何书鹏 authored
391 392 393 394 395 396 397 398 399 400 401 402
            // save it to a file
            $qrCode->save($url);
            $company->save([
                'invite_qrcode' => '/'.$url
            ]);
        }
        $this->success('成功',[
            'invite_qrcode' => $company->invite_qrcode
        ]);
    }

    /**
何书鹏 authored
403 404 405 406 407 408
     * @ApiWeigh (83)
     * @ApiTitle    (企业套餐)
     * @ApiSummary  (企业套餐)
     * @ApiMethod   (POST)
     *
     * @ApiHeaders  (name=token, type=string, required=true, description="请求的Token")
何书鹏 authored
409
     * @ApiParams   (name="keyword", type="inter", required=false, description="搜索关键字")
何书鹏 authored
410 411 412 413
     * @ApiParams   (name="is_buy", type="inter", required=false, description="0=未购买,1=已购买")
     * @ApiParams   (name="order", type="inter", required=false, description="排序方式:0=最新,1=购买最多,2=价格最低,3=优惠最大")
     *
     * @ApiReturn({
何书鹏 authored
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
        "code": 1, 
        "msg": "成功", 
        "time": "1600773758", 
        "data": [
            {
                "id": 8, //套餐ID
                "title": "1", //套餐名称
                "current_price": "123.00", //现价
                "is_buy": 1, //是否已购买:0=否,1=是
                "is_add_cart": 0, //是否已加入购物:0=否,1=是
                "original_price": "60.00", //原价
                "buy_num": 60, //购买数量
                "preferential_price": "-63.00", //优惠金额
                "people_num": 10, //套餐限制人数
                "secret_list": [
                    {
                        "id": 1, //密卷ID
                        "title": "测试密卷", //密卷标题
                        "current_price": "10.00", 
                        "original_price": "10000.00", 
                        "do_num_virtual": 10, 
                        "do_num_real": 10, 
                        "description": "测试密卷", 
                        "createtime": null, 
                        "updatetime": null, 
                        "do_num": 20
                    }
                ], 
                "course_list": [
                    {
                        "id": 1, //课程ID
                        "title": "测试课程", //课程标题
                        "cover": "", 
                        "current_price": "50.00", 
                        "original_price": "100.00", 
                        "content": null, 
                        "is_top": "0", 
                        "top_time": null, 
                        "study_num_virtual": 1, 
                        "study_num_real": 2, 
                        "createtime": null, 
                        "updatetime": null
                    }
                ]
            }
        ]
何书鹏 authored
460 461 462 463 464
    })
     */
    public function package()
    {
        $user_id = $this->auth->id;
何书鹏 authored
465
        $keyword = $this->request->param('keyword');
何书鹏 authored
466 467
        $is_buy = $this->request->param('is_buy',0);
        $order = $this->request->param('order',0);
何书鹏 authored
468 469 470 471 472 473 474
        if(empty($is_buy)){
            $is_buy = '0';
        }
        $where = [];
        if(!empty($keyword)){
            $where['p.title'] = ['like','%'.$keyword.'%'];
        }
何书鹏 authored
475 476 477 478 479 480 481 482 483 484 485 486 487 488
        switch ($order) {
            case 0:
                $order = ['p.createtime' => 'desc'];
                break;
            case 1:
                $order = ['buy_num' => 'desc'];
                break;
            case 2:
                $order = ['p.current_price' => 'asc'];
                break;
            case 3:
                $order = ['preferential_price' => 'asc'];
                break;
        }
何书鹏 authored
489 490 491 492 493 494 495 496
        $package_order = Db::name('mobile_package_order_info')
            ->alias('poi')
            ->join('mobile_package_order po','po.id = poi.package_order_id')
            ->where('poi.company_id',$this->company_id)
            ->where('poi.user_id',$user_id)
            ->where('po.pay_status','1')
            ->field('poi.id,poi.package_id,poi.people_num')
            ->order(['poi.is_top'=>'desc','poi.people_num'=>'desc'])
何书鹏 authored
497 498 499
            ->limit(1)
            ->buildSql();
        $list = Package::alias('p')
何书鹏 authored
500
            ->join([$package_order=>'poi'],'p.id = poi.package_id','left')
何书鹏 authored
501
            ->join('mobile_package_cart pc','pc.package_id = p.id and pc.user_id='.$user_id,'left')
何书鹏 authored
502
            ->where($where)
何书鹏 authored
503 504
            ->field("
                p.*,
何书鹏 authored
505
                if(poi.id > 0,1,0) is_buy,
何书鹏 authored
506 507 508 509 510
                if(pc.id > 0,1,0) is_add_cart,
                IFNULL((select SUM(current_price) from fa_mobile_secret where id in (p.secret_ids)),0) +
                IFNULL((select SUM(current_price) from fa_mobile_course where id in (p.course_ids)),0) original_price,
                p.buy_num_virtual + p.buy_num_real buy_num,
                IFNULL((select SUM(current_price) from fa_mobile_secret where id in (p.secret_ids)),0) +
何书鹏 authored
511 512
                IFNULL((select SUM(current_price) from fa_mobile_course where id in (p.course_ids)),0) - p.current_price preferential_price,
                poi.people_num
何书鹏 authored
513 514 515 516 517 518 519 520 521 522 523 524 525 526 527
            ")
            ->order($order)
            ->having("is_buy = {$is_buy}")
            ->select();
        foreach ($list as $v) {
            $v->visible([
                'id',
                'title',
                'current_price',
            ])->append([
                'is_buy',
                'is_add_cart',
                'original_price',
                'buy_num',
                'preferential_price',
何书鹏 authored
528
                'people_num',
何书鹏 authored
529 530 531 532 533 534
                'secret_list',
                'course_list',
            ]);
        }
        $this->success('成功',$list);
    }
何书鹏 authored
535 536

    /**
何书鹏 authored
537 538 539 540 541 542 543 544
     * @ApiWeigh (82)
     * @ApiTitle    (企业套餐-购物车数量)
     * @ApiSummary  (企业套餐-购物车数量)
     * @ApiMethod   (POST)
     *
     * @ApiHeaders  (name=token, type=string, required=true, description="请求的Token")
     *
     * @ApiReturn({
何书鹏 authored
545 546 547 548 549
        "code": 1,
        "msg": "成功",
        "time": "1603273475",
        "data": {
            "cart_num": 1, //数量
何书鹏 authored
550
            "pay_price_total": 500, //现价总数
何书鹏 authored
551 552
            "original_price_total": 500 //原价总数
        }
何书鹏 authored
553 554 555 556
    })
     */
    public function packageCartNum()
    {
何书鹏 authored
557
        $list = PackageCart::where('company_id',$this->company_id)->field('id,pay_price,original_price')->select();
何书鹏 authored
558
        $cart_num = count($list);
何书鹏 authored
559
        $pay_price_total = array_sum(array_column($list, 'pay_price'));
何书鹏 authored
560
        $original_price_total = array_sum(array_column($list, 'original_price'));
何书鹏 authored
561
        $this->success('成功',compact('cart_num','pay_price_total','original_price_total'));
何书鹏 authored
562 563 564
    }

    /**
何书鹏 authored
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
     * @ApiWeigh (81)
     * @ApiTitle    (选择套餐规格)
     * @ApiSummary  (选择套餐规格)
     * @ApiMethod   (POST)
     *
     * @ApiHeaders  (name=token, type=string, required=true, description="请求的Token")
     * @ApiParams   (name="package_id", type="inter", required=true, description="套餐ID")
     *
     * @ApiReturn({
        "code": 1, 
        "msg": "成功", 
        "time": "1600774924", 
        "data": [{
            "id": 1, //套餐规格ID
            "package_id": 8, //套餐ID
            "name": "基础版", //规格ID
            "current_price": 500, //现价
            "original_price": "1000.00", //原价
            "people_num": 20, //限制人数
            "is_top": "0", //是否顶配:0=否,1=是
            "createtime": null, 
            "updatetime": null, 
            "is_pay": 1 //是否可以购买:0=否,1=是
        }]
    })
     */
    public function packageSpec()
    {
        $user_id = $this->auth->id;
        $package_id = $this->request->param('package_id');
        empty($package_id) && $this->error('缺少必需参数');
        $info = Package::get($package_id);
        empty($info) && $this->error('套餐信息不存在');
        $list = PackageSpec::where('package_id',$package_id)->select();
        foreach ($list as &$v) {
            // 是否可购买
            $order = Db::name('mobile_package_order_info')
                ->alias('poi')
                ->join('mobile_package_order po','po.id = poi.package_order_id')
                ->where('poi.company_id',$this->company_id)
                ->where('poi.user_id',$user_id)
                ->where('poi.package_id',$package_id)
                ->where('po.pay_status','1')
何书鹏 authored
608
                ->field('poi.id,poi.current_price,poi.people_num,poi.is_top')
何书鹏 authored
609 610 611 612 613 614 615 616 617 618 619 620 621 622
                ->order(['poi.is_top'=>'desc','poi.people_num'=>'desc'])
                ->find();
            $people_num = CompanyUser::where('company_id',$this->company_id)
                ->where('status','1')
                ->count();
            if(!empty($order)){
                // 已购买顶配套餐,直接跳出本次循环
                if($order['is_top'] == '1'){
                    $v['is_pay'] = 0;
                    continue;
                }
                if($order['people_num'] > $people_num){
                    $people_num = $order['people_num'];
                }
何书鹏 authored
623
                $v['current_price'] = $v['current_price']-$order['current_price'];
何书鹏 authored
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
            }
            if($v['is_top'] == '1'){
                $v['is_pay'] = 1;
            }else{
                $v['is_pay'] = $v['people_num'] <= $people_num ? 0 : 1;
            }
        }
        $this->success('成功',$list);
    }

    /**
     * @ApiTitle    (套餐说明)
     * @ApiSummary  (套餐说明)
     * @ApiMethod   (POST)
     *
     * @ApiReturn({
        "code": 1,
        "msg": "成功",
        "time": "1599017563",
        "data": "套餐说明" //套餐说明内容
    })
     */
    public function spec_intro()
    {
        $content = Db::name('mobile_config')->where('id',1)->value('package_spec_intro');
        $this->success('成功', $content);
    }

    /**
     * @ApiWeigh (79)
     * @ApiTitle    (加入购物车)
     * @ApiSummary  (加入购物车)
     * @ApiMethod   (POST)
     *
     * @ApiHeaders  (name=token, type=string, required=true, description="请求的Token")
     * @ApiParams   (name="package_id", type="inter", required=true, description="套餐ID")
     * @ApiParams   (name="package_spec_id", type="inter", required=true, description="套餐规格ID")
     *
     * @ApiReturn({
        "code": 1, 
        "msg": "加入购物车成功", 
        "time": "1600774924", 
        "data": null
    })
     */
    public function packageAddCart()
    {
何书鹏 authored
671
    	$user_id = $this->auth->id;
何书鹏 authored
672 673 674 675 676 677 678 679 680 681 682 683 684 685
        $package_id = $this->request->param('package_id');
        $package_spec_id = $this->request->param('package_spec_id');
        empty($package_id) && $this->error('缺少必需参数');
        empty($package_spec_id) && $this->error('请选择套餐规格');
        $info = PackageSpec::get(['package_id'=>$package_id,'id'=>$package_spec_id]);
        empty($info) && $this->error('套餐规格信息不存在');
        // 是否可购买
        $order = Db::name('mobile_package_order_info')
            ->alias('poi')
            ->join('mobile_package_order po','po.id = poi.package_order_id')
            ->where('poi.company_id',$this->company_id)
            ->where('poi.user_id',$user_id)
            ->where('poi.package_id',$package_id)
            ->where('po.pay_status','1')
何书鹏 authored
686
            ->field('poi.id,poi.current_price,poi.people_num,poi.is_top')
何书鹏 authored
687 688 689 690 691 692 693
            ->order(['poi.is_top'=>'desc','poi.people_num'=>'desc'])
            ->find();
        if(!empty($order)){
            // 已购买顶配套餐,直接跳出本次循环
            if($order['is_top'] == '1'){
                $this->error('您已购买顶级套餐规格,无需再购买其他套餐规格');
            }
何书鹏 authored
694
            $pay_price = $info['current_price']-$order['current_price'];
何书鹏 authored
695 696 697 698 699
        }else{
            $pay_price = $info['current_price'];
        }
        PackageCart::create([
            'company_id' => $this->company_id,
何书鹏 authored
700
            'user_id' => $user_id,
何书鹏 authored
701 702 703
            'package_id' => $package_id,
            'package_spec_id' => $package_spec_id,
            'pay_price' => $pay_price,
何书鹏 authored
704 705
            'current_price' => $info['current_price'],
            'original_price' => $info['original_price'],
何书鹏 authored
706 707 708 709 710 711 712
            'people_num' => $info['people_num'],
            'is_top' => $info['is_top']
        ]);
        $this->success('加入购物车成功');
    }

    /**
何书鹏 authored
713
     * @ApiWeigh (79)
何书鹏 authored
714 715 716 717 718 719 720
     * @ApiTitle    (套餐购物车)
     * @ApiSummary  (套餐购物车)
     * @ApiMethod   (POST)
     *
     * @ApiHeaders  (name=token, type=string, required=true, description="请求的Token")
     *
     * @ApiReturn({
何书鹏 authored
721 722 723 724 725 726 727 728 729 730 731 732 733 734 735
        "code": 1,
        "msg": "成功",
        "time": "1603275248",
        "data": {
            "list": [{ //购物车信息
                "id": 1, //购物车ID
                "pay_price": "500.00", //现价
                "original_price": "500.00", //原价
                "package": { //套餐信息
                    "id": 8, //套餐ID
                    "title": "1" //套餐标题
                }
            }],
            "pay_price_total": 500 //应付金额
        }
何书鹏 authored
736 737 738 739
    })
     */
    public function packageCartList()
    {
何书鹏 authored
740
        $list = PackageCart::with(['package'])
何书鹏 authored
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
            ->where('company_id',$this->company_id)
            ->select();
        foreach ($list as $v) {
            $v->visible(['id','pay_price','original_price','package']);
            $v->getRelation('package')->visible(['id','title']);
        }
        $pay_price_total = array_sum(array_column($list, 'pay_price'));
        $this->success('成功',compact('list','pay_price_total'));
    }

    /**
     * @ApiWeigh (79)
     * @ApiTitle    (套餐下单)
     * @ApiSummary  (套餐下单)
     * @ApiMethod   (POST)
     *
     * @ApiHeaders (name=token, type=string, required=true, description="请求的Token")
     * @ApiParams (name="pay_type", type="string", required=true, description="支付方式:wechat=微信,alipay=支付宝")
     *
     * @ApiReturn({
        "code": 1,
        "msg": "成功",
        "time": "1599046220",
        "data": {
            "id": 1, //试卷ID
            "title": "测试试卷", //试卷标题
            "year": 2015, //年费(单位:年)
            "time": 100, //答题时间(单位:分)
            "pass_score": 80, //合格分数
            "description": "这个还行", //试卷描述
            "do_num": 10, //回答人数
            "full_score": 100 //试卷分数(单位:分)
        }
    })
     */
    public function pay()
    {
        $param = $this->request->param();
        if (!$param['pay_type'] || !in_array($param['pay_type'], ['alipay', 'wechat'])) {
            $this->error("请选择支付方式");
        }
        // 创建订单
        $model = new PackageOrder;
        $model->add($this->auth->getUser(), $param['pay_type']);
        //回调链接
        $notifyurl = $this->request->root(true) . '/mobile/notify/notifyPackage/paytype/' . $param['pay_type'];
        $payment = Service::submitOrder($model['pay_price'], $model['order_sn'], $param['pay_type'], '企业套餐', $notifyurl, null, 'app');
        $this->success('成功',$payment);
何书鹏 authored
789
    }
何书鹏 authored
790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960

    /**
     * @ApiWeigh (79)
     * @ApiTitle    (我的招聘-我发布的)
     * @ApiSummary  (我的招聘-我发布的)
     * @ApiMethod   (POST)
     *
     * @ApiHeaders  (name=token, type=string, required=true, description="请求的Token")
     * @ApiParams (name="page", type="inter", required=false, description="当前页(默认1)")
     * @ApiParams (name="page_num", type="inter", required=false, description="每页显示数据个数(默认10)")
     * @ApiParams   (name="type", type="inter", required=false, description="岗位类型:1=全职,2=兼职,3=其他")
     *
     * @ApiReturn({
        "code": 1,
        "msg": "成功",
        "time": "1602406820",
        "data": {
            "total": 1, //总条数
            "per_page": 15,
            "current_page": 1,
            "last_page": 1,
            "data": [{
                "id": 1, //职位ID
                "name": "123", //职位名称
                "type": "1", //职位类型
                "salary": "9753.20", //工资
                "start_time": "2020.10.11", //开始工作时间
                "end_time": "2020.10.11", //结束工作时间
                "address": "测试地址", //地址
                "is_has_red": "0", //是否有小红点:0=否,1=是
                "type_text": "全职" //职位类型说明
            }]
        }
    })
     */
    public function companyJob()
    {
        $page = $this->request->param('page', 1, 'intval');
        $page_num = $this->request->param('page_num', 10, 'intval');
        $type = $this->request->param('type');
        $where['cj.status'] = '1';
        // 求职类型
        if(!empty($type)){
            $where['cj.type'] = $type;
        }
        $data = CompanyJob::alias('cj')
            ->join('mobile_company_job_resume cjr',"cjr.company_job_id = cj.id and cjr.is_view = '0'",'left')
            ->where($where)
            ->field('
                cj.id,
                cj.name,
                cj.type,
                cj.salary,
                cj.start_time,
                cj.end_time,
                cj.address,
                if(cjr.id > 0,1,0) is_has_red
            ')
            ->order(['is_has_red' => 'desc','cj.createtime' => 'desc'])
            ->paginate($page_num,false,['page'=>$page])
            ->toArray();
        $this->success('成功', $data);
    }

    /**
     * @ApiWeigh (77)
     * @ApiTitle    (我的招聘-我发布的-删除)
     * @ApiSummary  (我的招聘-我发布的-删除)
     * @ApiMethod   (POST)
     *
     * @ApiHeaders  (name=token, type=string, required=true, description="请求的Token")
     * @ApiParams (name="company_job_id", type="inter", required=false, description="招聘ID")
     *
     * @ApiReturn({
        "code": 1,
        "msg": "成功",
        "time": "1602234925",
        "data": null
    })
     */
    public function companyJobDel()
    {
        $company_job_id = $this->request->param('company_job_id');
        empty($company_job_id) && $this->error('缺少必需参数');
        $info = CompanyJob::get(['user_id'=>$this->auth->id,'id'=>$company_job_id]);
        empty($info) && $this->error('招聘信息不存在');
        Db::startTrans();
        try {
            // 删除投递的简历
            $info->resume()->delete();
            // 删除招聘职位
            $info->delete();
            Db::commit();
        } catch (PDOException $e) {
            Db::rollback();
            $this->error($e->getMessage());
        } catch (Exception $e) {
            Db::rollback();
            $this->error($e->getMessage());
        }
        $this->success('删除成功');
    }

    /**
     * @ApiWeigh (75)
     * @ApiTitle    (我的招聘-我发布的-查看简历-详情)
     * @ApiSummary  (我的招聘-我发布的-查看简历-详情)
     * @ApiMethod   (POST)
     *
     * @ApiParams   (name="company_job_id", type="inter", required=false, description="招聘职位ID")
     *
     * @ApiReturn({
        "code": 1,
        "msg": "成功",
        "time": "1602416171",
        "data": {
            "id": 2, //招聘ID
            "user_id": 15,
            "company_id": 7,
            "name": "101640",
            "type": "3", //职位类型
            "start_time": "2020.10.11", //开始工作时间
            "end_time": "2020.10.11", //结束工作时间
            "salary": "9753.20", //工资
            "lng": "123",
            "lat": "456",
            "address": "测试地址", //地址
            "house_number": "测试门牌号", //门牌号
            "mobile": "15133120361", //电话
            "description": "sdfkl",
            "other_desc": "dsf",
            "status": "1",
            "createtime": 1602415172,
            "updatetime": 1602415172,
            "weigh": 0,
            "type_text": "其他" //职位类型描述
        }
    })
     */
    public function companyJobInfo()
    {
        $company_job_id = $this->request->param('company_job_id');
        empty($company_job_id) && $this->error('缺少必需参数');
        $info = CompanyJob::get($company_job_id);
        empty($info) && $this->error('招聘信息不存在');
        $this->success('成功', $info);
    }

    /**
     * @ApiWeigh (73)
     * @ApiTitle    (我的招聘-我发布的-查看简历-列表)
     * @ApiSummary  (我的招聘-我发布的-查看简历-列表)
     * @ApiMethod   (POST)
     *
     * @ApiHeaders  (name=token, type=string, required=true, description="请求的Token")
     * @ApiParams (name="page", type="inter", required=false, description="当前页(默认1)")
     * @ApiParams (name="page_num", type="inter", required=false, description="每页显示数据个数(默认10)")
     * @ApiParams   (name="company_job_id", type="inter", required=false, description="招聘职位ID")
     *
     * @ApiReturn({
        "code": 1,
        "msg": "成功",
        "time": "1602417085",
        "data": {
            "total": 1, //数据总数
            "per_page": 15,
            "current_page": 1,
            "last_page": 1,
            "data": [{
                "id": 4, //投递ID
                "is_view": "0", //是否已被查看:0=否,1=是
何书鹏 authored
961
                "createtime": "2020.10.11 20:31", //投递时间
何书鹏 authored
962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982
                "user": { //投递者信息
                    "id": 15, //用户ID
                    "nickname": "", //真实姓名
                    "image": "" //头像
                }
            }]
        }
    })
     */
    public function companyJobResume()
    {
        $page = $this->request->param('page', 1, 'intval');
        $page_num = $this->request->param('page_num', 10, 'intval');
        $company_job_id = $this->request->param('company_job_id');
        empty($company_job_id) && $this->error('缺少必需参数');
        $data = CompanyJobResume::with(['user'])
            ->where('status','0')
            ->where('company_job_id',$company_job_id)
            ->order('createtime desc')
            ->paginate($page_num,false,['page'=>$page])
            ->each(function($v){
何书鹏 authored
983 984 985
                // 投递时间
                $v->createtime = date('Y.m.d H:i',$v->createtime);
                $v->visible(['id','is_view','createtime','user']);
何书鹏 authored
986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065
                $v->getRelation('user')->visible(['id','image','nickname']);
            })->toArray();
        $this->success('成功', $data);
    }

    /**
     * @ApiWeigh (71)
     * @ApiTitle    (我的招聘-我发布的-查看简历-查看)
     * @ApiSummary  (我的招聘-我发布的-查看简历-查看)
     * @ApiMethod   (POST)
     *
     * @ApiHeaders  (name=token, type=string, required=true, description="请求的Token")
     * @ApiParams   (name="company_job_resume_id", type="inter", required=false, description="投递简历ID")
     *
     * @ApiReturn({
        "code": 1,
        "msg": "成功",
        "time": "1602417085",
        "data": {
            "total": 1, //数据总数
            "per_page": 15,
            "current_page": 1,
            "last_page": 1,
            "data": 简历链接
        }
    })
     */
    public function resumeView()
    {
        $company_job_resume_id = $this->request->param('company_job_resume_id');
        empty($company_job_resume_id) && $this->error('缺少必需参数');
        $info = CompanyJobResume::get($company_job_resume_id);
        empty($info) && $this->error('投递信息不存在');
        $info->is_view = '1';
        $info->save();
        $this->success('成功', $info['resume']);
    }

    /**
     * @ApiWeigh (71)
     * @ApiTitle    (我的招聘-我发布的-查看简历-不合适)
     * @ApiSummary  (我的招聘-我发布的-查看简历-不合适)
     * @ApiMethod   (POST)
     *
     * @ApiHeaders  (name=token, type=string, required=true, description="请求的Token")
     * @ApiParams   (name="company_job_resume_id", type="inter", required=false, description="投递简历ID")
     *
     * @ApiReturn({
        "code": 1,
        "msg": "成功",
        "time": "1602417085",
        "data": {
            "total": 1, //数据总数
            "per_page": 15,
            "current_page": 1,
            "last_page": 1,
            "data": null
        }
    })
     */
    public function resumeReject()
    {
        $company_job_resume_id = $this->request->param('company_job_resume_id');
        empty($company_job_resume_id) && $this->error('缺少必需参数');
        $info = CompanyJobResume::get($company_job_resume_id);
        empty($info) && $this->error('投递信息不存在');
        $info->status = '1';
        $info->save();
        $this->success('操作成功');
    }

    /**
     * @ApiWeigh (69)
     * @ApiTitle    (我的招聘-我下载的)
     * @ApiSummary  (我的招聘-我下载的)
     * @ApiMethod   (POST)
     *
     * @ApiHeaders  (name=token, type=string, required=true, description="请求的Token")
     * @ApiParams (name="page", type="inter", required=false, description="当前页(默认1)")
     * @ApiParams (name="page_num", type="inter", required=false, description="每页显示数据个数(默认10)")
何书鹏 authored
1066
     * @ApiParams (name="type", type="inter", required=false, description="岗位类型:1=全职,2=兼职,3=其他")
何书鹏 authored
1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102
     *
     * @ApiReturn({
        "code": 1,
        "msg": "成功",
        "time": "1602420197",
        "data": {
            "total": 1,
            "per_page": 15,
            "current_page": 1,
            "last_page": 1,
            "data": [{
                "id": 1, //下载ID
                "createtime": "2020.10.11 20:31", //下载时间
                "user_job": { //求职信息
                    "id": 2, //求职ID
                    "name": "怎么说", //职位名称
                    "start_time": "2020.10.11", //开始工作时间
                    "end_time": "2020.10.11", //结束工作时间
                    "salary": "9753.20", //工资
                    "address": "测试地址", //地址
                    "user": { //求职者信息
                        "id": 15, //用户ID
                        "nickname": "", //真实姓名
                        "image": "" //头像
                    },
                    "type_text": "全职", //职位类型说明
                    "qualification_arr": [] //资质证明
                }
            }]
        }
    })
     */
    public function userJob()
    {
        $page = $this->request->param('page', 1, 'intval');
        $page_num = $this->request->param('page_num', 10, 'intval');
何书鹏 authored
1103
        $type = $this->request->param('type');
何书鹏 authored
1104 1105 1106 1107
        $where = [
            'ujd.status' => '0',
            'ujd.company_id' => $this->company_id,
        ];
何书鹏 authored
1108 1109
        // 求职类型
        if(!empty($type)){
何书鹏 authored
1110
            $where['uj.type'] = $type;
何书鹏 authored
1111
        }
何书鹏 authored
1112 1113 1114 1115 1116
        $data = UserJobDownload::alias('ujd')
            ->join('mobile_user_job uj','uj.id = ujd.user_job_id')
            ->with(['user_job'=>['user']])
            ->where($where)
            ->order('ujd.createtime desc')
何书鹏 authored
1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159
            ->paginate($page_num,false,['page'=>$page])
            ->each(function($v){
                $v->createtime = date('Y.m.d H:i',$v->createtime);
                $v->visible(['id','createtime','user_job']);
                $v->getRelation('user_job')->visible(['id','name','salary','start_time','end_time','address','user']);
                $v->getRelation('user_job')->getRelation('user')->visible(['id','image','nickname']);
            })->toArray();
        $this->success('成功', $data);
    }

    /**
     * @ApiWeigh (67)
     * @ApiTitle    (我的招聘-我下载的-查看简历)
     * @ApiSummary  (我的招聘-我下载的-查看简历)
     * @ApiMethod   (POST)
     *
     * @ApiHeaders  (name=token, type=string, required=true, description="请求的Token")
     * @ApiParams   (name="user_job_id", type="inter", required=false, description="求职ID")
     *
     * @ApiReturn({
        "code": 1,
        "msg": "成功",
        "time": "1602417085",
        "data": {
            "total": 1, //数据总数
            "per_page": 15,
            "current_page": 1,
            "last_page": 1,
            "data": 简历链接
        }
    })
     */
    public function userJobResumeView()
    {
        $user_job_id = $this->request->param('user_job_id');
        empty($user_job_id) && $this->error('缺少必需参数');
        $info = UserJob::get($user_job_id);
        empty($info) && $this->error('求职信息不存在');
        $this->success('成功', $info['resume']);
    }

    /**
     * @ApiWeigh (65)
何书鹏 authored
1160 1161
     * @ApiTitle    (我的招聘-我下载的-不合适)
     * @ApiSummary  (我的招聘-我下载的-不合适)
何书鹏 authored
1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189
     * @ApiMethod   (POST)
     *
     * @ApiHeaders  (name=token, type=string, required=true, description="请求的Token")
     * @ApiParams   (name="user_job_download_id", type="inter", required=false, description="下载ID")
     *
     * @ApiReturn({
        "code": 1,
        "msg": "成功",
        "time": "1602417085",
        "data": {
            "total": 1, //数据总数
            "per_page": 15,
            "current_page": 1,
            "last_page": 1,
            "data": null
        }
    })
     */
    public function userJobResumeViewReject()
    {
        $user_job_download_id = $this->request->param('user_job_download_id');
        empty($user_job_download_id) && $this->error('缺少必需参数');
        $info = UserJobDownload::get($user_job_download_id);
        empty($info) && $this->error('下载记录不存在');
        $info->status = '1';
        $info->save();
        $this->success('操作成功');
    }
1190
}