ActivityCutPrice.php 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. <?php
  2. /**
  3. * 厦门云联储网络科技有限公司
  4. * https://www.baokuaiyun.com
  5. * Copyright (c) 2023 爆块云 All rights reserved.
  6. */
  7. namespace app\models;
  8. use Yii;
  9. use yii\behaviors\TimestampBehavior;
  10. use yii\db\ActiveRecord;
  11. /**
  12. * This is the model class for table "{{%activity_cut_price}}".
  13. *
  14. * @property integer $id
  15. */
  16. class ActivityCutPrice extends \yii\db\ActiveRecord
  17. {
  18. /**
  19. * @inheritdoc
  20. */
  21. public static function tableName()
  22. {
  23. return '{{%activity_cut_price}}';
  24. }
  25. public function behaviors()
  26. {
  27. return [
  28. [
  29. 'class' => TimestampBehavior::class,
  30. ]
  31. ];
  32. }
  33. public function beforeSave($insert)
  34. {
  35. if (parent::beforeSave($insert)) {
  36. //$this->dirtyAttributes 改动的项目
  37. if (intval($this->is_platform === 1) && !empty($this->dirtyAttributes) && !isset($this->dirtyAttributes['status']) && !in_array($this->dirtyAttributes['is_platform_audit'], [1, 2])) {
  38. $this->is_platform_audit = 0;
  39. }
  40. return true;
  41. }
  42. return false;
  43. }
  44. //店铺进行中活动
  45. public static function activityAt($id) {
  46. $query = self::find();
  47. $query->andWhere([
  48. 'and',
  49. ['id' => $id, 'is_delete' => 0, 'status' => 1],
  50. ['<', 'start_time', time()],
  51. ['>', 'end_time', time()],
  52. ]);
  53. $info = $query->one();
  54. return $info;
  55. }
  56. //店铺进行中活动
  57. public static function activityAtList($store_id = 0, $asArray = false) {
  58. $query = self::find();
  59. $query->andWhere([
  60. 'and',
  61. ['is_delete' => 0, 'status' => 1],
  62. ['<', 'start_time', time()],
  63. ['>', 'end_time', time()],
  64. ]);
  65. if($store_id > -1){
  66. $query->andWhere(['store_id' => $store_id]);
  67. }
  68. $asArray && $query->asArray();
  69. $list = $query->all();
  70. return $list;
  71. }
  72. }