refill_third.php 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200
  1. <?php
  2. class refill_thirdControl extends SystemControl
  3. {
  4. public function __construct()
  5. {
  6. parent::__construct();
  7. }
  8. public function indexOp()
  9. {
  10. $mod = Model('refill_third');
  11. $condition = [];
  12. if (trim($_GET['product_name']) != '') {
  13. $condition['product_name'] = ['like', '%' . $_GET['product_name'] . '%'];
  14. }
  15. $list = $mod->getThirdProductList($condition, 30);
  16. Tpl::output('product_list', $list);
  17. Tpl::output('page', $mod->showpage());
  18. Tpl::showpage('third.product.list');
  19. }
  20. public function product_addOp()
  21. {
  22. if (chksubmit()) {
  23. $obj_validate = new Validator();
  24. $obj_validate->validateparam = [
  25. ["input" => trim($_POST["product_name"]), "require" => "true", "message" => '产品名称不能为空'],
  26. ["input" => trim($_POST["refill_amount"]), "require" => "true", "message" => '产品面值不能为空'],
  27. ];
  28. $error = $obj_validate->validate();
  29. if ($error != '') {
  30. showMessage($error);
  31. } else {
  32. $mod = Model('refill_third');
  33. $insert['product_name'] = trim($_POST['product_name']);
  34. $insert['refill_amount'] = trim($_POST['refill_amount']);
  35. $last_item = $mod->table('third_product')->order('system_code desc')->find();
  36. if (empty($last_item)) {
  37. $system_code = 'XYZ100001';
  38. } else {
  39. $last_code = $last_item['system_code'];
  40. $last_code = explode('XYZ',$last_code);
  41. $system_code = intval($last_code[1] + 1);
  42. $system_code = "XYZ{$system_code}";
  43. }
  44. $insert['system_code'] = $system_code;
  45. $result = $mod->addThirdProduct($insert);
  46. if ($result) {
  47. showMessage('添加成功', 'index.php?act=refill_third&op=index');
  48. } else {
  49. showMessage('添加失败');
  50. }
  51. }
  52. }
  53. Tpl::showpage('third.product.add');
  54. }
  55. public function product_editOp()
  56. {
  57. $system_code = $_GET['system_code'] ?? $_POST['system_code'];
  58. $mod = Model('refill_third');
  59. $third_product = $mod->findThirdProduct($system_code);
  60. if(empty($third_product)) {
  61. showMessage('产品不存在');
  62. }
  63. if(chksubmit()) {
  64. $update_data['product_name'] = trim($_POST['product_name']);
  65. $update_data['refill_amount'] = trim($_POST['refill_amount']);
  66. $result = $mod->editThirdProduct($system_code, $update_data);
  67. if ($result) {
  68. showMessage('编辑成功', 'index.php?act=refill_third&op=index');
  69. } else {
  70. showMessage('编辑失败');
  71. }
  72. }else{
  73. Tpl::output('third_product', $third_product);
  74. Tpl::showpage('third.product.edit');
  75. }
  76. }
  77. public function third_propriceOp()
  78. {
  79. $system_code = $_GET['system_code'] ?? $_POST['system_code'];
  80. $mod = Model('refill_third');
  81. $third_product = $mod->findThirdProduct($system_code);
  82. if(empty($third_product)) {
  83. showMessage('产品不存在');
  84. }
  85. $condition['system_code'] = $system_code;
  86. if(!empty($_GET['store_id']))
  87. {
  88. $condition['store_id'] = $_GET['store_id'];
  89. }
  90. $list = $mod->getProviderProductList($condition, 30);
  91. $providers = $this->providers(['type' => 3]);
  92. Tpl::output('providers', $providers);
  93. Tpl::output('product_list', $list);
  94. Tpl::output('third_product', $third_product);
  95. Tpl::output('recharge_type_text', ['直充','卡密','直充+卡密']);
  96. Tpl::output('page', $mod->showpage());
  97. Tpl::showpage('third.proprice.list');
  98. }
  99. public function third_proprice_addOp()
  100. {
  101. $system_code = $_GET['system_code'] ?? $_POST['system_code'];
  102. $mod = Model('refill_third');
  103. $third_product = $mod->findThirdProduct($system_code);
  104. if(empty($third_product)) {
  105. showMessage('产品不存在');
  106. }
  107. if (chksubmit()) {
  108. $obj_validate = new Validator();
  109. $obj_validate->validateparam = [
  110. ["input" => trim($_POST["store"]), "require" => "true", "message" => '通道信息不能为空'],
  111. ["input" => trim($_POST["channel_product_name"]), "require" => "true", "message" => '通道产品名称不能为空'],
  112. ["input" => trim($_POST["goods_id"]), "require" => "true", "message" => '商品ID不能为空'],
  113. ["input" => trim($_POST["channel_code"]), "require" => "true", "message" => '通道code不能为空'],
  114. ["input" => trim($_POST["channel_amount"]), "require" => "true", "message" => '折扣价格不能为空'],
  115. ["input" => trim($_POST["recharge_type"]), "require" => "true", "message" => '充值类型不能为空'],
  116. ];
  117. $error = $obj_validate->validate();
  118. if ($error != '') {
  119. showMessage($error);
  120. } else {
  121. $store = trim($_POST['store']);
  122. $store = explode('-',$store);
  123. $store_id = $store[0];
  124. $channel_name = $store[1];
  125. $goods_id = trim($_POST['goods_id']);
  126. $channel_product = Model('thrid_refill')->getProviderProduct($store_id,$goods_id,$system_code);
  127. if(!empty($channel_product)) {
  128. showMessage('此通道已关联过此产品');
  129. exit;
  130. }
  131. $mod = Model('refill_third');
  132. $insert['channel_name'] = $channel_name;
  133. $insert['store_id'] = $store_id;
  134. $insert['channel_product_name'] = trim($_POST['channel_product_name']);
  135. $insert['goods_id'] = $goods_id;
  136. $insert['channel_code'] = trim($_POST['channel_code']);
  137. $insert['channel_amount'] = trim($_POST['channel_amount']);
  138. $insert['recharge_type'] = trim($_POST['recharge_type']);
  139. $insert['system_code'] = $system_code;
  140. $result = $mod->addProviderProduct($insert);
  141. if ($result) {
  142. showMessage('添加成功', "index.php?act=refill_third&op=third_proprice&system_code={$system_code}");
  143. } else {
  144. showMessage('添加失败');
  145. }
  146. }
  147. } else {
  148. $providers = $this->providers(['type' => 3]);
  149. Tpl::output('providers', $providers);
  150. Tpl::output('third_product', $third_product);
  151. Tpl::showpage('third.proprice.add');
  152. }
  153. }
  154. public function third_proprice_editOp()
  155. {
  156. $system_code = $_GET['system_code'] ?? $_POST['system_code'];
  157. $mod = Model('refill_third');
  158. $third_product = $mod->findThirdProduct($system_code);
  159. if(empty($third_product)) {
  160. showMessage('产品不存在');
  161. }
  162. $store_id = $_GET['store_id'] ?? $_POST['store_id'];
  163. $goods_id = $_GET['goods_id'] ?? $_POST['goods_id'];
  164. $channel_product = Model('thrid_refill')->getProviderProduct($store_id,$goods_id,$system_code);
  165. if(empty($channel_product)) {
  166. showMessage('此通道关联产品不存在');
  167. }
  168. if (chksubmit()) {
  169. $update_data = [];
  170. $update_data['channel_product_name'] = trim($_POST['channel_product_name']);
  171. $update_data['channel_code'] = trim($_POST['channel_code']);
  172. $update_data['channel_amount'] = trim($_POST['channel_amount']);
  173. $update_data['recharge_type'] = trim($_POST['recharge_type']);
  174. $result = $mod->edit_provider_product($system_code,$store_id,$goods_id,$update_data);
  175. if ($result) {
  176. showMessage('编辑成功', "index.php?act=refill_third&op=third_proprice&system_code={$system_code}");
  177. } else {
  178. showMessage('编辑失败');
  179. }
  180. } else {
  181. Tpl::output('third_product', $third_product);
  182. Tpl::output('channel_product', $channel_product);
  183. Tpl::showpage('third.proprice.edit');
  184. }
  185. }
  186. }