Store.php 10 KB

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