Beispiel #1
0
 public function edititemsAction()
 {
     // 返回值数组
     $result = array('success' => true, 'info' => '编辑成功');
     $request = $this->getRequest()->getParams();
     $type = isset($request['operate']) ? $request['operate'] : '';
     // 操作类别
     $typeArr = array('new' => '新建', 'edit' => '修改');
     $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']);
     $invoice_id = $json->invoice_id;
     $json_items = $json->items;
     $items_updated = $json_items->updated;
     $items_inserted = $json_items->inserted;
     $items_deleted = $json_items->deleted;
     $items = new Erp_Model_Purchse_Invoiceitems();
     // 更新
     if (count($items_updated) > 0) {
         foreach ($items_updated as $val) {
             $data = array('invoice_id' => $invoice_id, 'order_id' => $val->items_order_id, 'order_date' => $val->items_order_date, 'order_item_id' => $val->items_order_item_id, 'order_number' => $val->items_order_number, 'code' => $val->items_code, 'name' => $val->items_name, 'description' => $val->items_description, 'qty' => $val->items_qty, 'unit' => $val->items_unit, 'price' => $val->items_price, 'price_tax' => $val->items_order_price_tax, 'currency' => $val->items_order_currency, 'currency_rate' => $val->items_order_currency_rate, 'tax_id' => $val->items_order_tax_id, 'tax_name' => $val->items_order_tax_name, 'tax_rate' => $val->items_order_tax_rate, 'remark' => $val->items_remark, 'update_user' => $user_id, 'update_time' => $now);
             try {
                 $data['update_user'] = $user_id;
                 $data['update_time'] = $now;
                 $items->update($data, "id = " . $val->items_id);
             } catch (Exception $e) {
                 $result['success'] = false;
                 $result['info'] = $e->getMessage();
                 echo Zend_Json::encode($result);
                 exit;
             }
         }
     }
     // 插入
     if (count($items_inserted) > 0) {
         foreach ($items_inserted as $val) {
             $data = array('invoice_id' => $invoice_id, 'order_id' => $val->items_order_id, 'order_date' => $val->items_order_date, 'order_item_id' => $val->items_order_item_id, 'order_number' => $val->items_order_number, 'code' => $val->items_code, 'name' => $val->items_name, 'description' => $val->items_description, 'qty' => $val->items_qty, 'unit' => $val->items_unit, 'price' => $val->items_price, 'price_tax' => $val->items_price_tax, 'currency' => $val->items_order_currency, 'currency_rate' => $val->items_order_currency_rate, 'tax_id' => $val->items_order_tax_id, 'tax_name' => $val->items_order_tax_name, 'tax_rate' => $val->items_order_tax_rate, 'remark' => $val->items_remark, 'create_user' => $user_id, 'create_time' => $now, 'update_user' => $user_id, 'update_time' => $now);
             try {
                 $invoice_item_id = $items->insert($data);
             } catch (Exception $e) {
                 $result['success'] = false;
                 $result['info'] = $e->getMessage();
                 echo Zend_Json::encode($result);
                 exit;
             }
         }
     }
     // 删除
     if (count($items_deleted) > 0) {
         foreach ($items_deleted as $val) {
             try {
                 $items->delete("id = " . $val->items_id);
             } catch (Exception $e) {
                 $result['success'] = false;
                 $result['info'] = $e->getMessage();
                 echo Zend_Json::encode($result);
                 exit;
             }
         }
     }
     $items->refreshInvoiceTotal($invoice_id);
     $invoice = new Erp_Model_Purchse_Invoice();
     $invoice_data = $invoice->getData(null, $invoice_id);
     // 保存成功,进入审批流程
     if ($result['success']) {
         // 根据流程ID获取阶段信息
         $flow = new Admin_Model_Flow();
         $flowData = $flow->fetchRow("id = " . $invoice_data['flow_id'])->toArray();
         // 获取审核阶段
         $step = new Admin_Model_Step();
         $stepIds = $flowData['step_ids'];
         $stepArr = explode(',', $stepIds);
         $review = new Dcc_Model_Review();
         $review->delete("type = 'purchse_invoice_add' and file_id = " . $invoice_id);
         $mailTo = null;
         $i = 0;
         $help = new Application_Model_Helpers();
         // 根据阶段信息初始化审批流程,并向第一阶段审核人发送邮件
         foreach ($stepArr as $s) {
             $stepData = $step->fetchRow("id = " . $s)->toArray();
             $step_user = $stepData['user'] != '' ? $stepData['user'] : null;
             $step_role = $stepData['dept'] != '' ? $stepData['dept'] : null;
             $employeeArr = $help->getReviewEmployee($step_user, $step_role);
             $employeeIdArr = $employeeArr['id'];
             $employeeIds = implode(',', $employeeIdArr);
             $reviewData = array('type' => 'purchse_invoice_add', 'file_id' => $invoice_id, 'step_name' => $stepData['step_name'], 'plan_user' => $employeeIds, 'plan_dept' => $step_role, 'method' => $stepData['method'], 'return' => $stepData['return']);
             $review->insert($reviewData);
             // 第一阶段发送邮件通知
             if ($i == 0) {
                 $mailTo = $employeeIdArr;
             }
             $i++;
         }
         if ($mailTo) {
             // 获取币种信息
             $currency = new Erp_Model_Setting_Currency();
             $currencyInfo = $currency->getInfoByCode($invoice_data['currency']);
             $total = $invoice_data['total'];
             if ($invoice_data['currency'] != 'CNY') {
                 $total = $invoice_data['forein_total'];
             }
             $mailContent = '<div>新建采购发票,请登录系统查看:</div>
                         <div>
                         <p><b>发票号:</b>' . $invoice_data['number'] . '</p>
                         <p><b>制单员:</b>' . $user_session->user_info['user_name'] . '</p>
                         <p><b>供应商:</b>' . $invoice_data['supplier_ename'] . '</p>
                         <p><b>金额:</b><a style="color: #467500;font-weight: bold;">' . $currencyInfo['symbol'] . $total . '</a></p>
                         <p><b>描述:</b>' . $invoice_data['description'] . '</p>
                         <p><b>备注:</b>' . $invoice_data['remark'] . '</p>
                         <p><b>申请时间:</b>' . $invoice_data['create_time'] . '</p>
                         <p><b>更新时间:</b>' . $invoice_data['update_time'] . '</p>
                         </div><hr>';
             $mailData = array('type' => '消息', 'subject' => '采购发票-' . $typeArr[$type], 'cc' => $user_session->user_info['user_email'], 'content' => $mailContent, 'add_date' => $now);
             $result = $help->sendMailToStep($mailTo, $mailData);
         }
     }
     echo Zend_Json::encode($result);
     exit;
 }
