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