coupon_list.php 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. <?php
  2. //decode by http://dezend.qiling.org QQ 2859470
  3. define('CURSCRIPT', 'coupon');
  4. require_once dirname(__FILE__) . '/global.php';
  5. require_once MYMPS_INC . '/db.class.php';
  6. (!defined('IN_ADMIN') || !defined('IN_MYMPS')) && exit('Access Denied');
  7. $part = $part ? trim($part) : 'list';
  8. $id = isset($id) ? intval($id) : '';
  9. chk_admin_purview('purview_已上传优惠券');
  10. if (!submit_check(CURSCRIPT . '_submit')) {
  11. require_once MYMPS_ROOT . '/plugin/coupon/include/functions.php';
  12. $here = ($part == 'edit' ? '修改' : '') . '已发布的优惠券';
  13. if ($part == 'edit') {
  14. if (empty($id)) {
  15. write_msg('优惠券编号不能为空!');
  16. }
  17. $edit = $db->getRow('SELECT * FROM `' . $db_mymps . 'coupon` WHERE id = \'' . $id . '\'');
  18. if (empty($edit['id'])) {
  19. write_msg('该优惠券已不存在!');
  20. }
  21. $edit['des'] = de_textarea_post_change($edit['des']);
  22. $acontent = get_editor('content', '', $edit['content'], '100%', '300');
  23. $begindate = $edit['begindate'] ? date('Y-m-d', $edit['begindate']) : '';
  24. $enddate = $edit['enddate'] ? date('Y-m-d', $edit['enddate']) : '';
  25. } else {
  26. $title = isset($title) ? trim($title) : '';
  27. $userid = isset($userid) ? trim($userid) : '';
  28. $begindate = isset($begindate) ? intval(strtotime($begindate)) : '';
  29. $enddate = isset($enddate) ? intval(strtotime($enddate)) : '';
  30. $cate_id = isset($cate_id) ? intval($cate_id) : '';
  31. $areaid = isset($areaid) ? intval($areaid) : '';
  32. $status = $status == 'yes' || !$status ? 1 : 0;
  33. $where = ' WHERE 1';
  34. $where .= $title != '' ? ' AND title LIKE \'%' . $title . '%\'' : '';
  35. $where .= $userid != '' ? ' AND userid = \'' . $userid . '\'' : '';
  36. $where .= $begindate != '' ? ' AND begindate >= \'' . $begindate . '\'' : '';
  37. $where .= $enddate != '' ? ' AND enddate <= \'' . $enddate . '\'' : '';
  38. $where .= !empty($cate_id) ? ' AND cate_id = \'' . $cate_id . '\'' : '';
  39. $where .= !empty($areaid) ? ' AND areaid = \'' . $areaid . '\'' : '';
  40. $where .= ' AND status = \'' . $status . '\'';
  41. $rows_num = $db->getOne('SELECT COUNT(id) FROM `' . $db_mymps . 'coupon` ' . $where);
  42. $param = setParam(array('part', 'title', 'userid', 'begindate', 'enddate', 'cate_id', 'areaid', 'status'));
  43. $begindate = !$begindate ? '' : date('Y-m-d', $begindate);
  44. $enddate = !$enddate ? '' : date('Y-m-d', $begindate);
  45. $status = empty($status) ? 'no' : 'yes';
  46. $coupon = page1('SELECT * FROM `' . $db_mymps . 'coupon` ' . $where . ' ORDER BY dateline DESC');
  47. }
  48. include mymps_tpl('coupon_' . $part);
  49. } else {
  50. if ($part == 'list') {
  51. if (empty($selectedids)) {
  52. write_msg('您没有选中任何一个优惠券!');
  53. }
  54. $create_in = create_in($selectedids);
  55. if (!$action || !in_array($action, array('delall', 'grade0', 'grade1', 'grade2'))) {
  56. echo $action;
  57. write_msg('您尚未指定处理动作!');
  58. }
  59. if ($action == 'delall') {
  60. $query = $db->query('SELECT * FROM `' . $db_mymps . 'coupon` WHERE id ' . $create_in);
  61. while ($row = $db->fetchRow($query)) {
  62. $delete[$row['id']]['picture'] = $row['picture'];
  63. $delete[$row['id']]['pre_picture'] = $row['pre_picture'];
  64. }
  65. foreach ($delete as $k => $v) {
  66. @unlink(MYMPS_ROOT . $v['picture']);
  67. @unlink(MYMPS_ROOT . $v['pre_picture']);
  68. }
  69. $db->query('DELETE FROM `' . $db_mymps . 'coupon` WHERE id ' . $create_in);
  70. unset($delete);
  71. unset($row);
  72. unset($query);
  73. unset($create_in);
  74. } else {
  75. if (in_array($action, array('grade0', 'grade1', 'grade2'))) {
  76. switch ($action) {
  77. case 'grade0':
  78. $action = 0;
  79. break;
  80. case 'grade1':
  81. $action = 1;
  82. break;
  83. case 'grade2':
  84. $action = 2;
  85. break;
  86. }
  87. $db->query('UPDATE `' . $db_mymps . 'coupon` SET grade = \'' . $action . '\' WHERE id ' . $create_in);
  88. unset($create_in);
  89. }
  90. }
  91. } else {
  92. if ($part == 'edit') {
  93. if (empty($id)) {
  94. write_msg('优惠券编号不能为空!');
  95. }
  96. if (empty($title)) {
  97. write_msg('优惠券标题不能为空!');
  98. }
  99. $name_file = 'coupon_image';
  100. $begindate = intval(strtotime($begindate));
  101. $enddate = intval(strtotime($enddate));
  102. $des = textarea_post_change($des);
  103. if ($_FILES[$name_file]['name']) {
  104. require_once MYMPS_INC . '/upfile.fun.php';
  105. $destination = '/coupon/' . date('Ym') . '/';
  106. $mymps_image = start_upload($name_file, $destination, 0, $mymps_mymps['cfg_coupon_limit']['width'], $mymps_mymps['cfg_coupon_limit']['height'], $picture, $pre_picture);
  107. $picture = $mymps_image[0];
  108. $pre_picture = $mymps_image[1];
  109. unset($mymps_image);
  110. }
  111. unset($name_file);
  112. $db->query('UPDATE `' . $db_mymps . 'coupon` SET title = \'' . $title . '\',des = \'' . $des . '\',content = \'' . $content . '\',cate_id = \'' . $cate_id . '\',areaid = \'' . $areaid . '\',picture=\'' . $picture . '\',pre_picture=\'' . $pre_picture . '\',begindate = \'' . $begindate . '\',enddate = \'' . $enddate . '\',dateline = \'' . $timestamp . '\' , ctype = \'' . $ctype . '\' , sup = \'' . $sup . '\' , status = \'' . $status . '\',grade=\'' . $grade . '\' WHERE id = \'' . $id . '\'');
  113. $url = '?part=edit&id=' . $id;
  114. }
  115. }
  116. write_msg('操作成功!', $url ? $url : '?part=list');
  117. }