255], ]; } /** * {@inheritdoc} */ public function attributeLabels() { return [ 'id' => 'ID', 'mall_id' => 'Mall ID', 'user_id' => 'User ID', 'num' => 'Num', 'total_num' => 'Total Num', 'code' => 'Code', 'code_url' => 'Code Url', 'status' => 'Status', 'created_at' => 'Created At', 'updated_at' => 'Updated At', ]; } public function getUser() { return $this->hasOne(User::class, ['id' => 'user_id'])->select('id,mobile,nickname,avatar_url,parent_id'); } public static function setData(array $params){ try{ if(!empty($params['user_id'])){ $model = self::findOne(['user_id' => $params['user_id'],'mall_id' => $params['mall_id'], 'status' => StatusEnum::ENABLED]); if(empty($model)) { $model = new self(); $model->loadDefaultValues(); $model->mall_id = $params['mall_id']; } } else { throw new \Exception('数据不存在或已删除'); } if(!$model->load($params,'') || !$model->save()){ throw new \Exception($model->getErrorMessage()); } return $model; }catch(\Exception $e){ self::setStaticError($e->getMessage()); return false; } } }