Beispiel #2
0
 /**
  * @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'];
     $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();
     $desc = new Product_Model_Desc();
     if (isset($val->mid) && $val->mid) {
         $mid = $val->mid;
         $md = $materiel->fetchRow("id = {$mid}");
     } else {
         $result['result'] = false;
         $result['info'] = "数据加载失败";
         echo Zend_Json::encode($result);
         exit;
     }
     // 根据物料类别获取审批流
     $typeId = $md->type;
     $stepRows = array();
     if ($typeId) {
         $type = new Product_Model_Type();
         // 获取当前物料类别对应的流程ID 如果找不到,继续往上搜索
         $flow_id = $type->getFlowId($typeId, 'upd');
         if ($flow_id) {
             // 根据流程ID获取阶段
             $flow = new Admin_Model_Flow();
             $step = new Admin_Model_Step();
             $flowRow = $flow->getRow($flow_id);
             $step_ids = $flowRow['step_ids'];
             if ($step_ids) {
                 $stepRows = $step->getListByFlow($step_ids);
                 $state = "Reviewing";
             }
         }
     }
     // 新增还是编辑
     if (isset($val->id) && $val->id) {
         $result['info'] = '修改成功';
         $data = array('mid' => $mid, 'code' => $md->code, 'state' => 'Reviewing', 'type_before' => $md->type, 'type_after' => $md->type, 'desc_before' => $md->description, 'desc_after' => $val->desc_after, 'supply1_before' => $md->supply1, 'supply1_after' => $val->supply1_after, 'supply2_before' => $md->supply2, 'supply2_after' => $val->supply2_after, 'manufacturers_before' => $md->manufacturers, 'manufacturers_after' => $val->manufacturers_after, 'data_file_id_before' => $md->data_file_id, 'data_file_id_after' => $val->data_file_id_after, 'tsr_id_before' => $md->tsr_id, 'tsr_id_after' => $val->tsr_id_after, 'first_report_id_before' => $md->first_report_id, 'first_report_id_after' => $val->first_report_id_after, 'name_before' => $md->name, 'name_after' => $val->name_after, 'remark' => $val->remark, 'create_user' => $user, 'create_time' => $now);
         $id = $val->id;
         $where = "id = " . $id;
         try {
             if ($id) {
                 $desc->update($data, $where);
                 // 操作记录
                 $data = array('type' => "materiel_desc", 'table_name' => "oa_product_materiel_desc", 'table_id' => $id, 'handle_user' => $user, 'handle_time' => $now, 'action' => "编辑", 'ip' => $_SERVER['REMOTE_ADDR']);
                 $record->insert($data);
                 // 审核流程
                 // 删除已存在的审核记录
                 $review->delete("type = 'materiel_desc' and file_id = " . $id);
                 // 把阶段信息插入review记录
                 $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 && !$plan_user) {
                             $tmpUser = $member->getUserids("系统管理员");
                         }
                         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 ($users) {
                             if ($plan_user) {
                                 $plan_user .= ",";
                             }
                             $plan_user .= $users;
                         }
                     }
                     $repeatUser = explode(',', $plan_user);
                     $repeatUser = array_unique($repeatUser);
                     $plan_user = implode(',', $repeatUser);
                     $reviewData = array('type' => "materiel_desc", '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);
                 }
             }
         } catch (Exception $e) {
             $result['result'] = false;
             $result['info'] = $e->getMessage();
             echo Zend_Json::encode($result);
             exit;
         }
         echo Zend_Json::encode($result);
         exit;
     } else {
         $data = array('mid' => $mid, 'code' => $md->code, 'state' => 'Reviewing', 'ver_before' => $md->ver, 'ver_after' => $md->ver + 0.1, 'type_before' => $md->type, 'type_after' => $md->type, 'desc_before' => $md->description, 'desc_after' => $val->desc_after, 'supply1_before' => $md->supply1, 'supply1_after' => $val->supply1_after, 'supply2_before' => $md->supply2, 'supply2_after' => $val->supply2_after, 'manufacturers_before' => $md->manufacturers, 'manufacturers_after' => $val->manufacturers_after, 'data_file_id_before' => $md->data_file_id, 'data_file_id_after' => $val->data_file_id_after, 'tsr_id_before' => $md->tsr_id, 'tsr_id_after' => $val->tsr_id_after, 'first_report_id_before' => $md->first_report_id, 'first_report_id_after' => $val->first_report_id_after, 'name_before' => $md->name, 'name_after' => $val->name_after, 'remark' => $val->remark, 'create_user' => $user, 'create_time' => $now);
         try {
             $id = $desc->insert($data);
             if ($id) {
                 // 操作记录
                 $data = array('type' => "materiel_desc", 'table_name' => "oa_product_materiel_desc", 'table_id' => $id, 'handle_user' => $user, 'handle_time' => $now, 'action' => "申请", 'ip' => $_SERVER['REMOTE_ADDR']);
                 $record->insert($data);
                 // 审核流程
                 // 把阶段信息插入review记录
                 $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 && !$plan_user) {
                             $tmpUser = $member->getUserids("系统管理员");
                         }
                         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 ($users) {
                             if ($plan_user) {
                                 $plan_user .= ",";
                             }
                             $plan_user .= $users;
                         }
                     }
                     $repeatUser = explode(',', $plan_user);
                     $repeatUser = array_unique($repeatUser);
                     $plan_user = implode(',', $repeatUser);
                     $reviewData = array('type' => "materiel_desc", '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();
                         $mailData = array('type' => '物料号变更审批', 'subject' => '物料号变更审批', 'to' => $to->mail_to, 'cc' => '', 'content' => '你有新物料号变更申请(物料代码:' . $md["code"] . ')需要审核,请登录系统查看详情', 'send_time' => $now, 'add_date' => $now);
                         $mailId = $mail->insert($mailData);
                         if ($mailId) {
                             $mail->send($mailId);
                         }
                     }
                     $first = false;
                 }
             }
         } catch (Exception $e) {
             $result['result'] = false;
             $result['info'] = $e->getMessage();
             echo Zend_Json::encode($result);
             exit;
         }
         echo Zend_Json::encode($result);
         exit;
     }
 }
Beispiel #3
0
    /**
     * 保存采购申请表体
     */
    public function edititemsAction()
    {
        // 返回值数组
        $result = array('success' => true, 'info' => '编辑成功');
        $request = $this->getRequest()->getParams();
        $type = isset($request['operate']) ? $request['operate'] : '';
        // 操作类别
        $typeArr = array('new' => '新建', 'edit' => '修改', 'transfer' => '变更');
        $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']);
        $order_id = $json->order_id;
        $transfer_id = $json->transfer_id;
        $order_id = $json->order_id;
        $json_items = $json->items;
        $items_updated = $json_items->updated;
        $items_inserted = $json_items->inserted;
        $items_deleted = $json_items->deleted;
        $items = new Erp_Model_Purchse_Orderitems();
        $itemsreq = new Erp_Model_Purchse_Orderitemsreq();
        $transfer_items = new Erp_Model_Purchse_Transferorderitems();
        // 更新
        if (count($items_updated) > 0) {
            foreach ($items_updated as $val) {
                $active = $val->items_active ? 1 : 0;
                $total = round($val->items_qty * $val->items_price, 4);
                $data = array('active' => $active, 'req_number' => $val->items_req_number, 'code' => $val->items_code, 'name' => $val->items_name, 'description' => $val->items_description, 'supplier_code' => $val->items_supplier_code, 'supplier_codename' => $val->items_supplier_codename, 'supplier_description' => $val->items_supplier_description, 'qty' => $val->items_qty, 'unit' => $val->items_unit, 'price' => $val->items_price, 'total' => $total, 'warehouse_code' => $val->items_warehouse_code, 'request_date' => $val->items_request_date, 'dept_id' => $val->items_dept_id, 'project_info' => $val->items_project_info, 'remark' => $val->items_remark);
                try {
                    if ($type == 'transfer') {
                        $data['req_item_id'] = $val->items_req_item_id;
                        $data['order_id'] = $order_id;
                        $data['transfer_id'] = $transfer_id;
                        $data['order_item_id'] = $val->items_id;
                        $data['transfer_type'] = 'update';
                        $transfer_items->insert($data);
                    } else {
                        $data['update_user'] = $user_id;
                        $data['update_time'] = $now;
                        $items->update($data, "id = " . $val->items_id);
                        // 保存分拆订单项信息
                        $this->saveSplitItem('update', $val->items_id, $val->items_req_item_id, $val->items_qty, $val->items_code, $active);
                    }
                } catch (Exception $e) {
                    $result['success'] = false;
                    $result['info'] = $e->getMessage();
                    echo Zend_Json::encode($result);
                    exit;
                }
            }
        }
        // 插入
        if (count($items_inserted) > 0) {
            foreach ($items_inserted as $val) {
                $active = $val->items_active ? 1 : 0;
                $total = round($val->items_qty * $val->items_price, 4);
                $data = array('order_id' => $order_id, 'active' => $active, 'req_number' => $val->items_req_number, 'code' => $val->items_code, 'name' => $val->items_name, 'description' => $val->items_description, 'supplier_code' => $val->items_supplier_code, 'supplier_codename' => $val->items_supplier_codename, 'supplier_description' => $val->items_supplier_description, 'qty' => $val->items_qty, 'unit' => $val->items_unit, 'price' => $val->items_price, 'total' => $total, 'warehouse_code' => $val->items_warehouse_code, 'request_date' => $val->items_request_date, 'dept_id' => $val->items_dept_id, 'project_info' => $val->items_project_info, 'remark' => $val->items_remark);
                try {
                    if ($type == 'transfer') {
                        $data['transfer_id'] = $transfer_id;
                        $data['order_item_id'] = $val->items_id;
                        $data['req_item_id'] = $val->items_req_item_id;
                        $data['req_qty'] = $val->items_req_qty;
                        $data['transfer_type'] = 'add';
                        $transfer_items->insert($data);
                    } else {
                        $data['create_user'] = $user_id;
                        $data['create_time'] = $now;
                        $data['update_user'] = $user_id;
                        $data['update_time'] = $now;
                        $order_item_id = $items->insert($data);
                        $this->saveSplitItem('insert', $order_item_id, $val->items_req_item_id, $val->items_req_qty, $val->items_code);
                    }
                } catch (Exception $e) {
                    $result['success'] = false;
                    $result['info'] = $e->getMessage();
                    echo Zend_Json::encode($result);
                    exit;
                }
            }
        }
        // 删除
        if (count($items_deleted) > 0) {
            foreach ($items_deleted as $val) {
                try {
                    if ($type == 'transfer') {
                        $active = $val->items_active ? 1 : 0;
                        $line_total = round($val->items_qty * $val->items_price, 4);
                        $data = array('active' => $active, 'transfer_type' => 'delete', 'transfer_id' => $transfer_id, 'order_item_id' => $val->items_id, 'req_number' => $val->items_req_number, 'code' => $val->items_code, 'name' => $val->items_name, 'description' => $val->items_description, 'supplier_code' => $val->items_supplier_code, 'supplier_codename' => $val->items_supplier_codename, 'supplier_description' => $val->items_supplier_description, 'qty' => $val->items_qty, 'unit' => $val->items_unit, 'price' => $val->items_price, 'total' => $total, 'warehouse_code' => $val->items_warehouse_code, 'request_date' => $val->items_request_date, 'dept_id' => $val->items_dept_id, 'project_info' => $val->items_project_info, 'remark' => $val->items_remark);
                        $transfer_items->insert($data);
                    } else {
                        $items->delete("id = " . $val->items_id);
                        // 清除订单项对应的申请项数据
                        $itemsreq->delete("order_item_id = " . $val->items_id);
                        $this->saveSplitItem('delete', $val->items_id, $val->items_req_item_id, $val->items_req_qty, $val->items_code);
                    }
                } catch (Exception $e) {
                    $result['success'] = false;
                    $result['info'] = $e->getMessage();
                    echo Zend_Json::encode($result);
                    exit;
                }
            }
        }
        // 更新订单项状态
        $activeItemsRes = $items->fetchAll("active = 1 and order_id = " . $order_id);
        if ($activeItemsRes->count() > 0) {
            $activeItems = $activeItemsRes->toArray();
            for ($j = 0; $j < count($activeItems); $j++) {
                $itemsreq->update(array('active' => 1), "order_item_id = " . $activeItems[$j]['id']);
            }
        }
        // 更新采购申请总计
        if ($type != 'transfer') {
            $items->refreshOrderTotal($order_id);
        }
        $order = new Erp_Model_Purchse_Order();
        $order_data = $order->getData(null, $order_id);
        // 保存成功,进入审批流程
        if ($result['success']) {
            // 根据流程ID获取阶段信息
            $flow = new Admin_Model_Flow();
            $flowData = $flow->fetchRow("id = " . $order_data['order_flow_id'])->toArray();
            // 获取审核阶段
            $step = new Admin_Model_Step();
            $stepIds = $flowData['step_ids'];
            $stepArr = explode(',', $stepIds);
            $review = new Dcc_Model_Review();
            $review->delete("type = 'purchse_order_add' and file_id = " . $order_id);
            $mailTo = null;
            $i = 0;
            $help = new Application_Model_Helpers();
            // 根据阶段信息初始化审批流程,并向第一阶段审核人发送邮件
            foreach ($stepArr as $s) {
                $stepData = $step->fetchRow("id = " . $s)->toArray();
                $step_user = $stepData['user'] != '' ? $stepData['user'] : null;
                $step_role = $stepData['dept'] != '' ? $stepData['dept'] : null;
                $employeeArr = $help->getReviewEmployee($step_user, $step_role);
                $employeeIdArr = $employeeArr['id'];
                $employeeIds = implode(',', $employeeIdArr);
                $reviewData = array('type' => 'purchse_order_add', 'file_id' => $order_id, 'step_name' => $stepData['step_name'], 'plan_user' => $employeeIds, 'plan_dept' => $step_role, 'method' => $stepData['method'], 'return' => $stepData['return']);
                $review->insert($reviewData);
                // 第一阶段发送邮件通知
                if ($i == 0) {
                    $mailTo = $employeeIdArr;
                }
                $i++;
            }
            if ($mailTo) {
                // 获取币种信息
                $currency = new Erp_Model_Setting_Currency();
                $currencyInfo = $currency->getInfoByCode($order_data['currency']);
                $total = $order_data['total'];
                if ($order_data['currency_rate'] != 1) {
                    $total = $order_data['forein_total'];
                }
                $mailContent = '<div>新建采购订单,请登录系统查看:</div>
                            <div>
                            <p><b>订单号:</b>' . $order_data['number'] . '</p>
                            <p><b>采购员:</b>' . $user_session->user_info['user_name'] . '</p>
                            <p><b>类别:</b>' . $order_data['type'] . '</p>
                            <p><b>金额:</b><a style="color: #467500;font-weight: bold;">' . $currencyInfo['symbol'] . $total . '</a></p>
                            <p><b>描述:</b>' . $order_data['description'] . '</p>
                            <p><b>备注:</b>' . $order_data['remark'] . '</p>
                            <p><b>申请时间:</b>' . $order_data['create_time'] . '</p>
                            <p><b>更新时间:</b>' . $order_data['update_time'] . '</p>
                            </div><hr>';
                $transferContent = '';
                if ($type == 'transfer') {
                    $transferContent .= '<div><style type="text/css">
table.gridtable {
	font-family: verdana,arial,sans-serif;
	font-size:12px;
	color:#333333;
	border-width: 1px;
	border-color: #666666;
	border-collapse: collapse;
}
table.gridtable th {
	border-width: 1px;
	padding: 8px;
	border-style: solid;
	border-color: #666666;
	background-color: #dedede;
}
table.gridtable td {
	border-width: 1px;
	padding: 8px;
	border-style: solid;
	border-color: #666666;
	background-color: #ffffff;
}
.delete{
	text-decoration: line-through;
	color: #FF0000;
}
.update{
	font-weight: bold;
	color: #000093;
}
.inactive{
	font-weight: bold;
	color: #999999;
}
</style><table class="gridtable">
                			<tr>
                			<th>#</th>
                			<th>操作类别</th>
                			<th>启用</th>
                			<th>物料号</th>
                			<th>名称</th>
                			<th>描述</th>
                			<th>数量</th>
                			<th>已收货</th>
                			<th>需求日期</th>
                			<th>项目信息</th>
                			<th>备注</th>
                			</tr>';
                    $i = 1;
                    foreach ($items_inserted as $val) {
                        $active = $val->items_active ? '是' : '否';
                        $transferContent .= '<tr>
                			<td>' . $i . '</td>
                			<td>新增</td>
                			<td>' . $active . '</td>
                			<td>' . $val->items_code . '</td>
                			<td>' . $val->items_name . '</td>
                			<td>' . $val->items_description . '</td>
                			<td>' . $val->items_qty . '</td>
                			<td>0</td>
                			<td>' . date('Y-m-d', strtotime($val->items_request_date)) . '</td>
                			<td>' . $val->items_project_info . '</td>
                			<td>' . $val->items_remark . '</td>
                			</tr>';
                        $i++;
                    }
                    foreach ($items_updated as $val) {
                        $tr = '<tr>';
                        if (!$val->items_active) {
                            $tr = '<tr class="inactive">';
                        } else {
                            $tr = '<tr class="update">';
                        }
                        $active = $val->items_active ? '是' : '否';
                        $transferContent .= $tr . '
                			<td>' . $i . '</td>
                			<td>更新</td>
                			<td>' . $active . '</td>
                			<td>' . $val->items_code . '</td>
                			<td>' . $val->items_name . '</td>
                			<td>' . $val->items_description . '</td>
                			<td>' . $val->items_qty . '</td>
                			<td>' . $val->items_qty_receive . '</td>
                			<td>' . $val->items_request_date . '</td>
                			<td>' . $val->items_project_info . '</td>
                			<td>' . $val->items_remark . '</td>
                			</tr>';
                        $i++;
                    }
                    foreach ($items_deleted as $val) {
                        $active = $val->items_active ? '是' : '否';
                        $transferContent .= '<tr class="delete">
                			<td>' . $i . '</td>
                			<td>删除</td>
                			<td>' . $active . '</td>
                			<td>' . $val->items_code . '</td>
                			<td>' . $val->items_name . '</td>
                			<td>' . $val->items_description . '</td>
                			<td>' . $val->items_qty . '</td>
                			<td>0</td>
                			<td>' . $val->items_request_date . '</td>
                			<td>' . $val->items_project_info . '</td>
                			<td>' . $val->items_remark . '</td>
                			</tr>';
                        $i++;
                    }
                    $transferContent .= '</table></div>';
                }
                $mailData = array('type' => '消息', 'subject' => '采购订单-' . $typeArr[$type], 'cc' => $user_session->user_info['user_email'], 'content' => $mailContent . $transferContent, 'add_date' => $now);
                if ($transferContent != '') {
                    $transfer = new Erp_Model_Purchse_Transfer();
                    $transfer->update(array('transfer_content' => $transferContent), "id = " . $transfer_id);
                }
                $result = $help->sendMailToStep($mailTo, $mailData);
            }
        }
        echo Zend_Json::encode($result);
        exit;
    }
