refill_third.php 10.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240
  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. $result = $mod->editThirdProduct($system_code, $update_data);
  96. if ($result) {
  97. showMessage('编辑成功', 'index.php?act=refill_third&op=index');
  98. } else {
  99. showMessage('编辑失败');
  100. }
  101. }else{
  102. Tpl::output('third_product', $third_product);
  103. Tpl::showpage('third.product.edit');
  104. }
  105. }
  106. public function third_propriceOp()
  107. {
  108. $system_code = $_GET['system_code'] ?? $_POST['system_code'];
  109. $mod = Model('refill_third');
  110. $third_product = $mod->findThirdProduct($system_code);
  111. if(empty($third_product)) {
  112. showMessage('产品不存在');
  113. }
  114. $condition['system_code'] = $system_code;
  115. if(!empty($_GET['store_id']))
  116. {
  117. $condition['store_id'] = $_GET['store_id'];
  118. }
  119. $list = $mod->getProviderProductList($condition, 30);
  120. $providers = $this->providers(['type' => 3]);
  121. Tpl::output('providers', $providers);
  122. Tpl::output('product_list', $list);
  123. Tpl::output('third_product', $third_product);
  124. Tpl::output('recharge_type_text', ['直充','卡密','直充+卡密']);
  125. Tpl::output('page', $mod->showpage());
  126. Tpl::showpage('third.proprice.list');
  127. }
  128. public function third_proprice_addOp()
  129. {
  130. $system_code = $_GET['system_code'] ?? $_POST['system_code'];
  131. $mod = Model('refill_third');
  132. $third_product = $mod->findThirdProduct($system_code);
  133. if(empty($third_product)) {
  134. showMessage('产品不存在');
  135. }
  136. if (chksubmit()) {
  137. $obj_validate = new Validator();
  138. $obj_validate->validateparam = [
  139. ["input" => trim($_POST["store"]), "require" => "true", "message" => '通道信息不能为空'],
  140. ["input" => trim($_POST["channel_product_name"]), "require" => "true", "message" => '通道产品名称不能为空'],
  141. ["input" => trim($_POST["channel_code"]), "require" => "true", "message" => '通道code不能为空'],
  142. ["input" => trim($_POST["channel_amount"]), "require" => "true", "message" => '折扣价格不能为空'],
  143. ["input" => trim($_POST["recharge_type"]), "require" => "true", "message" => '充值类型不能为空'],
  144. ];
  145. $error = $obj_validate->validate();
  146. if ($error != '') {
  147. showMessage($error);
  148. } else {
  149. global $config;
  150. $store = trim($_POST['store']);
  151. $store = explode('-',$store);
  152. $store_id = $store[0];
  153. $channel_name = $store[1];
  154. $cfg_map = $config['third_providers'];
  155. $goods_id = 0;
  156. foreach ($cfg_map as $cfg) {
  157. if($cfg['name'] != $channel_name) continue;
  158. $goods_id = $cfg['cfg']['amount'][100][0]['goods_id'];
  159. }
  160. if(empty($goods_id)) {
  161. showMessage('商品配置有误,找不到商品ID!');
  162. }
  163. $channel_product = Model('thrid_refill')->getProviderProduct($store_id,$goods_id,$system_code);
  164. if(!empty($channel_product)) {
  165. showMessage('此通道已关联过此产品');
  166. }
  167. $mod = Model('refill_third');
  168. $insert['channel_name'] = $channel_name;
  169. $insert['store_id'] = $store_id;
  170. $insert['channel_product_name'] = trim($_POST['channel_product_name']);
  171. $insert['goods_id'] = $goods_id;
  172. $insert['channel_code'] = trim($_POST['channel_code']);
  173. $insert['channel_amount'] = trim($_POST['channel_amount']);
  174. $insert['recharge_type'] = trim($_POST['recharge_type']);
  175. $insert['system_code'] = $system_code;
  176. $insert['product_type'] = $third_product['product_type'];
  177. $result = $mod->addProviderProduct($insert);
  178. if ($result) {
  179. showMessage('添加成功', "index.php?act=refill_third&op=third_proprice&system_code={$system_code}");
  180. } else {
  181. showMessage('添加失败');
  182. }
  183. }
  184. } else {
  185. $providers = $this->providers(['type' => 3]);
  186. Tpl::output('third_product_type', self::THIRD_PRODUCT_TYPE);
  187. Tpl::output('providers', $providers);
  188. Tpl::output('third_product', $third_product);
  189. Tpl::showpage('third.proprice.add');
  190. }
  191. }
  192. public function third_proprice_editOp()
  193. {
  194. $system_code = $_GET['system_code'] ?? $_POST['system_code'];
  195. $mod = Model('refill_third');
  196. $third_product = $mod->findThirdProduct($system_code);
  197. if(empty($third_product)) {
  198. showMessage('产品不存在');
  199. }
  200. $store_id = $_GET['store_id'] ?? $_POST['store_id'];
  201. $goods_id = $_GET['goods_id'] ?? $_POST['goods_id'];
  202. $channel_product = Model('thrid_refill')->getProviderProduct($store_id,$goods_id,$system_code);
  203. if(empty($channel_product)) {
  204. showMessage('此通道关联产品不存在');
  205. }
  206. if (chksubmit()) {
  207. $update_data = [];
  208. $update_data['channel_product_name'] = trim($_POST['channel_product_name']);
  209. $update_data['channel_code'] = trim($_POST['channel_code']);
  210. $update_data['channel_amount'] = trim($_POST['channel_amount']);
  211. $update_data['recharge_type'] = trim($_POST['recharge_type']);
  212. $result = $mod->edit_provider_product($system_code,$store_id,$goods_id,$update_data);
  213. if ($result) {
  214. showMessage('编辑成功', "index.php?act=refill_third&op=third_proprice&system_code={$system_code}");
  215. } else {
  216. showMessage('编辑失败');
  217. }
  218. } else {
  219. Tpl::output('third_product', $third_product);
  220. Tpl::output('channel_product', $channel_product);
  221. Tpl::showpage('third.proprice.edit');
  222. }
  223. }
  224. }