예제 #1
0
 public function getCanBeReturnQty($key = null)
 {
     $sql = $this->select()->setIntegrityCheck(false)->from(array('t1' => $this->_name), array('order_item_id', 'code', 'price', 'order_id', 'order_number', 'qty' => new Zend_Db_Expr("sum(t1.qty)")))->joinLeft(array('t2' => $this->_dbprefix . 'product_materiel'), "t1.code = t2.code", array('name', 'description'))->joinLeft(array('t3' => $this->_dbprefix . 'erp_pur_order'), "t1.order_number = t3.number", array('buyer_id'))->joinLeft(array('t4' => $this->_dbprefix . 'bpartner'), "t3.supplier_id = t4.id", array('supplier_code' => 'code', 'supplier_name' => new Zend_Db_Expr("case when t4.cname != '' then t4.cname else t4.ename end")))->joinLeft(array('t5' => $this->_dbprefix . 'erp_stock_receive_items'), "t1.receive_item_id = t5.id", array('unit', 'warehouse_code'))->joinLeft(array('t6' => $this->_dbprefix . 'erp_stock_receive'), "t5.receive_id = t6.id", array('receive_number' => 'number'))->where("t1.active = 1 and t1.locked = 0")->group(array("t1.order_id", "t1.code"));
     if ($key) {
         $sql->where("t1.code like '%" . $key . "%' or t1.order_number like '%" . $key . "%' or t2.name like '%" . $key . "%' or t2.description like '%" . $key . "%'");
     }
     $data = $this->fetchAll($sql)->toArray();
     $buyer = new Erp_Model_Purchse_Buyer();
     /* echo '<pre>';
        print_r($data);
        exit; */
     for ($i = 0; $i < count($data); $i++) {
         if ($data[$i]['buyer_id']) {
             $buyerData = $buyer->getData($data[$i]['buyer_id']);
             $data[$i]['order_buyer'] = $buyerData['cname'];
         }
     }
     return $data;
 }