Beispiel #4
0
    public function editAction()
    {
        $result = array('success' => true, 'info' => '');
        $request = $this->getRequest()->getParams();
        $data = isset($request['data']) ? Zend_Json::decode($request['data']) : null;
        //echo '<pre>';print_r($data);exit;
        if ($data) {
            $priceModel = new Erp_Model_Sale_Price();
            $priceItemsModel = new Erp_Model_Sale_Priceitems();
            $priceLadderModel = new Erp_Model_Sale_Priceitemladder();
            $partnerModel = new Erp_Model_Partner();
            $price_id = $data['id'];
            $now = date('Y-m-d H:i:s');
            $user_session = new Zend_Session_Namespace('user');
            $user_id = $user_session->user_info['user_id'];
            $taxData = $partnerModel->getTaxInfo($data['customer_id']);
            //echo '<pre>';print_r(Zend_Json::decode($data['items']['inserted'][1]['items_ladder']));exit;
            $priceData = array('price_date' => $data['price_date'], 'customer_id' => $data['customer_id'], 'currency' => $data['currency'], 'price_tax' => $data['price_tax'], 'tax_id' => $taxData['id'], 'description' => $data['description'], 'remark' => $data['remark'], 'update_user' => $user_id, 'update_time' => $now);
            if ($data['operate'] == 'new') {
                $priceData['number'] = $priceModel->getNewNum();
                $priceData['create_user'] = $user_id;
                $priceData['create_time'] = $now;
                try {
                    $price_id = $priceModel->insert($priceData);
                } catch (Exception $e) {
                    $result['success'] = false;
                    $result['info'] = $e->getMessage();
                    echo Zend_Json::encode($result);
                    exit;
                }
            } else {
                $priceData['state'] = 0;
                $priceData['update_user'] = $user_id;
                $priceData['update_time'] = $now;
                try {
                    $priceModel->update($priceData, "id = " . $price_id);
                } catch (Exception $e) {
                    $result['success'] = false;
                    $result['info'] = $e->getMessage();
                    echo Zend_Json::encode($result);
                    exit;
                }
            }
            if ($result['success']) {
                // 插入
                foreach ($data['items']['inserted'] as $item) {
                    $insertData = array('customer_id' => $data['customer_id'], 'type' => $item['items_type'], 'currency' => $data['currency'], 'price_id' => $price_id, 'active_date' => $item['items_active_date'], 'code' => $item['items_code'], 'price_start' => $item['items_price_start'], 'price_final' => $item['items_price_final'], 'remark' => $item['items_remark'], 'customer_code' => $item['items_customer_code'], 'customer_description' => $item['items_customer_description'], 'name' => $item['items_name'], 'description' => $item['items_description'], 'product_type' => $item['items_product_type'], 'product_series' => $item['items_product_series'], 'remark' => $item['items_remark']);
                    try {
                        $item_id = $priceItemsModel->insert($insertData);
                    } catch (Exception $e) {
                        $result['success'] = false;
                        $result['info'] = $e->getMessage();
                        echo Zend_Json::encode($result);
                        exit;
                    }
                    if ($result['success'] && $item['items_ladder'] != '') {
                        $ladderData = Zend_Json::decode($item['items_ladder']);
                        foreach ($ladderData as $ld) {
                            $ld['item_id'] = $item_id;
                            $priceLadderModel->insert($ld);
                        }
                    }
                }
                // 表体处理
                if ($data['operate'] == 'edit') {
                    foreach ($data['items']['updated'] as $item) {
                        $updateData = array('type' => $item['items_type'], 'currency' => $data['currency'], 'active_date' => $item['items_active_date'], 'code' => $item['items_code'], 'name' => $item['items_name'], 'description' => $item['items_description'], 'customer_code' => $item['items_customer_code'], 'customer_description' => $item['items_customer_description'], 'price_start' => $item['items_price_start'], 'price_final' => $item['items_price_final'], 'product_type' => $item['items_product_type'], 'product_series' => $item['items_product_series'], 'remark' => $item['items_remark']);
                        try {
                            $priceItemsModel->update($updateData, "id = " . $item['items_id']);
                        } catch (Exception $e) {
                            $result['success'] = false;
                            $result['info'] = $e->getMessage();
                            echo Zend_Json::encode($result);
                            exit;
                        }
                        $item_id = $item['items_id'];
                        if ($result['success'] && $item['items_ladder'] != '') {
                            $priceLadderModel->delete("item_id = " . $item_id);
                            $ladderData = Zend_Json::decode($item['items_ladder']);
                            foreach ($ladderData as $ld) {
                                $ld['item_id'] = $item_id;
                                $priceLadderModel->insert($ld);
                            }
                        }
                    }
                    foreach ($data['items']['deleted'] as $item) {
                        try {
                            $priceItemsModel->delete("id = " . $item['items_id']);
                        } catch (Exception $e) {
                            $result['success'] = false;
                            $result['info'] = $e->getMessage();
                            echo Zend_Json::encode($result);
                            exit;
                        }
                        if ($result['success'] && $item['ladder'] != '') {
                            $priceLadderModel->delete("item_id = " . $item_id);
                        }
                    }
                }
                // 进入审核流程
                $flow = new Admin_Model_Flow();
                $flowData = $flow->fetchRow("flow_name = '销售价格清单审核'")->toArray();
                // 获取审核阶段
                $step = new Admin_Model_Step();
                $stepIds = $flowData['step_ids'];
                $stepArr = explode(',', $stepIds);
                $review = new Dcc_Model_Review();
                $review->delete("type = 'sale_price_add' and file_id = " . $price_id);
                $mailTo = null;
                $i = 0;
                $help = new Application_Model_Helpers();
                // 根据阶段信息初始化审批流程,并向第一阶段审核人发送邮件
                foreach ($stepArr as $s) {
                    $stepData = $step->fetchRow("id = " . $s)->toArray();
                    $step_user = $stepData['user'] != '' ? $stepData['user'] : null;
                    $step_role = $stepData['dept'] != '' ? $stepData['dept'] : null;
                    $employeeArr = $help->getReviewEmployee($step_user, $step_role);
                    $employeeIdArr = $employeeArr['id'];
                    $employeeIds = implode(',', $employeeIdArr);
                    $reviewData = array('type' => 'sale_price_add', 'file_id' => $price_id, 'step_name' => $stepData['step_name'], 'plan_user' => $employeeIds, 'plan_dept' => $step_role, 'method' => $stepData['method'], 'return' => $stepData['return']);
                    $review->insert($reviewData);
                    // 第一阶段发送邮件通知
                    if ($i == 0) {
                        $mailTo = $employeeIdArr;
                    }
                    $i++;
                }
                // 邮件通知
                if ($mailTo) {
                    $customerInfo = $partnerModel->getInfoById($data['customer_id']);
                    $customerName = $customerInfo['cname'] ? $customerInfo['cname'] : $customerInfo['ename'];
                    $priceData = $priceModel->getData(null, $price_id);
                    $mailContent = '<div>销售价格申请,请登录系统查看:</div>
                            <div>
                            <p><b>申请单号:</b>' . $priceData['number'] . '</p>
                            <p><b>客户代码:</b>' . $customerInfo['code'] . '</p>
                            <p><b>客户名称:</b>' . $customerName . '</p>
                            <p><b>申请人:</b>' . $user_session->user_info['user_name'] . '</p>
                            <p><b>描述:</b>' . $data['description'] . '</p>
                            <p><b>备注:</b>' . $data['remark'] . '</p>
                            <p><b>提交时间:</b>' . $now . '</p>
                            </div><hr>';
                    $itemsContent = '<div><style type="text/css">
table.gridtable {
    font-family: verdana,arial,sans-serif;
    font-size:12px;
    color:#333333;
    border-width: 1px;
    border-color: #666666;
    border-collapse: collapse;
}
table.gridtable th {
    border-width: 1px;
    padding: 8px;
    border-style: solid;
    border-color: #666666;
    background-color: #dedede;
}
table.gridtable td {
    border-width: 1px;
    padding: 8px;
    border-style: solid;
    border-color: #666666;
    background-color: #ffffff;
}
.delete{
    text-decoration: line-through;
    color: #FF0000;
}
.update{
    font-weight: bold;
    color: #000093;
}
.inactive{
    font-weight: bold;
    color: #999999;
}
</style><table class="gridtable">
                            <tr>
                            <th>#</th>
                            <th>类别</th>
                            <th>物料号/内部型号</th>
                            <th>名称</th>
                            <th>产品类别</th>
                            <th>产品系列</th>
                            <th>描述</th>
                            <th>客户产品名称</th>
                            <th>客户产品描述</th>
                            <th>初始价格</th>
                            <th>最终价格</th>
                            <th>生效日期</th>
                            <th>备注</th>
                            </tr>';
                    $itemsData = $priceItemsModel->getItems($price_id);
                    $i = 0;
                    foreach ($itemsData as $item) {
                        $i++;
                        $itemType = $item['items_type'] == 'catalog' ? '内部型号' : '物料号';
                        $itemsContent .= '<tr>
                            <td>' . $i . '</td>
                            <td>' . $itemType . '</td>
                            <td>' . $item['items_code'] . '</td>
                            <td>' . $item['items_name'] . '</td>
                            <td>' . $item['items_product_type'] . '</td>
                            <td>' . $item['items_product_series'] . '</td>
                            <td>' . $item['items_description'] . '</td>
                            <td>' . $item['items_customer_code'] . '</td>
                            <td>' . $item['items_customer_description'] . '</td>
                            <td>' . $item['items_price_start'] . '</td>
                            <td>' . $item['items_price_final'] . '</td>
                            <td>' . $item['items_active_date'] . '</td>
                            <td>' . $item['items_remark'] . '</td>
                            </tr>';
                    }
                    $itemsContent .= '</table></div>';
                    $mailData = array('type' => '消息', 'subject' => '销售价格清单申请', 'cc' => $user_session->user_info['user_email'], 'content' => $mailContent . $itemsContent, 'add_date' => $now);
                    $result = $help->sendMailToStep($mailTo, $mailData);
                }
            }
        } else {
            $result['success'] = false;
            $result['info'] = '参数错误';
        }
        echo Zend_Json::encode($result);
        exit;
    }
 public function overtimeAction()
 {
     // 返回值数组
     $result = array('success' => true, 'info' => '提交成功');
     // 请求参数
     $request = $this->getRequest()->getParams();
     // 操作类型
     $operate = array('new' => '新建', 'edit' => '编辑', 'delete' => '删除');
     // 操作类别(新建、更新、删除)
     $operate_type = isset($request['operate']) ? $request['operate'] : '';
     $overtime = new Hra_Model_Attendance_Overtime();
     if ($operate_type == 'new_hra' || $operate_type == 'new' || $operate_type == 'edit') {
         $time_from = str_replace('T', ' ', $request['time_from']);
         $time_to = str_replace('T', ' ', $request['time_to']);
         if (date('Y-m', strtotime($time_from)) != date('Y-m', strtotime($time_to))) {
             $result['success'] = false;
             $request['info'] = '不允许跨月申请,请重新填写时间!';
             echo Zend_Json::encode($result);
             exit;
         }
         // 获取加班人员的用工形式(0:弹性,1:非弹性)
         $user = new Application_Model_User();
         $userInfo = $user->getEmployeeInfoById($request['apply_user']);
         $userType = $userInfo['employment_type'];
         $workday = new Hra_Model_Workday();
         // 获取请假区间包含的工作日天数
         $overtimeInfo = $workday->getOvertimeQtyByTimeRange($userType, $request['time_from'], $request['time_to']);
         $overtimeQty = $overtimeInfo['qty'];
         $overtimeQty_hours = $overtimeInfo['qty_hours'];
         /* echo $overtimeQty;
            exit; */
         // 加班类别按起始日期获取
         $overtimeType = $workday->getWorkdayType($userType, date('Y-m-d', strtotime($request['time_from'])));
         if ($overtimeType == 0) {
             $result['success'] = false;
             $request['info'] = '工作日设置错误,请检查工作日设置!';
             echo Zend_Json::encode($result);
             exit;
         }
         // 当编辑请假申请时,检查时间是否重叠需要过滤当前加班申请ID
         $filter_id = null;
         if ($operate_type == 'edit') {
             $filter_id = $request['id'];
         }
         // 检查加班时间范围是否正确
         if ($overtimeQty > 0) {
             // 检查加班时间范围是否跟已有申请(包括已审核和审核中的申请)重叠
             if ($overtime->checkTimeOverlap($request['apply_user'], $request['time_from'], $request['time_to'], $filter_id)) {
                 $result['success'] = false;
                 $result['info'] = '时间设置错误,加班时间重叠,请优先处理未审申请。';
             } else {
                 $now = date('Y-m-d H:i:s');
                 $user_session = new Zend_Session_Namespace('user');
                 $user_id = $user_session->user_info['user_id'];
                 // 当前申请为代申请时,获取申请人真实部门主管
                 if ($request['apply_user'] != $user_id) {
                     // 获取部门主管
                     $manager = $user->getManagerUser($request['apply_user']);
                     $request['review_user_1'] = $manager[0]['id'];
                 }
                 if ($request['review_user_1'] >= 0) {
                     $data = array('type' => $overtimeType, 'apply_user' => $request['apply_user'], 'review_user_1' => $request['review_user_1'], 'time_from' => $request['time_from'], 'time_to' => $request['time_to'], 'qty' => $overtimeQty, 'qty_hours' => $overtimeQty_hours, 'reason' => $request['reason'], 'remark' => $request['remark'], 'update_time' => $now, 'update_user' => $user_id);
                     /* echo '<pre>';
                        print_r($data);
                        exit; */
                     if ($operate_type == 'new_hra') {
                         // HRA手动添加
                         $data['state'] = 3;
                         $data['create_time'] = $now;
                         $data['create_user'] = $user_id;
                         $data['review_info'] = $now . ': ' . $user_session->user_info['user_name'] . ' [手动添加]';
                         try {
                             $overtime_id = $overtime->insert($data);
                             echo Zend_Json::encode($result);
                             exit;
                         } catch (Exception $e) {
                             $result['success'] = false;
                             $result['info'] = $e->getMessage();
                         }
                     } else {
                         if ($operate_type == 'new') {
                             $data['create_time'] = $now;
                             $data['create_user'] = $user_id;
                             $data['review_info'] = $now . ': ' . $user_session->user_info['user_name'] . ' [新建]';
                             try {
                                 $overtime_id = $overtime->insert($data);
                             } catch (Exception $e) {
                                 $result['success'] = false;
                                 $result['info'] = $e->getMessage();
                             }
                         } else {
                             $overtime_id = $request['id'];
                             $review_info = $now . ': ' . $user_session->user_info['user_name'] . ' [修改]';
                             $overtimeData = $overtime->getData(null, $overtime_id);
                             $data['review_info'] = $overtimeData['review_info'] . '<br>' . $review_info;
                             $data['state'] = 0;
                             $data['review_time_1'] = null;
                             //$data['review_time_2'] = null;
                             $data['release_time'] = null;
                             try {
                                 $overtime->update($data, "id = " . $overtime_id);
                             } catch (Exception $e) {
                                 $result['success'] = false;
                                 $result['info'] = $e->getMessage();
                             }
                         }
                     }
                     $overtimeData = $overtime->getData(null, $overtime_id);
                     $review = new Dcc_Model_Review();
                     $user = new Application_Model_User();
                     $help = new Application_Model_Helpers();
                     // 记录审核日志:审核人1
                     $apply_user_info = $user->getEmployeeInfoById($request['apply_user']);
                     $review_user_1_info = $user->getEmployeeInfoById($request['review_user_1']);
                     $reviewData = array('type' => 'attendance_overtime', 'file_id' => $overtime_id, 'step_name' => '审核人1', 'plan_user' => $overtimeData['review_employee_1_id'], 'method' => 1, 'return' => 1);
                     $review->insert($reviewData);
                     // 如果存在审核人2记录审核日志:审核人2
                     /* if($request['review_user_2']){
                            $review_user_2_info = $user->getEmployeeInfoById($request['review_user_2']);
                            
                            $reviewData = array(
                                    'type'      => 'attendance_overtime',
                                    'file_id'   => $overtime_id,
                                    'step_name' => '审核人2',
                                    'plan_user' => $overtimeData['review_employee_2_id'],
                                    'method'    => 1,
                                    'return'    => 1
                            );
                            
                            $review->insert($reviewData);
                        } */
                     // 记录审核日志:人事主管
                     $member = new Admin_Model_Member();
                     $hraAdminUserArr = $member->getMemberWithNoManagerByName('人事主管');
                     $hraEmployeeIdArr = array();
                     foreach ($hraAdminUserArr as $hra) {
                         $hra_info = $user->getEmployeeInfoById($hra['user_id']);
                         array_push($hraEmployeeIdArr, $hra_info['id']);
                     }
                     $hraIds = implode(',', $hraEmployeeIdArr);
                     $reviewData = array('type' => 'attendance_overtime', 'file_id' => $overtime_id, 'step_name' => '人事审核', 'plan_user' => $hraIds, 'method' => 1, 'return' => 1);
                     $review->insert($reviewData);
                     // 向审核人1发送邮件
                     $mailContent = '<div>你有一个新的加班申请等待审核,请登录系统查看:</div>
                                     <div>
                                     <p><b>申请人:</b><a style="color:#008B00;font-weight: bold;">' . $overtimeData['apply_user_name'] . '</a></p>
                                     <p><b>加班时间:</b><a style="color:#008B00;font-weight: bold;">' . $overtimeData['time_from'] . '</a> 至 <a style="color:#008B00;font-weight: bold;">' . $overtimeData['time_to'] . '</a></p>
                                     <p><b>事由:</b>' . $overtimeData['reason'] . '</p>
                                     <p><b>备注:</b>' . $overtimeData['remark'] . '</p>
                                     <p><b>创建人:</b>' . $overtimeData['creater'] . '</p>
                                     <p><b>申请时间:</b>' . $overtimeData['create_time'] . '</p>
                                     <hr>
                                     <p><b>审核日志:</b></p><p>' . $data['review_info'] . '</p>
                                     </div>';
                     $mailData = array('type' => '消息', 'subject' => '加班申请-新申请', 'cc' => $user_session->user_info['user_email'], 'content' => $mailContent, 'add_date' => $now);
                     $result = $help->sendMailToStep(array($review_user_1_info['id']), $mailData);
                 } else {
                     $result['success'] = false;
                     $result['info'] = '申请失败,当前申请人未设置部门主管。';
                 }
             }
         } else {
             $result['success'] = false;
             $result['info'] = '时间设置错误,请确认时间范围是否正确。';
         }
     } else {
         if ($operate_type == 'delete') {
             if (isset($request['id']) && count(Zend_Json::decode($request['id'])) > 0) {
                 $ids = Zend_Json::decode($request['id']);
                 // 多条申请逐条删除
                 foreach ($ids as $id) {
                     try {
                         $review = new Dcc_Model_Review();
                         // 删除审核日志
                         $review->delete("type = 'attendance_overtime' and file_id = " . $id);
                         $overtime->delete("id = " . $id);
                     } catch (Exception $e) {
                         $result['success'] = false;
                         $result['info'] = $e->getMessage();
                     }
                 }
             } else {
                 $result['success'] = false;
                 $result['info'] = '参数错误,没有删除对象。';
             }
         } else {
             $result['success'] = false;
             $result['info'] = '参数错误,没有操作类别。';
         }
     }
     echo Zend_Json::encode($result);
     exit;
 }
