You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

71 lines
1.5 KiB

6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
  1. <?php
  2. declare (strict_types=1);
  3. namespace App\Model\v3;
  4. use App\Model\Model;
  5. use Hyperf\Database\Model\Builder;
  6. use Hyperf\Database\Model\SoftDeletes;
  7. /**
  8. */
  9. class Store extends Model
  10. {
  11. use SoftDeletes;
  12. const IS_OPEN_YES = 1;
  13. const IS_OPEN_NO = 2;
  14. const STATUS_EXAMINING = 1;
  15. const STATUS_PASS = 2;
  16. const STATUS_REFUSE = 3;
  17. const STATUS_EXPIRED = 4;
  18. /**
  19. * The table associated with the model.
  20. *
  21. * @var string
  22. */
  23. protected $table = 'lanzu_store';
  24. /**
  25. * The attributes that are mass assignable.
  26. *
  27. * @var array
  28. */
  29. protected $fillable = [];
  30. /**
  31. * The attributes that should be cast to native types.
  32. *
  33. * @var array
  34. */
  35. protected $casts = [];
  36. protected $appends = [
  37. 'month_sales'
  38. ];
  39. protected function boot(): void
  40. {
  41. parent::boot();
  42. self::addGlobalScope('normal', function (Builder $builder) {
  43. $builder->where(['is_open' => self::IS_OPEN_YES, 'status' => self::STATUS_PASS]);
  44. });
  45. }
  46. public function scopeOrderByDefault($query, $sort)
  47. {
  48. return $query->orderBy('sort', $sort)->orderBy('id', $sort);
  49. }
  50. public function scopeOrderBySales($query, $sort)
  51. {
  52. return $query->orderBy('sales', $sort);
  53. }
  54. public function getMonthSalesAttribute() {
  55. return mt_rand(0,100);
  56. }
  57. public function goods()
  58. {
  59. return $this->hasMany(Goods::class, 'store_id', 'id');
  60. }
  61. }