SiyuanService.php 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | Laravel框架 [ Laravel ]
  4. // +----------------------------------------------------------------------
  5. // | 版权所有 2017~2021 Laravel研发中心
  6. // +----------------------------------------------------------------------
  7. // | 官方网站: http://www.laravel.cn
  8. // +----------------------------------------------------------------------
  9. // | Author: wesmiler <12345678@qq.com>
  10. // +----------------------------------------------------------------------
  11. namespace App\Services;
  12. use App\Models\SiyuanModel;
  13. /**
  14. * 寺院管理-服务类
  15. * @author wesmiler
  16. * @since 2020/11/11
  17. * Class SiyuanService
  18. * @package App\Services
  19. */
  20. class SiyuanService extends BaseService
  21. {
  22. /**
  23. * 构造函数
  24. * @author wesmiler
  25. * @since 2020/11/11
  26. * SiyuanService constructor.
  27. */
  28. public function __construct()
  29. {
  30. $this->model = new SiyuanModel();
  31. }
  32. /**
  33. * 访问量
  34. * @return mixed
  35. */
  36. public function updateVisit($userId=0){
  37. $id = request()->get('id');
  38. $cacheKey = "caches:siyuan:visit:{$userId}_{$id}";
  39. $check = RedisService::get($cacheKey);
  40. if($id && !$check){
  41. RedisService::set($cacheKey, $id, 3600);
  42. return $this->model::where(['id'=> $id])->increment('count', 1);
  43. }
  44. }
  45. /**
  46. * 获取列表
  47. * @return array
  48. * @since 2020/11/11
  49. * @author wesmiler
  50. */
  51. public function getList()
  52. {
  53. $params = request()->all();
  54. return parent::getList();
  55. }
  56. /**
  57. * 添加或编辑
  58. * @return array
  59. * @since 2020/11/11
  60. * @author wesmiler
  61. */
  62. public function edit()
  63. {
  64. $data = request()->all();
  65. // 图片处理
  66. $image = trim($data['thumb']);
  67. $id = isset($data['id']) ? $data['id'] : 0;
  68. if (!$id && !$image) {
  69. return message('请上传寺院图片', false);
  70. }
  71. if (strpos($image, "temp")) {
  72. $data['thumb'] = save_image($image, 'item');
  73. } else {
  74. $data['thumb'] = str_replace(IMG_URL, "", $data['thumb']);
  75. }
  76. $data['update_time'] = time();
  77. return parent::edit($data); // TODO: Change the autogenerated stub
  78. }
  79. }