'moneyFormat', 'delivery_order_amount_d' => 'financeNum', 'delivery_receivable' => 'moneyFormat', 'delivery_receivable_d' => 'financeNum', 'total_product_weight_g' => 'weightToG', 'total_product_weight_kg' => 'weightToKG', 'cp_code' => 'strToUpper', 'order_paytime' => 'dateFormat', 'member_uname' => 'originEncrypt', ); /** * formatField * @param mixed $printRowData 数据 * @return mixed 返回值 */ public function formatField(&$printRowData) { foreach($printRowData as $k => &$val) { if(array_key_exists($k, $this->fieldFormat)) { $method = $this->fieldFormat[$k]; if(method_exists($this, $method)) { $val = $this->$method($val); } } else { //默认转换成字符串、去掉前后的空格 $val = $this->printSingleFormat($val); } } } /** * moneyFormat * @param mixed $money money * @return mixed 返回值 */ public function moneyFormat($money) { $num = number_format($money, 2, '.', ' '); return isset($num) ? $num : 0.00; } /** * financeNum * @param mixed $num num * @return mixed 返回值 */ public function financeNum($num) { $num = number_format($num, 2, '.', ''); $formatNum = kernel::single('ome_delivery_template')->financeNum($num); return isset($formatNum) ? $formatNum : ''; } /** * weightToG * @param mixed $num num * @return mixed 返回值 */ public function weightToG($num) { return $num . 'g'; } /** * weightToKG * @param mixed $num num * @return mixed 返回值 */ public function weightToKG($num) { return ($num/1000) . 'kg'; } /** * strToUpper * @param mixed $str str * @return mixed 返回值 */ public function strToUpper($str) { return strtoupper($str); } /** * dateFormat * @param mixed $time time * @return mixed 返回值 */ public function dateFormat($time) { return $time?date('Y-m-d H:i:s',$time):''; } /** * originEncrypt * @param mixed $value value * @return mixed 返回值 */ public function originEncrypt($value) { return kernel::single('ome_security_hash')->getOriginText($value); } /** * printSingleFormat * @param mixed $single single * @return mixed 返回值 */ public function printSingleFormat($single) { if($single === null) { return ''; } elseif (is_bool($single)) { return $single === false ? 'false' : 'true'; } $str = strval($single); $str = trim($str); $str = str_replace(array('"','"','"','"'),array('“','“','“'), $str); $str = str_replace(array('"','"'), array('”','”'), $str); return $str; } /** * array2xml2 * @param mixed $data 数据 * @param mixed $root root * @return mixed 返回值 */ public function array2xml2($data,$root='root'){ $xml='<'.$root.'>'; $this->_array2xml($data,$xml); $xml.=''; return $xml; } private function _array2xml(&$data,&$xml){ if(is_array($data)){ foreach($data as $k=>$v){ if(is_numeric($k)){ $xml.=''; $xml.=$this->_array2xml($v,$xml); $xml.=''; }else{ $xml.='<'.$k.'>'; $xml.=$this->_array2xml($v,$xml); $xml.=''; } } }elseif(is_numeric($data)){ $xml.=$data; }elseif(is_string($data)){ $xml.=''; } } }