/** * 获取文件编码及文件信息 */ public function getfilesbyidAction() { // 获取参数 $request = $this->getRequest()->getParams(); $id = $request['id']; $user_session = new Zend_Session_Namespace('user'); $user = $user_session->user_info['employee_id']; $myDept = $user_session->user_info['dept_id']; $nowDate = date('Y-m-d'); $files = new Dcc_Model_Files(); $record = new Dcc_Model_Record(); $upload = new Dcc_Model_Upload(); $codeModel = new Dcc_Model_Code(); $share = new Dcc_Model_Share(); $review = new Dcc_Model_Review(); $modelUser = new Application_Model_User(); $data = $files->getDataById($id); // [id, code, ver, file_id, file_name, file_path, file_view_path] $result = array(); $row0 = $data[0]; $names = explode(',', $row0['name']); $codes = explode(',', $row0['code']); $vers = explode(',', $row0['ver']); $description = explode('|', $row0['description']); $project_info = explode(',', $row0['project_info']); $final_codes = array(); $final_vers = array(); $final_names = array(); $final_descs = array(); $final_projs = array(); $k = 0; for ($i = 0; $i < count($names); $i++) { $sub_names = explode('|', $names[$i]); $final_codes[$k] = $codes[$i]; $final_vers[$k] = $vers[$i]; if (isset($description[$i]) && $description[$i]) { $final_descs[$k] = $description[$i]; } else { $final_descs[$k] = ""; } if (isset($project_info[$i]) && $project_info[$i]) { $final_projs[$k] = $project_info[$i]; } else { $final_projs[$k] = ""; } $final_names[$k] = $sub_names[0]; $k++; for ($j = 1; $j < count($sub_names); $j++) { $final_codes[$k] = $codes[$i]; $final_vers[$k] = $vers[$i]; $final_names[$k] = $sub_names[$j]; if (isset($description[$i]) && $description[$i]) { $final_descs[$k] = $description[$i]; } else { $final_descs[$k] = ""; } if (isset($project_info[$i]) && $project_info[$i]) { $final_projs[$k] = $project_info[$i]; } else { $final_projs[$k] = ""; } $k++; } } $catalog = new Product_Model_Catalog(); for ($i = 0; $i < count($data); $i++) { $paths = $this->getPathByName($data, trim($final_names[$i])); $row = $data[$i]; $result[$i]['id'] = $row['id']; $result[$i]['state'] = $row['state']; if ($final_descs[$i]) { $result[$i]['description'] = $final_descs[$i]; } else { // 获取描述 $descData = $codeModel->getJoinList("code = '{$final_codes[$i]}'", array(), array('description', 'project_no')); if (count($descData) > 0) { $result[$i]['description'] = $descData[0]['description']; if (!$final_projs[$i]) { $final_projs[$i] = $descData[0]['project_no']; } } } $result[$i]['project_no'] = $final_projs[$i]; if ($final_projs[$i]) { $projData = $catalog->getById($final_projs[$i]); if ($projData && $projData['model_internal']) { $result[$i]['project_name'] = $projData['model_internal']; } } $result[$i]['code'] = $final_codes[$i]; $result[$i]['ver'] = $final_vers[$i]; $result[$i]['file_id'] = $paths[0]; $result[$i]['file_name'] = $final_names[$i]; $result[$i]['file_path'] = $paths[1]; $result[$i]['file_view_path'] = $paths[2]; // 权限检查 // 有权限的情况:1、本人上传的文件 2、本人提交的文件评审 3、本人参与审核的文件评审 4、共享给我的 5、将要审核的审核人 6、文件管理员、BOM管理员、物料管理员 // 首先检查文件是否存在 $result[$i]['exists'] = true; if (!file_exists($paths[1])) { $result[$i]['exists'] = false; } $role = false; if ($modelUser->checkPermissionByRoleName('物料管理员') || $modelUser->checkPermissionByRoleName('文件管理员') || $modelUser->checkPermissionByRoleName('系统管理员') || $modelUser->checkPermissionByRoleName('BOM管理员')) { $role = true; } else { if ($row0['create_user'] == $user || $row0['update_user'] == $user) { $role = true; } else { if ($record->fetchAll("table_id = {$id} and handle_user = {$user} and table_name = 'oa_doc_files' and action = '审批'")->count() > 0) { $role = true; } else { if ($upload->fetchAll("id = " . $row['id'] . " and (create_user = {$user} or update_user = {$user})")->count() > 0) { $role = true; } else { if ($share->fetchAll("shared_id = " . $row['id'] . " and type = 'upload' and share_time_begin <= '{$nowDate}' and share_time_end >= '{$nowDate}' and (FIND_IN_SET({$user}, share_user) or FIND_IN_SET({$myDept}, share_dept))")->count() > 0) { $role = true; } else { if ($review->fetchAll("file_id = {$id} and FIND_IN_SET({$user}, plan_user) and type = 'files'")->count() > 0) { $role = true; } } } } } } $result[$i]['role'] = $role; } echo Zend_Json::encode($result); exit; }
public function exportcsvAction() { set_time_limit(0); $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(); $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 . "%'"; } } } } } } } } } } $rate = new Erp_Model_Setting_Currencyrate(); $date = date('Y-m-d'); $rateCny = $rate->getRateByCode('CNY', $date); $rateUsd = $rate->getRateByCode('USD', $date); $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')), array('type' => INNERJOIN, 'table' => $materiel->getName(), 'condition' => $materiel->getName() . '.id = ' . $fa->getName() . '.id', 'cols' => array("name", "description"))); $data = $fa->getJoinList($whereSearch, $join, null, $order); $allData = array(); for ($i = 0; $i < count($data); $i++) { // 对于每个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'] * ($rateCny / $rateUsd), 4); $data[$i]['high_usd'] = round($data[$i]['high_cny'] * ($rateCny / $rateUsd), 4); $data[$i]['average_usd'] = round($data[$i]['average_cny'] * ($rateCny / $rateUsd), 4); } $allData[] = $data[$i]; } print chr(0xef) . chr(0xbb) . chr(0xbf); // 获取物料数据 $data_csv = array(); $title = array('cnt' => '#', 'code' => 'BOM号', 'ver' => '版本', 'state' => '状态', 'low_cny' => '最低价格-人民币', 'high_cny' => '最高价格-人民币', 'average_cny' => '平均价格-人民币', 'low_usd' => '最低价格-美元', 'high_usd' => '最高价格-美元', 'average_usd' => '平均价格-美元', 'update_time' => '更新时间', 'name' => '物料名称', 'description' => '物料描述', 'project_no_name' => '产品型号', 'bom_upd_time' => '归档时间', 'remark' => '备注'); $title = $this->object_array($title); $date = date('YmdHsi'); $filename = 'bomprice-' . $date; $path = "../temp/" . $filename . ".csv"; $file = fopen($path, "w"); fputcsv($file, $title); array_push($data_csv, $title); $typeids = array(); $typenames = array(); $k = 0; for ($i = 0; $i < count($data); $i++) { $d = $data[$i]; $k++; $info = array('cnt' => $k, 'code' => Helper::ifNull($d, 'code'), 'ver' => "V" . $d['ver'], 'state' => Helper::ifNull($d, 'state'), 'low_cny' => Helper::ifNull($d, 'low_cny'), 'high_cny' => Helper::ifNull($d, 'high_cny'), 'average_cny' => Helper::ifNull($d, 'average_cny'), 'low_usd' => Helper::ifNull($d, 'low_usd'), 'high_usd' => Helper::ifNull($d, 'high_usd'), 'average_usd' => Helper::ifNull($d, 'average_usd'), 'update_time' => $d['update_time'], 'name' => Helper::ifNull($d, 'name'), 'description' => Helper::ifNull($d, 'description'), 'project_no_name' => Helper::ifNull($d, 'project_no_name'), 'bom_upd_time' => $d['bom_upd_time'], 'remark' => Helper::ifNull($d, 'remark')); $bomd = $this->object_array($info); fputcsv($file, $bomd); } fclose($file); $this->operate("BOM导出"); echo $filename; exit; }
public function selectAction() { $data = array(); $dataTmp = array(); $request = $this->getRequest()->getParams(); $type = isset($request['type']) ? $request['type'] : null; $key = isset($request['key']) ? $request['key'] : null; if ($type == 'catalog') { $model = new Product_Model_Catalog(); $dataTmp = $model->getCodeList($key); } else { if ($type == 'material') { $model = new Product_Model_Materiel(); $dataTmp = $model->getMaterils($key); } } for ($i = 0; $i < count($dataTmp); $i++) { if ($i < 200) { $dataTmp[$i]['type'] = $type; array_push($data, $dataTmp[$i]); } } echo Zend_Json::encode($data); exit; }
public function editmodeAction() { // 返回值数组 $result = array('success' => true, 'info' => '编辑成功'); $request = $this->getRequest()->getParams(); $now = date('Y-m-d H:i:s'); $user_session = new Zend_Session_Namespace('user'); $user_id = $user_session->user_info['user_id']; $json = json_decode($request['json']); $updated = $json->updated; $inserted = $json->inserted; $deleted = $json->deleted; $mode = new Product_Model_Mode(); if (count($updated) > 0) { foreach ($updated as $val) { $data = array('active' => $val->active, 'name' => $val->name, 'description' => $val->description, 'remark' => $val->remark, 'update_time' => $now, 'update_user' => $user_id); $where = "id = " . $val->id; try { $mode->update($data, $where); } catch (Exception $e) { $result['success'] = false; $result['info'] = $e->getMessage(); echo Zend_Json::encode($result); exit; } } } if (count($inserted) > 0) { foreach ($inserted as $val) { $data = array('active' => $val->active, 'name' => $val->name, 'description' => $val->description, 'remark' => $val->remark, 'create_time' => $now, 'create_user' => $user_id, 'update_time' => $now, 'update_user' => $user_id); try { $mode->insert($data); } catch (Exception $e) { $result['success'] = false; $result['info'] = $e->getMessage(); echo Zend_Json::encode($result); exit; } } } if (count($deleted) > 0) { $catalog = new Product_Model_Catalog(); foreach ($deleted as $val) { if ($catalog->fetchAll("mode_id = " . $val->id)->count() == 0) { try { $mode->delete("id = " . $val->id); } catch (Exception $e) { $result['success'] = false; $result['info'] = $e->getMessage(); echo Zend_Json::encode($result); exit; } } else { $result['success'] = false; $result['info'] = '开发模式ID' . $val->id . '存在关联产品信息,不能删除'; echo Zend_Json::encode($result); exit; } } } echo Zend_Json::encode($result); exit; }
/** * 取得标准产品型号 */ public function getprojectstandardAction() { $request = $this->getRequest()->getParams(); $where = "1=1"; if (isset($request['q']) && $request['q']) { $q = $request['q']; $where = "t1.model_standard like '%{$q}%'"; } $catalog = new Product_Model_Catalog(); $data = $catalog->getAdapter()->query("select t1.id, concat(t1.model_standard,'[', t2.name, ']') as name from oa_product_catalog t1 inner join oa_product_catalog_series t2 on t1.series_id = t2.id where {$where} and t1.active = 1 and t2.active=1 and t1.model_standard != '' order by t1.model_standard")->fetchAll(); echo Zend_Json::encode($data); exit; }
/** * bom dosage * @param $id * @param $name * @return string */ public function getmaterieldosageAction() { $code = $this->getRequest()->getParam('code'); $data = array(); if ($code) { $fa = new Product_Model_Fa(); $son = new Product_Model_Son(); $materiel = new Product_Model_Materiel(); $catalog = new Product_Model_Catalog(); // first step: find recordkey from bom_son $recordkeyData = $son->getJoinList("code = '{$code}'", array(), array('recordkey', 'code', 'qty', 'partposition', 'replace')); $recordkeys = $codes = $qtys = $partpositions = $replaces = array(); foreach ($recordkeyData as $r) { if (!in_array($r['recordkey'], $recordkeys)) { $recordkey = $r['recordkey']; $recordkeys[] = $recordkey; $codes[$recordkey] = $r['code']; $qtys[$recordkey] = $r['qty']; $partpositions[$recordkey] = $r['partposition']; $replaces[$recordkey] = $r['replace']; } } // second step: query bom code from bom_son with recordkey if (count($recordkeys) > 0) { $join = array(array('type' => INNERJOIN, 'table' => $materiel->getName(), 'condition' => $materiel->getName() . '.code = ' . $fa->getName() . '.code', 'cols' => array('name', 'description')), array('type' => LEFTJONIN, 'table' => $catalog->getName(), 'condition' => $catalog->getName() . '.id = ' . $fa->getName() . '.project_no', 'cols' => array('project_no_name' => 'model_internal'))); $where = $fa->getName() . ".recordkey in (" . implode(',', $recordkeys) . ") and " . $fa->getName() . ".state != 'Obsolete'"; $data = $fa->getJoinList($where, $join, array('sid', 'recordkey', 'code', 'state', 'ver', 'bom_upd_time')); for ($i = 0; $i < count($data); $i++) { $recordkey = $data[$i]['recordkey']; $data[$i]['archive_time'] = strtotime($data[$i]['bom_upd_time']); $data[$i]['qty'] = $qtys[$recordkey]; $data[$i]['partposition'] = $partpositions[$recordkey]; $data[$i]['replace'] = $replaces[$recordkey]; } } } echo Zend_Json::encode($data); exit; }