<?php
namespace admin\action;
use \model;
use model\carmodel;
use model\element;
use \model\oe;
use model\oeModel;
use model\oeModelCN;
use model\oeModelNA;
use model\oeNumidx;
use model\pro\cate;
use model\pro\pro;
use \model\napro;

class oeAction  extends \action
{
	//数据列表
	public function getList()
	{
		$req = \mvc::$req;
		$rules = $this->urlRulesToWhere($req);
		if(isset($req['numbers'])){
			$rules['numbers'] = explode(',', $req['numbers']);
			$rules['numlike'] = empty($req['numlike']) ? 0 : $req['numlike'];
		}
		if(isset($req['numbers'])){
			$rules['numbers'] = explode(',', $req['numbers']);
			$rules['numlike'] = empty($req['numlike']) ? 0 : $req['numlike'];
		}
		if(isset($rules['findNulls']) && $rules['findNulls']){
			$rules['findNulls'] = json_decode(base64_decode($rules['findNulls']),true);
		}
        $oe = new oe();
        $data = $oe->getList($req, $rules);
        $this->successJson($data);
	}
	
	//零件供应库
	public function getListSup()
	{
		$req = \mvc::$req;
		$rules = $this->urlRulesToWhere($req);
		if(isset($req['numbers'])){
			$rules['numbers'] = explode(',', $req['numbers']);
			$rules['numlike'] = empty($req['numlike']) ? 0 : $req['numlike'];
		}
		if(isset($rules['findNulls']) && $rules['findNulls']){
			$rules['findNulls'] = json_decode(base64_decode($rules['findNulls']),true);
		}
		$oe = new oe();
		$data = $oe->getListSup($req, $rules);
		$this->successJson($data);
	}

	public function detailSet($oe_id)
    {
		$req = \mvc::$req;
		$item = [];
		if($oe_id){
			$oe = new oe();
            $item = $oe->getRowByKey($oe_id);
        }

        \view::set('item',$item);
		\view::put();
    }

	public function saveDetail()
    {
		$req = \mvc::$req;
		$oe = new oe();
		$data = $oe->saveDetail($req['oe_id'], $req);
		$this->successJson($data);
    }
	//修改记录
	public function setCell()
	{
		$req = \mvc::$req;
		if(!empty($req['id']) && preg_match('/^\d+$/', $req['id'])){
			$setArr = [
				$req['field']=>$req[$req['field']]
			];
			$oe = new oe();
			$oe->setCell($req['id'], $setArr);
		}
	}

	public function setCnModelCell()
	{
		$req = \mvc::$req;
		if(!empty($req['id']) && preg_match('/^\d+$/', $req['id'])){
			$setArr = [
				$req['field']=>$req[$req['field']]
			];
			$oeModelCN = new oeModelCN();
			$oeModelCN->setCell($req['id'], $setArr);
		}
	}

	//删除OE数据
	public function delData()
	{
		$req = \mvc::$req;
		$oe = new oe();
		$data = $oe->delData($req['ids']);
		$this->successJson($data);
	}

	public function listSup()
	{	
		$req = \mvc::$req;
		\view::set('QUERY_STRING', $_SERVER['QUERY_STRING']);
		\view::put();
	}


	public function list()
	{	
		$req = \mvc::$req;

		\view::put();
	}

	/**
	 * @method OE基本资料
	 * @author zhengweihua 
	 * @copyright 2024-11-16
	 */
	public function base()
	{
		$req = \mvc::$req;
		$oe = new oe();
		$dataArr = $oe->getDetail($req['oe_id']);
		\view::set('cleanArr', $dataArr['cleans']);
		\view::set('cleanChkArr', $dataArr['cleans_chk']);
		\view::set('dataArr', $dataArr);
		\view::set('pwcode','A300');
		$pro = new pro();
		\view::set('allPos', $pro->allPos);
		\view::put();
	}

	/**
	 * @method OE参考号页面
	 * @author zhengweihua 
	 * @copyright 2024-11-16
	 */
	public function listNum()
	{
		$req = \mvc::$req;
		\view::set('req',$req);
		\view::put();	
	}

