心理咨询网
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

DoController.php 1.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. <?php
  2. /**
  3. * @copyright (C)2016-2099 Hnaoyun Inc.
  4. * @author XingMeng
  5. * @email hnxsh@foxmail.com
  6. * @date 2018年3月8日
  7. *
  8. */
  9. namespace app\home\controller;
  10. use core\basic\Controller;
  11. use app\home\model\DoModel;
  12. class DoController extends Controller
  13. {
  14. private $model;
  15. public function __construct()
  16. {
  17. $this->model = new DoModel();
  18. }
  19. // 多语言切换
  20. public function area()
  21. {
  22. $lg = request('lg', 'var');
  23. if ($lg) {
  24. $lgs = $this->config('lgs');
  25. if (isset($lgs[$lg])) {
  26. cookie('lg', $lg);
  27. }
  28. location(SITE_INDEX_DIR . '/');
  29. }
  30. }
  31. // 文章访问量累计
  32. public function visits()
  33. {
  34. if (! ! $id = get('id', 'int')) {
  35. $this->model->addVisits($id);
  36. echo 'var ok;'; // 避免前端浏览器报js错
  37. } else {
  38. echo 'var error;'; // 避免前端浏览器报js错
  39. }
  40. }
  41. // 点赞
  42. public function likes()
  43. {
  44. if (($id = get('id', 'int')) && ! cookie('likes_' . $id)) {
  45. $this->model->addLikes($id);
  46. cookie('likes_' . $id, true, 31536000, null, null, null, null);
  47. }
  48. location('-1');
  49. }
  50. // 获取是否点赞
  51. public function isLikes()
  52. {
  53. if (($id = get('id', 'int')) && cookie('likes_' . $id)) {
  54. return json(1, 'yes');
  55. } else {
  56. return json(0, 'no');
  57. }
  58. }
  59. // 反对
  60. public function oppose()
  61. {
  62. if (($id = get('id', 'int')) && ! cookie('oppose_' . $id)) {
  63. $this->model->addOppose($id);
  64. cookie('oppose_' . $id, true, 31536000, null, null, null, null);
  65. }
  66. location('-1');
  67. }
  68. // 获取是否反对
  69. public function isOppose()
  70. {
  71. if (($id = get('id', 'int')) && cookie('oppose_' . $id)) {
  72. return json(1, 'yes');
  73. } else {
  74. return json(0, 'no');
  75. }
  76. }
  77. }