UserLabel.php 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. <?php
  2. /**
  3. * 重庆赤晓店信息科技有限公司
  4. * https://www.chixiaodian.com
  5. * Copyright (c) 2023 赤店商城 All rights reserved.
  6. */
  7. namespace app\models;
  8. use Yii;
  9. use yii\db\ActiveRecord;
  10. use yii\behaviors\TimestampBehavior;
  11. /**
  12. * This is the model class for table "{{%user_coupon}}".
  13. *
  14. * @property integer $id
  15. * @property integer $store_id
  16. * @property string $label_name
  17. * @property integer $sort
  18. * @property integer $status
  19. * @property integer $is_delete
  20. * @property integer $created_at
  21. * @property integer $updated_at
  22. */
  23. class UserLabel extends \yii\db\ActiveRecord
  24. {
  25. /**
  26. * {@inheritdoc}
  27. */
  28. public static function tableName()
  29. {
  30. return '{{%user_label}}';
  31. }
  32. const STATUS_OPEN = 1;
  33. const STATUS_CLOSE = 0;
  34. public function behaviors()
  35. {
  36. return [
  37. [
  38. 'class' => TimestampBehavior::class,
  39. 'attributes' => [
  40. ActiveRecord::EVENT_BEFORE_INSERT => ['updated_at', 'created_at'],
  41. ActiveRecord::EVENT_BEFORE_UPDATE => 'updated_at'
  42. ]
  43. ]
  44. ];
  45. }
  46. /**
  47. * {@inheritdoc}
  48. */
  49. public function rules()
  50. {
  51. return [
  52. [['id', 'store_id', 'sort', 'status', 'is_delete'], 'integer'],
  53. [['label_name'], 'string'],
  54. [['created_at', 'updated_at'], 'safe'],
  55. ];
  56. }
  57. /**
  58. * {@inheritdoc}
  59. */
  60. public function attributeLabels()
  61. {
  62. return [
  63. 'id' => '',
  64. 'store_id' => 'Store Id',
  65. 'label_name' => '标签名称',
  66. 'sort' => '排序',
  67. 'status' => '状态:0=关闭;1=开启;',
  68. 'is_delete' => 'Is Delete',
  69. 'created_at' => '',
  70. 'updated_at' => '',
  71. ];
  72. }
  73. //获取无页码标签
  74. public static function getList($store_id, $label_name = '') {
  75. $query = self::find()->where(['store_id' => $store_id, 'is_delete' => 0, 'status' => self::STATUS_OPEN])->orderBy('sort DESC')
  76. ->select('id, label_name');
  77. if (!empty($label_name)) {
  78. $query->andWhere(['LIKE', 'label_name', $label_name]);
  79. }
  80. return $query->asArray()->all();
  81. }
  82. //获取标签
  83. public static function getLabel($store_id, $id) {
  84. return self::findOne(['store_id' => $store_id, 'is_delete' => 0, 'id' => $id, 'status' => self::STATUS_OPEN]);
  85. }
  86. public static function getLabelNames($store_id, $ids){
  87. return self::find()->where(['store_id' => $store_id, 'is_delete' => 0, 'id' => explode(',',$ids), 'status' => self::STATUS_OPEN])->select('label_name')->asArray()->column();
  88. }
  89. }