bonus.php 3.4 KB

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