<?php
/**
 * 公用控制器部分-无需授权
 */
namespace app\modules\shops\v1\controllers;
use app\modules\common\Helper;
use app\modules\common\Verify;
use app\modules\logic\services\UserService;
use app\modules\logic\services\UploadService;
use app\modules\logic\model\UsersShopInfoModel;
use app\modules\logic\model\UsersModel;
use app\modules\logic\model\SysCarmodelSetModel;
use app\modules\logic\model\SysProductSetModel;
use app\modules\logic\model\SysBasePriceSetModel;
use app\modules\logic\model\ShopRoleModel;
use app\modules\logic\model\MerchTypeModel;
use app\modules\third\sms\Sms;
use Yii;
use yii\web\Controller;

class CommonController extends MiddleController {
	/**
	 * 返回
	 * @param $code
	 * @param string $info
	 * @param string $controller
	 * @param string $total
	 */
	protected function response($code, $info = '', $total = '', $controller = 'common') {
		return parent::response($code, $info, $total, $controller);
	}
	/**
	 * [actionReg 门店注册]
	 * @apiDoc
	 * @api     v1/common/reg
	 * @group   common
	 * @name    门店注册
	 * @desc    门店APP-注册
	 * @method  POST
     * @param mobile string 手机号 req
     * @param password string 密码 req
     * @param verify string 短信验证码 req
     * @param wx_nick string 微信昵称 noreq
     * @param wx_openid string 微信openid noreq
	 * @author JOHN.W
	 * @version [1.0]
	 * @return  json
       {
        "code": "000000",
        "msg": "注册成功",
        "info": {
            "token": "b200fc29e11d02f8948115efe9067606_user",
            "auth": "pass"
        }
        }
	 */
    public function actionReg()
    {

        if (!isset($this->para['mobile']) || empty($this->para['mobile'])) {
            return $this->response('para_miss', '请输入手机号');
        }

        if (!Verify::phoneFormat($this->para['mobile'])) {
            return $this->response('para_error', '手机号格式错误');
        }
        $phone_flag = UserService::userPhoneExists($this->para['mobile'],'shop');
        if ($phone_flag) {
            return $this->response('Has_register');
        }

        if (!isset($this->para['password']) || empty($this->para['password'])) {
            return $this->response('para_miss', '请输入密码');
        }
        if (strlen($this->para['password']) < 6 || strlen($this->para['password']) > 20) {
            return $this->response('para_miss', '密码长度限制为6-20位');
        }
        if (!isset($this->para['verify']) || empty($this->para['verify'])) {
            return $this->response('para_miss', '请输入验证码');
        }
        $sms = new Sms();
        $flag_verify = $sms->verifyCode(['mobile'=>$this->para['mobile'],'sms_code'=>$this->para['verify']]);
        if (!$flag_verify) {
            return $this->response('para_error', '短信验证码不正确');
        }
        $data_insert = array(
            'username' => $this->para['mobile'],
            'mobile' => $this->para['mobile'],
            'password' => $this->para['password'],
            'source' => $this->para['terminalType'],
            'type' => 'shop',
            'wx_nick' => isset($this->para['wx_nick'])?$this->para['wx_nick']:'',
            'wx_openid' => isset($this->para['wx_openid'])?$this->para['wx_openid']:'',
        );

        $result = UserService::reg($data_insert);

        if ($result === 'Has_register') {
            return $this->response('Has_register');
        } elseif ($result) {
            return $this->response('deal_succ', '注册成功', $result);
        } else {
            return $this->response('deal_false', '注册失败');
        }
    }

