refill_third.php 11 KB

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