예제 #2
0
 public function getprintAction()
 {
     $result = array('success' => true, 'info' => '');
     $request = $this->getRequest()->getParams();
     if (isset($request['id']) && isset($request['tpl_id'])) {
         $order = new Erp_Model_Purchse_Order();
         $buyer = new Erp_Model_Purchse_Buyer();
         $items = new Erp_Model_Purchse_Orderitems();
         $helper = new Application_Model_Helpers();
         $supplier_contact = new Erp_Model_Contact();
         $tax = new Erp_Model_Setting_Tax();
         $currency = new Erp_Model_Setting_Currency();
         $orderData = $order->getData(null, $request['id']);
         $itemsData = $items->getData($request['id']);
         $buyerData = $buyer->getData($orderData['buyer_id']);
         $supplierContactData = $supplier_contact->getData($orderData['supplier_contact_id']);
         $taxData = $tax->getData($orderData['supplier_tax_id']);
         $currencyData = $currency->getInfoByCode($orderData['currency']);
         $tpl = new Erp_Model_Tpl();
         $tplHtmlData = $tpl->fetchRow("id = " . $request['tpl_id'])->toArray();
         $tplHtml = $tplHtmlData['html'];
         $itemsHtml = '';
         $itemsHtml_en = '';
         $itemsHtml_other = '';
         $i = 0;
         foreach ($itemsData as $item) {
             $i++;
             $req_number = str_replace(',', '<br>', $item['items_req_number']);
             $itemsHtml .= '
                 <tr>
                     <td>' . $i . '</td>
                     <td>' . $item['items_code'] . '</td>
                     <td width="100px">' . $item['items_name'] . '</td>
                     <td width="150px">' . $item['items_description'] . '</td>
                     <td>' . $item['items_qty'] . '</td>
                     <td>' . $item['items_unit'] . '</td>
                     <td>' . $currencyData['symbol'] . $item['items_price'] . '</td>
                     <td>' . $currencyData['symbol'] . $item['items_total'] . '</td>
                     <td>' . $req_number . '</td>
                     <td>' . $item['items_request_date'] . '</td>
                     <td>' . $item['items_remark'] . '</td>
                 </tr>';
             $itemsHtml_en .= '
                 <tr>
                     <td>' . $i . '</td>
                     <td>' . $item['items_code'] . '</td>
                     <td width="100px" style="word-wrap:break-word;">' . $item['items_name'] . '</td>
                     <td width="150px" style="word-wrap:break-word;">' . $item['items_description'] . '</td>
                     <td>' . $item['items_qty'] . '</td>
                     <td>' . $item['items_unit'] . '</td>
                     <td>' . $currencyData['symbol'] . $item['items_price'] . '</td>
                     <td>' . $currencyData['symbol'] . $item['items_total'] . '</td>
                     <td>' . $req_number . '</td>
                     <td>' . $item['items_request_date'] . '</td>
                     <td>' . $item['items_remark'] . '</td>
                 </tr>';
             $itemsHtml_other .= '
                 <tr>
                     <td>' . $i . '</td>
                     <td>' . $item['items_code'] . '</td>
                     <td width="250px" style="word-wrap:break-word;">' . $item['items_name'] . ' [' . $item['items_description'] . ']</td>
                     <td>' . $item['items_qty'] . '</td>
                     <td>' . $item['items_unit'] . '</td>
                     <td>' . $currencyData['symbol'] . $item['items_price'] . '</td>
                     <td>' . $currencyData['symbol'] . $item['items_total'] . '</td>
                     <td>' . $req_number . '</td>
                     <td>' . $item['items_request_date'] . '</td>
                     <td>' . $item['items_remark'] . '</td>
                 </tr>';
         }
         $receive = array();
         if ($orderData['receiver_id']) {
             // 公司收货人
             $receiver = new Erp_Model_Warehouse_Warehousereceiver();
             $receiverData = $receiver->getData($orderData['receiver_id']);
             $receive['address'] = $receiverData['address'];
             $receive['address_en'] = $receiverData['address_en'];
             $receive['cname'] = $receiverData['cname'];
             $receive['ename'] = $receiverData['ename'];
             $receive['tel'] = $receiverData['tel'];
             $receive['fax'] = $receiverData['fax'];
         } else {
             // 客户收货人
             $receiverData = $supplier_contact->getDataByCode($orderData['customer_address_code']);
             $receive['address'] = $receiverData['address'];
             $receive['address_en'] = $receiverData['address'];
             $receive['cname'] = $receiverData['name'];
             $receive['ename'] = $receiverData['name'];
             $receive['tel'] = $receiverData['tel'];
             $receive['fax'] = $receiverData['fax'];
         }
         $orderInfo = array('order_symbol' => $currencyData['symbol'], 'company_name' => '成都欧飞凌通讯技术有限公司', 'company_tel' => '028-85161178', 'company_fax' => '028-85161176', 'company_address' => '成都市高新区云华路333号1-5栋 3层', 'company_logo' => HOME_PATH . '/public/images/company.png', 'company_tax' => '510198698882411', 'company_account' => '128904731510811', 'company_bank' => '招商银行成都分行高新支行', 'order_title' => '采 购 合 同', 'type' => ' - 物料原材料', 'number' => $orderData['number'], 'date' => date('Y-m-d', strtotime($orderData['create_time'])), 'contact_name' => $buyerData['cname'], 'contact_ename' => $buyerData['ename'], 'contact_tel' => $buyerData['tel'], 'contact_fax' => $buyerData['fax'], 'supplier_cname' => $orderData['supplier_cname'], 'supplier_ename' => $orderData['supplier_ename'], 'supplier_code' => $orderData['supplier_code'], 'supplier_bank_type' => $orderData['supplier_bank_type'], 'supplier_bank_account' => $orderData['supplier_bank_account'], 'supplier_address' => $supplierContactData['address'], 'supplier_contact_name' => $supplierContactData['name'], 'supplier_contact_tel' => $supplierContactData['tel'], 'supplier_contact_fax' => $supplierContactData['fax'], 'receive_address' => $receive['address'], 'receive_address_en' => $receive['address_en'], 'receive_cname' => $receive['cname'], 'receive_ename' => $receive['ename'], 'receive_tel' => $receive['tel'], 'receive_fax' => $receive['fax'], 'total_upper' => $helper->num2rmb($orderData['total']), 'total_lower' => $orderData['currency_rate'] != 1 ? $orderData['forein_total'] : $orderData['total'], 'supplier_tax' => $orderData['supplier_tax_num'], 'supplier_tax_name' => $taxData['name'], 'supplier_tax_rate' => $taxData['rate'], 'supplier_payment_days' => $orderData['supplier_payment'], 'settle_way' => $orderData['settle_way'], 'delvery_clause' => $orderData['delvery_clause'], 'manufacture' => $orderData['manufacture'], 'responsible' => $orderData['responsible'], 'table' => $itemsHtml, 'table_en' => $itemsHtml_en, 'table_other' => $itemsHtml_other, 'order_other_info' => $orderData['remark'], 'responsible' => $orderData['responsible'], 'order_title_en' => 'Purchase Order', 'order_title_other' => '设 备 类 采 购 合 同', 'company_name_en' => 'OPhylink Communication Technology Inc.');
         foreach ($orderInfo as $key => $val) {
             $tplHtml = str_replace('<tpl_' . $key . '>', $val, $tplHtml);
         }
         $result['info'] = $tplHtml;
     } else {
         $result['success'] = false;
     }
     /* echo $tplHtml;
        exit; */
     echo Zend_Json::encode($result);
     exit;
 }
