<?php
namespace admin\action;
use \model\pro\pro;
use \model\pbrand;
class pbrandAction  extends \action
{
	//品牌扩展数据
	public function ext()
    {
        $req = \mvc::$req;
		$pro = new pro();
		$pbArr = $pro->getProBrand();
		\view::set('pbArr',$pbArr);
		\view::set('req',$req);
        \view::put();
    }
	
	//品牌扩展数据
	function listExt()
	{
		$req = \mvc::$req;
		$type = $req['type'];
		$cols = \mvc::$cfg['BrandExt'][$type]? \mvc::$cfg['BrandExt'][$type]: [];
		$pwcodes = [
			'outbox'=>'D100',
			'inbox'=>'D200',
			'inpocket'=>'D300',
			'tag'=>'D400',
			'material'=>'D500',
		];
		\view::set('QUERY_STRING', $_SERVER['QUERY_STRING']);
		\view::set('req',$req);
		\view::set('pwcode',$pwcodes[$type]);
		\view::set('cols',$cols);
        \view::put();
	}


	public function getExtList()
	{
		$req = \mvc::$req;
		$rules = $this->urlRulesToWhere($req);
		$pbrand = new pbrand();
		$data = $pbrand->getExtList($req, $rules);
		$this->successJson($data);
	}

	//删除数据
	public function delData()
	{
		$req = \mvc::$req;
		$pbrand = new pbrand();
		$data = $pbrand->delData($req['table'], explode(',', $req['ids']));
		$this->successJson($data);
	}

	//修改
	public function setExtCell()
	{
		$req = \mvc::$req;
		if(!empty($req['id']) && preg_match('/^\d+$/', $req['id'])){
			$setArr = [
				$req['field']=>$req[$req['field']]
			];
			$pbrand = new pbrand();
			$pbrand->setExtCell($req['id'], $setArr);
		}
	}

	public function getAllKeyValues($fields=null)
    {
		$req = \mvc::$req;
		$pbrand = new pbrand();
	
	
 		$result = $pbrand->getExtList($req);

		$rows = $result['rows'];
        $data = [];
        $regi=0;
		$firstkey = isset($req['firstkey'])? $req['firstkey']: 0;
        if(isset($req['hasFirst']) && $req['hasFirst']){
            $data[0] = ['key'=>$firstkey, 'value'=>'' ];
            $regi = 1;
        }
        foreach($rows as $k=>$row){

            $data[$k+$regi] = ['key'=>$row['pbe_id'], 'value'=> $row['pbe_val'] ];
        }
        $this->successJson($data);
    }

	public function detail()
	{
		$req = \mvc::$req;
		$pbrand  = new pbrand();
		$item = $pbrand->getDetail($req['key']);
		\view::set('item',$item);
		\view::set('req',$req);
        \view::put();
	}
}