UniacidApp.php 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. <?php
  2. namespace app\platform\modules\application\models;
  3. use app\common\models\BaseModel;
  4. use Illuminate\Database\Eloquent\Model;
  5. use Illuminate\Validation\Rule;
  6. use Illuminate\Database\Eloquent\SoftDeletes;
  7. use Carbon\Carbon;
  8. use app\platform\modules\application\models\AppUser;
  9. use Illuminate\Support\Facades\Schema;
  10. class UniacidApp extends BaseModel
  11. {
  12. use SoftDeletes;
  13. protected $table = 'yz_uniacid_app';
  14. protected $search_fields = ['name', 'validity_time'];
  15. protected $guarded = [''];
  16. protected $hidden = ['deleted_at', 'updated_at', 'created_at',
  17. 'type', 'kind', 'title', 'description', 'version'];
  18. protected $appends = ['status_name'];
  19. public function scopeSearch($query, $keyword)
  20. {
  21. if (!$keyword) {
  22. return $query;
  23. }
  24. if ($keyword['name']) {
  25. $query = $query->where('name', 'like', '%'.$keyword['name'].'%');
  26. }
  27. if ($keyword['maturity']) {
  28. if ($keyword['maturity'] == 1) {
  29. // 到期
  30. $query = $query->where('validity_time', '<>', 0)->where('validity_time', '<', mktime(0,0,0, date('m'), date('d'), date('Y')));
  31. }
  32. if ($keyword['maturity'] == 2) {
  33. $query = $query->where('validity_time', 0)->Orwhere('validity_time', '>=', mktime(0,0,0, date('m'), date('d'), date('Y')));
  34. }
  35. }
  36. return $query;
  37. }
  38. public function atributeNames()
  39. {
  40. return [
  41. 'img'=> "应用图片",
  42. 'url'=> "应用跳转地址",
  43. 'name' => "应用名称",
  44. 'kind' => "行业分类",
  45. 'title' => "应用标题",
  46. 'description' => "应用描述",
  47. 'version' => "应用版本",
  48. 'type' => '应用类型',
  49. 'status' => "应用状态",
  50. 'validity_time' => "有效期",
  51. ];
  52. }
  53. public function rules()
  54. {
  55. return [
  56. 'img' => '',
  57. 'url' => '',
  58. 'name' => '',
  59. 'kind' => '',
  60. 'type' => '',
  61. 'title' => '',
  62. 'description' => '',
  63. 'status' => '',
  64. 'version' => '',
  65. 'validity_time' => 'numeric',
  66. ];
  67. }
  68. public function getStatusNameAttribute()
  69. {
  70. return ['禁用', '启用'][$this->status];
  71. }
  72. public static function chekcApp($id)
  73. {
  74. $app = self::find($id);
  75. if (!$app || $app->status != 1) {
  76. return false;
  77. }
  78. return true;
  79. }
  80. public static function getApplicationByid($id)
  81. {
  82. return self::withTrashed()->where('id', $id)->first();
  83. }
  84. public function hasOneAdminUser()
  85. {
  86. return $this->hasOne(\app\platform\modules\user\models\AdminUser::class, 'uid', 'creator');
  87. }
  88. }