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; }
/** * 保存业务伙伴的联系人及地址信息 */ public function editlistinfoAction() { // 返回值数组 $result = array('success' => true, 'info' => '编辑成功'); $request = $this->getRequest()->getParams(); $now = date('Y-m-d H:i:s'); $user_session = new Zend_Session_Namespace('user'); $user_id = $user_session->user_info['user_id']; $json = json_decode($request['json']); $partner_id = $json->partner_id; $json_contact = $json->contact; $contact_updated = $json_contact->updated; $contact_inserted = $json_contact->inserted; $contact_deleted = $json_contact->deleted; $contact = new Erp_Model_Contact(); // 更新联系人 if (count($contact_updated) > 0) { foreach ($contact_updated as $val) { $active = $val->contact_active ? 1 : 0; $default = $val->contact_default ? 1 : 0; $data = array('active' => $active, 'default' => $default, 'name' => $val->contact_name, 'post' => $val->contact_post, 'tel' => $val->contact_tel, 'fax' => $val->contact_fax, 'email' => $val->contact_email, 'country' => $val->contact_country, 'area' => $val->contact_area, 'area_city' => $val->contact_area_city, 'area_code' => $val->contact_area_code, 'person_liable' => $val->contact_person_liable, 'address' => $val->contact_address, 'zip_code' => $val->contact_zip_code, 'remark' => $val->contact_remark); try { $contact->update($data, "id = " . $val->contact_id); } catch (Exception $e) { $result['result'] = false; $result['info'] = $e->getMessage(); echo Zend_Json::encode($result); exit; } } } // 插入联系人 if (count($contact_inserted) > 0) { foreach ($contact_inserted as $val) { $active = $val->contact_active ? 1 : 0; $default = $val->contact_default ? 1 : 0; $data = array('partner_id' => $partner_id, 'active' => $active, 'default' => $default, 'name' => $val->contact_name, 'post' => $val->contact_post, 'tel' => $val->contact_tel, 'fax' => $val->contact_fax, 'email' => $val->contact_email, 'country' => $val->contact_country, 'area' => $val->contact_area, 'area_city' => $val->contact_area_city, 'area_code' => $val->contact_area_code, 'person_liable' => $val->contact_person_liable, 'address' => $val->contact_address, 'zip_code' => $val->contact_zip_code, 'remark' => $val->contact_remark); try { $contact->insert($data); } catch (Exception $e) { $result['result'] = false; $result['info'] = $e->getMessage(); echo Zend_Json::encode($result); exit; } } } // 删除联系人 if (count($contact_deleted) > 0) { foreach ($contact_deleted as $val) { try { $contact->delete("id = " . $val->contact_id); } catch (Exception $e) { $result['result'] = false; $result['info'] = $e->getMessage(); echo Zend_Json::encode($result); exit; } } } echo Zend_Json::encode($result); exit; }