	/**
	 * @method OE参考号数据列表
	 * @author zhengweihua 
	 * @copyright 2024-11-15
	 */
	public function getListNum()
	{
		$req = \mvc::$req;
		$req['pnt_status'] = 1;
		$rules = $this->urlRulesToWhere($req);
		if(isset($req['numbers'])){
			$rules['numbers'] = formatNums($req['numbers']);
			$rules['numlike'] = empty($req['numlike']) ? 0 : $req['numlike'];
		}

		$oeNumidx = new oeNumidx();

        $data = $oeNumidx->getNumList($req, $rules);
        $this->successJson($data);
	}

	/**
	 * @method OE参考号单元格编辑
	 * @author zhengweihua 
	 * @copyright 2024-11-15
	 */
	public function setNumidxCell()
	{
		$req = \mvc::$req;
		if(!empty($req['id']) && preg_match('/^\d+$/', $req['id'])){
			$setArr = [
				$req['field']=>$req[$req['field']]
			];
			$oeNumidx = new oeNumidx();
			$oeNumidx->setCell($req['id'], $setArr);
		}
	}

	/**
	 * @method 添加OE交叉库数据
	* @author zhengweihua
	*/
	public function addNumidx()
	{
		$req = \mvc::$req;
		$oeNumidx = new oeNumidx();
		$data = $oeNumidx->addNumidx($req);
		$this->successJson($data);
	}

	/**
	 * @method 删除oe交叉库记录
	 * @author zhengweihua 
	 * @copyright 2024-11-15
	 */
	public function delNumData()
	{
		$req = \mvc::$req;
		$oeNumidx = new oeNumidx();
		$data = $oeNumidx->delData(explode(',', $req['ids']));
		$this->successJson($data);
	}


	/**
	 * @method 获取OE信息
	 * @author zhengweihua 
	 * @copyright 2024-11-15
	 */
	public function getRowByNumber($num)
	{	
		$oe = 	new oe();
		$pid = $oe->getPidByNumber($num);
		if($pid){
			$data = $oe->getRowByKey($pid);
			if(!empty($data))
				$this->successJson($oe->formatRow($data));
		}
		$this->successJson(0);
	}

	/**
	 * @method 号码自动完成
	* @param  num string  [必填] 号码
	* @author zhengweihua
	*/
	public function autocomNum()
	{
		$req = \mvc::$req;
		$oe = new oe();
		$data = $oe->autoComNum($req);
		$this->successJson($data);
	}

	public function getAllOeNum()
	{
		$req = \mvc::$req;
		$oe = new oe();
		$data = $oe->getAllOeNum($req);
		$this->successJson($data);
	}

	/**
	 * @method OE车型库列表
	 * @author zhengweihua 
	 * @copyright 2024-11-15
	 */
	public function listModel()
	{
		$req = \mvc::$req;
		$carmodel = new carmodel();
		\view::set('carModelFileds',$carmodel->fieldLnkCaption);
		\view::set('modelFiledVals', $carmodel->modelFiledVals);
		\view::set('req',$req);
		\view::put();	
	}

	/**
	 * @method OE车型数据
	 * @author zhengweihua 
	 * @copyright 2024-11-16
	 */
	public function getModelList()
	{
		$req = \mvc::$req;
		$req['pnt_status'] = 1;
		$rules = $this->urlRulesToWhere($req);
		if(isset($req['numbers'])){
			$rules['numbers'] = formatNums($req['numbers']);
			$rules['numlike'] = empty($req['numlike']) ? 0 : $req['numlike'];
		}

		$oeModel = new oeModel();

        $data = $oeModel->getModelList($req, $rules);
        $this->successJson($data);
	}

	public function setModelCell()
	{
		$req = \mvc::$req;
		if(!empty($req['id']) && preg_match('/^\d+$/', $req['id'])){
			$setArr = [
				$req['field']=>$req[$req['field']]
			];
			$oeModel = new oeModel();
			$data = $oeModel->setCell($req['id'], $setArr);
		}
	}

