|
- <?php
-
- class operate_link
- {
- function execLink($operate)
- {
- $id = isset($_POST['link_id']) ? trim($_POST['link_id']) : '';//id
- $link_name = isset($_POST['link_name']) ? trim($_POST['link_name']) : '';//联系类别
- $contact_name = isset($_POST['contact_name']) ? trim($_POST['contact_name']) : '';//姓名
- $contact_mobile = isset($_POST['contact_mobile']) ? trim($_POST['contact_mobile']) : '';//手机
- $contact_telphone = isset($_POST['contact_telphone']) ? trim($_POST['contact_telphone']) : '';//固话
- $fax = isset($_POST['fax']) ? trim($_POST['fax']) : '';//传真
- $email = isset($_POST['email']) ? trim($_POST['email']) : '';//邮箱
- $remark = isset($_POST['remark']) ? trim($_POST['remark']) : '';//备注
- //$is_db 是否为数据库已存的
-
- if ($operate == 'insert') {
- $this->insertLink($link_name, $contact_name, $contact_mobile, $contact_telphone, $fax, $email, $remark);
- }
-
- if ($operate == 'delete') {
- $this->deleteLink($id);
- }
-
- if ($operate == 'update') {
- $this->updateLink($id, $link_name, $contact_name, $contact_mobile, $contact_telphone, $fax, $email, $remark);
- }
-
- if ($operate == 'select') {
- $this->selectLink($id);
- }
- }
-
- //增
- function insertLink($link_name, $contact_name, $contact_mobile, $contact_telphone, $fax, $email, $remark)
- {
-
- if(!isset($_COOKIE['memcache']))
- {
- $time = time();
- setcookie('memcache',$time,time()+36000,"/");
- $_COOKIE['memcache']=$time;
- }
-
- $key = $_COOKIE['memcache'];
-
- $link_memcache = get_memcache('ZHANGS_LINK' . $key);
-
- if (!$link_memcache) {
- $link_memcache = array();
- }
-
- $link_info = array();
- $link_info['link_name'] = $link_name;
- $link_info['contact_name'] = $contact_name;
- $link_info['contact_mobile'] = $contact_mobile;
- $link_info['contact_telphone'] = $contact_telphone;
- $link_info['fax'] = $fax;
- $link_info['email'] = $email;
- $link_info['remark'] = $remark;
- // $link_info['is_db'] = '0';//是否为数据库已存的 1已存 0未存
- // $link_info['cancel_flag'] = '0';//0有效,1无效
- // $link_info['is_update'] = '0';// 数据库数据是否需要更改 0不,1需要
- $link_memcache[] = $link_info;
- $id_array = array_keys($link_memcache);
- $link_info['link_id'] = (string)end($id_array);//返回id
- $link_memcache[$link_info['link_id']] = $link_info;
- set_memcache("ZHANGS_LINK" . $key,$link_memcache);
- $json['code'] = '0';
- $json['info'] = '保存成功';
- $json['list'] = $link_info;
- echo json_encode($json);
- exit();
- }
-
- //删
- function deleteLink($id)
- {
- $key = $_COOKIE['memcache'];
- $link_memcache = get_memcache('ZHANGS_LINK' . $key);
- // if ($link_memcache[$id]['is_db'] == '1') {
- // $link_memcache[$id]['cancel_flag'] = '1';
- // } else {
- unset($link_memcache[$id]);
- // }
-
- set_memcache("ZHANGS_LINK" . $key,$link_memcache);
- $json['code'] = '0';
- $json['info'] = '删除成功';
- echo json_encode($json);
- exit();
-
- }
-
- //改
- function updateLink($id, $link_name, $contact_name, $contact_mobile, $contact_telphone, $fax, $email, $remark)
- {
- $key = $_COOKIE['memcache'];
- $link_memcache = get_memcache('ZHANGS_LINK' . $key);
- $link_info = $link_memcache[$id];
- $link_info['link_name'] = $link_name;
- $link_info['contact_name'] = $contact_name;
- $link_info['contact_mobile'] = $contact_mobile;
- $link_info['contact_telphone'] = $contact_telphone;
- $link_info['fax'] = $fax;
- $link_info['email'] = $email;
- $link_info['remark'] = $remark;
- //$link_info['is_db'] = '1';//是否为数据库已存的 0已存 1未存
- // $link_info['cancel_flag'] = '0';//0有效,1无效
- $link_memcache[$id] = $link_info;
- // if($link_info['is_db'] == '1')
- // {
- // $link_info['is_update'] = '1';
- // }
- set_memcache("ZHANGS_LINK" . $key,$link_memcache);
-
- $json['code'] = '0';
- $json['info'] = '修改成功';
- $json['list'] = $link_info;
- echo json_encode($json);
- exit();
- }
-
- //查
- function selectLink($id)
- {
- $key = $_COOKIE['memcache'];
- $link_memcache = get_memcache('ZHANGS_LINK' . $key);
- $link_info = $link_memcache[$id];
- $json['code'] = '0';
- $json['info'] = '查询成功';
- $json['list'] = $link_info;
- echo json_encode($json);
- exit();
- }
- }
-
- $operate = trim($_POST['operate']);
-
- $operate_link = new operate_link();
- $operate_link->execLink($operate);
- $_COOKIE['user'];
- ?>
|