| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130 |
- <?php
- namespace common\models\user;
- use common\enums\StatusEnum;
- use common\models\base\BaseActiveRecord;
- use PHPUnit\Util\Exception;
- use Yii;
- /**
- * This is the model class for table "qimall_tag".
- *
- *
- * @property int $id
- * @property int $mall_id
- * @property string $name 标签名称
- * @property int $type 标签类型
- * @property string $condition 条件
- * @property int $status 状态[-1:删除;0:禁用;1启用]
- * @property int $created_at
- * @property int $updated_at
- */
- class Tag extends BaseActiveRecord
- {
- public static $type_arr = [
- 1 => "价值分层",
- 2 => "生命周期",
- 3 => "营销偏好",
- 4 => "行为偏好",
- ];
- /**
- * {@inheritdoc}
- */
- public static function tableName()
- {
- return '{{%tag}}';
- }
- /**
- * {@inheritdoc}
- */
- public function rules()
- {
- return [
- [['mall_id'], 'required'],
- [['mall_id', 'type', 'status', 'created_at', 'updated_at'], 'integer'],
- [['name'], 'string', 'max' => 45],
- [['condition'], 'string', 'max' => 3000],
- ];
- }
- /**
- * {@inheritdoc}
- */
- public function attributeLabels()
- {
- return [
- 'id' => 'ID',
- 'mall_id' => 'Mall ID',
- 'name' => '标签名称',
- 'type' => '标签类型',
- 'condition' => '条件',
- 'status' => '状态[-1:删除;0:禁用;1启用]',
- 'created_at' => 'Created At',
- 'updated_at' => 'Updated At',
- ];
- }
- /**
- * @param array $where
- * @param string $select
- * @param array $with
- * @param int $is_array
- * @return array|Tag[]|\yii\db\ActiveRecord[]
- */
- public static function getTagList(array $where, $select = '*', array $with = [], int $is_array = 0)
- {
- $query = self::find();
- self::paramPack(['where' => $where, 'with' => $with], $query);
- return $query->select($select)->asArray($is_array)->all();
- }
- /**
- * 保存数据
- * @param array $params
- * @return bool|Tag
- */
- public static function setData(array $params)
- {
- try {
- if (!empty($params['id'])) {
- $model = self::findOne(['id' => $params['id'], 'status' => [StatusEnum::ENABLED, StatusEnum::DISABLED]]);
- if (empty($model)) throw new Exception('服务不存在或已删除');
- } else {
- $model = new self();
- $model->loadDefaultValues();
- }
- if (!$model->load($params, '') || !$model->save()) throw new Exception($model->getErrorMessage());
- return $model;
- } catch (Exception $e) {
- self::$static_error = $e->getMessage();
- return false;
- }
- }
- /**
- * 删除
- * @param $params
- * @param $status
- * @return bool
- */
- public static function del($params, $status)
- {
- try {
- $query = self::find()->where(['and',
- ['id' => $params['id']],
- ['<>', 'status', StatusEnum::DELETE]
- ]);
- $model = $query->one();
- $model->status = $status;
- $res = $model->save();
- if ($res === false) throw new Exception('删除失败');
- return true;
- } catch (\Exception $e) {
- return false;
- }
- }
- }
|