예제 #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;
 }
예제 #2
0
 /**
  * 获取流程
  */
 public function getflowforcomboAction()
 {
     $flow = new Admin_Model_Flow();
     $data = $flow->getBomListForCombo();
     echo Zend_Json::encode($data);
     exit;
 }
예제 #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;
    }
예제 #4
0
 /**
  * @abstract    删除
  * @return      null
  */
 public function removeAction()
 {
     // 返回值数组
     $result = array('success' => true, 'info' => '删除成功');
     $request = $this->getRequest()->getParams();
     $json = json_decode($request['json']);
     $deleted = $json->deleted;
     $flow = new Admin_Model_Flow();
     if (count($deleted) > 0) {
         foreach ($deleted as $val) {
             try {
                 $flow->delete("id = " . $val->id);
             } catch (Exception $e) {
                 $result['result'] = false;
                 $result['info'] = $e->getMessage();
                 echo Zend_Json::encode($result);
                 exit;
             }
         }
     }
     echo Zend_Json::encode($result);
     exit;
 }
예제 #5
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;
     }
 }
예제 #6
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;
    }
예제 #7
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;
 }
예제 #8
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;
     }
 }
예제 #9
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;
     }
 }
예제 #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'];
     $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;
 }