	/**
	 * @method oe车型详细
	 * @author zhengweihua 
	 * @copyright 2024-11-16
	 */
	public function oeModelDetail()
	{
		$req = \mvc::$req;
		$dataArr = [];
		if(!empty($req['oml_id']))
		{
			$oeModel = new oeModel();
			$dataArr = $oeModel->getModelList($req);
			$dataArr = $dataArr['rows'][0];
			
		}
		\view::set('dataArr', $dataArr);

		\View::put();
	}

	/**
	 * @method 保存OE车型数据 添加/修改
	 * @author zhengweihua 
	 * @copyright 2024-11-16
	 */
	public function saveOeModelDetail()
	{
		$req = \mvc::$req;
		$setArr = ['base'=>$req['base']];
		
		$oeModel = new oeModel();
		$data = $oeModel->saveOeModelDetail($req['oml_id'], $setArr);
		if(!empty($data['msg'])) exitJson($data['msg']);
		$this->successJson($data);
	}

	/**
	 * @method 删除OE车型
	 * @author zhengweihua 
	 * @copyright 2024-11-16
	 */
	public function delModelData()
	{
		$req = \mvc::$req;
		$oeModel = new oeModel();
		$data = $oeModel->delData(explode(',', $req['ids']));
		$this->successJson($data);
	}

	/**
	 * @method 某OE交叉库
	* @param  oe_id  int  [必填] OE ID
	* @author zhengweihua
	*/
	function numListOE()
	{
		$req = \mvc::$req;
		\view::put();
	}
  
	/**
	* @method 某OE交叉库 数据
	* @param  oe_id  int  [必填] OE ID
	* @author zhengweihua
	*/
	public function getNumListOE()
	{
		$req = \mvc::$req;
		if(empty($req['oe_id'])) {
			exitJson(lg('参数错误'));
		}else{
			$oeNumidx = new oeNumidx();
			$data = $oeNumidx->getNumList($req);
			$this->successJson($data);
		}
	}
	/**
	 * @method 添加某个OE的车型数据
	 * @author zhengweihua 
	 * @copyright 2024-11-16
	 */
	public function addOEModel()
	{
		$req = \mvc::$req;
		$oeModel = new oeModel();
		$modArr = [];
		foreach(explode(',', $req['ids']) as $id)
		{
			$modArr[] = ['oml_mm_id'=>$id];
		}
		$data = $oeModel->addOEModel($req['oe_id'], $modArr);
		$this->successJson($data);
	}

	/**
	 * @method OE中国车型
	 * @author zhengweihua 
	 * @copyright 2024-11-21
	 */
	public function listCnModel()
	{
		$req = \mvc::$req;
		\view::set('req',$req);
		\view::put();
	}

	/**
	 * @method 获取中国车型列表
	 * @author zhengweihua 
	 * @copyright 2024-11-21
	 */
	public function getCnModelList()
	{
		$req = \mvc::$req;
		$req['pnt_status'] = 1;
		$rules = $this->urlRulesToWhere($req);
		if(isset($req['numbers'])){
			$rules['numbers'] = formatNums($req['numbers']);
			$rules['numlike'] = empty($req['numlike']) ? 0 : $req['numlike'];
		}

		$oeModelCN = new oeModelCN();

        $data = $oeModelCN->getModelList($req, $rules);
        $this->successJson($data);
	}

	/**
	 * @method 添加中国车型
	 * @author zhengweihua 
	 * @copyright 2024-11-21
	 */
	public function cnModelDetail()
	{
		$req = \mvc::$req;
		$dataArr = [];
		if(!empty($req['oml_id']))
		{
			$oeModelCN = new oeModelCN();
			$dataArr = $oeModelCN->getModelList($req);
			$dataArr = $dataArr['rows'][0];
		}
		\view::set('dataArr', $dataArr);
		\View::put();
	}

	/**
	 * @method 保存中国车型数据 添加/修改
	 * @author zhengweihua 
	 * @copyright 2024-11-16
	 */
	public function saveCNModelDetail()
	{
		$req = \mvc::$req;
		$setArr = ['base'=>$req['base']];
		
		$oeModelCN = new oeModelCN();
		$data = $oeModelCN->saveModelDetail($req['oml_id'], $setArr);
		if(!empty($data['msg'])) exitJson($data['msg']);
		$this->successJson($data);
	}

