PkSetting.php 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. <?php
  2. namespace addons\Pk\common\models;
  3. use Yii;
  4. /**
  5. * This is the model class for table "{{%addons_pk_setting}}".
  6. *
  7. * @property int $id
  8. * @property int $mall_id
  9. * @property string $key
  10. * @property string $value
  11. * @property int $status 状态[-1:删除;0:禁用;1启用]
  12. * @property int $created_at 创建时间
  13. * @property int $updated_at 修改时间
  14. */
  15. class PkSetting extends \common\models\base\BaseActiveRecord
  16. {
  17. const OPEN = 1;//开启
  18. const CLOSED = 0; //关闭
  19. const KEY_BASIC = "basic"; //基础配置;
  20. const KEY_RULES = "rules";
  21. const FEILD_NOT_ALLOW_APPLY_HOUR = 'not_allow_apply_hour';//-1不限制,禁止报名PK活动时间.
  22. const ALLOW_APPLY_HOUR = -1;//-1不限制,禁止报名PK活动时间.
  23. const FEILD_IS_TEAM_AUDIT = 'is_team_audit';//战队审核
  24. /**
  25. * {@inheritdoc}
  26. */
  27. public static function tableName()
  28. {
  29. return '{{%addons_pk_setting}}';
  30. }
  31. /**
  32. * {@inheritdoc}
  33. */
  34. public function rules()
  35. {
  36. return [
  37. [['mall_id', 'key', 'value'], 'required'],
  38. [['mall_id', 'status', 'created_at', 'updated_at'], 'integer'],
  39. [['value'], 'string'],
  40. [['key'], 'string', 'max' => 255],
  41. ];
  42. }
  43. /**
  44. * {@inheritdoc}
  45. */
  46. public function attributeLabels()
  47. {
  48. return [
  49. 'id' => 'ID',
  50. 'mall_id' => 'Mall ID',
  51. 'key' => 'Key',
  52. 'value' => 'Value',
  53. 'status' => '状态[-1:删除;0:禁用;1启用]',
  54. 'created_at' => '创建时间',
  55. 'updated_at' => '修改时间',
  56. ];
  57. }
  58. /**
  59. * 单条数据
  60. * @param $mall_id
  61. * @return array|\yii\db\ActiveRecord|null
  62. */
  63. public function getOneItem($mall_id, $key)
  64. {
  65. return self::find()->where(['mall_id' => $mall_id, 'key' => $key])->one();
  66. }
  67. /**
  68. * 详情,json_encode过的
  69. * @param $mall_id
  70. * @return mixed
  71. */
  72. public function detail($mall_id, $key)
  73. {
  74. $one = $this->getOneItem($mall_id, $key);
  75. if(!empty($one) && !empty($one["value"])){
  76. $one = json_decode($one['value'], true);
  77. }
  78. return $one;
  79. }
  80. }