Beispiel #6
0
 public function editcatalogAction()
 {
     // 返回值数组
     $result = array('success' => true, 'info' => '编辑成功');
     $now = date('Y-m-d H:i:s');
     $user_session = new Zend_Session_Namespace('user');
     $user_id = $user_session->user_info['user_id'];
     $request = $this->getRequest()->getParams();
     $attribute = isset($request['attribute']) ? $request['attribute'] : false;
     $catalog = new Product_Model_Catalog();
     if ($attribute) {
         $catalog_id = isset($request['id']) ? $request['id'] : null;
         $code = isset($request['code']) ? $request['code'] : null;
         $code_old = isset($request['code_old']) ? $request['code_old'] : null;
         $stage_id = isset($request['stage_id']) && $request['stage_id'] != '' ? $request['stage_id'] : null;
         $remark = isset($request['remark']) ? $request['remark'] : null;
         $date_dvt = isset($request['date_dvt']) && $request['date_dvt'] != '' ? $request['date_dvt'] : null;
         $qa1_date = isset($request['qa1_date']) && $request['qa1_date'] != '' ? $request['qa1_date'] : null;
         $qa2_date = isset($request['qa2_date']) && $request['qa2_date'] != '' ? $request['qa2_date'] : null;
         $evt_date = isset($request['evt_date']) && $request['evt_date'] != '' ? $request['evt_date'] : null;
         $mass_production_date = isset($request['mass_production_date']) && $request['mass_production_date'] != '' ? $request['mass_production_date'] : null;
         if ($catalog_id && $code) {
             if ($catalog->fetchAll("id != " . $catalog_id . " and code = '" . $code . "'")->count() == 0) {
                 $data = array('code' => $code, 'code_old' => $code_old, 'stage_id' => $stage_id, 'remark' => $remark, 'date_dvt' => $date_dvt, 'qa1_date' => $qa1_date, 'qa2_date' => $qa2_date, 'evt_date' => $evt_date, 'mass_production_date' => $mass_production_date, 'update_time' => $now, 'update_user' => $user_id);
                 $where = "id = " . $catalog_id;
                 try {
                     $catalog->update($data, $where);
                 } catch (Exception $e) {
                     $result['success'] = false;
                     $result['info'] = $e->getMessage();
                     echo Zend_Json::encode($result);
                     exit;
                 }
             } else {
                 $result['success'] = false;
                 $result['info'] = '代码重复,请重新分配';
                 echo Zend_Json::encode($result);
                 exit;
             }
         } else {
             $result['success'] = false;
             $result['info'] = '信息不完整,编辑失败!';
         }
     } else {
         $operate = isset($request['operate']) ? $request['operate'] : null;
         $review = isset($request['review']) ? $request['review'] : null;
         $id = isset($request['id']) ? $request['id'] : null;
         $ids = isset($request['ids']) ? $request['ids'] : null;
         $active = isset($request['active']) ? $request['active'] : null;
         $active = $active == 'on' ? 1 : 0;
         $description = isset($request['description']) ? $request['description'] : null;
         $remark = isset($request['remark']) ? $request['remark'] : null;
         $code_customer = isset($request['code_customer']) ? trim($request['code_customer']) : null;
         $model_customer = isset($request['model_customer']) ? trim($request['model_customer']) : null;
         $description_customer = isset($request['description_customer']) ? $request['description_customer'] : null;
         $type_id = isset($request['type_id']) ? $request['type_id'] : null;
         $type_id = isset($request['type_id']) ? $request['type_id'] : null;
         $series_id = isset($request['series_id']) ? $request['series_id'] : null;
         $series_id = isset($request['series_id']) ? $request['series_id'] : null;
         $developmode_id = isset($request['developmode_id']) ? $request['developmode_id'] : null;
         $model_standard = isset($request['model_standard']) ? trim($request['model_standard']) : null;
         $model_internal = isset($request['model_internal']) ? trim($request['model_internal']) : null;
         if ($operate == 'delete' && $id) {
             // 删除
             try {
                 if ($catalog->fetchAll("id = " . $id . " and auditor_id is not null")->count() == 1) {
                     $catalogData = $catalog->fetchRow("id = " . $id)->toArray();
                     $catalog->update(array('delete' => 1, 'review_info' => $catalogData['review_info'] . '<br>' . $now . ': ' . $user_session->user_info['user_name'] . ' [删除]'), "id = " . $id);
                 } else {
                     $catalog->delete("id = " . $id);
                     $review = new Dcc_Model_Review();
                     $review->delete("type = 'product_add' and file_id = " . $id);
                 }
             } catch (Exception $e) {
                 $result['success'] = false;
                 $result['info'] = $e->getMessage();
                 echo Zend_Json::encode($result);
                 exit;
             }
         } else {
             if ($operate == 'disable' && $ids) {
                 // 作废
                 $idArr = explode(',', $ids);
                 foreach ($idArr as $id) {
                     try {
                         if ($catalog->fetchAll("id = " . $id . " and active = 1")->count() == 1) {
                             $catalogData = $catalog->fetchRow("id = " . $id)->toArray();
                             $catalog->update(array('active' => 0, 'review_info' => $catalogData['review_info'] . '<br>' . $now . ': ' . $user_session->user_info['user_name'] . ' [作废]'), "id = " . $id);
                         }
                     } catch (Exception $e) {
                         $result['success'] = false;
                         $result['info'] = $e->getMessage();
                         echo Zend_Json::encode($result);
                         exit;
                     }
                 }
             } else {
                 if ($operate == 'enable' && $ids) {
                     // 启用
                     $idArr = explode(',', $ids);
                     foreach ($idArr as $id) {
                         try {
                             if ($catalog->fetchAll("id = " . $id . " and active = 0")->count() == 1) {
                                 $catalogData = $catalog->fetchRow("id = " . $id)->toArray();
                                 $catalog->update(array('active' => 1, 'review_info' => $catalogData['review_info'] . '<br>' . $now . ': ' . $user_session->user_info['user_name'] . ' [启用]'), "id = " . $id);
                             }
                         } catch (Exception $e) {
                             $result['success'] = false;
                             $result['info'] = $e->getMessage();
                             echo Zend_Json::encode($result);
                             exit;
                         }
                     }
                 } else {
                     if ($operate == 'edit' && $id) {
                         // 判断是否重复
                         if ($catalog->fetchAll("id != " . $id . " and model_internal = '" . $model_internal . "'")->count() == 0) {
                             //type_id = ".$type_id." and series_id = ".$series_id." and
                             $catalogData = $catalog->fetchRow("id = " . $id)->toArray();
                             $data = array('active' => $active, 'type_id' => $type_id, 'series_id' => $series_id, 'developmode_id' => $developmode_id, 'model_standard' => $model_standard, 'model_internal' => $model_internal, 'description' => $description, 'remark' => $remark, 'review' => $review == 1 ? 0 : 2, 'code_customer' => $code_customer, 'model_customer' => $model_customer, 'description_customer' => $description_customer, 'update_time' => $now, 'update_user' => $user_id, 'review_info' => $catalogData['review_info'] . '<br>' . $now . ': ' . $user_session->user_info['user_name'] . ' [修改]');
                             $where = "id = " . $id;
                             try {
                                 $catalog->update($data, $where);
                                 if ($catalogData['review'] == 1) {
                                     // 修改
                                     $member = new Admin_Model_Member();
                                     $user = new Application_Model_User();
                                     $employee = new Hra_Model_Employee();
                                     $flow = new Admin_Model_Flow();
                                     $step = new Admin_Model_Step();
                                     $review = new Dcc_Model_Review();
                                     $flowData = $flow->fetchRow("flow_name = '产品中心-审核'")->toArray();
                                     // 获取审核阶段
                                     $stepIds = $flowData['step_ids'];
                                     $stepArr = explode(',', $stepIds);
                                     $i = 0;
                                     foreach ($stepArr as $s) {
                                         $stepData = $step->fetchRow("id = " . $s)->toArray();
                                         $step_user = $stepData['user'] != '' ? $stepData['user'] : null;
                                         $step_role = $stepData['dept'] != '' ? $stepData['dept'] : null;
                                         $reviewData = array('type' => 'product_add', 'file_id' => $id, 'step_name' => $stepData['step_name'], 'plan_user' => $step_user, 'plan_dept' => $step_role, 'method' => $stepData['method'], 'return' => $stepData['return']);
                                         $review->delete("type = 'product_add' AND file_id = " . $id);
                                         $review->insert($reviewData);
                                         // 第一阶段发送邮件通知
                                         if ($i == 0) {
                                             $employeeIdArr = array();
                                             if ($step_user) {
                                                 $tmpArr = explode(',', $stepData['user']);
                                                 foreach ($tmpArr as $t) {
                                                     if (!in_array($t, $employeeIdArr)) {
                                                         array_push($employeeIdArr, $t);
                                                     }
                                                 }
                                             }
                                             if ($step_role) {
                                                 $tmpArr = $member->getMember($stepData['dept']);
                                                 foreach ($tmpArr as $t) {
                                                     if (!in_array($t, $employeeIdArr)) {
                                                         array_push($employeeIdArr, $t['employee_id']);
                                                     }
                                                 }
                                             }
                                             $toAddress = array();
                                             $toIds = array();
                                             foreach ($employeeIdArr as $employeeId) {
                                                 $em = $employee->getInfoById($employeeId);
                                                 array_push($toAddress, $em['email']);
                                                 $u = $user->fetchRow("employee_id = " . $employeeId)->toArray();
                                                 array_push($toIds, $u['id']);
                                             }
                                             $mail = new Application_Model_Log_Mail();
                                             $mailContent = '<div>产品中心-修改产品信息,请登录系统审核:</div>
                                 <div>
                                 <p><b>标准型号:</b>' . $catalogData['model_standard'] . ' -> ' . $model_standard . '</p>
                                 <p><b>内部型号:</b>' . $catalogData['model_internal'] . ' -> ' . $model_internal . '</p>
                                 <p><b>描述:</b>' . $description . '</p>
                                 <p><b>申请人:</b>' . $user_session->user_info['user_name'] . '</p>
                                 <p><b>申请时间:</b>' . $now . '</p>
                                 </div>';
                                             $mailData = array('type' => '消息', 'subject' => '产品中心-修改', 'to' => implode(',', $toAddress), 'cc' => $user_session->user_info['user_email'], 'user_id' => implode(',', $toIds), 'content' => $mailContent, 'add_date' => $now);
                                             try {
                                                 // 记录邮件日志并发送邮件
                                                 $mail->send($mail->insert($mailData));
                                             } catch (Exception $e) {
                                                 $result['success'] = false;
                                                 $result['info'] = $e->getMessage();
                                                 echo Zend_Json::encode($result);
                                                 exit;
                                             }
                                         }
                                         $i++;
                                     }
                                 } else {
                                     // 变更
                                     $noticeMails = array();
                                     $noticeUsers = array();
                                     $user = new Application_Model_User();
                                     $employee = new Hra_Model_Employee();
                                     $member = new Admin_Model_Member();
                                     $reviewModel = new Dcc_Model_Review();
                                     $reviewerInfo = $reviewModel->getReviewUserInfo('product_add', $id);
                                     // 审核人
                                     $applyEmployeeData = $user->fetchRow("id = " . $catalogData['create_user'])->toArray();
                                     $applyEmployee = $employee->fetchRow("id = " . $applyEmployeeData['employee_id'])->toArray();
                                     // 申请人
                                     $noticeTo = $member->getMemberWithManagerByName('产品中心-PM');
                                     // 管理员
                                     foreach ($noticeTo as $n) {
                                         if ($n['email'] != '' && !in_array($n['user_id'], $noticeUsers)) {
                                             array_push($noticeMails, $n['email']);
                                             array_push($noticeUsers, $n['user_id']);
                                         }
                                     }
                                     foreach ($reviewerInfo as $r) {
                                         if ($r['email'] != '' && !in_array($r['user_id'], $noticeUsers)) {
                                             array_push($noticeMails, $r['email']);
                                             array_push($noticeUsers, $r['user_id']);
                                         }
                                     }
                                     if (!in_array($catalogData['create_user'], $noticeUsers)) {
                                         array_push($noticeMails, $applyEmployee['email']);
                                         array_push($noticeUsers, $catalogData['create_user']);
                                     }
                                     $mail = new Application_Model_Log_Mail();
                                     $mailContent = '<div>产品中心产品信息变更,请登录系统查看:</div>
                                 <div>
                                 <p><b>标准型号:</b>' . $catalogData['model_standard'] . ' -> ' . $model_standard . '</p>
                                 <p><b>内部型号:</b>' . $catalogData['model_internal'] . ' -> ' . $model_internal . '</p>
                                 <p><b>描述:</b>' . $description . '</p>
                                 <p><b>申请人:</b>' . $user_session->user_info['user_name'] . '</p>
                                 <p><b>申请时间:</b>' . $now . '</p>
                                 </div>';
                                     $mailData = array('type' => '消息', 'subject' => '产品中心-变更', 'cc' => $user_session->user_info['user_email'], 'to' => implode(',', $noticeMails), 'user_id' => $user_id, 'content' => $mailContent, 'add_date' => $now);
                                     try {
                                         // 记录邮件日志并发送邮件
                                         $mail->send($mail->insert($mailData));
                                     } catch (Exception $e) {
                                         $result['success'] = false;
                                         $result['info'] = $e->getMessage();
                                         echo Zend_Json::encode($result);
                                         exit;
                                     }
                                 }
                             } catch (Exception $e) {
                                 $result['success'] = false;
                                 $result['info'] = $e->getMessage();
                                 echo Zend_Json::encode($result);
                                 exit;
                             }
                         } else {
                             $result['success'] = false;
                             $result['info'] = '当前型号已存在,请勿重复添加!';
                             echo Zend_Json::encode($result);
                             exit;
                         }
                     } else {
                         if ($operate == 'add') {
                             if ($catalog->fetchAll("model_internal = '" . $model_internal . "'")->count() == 0) {
                                 //type_id = ".$type_id." and series_id = ".$series_id." and
                                 $data = array('active' => $active, 'type_id' => $type_id, 'series_id' => $series_id, 'developmode_id' => $developmode_id, 'model_standard' => $model_standard, 'model_internal' => $model_internal, 'remark' => $remark, 'description' => $description, 'code_customer' => $code_customer, 'model_customer' => $model_customer, 'description_customer' => $description_customer, 'create_time' => $now, 'create_user' => $user_id, 'update_time' => $now, 'update_user' => $user_id, 'review_info' => $now . ': ' . $user_session->user_info['user_name'] . ' [添加]');
                                 try {
                                     $catalog_id = $catalog->insert($data);
                                     $member = new Admin_Model_Member();
                                     $user = new Application_Model_User();
                                     $employee = new Hra_Model_Employee();
                                     $flow = new Admin_Model_Flow();
                                     $step = new Admin_Model_Step();
                                     $review = new Dcc_Model_Review();
                                     $flowData = $flow->fetchRow("flow_name = '产品中心-审核'")->toArray();
                                     // 获取审核阶段
                                     $stepIds = $flowData['step_ids'];
                                     $stepArr = explode(',', $stepIds);
                                     $i = 0;
                                     foreach ($stepArr as $s) {
                                         $stepData = $step->fetchRow("id = " . $s)->toArray();
                                         $step_user = $stepData['user'] != '' ? $stepData['user'] : null;
                                         $step_role = $stepData['dept'] != '' ? $stepData['dept'] : null;
                                         $reviewData = array('type' => 'product_add', 'file_id' => $catalog_id, 'step_name' => $stepData['step_name'], 'plan_user' => $step_user, 'plan_dept' => $step_role, 'method' => $stepData['method'], 'return' => $stepData['return']);
                                         $review->insert($reviewData);
                                         // 第一阶段发送邮件通知
                                         if ($i == 0) {
                                             $employeeIdArr = array();
                                             if ($step_user) {
                                                 $tmpArr = explode(',', $stepData['user']);
                                                 foreach ($tmpArr as $t) {
                                                     if (!in_array($t, $employeeIdArr)) {
                                                         array_push($employeeIdArr, $t);
                                                     }
                                                 }
                                             }
                                             if ($step_role) {
                                                 $tmpArr = $member->getMember($stepData['dept']);
                                                 foreach ($tmpArr as $t) {
                                                     if (!in_array($t, $employeeIdArr)) {
                                                         array_push($employeeIdArr, $t['employee_id']);
                                                     }
                                                 }
                                             }
                                             $toAddress = array();
                                             $toIds = array();
                                             foreach ($employeeIdArr as $employeeId) {
                                                 $em = $employee->getInfoById($employeeId);
                                                 array_push($toAddress, $em['email']);
                                                 $u = $user->fetchRow("employee_id = " . $employeeId)->toArray();
                                                 array_push($toIds, $u['id']);
                                             }
                                             $mail = new Application_Model_Log_Mail();
                                             $mailContent = '<div>产品中心新增产品型号,请登录系统审核:</div>
                                 <div>
                                 <p><b>标准型号:</b>' . $model_standard . '</p>
                                 <p><b>内部型号:</b>' . $model_internal . '</p>
                                 <p><b>描述:</b>' . $description . '</p>
                                 <p><b>申请人:</b>' . $user_session->user_info['user_name'] . '</p>
                                 <p><b>申请时间:</b>' . $now . '</p>
                                 </div>';
                                             $mailData = array('type' => '消息', 'subject' => '产品中心-新建', 'to' => implode(',', $toAddress), 'user_id' => implode(',', $toIds), 'content' => $mailContent, 'add_date' => $now);
                                             try {
                                                 // 记录邮件日志并发送邮件
                                                 $mail->send($mail->insert($mailData));
                                             } catch (Exception $e) {
                                                 $result['success'] = false;
                                                 $result['info'] = $e->getMessage();
                                                 echo Zend_Json::encode($result);
                                                 exit;
                                             }
                                         }
                                         $i++;
                                     }
                                 } catch (Exception $e) {
                                     $result['success'] = false;
                                     $result['info'] = $e->getMessage();
                                     echo Zend_Json::encode($result);
                                     exit;
                                 }
                             } else {
                                 $result['success'] = false;
                                 $result['info'] = '当前型号已存在,请勿重复添加!';
                                 echo Zend_Json::encode($result);
                                 exit;
                             }
                         }
                     }
                 }
             }
         }
     }
     echo Zend_Json::encode($result);
     exit;
 }