	/**
	 * @method 删除OE车型
	 * @author zhengweihua 
	 * @copyright 2024-11-16
	 */
	public function delCNModelData()
	{
		$req = \mvc::$req;
		$oeModelCN = new oeModelCN();
		$data = $oeModelCN->delData(explode(',', $req['ids']));
		$this->successJson($data);
	}

	/**
	 * @method 添加OE中国车型
	 * @author zhengweihua 
	 * @copyright 2024-11-20
	 */
	public function addCNModel()
	{
		$req = \mvc::$req;
		$oeModelCN = new oeModelCN();
		$modArr = [];
		foreach(explode(',', $req['ids']) as $id)
		{
			$modArr[] = ['oml_mod3_id'=>$id];
		}
		$data = $oeModelCN->addOECnModel($req['oe_id'], $modArr);
		$this->successJson($data);
	}
	

	/**
	 * @method OE北美车型
	 * @author zhengweihua 
	 * @copyright 2026-03-24
	 */
	public function listNaModel(){
		$req = \mvc::$req;
		\view::set('req',$req);
		\view::put();
	}

	public function getNaModelList(){
		$req = \mvc::$req;
		$oeModelNA = new oeModelNA();
		$data = $oeModelNA->getModelList($req);
        $this->successJson($data);
	}

	/**
	 * @method 审核
	 */
	public function check1()
	{
		$req = \mvc::$req;
		$oe = new oe();
		$data = $oe->check1(explode(',', $req['ids']), $req);
		$this->successJson($data);
	}

	public function chkOeIdByAny()
	{
		$oe = new oe();
		$res = $oe->chkOeIdByAny(\mvc::$req);
		$this->successJson($res);
	}


	 /**
     * 获取OE参数
     * @param $pId
     */
    public function oeParam($oeId)
    {
        $oe = new oe();
        $list = $oe->getOeParamByOeid($oeId);
        $this->successJson($list);
    }

	public function paramPhoto($cid)
    {
        $url = '';
        $cate = new cate();
        if($row = $cate->getRowByKey($cid)){
            if($row['photo_param']){
                $url = makeOne(\model\files::class)->getFilename($row['photo_param']);
                $url = makeOne(\lib\file::class)->formatDir($url);
                $url = ltrim($url,'/');
            }
        }
        $this->successJson(['filename'=>$url]);
    }

	/**
	 * 格式化参考参数
	 */
	public function formatPara()
	{
		$req = \mvc::$req;
		$oeId = $req['oeId'];
		
		$oe = new oe();
		$list = $oe->getDetail($oeId);
		if($list['oe_para'])
		{
			$ret = $oe->formatParaFromTcd($list['oe_cate_id'],$list['oe_para'],$oeId);

			$oe->setOeParaAndPos($oeId,$ret,$req['syncFgio']? 1 : 0);
		}
		
		$this->successJson("操作成功");
	}

	public function listSupplier()
	{
		$req = \mvc::$req;
		\view::set('req',$req);
		\view::put();
	}
	/**
	 * @method OE供应商列表
	 */
	public function getListSupplier()
	{
		$req = \mvc::$req;
		$rules = $this->urlRulesToWhere($req);
		$oe = new oe();
        $data = $oe->getListSupplier($req, $rules);
        $this->successJson($data);
	}
	
	/**
	 * @method 根据on_id设置零件库主号码
	 * @author zhengweihua 
	 * @copyright 2025-01-11
	 */
	public function setOeMain()
	{
		$req = \mvc::$req;
		$oe = new oe();
		$data = $oe->setOeMain($req['on_id'],$req['syncFgio']);
		$this->successJson($data);
	}

	/**
	 * @method 根据on_id设置借用号
	 * @author hongzhang
	 * @copyright 2025-08-29
	 */
	public function setBorrowNums(){
		$req = \mvc::$req;
		$oe = new oe();
		$data = $oe->setBorrowNums($req['ids'],$req['borrow']);
		$this->successJson($data);
	}

