SystemAttachment.php 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
  4. // +----------------------------------------------------------------------
  5. // | Copyright (c) 2016~2020 https://www.crmeb.com All rights reserved.
  6. // +----------------------------------------------------------------------
  7. // | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
  8. // +----------------------------------------------------------------------
  9. // | Author: CRMEB Team <admin@crmeb.com>
  10. // +----------------------------------------------------------------------
  11. namespace app\model\system\attachment;
  12. use crmeb\basic\BaseModel;
  13. use crmeb\traits\ModelTrait;
  14. use think\Model;
  15. /**
  16. * 附件管理模型
  17. * Class SystemAttachment
  18. * @package app\model\system\attachment
  19. */
  20. class SystemAttachment extends BaseModel
  21. {
  22. use ModelTrait;
  23. /**
  24. * 数据表主键
  25. * @var string
  26. */
  27. protected $pk = 'att_id';
  28. /**
  29. * 模型名称
  30. * @var string
  31. */
  32. protected $name = 'system_attachment';
  33. /**
  34. * 图片类型搜索器
  35. * @param Model $query
  36. * @param $value
  37. */
  38. public function searchModuleTypeAttr($query, $value)
  39. {
  40. $query->where('module_type', $value ?: 1);
  41. }
  42. /**
  43. * pid搜索器
  44. * @param Model $query
  45. * @param $value
  46. */
  47. public function searchPidAttr($query, $value)
  48. {
  49. if ($value) $query->where('pid', $value);
  50. }
  51. /**
  52. * name模糊搜索
  53. * @param Model $query
  54. * @param $value
  55. */
  56. public function searchLikeNameAttr($query, $value)
  57. {
  58. if ($value) $query->where('name','LIKE' ,"$value%");
  59. }
  60. /**
  61. * type搜索器
  62. * @param Model $query
  63. * @param $value
  64. */
  65. public function searchTypeAttr($query, $value)
  66. {
  67. if (is_array($value)) {
  68. if ($value) $query->whereIn('type', $value);
  69. } else {
  70. if ($value !== '') $query->where('type', $value);
  71. }
  72. }
  73. /**
  74. * 关联门店ID、供应商ID搜索器
  75. * @param Model $query
  76. * @param $value
  77. */
  78. public function searchRelationIdAttr($query, $value)
  79. {
  80. if (is_array($value)) {
  81. if ($value) $query->whereIn('relation_id', $value);
  82. } else {
  83. if ($value !== '') $query->where('relation_id', $value);
  84. }
  85. }
  86. /**
  87. * FileType搜索器
  88. * @param Model $query
  89. * @param $value
  90. */
  91. public function searchFileTypeAttr($query, $value)
  92. {
  93. if (is_array($value)) {
  94. if ($value) $query->whereIn('file_type', $value);
  95. } else {
  96. if ($value !== '') $query->where('file_type', $value);
  97. }
  98. }
  99. /**
  100. * store_id搜索器
  101. * @param Model $query
  102. * @param $value
  103. */
  104. public function searchStoreIdAttr($query, $value)
  105. {
  106. if ($value !== '') $query->where('relation_id', $value)->where('type', 1);
  107. }
  108. }