<?php
/**
 * 系统基础维护接口API
 */
namespace app\modules\manage\v1\controllers;

use app\modules\common\Helper;
use app\modules\logic\model\SysAreaSetModel;
use app\modules\logic\model\SysCarmodelSetModel;
use app\modules\logic\model\SysProductSetModel;
use app\modules\logic\model\SysBasePriceSetModel;
use app\modules\logic\model\SysCarmodelPriceSetModel;
use app\modules\logic\model\SysTechLevelSetModel;
use app\modules\logic\model\MerchTypeModel;
use app\modules\logic\model\SysMerchProductSetModel;
use app\modules\logic\model\SysTechHireSetModel;
use app\modules\logic\model\SysOpenHoursSetModel;
use Yii;
use yii\web\Controller;

class SystemController 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);
	}
	/**
	 * [actionAddarea 添加/修改地区]
	 * @apiDoc
	 * @api     v1/system/addarea
	 * @group   system
	 * @name    添加/修改地区
	 * @desc    城市地区维护添加/修改地区
	 * @method  POST
	 * @param id int ID【修改必填】 req
	 * @param prov_id int 省ID req
	 * @param city_id int 市ID req
	 * @param area_id int 区ID noreq
	 * @param order_type string 订单类型[1or1,2] req
	 * @author JOHN.W
	 * @version [1.0]
	 * @return  json
		{
		"code": "000000",
		"msg": "操作成功",
		"info": "4"
		}
	 */
	public function actionAddarea(){
		if (empty($this->para['prov_id']) || !is_numeric($this->para['prov_id'])) {
            return $this->response('para_miss', '请输入省ID');
        }
        if (empty($this->para['city_id']) || !is_numeric($this->para['city_id'])) {
            return $this->response('para_miss', '请输入市ID');
        }
        /*if (!isset($this->para['order_type']) || empty($this->para['order_type'])) {
            return $this->response('para_miss', '请选择订单类型');
        }*/
        $id = isset($this->para['id'])?(int)$this->para['id']:0;
        /*判断改地区是否存在*/
        $SysAreaSet = new SysAreaSetModel();
        $data  = [
        	'prov_id'=>$this->para['prov_id'],
        	'city_id'=>$this->para['city_id'],
        	'area_id'=>isset($this->para['area_id'])?(int)$this->para['area_id']:0,
        ];
        if(empty($id)){
			$row = $SysAreaSet->getWidgetRow($data);
			if(!empty($row)){
				return $this->response('deal_false', '该地区已添加，请做修改操作');
			}
        }
        $data['order_type']  = '1,2';
        $data['operator']  = $this->rec_role['operator_name'];
        $data['created']  = time();
        $res = $SysAreaSet->saveUs($data,$id);
		if($res){
			return $this->response('deal_succ', $res);
		}else{
			return $this->response('deal_false', $res);
		}		        
	}
	/**
	 * [actionListarea 地区列表]
	 * @apiDoc
	 * @api     v1/system/listarea
	 * @group   system
	 * @name    地区维护列表
	 * @desc    基础数据维护-城市地区维护列表
	 * @method  POST
	 * @param prov_id int 省ID req
	 * @param city_id int 市ID req
	 * @param area_id int 区ID req
	 * @param currentPage string 当前页 noreq 1
	 * @param pageSize string 每页条数 noreq 15
	 * @author JOHN.W
	 * @version [1.0]
	 * @return  json
		{
		"code": "000000",
		"msg": "操作成功",
		"total": "2",
		"info": [
		    {
		        "id": "3",
		        "order_type": "实时订单 预约订单",
		        "prov_id": "北京市",
		        "city_id": "河北省",
		        "area_id": "--",
		        "status": "allow",
		        "created": "2019-08-29 19:32:50",
		        "status_name": "启用"
		    },
		    {
		        "id": "2",
		        "order_type": "实时订单",
		        "prov_id": "北京市",
		        "city_id": "天津市",
		        "area_id": "--",
		        "status": "allow",
		        "created": "2019-08-29 19:29:40",
		        "status_name": "启用"
		    }
		]
		}
	 */
	public function actionListarea(){
		$_where = [];
		//$_where['cols'] = ['id','nid', 'user_id', 'borrower_name', 'borrower_id', 'borrower_tel', 'order_price', 'status', 'is_del', 'addtime'];
		$_where['order'] = ['id' => 'desc'];
		/*省搜索*/
		if (!empty($this->para['prov_id'])) {
			$_where['prov_id'] = $this->para['prov_id'];
		}
		/*市搜索*/
		if (!empty($this->para['city_id'])) {
			$_where['city_id'] = $this->para['city_id'];
		}
		/*区搜索*/
		if (!empty($this->para['area_id'])) {
			$_where['area_id'] = $this->para['area_id'];
		}
		/*分页处理*/
		$currentPage = 1;
		$pageSize = 15;
		if (isset($this->para['currentPage']) && !empty($this->para['currentPage']) && is_numeric($this->para['currentPage'])) {
			$currentPage = $this->para['currentPage'];
		}
		if (isset($this->para['pageSize']) && !empty($this->para['pageSize']) && is_numeric($this->para['pageSize'])) {
			$pageSize = $this->para['pageSize'];
		}
		$SysAreaSet = new SysAreaSetModel();
		$total = $SysAreaSet->getWidgetTotal($_where);
		$list = $SysAreaSet->getWidgetPages($_where, $pageSize, $pageSize * ($currentPage - 1));
		if (!empty($list)) {
			foreach ($list as &$value) {
				$value['order_type'] = Helper::getOrderTypeName($value['order_type']);
				$value['prov_id'] = Helper::getRegion($value['prov_id']);
				$value['city_id'] = Helper::getRegion($value['city_id']);
				$value['area_id'] = Helper::getRegion($value['area_id']);
				$value['status_name'] = Helper::getStatusByKey($value['status']);
				$value['created'] = date("Y-m-d H:i:s", $value['created']);
			}
		}
		return $this->response('search_succ', $list, $total);
	}
	/**
	 * [actionUparea 地区维护状态修改]
	 * @apiDoc
	 * @api     v1/system/uparea
	 * @group   system
	 * @name    启用/禁用地区
	 * @desc    基础数据维护-城市地区维护列表-启用/禁用操作
	 * @method  POST
	 * @param id int ID req
	 * @param status string 操作类型【allow:启用;deny:禁用 】 req
	 * @author JOHN.W
	 * @version [1.0]
	 * @return  json
		{
		"code": "000000",
		"msg": "操作成功",
		"info": true
		}
	 */
	public function actionUparea(){
		if (empty($this->para['status']) || !in_array($this->para['status'], ['allow','deny'])) {
            return $this->response('para_miss', '请选择正确的更新类型');
        }
        if (empty($this->para['id']) || !is_numeric($this->para['id'])) {
            return $this->response('para_miss', '操作ID不能为空');
        }
        $SysAreaSet = new SysAreaSetModel();
        $res = $SysAreaSet->saveUs(['status'=>$this->para['status'],'operator'=>$this->rec_role['operator_name'],'created'=>time()],(int)$this->para['id']);
        if($res){
			return $this->response('deal_succ', $res);
		}else{
			return $this->response('deal_false', $res);
		}
	}
	/**
	 * [actionAddcarmodel 添加/修改车型]
	 * @apiDoc
	 * @api     v1/system/addcarmodel
	 * @group   system
	 * @name    添加/修改车型
	 * @desc    基础数据维护-车型维护-添加/修改
	 * @method  POST
	 * @param car_model string 车辆型号 req 
	 * @param status string 是否禁用【allow:否，deny:是】 req 
	 * @param id int ID【修改必填】 noreq 
	 * @author JOHN.W
	 * @version [1.0]
	 * @return  josn
	 {
		"code": "000000",
		"msg": "操作成功",
		"info": true
		}
	 */
	public function actionAddcarmodel(){
		if (!isset($this->para['car_model']) || empty($this->para['car_model'])) {
            return $this->response('para_miss', '请选择车辆型号');
        }	
        if (empty($this->para['status']) || !in_array($this->para['status'], ['allow','deny'])) {
            return $this->response('para_miss', '请选择正确的状态类型');
        }
        $id = isset($this->para['id'])?(int)$this->para['id']:0;
        $SysCarmodelSet = new SysCarmodelSetModel();
        $data = [
        	'car_model'=>$this->para['car_model'],
        	'status'=>$this->para['status'],
        	'operator'=>$this->rec_role['operator_name'],
        	'created'=>time(),
        ];
        $res = $SysCarmodelSet->saveUs($data,$id);
        if($res){
			return $this->response('deal_succ', $res);
		}else{
			return $this->response('deal_false', $res);
		}
	}
	/**
	 * [actionListarea 地区列表]
	 * @apiDoc
	 * @api     v1/system/listcarmodel
	 * @group   system
	 * @name    车型维护列表
	 * @desc    基础数据维护-车型维护列表
	 * @method  POST
	 * @param currentPage string 当前页 noreq 1
	 * @param pageSize string 每页条数 noreq 15
	 * @author JOHN.W
	 * @version [1.0]
	 * @return  json
	 {
	    "code": "000000",
	    "msg": "操作成功",
	    "total": "2",
	    "info": [
	        {
	            "id": "2",
	            "car_model": "SUV",
	            "status": "deny",
	            "created": "2019-08-30 20:35:20",
	            "status_name": "禁用"
	        },
	        {
	            "id": "1",
	            "car_model": "轿车",
	            "status": "allow",
	            "created": "2019-08-30 20:34:42",
	            "status_name": "启用"
	        }
	    ]
	}
	 */
	public function actionListcarmodel(){
		$_where = [];
		$_where['order'] = ['id' => 'desc'];
		/*分页处理*/
		$currentPage = 1;
		$pageSize = 15;
		if (isset($this->para['currentPage']) && !empty($this->para['currentPage']) && is_numeric($this->para['currentPage'])) {
			$currentPage = $this->para['currentPage'];
		}
		if (isset($this->para['pageSize']) && !empty($this->para['pageSize']) && is_numeric($this->para['pageSize'])) {
			$pageSize = $this->para['pageSize'];
		}
		$SysCarmodelSet = new SysCarmodelSetModel();
		$total = $SysCarmodelSet->getWidgetTotal($_where);
		$list = $SysCarmodelSet->getWidgetPages($_where, $pageSize, $pageSize * ($currentPage - 1));
		if (!empty($list)) {
			foreach ($list as &$value) {
				$value['status_name'] = Helper::getStatusByKey($value['status']);
				$value['created'] = date("Y-m-d H:i:s", $value['created']);
			}
		}
		return $this->response('search_succ', $list, $total);
	}
	/**
	 * [actionUparea 车型维护状态修改]
	 * @apiDoc
	 * @api     v1/system/upcarmodel
	 * @group   system
	 * @name    启用/禁用车型
	 * @desc    基础数据维护-城市地区维护列表-启用/禁用操作
	 * @method  POST
	 * @param id int ID req
	 * @param status string 操作类型【allow:启用;deny:禁用 】 req
	 * @author JOHN.W
	 * @version [1.0]
	 * @return  json
		{
		"code": "000000",
		"msg": "操作成功",
		"info": true
		}
	 */
	public function actionUpcarmodel(){
		if (empty($this->para['status']) || !in_array($this->para['status'], ['allow','deny'])) {
            return $this->response('para_miss', '请选择正确的更新类型');
        }
        if (empty($this->para['id']) || !is_numeric($this->para['id'])) {
            return $this->response('para_miss', '操作ID不能为空');
        }
        $SysCarmodelSet = new SysCarmodelSetModel();
        $res = $SysCarmodelSet->saveUs(['status'=>$this->para['status'],'operator'=>$this->rec_role['operator_name'],'created'=>time()],(int)$this->para['id']);
        if($res){
			return $this->response('deal_succ', $res);
		}else{
			return $this->response('deal_false', $res);
		}
	}
	/**
	 * [actionAddproduct 产品项目维护]
	 * @apiDoc
	 * @api     v1/system/addproduct
	 * @group   system
	 * @name    添加/修改项目
	 * @desc    基础维护-业务维护
	 * @method  POST
	 * @param name string 名称【业务/项目】 req
	 * @param is_mult int 是否多选【1，是；0，否】 req
	 * @param parent_id int 父类ID【项目必填】 noreq
	 * @param id int ID【修改必填】 noreq
	 * @param status string 操作类型【allow:启用;deny:禁用 】 req
	 * @author JOHN.W
	 * @version [1.0]
	 * @return  json
	 {
    "code": "000000",
    "msg": "操作成功",
    "info": "1"
	}
	 */
	public function actionAddproduct(){
		if (!isset($this->para['name']) || empty($this->para['name'])) {
            return $this->response('para_miss', '请选择业务/项目名称');
        }
        if (!isset($this->para['is_mult'])) {
            return $this->response('para_miss', '请选择是否多选');
        }
		if (empty($this->para['status']) || !in_array($this->para['status'], ['allow','deny'])) {
            return $this->response('para_miss', '请选择是否禁用');
        }
        //parent_id不为空表示为项目
        $parent_id = isset($this->para['parent_id'])?(int)$this->para['parent_id']:0;
        $id = isset($this->para['id'])?(int)$this->para['id']:0;
        $SysProduct = new SysProductSetModel();
        $data = [
        	'name'=>$this->para['name'],
        	'is_mult'=>$this->para['is_mult'],
        	'status'=>$this->para['status'],
        	'parent_id'=>$parent_id,
        	'created'=>time()
        ];
        $res = $SysProduct->saveUs($data,$id);
        if($res){
			return $this->response('deal_succ', $res);
		}else{
			return $this->response('deal_false', $res);
		}
	}
	/**
	 * [actionDetailproduct 产品项目详情]
	 * @apiDoc
	 * @api    v1/system/detailproduct
	 * @group  system
	 * @name   业务名称维护详情
	 * @desc   接口描述
	 * @method POST
	 * @param id int ID req
	 * @return json
		{
		"code": "000000",
		"msg": "操作成功",
		"info": {
		    "id": "10",
		    "parent_id": "9",
		    "name": "漆面",
		    "is_mult": "0",
		    "status": "allow",
		    "created": "1579076447",
		    "parent_name": "美容业务"
		}
		}
	 */
	public function actionDetailproduct(){
		if (empty($this->para['id']) || !is_numeric($this->para['id'])) {
            return $this->response('para_miss', '操作ID不能为空');
        }
        $SysProductSet = new SysProductSetModel();
        $id = (int) $this->para['id'];
        $row = $SysProductSet->getWidgetRow(['id'=>$id]);
        if(!empty($row) && !empty($row['parent_id'])){
        	$row_p = $SysProductSet->getWidgetRow(['cols'=>['name'],'id'=>$row['parent_id']]);
        	$row['parent_name'] = $row_p['name'];
        }else{
        	$row['parent_name'] = '';
        }
        return $this->response('deal_succ', $row);
	}
	/**
	 * [actionListproduct 业务维护列表]
	 * @apiDoc
	 * @api     v1/system/listproduct
	 * @group   system
	 * @name    业务维护列表
	 * @desc    基础维护-业务维护列表
	 * @method  POST
	 * @param currentPage string 当前页 noreq 1
	 * @param pageSize string 每页条数 noreq 15
	 * @param parent_id ini 父类ID【获取下级列表必填列表中的`id`】 noreq
	 * @author JOHN.W
	 * @version [1.0]
	 * @return  json
	{
	"code": "000000",
	"msg": "操作成功",
	"total": "1",
	"info": [
	{
	    "id": "1",
	    "parent_id": "0",
	    "name": "美容",
	    "is_mult": "否",
	    "status": "allow",
	    "created": "2019-08-30 21:07:09",
	    "status_name": "启用"
	}
	]
	}
	 */
	public function actionListproduct(){
		$_where = [];
		$_where['order'] = ['id' => 'desc'];
		/*分类搜索*/
		if (isset($this->para['parent_id'])) {
			$_where['parent_id'] = $this->para['parent_id'];
		}else{
			$_where['parent_id'] = 0;
		}
		/*分页处理*/
		$currentPage = 1;
		$pageSize = 15;
		if (isset($this->para['currentPage']) && !empty($this->para['currentPage']) && is_numeric($this->para['currentPage'])) {
			$currentPage = $this->para['currentPage'];
		}
		if (isset($this->para['pageSize']) && !empty($this->para['pageSize']) && is_numeric($this->para['pageSize'])) {
			$pageSize = $this->para['pageSize'];
		}
		$SysProductSet = new SysProductSetModel();
		$total = $SysProductSet->getWidgetTotal($_where);
		$list = $SysProductSet->getWidgetPages($_where, $pageSize, $pageSize * ($currentPage - 1));
		if (!empty($list)) {
			foreach ($list as &$value) {
				$value['status_name'] = Helper::getStatusByKey($value['status']);
				$value['is_mult'] = ($value['is_mult']==0)?'否':'是';
				$value['created'] = date("Y-m-d H:i:s", $value['created']);
			}
		}
		return $this->response('search_succ', $list, $total);
	}
	/**
	 * [actionUparea 业务维护状态修改]
	 * @apiDoc
	 * @api     v1/system/upproduct
	 * @group   system
	 * @name    启用/禁用业务
	 * @desc    基础数据维护-业务维护列表-启用/禁用操作
	 * @method  POST
	 * @param id int ID req
	 * @param status string 操作类型【allow:启用;deny:禁用 】 req
	 * @author JOHN.W
	 * @version [1.0]
	 * @return  json
		{
		"code": "000000",
		"msg": "操作成功",
		"info": true
		}
	 */
	public function actionUpproduct(){
		if (empty($this->para['status']) || !in_array($this->para['status'], ['allow','deny'])) {
            return $this->response('para_miss', '请选择正确的更新类型');
        }
        if (empty($this->para['id']) || !is_numeric($this->para['id'])) {
            return $this->response('para_miss', '操作ID不能为空');
        }
        $SysProductSet = new SysProductSetModel();
        $res = $SysProductSet->saveUs(['status'=>$this->para['status'],'created'=>time()],(int)$this->para['id']);
        if($res){
			return $this->response('deal_succ', $res);
		}else{
			return $this->response('deal_false', $res);
		}
	}
	/**
	 * [actionAddprice 添加/修改价格]
	 * @apiDoc
	 * @api     v1/system/addprice
	 * @group   system
	 * @name    添加/修改价格
	 * @desc    基础维护-产品单价设置-新增/修改单价
	 * @method  POST
	 * @param id int ID【修改必填】 req
	 * @param  prov_id int 省ID req
	 * @param  city_id int 市ID req
	 * @param  area_id int 区ID noreq
	 * @param  name string 产品名称 req
	 * @param  yw_id int 业务ID req
	 * @param  pro_id int 项目ID req
	 * @param  attr_id int 熟悉ID【1:包工不包料，2:包工包料】 req
	 * @param  order_type string 订单类型【1,2】 req
	 * @param  price number 价格（元） req
	 * @param  cons_time number 施工时间（分） req
	 * @param  carmodel_id int 车型ID req
	 * @param  tech_price number 技师工时费（元） req
	 * @param  safe_fee number 保险费 req
	 * @param  pun_reach_award number 按时到达奖励 req
	 * @param  pun_work_award number 按时完工奖励 req
	 * @param  praise_award number 好评奖励 req
	 * @author JOHN.W
	 * @version [1.0]
	 * @return json 
		{
		"code": "000000",
		"msg": "操作成功",
		"info": "1"
		} 
	 */
	public function actionAddprice(){
		if (empty($this->para['prov_id']) || !is_numeric($this->para['prov_id'])) {
            return $this->response('para_miss', '省ID不能为空');
        }
        if (empty($this->para['city_id']) || !is_numeric($this->para['city_id'])) {
            return $this->response('para_miss', '市ID不能为空');
        }
        if (!isset($this->para['name']) || empty($this->para['name'])) {
            return $this->response('para_miss', '产品名称不能为空');
        }
        if (!isset($this->para['order_type']) || empty($this->para['order_type'])) {
            return $this->response('para_miss', '适用订单类型不能为空');
        }
        if (empty($this->para['yw_id']) || !is_numeric($this->para['yw_id'])) {
            return $this->response('para_miss', '业务ID不能为空');
        }
        if (empty($this->para['pro_id']) || !is_numeric($this->para['pro_id'])) {
            return $this->response('para_miss', '项目ID不能为空');
        }
        if (empty($this->para['carmodel_id']) || !is_numeric($this->para['carmodel_id'])) {
            return $this->response('para_miss', '车型ID不能为空');
        }
        if (empty($this->para['attr_id']) || !in_array($this->para['attr_id'],['1','2'])) {
            return $this->response('para_miss', '产品属性错误');
        }
        if (!isset($this->para['price']) || !is_numeric($this->para['price']) || $this->para['price']<=0) {
            return $this->response('para_miss', '价格错误');
        }
        if (empty($this->para['cons_time']) || !is_numeric($this->para['cons_time']) || $this->para['cons_time']<=0) {
            return $this->response('para_miss', '施工时间错误');
        }
        $id = isset($this->para['id'])?(int)$this->para['id']:0;
        $SysBasePriceSet = new SysBasePriceSetModel();
        //校验该省市区是否已添加过该类型产品
        $ver_param = [
        	'scope'=>['neq'=>['id'=>$id]],
        	'prov_id'=>$this->para['prov_id'],
        	'city_id'=>$this->para['city_id'],
        	'yw_id'=>$this->para['yw_id'],
        	'pro_id'=>$this->para['pro_id'],
        	'attr_id'=>$this->para['attr_id'],
        	'carmodel_id'=>$this->para['carmodel_id'],
        	'order_type'=>$this->para['order_type'],
        	'price'=>$this->para['price'],
        	'name'=>$this->para['name'],
        	'area_id'=>isset($this->para['area_id'])?$this->para['area_id']:0,
        	'is_del'=>0
        	];
        $flag = $SysBasePriceSet->getWidgetRow($ver_param);
        if($flag){
			return $this->response('deal_false', '相同地区相同价格请勿重复添加');      	
        }
        $data = Helper::elements(['prov_id','city_id','name','yw_id','pro_id','area_id','attr_id','price','cons_time','carmodel_id','tech_price','safe_fee','pun_reach_award','pun_work_award','praise_award','order_type'], $this->para, '0');
        $data['created'] = time();
        $res = $SysBasePriceSet->saveUs($data,$id);
        if($res){
			return $this->response('deal_succ', $res);
		}else{
			return $this->response('deal_false', $res);
		}
	}

	/**
	 * [actionDelprice 删除产品价格]
	 * @apiDoc
	 * @api     v1/system/delprice
	 * @group   system
	 * @name    删除价格
	 * @desc    基础维护-产品单价设置-删除（逻辑删除）
	 * @method  POST
	 * @param id int ID req
	 * @author JOHN.W
	 * @version [1.0]
	 * @return  json
	 {
		"code": "000000",
		"msg": "操作成功",
		"info": true
		}
	 */
	public function actionDelprice(){
		if (empty($this->para['id']) || !is_numeric($this->para['id'])) {
            return $this->response('para_miss', '操作ID不能为空');
        }
        $SysBasePriceSet = new SysBasePriceSetModel();
        $res = $SysBasePriceSet->saveUs(['is_del'=>1,'created'=>time()],(int)$this->para['id']);
        if($res){
			return $this->response('deal_succ', $res);
		}else{
			return $this->response('deal_false', $res);
		}
	}
	/**
	 * [actionListprice description]
	 * @apiDoc
	 * @api     v1/system/listprice
	 * @group   system
	 * @name    产品价格配置列表
	 * @desc    基础维护-产品单价设置列表
	 * @method  POST
	 * @param prov_id int 省ID req
	 * @param city_id int 市ID req
	 * @param area_id int 区ID noreq
	 * @author JOHN.W
	 * @version [1.0]
	 * @return  json
		{
		"code": "000000",
		"msg": "操作成功",
		"total": 1,
		"info": [
		{
		    "id": "1",
		    "prov_id": "1",
		    "city_id": "2",
		    "area_id": "0",
		    "name": "美容-保养",
		    "yw_id": "1",
		    "pro_id": "2",
		    "attr_id": "1",
		    "price": "50.00",
		    "cons_time": "60",
		    "is_del": "0",
		    "created": null,
		    "attr_id_show": "包工不包料",
		    "cons_time_show": "60分"
		}
		]
		}
	 */
	public function actionListprice(){
		if (empty($this->para['prov_id']) || !is_numeric($this->para['prov_id'])) {
            return $this->response('search_succ', [], 0);
        }
        if (empty($this->para['city_id']) || !is_numeric($this->para['city_id'])) {
            return $this->response('search_succ', [], 0);
        }
		$_where = ['is_del'=>0];
		$_where['order'] = ['id' => 'desc'];
		/*省搜索*/
		if (!empty($this->para['prov_id'])) {
			$_where['prov_id'] = $this->para['prov_id'];
		}
		/*市搜索*/
		if (!empty($this->para['city_id'])) {
			$_where['city_id'] = $this->para['city_id'];
		}
		/*区搜索*/
		if (!empty($this->para['area_id'])) {
			$_where['area_id'] = $this->para['area_id'];
		}
		$SysBasePriceSet = new SysBasePriceSetModel();
		$list = $SysBasePriceSet->getWidgetRows($_where);
		if (!empty($list)) {
			foreach ($list as &$value) {
				$value['attr_id_show'] = Helper::getAttrByKey($value['attr_id']);
				$value['prov_id'] = Helper::getRegion($value['prov_id']);
				$value['city_id'] = Helper::getRegion($value['city_id']);
				$value['area_id'] = Helper::getRegion($value['area_id']);
				$value['order_type'] = Helper::getOrderTypeNameApp($value['order_type']);
				$value['cons_time_show'] = $value['cons_time'].'分';
			}
		}
		/*$SysCarmodelPriceSet = new SysCarmodelPriceSetModel();
		$list_car = $SysCarmodelPriceSet->getWidgetRows($_where);
		if (!empty($list_car)) {
			foreach ($list_car as &$value) {
				$value['carmodel_id_show'] = Helper::getCarModelName($value['carmodel_id']);
			}
		}*/
		return $this->response('search_succ', ['list'=>$list], 2);
	}
	/**
	 * [actionDetailprice 产品单价设置详情]
	 * @apiDoc
	 * @api     v1/system/detailprice
	 * @group   system
	 * @name   产品单价设置详情
	 * @desc   产品单价设置->详情/编辑调用
	 * @method POST
	 * @param id int ID req
	 * @return json
		{
		"code": "000000",
		"msg": "操作成功",
		"info": {
			"id": "1",
			"prov_id": "23",
			"city_id": "275",
			"area_id": "0",
			"name": "基础内饰",
			"yw_id": "1",
			"pro_id": "2",
			"attr_id": "1",
			"order_type": null,
			"price": "10.00",
			"tech_price": "0.00",
			"cons_time": "60",
			"carmodel_id": "0",
			"safe_fee": "0.00",
			"pun_reach_award": "0.00",
			"pun_work_award": null,
			"praise_award": "0.00",
			"is_del": "0",
			"created": null
		}
		}
	 */
	public function actionDetailprice(){
		if (empty($this->para['id']) || !is_numeric($this->para['id'])) {
            return $this->response('para_miss', '操作ID不能为空');
        }
        $SysBasePriceSet = new SysBasePriceSetModel();
        $row = $SysBasePriceSet->getWidgetRow(['id'=>$this->para['id']]);
        return $this->response('deal_succ', $row);
	}
	/**
	 * [actionAddcarmodelprice 车型影响价格因素]
	 * @apiDoc
	 * @api     v1/system/addcarmodelprice
	 * @group   system
	 * @name    添加/修改车型价
	 * @desc    接口描述
	 * @method  POST
	 * @param id int ID【修改必填】 req
	 * @param  prov_id int 省ID req
	 * @param  city_id int 市ID req
	 * @param  area_id int 区ID noreq
	 * @param  carmodel_id int 车型ID req
	 * @param  price_up int 单价上浮 req
	 * @param  cons_time_up int 施工时间上浮 req
	 * @author JOHN.W
	 * @version [1.0]
	 * @return  json
	{
	"code": "000000",
	"msg": "操作成功",
	"info": "1"
	}
	 */
	public function actionAddcarmodelprice(){
		if (empty($this->para['prov_id']) || !is_numeric($this->para['prov_id'])) {
            return $this->response('para_miss', '省ID不能为空');
        }
        if (empty($this->para['city_id']) || !is_numeric($this->para['city_id'])) {
            return $this->response('para_miss', '市ID不能为空');
        }
        if (empty($this->para['carmodel_id']) || !is_numeric($this->para['carmodel_id'])) {
            return $this->response('para_miss', '车型ID不能为空');
        }
        if (!isset($this->para['price_up']) || !is_numeric($this->para['price_up'])) {
            return $this->response('para_miss', '价格上浮错误');
        }
        if (!isset($this->para['cons_time_up']) || !is_numeric($this->para['cons_time_up'])) {
            return $this->response('para_miss', '施工时间上浮错误');
        }
        $id = isset($this->para['id'])?(int)$this->para['id']:0;
        $SysCarmodelPriceSet = new SysCarmodelPriceSetModel();
        //校验该省市区是否已添加过该设置
        $ver_param = [
        	'scope'=>['neq'=>['id'=>$id]],
        	'prov_id'=>$this->para['prov_id'],
        	'city_id'=>$this->para['city_id'],
        	'carmodel_id'=>$this->para['carmodel_id'],
        	'area_id'=>isset($this->para['area_id'])?$this->para['area_id']:0,
        	'is_del'=>0
        	];
        $flag = $SysCarmodelPriceSet->getWidgetRow($ver_param);
        if($flag){
			return $this->response('deal_false', '请勿重复添加');      	
        }
        $data = Helper::elements(['prov_id','city_id','area_id','carmodel_id','price_up','cons_time_up'], $this->para, '0');
        $data['created'] = time();
        $res = $SysCarmodelPriceSet->saveUs($data,$id);
        if($res){
			return $this->response('deal_succ', $res);
		}else{
			return $this->response('deal_false', $res);
		}
	}
	/**
	 * [actionDelprice 删除车型价格上下浮动]
	 * @apiDoc
	 * @api     v1/system/delcarmodelprice
	 * @group   system
	 * @name    删除车型价格
	 * @desc    基础维护-产品单价设置-删除车型价格浮动（逻辑删除）
	 * @method  POST
	 * @param id int ID req
	 * @author JOHN.W
	 * @version [1.0]
	 * @return  json
	 {
		"code": "000000",
		"msg": "操作成功",
		"info": true
		}
	 */
	public function actionDelcarmodelprice(){
		if (empty($this->para['id']) || !is_numeric($this->para['id'])) {
            return $this->response('para_miss', '操作ID不能为空');
        }
        $SysCarmodelPriceSet = new SysCarmodelPriceSetModel();
        $res = $SysCarmodelPriceSet->saveUs(['is_del'=>1,'created'=>time()],(int)$this->para['id']);
        if($res){
			return $this->response('deal_succ', $res);
		}else{
			return $this->response('deal_false', $res);
		}
	}
	/**
	 * [actionAddtechlevel 技师等级维护]
	 * @apiDoc
	 * @api     v1/system/addtechlevel
	 * @group   system
	 * @name    添加/修改技师等级
	 * @desc    基础维护-技师等级维护-添加/修改
	 * @method  POST
	 * @param id int ID【修改必填】 req
	 * @param  yw_id int 业务ID req
	 * @param  pro_extra string 项目【1,2,3】 req
	 * @param  tech_level string 技师等级 req
	 * @author JOHN.W
	 * @version [1.0]
	 * @return  json
		{
		"code": "000000",
		"msg": "操作成功",
		"info": "1"
		}
	 */
	public function actionAddtechlevel(){
		if (empty($this->para['yw_id']) || !is_numeric($this->para['yw_id'])) {
            return $this->response('para_miss', '业务ID不能为空');
        }
        if (!isset($this->para['tech_level']) || empty($this->para['tech_level'])) {
            return $this->response('para_miss', '技师等级不能为空');
        }
		if (empty($this->para['pro_extra'])) {
            return $this->response('para_miss', '项目不能为空');
        }
        $id = isset($this->para['id'])?(int)$this->para['id']:0;
        $SysTechLevelSet = new SysTechLevelSetModel();
        $data=[
        	'yw_id'=>$this->para['yw_id'],
        	'tech_level'=>$this->para['tech_level'],
        	'pro_extra'=>$this->para['pro_extra'],
        	'created'=>time()
        ];
        $res = $SysTechLevelSet->saveUs($data,$id);
        if($res){
			return $this->response('deal_succ', $res);
		}else{
			return $this->response('deal_false', $res);
		}
	}
	/**
	 * [actionListtechlevel 技师等级列表]
	 * @apiDoc
	 * @api     v1/system/listtechlevel
	 * @group   system
	 * @name    技师等级列表
	 * @desc    基础数据维护-技师等级维护-列表
	 * @method  POST
	 * @param currentPage string 当前页 noreq 1
	 * @param pageSize string 每页条数 noreq 15
	 * @author JOHN.W
	 * @version [1.0]
	 * @return  json
		{
		"code": "000000",
		"msg": "操作成功",
		"total": "1",
		"info": [
		{
		    "id": "1",
		    "yw_id": "1",
		    "pro_extra": "1,2,3,4",
		    "tech_level": "2",
		    "status": "allow",
		    "created": "2019-08-31 14:41:33",
		    "pro_extra_show": "美容 SUV",
		    "yw_id_show": "美容"
		}
		]
		}
	 */
	public function actionListtechlevel(){
		$_where = [];
		$_where['order'] = ['id' => 'desc'];
		/*分页处理*/
		$currentPage = 1;
		$pageSize = 15;
		if (isset($this->para['currentPage']) && !empty($this->para['currentPage']) && is_numeric($this->para['currentPage'])) {
			$currentPage = $this->para['currentPage'];
		}
		if (isset($this->para['pageSize']) && !empty($this->para['pageSize']) && is_numeric($this->para['pageSize'])) {
			$pageSize = $this->para['pageSize'];
		}
		$SysTechLevelSet = new SysTechLevelSetModel();
		$total = $SysTechLevelSet->getWidgetTotal($_where);
		$list = $SysTechLevelSet->getWidgetPages($_where, $pageSize, $pageSize * ($currentPage - 1));
		if (!empty($list)) {
			foreach ($list as &$value) {
				$value['pro_extra_show'] = Helper::getProNameById($value['pro_extra']);
				$value['yw_id_show'] = Helper::getProNameById($value['yw_id']);
				$value['status_name'] = Helper::getStatusByKey($value['status']);
				$value['created'] = date("Y-m-d H:i:s", $value['created']);
			}
		}
		return $this->response('search_succ', $list, $total);
	}
	/**
	 * [actionUptechlevel 技师等级维护状态修改]
	 * @apiDoc
	 * @api     v1/system/uptechlevel
	 * @group   system
	 * @name    启用/禁用技师等级
	 * @desc    基础数据维护-技师等级维护列表-启用/禁用操作
	 * @method  POST
	 * @param id int ID req
	 * @param status string 操作类型【allow:启用;deny:禁用 】 req
	 * @author JOHN.W
	 * @version [1.0]
	 * @return  json
		{
		"code": "000000",
		"msg": "操作成功",
		"info": true
		}
	 */
	public function actionUptechlevel(){
		if (empty($this->para['status']) || !in_array($this->para['status'], ['allow','deny'])) {
            return $this->response('para_miss', '请选择正确的更新类型');
        }
        if (empty($this->para['id']) || !is_numeric($this->para['id'])) {
            return $this->response('para_miss', '操作ID不能为空');
        }
        $SysTechLevelSet = new SysTechLevelSetModel();
        $res = $SysTechLevelSet->saveUs(['status'=>$this->para['status'],'created'=>time()],(int)$this->para['id']);
        if($res){
			return $this->response('deal_succ', $res);
		}else{
			return $this->response('deal_false', $res);
		}
	}
	/**
	 * [actionAddmerch 添加商户性质]
	 * @apiDoc
	 * @api     v1/system/addmerch
	 * @group   system
	 * @name    添加/修改/启用.禁用/商户性质
	 * @desc    基础维护-商户性质名称维护-添加/修改/启用.禁用接口
	 * @method  POST
	 * @param name string 商户性质名称【添加/修改必填】 noreq
	 * @param id int ID【修改-启用禁用必填】 noreq
	 * @param status string 操作类型/启用禁用【allow:启用;deny:禁用 】 noreq 
	 * @author JOHN.W
	 * @version [1.0]
	 * @return  json
		{
			"code": "000000",
			"msg": "操作成功",
			"info": "1"
		}
	 */
	public function actionAddmerch(){
		$data = ['created'=>time()];
		$MerchType = new MerchTypeModel();
        if(isset($this->para['status']) && isset($this->para['id'])){
        	if (!in_array($this->para['status'], ['allow','deny'])) {
            	return $this->response('para_miss', '请选择正确的更新类型');
        	}
        	$data['status']=$this->para['status'];
        }else{
        	if (!isset($this->para['name']) || empty($this->para['name'])) {
            	return $this->response('para_miss', '商户性质不能为空');
        	}
        	$data['name']=$this->para['name'];
        	//校验名字是否存在
        	$falg = $MerchType->getWidgetRow(['name'=>$data['name']]);
        	if($falg) return $this->response('para_miss', '商户性质名称已存在');
        }
        $data['operator'] = $this->rec_role['operator_name'];
        $id = isset($this->para['id'])?(int)$this->para['id']:0;
        $res = $MerchType->saveUs($data,$id);
        if($res){
			return $this->response('deal_succ', $res);
		}else{
			return $this->response('deal_false', $res);
		}
	}
	/**
	 * [actionListmerch 商户性质列表]
	 * @apiDoc
	 * @api     v1/system/listmerch
	 * @group   system
	 * @name    商户性质列表
	 * @desc    基础数据维护-商户性质名称维护-列表
	 * @method  POST
	 * @param currentPage string 当前页 noreq 1
	 * @param pageSize string 每页条数 noreq 15
	 * @author JOHN.W
	 * @version [1.0]
	 * @return  json
		 {
		"code": "000000",
		"msg": "操作成功",
		"total": "2",
		"info": [
		    {
		        "id": "2",
		        "name": "综合社区店",
		        "status": "allow",
		        "created": "2019-08-31 15:32:56",
		        "status_name": "启用"
		    },
		    {
		        "id": "1",
		        "name": "二手车整备",
		        "status": "allow",
		        "created": "2019-08-31 15:32:04",
		        "status_name": "启用"
		    }
		]
		}
	 */
	public function actionListmerch(){
		$_where = [];
		$_where['order'] = ['id' => 'desc'];
		/*分页处理*/
		$currentPage = 1;
		$pageSize = 15;
		if (isset($this->para['currentPage']) && !empty($this->para['currentPage']) && is_numeric($this->para['currentPage'])) {
			$currentPage = $this->para['currentPage'];
		}
		if (isset($this->para['pageSize']) && !empty($this->para['pageSize']) && is_numeric($this->para['pageSize'])) {
			$pageSize = $this->para['pageSize'];
		}
		$MerchType = new MerchTypeModel();
		$total = $MerchType->getWidgetTotal($_where);
		$list = $MerchType->getWidgetPages($_where, $pageSize, $pageSize * ($currentPage - 1));
		if (!empty($list)) {
			foreach ($list as &$value) {
				$value['status_name'] = Helper::getStatusByKey($value['status']);
				$value['created'] = date("Y-m-d H:i:s", $value['created']);
			}
		}
		return $this->response('search_succ', $list, $total);
	}
	/**
	 * [actionAddmerchpro 添加/修改-启用/禁止商户业务授权]
	 * @apiDoc
	 * @api     v1/system/addmerchpro
	 * @group   system
	 * @name    添加/修改/启用.禁止商户业务授权
	 * @desc    基础维护-商业业务授权维护-添加/修改/启用.禁止商户业务授权
	 * @method  POST
	 * @param mt_id int 商户性质ID添加/修改必填】 noreq
	 * @param pro_extra string 业务ID【添加/修改必填】 noreq
	 * @param id int ID【修改-启用禁用必填】 noreq
	 * @param status string 操作类型/启用禁用【allow:启用;deny:禁用 】 noreq 
	 * @author JOHN.W
	 * @version [1.0]
	 * @return  json
		{
		"code": "000000",
		"msg": "操作成功",
		"info": "1"
		}
	 */
	public function actionAddmerchpro(){
		$data = ['created'=>time()];
		$SysMerchProductSet = new SysMerchProductSetModel();
        if(isset($this->para['status']) && isset($this->para['id'])){
        	if (!in_array($this->para['status'], ['allow','deny'])) {
            	return $this->response('para_miss', '请选择正确的更新类型');
        	}
        	$data['status']=$this->para['status'];
        }else{
        	if (empty($this->para['mt_id']) || !is_numeric($this->para['mt_id'])) {
            	return $this->response('para_miss', '商户性质ID不能为空');
        	}
        	if (!isset($this->para['pro_extra']) || empty($this->para['pro_extra'])) {
            	return $this->response('para_miss', '业务不能为空');
        	}
        	$data['mt_id']=$this->para['mt_id'];
        	$data['pro_extra']=$this->para['pro_extra'];
        	//校验名字是否存在
        	$falg = $SysMerchProductSet->getWidgetRow(['mt_id'=>$data['mt_id']]);
        	if($falg) return $this->response('para_miss', '商户性质已存在请修改');
        }
        $id = isset($this->para['id'])?(int)$this->para['id']:0;
        $res = $SysMerchProductSet->saveUs($data,$id);
        if($res){
			return $this->response('deal_succ', $res);
		}else{
			return $this->response('deal_false', $res);
		}
	}
	/**
	 * [actionListmerchpro 商户性质业务授权列表]
	 * @apiDoc
	 * @api     v1/system/listmerchpro
	 * @group   system
	 * @name    商户性质业务授权列表
	 * @desc    基础数据维护-商户性质业务授权维护-列表
	 * @method  POST
	 * @param currentPage string 当前页 noreq 1
	 * @param pageSize string 每页条数 noreq 15
	 * @version [1.0]
	 * @return  json
		{
		"code": "000000",
		"msg": "操作成功",
		"total": "1",
		"info": [
		{
		    "id": "1",
		    "mt_id": "1",
		    "pro_extra": "2,3,4",
		    "status": "allow",
		    "created": "2019-08-31 16:03:01",
		    "status_name": "启用",
		    "pro_extra_show": "SUV",
		    "mt_id_show": "二手车整备"
		}
		]
		}
	 */
	public function actionListmerchpro(){
		$_where = [];
		$_where['order'] = ['id' => 'desc'];
		/*分页处理*/
		$currentPage = 1;
		$pageSize = 15;
		if (isset($this->para['currentPage']) && !empty($this->para['currentPage']) && is_numeric($this->para['currentPage'])) {
			$currentPage = $this->para['currentPage'];
		}
		if (isset($this->para['pageSize']) && !empty($this->para['pageSize']) && is_numeric($this->para['pageSize'])) {
			$pageSize = $this->para['pageSize'];
		}
		$SysMerchProductSet = new SysMerchProductSetModel();
		$total = $SysMerchProductSet->getWidgetTotal($_where);
		$list = $SysMerchProductSet->getWidgetPages($_where, $pageSize, $pageSize * ($currentPage - 1));
		if (!empty($list)) {
			foreach ($list as &$value) {
				$value['status_name'] = Helper::getStatusByKey($value['status']);
				$value['pro_extra_show'] = Helper::getProNameById($value['pro_extra']);
				$value['mt_id_show'] = Helper::getMerchNameById($value['mt_id']);
				$value['created'] = date("Y-m-d H:i:s", $value['created']);
			}
		}
		return $this->response('search_succ', $list, $total);		
	}
	/**
	 * [actionAddtechhire 添加/修改技师提成]
	 * @apiDoc
	 * @api     v1/system/addtechhire
	 * @group   system
	 * @name    添加/修改技师提成
	 * @desc    基础设置-技师提成维护-添加/修改
	 * @method  POST
	 * @param prov_id int 省ID req
	 * @param city_id int 市ID req
	 * @param area_id int 区ID noreq
	 * @param id int ID【修改必填】noreg
	 * @param base_type string 管理费基数【obtain:产品收款金额,price:产品标价】 req
	 * @param hire_way string 提成方式【fix:固定提成,ladder:阶梯提成】 req
	 * @param hire_extra json 方式配置（{"fix":{"scale":"0.5","amount":"88"},"ladder":[{"begin":0,"end":100,"scale":0.3},{"begin":200,"end":300,"scale":0.3}]}） req
	 * @author JOHN.W
	 * @version [1.0]
	 * @return  json
		{
		"code": "000000",
		"msg": "操作成功",
		"info": "1"
		}
	 */
	public function actionAddtechhire(){
		if (empty($this->para['prov_id']) || !is_numeric($this->para['prov_id'])) {
            return $this->response('para_miss', '请输入省ID');
        }
        if (empty($this->para['city_id']) || !is_numeric($this->para['city_id'])) {
            return $this->response('para_miss', '请输入市ID');
        }
        if (!isset($this->para['base_type']) || !in_array($this->para['base_type'],['obtain','price'])) {
            return $this->response('para_miss', '请选择正确的管理费基数');
        }
        if (!isset($this->para['hire_way']) || !in_array($this->para['hire_way'],['fix','ladder'])) {
            return $this->response('para_miss', '请选择正确的提成方式');
        }
        if (!isset($this->para['hire_extra']) || empty($this->para['hire_extra'])) {
            return $this->response('para_miss', '提成配置不能为空');
        }
        $id = isset($this->para['id'])?(int)$this->para['id']:0;
        $SysTechHireSet = new SysTechHireSetModel();
        $ver_param = [
        	'scope'=>['neq'=>['id'=>$id]],
        	'prov_id'=>$this->para['prov_id'],
        	'city_id'=>$this->para['city_id'],
        	'area_id'=>isset($this->para['area_id'])?$this->para['area_id']:0
        	];
        $flag = $SysTechHireSet->getWidgetRow($ver_param);
        if($flag){
			return $this->response('deal_false', '请勿重复添加');  	
        }
        $data = Helper::elements(['prov_id','city_id','base_type','hire_way','area_id','hire_extra'], $this->para, '0');
        $data['created'] = time();
        $res = $SysTechHireSet->saveUs($data,$id);
        if($res){
			return $this->response('deal_succ', $res);
		}else{
			return $this->response('deal_false', $res);
		}
	}
	/**
	 * [actionUptechhire 启用/禁用提成]
	 * @apiDoc
	 * @api     v1/system/uptechhire
	 * @group   system
	 * @name    启用/禁用提成
	 * @desc    基础设置-技师提成维护列表-启用/禁用
	 * @method  POST
	 * @param id int ID req
	 * @param status string 操作类型【allow:启用;deny:禁用 】 req
	 * @author JOHN.W
	 * @version [1.0]
	 * @return  json
		{
		"code": "000000",
		"msg": "操作成功",
		"info": true
		}
	 */
	public function actionUptechhire(){
		if (empty($this->para['status']) || !in_array($this->para['status'], ['allow','deny'])) {
            return $this->response('para_miss', '请选择正确的更新类型');
        }
        if (empty($this->para['id']) || !is_numeric($this->para['id'])) {
            return $this->response('para_miss', '操作ID不能为空');
        }
        $SysTechHireSet = new SysTechHireSetModel();
        $res = $SysTechHireSet->saveUs(['status'=>$this->para['status'],'created'=>time()],(int)$this->para['id']);
        if($res){
			return $this->response('deal_succ', $res);
		}else{
			return $this->response('deal_false', $res);
		}
	}
	/**
	 * [actionListtechhire 技师提成配置列表]
	 * @apiDoc
	 * @api     v1/system/listtechhire
	 * @group   system
	 * @name    技师提成列表
	 * @desc    基础设置-技师提成维护列表
	 * @method  POST
	 * @param prov_id int 省ID noreq
	 * @param city_id int 市ID noreq
	 * @param area_id int 区ID noreq
	 * @author JOHN.W
	 * @version [1.0]
	 * @return  json
	 {
    "code": "000000",
    "msg": "操作成功",
    "total": "1",
    "info": [
        {
            "id": "1",
            "prov_id": "1",
            "city_id": "2",
            "area_id": "0",
            "base_type": "obtain",
            "hire_way": "fix",
            "hire_extra": {
                "fix": {
                    "scale": "0.5",
                    "amount": "88"
                },
                "ladder": [
                    {
                        "begin": 0,
                        "end": 100,
                        "scale": 0.3
                    },
                    {
                        "begin": 200,
                        "end": 300,
                        "scale": 0.3
                    }
                ]
            },
            "status": "allow",
            "created": "1567307375",
            "prov_id_show": "北京市",
            "city_id_show": "天津市",
            "area_id_show": "--",
            "status_name": "启用"
	        }
	    ]
	}
	 */
	public function actionListtechhire(){
		$_where['order'] = ['id' => 'desc'];
		/*省搜索*/
		if (!empty($this->para['prov_id'])) {
			$_where['prov_id'] = $this->para['prov_id'];
		}
		/*市搜索*/
		if (!empty($this->para['city_id'])) {
			$_where['city_id'] = $this->para['city_id'];
		}
		/*区搜索*/
		if (!empty($this->para['area_id'])) {
			$_where['area_id'] = $this->para['area_id'];
		}
		$SysTechHireSet = new SysTechHireSetModel();
		$total = $SysTechHireSet->getWidgetTotal($_where);
		$list = $SysTechHireSet->getWidgetPages($_where);
		if (!empty($list)) {
			foreach ($list as &$value) {
				$value['prov_id_show'] = Helper::getRegion($value['prov_id']);
				$value['city_id_show'] = Helper::getRegion($value['city_id']);
				$value['area_id_show'] = Helper::getRegion($value['area_id']);
				$value['hire_extra'] = isset($value['hire_extra'])?json_decode($value['hire_extra'],true):[];
				$value['status_name'] = Helper::getStatusByKey($value['status']);
			}
		}
		return $this->response('search_succ', $list, $total);
	}