    /**
     * [actionLogin 门店登录]
     * @apiDoc
     * @api     v1/common/login
     * @group   common
     * @name    门店登录
     * @desc    门店APP-登录
     * @method  POST
     * @param username string 账号 req
     * @param password string 密码 req
     * @author JOHN.W
     * @version [1.0]
     * @return  json
        {
        "code": "000000",
        "msg": "登录成功",
        "info": {
        "token": "b200fc29e11d02f8948115efe9067606_user",
            "auth": "pass"
        }
        }
     */
    public function actionLogin(){

        if (!isset($this->para['username']) || empty($this->para['username'])) {
            return $this->response('para_miss', '请输入账号');
        }
        if (!isset($this->para['password']) || empty($this->para['password'])) {
            return $this->response('para_miss', '请输入密码');
        }
        /*if (!Verify::phoneFormat($this->para['phone'])) {
            return $this->response('para_error', '手机号格式错误');
        }*/
        $redis = Yii::$app->redis;
        $username = $this->para['username'];
        $redis_key_locked = md5($username . "_" . "LOCKED");

        $result = UserService::login($this->para,'shop');
        if (in_array($result, array('lock', 'error', 'not_exists', 'log_error','pw_error'), true)) {
            //登陆失败；添加错误次数
            $redis_key_exist = $redis->exists($redis_key_locked);
            if ($redis_key_exist) {
                $number = $redis->incr($redis_key_locked);
            } else {
                $redis->set($redis_key_locked, 1, "EX", '3600');
                $number = 1;
            }
            $_number = 3 - $number;
            if ($result == 'lock') {
                return $this->response('para_error', "用户已锁定");
            } elseif ($result == 'error') {
                return $this->response('para_error', "用户名或密码错误," . "剩余登录次数:" . $_number . "次");
            } elseif ($result == 'not_exists') {
                return $this->response('para_error', '账号不存在,' . "剩余登录次数:" . $_number . "次");
            }elseif ($result == 'pw_error') {
                return $this->response('para_error', '用户名或密码错误,' . "剩余登录次数:" . $_number . "次");
            }else {
                return $this->response('deal_false', '处理登录记录失败' . "剩余登录次数:" . $_number . "次");
            }
        } else {
            //登录成功；删除错误次数
            $redis_key_exist = $redis->exists($redis_key_locked);
            if ($redis_key_exist) {
                $redis->del($redis_key_locked);
            }
            return $this->response('deal_succ', '登录成功', $result);
        }
    }
    /**
     * [actionModpwd 找回密码]
     * @apiDoc
     * @api     v1/common/modpwd
     * @group   common
     * @name    找回密码
     * @desc    门店APP-找回密码
     * @method  POST
     * @param username string 账号 req
     * @param mobile string 手机号 req
     * @param password string 新密码 req
     * @param verify string 短信验证码 req
     * @author JOHN.W
     * @version [1.0]
     * @return  json
        {
        "code": "000000",
        "msg": "修改成功",
        "info": ''
        }
     */
    public function actionModpwd(){
        if (!isset($this->para['username']) || empty($this->para['username'])) {
            return $this->response('para_miss', '请输入账号');
        }
        if (!isset($this->para['mobile']) || empty($this->para['mobile'])) {
            return $this->response('para_miss', '请输入手机号');
        }
        if (!isset($this->para['password']) || empty($this->para['password'])) {
            return $this->response('para_miss', '请输入新密码');
        }
        //校验账号+手机号是否一致
        $user_id  = UserService::checkUnameMobile($this->para['username'],$this->para['mobile']);
        if($user_id==false){
            return $this->response('para_miss', '账号和手机号不匹配');
        }
        $sms = new Sms();
        $flag_verify = $sms->verifyCode(['mobile'=>$this->para['mobile'],'sms_code'=>$this->para['verify']]);
        if (!$flag_verify) {
            return $this->response('para_error', '短信验证码不正确');
        }
        $where = [
            'user_id'=>$user_id
        ];
        $result = UserService::updatePassWord($where,$this->para['password']);
        return $this->response('deal_succ', '修改成功', $result);
    }
    /**
     * [actionWxlogin 微信登录]
     * @apiDoc
     * @api    v1/common/wxlogin
     * @group  common
     * @name   微信登录
     * @desc   微信快捷登录
     * @method POST
     * @param wx_openid string 微信openid req
     * @return json
        {
            "code": "003666",
            "msg": "用户未注册"
        }
        
        {
        "code": "000000",
        "msg": "登录成功",
        "info": {
            "token": "b200fc29e11d02f8948115efe9067606_user",
            "auth": "pass"
        }    
        }
     */
    public function actionWxlogin(){
        if (!isset($this->para['wx_openid']) || empty($this->para['wx_openid'])) {
            return $this->response('para_miss', '微信openid不能为空');
        }
        $user_id = UserService::checkWxOpenId($this->para['wx_openid']);
        if($user_id==false){
            return $this->response('no_register', '用户未注册');
        }
        $redis = Yii::$app->redis;
        $username = $this->para['wx_openid'];
        $redis_key_locked = md5($username . "_" . "LOCKED");
        $result =UserService::LoginByUid($user_id,'shop');
        if (in_array($result, array('lock', 'error', 'not_exists', 'log_error','pw_error'), true)) {
            //登陆失败；添加错误次数
            $redis_key_exist = $redis->exists($redis_key_locked);
            if ($redis_key_exist) {
                $number = $redis->incr($redis_key_locked);
            } else {
                $redis->set($redis_key_locked, 1, "EX", '3600');
                $number = 1;
            }
            $_number = 3 - $number;
            if ($result == 'lock') {
                return $this->response('para_error', "用户已锁定");
            } elseif ($result == 'error') {
                return $this->response('para_error', "用户名或密码错误," . "剩余登录次数:" . $_number . "次");
            } elseif ($result == 'not_exists') {
                return $this->response('para_error', '账号不存在,' . "剩余登录次数:" . $_number . "次");
            }elseif ($result == 'pw_error') {
                return $this->response('para_error', '用户名或密码错误,' . "剩余登录次数:" . $_number . "次");
            }else {
                return $this->response('deal_false', '处理登录记录失败' . "剩余登录次数:" . $_number . "次");
            }
        } else {
            //登录成功；删除错误次数
            $redis_key_exist = $redis->exists($redis_key_locked);
            if ($redis_key_exist) {
                $redis->del($redis_key_locked);
            }
            return $this->response('deal_succ', '登录成功', $result);
        }
    }
    /**
     * [actionApprove 提交认证]
     * @apiDoc
     * @api     v1/common/approve
     * @group   common
     * @name    提交认证
     * @desc    门店APP-提交认证-审核状态【0待审核，1通过，2拒绝，3驳回】   
     * @method  POST
     * @param  name string 名称 req
     * @param  address string 地址 req
     * @param  legal_person string 法人 req
     * @param  info_mobile string 法人电话 req
     * @param  tel string 固定电话 req
     * @param  merch_type_id int 商户性质ID req
     * @param  door_pic int 门头照 req
     * @param  license int 营业执照图 req
     * @param  parent_id int 集团user_id[连锁认证必传] noreq
     * @param  operate_scope string 经营范围 req
     * @author JOHN.W
     * @version [1.0]
     * @return  json
     {
        "code": "000000",
        "msg": "提交成功",
        "info": ''
        }
     */
    public function actionApprove(){
        if (empty($this->user_id)) {
            return $this->response('para_miss_user', '未能识别用户标志');
        }
        $UsersShopInfo = new UsersShopInfoModel();
        //查询门店是否认证或者驳回
        $row = $UsersShopInfo->getWidgetRow(['cols'=>['user_id','verify_status'],'user_id'=>$this->user_id]);
        $user_id  = 0;
        if(!empty($row) && isset($row['verify_status'])){
            switch ($row['verify_status']) {
                case '0':
                    return $this->response('deal_succ', '正在审核中',['auth'=>'wait']);
                    break;
                case '1':
                    return $this->response('deal_succ', '审核已通过',['auth'=>'pass']);
                    break;
                case '2':
                   return $this->response('deal_succ', '审核已拒绝请联系平台',['auth'=>'deny']);
                    break;
                default:
            }
           $user_id =  $row['user_id'];
        }
        $param = Helper::elements(['name','address','legal_person','info_mobile','tel','merch_type_id','door_pic','license','operate_scope'],$this->para,'');
        $param['user_id'] = $this->user_id;

        $Users = new UsersModel();
        if(isset($this->para['parent_id']) && !empty($this->para['parent_id'])){
            $Users->saveUs(['realname'=>$param['legal_person'],'parent_id'=>$this->para['parent_id']],$user_id);
        }else{
            $Users->saveUs(['realname'=>$param['legal_person']],$user_id);
        }
        $res = $UsersShopInfo->saveUs($param);
        return $this->response('deal_succ', '提交成功',['auth'=>'wait']);
    }
   /**
     * [actionLogout 注销]
     * @apiDoc
     * @api     v1/common/logout
     * @group   common
     * @name    注销
     * @desc    门店APP-注销登录
     * @method  POST
     * @param token string Token req
     * @author JOHN.W
     * @version [1.0]
     * @return  json
        {
        "code": "000000",
        "msg": "退出成功",
        "info": ''
        }
     */
     public function actionLogout()
    {
        if (empty($this->user_id)) {
            return $this->response('para_miss', '用户id为空');
        }
        $user_id = $this->user_id;
        $data = [
            'user_id' => $this->user_id,
            'registration' => '',
            'type' => 'shop',
            'source' => '',
        ];
        UserService::delToken($this->para['token']);
        //UserService::addUserJPush($data);
        return $this->response('deal_succ', '退出成功');
    }
    /**
     * [actionSaveregid 绑定客户的registrationid]
     * @apiDoc
     * @api     v1/common/saveregid
     * @group   common
     * @name    绑定推送ID【极光】
     * @desc    门店APP-绑定客户的registrationid
     * @method  POST
     * @param registrationid string 设备号ID req
     * @author JOHN.W
     * @version [1.0]
     * @return  json
        {
        "code": "000000",
        "msg": "保存设备号成功",
        "info": ''
        }
     */
    public function actionSaveregid()
    {
        if (empty($this->user_id)) {
            return $this->response('para_miss', '用户id为空');
        }
        if (!isset($this->para['registrationid']) || empty($this->para['registrationid'])) {
            return $this->response('para_miss', '设备号为空');
        }
        //1 ios/2 android
        $source=($this->para['terminalType']=='android')?'2':($this->para['terminalType']=='ios'?'1':'');
        if (empty($source)) {
            return $this->response('para_miss', '来源为空');
        }
        $data=[
            'user_id'=>$this->user_id,
            'registration'=>$this->para['registrationid'],
            'type'=>'shop',
            'source'=>$source,
        ];

        $re= UserService::addUserJPush($data);
        if ($re) {
            return $this->response('deal_succ', '保存设备号成功');
        } else {
            return $this->response('server_err', '保存设备号失败');
        }
    }
    /**
     * [actionOrdertype 获取订单类型]
     * @apiDoc
     * @api     v1/common/ordertype
     * @group   common
     * @name    获取订单类型
     * @desc    获取订单类型公用接口
     * @method  POST
     * @author JOHN.W
     * @version [1.0]
     * @return  json
    {
        "code": "000000",
        "msg": "获取成功",
        "info": [
        {
            "id": 1,
            "name": "实时单"
        },
        {
            "id": 2,
            "name": "预约单"
        }
        ]
    }
     */
    public function actionOrdertype(){
        $ret = Helper::getOrderType(1);
        return $this->response('deal_succ','获取成功' ,$ret);
    }