	/**
	 * @method 图片相关
	 * @author zhengweihua 
	 * @copyright 2025-01-14
	 */
	public function listPic()
	{
		$req = \mvc::$req;
		$data = [];
		$oe  = new oe();
		if($req['oe_id']){
			$data = $oe->getDetail($req['oe_id']);
		}

		\view::set('data',$data);
		\view::set('req',$req);
		\view::put();
	}

	/**
	 * @method 获取图片列表
	 * @author zhengweihua 
	 * @copyright 2025-01-14
	 */
	public function getListPic()
	{
		$req = \mvc::$req;
		$rules = $this->urlRulesToWhere($req);
		$oe = new oe();
        $data = $oe->getListPic($req, $rules);
        $this->successJson($data);
	}

	/**
	 * @method 单元格编辑
	 * @author zhengweihua 
	 * @copyright 2025-01-14
	 */
	public function setOePicCell()
	{
		$req = \mvc::$req;
		
		$oe = new oe();
		$data = $oe->setOePicCell($req);
		
	}

	/**
	 * @method 设置主图
	 * @author zhengweihua 
	 * @copyright 2025-01-14
	 */
	public function setOeMainPic()
	{
		$req = \mvc::$req;
		if(!$req['fileid']||!$req['oeid']||!$req['type']) return $this->exitJson(-1,lg('参数错误'));
		$oe = new oe();
		$data = $oe->setOeMainPic($req['fileid'],$req['oeid'],$req['type']);
		$this->successJson($data);
	}

	public function setPicSup()
	{
		$req = \mvc::$req;
		if(!$req['fileid']||!$req['oeid']||!$req['sup_id']) return $this->exitJson(-1,lg('参数错误'));
		$oe = new oe();
		$fileids = array_values(explode(',',$req['fileid']));
		$data = $oe->setPicLineSup($req['oeid'],$req['sup_id'],$fileids);
		$this->successJson($data);
	}

	public function delOePic()
	{
		$req = \mvc::$req;
		$oe = new oe();
		$data = $oe->delOePic($req);
		$this->successJson($data);	
	}

	public function autoSup()
	{
		$req = \mvc::$req;
		$oe = new oe();
		$data = $oe->autoSup($req);
		$this->successJson($data);
	}


	public function chkSup()
	{
		$oe = new oe();
		$res = $oe->chkSup(\mvc::$req);
		$this->successJson($res);
	}

	
	public function reGetEpcInfo()
	{
		$req = \mvc::$req;
		$oe = new oe();
		$data = $oe->reGetEpcInfo($req['oe_id'], $req['on_id']);
		$this->successJson($data);
	}


