CoreAttach.php 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. <?php
  2. /**
  3. * Created by PhpStorm.
  4. * User: Administrator
  5. * Date: 2019/3/17/017
  6. * Time: 15:05
  7. */
  8. namespace app\platform\modules\application\models;
  9. use app\common\models\BaseModel;
  10. use Illuminate\Database\Eloquent\SoftDeletes;
  11. use Illuminate\Support\Carbon;
  12. class CoreAttach extends BaseModel
  13. {
  14. use SoftDeletes;
  15. protected $table = 'yz_core_attachment';
  16. protected $guarded = [''];
  17. protected $hidden = ['deleted_at', 'updated_at'];
  18. public $timestamps = true;
  19. protected $datas = ['deleted_at'];
  20. protected $appends = ['tag_name'];
  21. // 存储在表中type字段的对应的类型
  22. const IMAGE_TYPE = 1;// 图片 1
  23. const VOICE_TYPE = 2;// 音频 2
  24. const VIDEO_TYPE = 3;// 视频 3
  25. // 存储在表中upload_type字段的对应的类型
  26. const UPLOAD_LOCAL = 0; // 本地
  27. const UPLOAD_OSS = 2; // 阿里云
  28. const UPLOAD_COS = 4; // 腾讯云
  29. public function scopeSearch($query, $keyword = null)
  30. {
  31. if ($keyword['month'] && $keyword['year']) {
  32. return $query->whereBetween('created_at', [
  33. mktime(0,0,0, $keyword['month'], 1, $keyword['year']),
  34. mktime(23,59,59, $keyword['month']+1, 0, $keyword['year'])
  35. ]);
  36. }
  37. if ($keyword['year']) {
  38. return $query->whereBetween(
  39. 'created_at',
  40. [
  41. mktime(0,0,0, 1, 1, $keyword['year']),
  42. mktime(23,59,59,12, 31, $keyword['year'])
  43. ]
  44. );
  45. }
  46. if ($keyword['month']) {
  47. return $query->whereBetween(
  48. 'created_at',
  49. [
  50. mktime(0,0,0, $keyword['month'], 1, date('Y')),
  51. mktime(23,59,59, $keyword['month']+1, 0, date('Y'))
  52. ]
  53. );
  54. }
  55. }
  56. public static function search($search)
  57. {
  58. $model = self::uniacid();
  59. if ($search['year'] || $search['month']) {
  60. $start_time = Carbon::createFromDate($search['year'], $search['month'])->startOfMonth()->timestamp;
  61. $end_time = Carbon::createFromDate($search['year'], $search['month'])->endOfMonth()->timestamp;
  62. $model->whereBetween('created_at', [$start_time, $end_time]);
  63. }
  64. if ($search['tag_id'] === '') {
  65. $model->where('uid', \YunShop::app()->uid);
  66. }
  67. if ($search['tag_id'] === 0) {
  68. $model->where('tag_id', 0);
  69. }
  70. return $model;
  71. }
  72. public function atributeNames()
  73. {
  74. return [
  75. 'uniacid' => '公众号id',
  76. 'uid' => '用户id',
  77. 'filename' => '原文件名',
  78. 'attachment' => '新文件名',
  79. ];
  80. }
  81. public function rules()
  82. {
  83. return [
  84. 'uniacid' => 'integer',
  85. 'uid' => 'integer',
  86. 'filename' => 'string|max:50',
  87. 'attachment' => '',
  88. ];
  89. }
  90. public function getTagNameAttribute(){
  91. return $this->tag_id?CoreAttachTags::where('id', $this->tag_id)->value('title'):'未分组';
  92. }
  93. }