    /**
     * [actionGetcarmodel 获取车型列表]
     * @apiDoc
     * @api     v1/common/getcarmodel
     * @group   common
     * @name    获取车型配置
     * @desc    获取车型动态配置
     * @method  POST
     * @author JOHN.W
     * @version [1.0]
     * @return  json
        {
        "code": "000000",
        "msg": "获取成功",
        "total": 1,
        "info": [
        {
            "id": "1",
            "car_model": "轿车"
        }
        ]
        }
     */
    public function actionGetcarmodel(){
        $SysCarmodelSet = new SysCarmodelSetModel();
        $param = [
            'cols'=>['id','car_model'],
            'status'=>'allow'
        ];
        $res =  $SysCarmodelSet->getWidgetRows($param);
        $res = !empty($res)?$res:[];
        return $this->response('deal_succ', '获取成功',$res);
    }
    /**
     * [actionGetpro 获取业务/项目/产品]
     * @apiDoc
     * @api     v1/common/getpro
     * @group   common
     * @name    获取业务/项目下拉
     * @desc    获取业务/项目下拉
     * @method  POST
     * @param parent_id int 父ID noreq
     * @author JOHN.W
     * @version [1.0]
     * @return  json
        {
        "code": "000000",
        "msg": "获取成功",
        "total": 1,
        "info": [
        {
            "id": "1",
            "name": "美容",
            "parent_id": "0"
        }
        ]
        }
     */
    public function actionGetpro(){
        $SysProductSet = new SysProductSetModel();
        $param = [
            'cols'=>['id','name','parent_id'],
            'parent_id'=>isset($this->para['parent_id'])?$this->para['parent_id']:0,
            'status'=>'allow'
        ];
        $res =  $SysProductSet->getWidgetRows($param);
        $res = !empty($res)?$res:[];
        return $this->response('deal_succ', '获取成功',$res);
    }
    /**
     * [actionGetprolist 获取产品列表]
     * @apiDoc
     * @api     v1/common/getprolist
     * @group   common
     * @name    获取产品列表下拉
     * @desc    选择产品的时候获取下拉
     * @method  POST
     * @param  pro_id int string 项目ID req
     * @param  carmodel_id int string 车型ID noreq
     * @param  order_type int string 订单类型【1,实时单2,预约单】 noreq
     * @author JOHN.W
     * @version [1.0]
     * @return  json
        {
        "code": "000000",
        "msg": "获取成功",
        "info": [
        {
            "id": "1",
            "name": "美容-保养",
            "attr_id": "1",
            "price": "50.00"
        }
        ]
        }
     */
    public function actionGetprolist(){
        if (empty($this->user_id)) {
            return $this->response('para_miss_user', '未能识别用户标志');
        }
        if (empty($this->para['pro_id']) || !is_numeric($this->para['pro_id'])) {
            return $this->response('para_miss', '请选择项目ID');
        }
        $pro_id = $this->para['pro_id'];
        $user_id = UserService::getShopUserId($this->user_id);
        if(empty($user_id)){
            return $this->response('para_miss', '账号异常#no_role');
        }
        //获取该门店省市区
        $area = Helper::getAreaByUid($user_id);
        $SysBasePriceSet = new SysBasePriceSetModel();
        $where = [
            'cols'=>['id','name','attr_id','price'],
            'pro_id'=>$pro_id,
            'is_del'=>0
        ];
        if(isset($this->para['carmodel_id']) && !empty($this->para['carmodel_id'])){
            $where['carmodel_id'] = $this->para['carmodel_id'];
        }
        if(isset($this->para['order_type']) && !empty($this->para['order_type'])){
            $where['like'] = ['order_type'=>$this->para['order_type']];
        }
        $where_c = $where ;
        $where_a = $where ;
        if(!empty($area['city_id'])){
           $where_c['city_id']  = $area['city_id'];
           $rows_city = $SysBasePriceSet->getWidgetRows($where_c);
        }
        $rows_city = isset($rows_city)?$rows_city:[];
        if(!empty($area['area_id'])){
           $where_a['area_id']  = $area['area_id'];
           $rows_area = $SysBasePriceSet->getWidgetRows($where_a);
        }
        $rt_list = isset($rows_area) && !empty($rows_area)?$rows_area:$rows_city;
        if(!empty($rt_list)){
            foreach ($rt_list as &$value) {
                $value['attr_id']=$value['attr_id']==1?'不包料':'包料';
            }    
        }
        return $this->response('deal_succ', '获取成功',$rt_list);
    }