	public function epcInfo()
	{
		$req = \mvc::$req;
		$oe = new oe();
		$data = $oe->getDetail($req['oe_id']);
		if(empty($data['oe_etk_epa_id'])) exitJson(lg('无相关信息'));
		$baseArr = $data['oe_etk_info'];
		$itemArr = $data['oe_etk_partitem'];

		$linkarr = [];
		$allLink = $oe->getListOELink(['oe_id'=>$req['oe_id'],'type'=>'link','ol_from'=>1070]);
		if($allLink['rows']){
			$linkarr = [];
			foreach ($allLink['rows'] as $val) {
				$linkarr[] = formatNum($val['rel_number']);
			}
		}
		//当前零件的号码
		$oeNumidx = new oeNumidx();
        $curNumRes = $oeNumidx->getNumList(['oe_id'=>$req['oe_id']], []);
		$curNum = $curNumRes['rows']?array_column($curNumRes['rows'],null,'on_formart'):[];
		//匹配&&排除
		foreach($itemArr['item'] as $k=> &$v){
			$format = formatNum($v['pro_realoem']);

			$v['showchk'] = true;
			if(!$v['pro_realoem']) $v['showchk'] = false;
			if($curNum[$format]){
				$v['showchk'] = false;
			}

			$v['chked'] =  false;
			
			if(in_array($format,$linkarr)){
				$v['chked'] =  true;
			}
		}
		unset($v);

		$imgmapJson = [];
		if(!empty($itemArr['part']['pic']))
		{
			$imgmapJson = [
				$itemArr['part']['pic']=>[
					'width'=>$itemArr['part']['width'],	
					'rate'=>$itemArr['part']['rate'],
					'wz'=>$itemArr['part']['wz'],
					//'weizhi'=>$baseArr['weizhi'],
					'loadCallback'=>'partItemLoadCallback',
					'selCallback'=>'partItemSelCallback'
				]
			];
			if(is_array($itemArr['picoth']))
			{
				foreach($itemArr['picoth'] as $v)
				{
					$imgmapJson[$v['pic']] = [
						'width'=>$v['width'],	
						'rate'=>$v['rate'],
						'wz'=>$v['wz'],
						//'weizhi'=>$baseArr['weizhi'],
						'loadCallback'=>'partItemLoadCallback',
						'selCallback'=>'partItemSelCallback'
					];
				}
			}
		}
		\view::set('req',$req);
		\view::set('linkarr', $linkarr);
		\view::set('imgmapJson', $imgmapJson);
		\view::set('baseArr', $baseArr);
		\view::set('itemArr', $itemArr);
		\view::put();
	}


	/**
	 * @method 搜图
	 * @author zhengweihua 
	 * @copyright 2025-01-15
	 */
	public function searchPic()
	{
		$req = \mvc::$req;
		$data = [];
		$searchArr = [];
		if($req['oe_id']){
			$oe = new oe();
			$res = $oe->getListPic(['oe_id'=>$req['oe_id'],'type'=>'img']);
			$data = $res['rows'];
		}
		\view::set('data',$data);
		if($req['number']){
			$res = $oe->searchPic($req['number']);
			$searchArr = $res['data'];
			// $jstr = file_get_contents(\mvc::$cfg['dir']['files'].'/jstr.txt');
			// $searchArr = json_decode($jstr,true)['data'];
		}
		\view::set('searchArr',$searchArr);
	
		\view::set('req',$req);
		\view::put();
	}

	/**
	 * @method 将选择的图片设置为零件图
	 * @author zhengweihua 
	 * @copyright 2025-01-15
	 */
	public function setOePicByFile()
	{
		$req = \mvc::$req;
		$oe = new oe();
		$data = $oe->setOePicByFile($req);
		$this->successJson($data);
	}

	/**
	 * @method 设置零件图为主图
	 * @author zhengweihua 
	 * @copyright 2025-01-15
	 */
	public function setImgToMain()
	{
		$req = \mvc::$req;
		$oe = new oe();
		$data = $oe->setImgToMain($req);
		$this->successJson($data);
	}


	public function setDevelopNo()
	{
		$req = \mvc::$req;
	
		if($req['oe_id']){
			$oe  = new oe();
			$detail = $oe->getListSup(['oe_id'=>$req['oe_id']]);
		}
		\view::set('devNoList',$detail['rows'][0]['devNoList']??[]);
		\view::set('req',$req);
		\view::put();
	}

	public function saveDevelopNo()
	{
		$req = \mvc::$req;
		if(!$req['oid_oe_id']||!$req['num']) exitJson(-1,lg('参数错误'));
		$oe = new oe();
		$data = $oe->saveDevelopNo($req['oid_oe_id'],$req['num']);
		$this->successJson($data);
	}

	public function saveCompetitor()
	{
		$req = \mvc::$req;
		$oe = new oe();
		$data = $oe->saveCompetitor($req);
		$this->successJson($data);
	}

	/**
	 * @method 竞品价格自动绑定oe零件
	 * @author zhengweihua 
	 * @copyright 2025-01-15
	 */
	public function autoBindOeItem()
	{
		$req = \mvc::$req;
		$oe = new oe();
		$data = $oe->autoBindOeItem($req['copIds']);
		$this->successJson($data);
	}

	public function oeLink()
	{
		$req = \mvc::$req;
		\view::set('req',$req);
		\view::put();
	}

