Showgroupbuy.php 14 KB

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