/** * 获取价格清单 */ public function getlistAction() { $fa = new Product_Model_Fa(); $bomPrice = new Product_Model_BomPrice(); $son = new Product_Model_Son(); $catalog = new Product_Model_Catalog(); $materiel = new Product_Model_Materiel(); $request = $this->getRequest()->getParams(); $limit = $request['limit']; $start = $request['start']; $faName = $fa->getName(); $priceName = $bomPrice->getName(); $mName = $materiel->getName(); $catalogName = $catalog->getName(); $db = $fa->getAdapter(); $whereSearch = "{$faName}.state != 'Obsolete'"; foreach ($request as $k => $v) { if ($v) { if ($k == 'search_key') { $whereSearch .= " and (ifnull({$faName}.remark,'') like '%{$v}%' or ifnull({$mName}.name,'') like '%{$v}%' or ifnull({$mName}.description,'') like '%{$v}%' or ifnull({$catalogName}.model_internal, '') like '%{$v}%')"; } else { if ("search_fa" == $k && $v) { $whereSearch .= " and {$faName}.code like '%{$v}%'"; } else { if ("search_archive_date_from" == $k && $v) { $whereSearch .= " and {$faName}.bom_upd_time >= '" . str_replace('T', ' ', $v) . "'"; } else { if ("search_archive_date_to" == $k && $v) { $whereSearch .= " and v.bom_upd_time <= '" . str_replace('T00:00:00', ' 23:59:59', $v) . "'"; } else { if ("search_son" == $k && $v) { $recordkey = ""; $sonData = $db->query("select group_concat(recordkey) as recordkey from oa_product_bom_son where code like '%{$v}%'")->fetchObject(); if ($sonData && $sonData->recordkey) { $recordkey = $sonData->recordkey; } if (!$recordkey) { $recordkey = "0"; } $whereSearch .= " and {$faName}.recordkey in ({$recordkey})"; } else { if ("search_recordkey" == $k && $v) { $whereSearch .= " and {$faName}.recordkey = '{$v}'"; } else { if ("explanded" == $k && $v) { $explanded = json_decode($v); } else { $col = str_replace('search_', '', $k); if ($col != $k) { // 查询条件 $whereSearch .= " and ifnull({$faName}." . $col . ",'') like '%" . $v . "%'"; } } } } } } } } } } $currencyrate = new Erp_Model_Setting_Currencyrate(); $date = date('Y-m-d'); $rateCny = $currencyrate->getRateByCode('CNY', $date); $rateUsd = $currencyrate->getRateByCode('USD', $date); $rate = round($rateCny / $rateUsd, 6); // 刷新价格 $recordkeys = $this->getRequest()->getParam('recordkeys'); if ($recordkeys) { $data = $fa->getJoinList('recordkey in (' . $recordkeys . ')'); foreach ($data as $bom) { $this->updatePrice($bom, 'single', $rate); } } $user_session = new Zend_Session_Namespace('user'); $user = $user_session->user_info['employee_id']; $sort = $this->getRequest()->getParam('sort'); if ($sort) { $sort = json_decode($sort); $sort = $sort[0]; $property = $sort->property; $direction = $sort->direction; if (in_array($property, array('code', 'ver', 'state', 'remark'))) { $order = array($faName . '.' . $property . ' ' . $direction); } else { if (in_array($property, array('low_cny', 'low_usd', 'high_cny', 'high_usd', 'average_cny', 'average_usd', 'update_time'))) { $order = array($bomPrice->getName() . '.' . $property . ' ' . $direction); } else { if (in_array($property, array('description', 'name'))) { $order = array($mName . '.' . $property . ' ' . $direction); } } } } if (isset($order)) { $order[] = $faName . '.code'; } else { $order = array($faName . '.code'); } // 获取物料数据 $cjoin = array(array('type' => LEFTJONIN, 'table' => $catalog->getName(), 'condition' => $catalog->getName() . '.id = ' . $fa->getName() . '.project_no'), array('type' => INNERJOIN, 'table' => $bomPrice->getName(), 'condition' => $bomPrice->getName() . '.recordkey = ' . $fa->getName() . '.recordkey'), array('type' => INNERJOIN, 'table' => $materiel->getName(), 'condition' => $materiel->getName() . '.id = ' . $fa->getName() . '.id')); $join = array(array('type' => LEFTJONIN, 'table' => $catalog->getName(), 'condition' => $catalog->getName() . '.id = ' . $fa->getName() . '.project_no', 'cols' => array('project_no_name' => 'model_internal')), array('type' => INNERJOIN, 'table' => $bomPrice->getName(), 'condition' => $bomPrice->getName() . '.recordkey = ' . $fa->getName() . '.recordkey', 'cols' => array("low_cny", "low_usd", 'high_cny', 'high_usd', 'average_cny', 'average_usd', 'update_time', 'noprice')), array('type' => INNERJOIN, 'table' => $materiel->getName(), 'condition' => $materiel->getName() . '.id = ' . $fa->getName() . '.id', 'cols' => array("name", "description"))); $data = $fa->getJoinList($whereSearch, $join, null, $order, $start, $limit); $totalCount = $fa->getJoinCount($whereSearch, $cjoin); $allData = array(); for ($i = 0; $i < count($data); $i++) { $data[$i]['bom_upd_time'] = strtotime($data[$i]['bom_upd_time']); $data[$i]['update_time'] = strtotime($data[$i]['update_time']); // 对于每个BOM,递归计算每个下级物料或BOM的价格 if (!$data[$i]['low_cny']) { $price = $bomPrice->calcBomPrice($data[$i]['recordkey'], 'CNY'); $data[$i]['low_cny'] = $price['low']; $data[$i]['high_cny'] = $price['high']; $data[$i]['average_cny'] = $price['average']; $data[$i]['low_usd'] = round($data[$i]['low_cny'] * $rate, 4); $data[$i]['high_usd'] = round($data[$i]['high_cny'] * $rate, 4); $data[$i]['average_usd'] = round($data[$i]['average_cny'] * $rate, 4); } $allData[] = $data[$i]; } $result = array("totalCount" => $totalCount, "topics" => $allData); // 转为json格式并输出 echo Zend_Json::encode($result); exit; }
public function getlistAction() { $request = $this->getRequest()->getParams(); $fa = new Product_Model_Fa(); $fadev = new Product_Model_Fadev(); $db = $fa->getAdapter(); if (!isset($request['left_code']) || !isset($request['left_ver']) || !isset($request['right_code']) || !isset($request['right_ver']) || !$request['left_code'] || !$request['left_ver'] || !$request['right_code'] || !$request['right_ver']) { echo Zend_Json::encode(""); exit; } $left_code = $request['left_code']; $left_ver = $request['left_ver']; $right_code = $request['right_code']; $right_ver = $request['right_ver']; $whereleft = "code='{$left_code}' and ver='{$left_ver}'"; $whereright = "code='{$right_code}' and ver='{$right_ver}'"; $left_recordkey = ""; $right_recordkey = ""; $left_type = ""; $right_type = ""; if ($fa->getJoinCount($whereleft) || $fadev->getJoinCount($whereleft)) { $left_fa = $fa->getJoinList($whereleft, array(), array('recordkey')); if ($left_fa && count($left_fa) > 0) { $left_recordkey = $left_fa[0]['recordkey']; } else { $left_fa = $fadev->getJoinList($whereleft, array(), array('recordkey')); if ($left_fa && count($left_fa) > 0) { $left_recordkey = $left_fa[count($left_fa) - 1]['recordkey']; $left_type = "dev"; } } } if ($fa->getJoinCount($whereright) || $fadev->getJoinCount($whereright)) { $right_fa = $fa->getJoinList($whereright, array(), array('recordkey')); if ($right_fa && count($right_fa) > 0) { $right_recordkey = $right_fa[0]['recordkey']; } else { $right_fa = $fadev->getJoinList($whereright, array(), array('recordkey')); if ($right_fa && count($right_fa) > 0) { $right_recordkey = $right_fa[count($right_fa) - 1]['recordkey']; $right_type = "dev"; } } } if ($left_recordkey && $right_recordkey) { if ($left_type == 'dev') { $son_left = new Product_Model_Sondev(); } else { $son_left = new Product_Model_Son(); } if ($right_type == 'dev') { $son_right = new Product_Model_Sondev(); } else { $son_right = new Product_Model_Son(); } $leftData = $son_left->getSon($left_recordkey); $rightData = $son_right->getSon($right_recordkey); if ($leftData && $rightData) { $leftCode = array(); $rightCode = array(); foreach ($rightData as $d) { $rightCode[] = $d['code']; } foreach ($leftData as $d) { $leftCode[] = $d['code']; } $result = array(); for ($i = 0; $i < count($rightData); $i++) { $data = array(); $row = $rightData[$i]; $data['code'] = $row['code']; $data['code2'] = $row['code']; $data['name'] = $row['name']; $data['description'] = $row['description']; $data['qty2'] = $row['qty']; $data['partposition2'] = $row['partposition']; $data['replace2'] = $row['replace']; $left = $this->getRowFromArrayByCode($leftData, $row['code']); $leftData = $this->removeFromArray($leftData, $row['code']); $data['code1'] = $left['code']; $data['qty1'] = $left['qty']; $data['partposition1'] = $left['partposition']; $data['replace1'] = $left['replace']; $result[] = $data; } if (count($leftData) > 0) { foreach ($leftData as $row) { $data = array(); $data['code'] = $row['code']; $data['code1'] = $row['code']; $data['name'] = $row['name']; $data['description'] = $row['description']; $data['qty1'] = $row['qty']; $data['partposition1'] = $row['partposition']; $data['replace1'] = $row['replace']; $data['code2'] = ""; $data['qty2'] = ""; $data['partposition2'] = ""; $data['replace2'] = ""; $result[] = $data; } } // 将类别数据转为json格式并输出 echo Zend_Json::encode($result); exit; } else { echo Zend_Json::encode($leftData); exit; } } $msg = "BOM不存在"; if (!$left_recordkey) { $msg = $left_code . " V" . $left_ver . "不存在"; } else { if (!$right_recordkey) { $msg = $right_code . " V" . $right_ver . "不存在"; } } echo Zend_Json::encode(array("msg" => $msg)); exit; }
public function getbomforselAction() { // 请求参数 $request = $this->getRequest()->getParams(); $limit = $request['limit']; $start = $request['start']; $key = isset($request['search_key']) ? $request['search_key'] : ''; $fa = new Product_Model_Fa(); $materiel = new Product_Model_Materiel(); $materielTable = $materiel->getName(); $product = new Product_Model_Catalog(); $productTable = $product->getName(); // 查询条件 /*$cols = array("code", "description"); $arr=preg_split('/\s+/',trim($key)); for ($i=0;$i<count($arr);$i++) { $tmp = array(); foreach($cols as $c) { $tmp[] = "ifnull($c,'')"; } $arr[$i] = "concat(".implode(',', $tmp).") like '%".$arr[$i]."%'"; }*/ $where = $fa->getName() . ".state!='Obsolete' and (" . $fa->getName() . ".code like '%{$key}%' or " . $fa->getName() . ".code like '%{$key}%')"; $join = array(array('type' => INNERJOIN, 'table' => $materielTable, 'condition' => $materielTable . '.code = ' . $fa->getName() . '.code', 'cols' => array('description')), array('type' => LEFTJONIN, 'table' => $productTable, 'condition' => $productTable . '.id = ' . $fa->getName() . '.project_no', 'cols' => array('model_internal'))); $total = $fa->getJoinCount($where, $join); $data = array(); if ($total > 0) { $data = $fa->getJoinList($where, $join, null, array($fa->getName() . '.code')); } $resutl = array('total' => $total, 'rows' => $data); echo Zend_Json::encode($resutl); exit; }