	public function getListOELink()
	{
		$req = \mvc::$req;
		$rules = $this->urlRulesToWhere($req);
		if(isset($req['numbers'])){
			$rules['numbers'] = explode(',', $req['numbers']);
			$rules['numlike'] = empty($req['numlike']) ? 0 : $req['numlike'];
		}
		$oe = new oe();
        $data = $oe->getListOELink($req, $rules);
        $this->successJson($data);
	}

	/**
	 * @method 获取自动绑定oe零件
	 * @author zhengweihua 
	 * @copyright 2025-04-23
	 */
	public function getAutoBindOe()
	{
		$req = \mvc::$req;
		$oe = new oe();
		$data = $oe->getAutoBindOe($req);
		$this->successJson($data);
	}

	/**
	 * @method 零件关联自动绑定
	 * @author zhengweihua 
	 * @copyright 2025-01-15
	 */
	public function oeLinkAutoBind()
	{
		$req = \mvc::$req;
		$oe = new oe();
		$data = $oe->oeLinkAutoBind($req);
		$this->successJson($data);
	}
	/**
	 * @method 零件自动配对
	 * @author zhengweihua 
	 * @copyright 2025-01-22
	 */
	public function oeLinkAutoPair()
	{
		$req = \mvc::$req;
		$oe = new oe();
		if(!$req['ids']) exitJson(-1,lg('参数错误'));

		$data = $oe->oeLinkAutoPair($req['ids']);
		$this->successJson($data);
	}

	/**
	 * @method 获取需要绑定配对的OEID以及号码
	 * @author zhengweihua 
	 * @copyright 2025-02-07
	 */
	public function getAutoOeIds()
	{
		$req = \mvc::$req;
		$oe = new oe();
		$data = $oe->getAutoOeIds($req);
		$this->successJson($data);
	}

	public function setOePair()
	{
		$req = \mvc::$req;

		\view::set('req',$req);
		\view::put();
	}

	public function delOeLink()
	{
		$req = \mvc::$req;
		$oe = new oe();
		$data = $oe->delOeLink($req);
		$this->successJson($data);
	}

	public function autoMatchCnModel()
	{
		$req = \mvc::$req;
		$oe = new oe();
		$data = $oe->autoMatchCnModel($req['type'], $req['id']);
		\view::set('data',$data);
		$html = \view::fetch();
		$this->successJson(['html'=>$html]);
	}

	public function saveAddCnModel()
	{
		$req = \mvc::$req;
		$oe = new oe();
		$data = $oe->saveAddCnModel($req['type'], $req['id'], $req['cnmodelids']);
		$this->successJson($data);
	}

	public function getOeItemInfo()
	{
		$req = \mvc::$req;
		$oe = new oe();
		if(!$req['pf_id'] || !$req['number']) $this->successJson([]);
		$data = $oe->getOeItemInfo($req);
		$this->successJson($data);
	}

	public function setEpcNumLink()
	{
		$req = \mvc::$req;
		$oe = new oe();
		if(!$req['oe_id']) exitJson(-1,lg('参数错误'));

		$data = $oe->setEpcNumLink($req['oe_id'],$req['number']?:[]);
		$this->successJson($data);
	}

