refill_third.php 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243
  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. if (!empty($_GET['product_type'])) {
  16. $condition['product_type'] = $_GET['product_type'];
  17. }
  18. $list = $mod->getThirdProductList($condition, 50);
  19. Tpl::output('opened_text', self::STATE_TEXT);
  20. Tpl::output('third_product_type', self::THIRD_PRODUCT_TYPE);
  21. Tpl::output('product_list', $list);
  22. Tpl::output('page', $mod->showpage());
  23. Tpl::showpage('third.product.list');
  24. }
  25. public function changeStateOp()
  26. {
  27. $system_code = $_GET['system_code'];
  28. $opened = intval($_GET['opened']);
  29. $mod = Model('refill_third');
  30. $third_product = $mod->findThirdProduct($system_code);
  31. if(empty($third_product)) {
  32. showMessage('产品不存在');
  33. }
  34. if (!in_array($opened, [1, 2])) {
  35. showMessage('操作状态错误');
  36. }
  37. $resp = $mod->editThirdProduct($system_code, ['opened' => $opened]);
  38. if (!$resp) {
  39. showMessage('操作失败');
  40. }
  41. showMessage('操作成功');
  42. }
  43. public function check_codeOp()
  44. {
  45. $mod = Model('thrid_refill');
  46. $system_code = $_GET['system_code'];
  47. $product = $mod->getProduct(['system_code' => $system_code]);
  48. if (empty($product)) {
  49. echo 'true';
  50. } else {
  51. echo 'false';
  52. }
  53. }
  54. public function product_addOp()
  55. {
  56. if (chksubmit()) {
  57. $obj_validate = new Validator();
  58. $obj_validate->validateparam = [
  59. ["input" => trim($_POST["system_code"]), "require" => "true", "message" => '产品CODE不能为空'],
  60. ["input" => trim($_POST["product_type"]), "require" => "true", "message" => '产品类型不能为空'],
  61. ["input" => trim($_POST["product_name"]), "require" => "true", "message" => '产品名称不能为空'],
  62. ["input" => trim($_POST["refill_amount"]), "require" => "true", "message" => '产品面值不能为空'],
  63. ];
  64. $error = $obj_validate->validate();
  65. if ($error != '') {
  66. showMessage($error);
  67. } else {
  68. $mod = Model('refill_third');
  69. $insert['system_code'] = trim($_POST['system_code']);
  70. $insert['product_name'] = trim($_POST['product_name']);
  71. $insert['product_type'] = trim($_POST['product_type']);
  72. $insert['refill_amount'] = trim($_POST['refill_amount']);
  73. $result = $mod->addThirdProduct($insert);
  74. if ($result) {
  75. showMessage('添加成功', 'index.php?act=refill_third&op=index');
  76. } else {
  77. showMessage('添加失败');
  78. }
  79. }
  80. }
  81. Tpl::output('third_product_type', self::THIRD_PRODUCT_TYPE);
  82. Tpl::showpage('third.product.add');
  83. }
  84. public function product_editOp()
  85. {
  86. $system_code = $_GET['system_code'] ?? $_POST['system_code'];
  87. $mod = Model('refill_third');
  88. $third_product = $mod->findThirdProduct($system_code);
  89. if(empty($third_product)) {
  90. showMessage('产品不存在');
  91. }
  92. if(chksubmit()) {
  93. $update_data['product_name'] = trim($_POST['product_name']);
  94. $update_data['refill_amount'] = trim($_POST['refill_amount']);
  95. $update_data['product_type'] = trim($_POST['product_type']);
  96. $result = $mod->editThirdProduct($system_code, $update_data);
  97. if ($result) {
  98. showMessage('编辑成功', 'index.php?act=refill_third&op=index');
  99. } else {
  100. showMessage('编辑失败');
  101. }
  102. }else{
  103. Tpl::output('third_product_type', self::THIRD_PRODUCT_TYPE);
  104. Tpl::output('third_product', $third_product);
  105. Tpl::showpage('third.product.edit');
  106. }
  107. }
  108. public function third_propriceOp()
  109. {
  110. $system_code = $_GET['system_code'] ?? $_POST['system_code'];
  111. $mod = Model('refill_third');
  112. $third_product = $mod->findThirdProduct($system_code);
  113. if(empty($third_product)) {
  114. showMessage('产品不存在');
  115. }
  116. $condition['system_code'] = $system_code;
  117. if(!empty($_GET['store_id']))
  118. {
  119. $condition['store_id'] = $_GET['store_id'];
  120. }
  121. $list = $mod->getProviderProductList($condition, 30);
  122. $providers = $this->providers(['type' => 3]);
  123. Tpl::output('providers', $providers);
  124. Tpl::output('product_list', $list);
  125. Tpl::output('third_product', $third_product);
  126. Tpl::output('recharge_type_text', ['直充','卡密','直充+卡密']);
  127. Tpl::output('page', $mod->showpage());
  128. Tpl::showpage('third.proprice.list');
  129. }
  130. public function third_proprice_addOp()
  131. {
  132. $system_code = $_GET['system_code'] ?? $_POST['system_code'];
  133. $mod = Model('refill_third');
  134. $third_product = $mod->findThirdProduct($system_code);
  135. if(empty($third_product)) {
  136. showMessage('产品不存在');
  137. }
  138. if (chksubmit()) {
  139. $obj_validate = new Validator();
  140. $obj_validate->validateparam = [
  141. ["input" => trim($_POST["store"]), "require" => "true", "message" => '通道信息不能为空'],
  142. ["input" => trim($_POST["channel_product_name"]), "require" => "true", "message" => '通道产品名称不能为空'],
  143. ["input" => trim($_POST["channel_code"]), "require" => "true", "message" => '通道code不能为空'],
  144. ["input" => trim($_POST["channel_amount"]), "require" => "true", "message" => '折扣价格不能为空'],
  145. ["input" => trim($_POST["recharge_type"]), "require" => "true", "message" => '充值类型不能为空'],
  146. ];
  147. $error = $obj_validate->validate();
  148. if ($error != '') {
  149. showMessage($error);
  150. } else {
  151. global $config;
  152. $store = trim($_POST['store']);
  153. $store = explode('-',$store);
  154. $store_id = $store[0];
  155. $channel_name = $store[1];
  156. $cfg_map = $config['third_providers'];
  157. $goods_id = 0;
  158. foreach ($cfg_map as $cfg) {
  159. if($cfg['name'] != $channel_name) continue;
  160. $goods_id = $cfg['cfg']['amount'][100][0]['goods_id'];
  161. }
  162. if(empty($goods_id)) {
  163. showMessage('商品配置有误,找不到商品ID!');
  164. }
  165. $channel_product = Model('thrid_refill')->getProviderProduct($store_id,$goods_id,$system_code);
  166. if(!empty($channel_product)) {
  167. showMessage('此通道已关联过此产品');
  168. }
  169. $mod = Model('refill_third');
  170. $insert['channel_name'] = $channel_name;
  171. $insert['store_id'] = $store_id;
  172. $insert['channel_product_name'] = trim($_POST['channel_product_name']);
  173. $insert['goods_id'] = $goods_id;
  174. $insert['channel_code'] = trim($_POST['channel_code']);
  175. $insert['channel_amount'] = trim($_POST['channel_amount']);
  176. $insert['recharge_type'] = trim($_POST['recharge_type']);
  177. $insert['system_code'] = $system_code;
  178. $insert['product_type'] = $third_product['product_type'];
  179. $result = $mod->addProviderProduct($insert);
  180. if ($result) {
  181. showMessage('添加成功', "index.php?act=refill_third&op=third_proprice&system_code={$system_code}");
  182. } else {
  183. showMessage('添加失败');
  184. }
  185. }
  186. } else {
  187. $providers = $this->providers(['type' => 3]);
  188. Tpl::output('third_product_type', self::THIRD_PRODUCT_TYPE);
  189. Tpl::output('providers', $providers);
  190. Tpl::output('third_product', $third_product);
  191. Tpl::showpage('third.proprice.add');
  192. }
  193. }
  194. public function third_proprice_editOp()
  195. {
  196. $system_code = $_GET['system_code'] ?? $_POST['system_code'];
  197. $mod = Model('refill_third');
  198. $third_product = $mod->findThirdProduct($system_code);
  199. if(empty($third_product)) {
  200. showMessage('产品不存在');
  201. }
  202. $store_id = $_GET['store_id'] ?? $_POST['store_id'];
  203. $goods_id = $_GET['goods_id'] ?? $_POST['goods_id'];
  204. $channel_product = Model('thrid_refill')->getProviderProduct($store_id,$goods_id,$system_code);
  205. if(empty($channel_product)) {
  206. showMessage('此通道关联产品不存在');
  207. }
  208. if (chksubmit()) {
  209. $update_data = [];
  210. $update_data['channel_product_name'] = trim($_POST['channel_product_name']);
  211. $update_data['channel_code'] = trim($_POST['channel_code']);
  212. $update_data['channel_amount'] = trim($_POST['channel_amount']);
  213. $update_data['recharge_type'] = trim($_POST['recharge_type']);
  214. $result = $mod->edit_provider_product($system_code,$store_id,$goods_id,$update_data);
  215. if ($result) {
  216. showMessage('编辑成功', "index.php?act=refill_third&op=third_proprice&system_code={$system_code}");
  217. } else {
  218. showMessage('编辑失败');
  219. }
  220. } else {
  221. Tpl::output('third_product', $third_product);
  222. Tpl::output('channel_product', $channel_product);
  223. Tpl::showpage('third.proprice.edit');
  224. }
  225. }
  226. }