public function importAction() { $result = array('success' => true, 'info' => '导入成功'); $request = $this->getRequest()->getParams(); $type = isset($request['type']) ? $request['type'] : null; $nid = isset($request['nid']) ? $request['nid'] : ""; if (isset($_FILES['csv'])) { $now = date('Y-m-d H:i:s'); $user_session = new Zend_Session_Namespace('user'); $user_id = $user_session->user_info['user_id']; $file = $_FILES['csv']; $file_extension = strrchr($file['name'], "."); $h = new Application_Model_Helpers(); $tmp_file_name = $h->getMicrotimeStr() . $file_extension; $savepath = "../temp/"; $tmp_file_path = $savepath . $tmp_file_name; move_uploaded_file($file["tmp_name"], $tmp_file_path); $materiel = new Product_Model_Materiel(); $db = $materiel->getAdapter(); if ($type == 'dev') { $fa = new Product_Model_Fadev(); $son = new Product_Model_Sondev(); $table = "oa_product_bom_fa_dev"; } else { if ($type == 'bom') { $fa = new Product_Model_Fa(); $son = new Product_Model_Son(); $table = "oa_product_bom_fa"; } } if ($type == 'dev' || $type == 'bom') { $file = fopen($tmp_file_path, "r"); $data = array(); while (!feof($file)) { array_push($data, fgetcsv($file)); } // 数据校验 if (count($data) <= 1) { $result['success'] = false; $result['info'] = "文件中无数据!"; fclose($file); echo Zend_Json::encode($result); exit; } for ($i = 1; $i < count($data); $i++) { $num = $i + 1; $row = $data[$i]; if ($i == 1 && !$row[1]) { $result['success'] = false; $result['info'] = "请以上级物料开头:第" . $num . "行!"; fclose($file); echo Zend_Json::encode($result); exit; } if (!$row[1] && !$row[2]) { continue; } if ($row[1] && $row[2]) { $result['success'] = false; $result['info'] = "上级物料和下级物料不能同时存在:第" . $num . "行!"; fclose($file); echo Zend_Json::encode($result); exit; } if ($row[1]) { if (!$materiel->checkExist($row[1])) { $result['success'] = false; $result['info'] = "物料“" . $row[1] . "”不存在:第" . $num . "行!"; fclose($file); echo Zend_Json::encode($result); exit; } $m = $materiel->getMaterielByCode($row[1]); } if ($row[2]) { if (!$materiel->checkExist($row[2])) { $result['success'] = false; $result['info'] = "物料“" . $row[2] . "”不存在:第" . $num . "行!"; fclose($file); echo Zend_Json::encode($result); exit; } } if ($row[2] && $row[7]) { $replace = explode(',', $row[7]); foreach ($replace as $r) { $r = iconv('utf-8', 'gbk//IGNORE', $r); if (!$materiel->checkExist($r)) { $result['success'] = false; $result['info'] = "物料“" . $r . "”不存在:第" . $i . "行!"; fclose($file); echo Zend_Json::encode($result); exit; } } } if ($i > 1 && $row[1] && $data[$i - 1][1]) { $result['success'] = false; $result['info'] = "BOM“" . $data[$i - 1][1] . "”不存在子物料:第{$i行!}"; fclose($file); echo Zend_Json::encode($result); exit; } } // 只取一次最大值,可能遇到重号 $maxkeys = $fa->getAdapter()->query("select ifnull(max(recordkey),0) as maxkey from {$table}")->fetchObject(); $recordkey = $maxkeys->maxkey; $pid = ""; $faArr = array(); $sonArr = array(); $obsoleteWhere = "1=0"; // 校验成功,开始保存数据 for ($i = 1; $i < count($data); $i++) { $row = $data[$i]; if ($row[1]) { $m = $materiel->getMaterielByCode($row[1]); $recordkey++; $pid = $m['id']; $faData = array('nid' => $nid, 'recordkey' => $recordkey, 'id' => $m['id'], 'code' => $row[1], 'qty' => 1, 'state' => $row[3] ? $row[3] : 'EBOM', 'ver' => $row[4] ? $row[4] : '1.0'); if ($faData['ver'] > '1.0') { $obsoleteWhere .= " or (code='" . $row[1] . "' and ver < '" . $faData['ver'] . "')"; } // 检查是否已经存在 if ($type == 'dev') { $list = $fa->getFaList("nid = {$nid} and ver = '" . $faData['ver'] . "' and id = " . $m['id']); } else { $list = $fa->getFaList("ver = '" . $faData['ver'] . "' and id = " . $m['id']); } if ($list && count($list) > 0) { $result['success'] = false; $result['info'] = "数据已存在:" . $faData['code'] . " " . $faData['ver'] . "!"; fclose($file); echo Zend_Json::encode($result); exit; } $faArr[] = $faData; } if ($row[2]) { $m = $materiel->getMaterielByCode($row[2]); $sonData = array('nid' => $nid, 'recordkey' => $recordkey, 'pid' => $pid, 'id' => $m['id'], 'code' => $row[2], 'qty' => $row[5] ? $row[5] : 1, 'partposition' => $row[6] ? $row[6] : '', 'replace' => $row[7] ? $row[7] : '', 'remark' => $row[8] ? $row[8] : ''); // 检查是否已经存在 if ($type == 'dev') { $list = $son->getList("nid = {$nid} and id = " . $m['id']); } else { $list = $son->getList("recordkey = {$recordkey} and id = " . $m['id']); } if ($list && count($list) > 0) { $result['success'] = false; $result['info'] = "数据已存在:" . $sonData['code'] . "!"; fclose($file); echo Zend_Json::encode($result); exit; } $sonArr[] = $sonData; } } $db->beginTransaction(); try { foreach ($faArr as $faData) { $fa->insert($faData); } foreach ($sonArr as $sonData) { $son->insert($sonData); } // 旧版作废 if ($type == 'bom') { $bosoleteData = array("state" => "Obsolete"); $fa->update($bosoleteData, $obsoleteWhere); } $db->commit(); //执行commit } catch (Exception $e) { $db->rollBack(); //如果出现错误,执行回滚操作 $result['result'] = false; $result['info'] = $e->getMessage(); fclose($file); echo Zend_Json::encode($result); exit; } fclose($file); } } echo Zend_Json::encode($result); exit; }
public function importitemsAction() { $result = array('success' => true, 'data' => array(), 'info' => '导入成功'); if (isset($_FILES['csv'])) { $file = $_FILES['csv']; $file_extension = strrchr($file['name'], "."); $h = new Application_Model_Helpers(); $tmp_file_name = $h->getMicrotimeStr() . $file_extension; $savepath = "../temp/"; $tmp_file_path = $savepath . $tmp_file_name; move_uploaded_file($file["tmp_name"], $tmp_file_path); $file = fopen($tmp_file_path, "r"); $i = 0; $materiel = new Product_Model_Materiel(); $desc = new Product_Model_Desc(); while (!feof($file)) { $csv_data = fgetcsv($file); $code = isset($csv_data[1]) ? $csv_data[1] : ''; $qty = isset($csv_data[2]) ? $csv_data[2] : 0; $date_req = isset($csv_data[3]) ? str_replace('-', '/', $csv_data[3]) : ''; $project_info = isset($csv_data[4]) ? $csv_data[4] : ''; $order_req_num = isset($csv_data[5]) ? $csv_data[5] : ''; $customer_address = isset($csv_data[6]) ? $csv_data[6] : ''; $customer_aggrement = isset($csv_data[7]) ? $csv_data[7] : ''; $remark = isset($csv_data[8]) ? $csv_data[8] : ''; if ($i > 0 && $code != '') { $materielData = $materiel->getOptionList($code); $is_changing = false; if ($code != '') { $is_changing = $desc->isChanging($code); } if (count($materielData) > 0) { array_push($result['data'], array('code' => $code, 'is_changing' => $is_changing, 'name' => $materielData['name'], 'description' => $materielData['description'], 'unit' => $materielData['unit'], 'qty' => $qty, 'date_req' => $date_req, 'project_info' => mb_convert_encoding($project_info, 'UTF-8', 'GBK'), 'order_req_num' => $order_req_num, 'customer_address' => $customer_address, 'customer_aggrement' => $customer_aggrement, 'remark' => mb_convert_encoding($remark, 'UTF-8', 'GBK'))); } else { $result['success'] = 0; $result['info'] = $code . '未找到,导入失败!'; echo Zend_Json::encode($result); exit; } } $i++; } fclose($file); } else { $result['success'] = false; $result['info'] = '没有选择文件,导入失败!'; } //echo '<pre>';print_r($result);die; echo Zend_Json::encode($result); exit; }
/** * @abstract 审核 * @return null */ public function reviewAction() { // 返回值数组 $result = array('success' => true, 'result' => true, 'info' => '审批成功'); $request = $this->getRequest()->getParams(); $now = date('Y-m-d H:i:s'); $user_session = new Zend_Session_Namespace('user'); $user = $user_session->user_info['employee_id']; $val = (object) $request; $materiel = new Product_Model_Materiel(); $record = new Dcc_Model_Record(); $review = new Dcc_Model_Review(); $employee = new Hra_Model_Employee(); $desc = new Product_Model_Desc(); $id = $val->id; $remark = $val->remark1; $pass = $val->review_result; $publish = false; if (isset($val->ids) && $val->ids && strpos($val->ids, ',') !== false) { // 多个 $ids = explode(',', $val->ids); } else { $ids = array($id); } foreach ($ids as $id) { // 获取物料信息 $materielData = $desc->getOne($id); if (!$materielData) { $result['result'] = false; $result['info'] = "数据状态已改变"; echo Zend_Json::encode($result); exit; } $review_id = $materielData->review_id; // 获取当前审核情况 // 如果record记录被删除或状态已改变,报错 $reviewWhere = "id = {$review_id}"; $reviewRows = $review->getList($reviewWhere, "materiel_desc"); if (count($reviewRows) == 0) { $result['result'] = false; $result['info'] = "非法数据"; echo Zend_Json::encode($result); exit; } $reviewRow = $reviewRows[0]; if ($reviewRow['finish_flg'] != 0) { $result['result'] = false; $result['info'] = "数据状态已改变"; echo Zend_Json::encode($result); exit; } // 处理记录 $recordData = array("type" => "materiel_desc", "table_name" => "oa_product_materiel_desc", "table_id" => $id, "handle_user" => $user, "handle_time" => $now, "action" => "审批", "result" => $pass == 1 ? "批准" : ($pass == 2 ? "拒绝" : "转审"), "ip" => $_SERVER['REMOTE_ADDR'], "remark" => $remark); // 增加记录 $record->insert($recordData); // 通过方式 $method = $reviewRow['method']; if ($pass == 1) { if ($method == 2) { // 任何一人处理即通过 $finish_flg = 1; $actual_user = $user; $finish_time = $now; } else { // 所有人都需要审核,检查是否所有人都已经审核 $plan_user = $reviewRow['plan_user']; $actual_user = $reviewRow['actual_user']; $actual_user = !$actual_user ? $user : $actual_user . "," . $user; // 检查计划审核人和实际审核人是否一致 $planA = explode(',', $plan_user); $actualA = explode(',', $actual_user); $passFlg = true; foreach ($planA as $u) { if ($u && !in_array($u, $actualA)) { $passFlg = false; } } if ($passFlg) { $finish_flg = 1; $finish_time = $now; } else { $finish_flg = 0; $finish_time = null; } } // 审核情况 $reviewData = array("actual_user" => $actual_user, "finish_time" => $finish_time, "finish_flg" => $finish_flg); } else { if ($pass == 3) { // 转审 $finish_flg = 0; if ($method == 2) { // 处理方式为任意时,一个人转审之后其他人员也删除 $plan_user = str_replace('E', '', $val->transfer_id); } else { // 更改审核情况中的审核人 $plan_users = explode(',', $reviewRow['plan_user']); for ($i = 0; $i < count($plan_users); $i++) { if ($plan_users[$i] == $user) { $plan_users[$i] = str_replace('E', '', $val->transfer_id); break; } } $plan_user = implode(',', $plan_users); } // 审核情况 $reviewData = array("plan_user" => $plan_user, "method" => 1); } else { // 退回 $actual_user = null; $finish_time = null; $finish_flg = 0; // 退回选项 $return = $reviewRow['return']; if ($return == 2) { // 退到初始状态 // 需更新的审核记录: 所有 $reviewWhere = "type = 'materiel_desc' and file_id = {$id}"; // 审核情况更新数据 $reviewData = array("actual_user" => $actual_user, "finish_time" => $finish_time, "finish_flg" => $finish_flg); // 文件状态不更新 } else { if ($return == 4) { // 退到本阶段开始 // 需更新的审核记录 $reviewWhere = "type = 'materiel_desc' and finish_flg = 0 and file_id = {$id}"; // 审核情况更新数据 $reviewData = array("actual_user" => $actual_user, "finish_time" => $finish_time, "finish_flg" => $finish_flg); // 文件状态不更新 } else { if ($return == 3) { // 退到上一阶段 // 需更新的审核记录:最后一个finish_flg为1的数据和第一个finish_flg为0的数据 $last_1 = $first_0 = 0; foreach ($reviewRows as $r) { if ($r['finish_flg'] == 1) { $last_1 = $r['id']; } if ($r['finish_flg'] == 0 && $first_0 == null) { $first_0 = $r['id']; } } $reviewWhere = "id = {$last_1} or id = {$first_0}"; // 审核情况更新数据 $reviewData = array("actual_user" => $actual_user, "finish_time" => $finish_time, "finish_flg" => $finish_flg); // 文件状态不更新 } else { $fileWhere = "id = {$id}"; // 更新文件状态为退回 $mData = array("state" => "Return"); // 退到初始状态 // 更新所有record的finish_flg为0 $reviewWhere = "type = 'materiel_desc' and file_id = {$id}"; // 审核情况 $reviewData = array("actual_user" => $actual_user, "finish_time" => $finish_time, "finish_flg" => $finish_flg); } } } } } // 如果所有record的记录的finish_flg 都为1,则发布 if ($finish_flg == 1 && $review->fetchAll("type = 'materiel_desc' and finish_flg = 0 and file_id = {$id}")->count() == 1) { $publish = true; // 修改物料信息 $descData = array('ver' => $materielData->ver_after, 'name' => $materielData->name_after, 'description' => $materielData->desc_after, 'manufacturers' => $materielData->manufacturers_after, 'supply1' => $materielData->supply1_after, 'supply2' => $materielData->supply2_after, 'data_file_id' => $materielData->data_file_id_after, 'tsr_id' => $materielData->tsr_id_after, 'first_report_id' => $materielData->first_report_id_after); $descWhere = "id = " . $materielData->mid; $mData = array("state" => "Active", "archive_time" => $now); $fileWhere = "id = {$id}"; } try { // 更新审核情况 $review->update($reviewData, $reviewWhere); // 更新文件 if (isset($fileWhere)) { $desc->update($mData, $fileWhere); } if (isset($descWhere)) { $materiel->update($descData, $descWhere); } $this->operate("物料变更评审"); } catch (Exception $e) { $result['result'] = false; $result['info'] = $e->getMessage(); echo Zend_Json::encode($result); exit; } // 邮件任务 // 文件提交者或更新人 $owner = $materielData['create_user']; $dev = false; $type = "物料变更申请(物料代码:" . $materielData['code'] . ")"; // 发邮件的情况: // 1、单站审核结束 $finish_flg = 1 && $publish = false if ($finish_flg == 1 && !$publish) { $subject = $type . "审批"; // $to = 下一站审核人 $current = $review->getFirstNoReview("materiel_desc", $id); $to = $employee->getInfosByOneLine($current['plan_user']); // $cc = $employee->getInfosByOneLine($owner); $cc = $cc['email']; $content = "你有一个" . $type . "需要审批,请登录系统查看详情!"; } // 2、所有审核结束 $publish = true if ($publish) { $subject = $type . "发布"; $to = $employee->getInfosByOneLine($owner); $cc = $employee->getInfosByOneLine($record->getEmployeeIds($materielData['id'], 'materiel_desc')); $cc = $cc['email']; // $cc = ""; $detail = "物料代码:" . $materielData['code']; if ($materielData['name_before'] != $materielData['name_after']) { if ($detail) { $detail .= '<br>'; } $detail .= "名称:" . $materielData['name_before'] . " → " . $materielData['name_after']; } if ($materielData['desc_before'] != $materielData['desc_after']) { if ($detail) { $detail .= '<br>'; } $detail .= "描述:" . $materielData['desc_before'] . " → " . $materielData['desc_after']; } if ($materielData['supply1_before'] != $materielData['supply1_after']) { if ($detail) { $detail .= '<br>'; } $detail .= "供应商1:" . $materielData['supply1_code_before'] . $materielData['supply1_cname_before'] . " → " . $materielData['supply1_code_after'] . $materielData['supply1_cname_after']; } if ($materielData['supply2_before'] != $materielData['supply2_after']) { if ($detail) { $detail .= '<br>'; } $detail .= "供应商2:" . $materielData['supply2_code_before'] . $materielData['supply2_cname_before'] . " → " . $materielData['supply2_code_after'] . $materielData['supply2_cname_after']; } if ($materielData['manufacturers_before'] != $materielData['manufacturers_after']) { if ($detail) { $detail .= '<br>'; } $detail .= "制造商:" . $materielData['manufacturers_before'] . " → " . $materielData['manufacturers_after']; } $content = "你申请的" . $type . "已通过审批,物料信息已自动变更,请登录系统查看详情!<br>变更详情:<br>{$detail}"; } // 3、退回 isset($return) if (isset($return)) { $subject = $type . "退回"; $to = $employee->getInfosByOneLine($owner); $cc = ""; // 原审核人 if ($reviewRow['plan_user']) { $orgUser = $reviewRow['plan_user']; $cc = $employee->getInfosByOneLine($orgUser); $cc = $cc['email']; } $content = "你申请的" . $type . "已被退回,请登录系统查看详情!"; } // 4、转审 $pass == 3 if ($pass == 3) { $subject = $type . "转审"; $toUser = str_replace('E', '', $val->transfer_id); $to = $employee->getInfosByOneLine($toUser); // 原审核人 if ($reviewRow['plan_user']) { $orgUser = $reviewRow['plan_user']; $owner .= "," . $orgUser; } $cc = $employee->getInfosByOneLine($owner); $cc = $cc['email']; $content = "有新的" . $type . "被转移到你处审批,请登录系统查看详情!"; } if (isset($subject)) { $mailData = array('type' => $type, 'subject' => $subject, 'to' => $to['email'], 'cc' => $cc, 'content' => $content, 'send_time' => $now, 'add_date' => $now); $mail = new Application_Model_Log_Mail(); try { $mailId = $mail->insert($mailData); } catch (Exception $e) { $result['result'] = false; $result['info'] = $e->getMessage(); echo Zend_Json::encode($result); exit; } if ($mailId) { $mail->send($mailId); } } } echo Zend_Json::encode($result); exit; }
public function getcodelistAction() { $data = array(); $code = new Product_Model_Materiel(); echo Zend_Json::encode($code->getOptionList()); exit; }
public function importAction() { $result = array('success' => true, 'info' => '导入成功'); $request = $this->getRequest()->getParams(); $now = date('Y-m-d H:i:s'); if (isset($_FILES['csv'])) { $now = date('Y-m-d H:i:s'); $user_session = new Zend_Session_Namespace('user'); $user_id = $user_session->user_info['user_id']; $file = $_FILES['csv']; $file_extension = strrchr($file['name'], "."); $h = new Application_Model_Helpers(); $tmp_file_name = $h->getMicrotimeStr() . $file_extension; $savepath = "../temp/"; $tmp_file_path = $savepath . $tmp_file_name; move_uploaded_file($file["tmp_name"], $tmp_file_path); $materiel = new Product_Model_Materiel(); $supply = new Product_Model_Bpartner(); $db = $materiel->getAdapter(); $file = fopen($tmp_file_path, "r"); $data = array(); while (!feof($file)) { array_push($data, fgetcsv($file)); } // 数据校验 if (count($data) <= 1) { $result['success'] = false; $result['info'] = "文件中无数据!"; fclose($file); echo Zend_Json::encode($result); exit; } // 文件格式 # 物料号 MPQ MOQ LT 供应商1 供应商2 备注 $errorCode = array(); $okData = array(); for ($i = 1; $i < count($data); $i++) { $num = $i + 1; $row = $data[$i]; if (count($row) < 2 || !$row[1]) { continue; } for ($k = 0; $k < count($row); $k++) { $row[$k] = str_replace("\"", "", $row[$k]); } // check materiel code if ($materiel->checkExist($row[1])) { // data $code = $row[1]; $supply1Id = $supply2Id = ''; $mpq = $moq = $lt = 0; $manufacturers = $remark = ''; if (isset($row[2]) && $row[2] && is_numeric($row[2])) { $mpq = $row[2]; } if (isset($row[3]) && $row[3] && is_numeric($row[3])) { $moq = $row[3]; } if (isset($row[4]) && $row[4] && is_numeric($row[4])) { $lt = $row[4]; } // supply $supply1 = isset($row[5]) ? $row[5] : 0; $supply2 = isset($row[6]) ? $row[6] : 0; // check supply exists if ($supply1) { $supply1 = iconv('GBK', 'UTF-8', $supply1); $where = "code = '{$supply1}' or cname like '{$supply1}' or ename like '{$supply1}' or concat(code, cname) like '{$supply1}' or concat(code, ename) like '{$supply1}'"; $supply1Data = $supply->getJoinList($where, array(), array('id')); if (count($supply1Data) > 0) { $supply1Id = $supply1Data[0]['id']; } } if ($supply2) { $supply2 = iconv('GBK', 'UTF-8', $supply2); $where = "code = '{$supply2}' or cname like '{$supply2}' or ename like '{$supply2}' or concat(code, cname) like '{$supply2}' or concat(code, ename) like '{$supply2}'"; $supply2Data = $supply->getJoinList($where, array(), array('id')); if (count($supply2Data) > 0) { $supply2Id = $supply2Data[0]['id']; } } $manufacturers = isset($row[7]) ? iconv('GBK', 'UTF-8', $row[7]) : ''; $remark = isset($row[8]) ? iconv('GBK', 'UTF-8', $row[8]) : ''; $profile = array('mpq' => $mpq, 'moq' => $moq, 'tod' => $lt, 'supply1' => $supply1Id, 'supply2' => $supply2Id, 'manufacturers' => $manufacturers, 'remark' => $remark); $where = "code = '{$code}'"; try { $materiel->update($profile, $where); } catch (Exception $e) { $errorCode[] = $code; } $okData[] = $row; } else { $errorCode[] = $row[1]; } } if (count($errorCode) > 0) { $result['error'] = $errorCode; } fclose($file); } echo Zend_Json::encode($result); exit; }
/** * * @abstract 添加、删除、修改类别 * @return null */ public function editAction() { // 返回值数组 $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 = $user_session->user_info['employee_id']; $json = json_decode($request['json']); $updated = $json->updated; $inserted = $json->inserted; $deleted = $json->deleted; $type = new Product_Model_Type(); if (count($updated) > 0) { foreach ($updated as $val) { // 检查code是否重复 if ($type->fetchAll("id != " . $val->id . " and parent_id = '" . $val->parent_id . "' and code = '" . $val->code . "'")->count() > 0) { $result['result'] = false; $result['info'] = "代码“" . $val->code . "”已经存在"; echo Zend_Json::encode($result); exit; } $data = array('code' => $val->code, 'parent_id' => $val->parent_id, 'name' => $val->name, 'description' => $val->description, 'remark' => $val->remark, 'active' => $val->active, 'sn_length' => $val->sn_length, 'auto' => $val->auto, 'bom' => $val->bom, 'new_flow_id' => $val->new_flow_id, 'upd_flow_id' => $val->upd_flow_id, 'del_flow_id' => $val->del_flow_id, 'example' => $val->example, 'datafile_flg' => $val->datafile_flg, 'tsr_flg' => $val->tsr_flg, 'checkreport_flg' => $val->checkreport_flg, 'update_time' => $now, 'update_user' => $user); $where = "id = " . $val->id; try { $type->update($data, $where); } catch (Exception $e) { $result['result'] = false; $result['info'] = $e->getMessage(); echo Zend_Json::encode($result); exit; } } } if (count($inserted) > 0) { foreach ($inserted as $val) { // 检查code是否重复 if ($type->fetchAll(" parent_id = '" . $val->parent_id . "' and code = '" . $val->code . "'")->count() > 0) { $result['result'] = false; $result['info'] = "代码“" . $val->code . "”已经存在"; echo Zend_Json::encode($result); exit; } $data = array('code' => $val->code, 'parent_id' => $val->parent_id, 'name' => $val->name, 'description' => $val->description, 'remark' => $val->remark, 'active' => $val->active, 'sn_length' => $val->sn_length, 'auto' => $val->auto, 'bom' => $val->bom, 'new_flow_id' => $val->new_flow_id, 'upd_flow_id' => $val->upd_flow_id, 'del_flow_id' => $val->del_flow_id, 'example' => $val->example, 'datafile_flg' => $val->datafile_flg, 'tsr_flg' => $val->tsr_flg, 'checkreport_flg' => $val->checkreport_flg, 'create_time' => $now, 'create_user' => $user, 'update_time' => $now, 'update_user' => $user); try { $type->insert($data); } catch (Exception $e) { $result['result'] = false; $result['info'] = $e->getMessage(); echo Zend_Json::encode($result); exit; } } } if (count($deleted) > 0) { foreach ($deleted as $val) { $materiel = new Product_Model_Materiel(); if ($materiel->fetchAll("type = " . $val->id)->count() == 0) { try { $type->deleteTreeData($val->id); } catch (Exception $e) { $result['result'] = false; $result['info'] = $e->getMessage(); echo Zend_Json::encode($result); exit; } } else { $result['result'] = false; $result['info'] = '类别ID' . $val->id . '已使用,不能删除'; echo Zend_Json::encode($result); exit; } } } 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; }
/** * @abstract 删除 * @return null */ public function removeAction() { // 返回值数组 $result = array('success' => true, 'result' => true, 'info' => '删除成功'); $request = $this->getRequest()->getParams(); $now = date('Y-m-d H:i:s'); $user_session = new Zend_Session_Namespace('user'); $user = $user_session->user_info['employee_id']; $json = json_decode($request['json']); $deleted = $json->deleted; $materiel = new Product_Model_Materiel(); $record = new Dcc_Model_Record(); $review = new Dcc_Model_Review(); if (count($deleted) > 0) { foreach ($deleted as $val) { $id = $val->id; // 操作记录 $data = array('type' => "materiel", 'table_name' => "oa_product_materiel", 'table_id' => $id, 'handle_user' => $user, 'handle_time' => $now, 'action' => "删除", 'ip' => $_SERVER['REMOTE_ADDR']); try { // 增加record记录 $record->insert($data); // 删除review记录 $review->delete("type = 'materiel' and file_id = {$id}"); // 更新物料状态 $materiel->update(array('state' => 'Deleted'), "id = {$id}"); } catch (Exception $e) { $result['result'] = false; $result['info'] = $e->getMessage(); echo Zend_Json::encode($result); exit; } } } echo Zend_Json::encode($result); exit; }
/** * @abstract 取得物料信息 * @return 物料代码+物料代码 */ public function getmaterielAction() { $result = $this->getRequest()->getParams(); $materiel = new Product_Model_Materiel(); if (isset($result['q']) && $result['q']) { $query = $result['q']; $where = "code like '%{$query}%' or name like '%{$query}%' or description like '%{$query}%'"; } else { $where = "1=1"; } $data = $materiel->getListBySel($where, 0, 50); $result = array(); for ($i = 0; $i < count($data); $i++) { $result[$i] = array(); $result[$i]['code'] = $data[$i]['code']; $result[$i]['name'] = $data[$i]['name']; $result[$i]['description'] = $data[$i]['description']; $result[$i]['state'] = $data[$i]['state']; /*if(($typeId = $data[$i]['type']) != '') { $typeName = $this->getTypeByConnect($typeId, ''); $result[$i]['type_name'] = $typeName; }*/ } // 转为json格式并输出 echo Zend_Json::encode($result); exit; }
public function importitemsAction() { $result = array('success' => true, 'data' => array(), 'info' => '导入成功'); $request = $this->getRequest()->getParams(); $type = isset($request['type']) ? $request['type'] : null; if ($type && isset($_FILES['csv'])) { $file = $_FILES['csv']; $file_extension = strrchr($file['name'], "."); $h = new Application_Model_Helpers(); $tmp_file_name = $h->getMicrotimeStr() . $file_extension; $savepath = "../temp/"; $tmp_file_path = $savepath . $tmp_file_name; move_uploaded_file($file["tmp_name"], $tmp_file_path); $file = fopen($tmp_file_path, "r"); $i = 0; $materiel = new Product_Model_Materiel(); $stock = new Erp_Model_Stock_Stock(); while (!feof($file)) { $csv_data = fgetcsv($file); $code = isset($csv_data[1]) ? $csv_data[1] : ''; $qty = isset($csv_data[2]) ? $csv_data[2] : 0; $warehouse_code = 0; $warehouse_code_transfer = 0; if ($type == 'in') { $warehouse_code = isset($csv_data[4]) ? $csv_data[4] : ''; } else { if ($type == 'out') { $warehouse_code = isset($csv_data[3]) ? $csv_data[3] : ''; } else { if ($type == 'transfer') { $warehouse_code = isset($csv_data[3]) ? $csv_data[3] : ''; $warehouse_code_transfer = isset($csv_data[4]) ? $csv_data[4] : ''; } } } $remark = isset($csv_data[5]) ? $csv_data[5] : ''; if ($i > 0 && $code != '') { $materielData = $materiel->getOptionList($code); if (count($materielData) > 0) { // 获取仓位剩余库存 $warehouse = array(); array_push($warehouse, $warehouse_code); $warehouse_qty = $stock->getStockQty($code, $warehouse); array_push($result['data'], array('code' => $code, 'name' => $materielData['name'], 'description' => $materielData['description'], 'unit' => $materielData['unit'], 'qty' => $qty, 'warehouse_qty' => $warehouse_qty['total'], 'warehouse_code' => $warehouse_code, 'warehouse_code_transfer' => $warehouse_code_transfer, 'remark' => $remark)); } else { echo Zend_Json::encode(array('success' => false, 'info' => '物料号 [' . $code . '] 错误,导入失败!')); exit; } } $i++; } fclose($file); } else { $result['success'] = false; $result['info'] = '没有选择文件,导入失败!'; } /* echo '<pre>'; print_r($result); exit; */ echo Zend_Json::encode($result); exit; }
/** * @abstract 保存 * @return null */ public function saveAction() { // 返回值数组 $result = array('success' => true, 'result' => true, 'info' => '提交成功'); $request = $this->getRequest()->getParams(); $now = date('Y-m-d H:i:s'); $user_session = new Zend_Session_Namespace('user'); $user = $user_session->user_info['employee_id']; $user_name = $user_session->user_info['user_name']; $val = (object) $request; $materiel = new Product_Model_Materiel(); $record = new Dcc_Model_Record(); $review = new Dcc_Model_Review(); $employee = new Hra_Model_Employee(); $mail = new Application_Model_Log_Mail(); $member = new Admin_Model_Member(); $fadev = new Product_Model_Fadev(); $faModel = new Product_Model_Fa(); $sondev = new Product_Model_Sondev(); $flow = new Admin_Model_Flow(); $step = new Admin_Model_Step(); $db = $fadev->getAdapter(); $type = $val->upd_type; if ($type == 'new') { $bomModel = new Product_Model_Newbom(); } else { $bomModel = new Product_Model_Updbom(); } // 检查BOM信息是否完整 if (!isset($val->id) || !$val->id) { $result['result'] = false; $result['info'] = "BOM信息不完整,请重新编辑"; echo Zend_Json::encode($result); exit; } $id = $val->id; $ismanager = ""; if (isset($val->ismanager) && $val->ismanager == '1') { $ismanager = "1"; $managerState = $val->state; } // BOM完整:存在上级物料和下级物料,每个上级物料都有下级物料,替代料都存在 $bomFinishFlg = true; $facount = 0; $faData = $fadev->fetchAll("type = '{$type}' and nid = " . $id)->toArray(); if (count($faData) > 0) { $files = new Dcc_Model_Files(); foreach ($faData as $farow) { if ($farow['bom_file']) { $fileArr = explode(',', $farow['bom_file']); foreach ($fileArr as $filecode) { if ($files->fetchAll("code='{$filecode}' and state ='Active'")->count() == 0) { $result['result'] = false; $result['info'] = "BOM " . $farow['code'] . "的关联文件:“<b>" . $filecode . "</b>”不存在!"; echo Zend_Json::encode($result); exit; } } } } } $sonData = $sondev->fetchAll("nid = " . $id)->toArray(); if (count($faData) > 0 && count($sonData) > 0) { foreach ($sonData as $son) { if ($son['replace'] == "") { continue; } $replace = explode(',', $son['replace']); foreach ($replace as $r) { if ($materiel->fetchAll("code='{$r}'")->count() == 0) { $result['result'] = false; $result['info'] = "物料" . $son['code'] . "的替代料:<b>" . $r . "</b>不存在!"; echo Zend_Json::encode($result); exit; } } } foreach ($faData as $fa) { foreach ($sonData as $son) { if ($fa['recordkey'] == $son['recordkey']) { $facount++; break; } } } if ($facount != count($faData)) { $bomFinishFlg = false; } } else { $bomFinishFlg = false; } if (!$bomFinishFlg) { $result['result'] = false; $result['info'] = "BOM信息不完整,请重新编辑"; echo Zend_Json::encode($result); exit; } // 下级BOM未归档 $materielType = new Product_Model_Type(); $bomArr = array(); foreach ($faData as $fa) { if ($type == 'new') { // 检查上级bom是否已经存在,或者正在申请 $join = array(array('type' => INNERJOIN, 'table' => $bomModel->getName(), 'condition' => $fadev->getName() . '.nid = ' . $bomModel->getName() . '.id')); $jwhere = $fadev->getName() . ".code = '" . $fa['code'] . "' and (" . $bomModel->getName() . ".state = 'Active' or " . $bomModel->getName() . ".state = 'Reviewing')"; if ($fadev->getJoinCount($jwhere, $join)) { $result['result'] = false; $result['info'] = "BOM“" . $fa['code'] . "”已存在或正在申请"; echo Zend_Json::encode($result); exit; } // 检查bom的状态,不能是作废或者删除 $bomMateriel = $materiel->getMaterielByCode($fa['code']); if (!$bomMateriel) { $result['result'] = false; $result['info'] = "物料“" . $fa['code'] . "”不存在"; echo Zend_Json::encode($result); exit; } if ($bomMateriel['state'] == 'Obsolete' || $bomMateriel['state'] == 'Deleted') { $result['result'] = false; $result['info'] = "物料“" . $fa['code'] . "”已作废"; echo Zend_Json::encode($result); exit; } } // 检查下级bom是否归档 foreach ($sonData as $son) { if (isset($bomArr[$son['id']]) && $bomArr[$son['id']]) { $isbom = true; } else { if (isset($bomArr[$son['id']]) && !$bomArr[$son['id']]) { $isbom = false; } else { $d = $materiel->fetchRow('id = ' . $son['id']); $d = $materielType->fetchRow('id = ' . $d['type']); $bomArr[$son['id']] = $d['bom']; $isbom = false; } } if ($isbom) { if ($faModel->fetchAll("id = '" . $son['id'] . "'")->count() == 0) { $result['result'] = false; $result['info'] = "子BOM“" . $son['code'] . "”未归档"; echo Zend_Json::encode($result); exit; } } } } // 根据BOM获取审批流 $flow_id = ""; if (isset($val->review_flow)) { $flow_id = $val->review_flow; $flowRow = $db->query("select t1.* from oa_admin_flow t1 where t1.id='{$flow_id}'")->fetchObject(); } if (!$flow_id) { $flowRow = $db->query("select t1.* from oa_admin_flow t1 inner join oa_product_bom_config t2 on t1.flow_name=t2.flow where t2.type='{$type}'")->fetchObject(); if ($flowRow) { $flow_id = $flowRow->id; } } if (!$flow_id) { $result['result'] = false; $result['info'] = "还没有配置BOM审核流程,请联系管理员配置"; echo Zend_Json::encode($result); exit; } // 根据流程ID获取阶段 $step_ids = $flowRow->step_ids; if ($step_ids) { $stepRows = $step->getListByFlow($step_ids); $state = "Reviewing"; } $state = "Reviewing"; if (isset($managerState) && $managerState) { $state = $managerState; } if ($type == 'new') { $data = array("description" => isset($val->description) ? $val->description : "", "state" => $state, "remark" => isset($val->remark) ? $val->remark : "", "update_time" => $now, "update_user" => $user); } else { $data = array("upd_type" => isset($val->upd_type) ? $val->upd_type : "", "replace_flg" => isset($val->replace_flg) ? 1 : 0, "description" => isset($val->description) ? $val->description : "", "upd_reason" => isset($val->upd_reason) ? $val->upd_reason : "", "reason_type" => isset($val->reason_type) ? $val->reason_type : "", "state" => $state, "remark" => isset($val->remark) ? $val->remark : "", "update_time" => $now, "update_user" => $user); } if (isset($managerState) && $managerState == 'Active') { $data['archive_time'] = $now; } try { $bomModel->update($data, "id=" . $id); // 自定义字段 $attrval = new Admin_Model_Formval(); if ($type == 'new') { $table = "oa_product_bom_new"; $recordType = "bom"; } else { if ($type == 'ECO') { $table = "oa_product_bom_eco"; $recordType = "ecobom"; } else { if ($type == 'DEV') { $table = "oa_product_bom_dev"; $recordType = "devbom"; } } } $menu = $table . '_' . $id; $attrval->delete("menu = '" . $menu . "'"); foreach ($request as $field => $value) { if (stripos($field, "intelligenceField") !== false && $value) { $attrId = str_replace("intelligenceField", "", $field); $formval = array('attrid' => $attrId, 'value' => $value, 'menu' => $menu); $attrval->insert($formval); } } $action = "申请"; if ($record->fetchAll("type='{$recordType}' and table_id={$id}")->count() > 0) { $action = "编辑"; } // 操作记录 $data = array('type' => $recordType, 'table_name' => $table, 'table_id' => $id, 'handle_user' => $user, 'handle_time' => $now, 'action' => $action, 'ip' => $_SERVER['REMOTE_ADDR']); $record->insert($data); // 管理员将状态改为审核中也会触发审批流程 if (!$ismanager || isset($managerState) && $managerState == 'Reviewing') { // 审核流程 // 把阶段信息插入review记录 // 删除已有流程 $review->delete("type='{$recordType}' and file_id = {$id}"); $first = true; foreach ($stepRows as $s) { $plan_user = $s['user']; if ($s['dept']) { $tmpUser = array(); $plan_dept = $s['dept']; foreach (explode(',', $plan_dept) as $role) { $tmpRole = $member->getMemberWithNoManager($role); foreach ($tmpRole as $m) { $tmpUser[] = $m['user_id']; } } if (count($tmpUser) > 0) { $tmpUser = $employee->getAdapter()->query("select group_concat(employee_id) as users from oa_user where active = 1 and id in ( " . implode(',', $tmpUser) . ")")->fetchObject(); $users = $tmpUser->users; } if (isset($users) && $users) { if ($plan_user) { $plan_user .= ","; } $plan_user .= $users; } } $repeatUser = explode(',', $plan_user); $repeatUser = array_unique($repeatUser); $plan_user = implode(',', $repeatUser); $reviewData = array('type' => "{$recordType}", 'file_id' => $id, 'plan_user' => $plan_user, 'method' => $s['method'], 'return' => $s['return'], 'step_name' => $s['step_name'], 'step_ename' => $s['step_ename']); $review->insert($reviewData); // 邮件任务 if ($first) { $to = $employee->getAdapter()->query("select group_concat(email) as mail_to from oa_employee where id in ( " . $plan_user . ")")->fetchObject(); $boms = array(); foreach ($faData as $fa) { if ($type == 'new') { $boms[] = $fa['code']; } else { $boms[] = $fa['code'] . " V" . $fa['ver']; } } if ($type == 'new') { $content = "你有新BOM归档申请需要审核,<p>" . "<b>BOM号:</b>" . implode(',', $boms) . "</p>" . "<p><b>描述:</b>" . $val->description . "</p>" . "<p><b>备注:</b>" . $val->remark . "</p>" . "<p><b>申请人:</b>" . $user_name . "</p>" . "<p><b>申请时间:</b>" . $now . "</p>" . "<p>请登录系统查看详情!</p>"; } else { $reson_type = ""; if ($val->reason_type) { $codemaster = new Admin_Model_Codemaster(); $mstData = $codemaster->getList("type=6 and code='" . $val->reason_type . "'"); if ($mstData && count($mstData) > 0) { $reson_type = $mstData[0]['text']; } } $content = "你有新BOM升版申请需要审核,<p>" . "<b>BOM号:</b>" . implode(',', $boms) . "</p>" . "<p><b>升版类型:</b>" . $val->upd_type . "</p>" . "<p><b>升版原因分类:</b>" . $reson_type . "</p>" . "<p><b>升版原因:</b>" . $val->upd_reason . "</p>" . "<p><b>升版描述:</b>" . $val->description . "</p>" . "<p><b>备注:</b>" . $val->remark . "</p>" . "<p><b>申请人:</b>" . $user_name . "</p>" . "<p><b>申请时间:</b>" . $now . "</p>" . "<p>请登录系统查看详情!</p>"; } $mailData = array('type' => 'BOM归档审批', 'subject' => 'BOM归档审批', 'to' => $to->mail_to, 'cc' => '', 'content' => $content, 'send_time' => $now, 'add_date' => $now); $mailId = $mail->insert($mailData); if ($mailId) { $mail->send($mailId); } } $first = false; } } else { if (isset($managerState) && $managerState == 'Active') { $bomfaData = $fadev->fetchAll("type = '{$type}' and nid=" . $id)->toArray(); // 如果是多个BOM,需要拆分 foreach ($bomfaData as $bomfa) { // 升版的情况,旧版作废 $facode = $bomfa['code']; if ($type != 'new') { $obsoleteData = array("state" => "Obsolete"); $obsoleteWhere = "code = '{$facode}'"; $faModel->update($obsoleteData, $obsoleteWhere); } $recordkey = $bomfa['recordkey']; $sql = "insert into oa_product_bom_fa (nid, recordkey, id, code, project_no, bom_file, qty, state, ver, type, remark) select nid, recordkey, id, code, project_no, bom_file, qty, 'EBOM', ver, type, remark from oa_product_bom_fa_dev where recordkey = {$recordkey}"; $db->query($sql); $sql = "insert into oa_product_bom_son (nid, recordkey, pid, id, code, qty, partposition, `replace`, remark) select nid, recordkey, pid, id, code, qty, partposition, `replace`, remark from oa_product_bom_son_dev where recordkey = {$recordkey}"; $db->query($sql); } // 更新所有record的finish_flg为0 $reviewWhere = "type = '{$recordType}' and file_id = {$id}"; // 审核情况 $reviewData = array("actual_user" => $user, "finish_time" => $now, "finish_flg" => '1'); // 更新审核情况 $review->update($reviewData, $reviewWhere); } } } catch (Exception $e) { $result['result'] = false; $result['info'] = $e->getMessage(); echo Zend_Json::encode($result); exit; } echo Zend_Json::encode($result); exit; }