MdGroupActivities.php 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. <?php
  2. /**
  3. * MdGroupActivities.php
  4. * todo 文件描述
  5. * Created on 2024/3/19 11:08
  6. * @author: hankaige
  7. */
  8. namespace app\models;
  9. use yii\behaviors\TimestampBehavior;
  10. use yii\db\ActiveRecord;
  11. /**
  12. * This is the model class for table "{{%md}}".
  13. * @property integer $id
  14. * @property integer $store_id
  15. * @property string $name
  16. * @property integer $start_time
  17. * @property integer $end_time
  18. * @property integer $type
  19. * @property integer $rules
  20. * @property integer $status
  21. * @property integer $jobs_id
  22. * @property integer $created_at
  23. * @property integer $updated_at
  24. * @property integer $is_delete
  25. */
  26. class MdGroupActivities extends \yii\db\ActiveRecord
  27. {
  28. public static function tableName()
  29. {
  30. return "{{%md_group_activities}}";
  31. }
  32. public function behaviors()
  33. {
  34. return [
  35. [
  36. 'class' => TimestampBehavior::class,
  37. 'attributes' => [
  38. ActiveRecord::EVENT_BEFORE_INSERT => ['created_at'],
  39. ActiveRecord::EVENT_BEFORE_UPDATE => ['updated_at']
  40. ]
  41. ]
  42. ];
  43. }
  44. public function rules()
  45. {
  46. return [
  47. [
  48. [
  49. 'store_id',
  50. 'start_time',
  51. 'end_time',
  52. 'name'
  53. ],
  54. 'required'
  55. ],
  56. [
  57. [
  58. 'store_id',
  59. 'start_time',
  60. 'end_time',
  61. 'type',
  62. 'rules',
  63. 'jobs_id'
  64. ],
  65. 'integer'
  66. ],
  67. [
  68. [
  69. 'name'
  70. ],
  71. 'string'
  72. ],
  73. [
  74. [
  75. 'type',
  76. 'rules'
  77. ],
  78. 'default',
  79. 'value' => 0
  80. ],
  81. [
  82. ['status'],
  83. 'default',
  84. 'value' => 1
  85. ],
  86. ];
  87. }
  88. public function attributeLabels()
  89. {
  90. return [
  91. 'store_id' => '商城ID',
  92. 'name' => '活动名称',
  93. 'start_time' => '活动开始时间',
  94. 'end_time' => '活动结束时间',
  95. 'type' => '活动规则',
  96. 'rules' => '规则限制',
  97. 'status' => '活动状态'
  98. ];
  99. }
  100. public function getGoods()
  101. {
  102. return $this->hasMany(MdGroupActivitiesGoods::className(), ['activities_id' => 'id'])->where(['is_delete' => 0]);
  103. }
  104. public function getactivityStatus()
  105. {
  106. if ($this->start_time > time()) {
  107. $activityStatus = 1;
  108. } elseif ($this->end_time < time()) {
  109. $activityStatus = 3;
  110. } else {
  111. $activityStatus = 2;
  112. }
  113. return $activityStatus;
  114. }
  115. }