|
- <?php
-
- class operate_sale
- {
- function execSale($operate)
- {
- $sale_id = isset($_POST['sale_id']) ? trim($_POST['sale_id']) : '';//id
- $prod_supplier_id = isset($_POST['prod_supplier_id']) ? trim($_POST['prod_supplier_id']) : '0';//供应商id
- $product_type = isset($_POST['product_type']) ? trim($_POST['product_type']) : '0';//产品子类(二级类)
- $parent_type = isset($_POST['parent_type']) ? trim($_POST['parent_type']) : '0';//产品父类(一级类)
- $sale_type = isset($_POST['sale_type']) ? trim($_POST['sale_type']) : '0';//销售方式
- $commision_flag = isset($_POST['commision_flag']) ? trim($_POST['commision_flag']) : '0';//是否有佣金规则,1:有,0:无
- $commision_type = isset($_POST['commision_type']) ? trim($_POST['commision_type']) : '0';//佣金类别
- $back_commision_type = isset($_POST['back_commision_type']) ? ($_POST['back_commision_type'] == '' ? '0' : trim($_POST['back_commision_type'])) : '0';//返佣类别
- $back_commision_method = isset($_POST['back_commision_method']) ? ($_POST['back_commision_method'] == '' ? '0' : trim($_POST['back_commision_method'])) : '0';//返佣方式
- $back_percent = isset($_POST['back_percent']) ? trim($_POST['back_percent']) : '0';//返佣比例
- $back_value = isset($_POST['back_value']) ? trim($_POST['back_value']) : '0';//返佣固定金额
-
- //$is_db 是否为数据库已存的
-
- if ($operate == 'insert') {
- $this->insertSale($prod_supplier_id, $product_type, $parent_type, $sale_type, $commision_flag, $commision_type, $back_commision_type, $back_commision_method, $back_percent, $back_value);
- }
-
- if ($operate == 'delete') {
- $this->deleteSale($sale_id);
- }
-
- if ($operate == 'update') {
- $this->updateSale($sale_id, $prod_supplier_id, $product_type, $parent_type, $sale_type, $commision_flag, $commision_type, $back_commision_type, $back_commision_method, $back_percent, $back_value);
- }
-
- if ($operate == 'select') {
- $this->selectSale($sale_id);
- }
- }
-
- //增
- function insertSale($prod_supplier_id, $product_type, $parent_type, $sale_type, $commision_flag, $commision_type, $back_commision_type, $back_commision_method, $back_percent, $back_value)
- {
- if (!isset($_COOKIE['memcache'])) {
- $time = time();
- setcookie('memcache', $time, time() + 36000, "/");
- $_COOKIE['memcache'] = $time;
- }
-
- $key = $_COOKIE['memcache'];
- $sale_memcache = get_memcache('ZHANGS_SALE' . $key);
-
- if (!$sale_memcache) {
- $sale_memcache = array();
- }
-
- if ($back_percent == '' || $back_value == '') {
- $json['code'] = '1';
- $json['info'] = '请完整填写佣金规则';
- echo json_encode($json);
- exit();
- }
-
- $sale_info = array();
- $sale_info['prod_supplier_id'] = $prod_supplier_id;
- $sale_info['product_type'] = $product_type;
- $sale_info['parent_type'] = $parent_type;
- $sale_info['sale_type'] = $sale_type;
- $sale_info['commision_flag'] = $commision_flag;
- $sale_info['commision_type'] = $commision_type;
- $sale_info['back_commision_type'] = $back_commision_type;
- $sale_info['back_commision_method'] = $back_commision_method;
- $sale_info['back_percent'] = $back_percent;
- $sale_info['back_value'] = $back_value;
- // $sale_info['is_db'] = '0';//是否为数据库已存的1已存 0未存
- // $sale_info['is_update'] = '0';//数据库数据是否需要更改 0不,1需要
- // $sale_info['cancel_flag'] = '0';//0有效,1无效
- $sale_memcache[] = $sale_info;
- $id_array = array_keys($sale_memcache);
- $sale_info['sale_id'] = (string)end($id_array);
- $sale_memcache[$sale_info['sale_id']] = $sale_info;
-
- set_memcache("ZHANGS_SALE" . $key, $sale_memcache);
-
- $json['code'] = '0';
- $json['info'] = '保存成功';
- $json['list'] = $sale_info;
- echo json_encode($json);
- exit();
- }
-
- //删
- function deleteSale($sale_id)
- {
- $key = $_COOKIE['memcache'];
- $sale_memcache = get_memcache('ZHANGS_SALE' . $key);
- // if ($sale_memcache[$sale_id]['is_db'] == '1') {
- // $sale_memcache[$sale_id]['cancel_flag'] = '1';
- // } else {
- unset($sale_memcache[$sale_id]);
- // }
- set_memcache("ZHANGS_SALE" . $key, $sale_memcache);
- $json['code'] = '0';
- $json['info'] = '删除成功';
- echo json_encode($json);
- exit();
-
- }
-
- //改
- function updateSale($sale_id, $prod_supplier_id, $product_type, $parent_type, $sale_type, $commision_flag, $commision_type, $back_commision_type, $back_commision_method, $back_percent, $back_value)
- {
- if ($back_percent == '' || $back_value == '') {
- $json['code'] = '1';
- $json['info'] = '请完整填写佣金规则';
- echo json_encode($json);
- exit();
- }
- $key = $_COOKIE['memcache'];
- $sale_memcache = get_memcache('ZHANGS_SALE' . $key);
- $sale_info = $sale_memcache[$sale_id];
- $sale_info['prod_supplier_id'] = $prod_supplier_id;
- $sale_info['product_type'] = $product_type;
- $sale_info['parent_type'] = $parent_type;
- $sale_info['sale_type'] = $sale_type;
- $sale_info['commision_flag'] = $commision_flag;
- $sale_info['commision_type'] = $commision_type;
- $sale_info['back_commision_type'] = $back_commision_type;
- $sale_info['back_commision_method'] = $back_commision_method;
- $sale_info['back_percent'] = $back_percent;
- $sale_info['back_value'] = $back_value;
- //$link_info['is_db'] = '1';//是否为数据库已存的1已存 0未存
- // $sale_info['cancel_flag'] = '0';//0有效,1无效
- $sale_memcache[$sale_id] = $sale_info;
- // if($sale_info['is_db'] == '1')
- // {
- // $sale_info['is_update'] = '1';
- // }
- set_memcache("ZHANGS_SALE" . $key, $sale_memcache);
-
- $json['code'] = '0';
- $json['info'] = '修改成功';
- $json['list'] = $sale_info;
- echo json_encode($json);
- exit();
- }
-
- //查
- function selectSale($sale_id)
- {
- $key = $_COOKIE['memcache'];
- $sale_memcache = get_memcache('ZHANGS_SALE' . $key);
- $sale_info = $sale_memcache[$sale_id];
- $json['code'] = '0';
- $json['info'] = '查询成功';
- $json['list'] = $sale_info;
- echo json_encode($json);
- exit();
- }
- }
-
- $operate = trim($_POST['operate']);
-
- $operate_sale = new operate_sale();
- $operate_sale->execSale($operate);
- ?>
|