예제 #3
0
파일: Order.php 프로젝트: xindalu/evolve
 public function getOrderStatistics($condition = array())
 {
     $sql = $this->select()->setIntegrityCheck(false)->from(array('t1' => $this->_name), array('order_price_tax' => 'price_tax', 'order_state' => new Zend_Db_Expr("case when t1.state = 0 then '审核中' when t1.state = 1 then '拒绝' else '批准' end"), 'order_create_time' => 'create_time', 'order_release_time' => 'release_time', 'order_buyer_id' => 'buyer_id', 'order_supplier_id' => 'supplier_id', 'order_date', 'order_number' => 'number', 'order_remark' => 'remark', 'order_currency' => 'currency', 'order_type_id' => 'type_id'))->joinLeft(array('t2' => $this->_dbprefix . 'user'), "t1.create_user = t2.id", array())->joinLeft(array('t3' => $this->_dbprefix . 'employee'), "t2.employee_id = t3.id", array('creater' => 'cname'))->joinLeft(array('t4' => $this->_dbprefix . 'user'), "t1.update_user = t4.id", array())->joinLeft(array('t5' => $this->_dbprefix . 'employee'), "t4.employee_id = t5.id", array('updater' => 'cname'))->joinLeft(array('t7' => $this->_dbprefix . 'erp_pur_type'), "t1.type_id = t7.id", array('order_type_name' => 'name'))->joinLeft(array('t8' => $this->_dbprefix . 'erp_pur_order_items'), "t1.id = t8.order_id", array('delivery_date', 'delivery_date_remark', 'active', 'id', 'order_id', 'request_date', 'code', 'name', 'description', 'remark', 'supplier_code', 'supplier_codename', 'supplier_description', 'warehouse_code', 'price', 'qty', 'unit', 'project_info', 'req_number'))->joinLeft(array('t9' => $this->_dbprefix . 'bpartner'), "t1.supplier_id = t9.id", array('order_supplier_code' => 'code', 'order_supplier_name' => new Zend_Db_Expr("case when t9.cname != '' then t9.cname else t9.ename end")))->joinLeft(array('t10' => $this->_dbprefix . 'bpartner_contact'), "t1.supplier_contact_id = t10.id", array('order_supplier_contact' => new Zend_Db_Expr("concat(t10.name, ' [', t10.tel, ']')")))->joinLeft(array('t11' => $this->_dbprefix . 'erp_pur_order_items_req'), "t11.order_item_id = t8.id", array('req_item_ids' => new Zend_Db_Expr("group_concat(t11.req_item_id)")))->joinLeft(array('t12' => $this->_dbprefix . 'erp_pur_req_items'), "t12.id = t11.req_item_id", array('qty_req' => new Zend_Db_Expr('sum(t12.qty)'), 'order_req_num', 'customer_address', 'customer_aggrement'))->where("t1.active = 1")->group("t8.id")->order(array('t1.number desc', 't1.create_time desc'));
     // 状态
     if ($condition['state'] != null) {
         $sql->where("t1.state = " . $condition['state']);
     }
     // 日前从
     if ($condition['date_from']) {
         $sql->where("t1.create_time >= '" . $condition['date_from'] . " 00:00:00'");
     }
     // 日期至
     if ($condition['date_to']) {
         $sql->where("t1.create_time <= '" . $condition['date_to'] . " 23:59:59'");
     }
     // 采购类别
     if ($condition['type']) {
         $type = json_decode($condition['type']);
         if (count($type)) {
             $type_con = "t1.type_id = " . $type[0];
             for ($i = 1; $i < count($type); $i++) {
                 $type_con .= " or t1.type_id = " . $type[$i];
             }
             $sql->where($type_con);
         }
     }
     // 需求部门
     if ($condition['dept']) {
         $dept = json_decode($condition['dept']);
         if (count($dept)) {
             $dept_con = "t8.dept_id = " . $dept[0];
             for ($i = 1; $i < count($dept); $i++) {
                 $dept_con .= " or t8.dept_id = " . $dept[$i];
             }
             $sql->where($dept_con);
         }
     }
     // 采购员
     if ($condition['buyer']) {
         $buyer = json_decode($condition['buyer']);
         if (count($buyer)) {
             $buyer_con = "t1.buyer_id = " . $buyer[0];
             for ($i = 1; $i < count($buyer); $i++) {
                 $buyer_con .= " or t1.buyer_id = " . $buyer[$i];
             }
             $sql->where($buyer_con);
         }
     }
     if ($condition['key']) {
         $sql->where("t9.code like '%" . $condition['key'] . "%' or t9.cname like '%" . $condition['key'] . "%' or t9.ename like '%" . $condition['key'] . "%' or t3.cname like '%" . $condition['key'] . "%' or t3.ename like '%" . $condition['key'] . "%' or t1.number like '%" . $condition['key'] . "%' or t1.remark like '%" . $condition['key'] . "%' or t3.cname like '%" . $condition['key'] . "%' or t3.ename like '%" . $condition['key'] . "%' or t7.name like '%" . $condition['key'] . "%' or t8.code like '%" . $condition['key'] . "%' or t8.name like '%" . $condition['key'] . "%' or t8.description like '%" . $condition['key'] . "%'");
     }
     $total = $this->fetchAll($sql)->count();
     /* echo $sql;
        exit; */
     if ($condition['option'] != 'csv') {
         $sql->limitPage($condition['page'], $condition['limit']);
     }
     $data = $this->fetchAll($sql)->toArray();
     //echo '<pre>';print_r($data);exit;
     $items_receive = new Erp_Model_Purchse_Receiveitemsorder();
     $items_invoice = new Erp_Model_Purchse_Invoiceitems();
     $buyer = new Erp_Model_Purchse_Buyer();
     $req = new Erp_Model_Purchse_Req();
     $operateModel = new Application_Model_Log_Operate();
     $receiveModel = new Erp_Model_Purchse_Reqitemsreceived();
     for ($i = 0; $i < count($data); $i++) {
         // 入库日志
         $in_stock_info = $receiveModel->getReceivedInfo('order', $data[$i]['id']);
         $data[$i]['in_stock_qty'] = $in_stock_info['qty'];
         $data[$i]['in_stock_info'] = implode(',', $in_stock_info['info']);
         // 交期回复日志
         if ($data[$i]['delivery_date'] != '' || $data[$i]['delivery_date_remark'] != '') {
             $logInfo = array();
             $log = $operateModel->getLogByOperateAndTargetId('采购交期回复', $data[$i]['id']);
             foreach ($log as $l) {
                 $content = Zend_Json::decode($l['content']);
                 $logText = $content['time'] . ' [' . $content['delivery_date'] . '] [' . $content['delivery_date_remark'] . '] ' . $content['user'];
                 array_push($logInfo, $logText);
             }
             $data[$i]['delivery_reply_log'] = implode(',', $logInfo);
         }
         // 获取采购申请数量(合并下单的申请分拆显示)
         $data[$i]['req_info'] = '';
         if ($data[$i]['req_item_ids'] != '') {
             $item_ids = explode(',', $data[$i]['req_item_ids']);
             $req_item_data = $req->getReqQty($item_ids);
             $reqInfoArr = array();
             foreach ($req_item_data as $req_info) {
                 array_push($reqInfoArr, $req_info['number'] . ' [' . $req_info['qty'] . '] [' . $req_info['time'] . ']');
             }
             $data[$i]['req_info'] = implode(',', $reqInfoArr);
         }
         $data[$i]['order_supplier'] = $data[$i]['order_supplier_code'] . $data[$i]['order_supplier_name'];
         $data[$i]['qty_receive'] = 0;
         $data[$i]['receive_info'] = '';
         if ($data[$i]['id']) {
             if ($data[$i]['code'] != '') {
                 // 已收货物料:从采购收货
                 $receiveData = $items_receive->getOrderItemReceivedQty($data[$i]['id']);
                 $receiveInfoArr = array();
                 foreach ($receiveData as $r) {
                     $data[$i]['qty_receive'] += $r['qty'];
                     array_push($receiveInfoArr, $r['number'] . ' [' . $r['qty'] . '] [' . $r['time'] . ']');
                 }
                 $data[$i]['receive_info'] = implode(',', $receiveInfoArr);
             } else {
                 // 已收货非物料:从采购发票
                 $data[$i]['qty_receive'] = $items_invoice->getQty($data[$i]['id'], 1);
             }
         }
         $data[$i]['qty_left'] = $data[$i]['qty'] - $data[$i]['qty_receive'];
         $buyerData = $buyer->getData($data[$i]['order_buyer_id']);
         $data[$i]['order_buyer_name'] = isset($buyerData['cname']) ? $buyerData['cname'] : '';
     }
     if ($condition['option'] == 'csv') {
         $data_csv = array();
         $showPrice = false;
         if (Application_Model_User::checkPermissionByRoleName('系统管理员') || Application_Model_User::checkPermissionByRoleName('采购人员') || Application_Model_User::checkPermissionByRoleName('财务人员')) {
             $showPrice = true;
         }
         if ($showPrice) {
             $title = array('cnt' => '#', 'active' => '启用', 'order_number' => '订单号', 'order_state' => '订单状态', 'order_date' => '订单日期', 'order_buyer_name' => '采购员', 'order_type_name' => '类别', 'order_supplier_code' => '供应商代码', 'order_supplier_name' => '供应商名称', 'code' => '物料号', 'price' => '价格', 'order_price_tax' => '含税', 'qty' => '订单数量', 'qty_req' => '申请数量', 'qty_receive' => '到货数量', 'receive_info' => '到货信息', 'in_stock_qty' => '入库数量', 'in_stock_info' => '入库信息', 'qty_left' => '未到货数量', 'request_date' => '需求交期', 'delivery_date' => '预计交期', 'delivery_date_remark' => '交期备注', 'order_req_num' => '订货产品出库申请号', 'customer_address' => '客户收件人地址简码', 'customer_aggrement' => '客户合同号', 'name' => '名称', 'description' => '描述', 'req_info' => '申购单号', 'remark' => '备注', 'order_create_date' => '下单日期', 'order_create_time' => '下单时间', 'order_release_date' => '批准日期', 'order_release_time' => '批准时间');
         } else {
             $title = array('cnt' => '#', 'active' => '启用', 'order_number' => '订单号', 'order_state' => '订单状态', 'order_date' => '订单日期', 'order_buyer_name' => '采购员', 'order_type_name' => '类别', 'order_supplier_code' => '供应商代码', 'order_supplier_name' => '供应商名称', 'code' => '物料号', 'qty' => '订单数量', 'qty_req' => '申请数量', 'qty_receive' => '到货数量', 'receive_info' => '到货信息', 'in_stock_qty' => '入库数量', 'in_stock_info' => '入库信息', 'qty_left' => '未到货数量', 'request_date' => '需求交期', 'delivery_date' => '预计交期', 'delivery_date_remark' => '交期备注', 'order_req_num' => '订货产品出库申请号', 'customer_address' => '客户收件人地址简码', 'customer_aggrement' => '客户合同号', 'name' => '名称', 'description' => '描述', 'req_info' => '申购单号', 'remark' => '备注', 'order_create_date' => '下单日期', 'order_create_time' => '下单时间', 'order_release_date' => '批准日期', 'order_release_time' => '批准时间');
         }
         array_push($data_csv, $title);
         $i = 0;
         foreach ($data as $d) {
             $i++;
             if ($showPrice) {
                 $info = array('cnt' => $i, 'active' => $d['active'] == 1 ? '是' : '否', 'order_number' => $d['order_number'], 'order_state' => $d['order_state'], 'order_date' => $d['order_date'], 'order_buyer_name' => $d['order_buyer_name'], 'order_type_name' => $d['order_type_name'], 'order_supplier_code' => $d['order_supplier_code'], 'order_supplier_name' => $d['order_supplier_name'], 'code' => $d['code'], 'price' => $d['price'], 'order_price_tax' => $d['order_price_tax'] == 1 ? '是' : '否', 'qty' => $d['qty'], 'qty_req' => $d['qty_req'], 'qty_receive' => $d['qty_receive'], 'receive_info' => $d['receive_info'], 'in_stock_qty' => $d['in_stock_qty'], 'in_stock_info' => $d['in_stock_info'], 'qty_left' => $d['qty_left'], 'request_date' => $d['request_date'], 'delivery_date' => $d['delivery_date'], 'delivery_date_remark' => $d['delivery_date_remark'], 'order_req_num' => $d['order_req_num'], 'customer_address' => $d['customer_address'], 'customer_aggrement' => $d['customer_aggrement'], 'name' => $d['name'], 'description' => $d['description'], 'req_info' => $d['req_info'], 'remark' => $d['remark'], 'order_create_date' => $d['order_create_time'] != '' ? date('Y-m-d', strtotime($d['order_create_time'])) : '', 'order_create_time' => $d['order_create_time'] != '' ? date('H:i:s', strtotime($d['order_create_time'])) : '', 'order_release_date' => $d['order_release_time'] != '' ? date('Y-m-d', strtotime($d['order_release_time'])) : '', 'order_release_time' => $d['order_release_time'] != '' ? date('H:i:s', strtotime($d['order_release_time'])) : '');
             } else {
                 $info = array('cnt' => $i, 'active' => $d['active'] == 1 ? '是' : '否', 'order_number' => $d['order_number'], 'order_state' => $d['order_state'], 'order_date' => $d['order_date'], 'order_buyer_name' => $d['order_buyer_name'], 'order_type_name' => $d['order_type_name'], 'order_supplier_code' => $d['order_supplier_code'], 'order_supplier_name' => $d['order_supplier_name'], 'code' => $d['code'], 'qty' => $d['qty'], 'qty_req' => $d['qty_req'], 'qty_receive' => $d['qty_receive'], 'receive_info' => $d['receive_info'], 'in_stock_qty' => $d['in_stock_qty'], 'in_stock_qty' => $d['in_stock_info'], 'qty_left' => $d['qty_left'], 'request_date' => $d['request_date'], 'delivery_date' => $d['delivery_date'], 'delivery_date_remark' => $d['delivery_date_remark'], 'order_req_num' => $d['order_req_num'], 'customer_address' => $d['customer_address'], 'customer_aggrement' => $d['customer_aggrement'], 'name' => $d['name'], 'description' => $d['description'], 'req_info' => $d['req_info'], 'remark' => $d['remark'], 'order_create_date' => $d['order_create_time'] != '' ? date('Y-m-d', strtotime($d['order_create_time'])) : '', 'order_create_time' => $d['order_create_time'] != '' ? date('H:i:s', strtotime($d['order_create_time'])) : '', 'order_release_date' => $d['order_release_time'] != '' ? date('Y-m-d', strtotime($d['order_release_time'])) : '', 'order_release_time' => $d['order_release_time'] != '' ? date('H:i:s', strtotime($d['order_release_time'])) : '');
             }
             array_push($data_csv, $info);
         }
         return $data_csv;
     }
     return array('total' => $total, 'rows' => $data);
 }
