| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109 |
- <?php
- namespace addons\Pk\common\models;
- use common\models\user\User;
- use Yii;
- /**
- * This is the model class for table "addons_pk_personal_member".
- *
- * @property int $id
- * @property int $user_id
- * @property int $mall_id
- * @property int $activity_id 活动id
- * @property float $performance 人数;业绩金额
- * @property int $performance_goal 业绩目标
- * @property int $created_at
- * @property int $updated_at
- * @property int $performance_type 业绩类型;1拉新;2业绩
- * @property int|null $performance_rank 业绩排名
- * @property int $order_id 订单id
- * @property int $status 状态[-1:删除;0:禁用;1启用]
- */
- class PkPersonalMember extends \common\models\base\BaseActiveRecord
- {
- const EABLE_STATUS = 1;
- /**
- * {@inheritdoc}
- */
- public static function tableName()
- {
- return '{{%addons_pk_personal_member}}';
- }
- /**
- * {@inheritdoc}
- */
- public function rules()
- {
- return [
- [['user_id', 'mall_id', 'activity_id', 'performance_type'], 'required'],
- [['user_id', 'mall_id', 'activity_id', 'created_at', 'updated_at', 'performance_type', 'performance_rank', 'order_id', 'status'], 'integer'],
- [['performance', 'performance_goal'], 'number'],
- ];
- }
- /**
- * {@inheritdoc}
- */
- public function attributeLabels()
- {
- return [
- 'id' => 'ID',
- 'user_id' => 'User ID',
- 'mall_id' => 'Mall ID',
- 'activity_id' => '活动id',
- 'performance' => '人数;业绩金额',
- 'performance_goal' => '业绩目标',
- 'created_at' => 'Created At',
- 'updated_at' => 'Updated At',
- 'performance_type' => '业绩类型;1拉新;2业绩',
- 'performance_rank' => '业绩排名',
- 'order_id' => '订单id',
- 'status' => '状态[-1:删除;0:禁用;1启用]',
- ];
- }
- public function getUser()
- {
- return $this->hasOne(User::ClassName(), ['id' => 'user_id']);
- }
- public function getActivity()
- {
- return $this->hasOne(PkActivity::ClassName(), ['id' => 'activity_id']);
- }
- /**
- * 保存数据
- * @Author: ltm
- * @DateTime: 2022/6/8 0015 9:26
- * @Copyright: copyright (c) 2021
- * @param $mall_id
- * @param array $params
- * @return Rebate|bool
- */
- public static function setData(array $params)
- {
- try {
- $mall_id = $params['mall_id'];
- if (!empty($params['id'])) {
- $model = self::findOne(['and', ['id' => $params['id'], 'mall_id' => $mall_id], ['<>', 'status', StatusEnum::ENABLED]]);
- if (empty($model)) throw new \Exception('活动不存在或已删除');
- } else {
- $model = new self();
- $model->loadDefaultValues();
- $model->mall_id = $mall_id;
- }
- if (!$model->load($params, '') || !$model->save()) throw new Exception($model->getErrorMessage());
- return $model;
- } catch (\Exception $e) {
- self::setStaticError($e->getMessage());
- return false;
- }
- }
- }
|