Storesnshome.php 17 KB

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