Showgroupbuy.php 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381
  1. <?php
  2. namespace app\home\controller;
  3. use think\facade\View;
  4. use think\facade\Lang;
  5. use think\facade\Db;
  6. /**
  7. *
  8. *
  9. * ----------------------------------------------------------------------------
  10. *
  11. * 控制器
  12. */
  13. class Showgroupbuy extends BaseMall
  14. {
  15. public function initialize()
  16. {
  17. parent::initialize(); // TODO: Change the autogenerated stub
  18. Lang::load(base_path() . 'home/lang/' . config('lang.default_lang') . '/groupbuy.lang.php');
  19. //检查抢购功能是否开启
  20. if (intval(config('ds_config.groupbuy_allow')) !== 1) {
  21. $this->error(lang('groupbuy_unavailable'), 'index');
  22. }
  23. if (request()->action() != 'groupbuy_detail') {
  24. // 抢购价格区间
  25. $this->groupbuy_price = rkcache('groupbuyprice', true);
  26. View::assign('price_list', $this->groupbuy_price);
  27. $groupbuy_model = model('groupbuy');
  28. // 线上抢购分类
  29. $this->groupbuy_classes = $groupbuy_model->getGroupbuyClasses();
  30. View::assign('groupbuy_classes', $this->groupbuy_classes);
  31. // 虚拟抢购分类
  32. $this->groupbuy_vr_classes = $groupbuy_model->getGroupbuyVrClasses();
  33. View::assign('groupbuy_vr_classes', $this->groupbuy_vr_classes);
  34. }
  35. }
  36. /**
  37. * 抢购聚合页
  38. */
  39. public function index()
  40. {
  41. $groupbuy_model = model('groupbuy');
  42. // 线上抢购 buy_quantity(virtual_quantity or groupbuy_buy_quantity)?
  43. $groupbuy = $groupbuy_model->getGroupbuyOnlineList(array(array('groupbuy_recommended', '=', 1), array('groupbuy_is_vr', '=', 0)), 9);
  44. View::assign('groupbuy', $groupbuy);
  45. // 虚拟抢购
  46. $vr_groupbuy = $groupbuy_model->getGroupbuyOnlineList(array(array('groupbuy_recommended', '=', 1), array('groupbuy_is_vr', '=', 1)), 9);
  47. View::assign('vr_groupbuy', $vr_groupbuy);
  48. // 轮播图片
  49. $picArr = array();
  50. foreach (range(1, 4) as $i) {
  51. $a = config('ds_config.live_pic' . $i);
  52. if ($a) {
  53. $picArr[] = array($a, config('ds_config.live_link' . $i));
  54. }
  55. }
  56. View::assign('picArr', $picArr);
  57. View::assign('current', 'online');
  58. return View::fetch($this->template_dir . 'index');
  59. }
  60. /**
  61. * 进行中的虚拟抢购
  62. */
  63. public function vr_groupbuy_list()
  64. {
  65. View::assign('current', 'online');
  66. View::assign('buy_button', lang('groupbuy_buy'));
  67. $this->_show_vr_groupbuy_list('getGroupbuyOnlineList');
  68. return View::fetch($this->template_dir . 'groupbuy_vr_list');
  69. }
  70. /**
  71. * 即将开始的虚拟抢购
  72. */
  73. public function vr_groupbuy_soon()
  74. {
  75. View::assign('current', 'soon');
  76. View::assign('buy_button', lang('not_at_the'));
  77. $this->_show_vr_groupbuy_list('getGroupbuySoonList');
  78. return View::fetch($this->template_dir . 'groupbuy_vr_list');
  79. }
  80. /**
  81. * 往期虚拟抢购
  82. */
  83. public function vr_groupbuy_history()
  84. {
  85. View::assign('current', 'history');
  86. View::assign('buy_button', lang('has_ended'));
  87. $this->_show_vr_groupbuy_list('getGroupbuyHistoryList');
  88. return View::fetch($this->template_dir . 'groupbuy_vr_list');
  89. }
  90. /**
  91. * 获取抢购列表
  92. */
  93. private function _show_vr_groupbuy_list($function_name)
  94. {
  95. $groupbuy_model = model('groupbuy');
  96. $condition = array(
  97. array('groupbuy_is_vr', '=', 1)
  98. );
  99. $order = '';
  100. // 分类筛选条件
  101. if (($vr_class_id = (int) input('vr_class')) > 0) {
  102. $condition[] = array('vr_class_id', '=', $vr_class_id);
  103. if (($vr_s_class_id = (int) input('vr_s_class')) > 0)
  104. $condition[] = array('vr_s_class_id', '=', $vr_s_class_id);
  105. }
  106. // 价格区间筛选条件
  107. if (($price_id = intval(input('groupbuy_price'))) > 0 && isset($this->groupbuy_price[$price_id])) {
  108. $p = $this->groupbuy_price[$price_id];
  109. $condition[] = array('groupbuy_price', 'between', array($p['gprange_start'], $p['gprange_end']));
  110. }
  111. // 排序
  112. $groupbuy_order_key = trim(input('groupbuy_order_key'));
  113. $groupbuy_order = input('groupbuy_order') == '2' ? 'desc' : 'asc';
  114. if (!empty($groupbuy_order_key)) {
  115. switch ($groupbuy_order_key) {
  116. case '1':
  117. $order = 'groupbuy_price ' . $groupbuy_order;
  118. break;
  119. case '2':
  120. $order = 'groupbuy_rebate ' . $groupbuy_order;
  121. break;
  122. case '3':
  123. $order = 'groupbuy_buyer_count ' . $groupbuy_order;
  124. break;
  125. }
  126. }
  127. $groupbuy_list = $groupbuy_model->$function_name($condition, 20, $order);
  128. View::assign('groupbuy_list', $groupbuy_list);
  129. View::assign('show_page', $groupbuy_model->page_info->render());
  130. View::assign('html_title', lang('text_groupbuy_list'));
  131. $this->_assign_seo(model('seo')->type('group')->show());
  132. /* 引用搜索相关函数 */
  133. require_once(base_path() . '/home/common_search.php');
  134. View::assign('groupbuyMenuIsVr', 1);
  135. }
  136. /**
  137. * 进行中的抢购抢购
  138. * */
  139. public function groupbuy_list()
  140. {
  141. View::assign('current', 'online');
  142. View::assign('buy_button', lang('groupbuy_buy'));
  143. $this->_show_groupbuy_list('getGroupbuyOnlineList');
  144. return View::fetch($this->template_dir . 'groupbuy_list');
  145. }
  146. /**
  147. * 即将开始的抢购
  148. * */
  149. public function groupbuy_soon()
  150. {
  151. View::assign('current', 'soon');
  152. View::assign('buy_button', lang('not_at_the'));
  153. $this->_show_groupbuy_list('getGroupbuySoonList');
  154. return View::fetch($this->template_dir . 'groupbuy_list');
  155. }
  156. /**
  157. * 往期抢购
  158. * */
  159. public function groupbuy_history()
  160. {
  161. View::assign('current', 'history');
  162. View::assign('buy_button', lang('has_ended'));
  163. $this->_show_groupbuy_list('getGroupbuyHistoryList');
  164. return View::fetch($this->template_dir . 'groupbuy_list');
  165. }
  166. /**
  167. * 获取抢购列表
  168. * */
  169. private function _show_groupbuy_list($function_name)
  170. {
  171. $groupbuy_model = model('groupbuy');
  172. $condition = array();
  173. $condition[] = array('groupbuy_is_vr', '=', 0);
  174. $order = '';
  175. // 分类筛选条件
  176. if (($gclass_id = (int) input('class')) > 0) {
  177. $condition[] = array('gclass_id', '=', $gclass_id);
  178. if (($s_gclass_id = (int) input('s_class')) > 0)
  179. $condition[] = array('s_gclass_id', '=', $s_gclass_id);
  180. }
  181. // 价格区间筛选条件
  182. if (($price_id = intval(input('groupbuy_price'))) > 0 && isset($this->groupbuy_price[$price_id])) {
  183. $p = $this->groupbuy_price[$price_id];
  184. $condition[] = array('groupbuy_price', 'between', array($p['gprange_start'], $p['gprange_end']));
  185. }
  186. // 排序
  187. $groupbuy_order_key = trim(input('groupbuy_order_key'));
  188. $groupbuy_order = input('groupbuy_order') == '2' ? 'desc' : 'asc';
  189. if (!empty($groupbuy_order_key)) {
  190. switch ($groupbuy_order_key) {
  191. case '1':
  192. $order = 'groupbuy_price ' . $groupbuy_order;
  193. break;
  194. case '2':
  195. $order = 'groupbuy_rebate ' . $groupbuy_order;
  196. break;
  197. case '3':
  198. $order = 'groupbuy_buyer_count ' . $groupbuy_order;
  199. break;
  200. }
  201. }
  202. $groupbuy_list = $groupbuy_model->$function_name($condition, 20, $order);
  203. View::assign('groupbuy_list', $groupbuy_list);
  204. View::assign('show_page', $groupbuy_model->page_info->render());
  205. View::assign('html_title', lang('text_groupbuy_list'));
  206. $this->_assign_seo(model('seo')->type('group')->show());
  207. /* 引用搜索相关函数 */
  208. require_once(base_path() . '/home/common_search.php');
  209. View::assign('groupbuyMenuIsVr', 0);
  210. }
  211. /**
  212. * 抢购详细信息
  213. * */
  214. public function groupbuy_detail()
  215. {
  216. $group_id = intval(input('param.group_id'));
  217. $groupbuy_model = model('groupbuy');
  218. $store_model = model('store');
  219. //获取抢购详细信息
  220. $groupbuy_info = $groupbuy_model->getGroupbuyInfoByID($group_id);
  221. if (empty($groupbuy_info)) {
  222. $this->error(lang('param_error'), 'showgroupbuy/index');
  223. }
  224. View::assign('groupbuy_info', $groupbuy_info);
  225. View::assign('groupbuyMenuIsVr', (bool) $groupbuy_info['groupbuy_is_vr']);
  226. if ($groupbuy_info['groupbuy_is_vr']) {
  227. $goods_info = model('goods')->getGoodsInfoByID($groupbuy_info['goods_id']);
  228. $buy_limit = max(0, (int) $goods_info['virtual_limit']);
  229. $upper_limit = max(0, (int) $groupbuy_info['groupbuy_upper_limit']);
  230. if ($buy_limit < 1 || ($buy_limit > 0 && $upper_limit > 0 && $buy_limit > $upper_limit)) {
  231. $buy_limit = $upper_limit;
  232. }
  233. View::assign('goods_info', $goods_info);
  234. View::assign('buy_limit', $buy_limit);
  235. } else {
  236. View::assign('buy_limit', $groupbuy_info['groupbuy_upper_limit']);
  237. }
  238. // 输出店铺信息
  239. $store_info = $store_model->getStoreInfoByID($groupbuy_info['store_id']);
  240. View::assign('store_info', $store_info);
  241. // 浏览数加1
  242. $update_array = array();
  243. $update_array['groupbuy_views'] = Db::raw('groupbuy_views+1');
  244. $groupbuy_model->editGroupbuy($update_array, array('groupbuy_id' => $group_id));
  245. //获取店铺推荐商品
  246. $commended_groupbuy_list = $groupbuy_model->getGroupbuyCommendedList(8);
  247. View::assign('commended_groupbuy_list', $commended_groupbuy_list);
  248. // 好评率
  249. $evaluategoods_model = model('evaluategoods');
  250. $evaluate_info = $evaluategoods_model->getEvaluategoodsInfoByCommonidID($groupbuy_info['goods_commonid']);
  251. View::assign('evaluate_info', $evaluate_info);
  252. $this->_assign_seo(model('seo')->type('group_content')->param(array('name' => $groupbuy_info['groupbuy_name']))->show());
  253. /* 引用搜索相关函数 */
  254. require_once(base_path() . '/home/common_search.php');
  255. return View::fetch($this->template_dir . 'groupbuy_detail');
  256. }
  257. /**
  258. * 购买记录
  259. */
  260. public function groupbuy_order()
  261. {
  262. $group_id = intval(input('group_id'));
  263. if ($group_id > 0) {
  264. if (!input('is_vr')) {
  265. //获取购买记录
  266. $order_model = model('order');
  267. $condition = array();
  268. $condition[] = array('goods_type', '=', 2);
  269. $condition[] = array('promotions_id', '=', $group_id);
  270. $order_goods_list = $order_model->getOrdergoodsList($condition, '*', 0, 10);
  271. View::assign('order_goods_list', $order_goods_list);
  272. View::assign('show_page', $order_model->page_info->render());
  273. if (!empty($order_goods_list)) {
  274. $orderid_array = array();
  275. foreach ($order_goods_list as $value) {
  276. $orderid_array[] = $value['order_id'];
  277. }
  278. $order_list = $order_model->getNormalOrderList(array(array('order_id', 'in', $orderid_array)), '', 'order_id,buyer_name,add_time');
  279. $order_list = array_under_reset($order_list, 'order_id');
  280. View::assign('order_list', $order_list);
  281. }
  282. } else {
  283. $vrorder_model = model('vrorder');
  284. $condition = array();
  285. $condition[] = array('order_promotion_type', '=', 1);
  286. $condition[] = array('promotions_id', '=', $group_id);
  287. $order_goods_list = $vrorder_model->getVrorderAndOrderGoodsSalesRecordList($condition, '*', 10);
  288. View::assign('order_goods_list', $order_goods_list);
  289. View::assign('show_page', $vrorder_model->page_info->render());
  290. }
  291. }
  292. echo View::fetch($this->template_dir . 'groupbuy_order');
  293. }
  294. /**
  295. * 商品评价
  296. */
  297. public function groupbuy_evaluate()
  298. {
  299. $goods_commonid = intval(input('commonid'));
  300. if ($goods_commonid > 0) {
  301. $condition = array();
  302. $condition[] = array('goods_commonid', '=', $goods_commonid);
  303. $goods_list = model('goods')->getGoodsList($condition, 'goods_id');
  304. if (!empty($goods_list)) {
  305. $goodsid_array = array();
  306. foreach ($goods_list as $value) {
  307. $goodsid_array[] = $value['goods_id'];
  308. }
  309. $evaluategoods_model = model('evaluategoods');
  310. $where = array();
  311. $where[] = array('geval_goodsid', 'in', $goodsid_array);
  312. $evaluate_list = $evaluategoods_model->getEvaluategoodsList($where, 10);
  313. View::assign('goodsevallist', $evaluate_list);
  314. View::assign('show_page', $evaluategoods_model->page_info->render());
  315. }
  316. }
  317. echo View::fetch($this->template_dir . 'groupbuy_evaluate');
  318. }
  319. }