예제 #4
0
 public function reviewAction()
 {
     // 返回值数组
     $result = array('success' => true, 'info' => '审核成功');
     $request = $this->getRequest()->getParams();
     $review_id = isset($request['review_id']) ? $request['review_id'] : null;
     //$review_type_id = isset($request['review_type_id']) ? $request['review_type_id'] : null;
     $review_operate = isset($request['review_operate']) ? $request['review_operate'] : null;
     $review_current_step = isset($request['review_current_step']) ? $request['review_current_step'] : null;
     // 当前阶段(review表ID)
     $review_last_step = isset($request['review_last_step']) ? $request['review_last_step'] : null;
     // 是否当前阶段为最后一阶段
     $review_to_finish = isset($request['review_to_finish']) ? $request['review_to_finish'] : null;
     // 是否批准后当前阶段结束
     $review_next_step = isset($request['review_next_step']) ? $request['review_next_step'] : null;
     // 下一阶段(review表ID)
     $review_remark = isset($request['review_remark']) ? $request['review_remark'] : null;
     $review_transfer_user = isset($request['review_transfer_user']) ? $request['review_transfer_user'] : null;
     //转审人
     $review_transfer = $request['review_transfer'] == 1 ? true : false;
     if ($review_id && $review_operate) {
         $transfer = new Erp_Model_Purchse_Transfer();
         $now = date('Y-m-d H:i:s');
         $user_session = new Zend_Session_Namespace('user');
         $user_id = $user_session->user_info['user_id'];
         $employee_id = $user_session->user_info['employee_id'];
         // 评审意见
         $review_info = '意见: ' . $review_remark;
         $req = new Erp_Model_Purchse_Req();
         $user = new Application_Model_User();
         $review = new Dcc_Model_Review();
         $employee = new Hra_Model_Employee();
         $reqData = $req->getData(null, $review_id);
         // 更新审核状态及审核意见
         if ($review_operate == 'transfer') {
             // 转审
             $review_info = $reqData['review_info'] . '<br>' . $now . ': ' . $user_session->user_info['user_name'] . ' [审核-转审] [' . $review_info . ']';
             $req->update(array('review_info' => $review_info), "id = " . $review_id);
             $reviewState = $review->fetchRow("type = 'purchse_req_add' and finish_flg = 0 and file_id = " . $review_id, "id")->toArray();
             // 转审对象
             $transferUserInfo = $user->getEmployeeInfoById($review_transfer_user);
             $reviewUsers = $reviewState['plan_user'];
             $reviewUserArr = explode(',', $reviewUsers);
             $reviewer = array();
             if ($reviewState['method'] == 2) {
                 // 任意: 直接替换审核人为转审对象
                 foreach ($reviewUserArr as $review_user) {
                     if ($review_user == $employee_id) {
                         array_push($reviewer, $transferUserInfo['id']);
                     }
                 }
             } else {
                 // 全部: 替换当前审核人为转审对象,其余审核人保留
                 foreach ($reviewUserArr as $review_user) {
                     if ($review_user == $employee_id) {
                         array_push($reviewer, $transferUserInfo['id']);
                     } else {
                         if (!in_array($review_user, $reviewer)) {
                             array_push($reviewer, $review_user);
                         }
                     }
                 }
             }
             $reviewerstr = implode(',', $reviewer);
             $review->update(array('plan_user' => $reviewerstr), "id = " . $reviewState['id']);
             // 发送邮件通知制单人
             $reviewResult = '<font style="color: #FF0000"><b>转审</b></font>';
             $mail = new Application_Model_Log_Mail();
             $to = $transferUserInfo['email'];
             $mailContent = '<div>采购申请审核:</div>
                             <div>
                             <p><b>审核人:</b>' . $user_session->user_info['user_name'] . '</p>
                             <p><b>审核结果:</b>' . $reviewResult . '</p>
                             <p><b>审核意见:</b>' . $review_remark . '</p>
                             <p><b>申请单号:</b>' . $reqData['number'] . '</p>
                             <p><b>申请部门:</b>' . $reqData['dept'] . '</p>
                             <p><b>申请人:</b>' . $reqData['apply_user_name'] . '</p>
                             <p><b>制单人:</b>' . $reqData['creater'] . '</p>
                             <p><b>类别:</b>' . $reqData['type'] . '</p>
                             <p><b>事由:</b>' . $reqData['reason'] . '</p>
                             <p><b>金额:</b><a style="color: #467500;font-weight: bold;">¥' . round($reqData['total'], 2) . '</a></p>
                             <p><b>备注:</b>' . $reqData['remark'] . '</p>
                             <p><b>制单时间:</b>' . $reqData['create_time'] . '</p>
                             <p><b>更新时间:</b>' . $reqData['update_time'] . '</p>
                             <hr>
                             <p><b>审核日志:</b></p><p>' . $reqData['review_info'] . '</p>
                             </div>';
             $mailData = array('type' => '消息', 'subject' => '采购申请-转审', 'to' => $to, 'cc' => $user_session->user_info['user_email'], 'user_id' => $user_session->user_info['user_id'], 'content' => $mailContent, 'add_date' => $now);
             try {
                 // 记录邮件日志并发送邮件
                 $mail->send($mail->insert($mailData));
             } catch (Exception $e) {
                 $result['success'] = false;
                 $result['info'] = $e->getMessage();
             }
         } else {
             if ($review_operate == 'no') {
                 // 更新采购申请状态
                 $review_info = $now . ': ' . $user_session->user_info['user_name'] . ' [审核-拒绝] [' . $review_info . ']';
                 $data = array('state' => 1, 'transfer_description' => null, 'review_info' => $reqData['review_info'] . '<br>' . $review_info);
                 $req->update($data, "id = " . $review_id);
                 if ($review_transfer) {
                     $transfer->update(array('state' => 1), "id = " . $reqData['transfer_id']);
                 }
                 // 删除当前申请的审核配置
                 $review->delete("type = 'purchse_req_add' and file_id = " . $review_id);
                 // 发送邮件通知制单人
                 $reviewResult = '<font style="color: #FF0000"><b>拒绝</b></font>';
                 $mail = new Application_Model_Log_Mail();
                 $applyEmployeeData = $user->fetchRow("id = " . $reqData['create_user'])->toArray();
                 $applyEmployee = $employee->fetchRow("id = " . $applyEmployeeData['employee_id'])->toArray();
                 $to = $applyEmployee['email'];
                 $mailContent = '<div>采购申请审核:</div>
                             <div>
                             <p><b>审核人:</b>' . $user_session->user_info['user_name'] . '</p>
                             <p><b>审核结果:</b>' . $reviewResult . '</p>
                             <p><b>审核意见:</b>' . $review_remark . '</p>
                             <p><b>申请单号:</b>' . $reqData['number'] . '</p>
                             <p><b>申请部门:</b>' . $reqData['dept'] . '</p>
                             <p><b>申请人:</b>' . $reqData['apply_user_name'] . '</p>
                             <p><b>制单人:</b>' . $reqData['creater'] . '</p>
                             <p><b>类别:</b>' . $reqData['type'] . '</p>
                             <p><b>事由:</b>' . $reqData['reason'] . '</p>
                             <p><b>金额:</b><a style="color: #467500;font-weight: bold;">¥' . round($reqData['total'], 2) . '</a></p>
                             <p><b>备注:</b>' . $reqData['remark'] . '</p>
                             <p><b>制单时间:</b>' . $reqData['create_time'] . '</p>
                             <p><b>更新时间:</b>' . $reqData['update_time'] . '</p>
                             <hr>
                             <p><b>审核日志:</b></p><p>' . $reqData['review_info'] . '</p>
                             </div>';
                 $mailData = array('type' => '消息', 'subject' => '采购申请-审核', 'to' => $to, 'cc' => $user_session->user_info['user_email'], 'user_id' => $reqData['create_user'], 'content' => $mailContent, 'add_date' => $now);
                 try {
                     // 记录邮件日志并发送邮件
                     $mail->send($mail->insert($mailData));
                 } catch (Exception $e) {
                     $result['success'] = false;
                     $result['info'] = $e->getMessage();
                 }
             } else {
                 $help = new Application_Model_Helpers();
                 $review_info = $now . ': ' . $user_session->user_info['user_name'] . ' [审核-批准] [' . $review_info . ']';
                 $reqUpdateData = array('review_info' => $reqData['review_info'] . '<br>' . $review_info);
                 $reviewData = $review->fetchRow("id = " . $review_current_step)->toArray();
                 $actual_user = $reviewData['actual_user'] == '' ? $user_session->user_info['employee_id'] : $reviewData['actual_user'] . ',' . $user_session->user_info['employee_id'];
                 $data = array('actual_user' => $actual_user, 'finish_time' => $now, 'finish_flg' => 1);
                 // 当前审核阶段为最后一阶段
                 if ($review_last_step == 1) {
                     // 当前阶段已完结
                     if ($review_to_finish == 1) {
                         if ($review_transfer) {
                             if ($reqData['transfer_type'] == '取消') {
                                 $this->cancelReq($review_id);
                             } else {
                                 $this->approveTransferUpdateItems($reqData['transfer_id']);
                             }
                             $transfer->update(array('state' => 2), "id = " . $reqData['transfer_id']);
                         }
                         $data = array('actual_user' => $actual_user, 'finish_time' => $now, 'finish_flg' => 1);
                         $reviewResult = '<font style="color: #006400"><b>发布</b></font>';
                         // 发布
                         // 更新申请状态
                         $reqUpdateData['state'] = 2;
                         $reqUpdateData['transfer_description'] = null;
                         $reqUpdateData['release_time'] = $now;
                         // 更新审核记录表
                         $review->update($data, "id = " . $review_current_step);
                         $mail = new Application_Model_Log_Mail();
                         $applyEmployeeData = $user->fetchRow("id = " . $reqData['create_user'])->toArray();
                         $applyEmployee = $employee->fetchRow("id = " . $applyEmployeeData['employee_id'])->toArray();
                         $to = $applyEmployee['email'];
                         $cc = $user_session->user_info['user_email'];
                         // 发布通知采购员
                         $buyer = new Erp_Model_Purchse_Buyer();
                         $buyerData = $buyer->getData();
                         foreach ($buyerData as $b) {
                             $cc .= ',' . $b['email'];
                         }
                         $mailContent = '<div>采购申请审核批准,请登录系统查看:</div>
                             <div>
                             <p><b>审核人:</b>' . $user_session->user_info['user_name'] . '</p>
                             <p><b>审核结果:</b>' . $reviewResult . '</p>
                             <p><b>审核意见:</b>' . $review_remark . '</p>
                             <p><b>申请单号:</b>' . $reqData['number'] . '</p>
                             <p><b>申请部门:</b>' . $reqData['dept'] . '</p>
                             <p><b>申请人:</b>' . $reqData['apply_user_name'] . '</p>
                             <p><b>制单人:</b>' . $reqData['creater'] . '</p>
                             <p><b>类别:</b>' . $reqData['type'] . '</p>
                             <p><b>事由:</b>' . $reqData['reason'] . '</p>
                             <p><b>金额:</b><a style="color: #467500;font-weight: bold;">¥' . round($reqData['total'], 2) . '</a></p>
                             <p><b>备注:</b>' . $reqData['remark'] . '</p>
                             <p><b>制单时间:</b>' . $reqData['create_time'] . '</p>
                             <p><b>更新时间:</b>' . $reqData['update_time'] . '</p>
                             <hr>
                             <p><b>审核日志:</b></p><p>' . $reqUpdateData['review_info'] . '</p>
                             </div>';
                         $mailData = array('type' => '消息', 'subject' => '采购申请-发布', 'to' => $to, 'cc' => $cc, 'user_id' => $reqData['create_user'], 'content' => $mailContent, 'add_date' => $now);
                         try {
                             // 记录邮件日志并发送邮件
                             $mail->send($mail->insert($mailData));
                         } catch (Exception $e) {
                             $result['success'] = false;
                             $result['info'] = $e->getMessage();
                         }
                     } else {
                         $data = array('actual_user' => $actual_user);
                         $review->update($data, "id = " . $review_current_step);
                         // 等待其他审核人批准
                     }
                 } else {
                     // 当前阶段已完结
                     if ($review_to_finish == 1) {
                         $data = array('actual_user' => $actual_user, 'finish_time' => $now, 'finish_flg' => 1);
                         $reviewResult = '<font style="color: #006400"><b>批准</b></font>';
                         // 进入下一阶段
                         // 更新审核记录表
                         $review->update($data, "id = " . $review_current_step);
                         // 邮件通知下一阶段审核人
                         $reviewNextStepData = $review->fetchRow("id = " . $review_next_step)->toArray();
                         $mailTo = explode(',', $reviewNextStepData['plan_user']);
                         if ($mailTo) {
                             $mailContent = '<div>新建采购申请,请登录系统查看:</div>
                                         <div>
                                         <p><b>申请单号:</b>' . $reqData['number'] . '</p>
                                         <p><b>申请部门:</b>' . $reqData['dept'] . '</p>
                                         <p><b>申请人:</b>' . $reqData['apply_user_name'] . '</p>
                                         <p><b>制单人:</b>' . $reqData['creater'] . '</p>
                                         <p><b>类别:</b>' . $reqData['type'] . '</p>
                                         <p><b>事由:</b>' . $reqData['reason'] . '</p>
                                         <p><b>金额:</b><a style="color: #467500;font-weight: bold;">¥' . round($reqData['total'], 2) . '</a></p>
                                         <p><b>备注:</b>' . $reqData['remark'] . '</p>
                                         <p><b>制单时间:</b>' . $reqData['create_time'] . '</p>
                                         <p><b>更新时间:</b>' . $reqData['update_time'] . '</p>
                                         <hr>
                                         <p><b>审核日志:</b></p><p>' . $reqUpdateData['review_info'] . '</p>
                                         </div>';
                             $mailData = array('type' => '消息', 'subject' => '采购申请-新申请', 'cc' => $user_session->user_info['user_email'], 'content' => $mailContent, 'add_date' => $now);
                             $resultMail = $help->sendMailToStep($mailTo, $mailData);
                             if (!$resultMail['success']) {
                                 $result = $resultMail;
                             }
                         }
                     } else {
                         $data = array('actual_user' => $actual_user);
                         $review->update($data, "id = " . $review_current_step);
                         // 等待其他审核人批准
                     }
                 }
                 // 更新申请状态
                 $req->update($reqUpdateData, "id = " . $review_id);
             }
         }
     }
     echo Zend_Json::encode($result);
     exit;
 }