Choose.php 7.1 KB
<?php

namespace app\api\controller;

use app\api\model\ChoosePage;
use app\api\model\Exhibition;
use app\api\model\Video;
use app\common\controller\Api;
use think\Db;
use think\Validate;
use think\Config;

/**
 * 选购助手接口
 */
class Choose extends Api
{

    protected function _initialize()
    {
        parent::_initialize();
    }


    /**
     * @ApiTitle    (获取选购助手列表)
     * @ApiSummary  (获取选购助手列表)
     * @ApiMethod   (POST)
     * @ApiRoute    (/api/choose/getChooseList)
     * @ApiHeaders  (name=token, type=string, required=false, description="请求的Token")
     * @ApiReturn({
    "code": 1,
    "msg": "SUCCESS",
    "time": "1587518501",
    "data": [
    {
    "id": 1,
    "title": "公司介绍", 标题
    "image": "http://q7s0a1rb4.bkt.clouddn.com/uploads/20200420/26f5e51b8ac7fbd6f1c649cc45a18265.png", 图片
    },
    {
    "id": 2,
    "title": "展会活动",
    "image": "http://q7s0a1rb4.bkt.clouddn.com/uploads/20200420/26f5e51b8ac7fbd6f1c649cc45a18265.png",
    }}
    }
    })
     */
    public function getChooseList(){
        $model = new ChoosePage();
        $data = $model->selectData([],$this->lang);
        $this->success('SUCCESS',$data);
    }

    /**
     * @ApiTitle    (获取选购助手图文详情)
     * @ApiSummary  (获取选购助手图文详情)
     * @ApiMethod   (POST)
     * @ApiRoute    (/api/choose/getChooseInfo)
     * @ApiHeaders  (name=token, type=string, required=false, description="请求的Token")
     * @ApiParams  (name=choose_id, type=string, required=true, description="选购助手id")
     * @ApiReturn({


    })
     */
    public function getChooseInfo(){
        $model = new ChoosePage();
        $choose_id = $this->request->param('choose_id');
        if (!$choose_id) $this->error('缺少参数 choose_id!');

        if ($this->lang == 'ch') $field = 'id,ch_title title,ch_content content,image,phone,wechat,activitytime';
        else $field = 'id,en_title title,en_content content,image,phone,wechat,activitytime';

        $data = $model->where(['id'=>$choose_id])->field($field)->find();
        $this->success('SUCCESS',$data);
    }

    /**
     * @ApiTitle    (获取选购助手短视频列表)
     * @ApiSummary  (获取选购助手短视频列表)
     * @ApiMethod   (POST)
     * @ApiRoute    (/api/choose/getChooseVideo)
     * @ApiHeaders  (name=token, type=string, required=false, description="请求的Token")
     * @ApiParams  (name=page, type=string, required=true, description="页数")
     * @ApiReturn({


    })
     */
    public function getChooseVideo(){
        $model = new Video();
        $page = $this->request->param('page');
        $limit = Config::get('paginate.index_rows');

        $data = $model->selectPageData([],$page,$limit,$this->lang);
        $this->success('SUCCESS',$data);
    }

    /**
     * @ApiTitle    (添加展会预约(个人预约))
     * @ApiSummary  (添加展会预约(个人预约))
     * @ApiMethod   (POST)
     * @ApiRoute    (/api/choose/addExhibitionType1)
     * @ApiHeaders  (name=token, type=string, required=true, description="请求的Token")
     * @ApiParams  (name=name, type=string, required=true, description="姓名")
     * @ApiParams  (name=phone, type=string, required=true, description="手机号")
     * @ApiParams  (name=code, type=string, required=true, description="验证码")
     * @ApiParams  (name=sex, type=string, required=true, description="性别:1=男,2=女")
     * @ApiReturn({
    "code": 1,
    "msg": "SUCCESS",
    "time": "1587472510",
    "data":
    ]
    }
    })
     */
    public function addExhibitionType1(){
        $model = new Exhibition();
        $userId = $this->getUserId();
        $data = $this->request->param();
        $data['user_id'] = $userId;
        $data['status'] = 1; //个人预约
        $validate = new Validate([
            'name' => 'require',
            'phone' => ['^1\d{10}$','require'],
            'sex' => 'require',
            'code' => 'require',
        ]);

        $validate->message([
            'name' => '缺少参数 name!',
            'phone.require' => '缺少参数 phone!',
            'sex' => '缺少参数 sex!',
            'phone' => '手机号格式错误',
            'code' => '缺少参数 code!',
        ]);

        if (!$validate->check($data)) {
            $this->error($validate->getError());
        }

        $smsModel = new \app\common\model\Sms();
        $last = $smsModel->where(['mobile'=>$data['phone'],'code'=>$data['code']])->find();
        if ($last) {
            if ($last['createtime']+600 < time()) $this->error('验证码已失效');
            unset($data['code']);
            $data = $model->save($data);
            $this->success('SUCCESS',$data);
        } else {
            $this->error('验证码不正确');
        }
    }

    /**
     * @ApiTitle    (添加展会预约(商家预约))
     * @ApiSummary  (添加展会预约(商家预约))
     * @ApiMethod   (POST)
     * @ApiRoute    (/api/choose/addExhibitionType2)
     * @ApiHeaders  (name=token, type=string, required=true, description="请求的Token")
     * @ApiParams  (name=name, type=string, required=true, description="姓名")
     * @ApiParams  (name=phone, type=string, required=true, description="手机号")
     * @ApiParams  (name=code, type=string, required=true, description="验证码")
     * @ApiParams  (name=sex, type=string, required=true, description="性别:1=男,2=女")
     * @ApiParams  (name=store_type, type=string, required=true, description="商家类型:1=公司,2=餐厅")
     * @ApiParams  (name=num, type=string, required=true, description="参展人数")
     * @ApiReturn({
    "code": 1,
    "msg": "SUCCESS",
    "time": "1587472510",
    "data":
    })
     */
    public function addExhibitionType2(){
        $model = new Exhibition();
        $userId = $this->getUserId();
        $data = $this->request->param();
        $data['user_id'] = $userId;
        $data['status'] = 2; //商家预约
        $validate = new Validate([
            'name' => 'require',
            'phone' => ['^1\d{10}$','require'],
            'sex' => 'require',
            'store_type' => 'require',
            'num' => 'require',
            'code' => 'require',
        ]);

        $validate->message([
            'name' => '缺少参数 name!',
            'phone.require' => '缺少参数 phone!',
            'phone' => '手机号格式错误',
            'sex' => '缺少参数 sex!',
            'store_type' => '缺少参数 store_type!',
            'num' => '缺少参数 num!',
            'code' => '缺少参数 code!',
        ]);

        if (!$validate->check($data)) {
            $this->error($validate->getError());
        }

        $smsModel = new \app\common\model\Sms();
        $last = $smsModel->where(['mobile'=>$data['phone'],'code'=>$data['code']])->find();
        if ($last) {
            if ($last['createtime']+600 < time()) $this->error('验证码已失效');
            unset($data['code']);
            $data = $model->save($data);
            $this->success('SUCCESS',$data);
        } else {
            $this->error('验证码不正确');
        }
    }
}