Goods.php 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. <?php
  2. namespace App\Models;
  3. use Illuminate\Database\Eloquent\Builder;
  4. use Illuminate\Database\Eloquent\Model;
  5. use Illuminate\Database\Eloquent\SoftDeletes;
  6. /**
  7. * 商品
  8. *
  9. * @property int $id
  10. * @property string $name 商品名称
  11. * @property string|null $logo 商品图片地址
  12. * @property int $traffic 商品内含多少流量,单位MiB
  13. * @property int $type 商品类型:1-流量包、2-套餐
  14. * @property int $price 售价,单位分
  15. * @property int $level 购买后给用户授权的等级
  16. * @property int $renew 流量重置价格,单位分
  17. * @property int $period 流量自动重置周期
  18. * @property string|null $info 商品信息
  19. * @property string|null $description 商品描述
  20. * @property int $days 有效期
  21. * @property int $invite_num 赠送邀请码数
  22. * @property int $limit_num 限购数量,默认为0不限购
  23. * @property string $color 商品颜色
  24. * @property int $sort 排序
  25. * @property int $is_hot 是否热销:0-否、1-是
  26. * @property int $status 状态:0-下架、1-上架
  27. * @property \Illuminate\Support\Carbon $created_at 创建时间
  28. * @property \Illuminate\Support\Carbon $updated_at 最后更新时间
  29. * @property \Illuminate\Support\Carbon|null $deleted_at 删除时间
  30. * @property-read mixed $traffic_label
  31. * @method static Builder|Goods newModelQuery()
  32. * @method static Builder|Goods newQuery()
  33. * @method static Builder|Goods onlyTrashed()
  34. * @method static Builder|Goods query()
  35. * @method static Builder|Goods type($type)
  36. * @method static Builder|Goods whereColor($value)
  37. * @method static Builder|Goods whereCreatedAt($value)
  38. * @method static Builder|Goods whereDays($value)
  39. * @method static Builder|Goods whereDeletedAt($value)
  40. * @method static Builder|Goods whereDescription($value)
  41. * @method static Builder|Goods whereId($value)
  42. * @method static Builder|Goods whereInfo($value)
  43. * @method static Builder|Goods whereInviteNum($value)
  44. * @method static Builder|Goods whereIsHot($value)
  45. * @method static Builder|Goods whereLevel($value)
  46. * @method static Builder|Goods whereLimitNum($value)
  47. * @method static Builder|Goods whereLogo($value)
  48. * @method static Builder|Goods whereName($value)
  49. * @method static Builder|Goods wherePeriod($value)
  50. * @method static Builder|Goods wherePrice($value)
  51. * @method static Builder|Goods whereRenew($value)
  52. * @method static Builder|Goods whereSort($value)
  53. * @method static Builder|Goods whereStatus($value)
  54. * @method static Builder|Goods whereTraffic($value)
  55. * @method static Builder|Goods whereType($value)
  56. * @method static Builder|Goods whereUpdatedAt($value)
  57. * @method static Builder|Goods withTrashed()
  58. * @method static Builder|Goods withoutTrashed()
  59. * @mixin \Eloquent
  60. */
  61. class Goods extends Model {
  62. use SoftDeletes;
  63. protected $table = 'goods';
  64. protected $dates = ['deleted_at'];
  65. public function scopeType($query, $type) {
  66. return $query->whereType($type)->whereStatus(1)->orderByDesc('sort');
  67. }
  68. public function getPriceAttribute($value) {
  69. return $value / 100;
  70. }
  71. public function setPriceAttribute($value): void {
  72. $this->attributes['price'] = $value * 100;
  73. }
  74. public function getRenewAttribute($value) {
  75. return $value / 100;
  76. }
  77. public function setRenewAttribute($value) {
  78. return $this->attributes['renew'] = $value * 100;
  79. }
  80. public function getTrafficLabelAttribute() {
  81. return flowAutoShow($this->attributes['traffic'] * MB);
  82. }
  83. }