255], ]; } /** * {@inheritdoc} */ public function attributeLabels() { return [ 'id' => '自增id', 'e_coupon_code_id' => '核销码id', 'user_e_coupon_id' => '会员电子券id', 'e_coupon_id' => '电子券id', 'created_at' => 'Created At', 'updated_at' => 'Updated At', 'status' => '状态[-1:删除;0:禁用;1启用]', 'user_id' => '使用会员user_id', 'e_coupon_name' => '电子券名称', 'amount' => '数量', 'mall_id' => '商城id', 'price_type' => '收益类型1积分2佣金', 'commission' => '积分或佣金金额', 'clerk_user_id' => '核销员user_id', 'clerk_admin_id' => '核销员admin_id(后台核销)', ]; } public function getUser() { return $this->hasOne(User::class, ['id' => 'user_id'])->select('id,mobile,nickname,avatar_url,username'); } /** * 数据设置 */ public static function setData(array $params) { try{ if (!isset($params['mall_id']) || empty($params['mall_id'])) throw new Exception('缺少商城ID'); $mall_id = $params['mall_id']; if (isset($params['id']) && !empty($params['id'])) { $model = self::findOne(['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; } } }