UserLabelCond.php 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. <?php
  2. namespace common\models\user;
  3. use Yii;
  4. use yii\db\Exception;
  5. /**
  6. * This is the model class for table "{{%user_label_cond}}".
  7. *
  8. *
  9. * @property int $id
  10. * @property int $mall_id 商城ID
  11. * @property int $label_id 对应qimall_user_label.id
  12. * @property string $cond_type 条件类型
  13. * @property string|null $condition 条件内容
  14. * @property int|null $status 状态[-1:删除;0:禁用;1启用]
  15. * @property int $created_at
  16. * @property int $updated_at
  17. * @property int $select_status 是否选择中 是选中条件0:未选中,1:选中
  18. */
  19. class UserLabelCond extends \common\models\base\BaseActiveRecord
  20. {
  21. /**
  22. * {@inheritdoc}
  23. */
  24. public static function tableName()
  25. {
  26. return '{{%user_label_cond}}';
  27. }
  28. /**
  29. * {@inheritdoc}
  30. */
  31. public function rules()
  32. {
  33. return [
  34. [['mall_id', 'label_id', 'status', 'created_at', 'updated_at','select_status'], 'integer'],
  35. [['cond_type'], 'string', 'max' => 45],
  36. [['condition'], 'string', 'max' => 5000],
  37. ];
  38. }
  39. /**
  40. * {@inheritdoc}
  41. */
  42. public function attributeLabels()
  43. {
  44. return [
  45. 'id' => 'ID',
  46. 'mall_id' => '商城ID',
  47. 'label_id' => '对应qimall_user_label.id',
  48. 'cond_type' => '条件类型',
  49. 'condition' => '条件内容',
  50. 'status' => '状态[-1:删除;0:禁用;1启用]',
  51. 'select_status' => '是否选择中',
  52. 'created_at' => 'Created At',
  53. 'updated_at' => 'Updated At',
  54. ];
  55. }
  56. /**
  57. * @Author: ltm
  58. * @DateTime: 2022/3/10 0010 9:29
  59. * @Copyright: copyright (c) 2021 广东七件事集团
  60. * @param $data
  61. * @return string
  62. */
  63. public static function setData(array $params){
  64. try{
  65. $model = self::findOne(['label_id'=>$params['label_id'],'mall_id'=>$params['mall_id'],'cond_type'=>$params['cond_type']]);
  66. if(empty($model)){
  67. $model = new self();
  68. $model->loadDefaultValues();
  69. }
  70. if(!$model->load($params,'') || !$model->save()){
  71. throw new Exception($model->getErrorMessage());
  72. }
  73. return $model;
  74. }catch(\Exception $e){
  75. self::setStaticError($e->getMessage());
  76. return false;
  77. }
  78. }
  79. }