bonus.php 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. <?php
  2. /**
  3. * 红包管理
  4. *
  5. *
  6. *
  7. ***/
  8. defined('InShopNC') or exit('Access Invalid!');
  9. class bonusControl extends SystemControl
  10. {
  11. public function __construct()
  12. {
  13. parent::__construct();
  14. }
  15. public function bonus_typeOp()
  16. {
  17. $bonus_type = Model('bonus_type');
  18. $bonus_list = $bonus_type->getAll();
  19. Tpl::output('bonus_list', $bonus_list);
  20. $this->show_menu('bonus', 'bonus_type_list');
  21. Tpl::showpage('bonus.bonus_type_list');
  22. }
  23. public function bonus_type_addOp()
  24. {
  25. $this->show_menu('bonus', 'bonus_type_add');
  26. $this->bonus_form();
  27. }
  28. // 添加随机红包
  29. public function bonus_type_add_randomOp()
  30. {
  31. $this->show_menu('bonus', 'bonus_type_add_random');
  32. $this->bonus_add_random_form();
  33. }
  34. public function bonus_type_editOp()
  35. {
  36. $id = $_GET['id'];
  37. $this->show_menu('type', 'bonus_type_edit');
  38. $this->bonus_form($id);
  39. }
  40. public function bonus_type_saveOp()
  41. {
  42. $type_id = $_POST['type_id'] ? $_POST['type_id'] : 0;
  43. $bonus_value = array(
  44. 'type_name' => $_POST['hb_words'],
  45. 'send_type' => $_POST['send_type'],
  46. 'send_start_date' => strtotime(trim($_POST['send_start_date'])),
  47. 'send_end_date' => strtotime(trim($_POST['send_end_date'])),
  48. 'use_start_date' => strtotime(trim($_POST['use_start_date'])),
  49. 'use_end_date' => strtotime(trim($_POST['use_end_date']))
  50. );
  51. $bonus_type = Model('bonus_type');
  52. $bonus_type->save($bonus_value, $type_id);
  53. if (intval($_POST['send_type']) === 1) {
  54. $bonus_file = $_FILES['bonus_file'];
  55. if ($bonus_file && !empty($bonus_file['name'])) {
  56. if ($bonus_file['tmp_name'] == "") {
  57. $this->setError('上传失败,请联系服务器管理员。');
  58. return false;
  59. }
  60. $bonus_file_content = file_get_contents($bonus_file['tmp_name']);
  61. $bonus = Model('user_bonus');
  62. $bonus->loadFile($bonus_file_content);
  63. }
  64. }
  65. $this->bonus_typeOp();
  66. }
  67. private function bonus_form($id = 0)
  68. {
  69. Tpl::output('id', $id);
  70. if ($id > 0) {
  71. $bonus_type = Model('bonus_type');
  72. $bonus_type_data = $bonus_type->get($id);
  73. Tpl::output('data', $bonus_type_data[0]);
  74. }
  75. Tpl::showpage('bonus.bonus_type_form');
  76. }
  77. private function bonus_add_random_form($id = 0)
  78. {
  79. Tpl::output('id', $id);
  80. if ($id > 0) {
  81. $bonus_type = Model('bonus_type');
  82. $bonus_type_data = $bonus_type->get($id);
  83. Tpl::output('data', $bonus_type_data[0]);
  84. }
  85. Tpl::showpage('bonus.bonus_type_add_random_form');
  86. }
  87. private function show_menu($menu_type, $menu_key = '')
  88. {
  89. $menu_array = array();
  90. switch ($menu_type) {
  91. case 'bonus':
  92. $menu_array = array(
  93. 1 => array('menu_key' => 'bonus_type_list', 'menu_name' => '已发红包', 'menu_url' => 'index.php?act=bonus&op=bonus_type'),
  94. 2 => array('menu_key' => 'bonus_type_add', 'menu_name' => '添加定向红包', 'menu_url' => 'index.php?act=bonus&op=bonus_type_add'),
  95. 3 => array('menu_key' => 'bonus_type_add_random', 'menu_name' => '添加随机红包', 'menu_url' => 'index.php?act=bonus&op=bonus_type_add_random'),
  96. );
  97. break;
  98. case 'type':
  99. $menu_array = array(
  100. 1 => array('menu_key' => 'bonus_type_edit', 'menu_name' => '编辑红包', 'menu_url' => 'index.php?act=bonus&op=bonus_type_edit')
  101. );
  102. break;
  103. }
  104. Tpl::output('menu', $menu_array);
  105. Tpl::output('menu_key', $menu_key);
  106. }
  107. }