Beispiel #7
0
 /**
  * @abstract    保存
  * @return      null
  */
 public function editAction()
 {
     // 返回值数组
     $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();
     $mail = new Application_Model_Log_Mail();
     $member = new Admin_Model_Member();
     // 根据物料类别获取审批流
     $typeId = $val->type_id;
     $stepRows = array();
     if ($typeId) {
         $type = new Product_Model_Type();
         // 获取当前物料类别对应的流程ID 如果找不到,继续往上搜索
         $flow_id = $type->getFlowId($typeId, 'new');
         if ($flow_id) {
             // 根据流程ID获取阶段
             $flow = new Admin_Model_Flow();
             $step = new Admin_Model_Step();
             $flowRow = $flow->getRow($flow_id);
             $step_ids = $flowRow['step_ids'];
             if ($step_ids) {
                 $stepRows = $step->getListByFlow($step_ids);
                 $state = "Reviewing";
             }
         }
     }
     // 新增还是编辑
     if (isset($val->id) && $val->id) {
         $result['info'] = '修改成功';
         $data = array('type' => $val->type_id, 'description' => $val->description, 'remark' => $val->remark, 'ver' => $val->ver, 'unit' => $val->unit, 'state' => isset($state) ? 'Reviewing' : 'Active', 'manufacturers' => $val->manufacturers, 'supply1' => $val->supply1, 'supply2' => $val->supply2, 'mpq' => $val->mpq, 'moq' => $val->moq, 'tod' => $val->tod, 'data_file_id' => $val->data_file_id, 'first_report_id' => $val->first_report_id);
         $id = $val->id;
         $where = "id = " . $id;
         try {
             if ($id) {
                 $materiel->update($data, $where);
                 /*
                  $attrval = new Admin_Model_Formval();
                  // 自定义字段
                  foreach($request as $field => $value) {
                  if(stripos($field, "intelligenceField") !== false) {
                  $attrId = str_replace("intelligenceField", "", $field);
                  $menu = 'oa_doc_files_'.$id;
                 
                  $formval = array(
                  'attrid' => $attrId,
                  'value' => $value,
                  'menu' => $menu
                  );
                  $where = "attrid = ".$attrId." and menu = '".$menu."'";
                  if($attrval->fetchAll($where)->count() > 0) {
                  // 更新
                  $attrval->update($formval, $where);
                  } else {
                  $attrval->insert($formval);
                  }
                  }
                  }
                 */
                 // 操作记录
                 $data = array('type' => "materiel", 'table_name' => "oa_product_materiel", 'table_id' => $id, 'handle_user' => $user, 'handle_time' => $now, 'action' => "编辑", 'ip' => $_SERVER['REMOTE_ADDR']);
                 $record->insert($data);
                 // 审核流程
                 // 删除已存在的审核记录
                 $review->delete("type = 'materiel' and file_id = " . $id);
                 // 把阶段信息插入review记录
                 $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 && !$plan_user) {
                             $tmpUser = $member->getUserids("系统管理员");
                         }
                         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 ($users) {
                             if ($plan_user) {
                                 $plan_user .= ",";
                             }
                             $plan_user .= $users;
                         }
                     }
                     $repeatUser = explode(',', $plan_user);
                     $repeatUser = array_unique($repeatUser);
                     $plan_user = implode(',', $repeatUser);
                     $reviewData = array('type' => "materiel", '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);
                 }
             }
         } catch (Exception $e) {
             $result['result'] = false;
             $result['info'] = $e->getMessage();
             echo Zend_Json::encode($result);
             exit;
         }
         echo Zend_Json::encode($result);
         exit;
     } else {
         $data = array('type' => $val->type_id, 'description' => $val->description, 'remark' => $val->remark, 'ver' => $val->ver, 'unit' => $val->unit, 'state' => isset($state) ? 'Reviewing' : 'Active', 'manufacturers' => $val->manufacturers, 'supply1' => $val->supply1, 'supply2' => $val->supply2, 'mpq' => $val->mpq, 'moq' => $val->moq, 'tod' => $val->tod, 'data_file_id' => $val->data_file_id, 'first_report_id' => $val->first_report_id, 'create_user' => $user, 'create_time' => $now);
         try {
             $id = $materiel->insert($data);
             if ($id) {
                 /*
                  // 自定义字段
                  $attrval = new Admin_Model_Formval();
                  foreach($request as $field => $value) {
                  if(stripos($field, "intelligenceField") !== false && $value) {
                  $attrId = str_replace("intelligenceField", "", $field);
                  $menu = 'oa_doc_files_'.$id;
                 
                  $formval = array(
                  'attrid' => $attrId,
                  'value' => $value,
                  'menu' => $menu
                  );
                  $attrval->insert($formval);
                  }
                  }
                 */
                 // 操作记录
                 $data = array('type' => "materiel", 'table_name' => "oa_product_materiel", 'table_id' => $id, 'handle_user' => $user, 'handle_time' => $now, 'action' => "申请", 'ip' => $_SERVER['REMOTE_ADDR']);
                 $record->insert($data);
                 // 审核流程
                 // 把阶段信息插入review记录
                 $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 && !$plan_user) {
                             $tmpUser = $member->getUserids("系统管理员");
                         }
                         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 ($users) {
                             if ($plan_user) {
                                 $plan_user .= ",";
                             }
                             $plan_user .= $users;
                         }
                     }
                     $repeatUser = explode(',', $plan_user);
                     $repeatUser = array_unique($repeatUser);
                     $plan_user = implode(',', $repeatUser);
                     $reviewData = array('type' => "materiel", '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();
                         $mailData = array('type' => '物料号归档审批', 'subject' => '物料号归档审批', 'to' => $to->mail_to, 'cc' => '', 'content' => '你有新物料号归档申请需要审核,请登录系统查看详情', 'send_time' => $now, 'add_date' => $now);
                         $mailId = $mail->insert($mailData);
                         if ($mailId) {
                             $mail->send($mailId);
                         }
                     }
                     $first = false;
                 }
             }
         } catch (Exception $e) {
             $result['result'] = false;
             $result['info'] = $e->getMessage();
             echo Zend_Json::encode($result);
             exit;
         }
         echo Zend_Json::encode($result);
         exit;
     }
 }