	/**
	 * @method 详情信息
	 * @author zhengweihua 
	 * @copyright 2025-02-19
	 */
	public function detail()
	{	
		$req = \mvc::$req;
		header('Location: '.\mvc::$cfg['sitePath'].'/oe/detailSet?tab='.$req['tab'].'&oe_id='.$req['oe_id']);
		exit;

		$oe = new oe();
		$dataArr = $oe->getDetail($req['oe_id']);

		\view::set('dataArr', $dataArr);
		$oeNumidx = new oeNumidx();
		//参数
        $numData = $oeNumidx->getNumList(['oe_id'=>$req['oe_id']]);
		\view::set('numData', $numData['rows']);
		//车型
		$oeModel = new oeModel();
		$modelData = $oeModel->getModelList(['oe_id'=>$req['oe_id'],'orderby'=>'mk_'.LG_NAME.',ms_name,mm_name']);

		$modelArr = [];
		foreach ($modelData['rows'] as $key => $val) {
			
			$modelArr[$val['mk_name']][$val['ms_name']][] = $val;
		}
		\view::set('modelData', $modelArr);
		//中国车型
		$oeModelCN = new oeModelCN();
        $cnmodelData = $oeModelCN->getModelList(['oe_id'=>$req['oe_id'],'orderby'=>'brand_initial,brand_name,make_name,mod1_name,mod2_name,mod2_start_year,mod3_name,mod3_start_year']);
		$cnmodelArr = [];
		foreach ($cnmodelData['rows'] as $key => $val) {
			
			$cnmodelArr[$val['brand_name']][$val['make_name'].$val['mod2_name']][] = $val;
		}
		\view::set('cnmodelData', $cnmodelArr);
		//供应商
		$supplierData = $oe->getListSupplier(['oe_id'=>$req['oe_id']]);
		\view::set('supplierData', $supplierData['rows']);
		//竞争对手
		$element = new element('competitor_price');
		$competitorData = $element->list(['cop_oe_id'=>$req['oe_id']]);
		\view::set('competitorData', $competitorData['rows']);
		//关联号码
		$linkData = $oe->getListOELink(['oe_id'=>$req['oe_id'],'type'=>'link','onlyExits'=>1]);
		\view::set('linkData', $linkData['rows']);
		$pro = new pro();
		\view::set('allPos', $pro->allPos);
		\view::put();	
	}

	/**
	 * @method 添加已选号码到零件
	 * @author zhengweihua 
	 * @copyright 2025-04-11
	 */
	public function saveNumToOe()
	{
		$req = \mvc::$req;
		if(!$req['oe_id'] || !$req['nums']) exitJson(-1,lg('参数错误'));
		$oeNumidx = new oeNumidx();
		$data = $oeNumidx->saveNumToOe($req['oe_id'], $req['nums']);
		$this->successJson($data);
	}

	/**
	 * @method 修改竞争对手价格分类
	 * @author zhengweihua 
	 * @copyright 2025-04-25
	 */
	public function setCopPriceCate()
	{
		$req = \mvc::$req;
		$oe = new oe();
		$data = $oe->setCopPriceCate(explode(',', $req['ids']), $req['cate_id']);
		$this->successJson($data);
	}
	/**
	 * @method 获取无零件的竞争对手价格
	 * @author zhengweihua 
	 * @copyright 2025-04-25
	 */
	public function getCopPriceNoOe()
	{
		$req = \mvc::$req;
		$oe = new oe();
		$data = $oe->getCopPriceNoOe();
		$this->successJson($data);
	}

	public function getBaseInfo($oe_id)
	{	
		$data = [];
		$oe = new oe();
		if($oe_id){
			$data = $oe->getDetail($oe_id);
		}
	
		$this->successJson($data);
	}

	public function getPoeModelTxt($oe_id)
	{	
		$oe = new oe();
		$data = $oe->getPoeModelTxt($oe_id);
		$this->successJson($data);
	}

	/**
	 * @method 零件同步到FGIO
	 * @author zhengweihua 
	 * @copyright 2025-08-16
	 */
	public function synFgioByOe()
	{
		$req = \mvc::$req;
		if($req['ids'])
		{
			$pro = new pro();
			$data = $pro->synFgioByOe($req['ids']);
			$this->successJson($data);
		}
	}

	/**
	 * @method 删除零件绑定的北美车型
	 * @author hongzhang
	 * @copyright 2026-04-17
	 */
	public function delNaModelData()
	{
		$req = \mvc::$req;
		$napro = new napro();
		$data = $napro->delNaModelData($req);
		$this->successJson($data);
	}

	public function setOELinkCell()
	{
		$req = \mvc::$req;
		if(!empty($req['id']) && preg_match('/^\d+$/', $req['id'])){
			$setArr = [
				$req['field']=>$req[$req['field']]
			];
			$oe = new oe();
			$oe->setOELinkCell($req['id'], $setArr);
		}
	}

}