You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

преди 3 години
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163
  1. <?php
  2. class operate_sale
  3. {
  4. function execSale($operate)
  5. {
  6. $sale_id = isset($_POST['sale_id']) ? trim($_POST['sale_id']) : '';//id
  7. $prod_supplier_id = isset($_POST['prod_supplier_id']) ? trim($_POST['prod_supplier_id']) : '0';//供应商id
  8. $product_type = isset($_POST['product_type']) ? trim($_POST['product_type']) : '0';//产品子类(二级类)
  9. $parent_type = isset($_POST['parent_type']) ? trim($_POST['parent_type']) : '0';//产品父类(一级类)
  10. $sale_type = isset($_POST['sale_type']) ? trim($_POST['sale_type']) : '0';//销售方式
  11. $commision_flag = isset($_POST['commision_flag']) ? trim($_POST['commision_flag']) : '0';//是否有佣金规则,1:有,0:无
  12. $commision_type = isset($_POST['commision_type']) ? trim($_POST['commision_type']) : '0';//佣金类别
  13. $back_commision_type = isset($_POST['back_commision_type']) ? ($_POST['back_commision_type'] == '' ? '0' : trim($_POST['back_commision_type'])) : '0';//返佣类别
  14. $back_commision_method = isset($_POST['back_commision_method']) ? ($_POST['back_commision_method'] == '' ? '0' : trim($_POST['back_commision_method'])) : '0';//返佣方式
  15. $back_percent = isset($_POST['back_percent']) ? trim($_POST['back_percent']) : '0';//返佣比例
  16. $back_value = isset($_POST['back_value']) ? trim($_POST['back_value']) : '0';//返佣固定金额
  17. //$is_db 是否为数据库已存的
  18. if ($operate == 'insert') {
  19. $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);
  20. }
  21. if ($operate == 'delete') {
  22. $this->deleteSale($sale_id);
  23. }
  24. if ($operate == 'update') {
  25. $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);
  26. }
  27. if ($operate == 'select') {
  28. $this->selectSale($sale_id);
  29. }
  30. }
  31. //增
  32. 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)
  33. {
  34. if (!isset($_COOKIE['memcache'])) {
  35. $time = time();
  36. setcookie('memcache', $time, time() + 36000, "/");
  37. $_COOKIE['memcache'] = $time;
  38. }
  39. $key = $_COOKIE['memcache'];
  40. $sale_memcache = get_memcache('ZHANGS_SALE' . $key);
  41. if (!$sale_memcache) {
  42. $sale_memcache = array();
  43. }
  44. if ($back_percent == '' || $back_value == '') {
  45. $json['code'] = '1';
  46. $json['info'] = '请完整填写佣金规则';
  47. echo json_encode($json);
  48. exit();
  49. }
  50. $sale_info = array();
  51. $sale_info['prod_supplier_id'] = $prod_supplier_id;
  52. $sale_info['product_type'] = $product_type;
  53. $sale_info['parent_type'] = $parent_type;
  54. $sale_info['sale_type'] = $sale_type;
  55. $sale_info['commision_flag'] = $commision_flag;
  56. $sale_info['commision_type'] = $commision_type;
  57. $sale_info['back_commision_type'] = $back_commision_type;
  58. $sale_info['back_commision_method'] = $back_commision_method;
  59. $sale_info['back_percent'] = $back_percent;
  60. $sale_info['back_value'] = $back_value;
  61. // $sale_info['is_db'] = '0';//是否为数据库已存的1已存 0未存
  62. // $sale_info['is_update'] = '0';//数据库数据是否需要更改 0不,1需要
  63. // $sale_info['cancel_flag'] = '0';//0有效,1无效
  64. $sale_memcache[] = $sale_info;
  65. $id_array = array_keys($sale_memcache);
  66. $sale_info['sale_id'] = (string)end($id_array);
  67. $sale_memcache[$sale_info['sale_id']] = $sale_info;
  68. set_memcache("ZHANGS_SALE" . $key, $sale_memcache);
  69. $json['code'] = '0';
  70. $json['info'] = '保存成功';
  71. $json['list'] = $sale_info;
  72. echo json_encode($json);
  73. exit();
  74. }
  75. //删
  76. function deleteSale($sale_id)
  77. {
  78. $key = $_COOKIE['memcache'];
  79. $sale_memcache = get_memcache('ZHANGS_SALE' . $key);
  80. // if ($sale_memcache[$sale_id]['is_db'] == '1') {
  81. // $sale_memcache[$sale_id]['cancel_flag'] = '1';
  82. // } else {
  83. unset($sale_memcache[$sale_id]);
  84. // }
  85. set_memcache("ZHANGS_SALE" . $key, $sale_memcache);
  86. $json['code'] = '0';
  87. $json['info'] = '删除成功';
  88. echo json_encode($json);
  89. exit();
  90. }
  91. //改
  92. 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)
  93. {
  94. if ($back_percent == '' || $back_value == '') {
  95. $json['code'] = '1';
  96. $json['info'] = '请完整填写佣金规则';
  97. echo json_encode($json);
  98. exit();
  99. }
  100. $key = $_COOKIE['memcache'];
  101. $sale_memcache = get_memcache('ZHANGS_SALE' . $key);
  102. $sale_info = $sale_memcache[$sale_id];
  103. $sale_info['prod_supplier_id'] = $prod_supplier_id;
  104. $sale_info['product_type'] = $product_type;
  105. $sale_info['parent_type'] = $parent_type;
  106. $sale_info['sale_type'] = $sale_type;
  107. $sale_info['commision_flag'] = $commision_flag;
  108. $sale_info['commision_type'] = $commision_type;
  109. $sale_info['back_commision_type'] = $back_commision_type;
  110. $sale_info['back_commision_method'] = $back_commision_method;
  111. $sale_info['back_percent'] = $back_percent;
  112. $sale_info['back_value'] = $back_value;
  113. //$link_info['is_db'] = '1';//是否为数据库已存的1已存 0未存
  114. // $sale_info['cancel_flag'] = '0';//0有效,1无效
  115. $sale_memcache[$sale_id] = $sale_info;
  116. // if($sale_info['is_db'] == '1')
  117. // {
  118. // $sale_info['is_update'] = '1';
  119. // }
  120. set_memcache("ZHANGS_SALE" . $key, $sale_memcache);
  121. $json['code'] = '0';
  122. $json['info'] = '修改成功';
  123. $json['list'] = $sale_info;
  124. echo json_encode($json);
  125. exit();
  126. }
  127. //查
  128. function selectSale($sale_id)
  129. {
  130. $key = $_COOKIE['memcache'];
  131. $sale_memcache = get_memcache('ZHANGS_SALE' . $key);
  132. $sale_info = $sale_memcache[$sale_id];
  133. $json['code'] = '0';
  134. $json['info'] = '查询成功';
  135. $json['list'] = $sale_info;
  136. echo json_encode($json);
  137. exit();
  138. }
  139. }
  140. $operate = trim($_POST['operate']);
  141. $operate_sale = new operate_sale();
  142. $operate_sale->execSale($operate);
  143. ?>