Beispiel #8
0
 /**
  * @abstract    文件升版
  * @return      null
  */
 public function upgradeAction()
 {
     // 返回值数组
     $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;
     $json = json_decode($request['json']);
     $code_file_code_id = $json->code_id;
     $code_file_code = $json->code;
     $code_file_file_id = $json->file_id;
     $code_file_file = $json->file;
     $code_file_desc = isset($json->code_file_desc) ? $json->code_file_desc : '';
     $code_file_project_no = isset($json->code_file_project_no) ? $json->code_file_project_no : '';
     $files = new Dcc_Model_Files();
     $upload = new Dcc_Model_Upload();
     $record = new Dcc_Model_Record();
     $review = new Dcc_Model_Review();
     $upgrade = new Dcc_Model_Upgrade();
     $employee = new Hra_Model_Employee();
     $mail = new Application_Model_Log_Mail();
     $member = new Admin_Model_Member();
     $code = $code_file_code[0];
     $stepRows = array();
     if (count($code) > 0 && $code) {
         $codeModel = new Dcc_Model_Code();
         // 获取当前文件类别对应的流程ID
         $row = $codeModel->getTypeInfo("t1.code = '{$code}'");
         $flow_id = $row['dev_flow_id'];
         if ($flow_id) {
             // 根据流程ID获取阶段
             $flow = new Admin_Model_Flow();
             $step = new Admin_Model_Step();
             $flowRow = $flow->getRow($flow_id);
             $step_ids = $flowRow['step_ids'];
             if ($step_ids) {
                 $stepRows = $step->getListByFlow($step_ids);
                 $state = $stepRows[0]['step_name'];
             }
         }
     }
     // 获取所有文件的版本号
     $vers = array();
     foreach ($code_file_code as $c) {
         $d = $files->getAdapter()->query("select max(ver)+0.1 as ver from oa_doc_files where code = :code and state = 'Active' and del_flg = 0", array('code' => $c))->fetch();
         $v = round($d['ver'], 1);
         if (strcmp($v, (int) $v) === 0) {
             $v .= ".0";
         }
         $vers[] = $v;
     }
     // 新增还是编辑
     if ($val->id) {
         $result['info'] = '修改成功';
         $data = array('state' => isset($state) ? 'Reviewing' : 'Active', 'code' => implode(',', $code_file_code), 'name' => implode(',', $code_file_file), 'file_ids' => implode(',', $code_file_file_id), 'ver' => implode(',', $vers), 'description' => $code_file_desc, 'project_info' => implode(',', $code_file_project_no), 'remark' => $val->remark, 'tag' => $val->tag, 'update_time' => $now, 'update_user' => $user);
         $id = $val->id;
         $where = "id = " . $id;
         // 修改升版记录
         $upgradeData = array('reason' => $val->reason, 'reason_type' => $val->reason_type, 'update_time' => $now, 'update_user' => $user);
         $upgradeWhere = "file_id = {$id}";
         try {
             if ($id) {
                 $upgrade->update($upgradeData, $upgradeWhere);
                 $files->update($data, $where);
                 $attrval = new Admin_Model_Formval();
                 // 自定义字段
                 foreach ($request as $field => $value) {
                     if (stripos($field, "intelligenceField") !== false) {
                         $attrId = str_replace("intelligenceField", "", $field);
                         $menu = 'oa_doc_files_' . $id;
                         $formval = array('attrid' => $attrId, 'value' => $value, 'menu' => $menu);
                         $where = "attrid = " . $attrId . " and menu = '" . $menu . "'";
                         if ($attrval->fetchAll($where)->count() > 0) {
                             // 更新
                             $attrval->update($formval, $where);
                         } else {
                             $attrval->insert($formval);
                         }
                     }
                 }
                 // 操作记录
                 $data = array('type' => "files", 'table_name' => "oa_doc_files", 'table_id' => $id, 'handle_user' => $user, 'handle_time' => $now, 'action' => "编辑", 'ip' => $_SERVER['REMOTE_ADDR']);
                 $record->insert($data);
                 // 审核流程
                 // 删除已存在的审核记录
                 $review->delete("type='files' and file_id = " . $id);
                 // 把阶段信息插入review记录
                 $first = true;
                 foreach ($stepRows as $s) {
                     $plan_user = $s['user'];
                     if ($s['dept']) {
                         $plan_dept = $s['dept'];
                         // 根据角色id和项目号获取用户成员列表
                         $roleid = $s['dept'];
                         $codeTmp = $employee->getAdapter()->query("select project_no from oa_doc_code where code = '{$code}'")->fetchObject();
                         $projectno = $codeTmp->project_no;
                         // 如果不存在项目号,则直接取角色中的用户 否则根据角色id和项目号获取roleset id
                         $tmpUser = array();
                         $tmpBool = true;
                         if ($projectno) {
                             // 根据角色id和项目号获取roleset id
                             $rolesetTmp = $employee->getAdapter()->query("select group_concat(id) as id from oa_product_catalog_roleset where active=1 and catalog_id='{$projectno}' and role_id in ( " . $roleid . ")")->fetchObject();
                             $rolesetid = $rolesetTmp->id;
                             if ($rolesetid) {
                                 $tmpBool = false;
                                 $userTmp = $employee->getAdapter()->query("select group_concat(user_id) as ids from oa_product_catalog_roleset_member where roleset_id in ( " . $rolesetid . ")")->fetchObject();
                                 $tmpUser = explode(',', $userTmp->ids);
                                 // 如果没有取到用户,还是使用默认用户
                                 if (count($tmpUser) == 0) {
                                     $tmpBool = true;
                                 }
                             }
                         }
                         if ($tmpBool) {
                             foreach (explode(',', $plan_dept) as $role) {
                                 $tmpRole = $member->getMemberWithNoManager($role);
                                 foreach ($tmpRole as $m) {
                                     $tmpUser[] = $m['user_id'];
                                 }
                             }
                         }
                         if (count($tmpUser) == 0 && !$plan_user) {
                             $tmpUser = $member->getUserids("系统管理员");
                         }
                         // user id 转换成employee 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;
                         }
                         // 获取角色所有人员
                         //                            $tmpUser = $employee->getAdapter()->query("select group_concat(id) as ids from oa_employee where dept_id in ( " . $plan_dept . ")")->fetchObject();
                         if ($users) {
                             if ($plan_user) {
                                 $plan_user .= ",";
                             }
                             $plan_user .= $users;
                         }
                         $repeatUser = explode(',', $plan_user);
                         $repeatUser = array_unique($repeatUser);
                         $plan_user = implode(',', $repeatUser);
                     }
                     $reviewData = array('type' => "files", 'file_id' => $id, 'plan_dept' => $s['dept'], '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();
                         $content = "你有文件升版需要审核,<p><b>文件号:</b>" . implode(',', $code_file_code) . "</p><p><b>版本:</b>" . implode(',', $vers) . "</p><p><b>升版原因:</b>" . $val->reason . "</p><p><b>备注:</b>" . $val->remark . "</p><p><b>申请人:</b>" . $user_name . "</p><p><b>申请时间:</b>" . $now . "</p><p>请登录系统查看详情!</p>";
                         $mailData = array('type' => '升版文件', 'subject' => '升版文件评审', 'to' => $to->mail_to, 'cc' => '', 'content' => $content, 'send_time' => $now, 'add_date' => $now);
                         $mailId = $mail->insert($mailData);
                         if ($mailId) {
                             $mail->send($mailId);
                         }
                     }
                     $first = false;
                 }
                 // 没有审批流程,旧版文件自动作废
                 if (!isset($state)) {
                     $sids = array($id);
                     if (isset($sids) && count($sids) > 0) {
                         if (count($code_file_code) > 0) {
                             $codes = array();
                             foreach ($code_file_code as $c) {
                                 $codes[] = $c;
                             }
                         }
                         if (isset($codes) && count($codes) > 0) {
                             for ($i = 0; $i < count($codes); $i++) {
                                 $codes[$i] = "'" . $codes[$i] . "'";
                             }
                         }
                         $obsoluteWhere = " id not in (" . implode(',', $sids) . ") and code in (" . implode(',', $codes) . ")";
                     }
                     $obsoluteData = array("state" => "Obsolete");
                     if (isset($obsoluteWhere)) {
                         $files->update($obsoluteData, $obsoluteWhere);
                     }
                     // 更改文件状态为归档
                     $uploadData = array("archive" => 1, "archive_time" => $now);
                     $uploadWhere = "id in (" . implode(',', $code_file_file_id) . ")";
                     // 更新文件
                     $upload->update($uploadData, $uploadWhere);
                 }
             }
         } catch (Exception $e) {
             $result['result'] = false;
             $result['info'] = $e->getMessage();
             echo Zend_Json::encode($result);
             exit;
         }
         echo Zend_Json::encode($result);
         exit;
     } else {
         $data = array('state' => isset($state) ? 'Reviewing' : 'Active', 'code' => implode(',', $code_file_code), 'name' => implode(',', $code_file_file), 'file_ids' => implode(',', $code_file_file_id), 'ver' => implode(',', $vers), 'description' => $code_file_desc, 'project_info' => implode(',', $code_file_project_no), 'remark' => $val->remark, 'tag' => $val->tag, 'create_time' => $now, 'create_user' => $user, 'update_time' => $now, 'update_user' => $user);
         try {
             $id = $files->insert($data);
             if ($id) {
                 // 升版记录
                 $upgradeData = array('file_id' => $id, 'reason' => $val->reason, 'reason_type' => $val->reason_type, 'create_time' => $now, 'create_user' => $user, 'update_time' => $now, 'update_user' => $user);
                 $upgrade->insert($upgradeData);
                 // 自定义字段
                 $attrval = new Admin_Model_Formval();
                 foreach ($request as $field => $value) {
                     if (stripos($field, "intelligenceField") !== false && $value) {
                         $attrId = str_replace("intelligenceField", "", $field);
                         $menu = 'oa_doc_files_' . $id;
                         $formval = array('attrid' => $attrId, 'value' => $value, 'menu' => $menu);
                         $attrval->insert($formval);
                     }
                 }
                 // 操作记录
                 $data = array('type' => "files", 'table_name' => "oa_doc_files", 'table_id' => $id, 'handle_user' => $user, 'handle_time' => $now, 'action' => "申请", 'ip' => $_SERVER['REMOTE_ADDR']);
                 $record->insert($data);
                 // 审核流程
                 // 把阶段信息插入review记录
                 $first = true;
                 foreach ($stepRows as $s) {
                     $plan_user = $s['user'];
                     if ($s['dept']) {
                         $plan_dept = $s['dept'];
                         // 根据角色id和项目号获取用户成员列表
                         $roleid = $s['dept'];
                         $codeTmp = $employee->getAdapter()->query("select project_no from oa_doc_code where code = '{$code}'")->fetchObject();
                         $projectno = $codeTmp->project_no;
                         // 如果不存在项目号,则直接取角色中的用户 否则根据角色id和项目号获取roleset id
                         $tmpUser = array();
                         $tmpBool = true;
                         if ($projectno) {
                             // 根据角色id和项目号获取roleset id
                             $rolesetTmp = $employee->getAdapter()->query("select group_concat(id) as id from oa_product_catalog_roleset where active=1 and catalog_id='{$projectno}' and role_id in ( " . $roleid . ")")->fetchObject();
                             $rolesetid = $rolesetTmp->id;
                             if ($rolesetid) {
                                 $tmpBool = false;
                                 $userTmp = $employee->getAdapter()->query("select group_concat(user_id) as ids from oa_product_catalog_roleset_member where roleset_id in ( " . $rolesetid . ")")->fetchObject();
                                 $tmpUser = explode(',', $userTmp->ids);
                                 // 如果没有取到用户,还是使用默认用户
                                 if (count($tmpUser) == 0) {
                                     $tmpBool = true;
                                 }
                             }
                         }
                         if ($tmpBool) {
                             foreach (explode(',', $plan_dept) as $role) {
                                 $tmpRole = $member->getMemberWithNoManager($role);
                                 foreach ($tmpRole as $m) {
                                     $tmpUser[] = $m['user_id'];
                                 }
                             }
                         }
                         if (count($tmpUser) == 0 && !$plan_user) {
                             $tmpUser = $member->getUserids("系统管理员");
                         }
                         // user id 转换成employee 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;
                         }
                         // 获取角色所有人员
                         //                            $tmpUser = $employee->getAdapter()->query("select group_concat(id) as ids from oa_employee where dept_id in ( " . $plan_dept . ")")->fetchObject();
                         if ($users) {
                             if ($plan_user) {
                                 $plan_user .= ",";
                             }
                             $plan_user .= $users;
                         }
                         $repeatUser = explode(',', $plan_user);
                         $repeatUser = array_unique($repeatUser);
                         $plan_user = implode(',', $repeatUser);
                     }
                     $reviewData = array('type' => "files", 'file_id' => $id, 'plan_dept' => $s['dept'], '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();
                         $content = "你有文件升版需要审核,<p><b>文件号:</b>" . implode(',', $code_file_code) . "</p><p><b>版本:</b>" . implode(',', $vers) . "</p><p><b>升版原因:</b>" . $val->reason . "</p><p><b>备注:</b>" . $val->remark . "</p><p><b>申请人:</b>" . $user_name . "</p><p><b>申请时间:</b>" . $now . "</p><p>请登录系统查看详情!</p>";
                         $mailData = array('type' => '升版文件', 'subject' => '升版文件评审', 'to' => $to->mail_to, 'cc' => '', 'content' => $content, 'send_time' => $now, 'add_date' => $now);
                         $mailId = $mail->insert($mailData);
                         if ($mailId) {
                             $mail->send($mailId);
                         }
                     }
                     $first = false;
                 }
                 // 没有审批流程,旧版文件自动作废
                 if (!isset($state)) {
                     $sids = array($id);
                     if (isset($sids) && count($sids) > 0) {
                         if (count($code_file_code) > 0) {
                             $codes = array();
                             foreach ($code_file_code as $c) {
                                 $codes[] = $c;
                             }
                         }
                         if (isset($codes) && count($codes) > 0) {
                             for ($i = 0; $i < count($codes); $i++) {
                                 $codes[$i] = "'" . $codes[$i] . "'";
                             }
                         }
                         $obsoluteWhere = " id not in (" . implode(',', $sids) . ") and code in (" . implode(',', $codes) . ")";
                     }
                     $obsoluteData = array("state" => "Obsolete");
                     if (isset($obsoluteWhere)) {
                         $files->update($obsoluteData, $obsoluteWhere);
                     }
                     // 更改文件状态为归档
                     $uploadData = array("archive" => 1, "archive_time" => $now);
                     $uploadWhere = "id in (" . implode(',', $code_file_file_id) . ")";
                     // 更新文件
                     $upload->update($uploadData, $uploadWhere);
                 }
             }
         } catch (Exception $e) {
             $result['result'] = false;
             $result['info'] = $e->getMessage();
             echo Zend_Json::encode($result);
             exit;
         }
         echo Zend_Json::encode($result);
         exit;
     }
 }