    /**
     * [actionUploadimg 上传图片]
     * @apiDoc
     * @api     v1/common/uploadimg
     * @group   common
     * @name    上传图片【公用】
     * @desc    公用上传图片接口
     * @method  POST
     * @param   upload_file png 图片路径 req
     * @author JOHN.W
     * @version [1.0]
     * @return  json
        {
        "code": "000000",
        "msg": "上传成功",
        "info": "4"
        }
     */
    public function actionUploadimg(){
        $Upload = new UploadService();
        if(!isset($this->para['modelname'])) $this->para['modelname'] = 'shop';
        if(!isset($this->para['filename'])) $this->para['filename'] = 'upload_file';
        $res  = $Upload->sendUpimg($this->para);
        if(isset($res['code']) && $res['code']=='000000'){
            return $this->response('deal_succ',"上传成功",$res['info']);
        }else{
            return $this->response('deal_false',"上传失败", $res['msg']);
        }
    }

    /**
     * [actionGetcmtlist 获取评论配置-未完]
     * @apiDoc
     * @api     v1/common/getcmtlist
     * @group   common
     * @name    获取评论配置
     * @desc    显示评论配置
     * @method  POST
     * @author JOHN.W
     * @version [1.0]
     * @return  json
     */
    public function actionGetcmtlist(){
        
    }
     /* [actionFeedback 提交投诉或意见]
     * @apiDoc
     * @api     v1/common/feedback
     * @group   common
     * @name    提交投诉或意见
     * @desc    个人设置-提交投诉或意见
     * @method  POST
     * @param  content string 内容 req
     * @author JOHN.W
     * @version [1.0]
     * @return  json
        {
        "code": "000000",
        "msg": "提交成功",
        "info": ""
        }
     */
    public function actionFeedback(){
        if (empty($this->user_id)) {
            return $this->response('para_miss_user', '未能识别用户标志');
        }
        if (empty($this->para['content'])) {
            return $this->response('para_miss', '意见不能为空');
        }
        $param = [
            'content'=>$this->para['content'],
            'user_id'=>$this->user_id,
            'created'=>time(),
        ];
        $res = UserService::addComplaint($param);

        return $this->response('deal_succ',"提交成功");
    }
    /**
     * [actionGetinvite 获取集团账号邀请码]
     * @apiDoc
     * @api     v1/common/getinvite
     * @group   common
     * @name    获取集团账号邀请码
     * @desc    门店APP-集团账号首页-邀请码
     * @method  POST
     * @author JOHN.W
     * @version [1.0]
     * @return  json
        {
        "code": "000000",
        "msg": "获取成功",
        "info": "CGKW7Y"
        }
     */
    public function actionGetinvite(){
        if (empty($this->user_id)) {
            return $this->response('para_miss_user', '未能识别用户标志');
        }
        //判断门店是否为集团账号
        $res = UserService::getShopAccountInfo($this->user_id);
        if(empty($res) || $res['shop_type']!=1){
            return $this->response('para_miss', '账号类型不正确不能获取');
        }
        $redis = Yii::$app->redis;
        $key = 'shop-invite:'.$this->user_id;
        if($redis->exists($key)){
            return $this->response('deal_succ',"获取成功",$redis->get($key));
        }
        $val = Helper::random_string('alnumb',6);
        $key_iv = 'invite-list:'.$val;

        Yii::$app->redis->set($key, $val, "EX", 3600 * 12);

        Yii::$app->redis->set($key_iv,$this->user_id, "EX",3600 * 12);

        return $this->response('deal_succ',"获取成功",$val);
    }
    /**
     * [actionInvitetouid 邀请码转换user_id]
     * @apiDoc
     * @api     v1/common/invitetouid
     * @group   common
     * @name    邀请码转换user_id
     * @desc    门店APP-连锁认证时输入邀请码转换集团ID
     * @method  POST
     * @author JOHN.W
     * @param code string 邀请码 req
     * @version [1.0]
     * @return  json
        {
        "code": "000000",
        "msg": "获取成功",
        "info": "2"
        }
     */
    public function actionInvitetouid(){
        if (empty($this->user_id)) {
            return $this->response('para_miss_user', '未能识别用户标志');
        }
        if(empty($this->para['code'])){
            return $this->response('para_miss', '请输入邀请码');
        }
        $redis = Yii::$app->redis;
        $key = 'invite-list:'.$this->para['code'];
        if($redis->exists($key)){
            return $this->response('deal_succ',"获取成功",$redis->get($key));
        }else{
            return $this->response('deal_false',"邀请码错误");
        }
    }
    /**
     * [actionGetroleopt 角色选择]
     * @apiDoc
     * @api     v1/common/getroleopt
     * @group   common
     * @name    角色选择下拉
     * @desc    门店APP-公用-角色下拉
     * @method  POST
     * @author JOHN.W
     * @version [1.0]
     * @return  json
        {
            "code": "000000",
            "msg": "获取成功",
            "info": [
        {
            "id": "1",
            "role_name": "管理员"
        },
        {
            "id": "2",
            "role_name": "高级管理1"
        }
        ]
        }
     */
    public function actionGetroleopt(){
        if (empty($this->user_id)) {
            return $this->response('para_miss_user', '未能识别用户标志');
        }
        $ShopRole = new ShopRoleModel();
        $rows = $ShopRole->getWidgetRows(['cols'=>['id','role_name'],'user_id'=>$this->user_id]);
        return $this->response('deal_succ', '获取成功',$rows);
    }
    /**
     * [actionGetpaytype 获取支付方式类型]
     * @apiDoc
     * @api     v1/common/getpaytype
     * @group   common
     * @name    获取支付方式下拉
     * @desc    门店APP-公用-获取支付方式下拉
     * @method  POST
     * @author JOHN.W
     * @version [1.0]
     * @return  json
        {
        "code": "000000",
        "msg": "获取成功",
        "info": {
        "1": "单店支付",
        "2": "公司支付",
        "3": "共享支付"
        }
        }
     */
    public function actionGetpaytype(){
        if (empty($this->user_id)) {
            return $this->response('para_miss_user', '未能识别用户标志');
        }
        $list = Helper::getPayType(0,true);
        return $this->response('deal_succ', '获取成功',$list);
    }
    /**
     * [actionGetmerch description]
     * @apiDoc
     * @api     v1/common/getmerch
     * @group   common
     * @name    获取商户性质
     * @desc    获取所有有效商户性质
     * @method  POST
     * @author JOHN.W
     * @version [1.0]
     * @return  json
        {
        "code": "000000",
        "msg": "获取成功",
        "info": [
        {
            "id": "1",
            "name": "二手车整备"
        },
        {
            "id": "2",
            "name": "综合社区店"
        },
        {
            "id": "3",
            "name": "快修店"
        },
        {
            "id": "4",
            "name": "美容店"
        }
        ]
        }
     */
    public function actionGetmerch(){
        $MerchType = new MerchTypeModel();
        $param = [
            'cols'=>['id','name'],
            'status'=>'allow'
        ];
        $res =  $MerchType->getWidgetRows($param);
        $res = !empty($res)?$res:[];
        return $this->response('deal_succ', '获取成功',$res);
    }
    /**
     * @apiDoc
     * @api v1/common/accesstoken
     * @name 微信获取accesstoken
     * @desc 微信获取accesstoken
     * @group common
     * @method POST
     * @param authorization_code string 授权码 req
     * @param state string 验证码 req
     * @return json
     * {
     * "code": "000000",
     * "msg": "绑定成功",
     * "info": ""
     * }
     */
    public function actionAccesstoken()
    {
        if (empty($this->user_id)) {
            return $this->response('para_miss_user', '未能识别用户标识');
        }
        if (empty($this->para['authorization_code'])) {
            return $this->response('para_miss', '授权码');
        }
        if (empty($this->para['state'])) {
            return $this->response('para_miss', '验证码不能为空');
        }
        $bind_service = new WxBindService($this->user_id);
        if ($bind_service->user_bind) {
            return $this->response('para_miss', '用户已经绑定');
        }
        $bind_result = $bind_service->bindUser($this->user_id, $this->para['authorization_code'], $this->para['state']);
        if (is_bool($bind_result) and $bind_result) {
            return $this->response('deal_succ', '绑定成功');
        } else {
            return $this->response('deal_false', $bind_result);
        }
    }
    /**
     * [actionSendsms description]
     * @apiDoc
     * @api    v1/common/sendsms
     * @group  common
     * @name   发送短信验证码
     * @desc   技师APP-公用发送短信
     * @method POST
     * @param mobile string 手机号 req
     * @param type string 类型【reg:注册 login:登录 modmobile:修改手机号 resetpwd:重置密码】 req
     * @return json
        {
        "code": "000000",
        "msg": "发送成功",
        "info": ''
        }
     */
    public function actionSendsms(){
        if(empty($this->para['mobile']) || !Verify::phoneFormat($this->para['mobile'])){
            return $this->response('para_miss', '手机号格式错误');
        }
        if(empty($this->para['type']) || !in_array($this->para['type'], ['reg','modmobile','login','resetpwd'])){
            return $this->response('para_miss', '发送验证类型不正确');
        }
        //校验手机号是否存在
        if($this->para['type']=='modmobile'){
           $flag_mobile =  UserService::userPhoneExists($this->para['mobile']);
           if($flag_mobile){
               return $this->response('para_miss', '修改手机号码占用');
           }
        }

        $sms = new Sms();
        $param = [
            'mobile'=>$this->para['mobile'],
            'tp_code'=>$this->para['type'],
        ];
        $res = $sms->send($param);
        if ($res) {
            return $this->response('deal_succ', '发送成功');
        } else {
            return $this->response('deal_false', '发送失败');
        }
    }
}