public function editcontactAction() { // 返回值数组 $result = array('success' => true, 'info' => '提交成功'); $request = $this->getRequest()->getParams(); // 操作类别(新建、更新、删除) $operate = isset($request['operate']) ? $request['operate'] : null; $customer_id = isset($request['customer_id']) ? $request['customer_id'] : null; $area_code = isset($request['area_code']) ? $request['area_code'] : null; $contact = new Erp_Model_Contact(); if ($operate == 'delete' && isset($request['id'])) { $contact->delete("id = " . $request['id']); } else { if ($area_code) { if ($operate && $customer_id) { if ($operate == 'new' && $contact->fetchAll("area_code = '" . $request['area_code'] . "'")->count() > 0 || $operate == 'edit' && $contact->fetchAll("id != " . $request['id'] . " and area_code = '" . $request['area_code'] . "'")->count() > 0) { $result['success'] = false; $result['info'] = '地址简码重复,操作失败!'; } else { $now = date('Y-m-d H:i:s'); $user_session = new Zend_Session_Namespace('user'); $user_id = $user_session->user_info['user_id']; $active = isset($request['active']) ? 1 : 0; $default = isset($request['default']) ? 1 : 0; $data = array('partner_id' => $customer_id, 'active' => $active, 'default' => $default, 'name' => $request['name'], 'post' => $request['post'], 'tel' => $request['tel'], 'fax' => $request['fax'], 'email' => $request['email'], 'remark' => $request['remark'], 'country' => $request['country'], 'area' => $request['area'], 'address' => $request['address'], 'zip_code' => $request['zip_code'], 'area_city' => $request['area_city'], 'area_code' => $request['area_code'], 'person_liable' => $request['person_liable']); /* echo '<pre>'; print_r($data); exit; */ if ($operate == 'new') { $contact_id = $contact->insert($data); } else { if ($operate == 'edit') { $contact_id = $request['id']; $contact->update($data, "id = " . $contact_id); } } // 更新非默认联系人 if ($default) { $contact->update(array('default' => 0), "id != " . $contact_id . " and partner_id = " . $customer_id); } } } else { $result['success'] = false; $result['info'] = '操作/客户ID为空,操作失败!'; } } else { $result['success'] = false; $result['info'] = '地址简码为空,操作失败!'; } } echo Zend_Json::encode($result); exit; }
/** * 根据业务伙伴ID获取联系方式列表 */ public function getcontactAction() { $data = array(); $request = $this->getRequest()->getParams(); $partner_id = isset($request['partner_id']) ? $request['partner_id'] : 0; if ($partner_id > 0) { $contact = new Erp_Model_Contact(); $record = $contact->fetchAll("partner_id = " . $partner_id)->toArray(); foreach ($record as $rec) { $active = $rec['active'] == 1 ? true : false; array_push($data, array('contact_id' => $rec['id'], 'contact_partner_id' => $rec['partner_id'], 'contact_active' => $active, 'contact_name' => $rec['name'], 'contact_post' => $rec['post'], 'contact_tel' => $rec['tel'], 'contact_fax' => $rec['fax'], 'contact_email' => $rec['email'], 'contact_country' => $rec['country'], 'contact_area' => $rec['area'], 'contact_address' => $rec['address'], 'contact_zip_code' => $rec['zip_code'], 'contact_remark' => $rec['remark'])); } } echo Zend_Json::encode($data); exit; }
/** * 根据业务伙伴ID获取联系方式列表 */ public function getcontactAction() { $data = array(); $request = $this->getRequest()->getParams(); $option = isset($request['option']) ? $request['option'] : 'data'; $partner_id = isset($request['partner_id']) ? $request['partner_id'] : 0; if ($partner_id > 0) { $contact = new Erp_Model_Contact(); $record = $contact->fetchAll("partner_id = " . $partner_id, 'CONVERT( name USING gbk )')->toArray(); if ($option == 'list') { foreach ($record as $rec) { $active = $rec['active'] == 1 ? true : false; $default = $rec['default'] == 1 ? true : false; array_push($data, array('id' => $rec['id'], 'partner_id' => $rec['partner_id'], 'active' => $active, 'default' => $default, 'name' => $rec['name'], 'post' => $rec['post'], 'tel' => $rec['tel'], 'fax' => $rec['fax'], 'email' => $rec['email'], 'country' => $rec['country'], 'area' => $rec['area'], 'address' => $rec['address'], 'zip_code' => $rec['zip_code'], 'remark' => $rec['remark'])); } } else { foreach ($record as $rec) { $active = $rec['active'] == 1 ? true : false; $default = $rec['default'] == 1 ? true : false; array_push($data, array('contact_id' => $rec['id'], 'contact_partner_id' => $rec['partner_id'], 'contact_active' => $active, 'contact_default' => $default, 'contact_name' => $rec['name'], 'contact_post' => $rec['post'], 'contact_tel' => $rec['tel'], 'contact_fax' => $rec['fax'], 'contact_email' => $rec['email'], 'contact_country' => $rec['country'], 'contact_area' => $rec['area'], 'contact_area_city' => $rec['area_city'], 'contact_area_code' => $rec['area_code'], 'contact_person_liable' => $rec['person_liable'], 'contact_address' => $rec['address'], 'contact_zip_code' => $rec['zip_code'], 'contact_remark' => $rec['remark'])); } } } echo Zend_Json::encode($data); exit; }