/*******************************门店营业时间配置*******************************************/
	/**
	 * [actionAddopenhours 添加/修改营业时间]
	 * @apiDoc
	 * @api     v1/system/addopenhours
	 * @group   system
	 * @name    添加/修改营业时间
	 * @desc    基础设置-门店营业时间维护-添加/修改
	 * @method  POST
	 * @param prov_id int 省ID req
	 * @param city_id int 市ID req
	 * @param area_id int 区ID noreq
	 * @param id int ID【修改必填】 noreq
	 * @param season_name string 季节名称 req
	 * @param month_start int 季节时间开始 req
	 * @param month_end int 季节时间结束 req
	 * @param day_time_start sring 营业时间上午 req
	 * @param day_time_end sring 营业时间下午 req
	 * @param night_time_start int 夜间营业时间开始 noreq
	 * @param night_time_end int 夜间营业时间结束 noreq
	 * @author JOHN.W
	 * @version [1.0]
	 * @return  json
	 {
		"code": "000000",
		"msg": "操作成功",
		"info": 1
		}
	 */
	public function actionAddopenhours(){
		if (empty($this->para['prov_id']) || !is_numeric($this->para['prov_id'])) {
            return $this->response('para_miss', '请输入省ID');
        }
        if (empty($this->para['city_id']) || !is_numeric($this->para['city_id'])) {
            return $this->response('para_miss', '请输入市ID');
        }
        if (!isset($this->para['season_name']) || empty($this->para['season_name'])) {
            return $this->response('para_miss', '请输入季节名称');
        }
        if (!isset($this->para['month_start']) || !is_numeric($this->para['month_start'])) {
            return $this->response('para_miss', '请输入季节时间开始');
        }
        if (!isset($this->para['month_end']) || !is_numeric($this->para['month_end'])) {
            return $this->response('para_miss', '请输入季节时间结束');
        }
        if (!isset($this->para['day_time_start']) || empty($this->para['day_time_start'])) {
            return $this->response('para_miss', '请输入营业时间上午');
        }
        if (!isset($this->para['day_time_end']) || empty($this->para['day_time_end'])) {
            return $this->response('para_miss', '请输入营业时间下午');
        }
        /*if (!isset($this->para['night_time_start']) || empty($this->para['night_time_start'])) {
            return $this->response('para_miss', '请输入夜间营业时间开始');
        }
        if (!isset($this->para['night_time_end']) || empty($this->para['night_time_end'])) {
            return $this->response('para_miss', '请输入夜间营业时间结束');
        }*/
        $id = isset($this->para['id'])?(int)$this->para['id']:0;
        $ysOpenHoursSet = new SysOpenHoursSetModel();
        $ver_param = [
        	'scope'=>['neq'=>['id'=>$id]],
        	'prov_id'=>$this->para['prov_id'],
        	'city_id'=>$this->para['city_id'],
        	'season_name'=>$this->para['season_name'],
        	'area_id'=>isset($this->para['area_id'])?$this->para['area_id']:0
        	];
        $flag = $ysOpenHoursSet->getWidgetRow($ver_param);
        if($flag){
			return $this->response('deal_false', '请勿重复添加');  	
        }
        $data = Helper::elements(['prov_id','city_id','area_id','season_name','month_start','month_end','day_time_start','day_time_end','night_time_start','night_time_end'], $this->para, '0');
        $data['created'] = time();
        $res = $ysOpenHoursSet->saveUs($data,$id);
        if($res){
			return $this->response('deal_succ', $res);
		}else{
			return $this->response('deal_false', $res);
		}
	}
	/**
	 * [actionListopenhours 营业时间列表]
	 * @apiDoc
	 * @api     v1/system/listopenhours
	 * @group   system
	 * @name    营业时间列表
	 * @desc    基础设置-门店营业时间维护列表
	 * @method  POST
	 * @param prov_id int 省ID req
	 * @param city_id int 市ID req
	 * @param area_id int 区ID noreq
	 * @author JOHN.W
	 * @version [1.0]
	 * @return  json
		{
		"code": "000000",
		"msg": "操作成功",
		"total": 1,
		"info": [
		{
		    "id": "1",
		    "prov_id": "1",
		    "city_id": "2",
		    "area_id": "0",
		    "season_name": "春季时间",
		    "month_start": "1",
		    "month_end": "6",
		    "day_time_start": "9",
		    "day_time_end": "12",
		    "night_time_start": "19",
		    "night_time_end": "21",
		    "is_open_night": "0",
		    "created": "2019-09-01 11:43:26"
		}
		]
		}
	 */
	public function actionListopenhours(){
		if (empty($this->para['prov_id']) || !is_numeric($this->para['prov_id'])) {
            return $this->response('search_succ', [], 0);
        }
        if (empty($this->para['city_id']) || !is_numeric($this->para['city_id'])) {
            return $this->response('search_succ', [], 0);
        }
		$_where = [];
		$_where['order'] = ['id' => 'desc'];
		/*省搜索*/
		if (!empty($this->para['prov_id'])) {
			$_where['prov_id'] = $this->para['prov_id'];
		}
		/*市搜索*/
		if (!empty($this->para['city_id'])) {
			$_where['city_id'] = $this->para['city_id'];
		}
		/*区搜索*/
		if (!empty($this->para['area_id'])) {
			$_where['area_id'] = $this->para['area_id'];
		}
		$SysOpenHoursSet = new SysOpenHoursSetModel();
		$list = $SysOpenHoursSet->getWidgetPages($_where);
		if (!empty($list)) {
			foreach ($list as &$value) {
				$value['created'] = date("Y-m-d H:i:s", $value['created']);
			}
		}
		return $this->response('search_succ', $list, count($list));
	}
	/**
	 * [actionUptechhire 关闭/开启夜间营业]
	 * @apiDoc
	 * @api     v1/system/upopenhours
	 * @group   system
	 * @name    开启/关闭夜间
	 * @desc    基础设置-门店营业时间维护-开启/关闭夜间
	 * @method  POST
	 * @param id int ID req
	 * @param is_open_night int 操作类型【1:关闭;0:开启 】 req
	 * @author JOHN.W
	 * @version [1.0]
	 * @return  json
		{
		"code": "000000",
		"msg": "操作成功",
		"info": true
		}
	 */
	public function actionUpopenhours(){
		if (isset($this->para['is_open_night']) || !in_array($this->para['is_open_night'], ['0','1'])){
            return $this->response('para_miss', '请选择正确类型');
        }
        if (empty($this->para['id']) || !is_numeric($this->para['id'])) {
            return $this->response('para_miss', '操作ID不能为空');
        }
        $SysOpenHoursSet = new SysOpenHoursSetModel();
        $res = $SysOpenHoursSet->saveUs(['is_open_night'=>$this->para['is_open_night'],'created'=>time()],(int)$this->para['id']);
        if($res){
			return $this->response('deal_succ', $res);
		}else{
			return $this->response('deal_false', $res);
		}
	}
}