refill_third.php 11 KB

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