Storesnshome.php 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406
  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 Storesnshome extends BaseStoreSns
  14. {
  15. public function initialize()
  16. {
  17. parent::initialize();
  18. Lang::load(base_path() . 'home/lang/' . config('lang.default_lang') . '/sellersns.lang.php');
  19. }
  20. /**
  21. * 查看店铺动态
  22. */
  23. public function index()
  24. {
  25. //获得店铺ID
  26. $sid = intval(input('param.sid'));
  27. $this->getStoreInfo($sid);
  28. // where 条件
  29. $where = array();
  30. $where[] = array('stracelog_state', '=', 1);
  31. $where[] = array('stracelog_storeid', '=', $sid);
  32. $type = input('type');
  33. if ($type != '') {
  34. switch (trim($type)) {
  35. case 'promotion':
  36. $where[] = array('stracelog_type', 'in', array(4, 5, 6, 7, 8));
  37. break;
  38. case 'new':
  39. $where[] = array('stracelog_type', '=', 3);
  40. break;
  41. case 'hotsell':
  42. $where[] = array('stracelog_type', '=', 10);
  43. break;
  44. case 'recommend':
  45. $where[] = array('stracelog_type', '=', 9);
  46. break;
  47. }
  48. }
  49. $storesnstracelog_model = model('storesnstracelog');
  50. $strace_array = $storesnstracelog_model->getStoresnstracelogList($where, '*', 'stracelog_id desc', 0, 40);
  51. // 整理
  52. if (!empty($strace_array) && is_array($strace_array)) {
  53. foreach ($strace_array as $key => $val) {
  54. switch ($val['stracelog_type']) {
  55. case 4:
  56. case 5:
  57. case 6:
  58. case 7:
  59. case 8:
  60. $strace_array[$key]['stracelog_style'] = 'promotion';
  61. $strace_array[$key]['stracelog_lang'] = lang('store_sns_sales_promotion');
  62. break;
  63. case 3:
  64. $strace_array[$key]['stracelog_style'] = 'new';
  65. $strace_array[$key]['stracelog_lang'] = lang('store_sns_new_goods');
  66. break;
  67. case 10:
  68. $strace_array[$key]['stracelog_style'] = 'hotsell';
  69. $strace_array[$key]['stracelog_lang'] = lang('store_sns_hot_sale');
  70. break;
  71. case 9:
  72. $strace_array[$key]['stracelog_style'] = 'recommend';
  73. $strace_array[$key]['stracelog_lang'] = lang('store_sns_recommended');
  74. break;
  75. case 2:
  76. $strace_array[$key]['stracelog_style'] = 'normal';
  77. $strace_array[$key]['stracelog_lang'] = lang('store_sns_normal');
  78. break;
  79. }
  80. if ($val['stracelog_content'] == '') {
  81. $val['stracelog_goodsdata'] = json_decode(stripslashes($val['stracelog_goodsdata']), true);
  82. $content = $storesnstracelog_model->spellingStyle($val['stracelog_type'], $val['stracelog_goodsdata']);
  83. $strace_array[$key]['stracelog_content'] = str_replace("%siteurl%", HOME_SITE_URL . DIRECTORY_SEPARATOR, $content);
  84. }
  85. }
  86. }
  87. View::assign('strace_array', $strace_array);
  88. //允许插入新记录的最大条数
  89. View::assign('max_recordnum', self::MAX_RECORDNUM);
  90. View::assign('show_page', $storesnstracelog_model->page_info->render());
  91. // 最多收藏的会员
  92. $favorites = model('favorites')->getStoreFavoritesList(array(array('fav_id', '=', $sid)), '*', 0, 'fav_time desc', 8);
  93. if (!empty($favorites)) {
  94. $memberid_array = array();
  95. foreach ($favorites as $val) {
  96. $memberid_array[] = $val['member_id'];
  97. }
  98. $favorites_list = model('member')->getMemberList(array(array('member_id', 'in', $memberid_array)), 'member_id,member_name,member_avatar');
  99. View::assign('favorites_list', $favorites_list);
  100. }
  101. return View::fetch($this->template_dir . 'store_snshome');
  102. }
  103. /**
  104. * 评论前10条记录
  105. */
  106. public function commenttop()
  107. {
  108. $stid = intval(input('param.id'));
  109. if ($stid > 0) {
  110. $storesnscomment_model = model('storesnscomment');
  111. //查询评论总数
  112. $where = array(
  113. 'stracelog_id' => $stid,
  114. 'storesnscomm_state' => 1
  115. );
  116. $countnum = $storesnscomment_model->getStoresnscommentCount($where);
  117. //动态列表
  118. $commentlist = $storesnscomment_model->getStoresnscommentList($where, '*', 'storesnscomm_id desc', 10);
  119. // 更新评论数量
  120. model('storesnstracelog')->editStoresnstracelog(array('stracelog_comment' => $countnum), array('stracelog_id' => $stid));
  121. }
  122. $showmore = '0'; //是否展示更多的连接
  123. if ($countnum > count($commentlist)) {
  124. $showmore = '1';
  125. }
  126. View::assign('countnum', $countnum);
  127. View::assign('showmore', $showmore);
  128. View::assign('showtype', 1); //页面展示类型 0表示分页 1表示显示前几条
  129. View::assign('stid', $stid);
  130. //允许插入新记录的最大条数
  131. View::assign('max_recordnum', self::MAX_RECORDNUM);
  132. View::assign('commentlist', $commentlist);
  133. echo View::fetch($this->template_dir . 'store_snscommentlist');
  134. exit;
  135. }
  136. /**
  137. * 评论列表
  138. */
  139. public function commentlist()
  140. {
  141. $stid = intval(input('param.id'));
  142. if ($stid > 0) {
  143. $storesnscomment_model = model('storesnscomment');
  144. //查询评论总数
  145. $where = array(
  146. 'stracelog_id' => $stid,
  147. 'storesnscomm_state' => 1
  148. );
  149. $countnum = $storesnscomment_model->getStoresnscommentCount($where);
  150. //评价列表
  151. $commentlist = $storesnscomment_model->getStoresnscommentList($where, '*', 'storesnscomm_id desc', 0, 10);
  152. // 更新评论数量
  153. model('storesnstracelog')->editStoresnstracelog(array('stracelog_comment' => $countnum), array('stracelog_id' => $stid));
  154. }
  155. View::assign('commentlist', $commentlist);
  156. View::assign('show_page', $storesnscomment_model->page_info->render());
  157. View::assign('countnum', $countnum);
  158. View::assign('stid', $stid);
  159. View::assign('showtype', '0'); //页面展示类型 0表示分页 1表示显示前几条
  160. //允许插入新记录的最大条数
  161. View::assign('max_recordnum', self::MAX_RECORDNUM);
  162. echo View::fetch($this->template_dir . 'store_snscommentlist');
  163. exit;
  164. }
  165. /**
  166. * 添加评论(访客登录后操作)
  167. */
  168. public function addcomment()
  169. {
  170. // 验证用户是否登录
  171. $this->checkLoginStatus();
  172. $stid = intval(input('post.stid'));
  173. if ($stid <= 0) {
  174. ds_json_encode(10001, lang('param_error'));
  175. }
  176. $validate_arr = array(
  177. 'commentcontent' => input('post.commentcontent'),
  178. );
  179. $storesnshome_validate = ds_validate('storesnshome');
  180. if (!$storesnshome_validate->scene('addcomment')->check($validate_arr)) {
  181. ds_json_encode(10001, $storesnshome_validate->getError());
  182. }
  183. //发帖数超过最大次数出现验证码
  184. if (intval(cookie('commentnum')) >= self::MAX_RECORDNUM) {
  185. if (!captcha_check(input('post.captcha'))) {
  186. ds_json_encode(10001, lang('wrong_checkcode'));
  187. }
  188. }
  189. //查询会员信息
  190. $member_info = Db::name('member')->where(array('member_state' => 1, 'member_id' => session('member_id')))->find();
  191. if (empty($member_info)) {
  192. ds_json_encode(10001, lang('sns_member_error'));
  193. }
  194. $insert_arr = array();
  195. $insert_arr['stracelog_id'] = $stid;
  196. $insert_arr['storesnscomm_content'] = input('post.commentcontent');
  197. $insert_arr['storesnscomm_memberid'] = $member_info['member_id'];
  198. $insert_arr['storesnscomm_membername'] = $member_info['member_name'];
  199. $insert_arr['storesnscomm_memberavatar'] = $member_info['member_avatar'];
  200. $insert_arr['storesnscomm_time'] = TIMESTAMP;
  201. $result = model('storesnscomment')->addStoresnscomment($insert_arr);
  202. if ($result) {
  203. // 原帖增加评论次数
  204. $where = array('stracelog_id' => $stid);
  205. $update = array('stracelog_comment' => Db::raw('stracelog_comment+1'));
  206. $rs = model('storesnstracelog')->editStoresnstracelog($update, $where);
  207. //建立cookie
  208. if (cookie('commentnum') != null && intval(cookie('commentnum')) > 0) {
  209. cookie('commentnum', intval(cookie('commentnum')) + 1, 2 * 3600); //保存2小时
  210. } else {
  211. cookie('commentnum', 1, 2 * 3600); //保存2小时
  212. }
  213. ds_json_encode(10000, lang('sns_comment_succ'), $stid);
  214. }
  215. }
  216. /**
  217. * 添加转发
  218. */
  219. public function addforward()
  220. {
  221. // 验证用户是否登录
  222. $this->checkLoginStatus();
  223. $stid = intval(input('param.stid'));
  224. if ($stid <= 0) {
  225. ds_json_encode(10001, lang('param_error'));
  226. }
  227. $validate_arr = array(
  228. 'forwardcontent' => input('post.forwardcontent'),
  229. );
  230. $storesnshome_validate = ds_validate('storesnshome');
  231. if (!$storesnshome_validate->scene('addforward')->check($validate_arr)) {
  232. ds_json_encode(10001, $storesnshome_validate->getError());
  233. }
  234. //发帖数超过最大次数出现验证码
  235. if (intval(cookie('forwardnum')) >= self::MAX_RECORDNUM) {
  236. if (!captcha_check(input('post.captcha'))) {
  237. ds_json_encode(10001, lang('wrong_checkcode'));
  238. }
  239. }
  240. //查询会员信息
  241. $member_info = Db::name('member')->where(array('member_state' => 1, 'member_id' => session('member_id')))->find();
  242. if (empty($member_info)) {
  243. ds_json_encode(10001, lang('sns_member_error'));
  244. }
  245. //查询原帖信息
  246. $storesnstracelog_model = model('storesnstracelog');
  247. $stracelog_info = $storesnstracelog_model->getStoresnstracelogInfo(array('stracelog_id' => $stid));
  248. if (empty($stracelog_info)) {
  249. ds_json_encode(10001, lang('sns_forward_fail'));
  250. }
  251. if ($stracelog_info['stracelog_content'] == '') {
  252. $data = json_decode($stracelog_info['stracelog_goodsdata'], true);
  253. $stracelog_info['stracelog_content'] = $storesnstracelog_model->spellingStyle($stracelog_info['stracelog_type'], $data);
  254. }
  255. $insert_arr = array();
  256. $insert_arr['tracelog_originalid'] = 0;
  257. $insert_arr['tracelog_originalmemberid'] = 0;
  258. $insert_arr['tracelog_originalstate'] = 0;
  259. $insert_arr['tracelog_memberid'] = $member_info['member_id'];
  260. $insert_arr['tracelog_membername'] = $member_info['member_name'];
  261. $insert_arr['tracelog_memberavatar'] = $member_info['member_avatar'];
  262. $insert_arr['tracelog_title'] = input('post.forwardcontent') ? input('post.forwardcontent') : lang('sns_forward');
  263. $insert_arr['tracelog_content'] = "<dl class=\"fd-wrap\">
  264. <dt>
  265. <h3><a href=\"" . HOME_SITE_URL . "/Storesnshome/index.html?sid=" . $stracelog_info['stracelog_storeid'] . "\" target=\"_blank\">" . $stracelog_info['stracelog_storename'] . "</a>" . lang('ds_colon') . "
  266. " . $stracelog_info['stracelog_title'] . "</h3>
  267. </dt>
  268. <dd>" . $stracelog_info['stracelog_content'] . "</dd>
  269. <dl>";
  270. $insert_arr['tracelog_addtime'] = TIMESTAMP;
  271. $insert_arr['tracelog_state'] = 0;
  272. $insert_arr['tracelog_privacy'] = 0;
  273. $insert_arr['tracelog_commentcount'] = 0;
  274. $insert_arr['tracelog_copycount'] = 0;
  275. $insert_arr['tracelog_orgcommentcount'] = 0;
  276. $insert_arr['tracelog_orgcopycount'] = 0;
  277. $insert_arr['tracelog_from'] = 2;
  278. $result = Db::name('snstracelog')->insert($insert_arr);
  279. if ($result) {
  280. //更新动态转发次数
  281. $where = array('stracelog_id' => $stid);
  282. $update = array('stracelog_spread' => Db::raw('stracelog_spread+1'));
  283. model('storesnstracelog')->editStoresnstracelog($update, $where);
  284. ds_json_encode(10000, lang('sns_forward_succ'));
  285. } else {
  286. ds_json_encode(10001, lang('sns_forward_fail'));
  287. }
  288. }
  289. /**
  290. * 删除动态
  291. */
  292. public function deltrace()
  293. {
  294. // 验证用户是否登录
  295. $this->checkLoginStatus();
  296. $stid = intval(input('id'));
  297. if ($stid <= 0) {
  298. $this->error(lang('param_error'));
  299. }
  300. //删除动态
  301. $result = model('storesnstracelog')->delStoresnstracelog(array('stracelog_id' => $stid, 'stracelog_storeid' => session('store_id')));
  302. if ($result) {
  303. //删除对应的评论
  304. model('storesnscomment')->delStoresnscomment(array('stracelog_id' => $stid));
  305. ds_json_encode(10000, lang('ds_common_del_succ'));
  306. } else {
  307. ds_json_encode(10001, lang('ds_common_del_fail'));
  308. }
  309. }
  310. /**
  311. * 删除评论(访客登录后操作)
  312. */
  313. public function delcomment()
  314. {
  315. // 验证用户是否登录
  316. $this->checkLoginStatus();
  317. $scid = intval(input('param.scid'));
  318. $stid = intval(input('param.stid'));
  319. if ($scid <= 0 || $stid <= 0) {
  320. ds_json_encode(10001, lang('param_error'));
  321. }
  322. // 查询评论相关信息
  323. $storesnscomment_model = model('storesnscomment');
  324. $where = array('stracelog_id' => $stid, 'storesnscomm_id' => $scid, 'storesnscomm_memberid' => session('member_id')); // where条件
  325. $scomment_info = $storesnscomment_model->getStoresnscommentInfo($where);
  326. if (empty($scomment_info)) {
  327. ds_json_encode(10001, lang('param_error'));
  328. }
  329. // 删除评论
  330. $result = $storesnscomment_model->delStoresnscomment($where);
  331. if ($result) {
  332. // 更新动态统计信息
  333. $where = array('stracelog_id' => $scomment_info['stracelog_id']);
  334. $update = array('stracelog_comment' => Db::raw('stracelog_comment-1'));
  335. model('storesnstracelog')->editStoresnstracelog($update, $where);
  336. // $js ="$('.comment-list [ds_type=\"commentrow_" . $scid . "\"]').remove();";
  337. ds_json_encode(10000, lang('ds_common_del_succ'));
  338. } else {
  339. ds_json_encode(10001, lang('ds_common_del_fail'));
  340. }
  341. }
  342. /**
  343. * 一条SNS动态及其评论
  344. */
  345. public function straceinfo()
  346. {
  347. $stid = intval(input('get.st_id'));
  348. if ($stid <= 0) {
  349. $this->error(lang('param_error'));
  350. }
  351. $storesnstracelog_model = model('storesnstracelog');
  352. $strace_info = $storesnstracelog_model->getStoresnstracelogInfo(array('stracelog_id' => $stid));
  353. if (!empty($strace_info)) {
  354. if ($strace_info['stracelog_content'] == '') {
  355. $content = $storesnstracelog_model->spellingStyle($strace_info['stracelog_type'], json_decode(stripslashes($strace_info['stracelog_goodsdata']), true));
  356. $strace_info['stracelog_content'] = str_replace("%siteurl%", HOME_SITE_URL . DIRECTORY_SEPARATOR, $content);
  357. }
  358. }
  359. View::assign('strace_info', $strace_info);
  360. return View::fetch($this->template_dir . 'store_snstraceinfo');
  361. }
  362. /**
  363. * 验证用户是否登录
  364. */
  365. private function checkLoginStatus()
  366. {
  367. if (session('is_login') != 1) {
  368. @header("location: " . HOME_SITE_URL . "/Login/logon.html");
  369. }
  370. }
  371. }