Store.php 10 KB

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