Beispiel #9
0
 /**
  * @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'];
     $val = (object) $request;
     $code = new Dcc_Model_Code();
     $type = new Dcc_Model_Type();
     $db = $code->getAdapter();
     if ($val->id) {
         // 编辑
         if (isset($val->code) && $val->code) {
             $auto_code = $val->code;
             // 检查是否文件号已经存在
             if ($code->fetchAll("id != " . $val->id . " and code = '" . $auto_code . "'")->count() > 0) {
                 $result['result'] = false;
                 $result['info'] = "文件编码“" . $val->code . "”已经存在";
                 echo Zend_Json::encode($result);
                 exit;
             }
         } else {
             $auto_code = "";
         }
         $data = array('code' => $auto_code, 'active' => isset($val->active) ? 1 : 0, 'project_no' => $val->project_no, 'project_standard_no' => isset($val->project_standard_no) ? $val->project_standard_no : "", 'description' => $val->description, 'remark' => $val->remark, 'update_time' => $now, 'update_user' => $user);
         try {
             $code->update($data, "id = " . $val->id);
             $result['info'] = "修改成功";
         } catch (Exception $e) {
             $result['result'] = false;
             $result['info'] = $e->getMessage();
             echo Zend_Json::encode($result);
             exit;
         }
     } else {
         // 检查是自动生成编码还是手动
         $typedata = $db->query("select t2.automethod from oa_doc_type t1 inner join oa_doc_auto t2 on t1.autotype=t2.id where t1.state = 1 and t1.id = " . $val->prefix)->fetchObject();
         if ($typedata && $typedata->automethod != 'H' && $typedata->automethod != 'A' && $typedata->automethod != 'F') {
             $auto_code = $this->getCode($val->prefix, $val->project_no);
             if (!$auto_code) {
                 $result['result'] = false;
                 $result['info'] = "文件编码获取失败";
                 echo Zend_Json::encode($result);
                 exit;
             }
         } else {
             if ($typedata && $typedata->automethod == 'A' && (!isset($val->code) || !$val->code)) {
                 $auto_code = "";
                 // 需发邮件
                 $mailId = '';
                 $type = "文件编码申请";
                 $subject = "文件号分配";
                 // $to =   文件管理员
                 $employee = new Hra_Model_Employee();
                 $member = new Admin_Model_Member();
                 $role = new Admin_Model_Role();
                 $toArr = array();
                 $roleArr = $role->getRoleIdByName('文件管理员');
                 $roleData = array();
                 if ($roleArr['role_id']) {
                     $roleData = $member->getMember($roleArr['role_id']);
                 }
                 foreach ($roleData as $r) {
                     if ($r['user_id'] == 1) {
                         continue;
                     }
                     $toArr[] = $r['email'];
                 }
                 $to = implode(',', $toArr);
                 if ($to) {
                     $emp = $employee->getInfoById($user);
                     $userName = '';
                     if (count($emp) > 0) {
                         $userName = $emp[0]['cname'];
                     }
                     $user_name = $user_session->user_info['user_name'];
                     $content = "<p>你有一个文件编码申请需要分配文件号</p>";
                     $content .= "<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' => $type, 'subject' => $subject, 'to' => $to, 'content' => $content, 'send_time' => $now, 'add_date' => $now);
                     $mail = new Application_Model_Log_Mail();
                     try {
                         $mailId = $mail->insert($mailData);
                     } catch (Exception $e) {
                     }
                     if ($mailId) {
                         $mail->send($mailId);
                     }
                 }
             } else {
                 if ($typedata && $typedata->automethod == 'F' && (!isset($val->code) || !$val->code)) {
                     // 流程
                     // 获取当前文件类别对应的流程ID
                     $row = $type->getList("id='{$val->prefix}'");
                     $flow_id = '';
                     if ($row && count($row) > 0) {
                         $flow_id = $row[0]['apply_flow_id'];
                     } else {
                         $result['info'] = "文件类型未设置审核流程";
                         echo Zend_Json::encode($result);
                         exit;
                     }
                     // 根据流程ID获取阶段
                     $flow = new Admin_Model_Flow();
                     $step = new Admin_Model_Step();
                     $member = new Admin_Model_Member();
                     $employee = new Hra_Model_Employee();
                     $mail = new Application_Model_Log_Mail();
                     $record = new Dcc_Model_Record();
                     $review = new Dcc_Model_Review();
                     $flowRow = $flow->getRow($flow_id);
                     $step_ids = $flowRow['step_ids'];
                     if ($step_ids) {
                         $data = array('prefix' => $val->prefix, 'code' => '', 'state' => 'Reviewing', 'active' => isset($val->active) ? 1 : 0, 'project_no' => $val->project_no, 'project_standard_no' => isset($val->project_standard_no) ? $val->project_standard_no : "", 'description' => $val->description, 'remark' => $val->remark, 'create_time' => $now, 'create_user' => $user, 'update_time' => $now, 'update_user' => $user);
                         try {
                             $id = $code->insert($data);
                             $inserted = true;
                             // 操作记录
                             $data = array('type' => "code_apply", 'table_name' => "oa_doc_code", 'table_id' => $id, 'handle_user' => $user, 'handle_time' => $now, 'action' => "申请", 'ip' => $_SERVER['REMOTE_ADDR']);
                             $record->insert($data);
                         } catch (Exception $e) {
                             $result['result'] = false;
                             $result['info'] = $e->getMessage();
                             echo Zend_Json::encode($result);
                             exit;
                         }
                         $stepRows = $step->getListByFlow($step_ids);
                         $state = "Reviewing";
                         // 把阶段信息插入review记录
                         $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 && !$plan_user) {
                                     $tmpUser = $member->getUserids("系统管理员");
                                 }
                                 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 ($users) {
                                     if ($plan_user) {
                                         $plan_user .= ",";
                                     }
                                     $plan_user .= $users;
                                 }
                             }
                             $repeatUser = explode(',', $plan_user);
                             $repeatUser = array_unique($repeatUser);
                             $plan_user = implode(',', $repeatUser);
                             $reviewData = array('type' => "code_apply", '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) {
                                 // 需发邮件
                                 $mailId = '';
                                 $type = "文件编码申请";
                                 $subject = "文件编码申请审核";
                                 $user_name = $user_session->user_info['user_name'];
                                 $to = $employee->getAdapter()->query("select group_concat(email) as mail_to from oa_employee where id in ( " . $plan_user . ")")->fetchObject();
                                 $content = "<p>你有一个文件编码申请需要审核</p>";
                                 $content .= "<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' => $type, 'subject' => $subject, 'to' => $to->mail_to, 'content' => $content, 'send_time' => $now, 'add_date' => $now);
                                 $mailId = $mail->insert($mailData);
                                 if ($mailId) {
                                     $mail->send($mailId);
                                 }
                             }
                             $first = false;
                         }
                         $result['info'] = "申请成功,已通知相关人员审核";
                         echo Zend_Json::encode($result);
                         exit;
                     }
                 } else {
                     $auto_code = $val->code;
                     // 检查是否文件号已经存在
                     if ($auto_code && $code->fetchAll("code = '" . $auto_code . "'")->count() > 0) {
                         $result['result'] = false;
                         $result['info'] = "文件编码“" . $val->code . "”已经存在";
                         echo Zend_Json::encode($result);
                         exit;
                     }
                 }
             }
         }
         $auto_code = strtoupper($auto_code);
         $data = array('prefix' => $val->prefix, 'code' => $auto_code, 'state' => isset($state) ? 'Reviewing' : 'Active', 'active' => isset($val->active) ? 1 : 0, 'project_no' => $val->project_no, 'project_standard_no' => isset($val->project_standard_no) ? $val->project_standard_no : "", 'description' => $val->description, 'remark' => $val->remark, 'create_time' => $now, 'create_user' => $user, 'update_time' => $now, 'update_user' => $user);
         try {
             $code->insert($data);
             if ($auto_code) {
                 $result['info'] = "申请成功,文件编码:{$auto_code}";
             } else {
                 $result['info'] = "申请成功,请通知管理员分配文件编码";
             }
         } catch (Exception $e) {
             $result['result'] = false;
             $result['info'] = $e->getMessage();
             echo Zend_Json::encode($result);
             exit;
         }
     }
     echo Zend_Json::encode($result);
     exit;
 }
Beispiel #10
0
 /**
  * @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;
 }