View.php 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | ThinkAdmin
  4. // +----------------------------------------------------------------------
  5. // | 版权所有 2014~2022 广州楚才信息科技有限公司 [ http://www.cuci.cc ]
  6. // +----------------------------------------------------------------------
  7. // | 官方网站: https://thinkadmin.top
  8. // +----------------------------------------------------------------------
  9. // | 开源协议 ( https://mit-license.org )
  10. // | 免费声明 ( https://thinkadmin.top/disclaimer )
  11. // +----------------------------------------------------------------------
  12. // | gitee 代码仓库:https://gitee.com/zoujingli/ThinkAdmin
  13. // | github 代码仓库:https://github.com/zoujingli/ThinkAdmin
  14. // +----------------------------------------------------------------------
  15. namespace app\wechat\controller\api;
  16. use app\wechat\model\WechatNewsArticle;
  17. use app\wechat\service\MediaService;
  18. use think\admin\Controller;
  19. /**
  20. * 微信图文显示
  21. * Class View
  22. * @package app\wechat\controller\api
  23. */
  24. class View extends Controller
  25. {
  26. /**
  27. * 图文列表展示
  28. * @param string|integer $id 图文ID编号
  29. * @throws \think\db\exception\DataNotFoundException
  30. * @throws \think\db\exception\DbException
  31. * @throws \think\db\exception\ModelNotFoundException
  32. */
  33. public function news($id = 0)
  34. {
  35. $this->id = $id ?: input('id', 0);
  36. $this->news = MediaService::instance()->news($this->id);
  37. $this->fetch();
  38. }
  39. /**
  40. * 文章内容展示
  41. * @param string|integer $id 文章ID编号
  42. * @throws \think\db\exception\DataNotFoundException
  43. * @throws \think\db\exception\DbException
  44. * @throws \think\db\exception\ModelNotFoundException
  45. */
  46. public function item($id = 0)
  47. {
  48. $map = ['id' => $id ?: input('id', 0)];
  49. WechatNewsArticle::mk()->where($map)->update([
  50. 'read_num' => $this->app->db->raw('read_num+1'),
  51. ]);
  52. $this->info = WechatNewsArticle::mk()->where($map)->find();
  53. $this->fetch();
  54. }
  55. /**
  56. * 文本展示
  57. */
  58. public function text()
  59. {
  60. $this->content = strip_tags(input('content', ''), '<a><img>');
  61. $this->fetch();
  62. }
  63. /**
  64. * 图片展示
  65. */
  66. public function image()
  67. {
  68. $this->content = strip_tags(input('content', ''), '<a><img>');
  69. $this->fetch();
  70. }
  71. /**
  72. * 视频展示
  73. */
  74. public function video()
  75. {
  76. $this->url = strip_tags(input('url', ''), '<a><img>');
  77. $this->title = strip_tags(input('title', ''), '<a><img>');
  78. $this->fetch();
  79. }
  80. /**
  81. * 语音展示
  82. */
  83. public function voice()
  84. {
  85. $this->url = strip_tags(input('url', ''), '<a><img>');
  86. $this->fetch();
  87. }
  88. /**
  89. * 音乐展示
  90. */
  91. public function music()
  92. {
  93. $this->url = strip_tags(input('url', ''), '<a><img>');
  94. $this->desc = strip_tags(input('desc', ''), '<a><img>');
  95. $this->title = strip_tags(input('title', ''), '<a><img>');
  96. $this->fetch();
  97. }
  98. }