CoreAttach.php 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. <?php
  2. /**
  3. * Author: 芸众商城 www.yunzshop.com
  4. * Date: 2017/6/6
  5. * Time: 下午9:09
  6. */
  7. namespace app\backend\modules\upload\models;
  8. use app\common\models\BaseModel;
  9. use app\platform\modules\application\models\CoreAttachTags;
  10. use Illuminate\Support\Carbon;
  11. class CoreAttach extends BaseModel
  12. {
  13. protected $table = 'core_attachment';
  14. protected $guarded = [''];
  15. protected $hidden = [];
  16. protected $appends = ['created_at','tag_name'];
  17. public $timestamps = false;
  18. const PAGE_SIZE = 33;
  19. // 存储在表中type字段的对应的类型
  20. const IMAGE_TYPE = 1;// 图片 1
  21. const VOICE_TYPE = 2;// 音频 2
  22. const VIDEO_TYPE = 3;// 视频 3
  23. public function scopeSearch($query, $keyword)
  24. {
  25. if ($keyword['month'] && $keyword['year']) {
  26. return $query->whereBetween('createtime', [
  27. mktime(0,0,0, $keyword['month'], 1, $keyword['year']),
  28. mktime(23,59,59, $keyword['month']+1, 0, $keyword['year'])
  29. ]);
  30. }
  31. if ($keyword['year']) {
  32. return $query->whereBetween('createtime', [
  33. mktime(0,0,0, 1, 1, $keyword['year']),
  34. mktime(23,59,59,12, 31, $keyword['year'])
  35. ]);
  36. }
  37. if ($keyword['month']) {
  38. return $query->whereBetween('createtime', [
  39. mktime(0,0,0, $keyword['month'], 1, date('Y')),
  40. mktime(23,59,59, $keyword['month']+1, 0, date('Y'))
  41. ]);
  42. }
  43. return $query;
  44. }
  45. public static function search($search)
  46. {
  47. $model = self::uniacid();
  48. if ($search['year'] || $search['month']) {
  49. $start_time = Carbon::createFromDate($search['year'], $search['month'])->startOfMonth()->timestamp;
  50. $end_time = Carbon::createFromDate($search['year'], $search['month'])->endOfMonth()->timestamp;
  51. $model->whereBetween('createtime', [$start_time, $end_time]);
  52. }
  53. if ($search['tag_id'] === '') {
  54. $model->where('uid', \YunShop::app()->uid);
  55. }
  56. if ($search['tag_id'] === 0) {
  57. $model->where('tag_id', 0);
  58. }
  59. return $model;
  60. }
  61. public function getCreatedAtAttribute()
  62. {
  63. return date('Y-m-d H:i:s',$this->attributes['createtime']);
  64. }
  65. public function getTagNameAttribute(){
  66. return $this->tag_id?CoreAttachTags::where('id', $this->tag_id)->value('title'):'未分组';
  67. }
  68. public function atributeNames()
  69. {
  70. }
  71. public function rules()
  72. {
  73. }
  74. }