| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081 |
- <?php
- namespace addons\Achievement\common\models;
- use common\enums\StatusEnum;
- use common\models\base\BaseActiveRecord;
- use Yii;
- /**
- * This is the model class for table "qimall_addons_achievement_user".
- *
- * @property int $id
- * @property int $mall_id 商城id
- * @property int|null $user_id 用户id
- * @property float $total_commission 累计佣金
- * @property int $created_at
- * @property int $updated_at
- * @property int $status 状态[-1:删除;0:禁用;1启用]
- */
- class AchievementUser extends BaseActiveRecord
- {
- /**
- * {@inheritdoc}
- */
- public static function tableName()
- {
- return 'qimall_addons_achievement_user';
- }
- /**
- * {@inheritdoc}
- */
- public function rules()
- {
- return [
- [['mall_id', 'user_id', 'created_at', 'updated_at', 'status', 'is_manual'], 'integer'],
- [['total_commission'], 'number'],
- ];
- }
- /**
- * {@inheritdoc}
- */
- public function attributeLabels()
- {
- return [
- 'id' => 'ID',
- 'mall_id' => '商城id',
- 'user_id' => '用户id',
- 'total_commission' => '累计佣金',
- 'created_at' => 'Created At',
- 'updated_at' => 'Updated At',
- 'status' => '状态[-1:删除;0:禁用;1启用]',
- 'integer' => '是否手动添加[1:是 0:否]',
- ];
- }
- public static function setData(array $params)
- {
- try {
- if (!empty($params['id'])) {
- $model = self::findOne(['mall_id' => $params['mall_id'], 'id' => $params['id'], 'status' => [StatusEnum::ENABLED, StatusEnum::DISABLED]]);
- if (empty($model)) throw new \Exception('服务不存在或已删除');
- } else {
- $model = new self();
- $model->loadDefaultValues();
- }
- if (!$model->load($params, '')) throw new \Exception($model->getErrorMessage());
- if (!$model->save()) throw new \Exception($model->getErrorMessage());
- if($model->status==StatusEnum::DELETE){
- AchievementFirstOrder::updateAll(['status'=>StatusEnum::DELETE,'updated_at'=>time()],['mall_id'=>$model->mall_id,'user_id'=>$model->user_id]);
- }
- return $model;
- } catch (\Exception $e) {
- self::$static_error = $e->getMessage();
- return false;
- }
- }
- }
|