SeckillActivity.php 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. <?php
  2. /**
  3. * 厦门云联储网络科技有限公司
  4. * https://www.baokuaiyun.com
  5. * Copyright (c) 2023 爆块云 All rights reserved.
  6. */
  7. namespace app\models;
  8. use app\jobs\storeSync\DiyCommon;
  9. use yii\behaviors\TimestampBehavior;
  10. use yii\db\ActiveRecord;
  11. /**
  12. * This is the model class for table "{{%seckill_activity}}".
  13. *
  14. * @property integer $id
  15. * @property string $name
  16. * @property integer $start_time
  17. * @property integer $end_time
  18. * @property integer $self_limit_num
  19. * @property integer $order_limit_num
  20. * @property integer $is_use_coupon
  21. * @property integer $created_at
  22. * @property integer $updated_at
  23. * @property integer $is_delete
  24. * @property integer $store_id
  25. * @property integer $status
  26. * @property integer $is_platform
  27. * @property integer $is_platform_audit
  28. */
  29. class SeckillActivity extends \yii\db\ActiveRecord
  30. {
  31. /**
  32. * @inheritdoc
  33. */
  34. public static function tableName()
  35. {
  36. return '{{%seckill_activity}}';
  37. }
  38. public function behaviors()
  39. {
  40. return [
  41. [
  42. 'class' => TimestampBehavior::class,
  43. 'attributes' => [
  44. ActiveRecord::EVENT_BEFORE_INSERT => ['created_at'],
  45. ActiveRecord::EVENT_BEFORE_UPDATE => ['updated_at']
  46. ]
  47. ]
  48. ];
  49. }
  50. public function beforeSave($insert)
  51. {
  52. if (parent::beforeSave($insert)) {
  53. //$this->dirtyAttributes 改动的项目
  54. if (intval($this->is_platform === 1) && !empty($this->dirtyAttributes) && !isset($this->dirtyAttributes['status']) && !in_array($this->dirtyAttributes['is_platform_audit'], [1, 2])) {
  55. $this->is_platform_audit = 0;
  56. }
  57. return true;
  58. }
  59. return false;
  60. }
  61. /**
  62. * @inheritdoc
  63. */
  64. public function rules()
  65. {
  66. return [
  67. [['id', 'start_time', 'end_time', 'self_limit_num', 'order_limit_num', 'is_use_coupon', 'is_delete', 'store_id', 'status', 'is_platform', 'is_platform_audit'], 'integer'],
  68. [['name'], 'string'],
  69. [['created_at', 'updated_at'], 'safe']
  70. ];
  71. }
  72. /**
  73. * @inheritdoc
  74. */
  75. public function attributeLabels()
  76. {
  77. return [
  78. 'id' => 'ID',
  79. 'name' => '活动名称',
  80. 'start_time' => '开始时间',
  81. 'end_time' => '结束时间',
  82. 'self_limit_num' => '个人限购',
  83. 'order_limit_num' => '订单限购',
  84. 'is_use_coupon' => '是否使用优惠券',
  85. 'created_at' => '创建时间',
  86. 'updated_at' => '修改时间',
  87. 'is_delete' => 'is_delete',
  88. 'store_id' => 'Store Id',
  89. 'status' => '状态'
  90. ];
  91. }
  92. public function afterSave($insert, $changedAttributes)
  93. {
  94. parent::afterSave($insert, $changedAttributes); // TODO: Change the autogenerated stub
  95. (new DiyCommon)->JobBehaviors($this->store_id, StoreSyncExtLog::TYPE_SECKILL, [$this->id]);
  96. }
  97. }