Storesnshome.php 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396
  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 Storesnshome extends BaseStoreSns {
  17. public function initialize() {
  18. parent::initialize();
  19. Lang::load(base_path() . 'home/lang/' . config('lang.default_lang') . '/sellersns.lang.php');
  20. }
  21. /**
  22. * 查看店铺动态
  23. */
  24. public function index() {
  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. $stid = intval(input('param.id'));
  108. if ($stid > 0) {
  109. $storesnscomment_model = model('storesnscomment');
  110. //查询评论总数
  111. $where = array(
  112. 'stracelog_id' => $stid,
  113. 'storesnscomm_state' => 1
  114. );
  115. $countnum = $storesnscomment_model->getStoresnscommentCount($where);
  116. //动态列表
  117. $commentlist = $storesnscomment_model->getStoresnscommentList($where, '*', 'storesnscomm_id desc', 10);
  118. // 更新评论数量
  119. model('storesnstracelog')->editStoresnstracelog(array('stracelog_comment' => $countnum), array('stracelog_id' => $stid));
  120. }
  121. $showmore = '0'; //是否展示更多的连接
  122. if ($countnum > count($commentlist)) {
  123. $showmore = '1';
  124. }
  125. View::assign('countnum', $countnum);
  126. View::assign('showmore', $showmore);
  127. View::assign('showtype', 1); //页面展示类型 0表示分页 1表示显示前几条
  128. View::assign('stid', $stid);
  129. //允许插入新记录的最大条数
  130. View::assign('max_recordnum', self::MAX_RECORDNUM);
  131. View::assign('commentlist', $commentlist);
  132. echo View::fetch($this->template_dir . 'store_snscommentlist');
  133. exit;
  134. }
  135. /**
  136. * 评论列表
  137. */
  138. public function commentlist() {
  139. $stid = intval(input('param.id'));
  140. if ($stid > 0) {
  141. $storesnscomment_model = model('storesnscomment');
  142. //查询评论总数
  143. $where = array(
  144. 'stracelog_id' => $stid,
  145. 'storesnscomm_state' => 1
  146. );
  147. $countnum = $storesnscomment_model->getStoresnscommentCount($where);
  148. //评价列表
  149. $commentlist = $storesnscomment_model->getStoresnscommentList($where, '*', 'storesnscomm_id desc', 0, 10);
  150. // 更新评论数量
  151. model('storesnstracelog')->editStoresnstracelog(array('stracelog_comment' => $countnum), array('stracelog_id' => $stid));
  152. }
  153. View::assign('commentlist', $commentlist);
  154. View::assign('show_page', $storesnscomment_model->page_info->render());
  155. View::assign('countnum', $countnum);
  156. View::assign('stid', $stid);
  157. View::assign('showtype', '0'); //页面展示类型 0表示分页 1表示显示前几条
  158. //允许插入新记录的最大条数
  159. View::assign('max_recordnum', self::MAX_RECORDNUM);
  160. echo View::fetch($this->template_dir . 'store_snscommentlist');
  161. exit;
  162. }
  163. /**
  164. * 添加评论(访客登录后操作)
  165. */
  166. public function addcomment() {
  167. // 验证用户是否登录
  168. $this->checkLoginStatus();
  169. $stid = intval(input('post.stid'));
  170. if ($stid <= 0) {
  171. ds_json_encode(10001, lang('param_error'));
  172. }
  173. $validate_arr = array(
  174. 'commentcontent' => input('post.commentcontent'),
  175. );
  176. $storesnshome_validate = ds_validate('storesnshome');
  177. if (!$storesnshome_validate->scene('addcomment')->check($validate_arr)) {
  178. ds_json_encode(10001, $storesnshome_validate->getError());
  179. }
  180. //发帖数超过最大次数出现验证码
  181. if (intval(cookie('commentnum')) >= self::MAX_RECORDNUM) {
  182. if (!captcha_check(input('post.captcha'))) {
  183. ds_json_encode(10001, lang('wrong_checkcode'));
  184. }
  185. }
  186. //查询会员信息
  187. $member_info = Db::name('member')->where(array('member_state' => 1, 'member_id' => session('member_id')))->find();
  188. if (empty($member_info)) {
  189. ds_json_encode(10001, lang('sns_member_error'));
  190. }
  191. $insert_arr = array();
  192. $insert_arr['stracelog_id'] = $stid;
  193. $insert_arr['storesnscomm_content'] = input('post.commentcontent');
  194. $insert_arr['storesnscomm_memberid'] = $member_info['member_id'];
  195. $insert_arr['storesnscomm_membername'] = $member_info['member_name'];
  196. $insert_arr['storesnscomm_memberavatar'] = $member_info['member_avatar'];
  197. $insert_arr['storesnscomm_time'] = TIMESTAMP;
  198. $result = model('storesnscomment')->addStoresnscomment($insert_arr);
  199. if ($result) {
  200. // 原帖增加评论次数
  201. $where = array('stracelog_id' => $stid);
  202. $update = array('stracelog_comment' => Db::raw('stracelog_comment+1'));
  203. $rs = model('storesnstracelog')->editStoresnstracelog($update, $where);
  204. //建立cookie
  205. if (cookie('commentnum') != null && intval(cookie('commentnum')) > 0) {
  206. cookie('commentnum', intval(cookie('commentnum')) + 1, 2 * 3600); //保存2小时
  207. } else {
  208. cookie('commentnum', 1, 2 * 3600); //保存2小时
  209. }
  210. ds_json_encode(10000, lang('sns_comment_succ'), $stid);
  211. }
  212. }
  213. /**
  214. * 添加转发
  215. */
  216. public function addforward() {
  217. // 验证用户是否登录
  218. $this->checkLoginStatus();
  219. $stid = intval(input('param.stid'));
  220. if ($stid <= 0) {
  221. ds_json_encode(10001, lang('param_error'));
  222. }
  223. $validate_arr = array(
  224. 'forwardcontent' => input('post.forwardcontent'),
  225. );
  226. $storesnshome_validate = ds_validate('storesnshome');
  227. if (!$storesnshome_validate->scene('addforward')->check($validate_arr)) {
  228. ds_json_encode(10001, $storesnshome_validate->getError());
  229. }
  230. //发帖数超过最大次数出现验证码
  231. if (intval(cookie('forwardnum')) >= self::MAX_RECORDNUM) {
  232. if (!captcha_check(input('post.captcha'))) {
  233. ds_json_encode(10001, lang('wrong_checkcode'));
  234. }
  235. }
  236. //查询会员信息
  237. $member_info = Db::name('member')->where(array('member_state' => 1, 'member_id' => session('member_id')))->find();
  238. if (empty($member_info)) {
  239. ds_json_encode(10001, lang('sns_member_error'));
  240. }
  241. //查询原帖信息
  242. $storesnstracelog_model = model('storesnstracelog');
  243. $stracelog_info = $storesnstracelog_model->getStoresnstracelogInfo(array('stracelog_id' => $stid));
  244. if (empty($stracelog_info)) {
  245. ds_json_encode(10001, lang('sns_forward_fail'));
  246. }
  247. if ($stracelog_info['stracelog_content'] == '') {
  248. $data = json_decode($stracelog_info['stracelog_goodsdata'], true);
  249. $stracelog_info['stracelog_content'] = $storesnstracelog_model->spellingStyle($stracelog_info['stracelog_type'], $data);
  250. }
  251. $insert_arr = array();
  252. $insert_arr['tracelog_originalid'] = 0;
  253. $insert_arr['tracelog_originalmemberid'] = 0;
  254. $insert_arr['tracelog_originalstate'] = 0;
  255. $insert_arr['tracelog_memberid'] = $member_info['member_id'];
  256. $insert_arr['tracelog_membername'] = $member_info['member_name'];
  257. $insert_arr['tracelog_memberavatar'] = $member_info['member_avatar'];
  258. $insert_arr['tracelog_title'] = input('post.forwardcontent') ? input('post.forwardcontent') : lang('sns_forward');
  259. $insert_arr['tracelog_content'] = "<dl class=\"fd-wrap\">
  260. <dt>
  261. <h3><a href=\"" . HOME_SITE_URL . "/Storesnshome/index.html?sid=" . $stracelog_info['stracelog_storeid'] . "\" target=\"_blank\">" . $stracelog_info['stracelog_storename'] . "</a>" . lang('ds_colon') . "
  262. " . $stracelog_info['stracelog_title'] . "</h3>
  263. </dt>
  264. <dd>" . $stracelog_info['stracelog_content'] . "</dd>
  265. <dl>";
  266. $insert_arr['tracelog_addtime'] = TIMESTAMP;
  267. $insert_arr['tracelog_state'] = 0;
  268. $insert_arr['tracelog_privacy'] = 0;
  269. $insert_arr['tracelog_commentcount'] = 0;
  270. $insert_arr['tracelog_copycount'] = 0;
  271. $insert_arr['tracelog_orgcommentcount'] = 0;
  272. $insert_arr['tracelog_orgcopycount'] = 0;
  273. $insert_arr['tracelog_from'] = 2;
  274. $result = Db::name('snstracelog')->insert($insert_arr);
  275. if ($result) {
  276. //更新动态转发次数
  277. $where = array('stracelog_id' => $stid);
  278. $update = array('stracelog_spread' => Db::raw('stracelog_spread+1'));
  279. model('storesnstracelog')->editStoresnstracelog($update, $where);
  280. ds_json_encode(10000, lang('sns_forward_succ'));
  281. } else {
  282. ds_json_encode(10001, lang('sns_forward_fail'));
  283. }
  284. }
  285. /**
  286. * 删除动态
  287. */
  288. public function deltrace() {
  289. // 验证用户是否登录
  290. $this->checkLoginStatus();
  291. $stid = intval(input('id'));
  292. if ($stid <= 0) {
  293. $this->error(lang('param_error'));
  294. }
  295. //删除动态
  296. $result = model('storesnstracelog')->delStoresnstracelog(array('stracelog_id' => $stid, 'stracelog_storeid' => session('store_id')));
  297. if ($result) {
  298. //删除对应的评论
  299. model('storesnscomment')->delStoresnscomment(array('stracelog_id' => $stid));
  300. ds_json_encode(10000, lang('ds_common_del_succ'));
  301. } else {
  302. ds_json_encode(10001, lang('ds_common_del_fail'));
  303. }
  304. }
  305. /**
  306. * 删除评论(访客登录后操作)
  307. */
  308. public function delcomment() {
  309. // 验证用户是否登录
  310. $this->checkLoginStatus();
  311. $scid = intval(input('param.scid'));
  312. $stid = intval(input('param.stid'));
  313. if ($scid <= 0 || $stid <= 0) {
  314. ds_json_encode(10001, lang('param_error'));
  315. }
  316. // 查询评论相关信息
  317. $storesnscomment_model = model('storesnscomment');
  318. $where = array('stracelog_id' => $stid, 'storesnscomm_id' => $scid, 'storesnscomm_memberid' => session('member_id')); // where条件
  319. $scomment_info = $storesnscomment_model->getStoresnscommentInfo($where);
  320. if (empty($scomment_info)) {
  321. ds_json_encode(10001, lang('param_error'));
  322. }
  323. // 删除评论
  324. $result = $storesnscomment_model->delStoresnscomment($where);
  325. if ($result) {
  326. // 更新动态统计信息
  327. $where = array('stracelog_id' => $scomment_info['stracelog_id']);
  328. $update = array('stracelog_comment' => Db::raw('stracelog_comment-1'));
  329. model('storesnstracelog')->editStoresnstracelog($update, $where);
  330. // $js ="$('.comment-list [ds_type=\"commentrow_" . $scid . "\"]').remove();";
  331. ds_json_encode(10000, lang('ds_common_del_succ'));
  332. } else {
  333. ds_json_encode(10001, lang('ds_common_del_fail'));
  334. }
  335. }
  336. /**
  337. * 一条SNS动态及其评论
  338. */
  339. public function straceinfo() {
  340. $stid = intval(input('get.st_id'));
  341. if ($stid <= 0) {
  342. $this->error(lang('param_error'));
  343. }
  344. $storesnstracelog_model = model('storesnstracelog');
  345. $strace_info = $storesnstracelog_model->getStoresnstracelogInfo(array('stracelog_id' => $stid));
  346. if (!empty($strace_info)) {
  347. if ($strace_info['stracelog_content'] == '') {
  348. $content = $storesnstracelog_model->spellingStyle($strace_info['stracelog_type'], json_decode(stripslashes($strace_info['stracelog_goodsdata']), true));
  349. $strace_info['stracelog_content'] = str_replace("%siteurl%", HOME_SITE_URL . DIRECTORY_SEPARATOR, $content);
  350. }
  351. }
  352. View::assign('strace_info', $strace_info);
  353. return View::fetch($this->template_dir . 'store_snstraceinfo');
  354. }
  355. /**
  356. * 验证用户是否登录
  357. */
  358. private function checkLoginStatus() {
  359. if (session('is_login') != 1) {
  360. @header("location: " . HOME_SITE_URL . "/Login/logon.html");
  361. }
  362. }
  363. }