<?php

/**
 * 控制器:后台系统-协议管理
 * date:2019-08-31
 */

namespace app\modules\manage\v1\controllers;

use app\modules\common\Helper;
use app\modules\logic\model\ProtocolModel;
use Yii;
use yii\web\Controller;

class ProtocolController extends MiddleController {
	/**
	 * 返回
	 * @param $code
	 * @param string $info
	 * @param string $controller
	 * @param string $total
	 */
	protected function response($code, $info = '', $total = '', $controller = 'protocol') {
		return parent::response($code, $info, $total, $controller);
	}
	/**
	 * [actionList 协议列表]
	 * @apiDoc
	 * @api     v1/protocol/list
	 * @group   protocol
	 * @name    协议管理
	 * @desc    管理后台-协议管理
	 * @method  POST
	 * @param type string 协议类型【tech:技师;shop:门店 】 req
	 * @author JOHN.W
	 * @version [1.0]
	 * @return  json
	 {
    "code": "000000",
    "msg": "操作成功",
    "info": [
        {
            "id": "7",
            "type": "tech",
            "title": "用户协议",
            "content": null
        },
        {
            "id": "8",
            "type": "tech",
            "title": "隐私保护协议",
            "content": null
        },
        {
            "id": "9",
            "type": "tech",
            "title": "提现规则",
            "content": null
        },
        {
            "id": "10",
            "type": "tech",
            "title": "结算规则",
            "content": null
        },
        {
            "id": "11",
            "type": "tech",
            "title": "出行险扣款协议",
            "content": null
        },
        {
            "id": "12",
            "type": "tech",
            "title": "施工险扣款协议",
            "content": null
        },
        {
            "id": "13",
            "type": "tech",
            "title": "劳务协议",
            "content": null
        },
        {
            "id": "14",
            "type": "tech",
            "title": "技师等级规则",
            "content": null
        },
        {
            "id": "15",
            "type": "tech",
            "title": "技师星级规则",
            "content": null
        },
        {
            "id": "16",
            "type": "tech",
            "title": "处罚规则",
            "content": null
        }
    	]
		}
	 */
	public function actionList(){
		if (empty($this->para['type']) || !in_array($this->para['type'], ['tech','shop'])) {
            return $this->response('para_miss', '请选择正确的类型');
        }
        $Protocol = new ProtocolModel();
        $data = $Protocol->getWidgetRows(['cols'=>['id','type','title','content'],'type'=>$this->para['type']]);
        return $this->response('deal_succ', $data);
	}
	/**
	 * [actionModify 修改协议]
	 * @apiDoc
	  * @api     v1/protocol/modify
	 * @group   protocol
	 * @name    修改协议
	 * @desc    管理后台-协议管理-修改协议（公用）
	 * @method  POST
	 * @param id int 协议ID req
     * @param title string 标题 noreq
     * @param content string 内容 noreq
	 * @author JOHN.W
	 * @version [1.0]
	 * @return  json
		{
		"code": "000000",
		"msg": "操作成功",
		"info": "修改协议成功"
		}
	 */
	public function actionModify(){
		if (empty($this->para['id']) || !is_numeric($this->para['id'])) {
            return $this->response('para_miss', 'id为空或不是数字');
        }
        $Protocol = new ProtocolModel();
        $param = [
        	'title'=>$this->para['title'],
        	'content'=>$this->para['content']
        ];
        $res =  $Protocol->saveUs($param,$this->para['id']);
        return $this->response('deal_succ', '修改协议成功');
	}
}