InstitutionModel.php 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | LARAVEL8.0 框架 [ LARAVEL ][ RXThinkCMF ]
  4. // +----------------------------------------------------------------------
  5. // | 版权所有 2017~2021 LARAVEL研发中心
  6. // +----------------------------------------------------------------------
  7. // | 官方网站: http://www.laravel.cn
  8. // +----------------------------------------------------------------------
  9. // | Author: laravel开发员 <laravel.qq.com>
  10. // +----------------------------------------------------------------------
  11. namespace App\Models;
  12. /**
  13. * 院校-模型
  14. * @author laravel开发员
  15. * @since 2024/01/08
  16. * @package App\Models
  17. */
  18. class InstitutionModel extends BaseModel
  19. {
  20. // 设置数据表
  21. protected $table = 'institutions';
  22. /**
  23. * 格式化信息
  24. * @param array $info 实体数据对象
  25. * @return array 返回实体对象
  26. * @author laravel开发员
  27. * @date 2024/01/08
  28. */
  29. public function formatInfo($info)
  30. {
  31. // 格式化链接类型
  32. if (isset($info['link_type'])) {
  33. $linkTypeMap = [
  34. 1 => 'Web链接',
  35. 2 => '小程序链接'
  36. ];
  37. $info['link_type_text'] = isset($linkTypeMap[$info['link_type']]) ? $linkTypeMap[$info['link_type']] : '未知类型';
  38. }
  39. // 格式化状态
  40. if (isset($info['status'])) {
  41. $info['status_text'] = $info['status'] == 1 ? '正常' : '不显示';
  42. }
  43. return $info;
  44. }
  45. public function getThumbAttribute($value)
  46. {
  47. return $value ? get_image_url($value) : '';
  48. }
  49. public function setThumbAttribute($value)
  50. {
  51. $this->attributes['thumb'] = $value ? get_image_path($value) : '';
  52. }
  53. }