/** * 通过日期获取表名 * * @param date $sdte 开始日期 * @param dat $edate 结束日期 * * @return array when $begindate and $enddte are not emtpy * string when has one empty of $begindate or $enddte */ public static function getTableNameByDate($begindate = '', $enddte = '') { try { if ($begindate != '' && $enddte != '') { $y = substr($enddte, 0, 4); $m = substr($enddte, 5, 2); $sdate = strtotime("{$y}-{$m}-1"); // 该月开始 $edate = strtotime("{$y}-{$m}-" . date("t", $sdate)); //该月结束 $y = substr($begindate, 0, 4); $m = substr($begindate, 5, 2); $sdate = strtotime("{$y}-{$m}-1"); // 该月开始 $begindate = date('Y-m-d', $sdate); $enddte = date('Y-m-d', $edate); $condition = "begindate >='{$begindate}' and enddate <='{$enddte}'"; } else { if ($begindate != '') { $condition = "'{$begindate}' between begindate and enddate"; } else { if ($enddte != '') { $condition = "'{$enddte}' between begindate and enddate"; } else { $condition = ''; } } } $result = StocksIndexAction::getTableNameAll($condition); //如果两个日期都不为空则,返回数组,否则返回字符串(表名) if ($begindate != '' && $enddte != '' || $begindate == '' && $enddte == '') { return $result; } else { if ($result) { return $result[0]['tablename']; } } //默认返回空 return ''; } catch (Exception $e) { throw new Exception($e); } }
/** * 电能计量装置资产定位表 * * @param string $code * @param string $goodsName * @param string $spec * @param string $madeIn * @param string $client * @return boolean/array */ public function queryLocation($code = '', $factoryNo = '', $goodsName = '', $spec = '', $madeIn = '', $client = '') { $condition = "ifnull(code,'') like '%{$code}%' and ifnull(factoryNo,'') like '%{$factoryNo}%' and \n\t\t\t\t\t ifnull(goodsName,'') like '%{$goodsName}%' and ifnull(spec,'') like '%{$spec}%' and \n\t\t\t\t\t ifnull(madeIn,'') like '%{$madeIn}%' and ifnull(client,'') like '%{$client}%' and \n\t\t\t\t\t ifnull(code,'')<>'' and code is not null "; $codelist = array(); if ($code) { $codelist = array($code); } else { $tables = StocksIndexAction::getTableNameAll(''); //如果没有找到表,则返回false if (!$tables) { return false; } $dao = new StocksDao(); for ($i = 0; $i < sizeof($tables); $i++) { $result = array(); $result = $dao->findAllDistinct($condition, $tables[$i]['tablename'], 'code')->toResultSet(); $codelist = $this->addInfo($result, $codelist); } } $locationList = array(); //查询某个条码的当前状态 for ($i = 0; $i < sizeof($codelist); $i++) { $result = $this->getStation($codelist[$i]); if ($result) { array_push($locationList, $result); } } //print_r($locationList); //表的结构 $item = array("code", "factoryNo", "goodsName", "spec", "madeIn", "location"); $label = array("code" => "条码", "factoryNo" => "出厂编号", "goodsName" => "品名", "spec" => "型号", "madeIn" => "生产厂家", "location" => "存放位置"); $columnitem = $item; $enabled = array("_type_" => "*"); $visible = array("_type_" => "*"); $align = array(); $width = array("goodsName" => 180, "madeIn" => 150); $inputtype = array(); $struct["item"] = $item; $struct["label"] = $label; $struct["columnitem"] = $columnitem; $struct["enabled"] = $enabled; $struct["visible"] = $visible; $struct["align"] = $align; $struct["width"] = $width; $struct["inputtype"] = $inputtype; //返回值 $rtn["struct"] = $struct; $rtn["data"] = $locationList; return $rtn; }