PageRenderTime 100ms CodeModel.GetById 26ms RepoModel.GetById 0ms app.codeStats 0ms

/app/store.app.php

https://bitbucket.org/ec4us/ecmall2
PHP | 418 lines | 350 code | 42 blank | 26 comment | 30 complexity | 504bfcbaa6a0ebfdb69330d32a3f485c MD5 | raw file
Possible License(s): LGPL-2.1
  1. <?php
  2. class StoreApp extends StorebaseApp
  3. {
  4. function index()
  5. {
  6. /* ???? */
  7. $_GET['act'] = 'index';
  8. $id = empty($_GET['id']) ? 0 : intval($_GET['id']);
  9. if (!$id)
  10. {
  11. $this->show_warning('Hacking Attempt');
  12. return;
  13. }
  14. $this->set_store($id);
  15. $store = $this->get_store_data();
  16. $this->assign('store', $store);
  17. /* ?????? */
  18. $this->assign('partners', $this->_get_partners($id));
  19. /* ?????? */
  20. $this->assign('recommended_goods', $this->_get_recommended_goods($id));
  21. $this->assign('new_groupbuy', $this->_get_new_groupbuy($id));
  22. /* ?????? */
  23. $this->assign('new_goods', $this->_get_new_goods($id));
  24. /* ???? */
  25. $this->_curlocal(LANG::get('all_stores'), 'index.php?app=search&amp;act=store', $store['store_name']);
  26. $this->assign('page_title', $store['store_name'] . ' - ' . Conf::get('site_title'));
  27. $this->display('store.index.html');
  28. }
  29. function search()
  30. {
  31. /* ???? */
  32. $id = empty($_GET['id']) ? 0 : intval($_GET['id']);
  33. if (!$id)
  34. {
  35. $this->show_warning('Hacking Attempt');
  36. return;
  37. }
  38. $this->set_store($id);
  39. $store = $this->get_store_data();
  40. $this->assign('store', $store);
  41. /* ?????? */
  42. $this->_assign_searched_goods($id);
  43. /* ???? */
  44. $this->_curlocal(LANG::get('all_stores'), 'index.php?app=search&amp;act=store',
  45. $store['store_name'], 'index.php?app=store&amp;id=' . $store['store_id'],
  46. LANG::get('goods_list')
  47. );
  48. $this->assign('page_title', Lang::get('goods_list') . ' - ' . $store['store_name']);
  49. $this->display('store.search.html');
  50. }
  51. function groupbuy()
  52. {
  53. /* ???? */
  54. $id = empty($_GET['id']) ? 0 : intval($_GET['id']);
  55. if (!$id)
  56. {
  57. $this->show_warning('Hacking Attempt');
  58. return;
  59. }
  60. $this->set_store($id);
  61. $store = $this->get_store_data();
  62. $this->assign('store', $store);
  63. /* ???? */
  64. empty($_GET['state']) && $_GET['state'] = 'on';
  65. $conditions = '1=1';
  66. if ($_GET['state'] == 'on')
  67. {
  68. $conditions .= ' AND gb.state ='. GROUP_ON .' AND gb.end_time>' . gmtime();
  69. $search_name = array(
  70. array(
  71. 'text' => Lang::get('group_on')
  72. ),
  73. array(
  74. 'text' => Lang::get('all_groupbuy'),
  75. 'url' => url('app=store&act=groupbuy&state=all&id=' . $id)
  76. ),
  77. );
  78. }
  79. else if ($_GET['state'] == 'all')
  80. {
  81. $conditions .= ' AND gb.state '. db_create_in(array(GROUP_ON,GROUP_END,GROUP_FINISHED));
  82. $search_name = array(
  83. array(
  84. 'text' => Lang::get('all_groupbuy')
  85. ),
  86. array(
  87. 'text' => Lang::get('group_on'),
  88. 'url' => url('app=store&act=groupbuy&state=on&id=' . $id)
  89. ),
  90. );
  91. }
  92. $page = $this->_get_page(16);
  93. $groupbuy_mod = &m('groupbuy');
  94. $groupbuy_list = $groupbuy_mod->find(array(
  95. 'fields' => 'goods.default_image, gb.group_name, gb.group_id, gb.spec_price, gb.end_time, gb.state',
  96. 'join' => 'belong_goods',
  97. 'conditions'=> $conditions . ' AND gb.store_id=' . $id ,
  98. 'order' => 'group_id DESC',
  99. 'limit' => $page['limit'],
  100. 'count' => true
  101. ));
  102. $page['item_count'] = $groupbuy_mod->getCount();
  103. $this->_format_page($page);
  104. $this->assign('page_info', $page);
  105. if (empty($groupbuy_list))
  106. {
  107. $groupbuy_list = array();
  108. }
  109. foreach ($groupbuy_list as $key => $_g)
  110. {
  111. empty($groupbuy_list[$key]['default_image']) && $groupbuy_list[$key]['default_image'] = Conf::get('default_goods_image');
  112. $tmp = current(unserialize($_g['spec_price']));
  113. $groupbuy_list[$key]['price'] = $tmp['price'];
  114. if ($_g['end_time'] < gmtime())
  115. {
  116. $groupbuy_list[$key]['group_state'] = group_state($_g['state']);
  117. }
  118. else
  119. {
  120. $groupbuy_list[$key]['lefttime'] = lefttime($_g['end_time']);
  121. }
  122. }
  123. /* ???? */
  124. $this->_curlocal(LANG::get('all_stores'), 'index.php?app=search&amp;act=store',
  125. $store['store_name'], 'index.php?app=store&amp;id=' . $store['store_id'],
  126. LANG::get('groupbuy_list')
  127. );
  128. $this->assign('groupbuy_list', $groupbuy_list);
  129. $this->assign('search_name', $search_name);
  130. $this->assign('page_title', $search_name[0]['text'] . ' - ' . $store['store_name']);
  131. $this->display('store.groupbuy.html');
  132. }
  133. function article()
  134. {
  135. $id = empty($_GET['id']) ? 0 : intval($_GET['id']);
  136. if (!$id)
  137. {
  138. $this->show_warning('Hacking Attempt');
  139. return;
  140. }
  141. $article = $this->_get_article($id);
  142. if (!$article)
  143. {
  144. $this->show_warning('Hacking Attempt');
  145. return;
  146. }
  147. $this->assign('article', $article);
  148. /* ???? */
  149. $this->set_store($article['store_id']);
  150. $store = $this->get_store_data();
  151. $this->assign('store', $store);
  152. /* ???? */
  153. $this->_curlocal(LANG::get('all_stores'), 'index.php?app=search&amp;act=store',
  154. $store['store_name'], 'index.php?app=store&amp;id=' . $store['store_id'],
  155. $article['title']
  156. );
  157. $this->assign('page_title', $article['title'] . ' - ' . $store['store_name']);
  158. $this->display('store.article.html');
  159. }
  160. /* ???? */
  161. function credit()
  162. {
  163. /* ???? */
  164. $id = empty($_GET['id']) ? 0 : intval($_GET['id']);
  165. if (!$id)
  166. {
  167. $this->show_warning('Hacking Attempt');
  168. return;
  169. }
  170. $this->set_store($id);
  171. $store = $this->get_store_data();
  172. $this->assign('store', $store);
  173. /* ???????? */
  174. if (!empty($_GET['eval']) && in_array($_GET['eval'], array(1,2,3)))
  175. {
  176. $conditions = "AND evaluation = '{$_GET['eval']}'";
  177. }
  178. else
  179. {
  180. $conditions = "";
  181. $_GET['eval'] = '';
  182. }
  183. $page = $this->_get_page(10);
  184. $order_goods_mod =& m('ordergoods');
  185. $goods_list = $order_goods_mod->find(array(
  186. 'conditions' => "seller_id = '$id' AND evaluation_status = 1 AND is_valid = 1 " . $conditions,
  187. 'join' => 'belongs_to_order',
  188. 'fields' => 'buyer_id, buyer_name, anonymous, evaluation_time, goods_id, goods_name, specification, price, quantity, goods_image, evaluation, comment',
  189. 'order' => 'evaluation_time desc',
  190. 'limit' => $page['limit'],
  191. 'count' => true,
  192. ));
  193. $this->assign('goods_list', $goods_list);
  194. $page['item_count'] = $order_goods_mod->getCount();
  195. $this->_format_page($page);
  196. $this->assign('page_info', $page);
  197. /* ????? */
  198. $stats = array();
  199. for ($i = 0; $i <= 3; $i++)
  200. {
  201. $stats[$i]['in_a_week'] = 0;
  202. $stats[$i]['in_a_month'] = 0;
  203. $stats[$i]['in_six_month'] = 0;
  204. $stats[$i]['six_month_before'] = 0;
  205. $stats[$i]['total'] = 0;
  206. }
  207. $goods_list = $order_goods_mod->find(array(
  208. 'conditions' => "seller_id = '$id' AND evaluation_status = 1 AND is_valid = 1 ",
  209. 'join' => 'belongs_to_order',
  210. 'fields' => 'evaluation_time, evaluation',
  211. ));
  212. foreach ($goods_list as $goods)
  213. {
  214. $eval = $goods['evaluation'];
  215. $stats[$eval]['total']++;
  216. $stats[0]['total']++;
  217. $days = (gmtime() - $goods['evaluation_time']) / (24 * 3600);
  218. if ($days <= 7)
  219. {
  220. $stats[$eval]['in_a_week']++;
  221. $stats[0]['in_a_week']++;
  222. }
  223. if ($days <= 30)
  224. {
  225. $stats[$eval]['in_a_month']++;
  226. $stats[0]['in_a_month']++;
  227. }
  228. if ($days <= 180)
  229. {
  230. $stats[$eval]['in_six_month']++;
  231. $stats[0]['in_six_month']++;
  232. }
  233. if ($days > 180)
  234. {
  235. $stats[$eval]['six_month_before']++;
  236. $stats[0]['six_month_before']++;
  237. }
  238. }
  239. $this->assign('stats', $stats);
  240. /* ???? */
  241. $this->_curlocal(LANG::get('all_stores'), 'index.php?app=search&amp;act=store',
  242. $store['store_name'], 'index.php?app=store&amp;id=' . $store['store_id'],
  243. LANG::get('credit_evaluation')
  244. );
  245. $this->assign('page_title', Lang::get('credit_evaluation') . ' - ' . $store['store_name']);
  246. $this->display('store.credit.html');
  247. }
  248. /* ?????? */
  249. function _get_partners($id)
  250. {
  251. $partner_mod =& m('partner');
  252. return $partner_mod->find(array(
  253. 'conditions' => "store_id = '$id'",
  254. 'order' => 'sort_order',
  255. ));
  256. }
  257. /* ?????? */
  258. function _get_recommended_goods($id, $num = 12)
  259. {
  260. $goods_mod =& bm('goods', array('_store_id' => $id));
  261. $goods_list = $goods_mod->find(array(
  262. 'conditions' => "closed = 0 AND if_show = 1 AND recommended = 1",
  263. 'fields' => 'goods_name, default_image, price',
  264. 'limit' => $num,
  265. ));
  266. foreach ($goods_list as $key => $goods)
  267. {
  268. empty($goods['default_image']) && $goods_list[$key]['default_image'] = Conf::get('default_goods_image');
  269. }
  270. return $goods_list;
  271. }
  272. function _get_new_groupbuy($id, $num = 12)
  273. {
  274. $model_groupbuy =& m('groupbuy');
  275. $groupbuy_list = $model_groupbuy->find(array(
  276. 'fields' => 'goods.default_image, this.group_name, this.group_id, this.spec_price, this.end_time',
  277. 'join' => 'belong_goods',
  278. 'conditions'=> $model_groupbuy->getRealFields('this.state=' . GROUP_ON . ' AND this.store_id=' . $id . ' AND end_time>'. gmtime()),
  279. 'order' => 'group_id DESC',
  280. 'limit' => $num
  281. ));
  282. if (empty($groupbuy_list))
  283. {
  284. $groupbuy_list = array();
  285. }
  286. foreach ($groupbuy_list as $key => $_g)
  287. {
  288. empty($groupbuy_list[$key]['default_image']) && $groupbuy_list[$key]['default_image'] = Conf::get('default_goods_image');
  289. $tmp = current(unserialize($_g['spec_price']));
  290. $groupbuy_list[$key]['price'] = $tmp['price'];
  291. $groupbuy_list[$key]['lefttime'] = lefttime($_g['end_time']);
  292. }
  293. return $groupbuy_list;
  294. }
  295. /* ?????? */
  296. function _get_new_goods($id, $num = 12)
  297. {
  298. $goods_mod =& bm('goods', array('_store_id' => $id));
  299. $goods_list = $goods_mod->find(array(
  300. 'conditions' => "closed = 0 AND if_show = 1",
  301. 'fields' => 'goods_name, default_image, price',
  302. 'order' => 'add_time desc',
  303. 'limit' => $num,
  304. ));
  305. foreach ($goods_list as $key => $goods)
  306. {
  307. empty($goods['default_image']) && $goods_list[$key]['default_image'] = Conf::get('default_goods_image');
  308. }
  309. return $goods_list;
  310. }
  311. /* ?????? */
  312. function _assign_searched_goods($id)
  313. {
  314. $goods_mod =& bm('goods', array('_store_id' => $id));
  315. $search_name = LANG::get('all_goods');
  316. $conditions = $this->_get_query_conditions(array(
  317. array(
  318. 'field' => 'goods_name',
  319. 'name' => 'keyword',
  320. 'equal' => 'like',
  321. ),
  322. ));
  323. if ($conditions)
  324. {
  325. $search_name = sprintf(LANG::get('goods_include'), $_GET['keyword']);
  326. $sgcate_id = 0;
  327. }
  328. else
  329. {
  330. $sgcate_id = empty($_GET['cate_id']) ? 0 : intval($_GET['cate_id']);
  331. }
  332. if ($sgcate_id > 0)
  333. {
  334. $gcategory_mod =& bm('gcategory', array('_store_id' => $id));
  335. $sgcate = $gcategory_mod->get_info($sgcate_id);
  336. $search_name = $sgcate['cate_name'];
  337. $sgcate_ids = $gcategory_mod->get_descendant_ids($sgcate_id);
  338. }
  339. else
  340. {
  341. $sgcate_ids = array();
  342. }
  343. /* ???? */
  344. $orders = array(
  345. 'add_time desc' => LANG::get('add_time_desc'),
  346. 'price asc' => LANG::get('price_asc'),
  347. 'price desc' => LANG::get('price_desc'),
  348. );
  349. $this->assign('orders', $orders);
  350. $page = $this->_get_page(16);
  351. $goods_list = $goods_mod->get_list(array(
  352. 'conditions' => 'closed = 0 AND if_show = 1' . $conditions,
  353. 'count' => true,
  354. 'order' => empty($_GET['order']) || !isset($orders[$_GET['order']]) ? 'add_time desc' : $_GET['order'],
  355. 'limit' => $page['limit'],
  356. ), $sgcate_ids);
  357. foreach ($goods_list as $key => $goods)
  358. {
  359. empty($goods['default_image']) && $goods_list[$key]['default_image'] = Conf::get('default_goods_image');
  360. }
  361. $this->assign('searched_goods', $goods_list);
  362. $page['item_count'] = $goods_mod->getCount();
  363. $this->_format_page($page);
  364. $this->assign('page_info', $page);
  365. $this->assign('search_name', $search_name);
  366. }
  367. /**
  368. * ??????
  369. */
  370. function _get_article($id)
  371. {
  372. $article_mod =& m('article');
  373. return $article_mod->get_info($id);
  374. }
  375. }
  376. ?>