Store.php 9.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231
  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 Store extends BaseStore
  14. {
  15. public function initialize()
  16. {
  17. parent::initialize();
  18. Lang::load(base_path() . 'home/lang/' . config('lang.default_lang') . '/store.lang.php');
  19. }
  20. public function index()
  21. {
  22. $editable_page_model = model('editable_page');
  23. $editable_page_info = $editable_page_model->getOneEditablePage(array('store_id' => $this->store_info['store_id'], 'editable_page_path' => 'store/index', 'editable_page_client' => 'pc'));
  24. if ($editable_page_info) {
  25. $editable_page_info['editable_page_theme_config'] = json_decode($editable_page_info['editable_page_theme_config'], true);
  26. View::assign('editable_page', $editable_page_info);
  27. $editable_page_config_model = model('editable_page_config');
  28. $editable_page_config_list = $editable_page_config_model->getEditablePageConfigList(array(array('editable_page_id', '=', $editable_page_info['editable_page_id'])));
  29. $config_list = array();
  30. foreach ($editable_page_config_list as $key => $val) {
  31. $config_info = json_decode($val['editable_page_config_content'], true);
  32. $model_id = $val['editable_page_model_id'];
  33. $var_html = array();
  34. if (!empty($config_info)) {
  35. require_once PLUGINS_PATH . '/editable_page_model/' . $model_id . '/config.php';
  36. $model_name = 'Model' . $model_id;
  37. $model = new $model_name();
  38. $res = $model->filterData($config_info);
  39. if ($res['code']) {
  40. $res = $model->formatData(json_encode($res['data']), $this->store_info['store_id']);
  41. if ($res['code']) {
  42. $var_html['config_info'] = $res['data'];
  43. }
  44. }
  45. }
  46. $html = View::fetch('../../../plugins/editable_page_model/' . $model_id . '/index', $var_html);
  47. $config_list[] = array(
  48. 'val' => $val,
  49. 'html' => $html,
  50. );
  51. }
  52. View::assign('config_list', $config_list);
  53. View::assign('editable_page', $editable_page_info);
  54. } else {
  55. $condition = array();
  56. $condition[] = array('store_id', '=', $this->store_info['store_id']);
  57. $goods_model = model('goods'); // 字段
  58. $fieldstr = "goods_id,goods_commonid,goods_name,goods_advword,store_id,store_name,goods_price,goods_promotion_price,goods_marketprice,goods_storage,goods_image,goods_freight,goods_salenum,color_id,evaluation_good_star,evaluation_count,goods_promotion_type";
  59. //得到最新12个商品列表
  60. $new_goods_list = $goods_model->getGoodsListByColorDistinct($condition, $fieldstr, 'goods_id desc', 12);
  61. $condition[] = array('goods_commend', '=', 1);
  62. //得到12个推荐商品列表
  63. $recommended_goods_list = $goods_model->getGoodsListByColorDistinct($condition, $fieldstr, 'goods_sort desc,goods_id desc', 12);
  64. $goods_list = $this->getGoodsMore($new_goods_list, $recommended_goods_list);
  65. View::assign('new_goods_list', $goods_list[1]);
  66. View::assign('recommended_goods_list', $goods_list[2]);
  67. //幻灯片图片
  68. if ($this->store_info['store_slide'] != '' && $this->store_info['store_slide'] != ',,,,') {
  69. View::assign('store_slide', explode(',', $this->store_info['store_slide']));
  70. View::assign('store_slide_url', explode(',', $this->store_info['store_slide_url']));
  71. }
  72. }
  73. View::assign('page', 'index');
  74. return View::fetch($this->template_dir . 'index');
  75. }
  76. private function getGoodsMore($goods_list1, $goods_list2 = array())
  77. {
  78. if (!empty($goods_list2)) {
  79. $goods_list = array_merge($goods_list1, $goods_list2);
  80. } else {
  81. $goods_list = $goods_list1;
  82. }
  83. // 商品多图
  84. if (!empty($goods_list)) {
  85. $goodsid_array = array(); // 商品id数组
  86. $commonid_array = array(); // 商品公共id数组
  87. $storeid_array = array(); // 店铺id数组
  88. foreach ($goods_list as $value) {
  89. $goodsid_array[] = $value['goods_id'];
  90. $commonid_array[] = $value['goods_commonid'];
  91. $storeid_array[] = $value['store_id'];
  92. }
  93. $goodsid_array = array_unique($goodsid_array);
  94. $commonid_array = array_unique($commonid_array);
  95. // 商品多图
  96. $goodsimage_more = model('goods')->getGoodsImageList(array(array('goods_commonid', 'in', $commonid_array)));
  97. foreach ($goods_list1 as $key => $value) {
  98. // 商品多图
  99. foreach ($goodsimage_more as $v) {
  100. if ($value['goods_commonid'] == $v['goods_commonid'] && $value['store_id'] == $v['store_id'] && $value['color_id'] == $v['color_id']) {
  101. $goods_list1[$key]['image'][] = $v;
  102. }
  103. }
  104. }
  105. if (!empty($goods_list2)) {
  106. foreach ($goods_list2 as $key => $value) {
  107. // 商品多图
  108. foreach ($goodsimage_more as $v) {
  109. if ($value['goods_commonid'] == $v['goods_commonid'] && $value['store_id'] == $v['store_id'] && $value['color_id'] == $v['color_id']) {
  110. $goods_list2[$key]['image'][] = $v;
  111. }
  112. }
  113. }
  114. }
  115. }
  116. return array(1 => $goods_list1, 2 => $goods_list2);
  117. }
  118. public function article()
  119. {
  120. //判断是否为导航页面
  121. $storenavigation_model = model('storenavigation');
  122. $store_navigation_info = $storenavigation_model->getStorenavigationInfo(array('storenav_id' => intval(input('param.storenav_id'))));
  123. if (!empty($store_navigation_info) && is_array($store_navigation_info)) {
  124. View::assign('store_navigation_info', $store_navigation_info);
  125. return View::fetch($this->template_dir . 'article');
  126. }
  127. }
  128. /**
  129. * 全部商品
  130. */
  131. public function goods_all()
  132. {
  133. $condition = array();
  134. $condition[] = array('store_id', '=', $this->store_info['store_id']);
  135. $inkeyword = trim(input('inkeyword'));
  136. if ($inkeyword != '') {
  137. $condition[] = array('goods_name', 'like', '%' . $inkeyword . '%');
  138. }
  139. // 排序
  140. $order = input('order');
  141. $order = $order == 1 ? 'asc' : 'desc';
  142. $key = trim(input('key'));
  143. switch ($key) {
  144. case '1':
  145. $order = 'goods_id ' . $order;
  146. break;
  147. case '2':
  148. $order = 'goods_promotion_price ' . $order;
  149. break;
  150. case '3':
  151. $order = 'goods_salenum ' . $order;
  152. break;
  153. case '4':
  154. $order = 'goods_collect ' . $order;
  155. break;
  156. case '5':
  157. $order = 'goods_click ' . $order;
  158. break;
  159. default:
  160. $order = 'goods_id desc';
  161. break;
  162. }
  163. //查询分类下的子分类
  164. $storegc_id = intval(input('storegc_id'));
  165. if ($storegc_id > 0) {
  166. $condition[] = array('goods_stcids', 'like', '%,' . $storegc_id . ',%');
  167. }
  168. $goods_model = model('goods');
  169. $fieldstr = "goods_id,goods_commonid,goods_name,goods_advword,store_id,store_name,goods_price,goods_promotion_price,goods_marketprice,goods_storage,goods_image,goods_freight,goods_salenum,color_id,evaluation_good_star,evaluation_count,goods_promotion_type";
  170. $recommended_goods_list = $goods_model->getGoodsListByColorDistinct($condition, $fieldstr, $order, 24);
  171. $recommended_goods_list = $this->getGoodsMore($recommended_goods_list);
  172. View::assign('recommended_goods_list', $recommended_goods_list[1]);
  173. /* 引用搜索相关函数 */
  174. require_once(base_path() . '/home/common_search.php');
  175. //输出分页
  176. View::assign('show_page', empty($recommended_goods_list[1]) ? '' : $goods_model->page_info->render());
  177. $stc_class = model('storegoodsclass');
  178. $stc_info = $stc_class->getStoregoodsclassInfo(array('storegc_id' => $storegc_id));
  179. View::assign('storegc_name', $stc_info['storegc_name']);
  180. View::assign('page', 'index');
  181. return View::fetch($this->template_dir . 'goods_list');
  182. }
  183. /**
  184. * ajax获取动态数量
  185. */
  186. function ajax_store_trend_count()
  187. {
  188. $count = model('storesnstracelog')->getStoresnstracelogCount(array('stracelog_storeid' => $this->store_info['store_id']));
  189. echo json_encode(array('count' => $count));
  190. exit;
  191. }
  192. /**
  193. * ajax 店铺流量统计入库
  194. */
  195. public function ajax_flowstat_record()
  196. {
  197. $store_id = intval(input('param.store_id'));
  198. $goods_id = intval(input('param.goods_id'));
  199. $controller_param = input('param.controller_param');
  200. $action_param = input('param.action_param');
  201. $store_info = model('store')->getStoreOnlineInfoByID(session('store_id'));
  202. model('store')->flowstat_record($store_id, $goods_id, $controller_param, $action_param, $store_info);
  203. }
  204. }