Store.php 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249
  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 = $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) {
  27. Lang::load(base_path() . 'home/lang/' . config('lang.default_lang') . '/seller_editable_page.lang.php');
  28. $editable_page['if_edit'] = 0;
  29. $editable_page['editable_page_theme_config'] = json_decode($editable_page['editable_page_theme_config'], true);
  30. //获取可编辑模块
  31. $data = $editable_page_model->getEditablePageConfigByPageId($editable_page['editable_page_id'],$this->store_info['store_id']);
  32. View::assign('editable_page_config_list', $data['editable_page_config_list']);
  33. View::assign('editable_page', $editable_page);
  34. } else {
  35. $condition = array();
  36. $condition[]=array('store_id','=',$this->store_info['store_id']);
  37. $goods_model = model('goods'); // 字段
  38. $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";
  39. //得到最新12个商品列表
  40. $new_goods_list = $goods_model->getGoodsListByColorDistinct($condition, $fieldstr, 'goods_id desc', 12);
  41. $condition[]=array('goods_commend','=',1);
  42. //得到12个推荐商品列表
  43. $recommended_goods_list = $goods_model->getGoodsListByColorDistinct($condition, $fieldstr, 'goods_sort desc,goods_id desc', 12);
  44. $goods_list = $this->getGoodsMore($new_goods_list, $recommended_goods_list);
  45. View::assign('new_goods_list', $goods_list[1]);
  46. View::assign('recommended_goods_list', $goods_list[2]);
  47. //幻灯片图片
  48. if ($this->store_info['store_slide'] != '' && $this->store_info['store_slide'] != ',,,,') {
  49. View::assign('store_slide', explode(',', $this->store_info['store_slide']));
  50. View::assign('store_slide_url', explode(',', $this->store_info['store_slide_url']));
  51. }
  52. }
  53. View::assign('page', 'index');
  54. return View::fetch($this->template_dir . 'index');
  55. }
  56. private function getGoodsMore($goods_list1, $goods_list2 = array()) {
  57. if (!empty($goods_list2)) {
  58. $goods_list = array_merge($goods_list1, $goods_list2);
  59. } else {
  60. $goods_list = $goods_list1;
  61. }
  62. // 商品多图
  63. if (!empty($goods_list)) {
  64. $goodsid_array = array(); // 商品id数组
  65. $commonid_array = array(); // 商品公共id数组
  66. $storeid_array = array(); // 店铺id数组
  67. foreach ($goods_list as $value) {
  68. $goodsid_array[] = $value['goods_id'];
  69. $commonid_array[] = $value['goods_commonid'];
  70. $storeid_array[] = $value['store_id'];
  71. }
  72. $goodsid_array = array_unique($goodsid_array);
  73. $commonid_array = array_unique($commonid_array);
  74. // 商品多图
  75. $goodsimage_more = model('goods')->getGoodsImageList(array(array('goods_commonid', 'in', $commonid_array)));
  76. foreach ($goods_list1 as $key => $value) {
  77. // 商品多图
  78. foreach ($goodsimage_more as $v) {
  79. if ($value['goods_commonid'] == $v['goods_commonid'] && $value['store_id'] == $v['store_id'] && $value['color_id'] == $v['color_id']) {
  80. $goods_list1[$key]['image'][] = $v;
  81. }
  82. }
  83. }
  84. if (!empty($goods_list2)) {
  85. foreach ($goods_list2 as $key => $value) {
  86. // 商品多图
  87. foreach ($goodsimage_more as $v) {
  88. if ($value['goods_commonid'] == $v['goods_commonid'] && $value['store_id'] == $v['store_id'] && $value['color_id'] == $v['color_id']) {
  89. $goods_list2[$key]['image'][] = $v;
  90. }
  91. }
  92. }
  93. }
  94. }
  95. return array(1 => $goods_list1, 2 => $goods_list2);
  96. }
  97. public function article() {
  98. //判断是否为导航页面
  99. $storenavigation_model = model('storenavigation');
  100. $store_navigation_info = $storenavigation_model->getStorenavigationInfo(array('storenav_id' => intval(input('param.storenav_id'))));
  101. if (!empty($store_navigation_info) && is_array($store_navigation_info)) {
  102. View::assign('store_navigation_info', $store_navigation_info);
  103. return View::fetch($this->template_dir . 'article');
  104. }
  105. }
  106. /**
  107. * 全部商品
  108. */
  109. public function goods_all() {
  110. $condition = array();
  111. $condition[] = array('store_id', '=', $this->store_info['store_id']);
  112. $inkeyword = trim(input('inkeyword'));
  113. if ($inkeyword != '') {
  114. $condition[] = array('goods_name', 'like', '%' . $inkeyword . '%');
  115. }
  116. // 排序
  117. $order = input('order');
  118. $order = $order == 1 ? 'asc' : 'desc';
  119. $key = trim(input('key'));
  120. switch ($key) {
  121. case '1':
  122. $order = 'goods_id ' . $order;
  123. break;
  124. case '2':
  125. $order = 'goods_promotion_price ' . $order;
  126. break;
  127. case '3':
  128. $order = 'goods_salenum ' . $order;
  129. break;
  130. case '4':
  131. $order = 'goods_collect ' . $order;
  132. break;
  133. case '5':
  134. $order = 'goods_click ' . $order;
  135. break;
  136. default:
  137. $order = 'goods_id desc';
  138. break;
  139. }
  140. //查询分类下的子分类
  141. $storegc_id = intval(input('storegc_id'));
  142. if ($storegc_id > 0) {
  143. $condition[] = array('goods_stcids', 'like', '%,' . $storegc_id . ',%');
  144. }
  145. $goods_model = model('goods');
  146. $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";
  147. $recommended_goods_list = $goods_model->getGoodsListByColorDistinct($condition, $fieldstr, $order, 24);
  148. $recommended_goods_list = $this->getGoodsMore($recommended_goods_list);
  149. View::assign('recommended_goods_list', $recommended_goods_list[1]);
  150. /* 引用搜索相关函数 */
  151. require_once(base_path() . '/home/common_search.php');
  152. //输出分页
  153. View::assign('show_page', empty($recommended_goods_list[1]) ? '' : $goods_model->page_info->render());
  154. $stc_class = model('storegoodsclass');
  155. $stc_info = $stc_class->getStoregoodsclassInfo(array('storegc_id' => $storegc_id));
  156. View::assign('storegc_name', $stc_info['storegc_name']);
  157. View::assign('page', 'index');
  158. return View::fetch($this->template_dir . 'goods_list');
  159. }
  160. /**
  161. * ajax获取动态数量
  162. */
  163. function ajax_store_trend_count() {
  164. $count = model('storesnstracelog')->getStoresnstracelogCount(array('stracelog_storeid' => $this->store_info['store_id']));
  165. echo json_encode(array('count' => $count));
  166. exit;
  167. }
  168. /**
  169. * ajax 店铺流量统计入库
  170. */
  171. public function ajax_flowstat_record() {
  172. $store_id = intval(input('param.store_id'));
  173. if ($store_id <= 0 || session('store_id') == $store_id) {
  174. echo json_encode(array('done' => true, 'msg' => 'done'));
  175. die;
  176. }
  177. //确定统计分表名称
  178. $last_num = $store_id % 10; //获取店铺ID的末位数字
  179. $tablenum = ($t = intval(config('ds_config.flowstat_tablenum'))) > 1 ? $t : 1; //处理流量统计记录表数量
  180. $flow_tablename = ($t = ($last_num % $tablenum)) > 0 ? "flowstat_$t" : 'flowstat';
  181. //判断是否存在当日数据信息
  182. $stattime = strtotime(date('Y-m-d', TIMESTAMP));
  183. $stat_model = model('stat');
  184. //查询店铺流量统计数据是否存在
  185. // halt($flow_tablename);
  186. if ($flow_tablename == 'flowstat') {
  187. $flow_tablename_condition = array('flowstat_stattime' => $stattime, 'store_id' => $store_id, 'flowstat_type' => 'sum');
  188. } else {
  189. $flow_tablename_condition = array('flowstat_stattime' => $stattime, 'store_id' => $store_id, 'flowstat_type' => 'sum');
  190. }
  191. $store_exist = $stat_model->getoneByFlowstat($flow_tablename, $flow_tablename_condition);
  192. if (input('param.controller_param') == 'Goods' && input('param.action_param') == 'index') {//统计商品页面流量
  193. $goods_id = intval(input('param.goods_id'));
  194. if ($goods_id <= 0) {
  195. echo json_encode(array('done' => false, 'msg' => 'done'));
  196. die;
  197. }
  198. if ($flow_tablename == 'flowstat') {
  199. $flow_tablename_condition = array('flowstat_stattime' => $stattime, 'goods_id' => $goods_id, 'flowstat_type' => 'goods');
  200. } else {
  201. $flow_tablename_condition = array('flowstat_stattime' => $stattime, 'goods_id' => $goods_id, 'flowstat_type' => 'goods');
  202. }
  203. $goods_exist = $stat_model->getoneByFlowstat($flow_tablename, $flow_tablename_condition);
  204. }
  205. //向数据库写入访问量数据
  206. $insert_arr = array();
  207. if ($store_exist) {
  208. Db::name($flow_tablename)->where(array('flowstat_stattime' => $stattime, 'store_id' => $store_id, 'flowstat_type' => 'sum'))->inc('flowstat_clicknum')->update();
  209. } else {
  210. $insert_arr[] = array('flowstat_stattime' => $stattime, 'flowstat_clicknum' => 1, 'store_id' => $store_id, 'flowstat_type' => 'sum', 'goods_id' => 0);
  211. }
  212. if (input('param.controller_param') == 'Goods' && input('param.action_param') == 'index') {//已经存在数据则更新
  213. if ($goods_exist) {
  214. Db::name($flow_tablename)->where(array('flowstat_stattime' => $stattime, 'goods_id' => $goods_id, 'flowstat_type' => 'goods'))->inc('flowstat_clicknum')->update();
  215. } else {
  216. $insert_arr[] = array('flowstat_stattime' => $stattime, 'flowstat_clicknum' => 1, 'store_id' => $store_id, 'flowstat_type' => 'goods', 'goods_id' => $goods_id);
  217. }
  218. }
  219. if ($insert_arr) {
  220. Db::name($flow_tablename)->insertAll($insert_arr);
  221. }
  222. echo json_encode(array('done' => true, 'msg' => 'done'));
  223. }
  224. }