Storesnshome.php 17 KB

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