Showgroupbuy.php 14 KB

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