CoreAttach.php 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. <?php
  2. /**
  3. * Author: 芸众商城 www.yunzshop.com
  4. * Date: 2017/6/6
  5. * Time: 下午9:09
  6. */
  7. namespace app\common\modules\upload\models;
  8. use app\common\models\BaseModel;
  9. use Illuminate\Database\Eloquent\SoftDeletes;
  10. class CoreAttach extends BaseModel
  11. {
  12. use SoftDeletes;
  13. protected $table = 'yz_core_attachment';
  14. protected $guarded = [''];
  15. protected $hidden = ['deleted_at', 'updated_at'];
  16. public $timestamps = true;
  17. protected $datas = ['deleted_at'];
  18. // 存储在表中type字段的对应的类型
  19. const IMAGE_TYPE = 1;// 图片 1
  20. const VOICE_TYPE = 2;// 音频 2
  21. const VIDEO_TYPE = 3;// 视频 3
  22. // 存储在表中upload_type字段的对应的类型
  23. const UPLOAD_LOCAL = 0; // 本地
  24. const UPLOAD_OSS = 2; // 阿里云
  25. const UPLOAD_COS = 4; // 腾讯云
  26. public function scopeSearch($query, $keyword)
  27. {
  28. if ($keyword['month'] && $keyword['year']) {
  29. return $query->whereBetween('created_at', [
  30. mktime(0,0,0, $keyword['month'], 1, $keyword['year']),
  31. mktime(23,59,59, $keyword['month']+1, 0, $keyword['year'])
  32. ]);
  33. }
  34. if ($keyword['year']) {
  35. return $query->whereBetween(
  36. 'created_at',
  37. [
  38. mktime(0,0,0, 1, 1, $keyword['year']),
  39. mktime(23,59,59,12, 31, $keyword['year'])
  40. ]
  41. );
  42. }
  43. if ($keyword['month']) {
  44. return $query->whereBetween(
  45. 'created_at',
  46. [
  47. mktime(0,0,0, $keyword['month'], 1, date('Y')),
  48. mktime(23,59,59, $keyword['month']+1, 0, date('Y'))
  49. ]
  50. );
  51. }
  52. }
  53. public function atributeNames()
  54. {
  55. }
  56. public function rules()
  57. {
  58. }
  59. }