PageRenderTime 25ms CodeModel.GetById 14ms RepoModel.GetById 0ms app.codeStats 0ms

/trunk/upload/admin/goods_auto.php

https://gitlab.com/BGCX261/zishashop-svn-to-git
PHP | 217 lines | 167 code | 34 blank | 16 comment | 31 complexity | a6e8d4cde2dd3f7351b84bc1ec4e134a MD5 | raw file
  1. <?php
  2. /**
  3. * ECSHOP 程序说明
  4. * ===========================================================
  5. * 版权所有 2005-2008 上海商派网络科技有限公司,并保留所有权利。
  6. * 网站地址: http://www.ecshop.com;
  7. * ----------------------------------------------------------
  8. * 这不是一个自由软件!您只能在不用于商业目的的前提下对程序代码进行修改和
  9. * 使用;不允许对程序代码以任何形式任何目的的再发布。
  10. * ==========================================================
  11. * $Author: testyang $
  12. * $Id: goods_auto.php 15013 2008-10-23 09:31:42Z testyang $
  13. */
  14. define('IN_ECS', true);
  15. require(dirname(__FILE__) . '/includes/init.php');
  16. admin_priv('goods_auto');
  17. $smarty->assign('thisfile', 'goods_auto.php');
  18. if ($_REQUEST['act'] == 'list')
  19. {
  20. $goodsdb = get_auto_goods();
  21. $crons_enable = $db->getOne("SELECT enable FROM " . $GLOBALS['ecs']->table('crons') . " WHERE cron_code='auto_manage'");
  22. $smarty->assign('crons_enable', $crons_enable);
  23. $smarty->assign('full_page', 1);
  24. $smarty->assign('ur_here', $_LANG['goods_auto']);
  25. $smarty->assign('cfg_lang', $_CFG['lang']);
  26. $smarty->assign('goodsdb', $goodsdb['goodsdb']);
  27. $smarty->assign('filter', $goodsdb['filter']);
  28. $smarty->assign('record_count', $goodsdb['record_count']);
  29. $smarty->assign('page_count', $goodsdb['page_count']);
  30. assign_query_info();
  31. $smarty->display('goods_auto.htm');
  32. }
  33. elseif ($_REQUEST['act'] == 'query')
  34. {
  35. $goodsdb = get_auto_goods();
  36. $smarty->assign('goodsdb', $goodsdb['goodsdb']);
  37. $smarty->assign('filter', $goodsdb['filter']);
  38. $smarty->assign('cfg_lang', $_CFG['lang']);
  39. $smarty->assign('record_count', $goodsdb['record_count']);
  40. $smarty->assign('page_count', $goodsdb['page_count']);
  41. $sort_flag = sort_flag($goodsdb['filter']);
  42. $smarty->assign($sort_flag['tag'], $sort_flag['img']);
  43. make_json_result($smarty->fetch('goods_auto.htm'), '', array('filter' => $goodsdb['filter'], 'page_count' => $goodsdb['page_count']));
  44. }
  45. elseif ($_REQUEST['act'] == 'del')
  46. {
  47. $goods_id = (int)$_REQUEST['goods_id'];
  48. $sql = "DELETE FROM " . $ecs->table('auto_manage') . " WHERE item_id = '$goods_id' AND type = 'goods'";
  49. $db->query($sql);
  50. $links[] = array('text' => $_LANG['goods_auto'], 'href' => 'goods_auto.php?act=list');
  51. sys_msg($_LANG['edit_ok'], 0 ,$links);
  52. }
  53. elseif ($_REQUEST['act'] == 'edit_starttime')
  54. {
  55. check_authz_json('goods_auto');
  56. if(! preg_match('/^\d{4}-\d{2}-\d{2}$/', trim($_POST['val'])) )
  57. {
  58. make_json_error('');
  59. }
  60. $id = intval($_POST['id']);
  61. $time = local_strtotime(trim($_POST['val']));
  62. if($id <= 0 || $_POST['val'] == '0000-00-00' || $time <= 0)
  63. {
  64. make_json_error('');
  65. }
  66. $db->autoReplace($ecs->table('auto_manage'), array('item_id' => $id,'type' => 'goods',
  67. 'starttime' => $time), array('starttime' =>(string)$time));
  68. clear_cache_files();
  69. make_json_result(stripslashes($_POST['val']), '', array('act' => 'goods_auto', 'id' => $id));
  70. }
  71. elseif ($_REQUEST['act'] == 'edit_endtime')
  72. {
  73. check_authz_json('goods_auto');
  74. if(! preg_match('/^\d{4}-\d{2}-\d{2}$/', trim($_POST['val'])) )
  75. {
  76. make_json_error('');
  77. }
  78. $id = intval($_POST['id']);
  79. $time = local_strtotime(trim($_POST['val']));
  80. if($id <= 0 || $_POST['val'] == '0000-00-00' || $time <= 0)
  81. {
  82. make_json_error('');
  83. }
  84. $db->autoReplace($ecs->table('auto_manage'), array('item_id' => $id,'type' => 'goods',
  85. 'endtime' => $time), array('endtime' =>(string)$time));
  86. clear_cache_files();
  87. make_json_result(stripslashes($_POST['val']), '', array('act' => 'goods_auto', 'id' => $id));
  88. }
  89. //批量上架
  90. elseif ($_REQUEST['act'] == 'batch_start')
  91. {
  92. admin_priv('goods_auto');
  93. if (!isset($_POST['checkboxes']) || !is_array($_POST['checkboxes']))
  94. {
  95. sys_msg($_LANG['no_select_goods'], 1);
  96. }
  97. if($_POST['date'] == '0000-00-00')
  98. {
  99. $_POST['date'] = 0;
  100. }
  101. else
  102. {
  103. $_POST['date'] = local_strtotime(trim($_POST['date']));
  104. }
  105. foreach($_POST['checkboxes'] as $id)
  106. {
  107. $db->autoReplace($ecs->table('auto_manage'), array('item_id' => $id,'type' => 'goods',
  108. 'starttime' => $_POST['date']), array('starttime' =>(string)$_POST['date']));
  109. }
  110. $lnk[] = array('text' => $_LANG['back_list'], 'href' => 'goods_auto.php?act=list');
  111. sys_msg($_LANG['batch_start_succeed'], 0, $lnk);
  112. }
  113. //批量下架
  114. elseif ($_REQUEST['act'] == 'batch_end')
  115. {
  116. admin_priv('goods_auto');
  117. if (!isset($_POST['checkboxes']) || !is_array($_POST['checkboxes']))
  118. {
  119. sys_msg($_LANG['no_select_goods'], 1);
  120. }
  121. if($_POST['date'] == '0000-00-00')
  122. {
  123. $_POST['date'] = 0;
  124. }
  125. else
  126. {
  127. $_POST['date'] = local_strtotime(trim($_POST['date']));
  128. }
  129. foreach($_POST['checkboxes'] as $id)
  130. {
  131. $db->autoReplace($ecs->table('auto_manage'), array('item_id' => $id,'type' => 'goods',
  132. 'endtime' => $_POST['date']), array('endtime' =>(string)$_POST['date']));
  133. }
  134. $lnk[] = array('text' => $_LANG['back_list'], 'href' => 'goods_auto.php?act=list');
  135. sys_msg($_LANG['batch_end_succeed'], 0, $lnk);
  136. }
  137. function get_auto_goods()
  138. {
  139. $where = ' WHERE g.is_delete <> 1 ';
  140. if (!empty($_POST['goods_name']))
  141. {
  142. $goods_name = trim($_POST['goods_name']);
  143. $where .= " AND g.goods_name LIKE '%$goods_name%'";
  144. $filter['goods_name'] = $goods_name;
  145. }
  146. $result = get_filter();
  147. if ($result === false)
  148. {
  149. $filter['sort_by'] = empty($_REQUEST['sort_by']) ? 'last_update' : trim($_REQUEST['sort_by']);
  150. $filter['sort_order'] = empty($_REQUEST['sort_order']) ? 'DESC' : trim($_REQUEST['sort_order']);
  151. $sql = "SELECT COUNT(*) FROM " . $GLOBALS['ecs']->table('goods') . " g" . $where;
  152. $filter['record_count'] = $GLOBALS['db']->getOne($sql);
  153. /* 分页大小 */
  154. $filter = page_and_size($filter);
  155. /* 查询 */
  156. $sql = "SELECT g.*,a.starttime,a.endtime FROM " . $GLOBALS['ecs']->table('goods') . " g LEFT JOIN " . $GLOBALS['ecs']->table('auto_manage') . " a ON g.goods_id = a.item_id AND a.type='goods'" . $where .
  157. " ORDER by goods_id, " . $filter['sort_by'] . ' ' . $filter['sort_order'] .
  158. " LIMIT " . $filter['start'] . ",$filter[page_size]";
  159. set_filter($filter, $sql);
  160. }
  161. else
  162. {
  163. $sql = $result['sql'];
  164. $filter = $result['filter'];
  165. }
  166. $query = $GLOBALS['db']->query($sql);
  167. $goodsdb = array();
  168. while ($rt = $GLOBALS['db']->fetch_array($query))
  169. {
  170. if (!empty($rt['starttime']))
  171. {
  172. $rt['starttime'] = local_date('Y-m-d',$rt['starttime']);
  173. }
  174. if (!empty($rt['endtime']))
  175. {
  176. $rt['endtime'] = local_date('Y-m-d',$rt['endtime']);
  177. }
  178. $goodsdb[] = $rt;
  179. }
  180. $arr = array('goodsdb' => $goodsdb, 'filter' => $filter, 'page_count' => $filter['page_count'], 'record_count' => $filter['record_count']);
  181. return $arr;
  182. }
  183. ?>