channel.php 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. <?php
  2. defined('InShopNC') or exit('Access Invalid!');
  3. class channelControl extends SystemControl
  4. {
  5. public function __construct()
  6. {
  7. parent::__construct();
  8. }
  9. public function indexOp()
  10. {
  11. $channel_list = Model('channel')->getChannelList([] , 30 , 'add_time desc');
  12. Tpl::output('channel_list', $channel_list);
  13. Tpl::output('page', Model('channel')->showpage());
  14. Tpl::showpage('channel.index');
  15. }
  16. public function channel_addOp()
  17. {
  18. if (chksubmit()) {
  19. $obj_validate = new Validator();
  20. $obj_validate->validateparam = [
  21. ["input" => $_POST["channel_name"], "require" => "true", "message" => '名称不能为空'],
  22. ["input" => $_POST["store"], "require" => "true", "message" => '包含店铺不能为空']
  23. ];
  24. $error = $obj_validate->validate();
  25. if ($error != '') {
  26. showMessage($error);
  27. } else {
  28. $channel_name = trim($_POST['channel_name']);
  29. $store = trim($_POST['store']);
  30. $store = trim($store , ',');
  31. $stores = explode(',' , $store);
  32. foreach ($stores as $id) {
  33. $store_data = Model('store')->getStoreMemberIDList($id);
  34. if(empty($store_data)) {
  35. showMessage("店铺ID为{$id}的店铺不存在");
  36. }
  37. }
  38. $insert_array['channel_name'] = $channel_name;
  39. $insert_array['store_id'] = $store;
  40. $insert_array['add_time'] = time();
  41. $model_channel = Model('channel');
  42. $result = $model_channel->addChannel($insert_array);
  43. if ($result) {
  44. $url = [
  45. [
  46. 'url' => 'index.php?act=channel&op=index',
  47. 'msg' => '返回充值商列表',
  48. ],
  49. [
  50. 'url' => 'index.php?act=channel&op=channel_add',
  51. 'msg' => '继续新增充值商',
  52. ],
  53. ];
  54. $this->log('添加充值商:' . '[ ' . $_POST['channel_name'] . ']', 1);
  55. showMessage('充值商添加成功', $url);
  56. } else {
  57. showMessage('充值商添加失败');
  58. }
  59. }
  60. }
  61. Tpl::showpage('channel.add');
  62. }
  63. public function channel_editOp()
  64. {
  65. $cid = $_GET['cid'] ?? $_POST['cid'];
  66. $model_channel = Model('channel');
  67. $channel = $model_channel->getChannelInfo(['cid' => $cid]);
  68. if(empty($channel)){
  69. showMessage('充值商信息有误');
  70. }
  71. if (chksubmit()) {
  72. $store = trim($_POST['store']);
  73. $store = trim($store , ',');
  74. $stores = explode(',' , $store);
  75. foreach ($stores as $id) {
  76. $store_data = Model('store')->getStoreMemberIDList($id);
  77. if(empty($store_data)) {
  78. showMessage("店铺ID为{$id}的店铺不存在");
  79. }
  80. }
  81. $update['channel_name'] = trim($_POST['channel_name']);
  82. $update['store_id'] = $store;
  83. $result = $model_channel->editChannel($update,['cid' => $cid]);
  84. if ($result) {
  85. $this->log('编辑充值商:' . '[ ' . $channel['channel_name'] . ']', 1);
  86. showMessage('充值商编辑成功', 'index.php?act=channel&op=index');
  87. } else {
  88. showMessage('充值商编辑失败', 'index.php?act=channel&op=index');
  89. }
  90. }
  91. Tpl::output('channel', $channel);
  92. Tpl::showpage('channel.edit');
  93. }
  94. }