
{
"uuid": "e88e79faad9011e8a14554ee75d2ebc1",
"article_type_code": "standard",
"article_category_id": 1,
"title": "标题 - 20180904 - 1",
"author": "作者 - 20180904 - 1",
"source": "spider",
"source_user_id": 1,
"source_article_id": 1,
"content": "文章内容 - 20180904 - 1",
"cover_pic": "/upload/Image/mrtp/2018/08/30/1_8a2fa998c0624c0ebee6eb72c5434e7a.gif",
"cover_type": 1,
"tag": "",
"apply": 0,
"original_platform": 0,
"original_url": "",
"original_author": ""
}
Array
(
[uuid] => e88e79faad9011e8a14554ee75d2ebc1
[article_type_code] => standard
[article_category_id] => 1
[title] => 标题 - 20180904 - 1
[author] => 作者 - 20180904 - 1
[source] => spider
[source_user_id] => 1
[source_article_id] => 1
[content] => 文章内容 - 20180904 - 1
[cover_pic] => /upload/Image/mrtp/2018/08/30/1_8a2fa998c0624c0ebee6eb72c5434e7a.gif
[cover_type] => 1
[tag] =>
[apply] => 0
[original_platform] => 0
[original_url] =>
[original_author] =>
[group_id] => 015ce30b116ce86058fa6ab4fea4ac63
)

{
"uuid": [
"e88e79faad9011e8a14554ee75d2ebc1",
"9f359272b00e11e8875654ee75d2ebc1"
],
"article_type_code": "standard",
"article_category_id": 1,
"title": "标题 - 20180904 - 1",
"author": "作者 - 20180904 - 1",
"source": "spider",
"source_user_id": 1,
"source_article_id": 1,
"content": "文章内容 - 20180904 - 1",
"cover_pic": "/upload/Image/mrtp/2018/08/30/1_8a2fa998c0624c0ebee6eb72c5434e7a.gif",
"cover_type": 1,
"tag": "",
"apply": 0,
"original_platform": 0,
"original_url": "",
"original_author": ""
}
Array
(
[uuid] => Array
(
[0] => e88e79faad9011e8a14554ee75d2ebc1
[1] => 9f359272b00e11e8875654ee75d2ebc1
)
[article_type_code] => standard
[article_category_id] => 1
[title] => 标题 - 20180904 - 1
[author] => 作者 - 20180904 - 1
[source] => spider
[source_user_id] => 1
[source_article_id] => 1
[content] => 文章内容 - 20180904 - 1
[cover_pic] => /upload/Image/mrtp/2018/08/30/1_8a2fa998c0624c0ebee6eb72c5434e7a.gif
[cover_type] => 1
[tag] =>
[apply] => 0
[original_platform] => 0
[original_url] =>
[original_author] =>
[group_id] => 015ce30b116ce86058fa6ab4fea4ac63
)
/**
* Creates a new model.
* @return \yii\db\ActiveRecordInterface the model newly created
* @throws ServerErrorHttpException if there is any error when creating the model
*/
public function run()
{
if ($this->checkAccess) {
call_user_func($this->checkAccess, $this->id);
}
$requestParams = Yii::$app->getRequest()->getBodyParams();
/* 判断请求体参数中租户ID是否存在 */
if (!isset($requestParams['group_id'])) {
$requestParams = ArrayHelper::merge($requestParams, ['group_id' => Yii::$app->params['groupId']]);
}
/* 标准(普通、图文)的文章发布参数 */
$qqArticleStandardCreateParam = new QqArticleStandardCreateParam();
// 把请求数据填充到模型中
if (!$qqArticleStandardCreateParam->load($requestParams, '')) {
return ['code' => 40009, 'message' => Yii::t('error', '40009')];
}
// 验证模型
if (!$qqArticleStandardCreateParam->validate()) {
$qqArticleStandardCreateParamResult = self::handleValidateError($qqArticleStandardCreateParam);
if ($qqArticleStandardCreateParamResult['status'] === false) {
return ['code' => $qqArticleStandardCreateParamResult['code'], 'message' => $qqArticleStandardCreateParamResult['message']];
}
}
/* 基于文章类型代码定义场景 */
$this->scenario = 'qq_article_' . $qqArticleStandardCreateParam->article_type_code . '_create';
/* 实例化多个模型 */
// 企鹅号的第三方服务平台应用的企鹅媒体用户
$qqTpAppPenguin = new QqTpAppPenguin([
'scenario' => $this->scenario,
]);
// 转换标准(普通、图文)的文章发布参数,多模型的填充、验证的实现
$requestParams[$qqTpAppPenguin->formName()]['uuid'] = $qqArticleStandardCreateParam->uuid;
$qqTpAppPenguinResult = self::handleLoadAndValidate($qqTpAppPenguin, $requestParams);
if ($qqTpAppPenguinResult['status'] === false) {
return ['code' => $qqTpAppPenguinResult['code'], 'message' => $qqTpAppPenguinResult['message']];
}
}
/**
* 处理模型填充与验证
* @param object $model 模型
* @param array $requestParams 请求参数
* @return array
* 格式如下:
*
* [
* 'status' => true, // 成功
* ]
*
* [
* 'status' => false, // 失败
* 'code' => 20004, // 返回码
* 'message' => '数据验证失败:企鹅号ID(UUID)是无效的。', // 说明
* ]
*
* @throws ServerErrorHttpException
*/
public static function handleLoadAndValidate($model, $requestParams)
{
// 把请求数据填充到模型中
if (!$model->load($requestParams)) {
return ['status' => false, 'code' => 40009, 'message' => Yii::t('error', '40009')];
}
// 验证模型
if (!$model->validate()) {
return self::handleValidateError($model);
}
return ['status' => true];
}
/**
* 处理模型错误
* @param object $model 模型
* @return array
* 格式如下:
*
* [
* 'status' => false, // 失败
* 'code' => 20004, // 返回码
* 'message' => '数据验证失败:代码是无效的。', // 说明
* ]
*
* @throws ServerErrorHttpException
*/
public static function handleValidateError($model)
{
if ($model->hasErrors()) {
$response = Yii::$app->getResponse();
$response->setStatusCode(422, 'Data Validation Failed.');
foreach ($model->getFirstErrors() as $message) {
$firstErrors = $message;
break;
}
return ['status' => false, 'code' => 20004, 'message' => Yii::t('error', Yii::t('error', Yii::t('error', '20004'), ['firstErrors' => $firstErrors]))];
} elseif (!$model->hasErrors()) {
throw new ServerErrorHttpException('Failed to create the object for unknown reason.');
}
}
<pre class="wp-block-syntaxhighlighter-code">
/**
* Creates a new model.
* @return \yii\db\ActiveRecordInterface the model newly created
* @throws ServerErrorHttpException if there is any error when creating the model
*/
public function run()
{
if ($this->checkAccess) {
call_user_func($this->checkAccess, $this->id);
}
$requestParams = Yii::$app->getRequest()->getBodyParams();
/* 判断请求体参数中租户ID是否存在 */
if (!isset($requestParams['group_id'])) {
$requestParams = ArrayHelper::merge($requestParams, ['group_id' => Yii::$app->params['groupId']]);
}
/* 标准(普通、图文)的文章发布参数 */
$qqArticleStandardCreateParam = new QqArticleStandardCreateParam();
// 把请求数据填充到模型中
if (!$qqArticleStandardCreateParam->load($requestParams, '')) {
return ['code' => 40009, 'message' => Yii::t('error', '40009')];
}
// 验证模型
if (!$qqArticleStandardCreateParam->validate()) {
$qqArticleStandardCreateParamResult = self::handleValidateError($qqArticleStandardCreateParam);
if ($qqArticleStandardCreateParamResult['status'] === false) {
return ['code' => $qqArticleStandardCreateParamResult['code'], 'message' => $qqArticleStandardCreateParamResult['message']];
}
}
/* 基于文章类型代码定义场景 */
$this->scenario = 'qq_article_' . $qqArticleStandardCreateParam->article_type_code . '_create';
/* 实例化多个模型 */
// 企鹅号的第三方服务平台应用的企鹅媒体用户
if (!is_array($requestParams['uuid'])) {
return ['code' => 40009, 'message' => Yii::t('error', '40009')];
}
$count = count($requestParams['uuid']);
// 创建一个初始的 $qqTpAppPenguins 数组包含一个默认的模型
$qqTpAppPenguins = [new QqTpAppPenguin([
'scenario' => $this->scenario,
])];
for($i = 1; $i < $count; $i++) {
$qqTpAppPenguins[] = new QqTpAppPenguin([
'scenario' => $this->scenario,
]);
}
foreach ($requestParams['uuid'] as $key => $uuid) {
// 转换标准(普通、图文)的文章发布参数,多模型的填充、验证的实现
$requestParams[$qqTpAppPenguins[0]->formName()][$key]['uuid'] = $uuid;
}
// 批量填充模型属性
if (!Model::loadMultiple($qqTpAppPenguins, $requestParams, $qqTpAppPenguins[0]->formName())) {
return ['code' => 40009, 'message' => Yii::t('error', '40009')];
}
// 批量验证模型
if (!Model::validateMultiple($qqTpAppPenguins)) {
$qqTpAppPenguinsResult = self::handleValidateMultipleError($qqTpAppPenguins);
if ($qqTpAppPenguinsResult['status'] === false) {
return ['code' => $qqTpAppPenguinsResult['code'], 'message' => $qqTpAppPenguinsResult['message']];
}
}
}
/**
* 处理模型填充与验证
* @param object $model 模型
* @param array $requestParams 请求参数
* @return array
* 格式如下:
*
* [
* 'status' => true, // 成功
* ]
*
* [
* 'status' => false, // 失败
* 'code' => 20004, // 返回码
* 'message' => '数据验证失败:企鹅号ID(UUID)是无效的。', // 说明
* ]
*
* @throws ServerErrorHttpException
*/
public static function handleLoadAndValidate($model, $requestParams)
{
// 把请求数据填充到模型中
if (!$model->load($requestParams)) {
return ['status' => false, 'code' => 40009, 'message' => Yii::t('error', '40009')];
}
// 验证模型
if (!$model->validate()) {
return self::handleValidateError($model);
}
return ['status' => true];
}
/**
* 处理模型错误
* @param object $model 模型
* @return array
* 格式如下:
*
* [
* 'status' => false, // 失败
* 'code' => 20004, // 返回码
* 'message' => '数据验证失败:代码是无效的。', // 说明
* ]
*
* @throws ServerErrorHttpException
*/
public static function handleValidateError($model)
{
if ($model->hasErrors()) {
$response = Yii::$app->getResponse();
$response->setStatusCode(422, 'Data Validation Failed.');
foreach ($model->getFirstErrors() as $message) {
$firstErrors = $message;
break;
}
return ['status' => false, 'code' => 20004, 'message' => Yii::t('error', Yii::t('error', Yii::t('error', '20004'), ['firstErrors' => $firstErrors]))];
} elseif (!$model->hasErrors()) {
throw new ServerErrorHttpException('Failed to create the object for unknown reason.');
}
}
/**
* 处理模型错误
* @param array $models 模型列表
* @return array
* 格式如下:
*
* [
* 'status' => false, // 失败
* 'code' => 20004, // 返回码
* 'message' => '数据验证失败:代码是无效的。', // 说明
* ]
*
* @throws ServerErrorHttpException
*/
public static function handleValidateMultipleError($models)
{
foreach ($models as $model) {
if ($model->hasErrors()) {
$response = Yii::$app->getResponse();
$response->setStatusCode(422, 'Data Validation Failed.');
foreach ($model->getFirstErrors() as $message) {
$firstErrors = $message;
break;
}
return ['status' => false, 'code' => 20004, 'message' => Yii::t('error', Yii::t('error', Yii::t('error', '20004'), ['firstErrors' => $firstErrors]))];
}
}
throw new ServerErrorHttpException('Failed to create the object for unknown reason.');
}
</pre>
{
"uuid": "e88e79faad9011e8a14554ee75d2ebc1",
"article_type_code": "standard",
"article_category_id": 1,
"title": "标题 - 20180904 - 1",
"author": "作者 - 20180904 - 1",
"source": "spider",
"source_user_id": 1,
"source_article_id": 1,
"content": "文章内容 - 20180904 - 1",
"cover_pic": "/upload/Image/mrtp/2018/08/30/1_8a2fa998c0624c0ebee6eb72c5434e7a.gif",
"cover_type": 1,
"tag": "",
"apply": 0,
"original_platform": 0,
"original_url": "",
"original_author": ""
}
{
"code": 40009,
"message": "数据模型填充失败"
}
{
"uuid": [
"e88e79faad9011e8a14554ee75d2ebc10"
],
"article_type_code": "standard",
"article_category_id": 1,
"title": "标题 - 20180904 - 1",
"author": "作者 - 20180904 - 1",
"source": "spider",
"source_user_id": 1,
"source_article_id": 1,
"content": "文章内容 - 20180904 - 1",
"cover_pic": "/upload/Image/mrtp/2018/08/30/1_8a2fa998c0624c0ebee6eb72c5434e7a.gif",
"cover_type": 1,
"tag": "",
"apply": 0,
"original_platform": 0,
"original_url": "",
"original_author": ""
}
{
"code": 20004,
"message": "数据验证失败:企鹅号ID(UUID)是无效的。"
}
SELECT EXISTS(SELECT * FROM `cpa_qq_tp_app_penguin` WHERE (`cpa_qq_tp_app_penguin`.`uuid`='e88e79faad9011e8a14554ee75d2ebc10') AND (`status`=1))
{
"uuid": [
"e88e79faad9011e8a14554ee75d2ebc15",
"9f359272b00e11e8875654ee75d2ebc16"
],
"article_type_code": "standard",
"article_category_id": 1,
"title": "标题 - 20180904 - 1",
"author": "作者 - 20180904 - 1",
"source": "spider",
"source_user_id": 1,
"source_article_id": 1,
"content": "文章内容 - 20180904 - 1",
"cover_pic": "/upload/Image/mrtp/2018/08/30/1_8a2fa998c0624c0ebee6eb72c5434e7a.gif",
"cover_type": 1,
"tag": "",
"apply": 0,
"original_platform": 0,
"original_url": "",
"original_author": ""
}
{
"code": 20004,
"message": "数据验证失败:企鹅号ID(UUID)是无效的。"
}
SELECT EXISTS(SELECT * FROM `cpa_qq_tp_app_penguin` WHERE (`cpa_qq_tp_app_penguin`.`uuid`='e88e79faad9011e8a14554ee75d2ebc15') AND (`status`=1))
SELECT EXISTS(SELECT * FROM `cpa_qq_tp_app_penguin` WHERE (`cpa_qq_tp_app_penguin`.`uuid`='9f359272b00e11e8875654ee75d2ebc16') AND (`status`=1))
{
"uuid": [
"e88e79faad9011e8a14554ee75d2ebc1",
"9f359272b00e11e8875654ee75d2ebc16"
],
"article_type_code": "standard",
"article_category_id": 1,
"title": "标题 - 20180904 - 1",
"author": "作者 - 20180904 - 1",
"source": "spider",
"source_user_id": 1,
"source_article_id": 1,
"content": "文章内容 - 20180904 - 1",
"cover_pic": "/upload/Image/mrtp/2018/08/30/1_8a2fa998c0624c0ebee6eb72c5434e7a.gif",
"cover_type": 1,
"tag": "",
"apply": 0,
"original_platform": 0,
"original_url": "",
"original_author": ""
}
{
"code": 20004,
"message": "数据验证失败:企鹅号ID(UUID)是无效的。"
}
SELECT EXISTS(SELECT * FROM `cpa_qq_tp_app_penguin` WHERE (`cpa_qq_tp_app_penguin`.`uuid`='e88e79faad9011e8a14554ee75d2ebc1') AND (`status`=1))
SELECT EXISTS(SELECT * FROM `cpa_qq_tp_app_penguin` WHERE (`cpa_qq_tp_app_penguin`.`uuid`='9f359272b00e11e8875654ee75d2ebc16') AND (`status`=1))
{
"uuid": [
"e88e79faad9011e8a14554ee75d2ebc13",
"9f359272b00e11e8875654ee75d2ebc1"
],
"article_type_code": "standard",
"article_category_id": 1,
"title": "标题 - 20180904 - 1",
"author": "作者 - 20180904 - 1",
"source": "spider",
"source_user_id": 1,
"source_article_id": 1,
"content": "文章内容 - 20180904 - 1",
"cover_pic": "/upload/Image/mrtp/2018/08/30/1_8a2fa998c0624c0ebee6eb72c5434e7a.gif",
"cover_type": 1,
"tag": "",
"apply": 0,
"original_platform": 0,
"original_url": "",
"original_author": ""
}
{
"code": 20004,
"message": "数据验证失败:企鹅号ID(UUID)是无效的。"
}
SELECT EXISTS(SELECT * FROM `cpa_qq_tp_app_penguin` WHERE (`cpa_qq_tp_app_penguin`.`uuid`='e88e79faad9011e8a14554ee75d2ebc13') AND (`status`=1))
SELECT EXISTS(SELECT * FROM `cpa_qq_tp_app_penguin` WHERE (`cpa_qq_tp_app_penguin`.`uuid`='9f359272b00e11e8875654ee75d2ebc1') AND (`status`=1))
{
"uuid": [
"e88e79faad9011e8a14554ee75d2ebc1",
"9f359272b00e11e8875654ee75d2ebc1"
],
"article_type_code": "standard",
"article_category_id": 1,
"title": "标题 - 20180904 - 1",
"author": "作者 - 20180904 - 1",
"source": "spider",
"source_user_id": 1,
"source_article_id": 1,
"content": "文章内容 - 20180904 - 1",
"cover_pic": "/upload/Image/mrtp/2018/08/30/1_8a2fa998c0624c0ebee6eb72c5434e7a.gif",
"cover_type": 1,
"tag": "",
"apply": 0,
"original_platform": 0,
"original_url": "",
"original_author": ""
}
{
"code": 10000,
"message": "发布文章类型:标准(普通、图文)的文章成功"
}
SELECT EXISTS(SELECT * FROM `cpa_qq_tp_app_penguin` WHERE (`cpa_qq_tp_app_penguin`.`uuid`='e88e79faad9011e8a14554ee75d2ebc1') AND (`status`=1))
SELECT EXISTS(SELECT * FROM `cpa_qq_tp_app_penguin` WHERE (`cpa_qq_tp_app_penguin`.`uuid`='9f359272b00e11e8875654ee75d2ebc1') AND (`status`=1))
PHP / Laravel / Yii2 老项目维护与长期技术支持
如果你的 PHP / Laravel / Yii2 项目已经上线,但遇到原开发离职、Bug 长期无人修复、接口不稳定、性能下降、代码难以接手等问题,可以联系我做一次远程技术排查。
适合以下情况:
✅ 老旧 PHP 系统无人维护
✅ Laravel / Yii2 项目 Bug 修复
✅ 后台管理系统小功能迭代
✅ RESTful API 接口排查
✅ MySQL / Redis / Nginx 性能问题
✅ 长期远程兼职维护
可先从一次小问题开始:
✅ 线上报错排查
✅ 接口异常分析
✅ 慢查询与性能瓶颈定位
✅ 代码结构初步评估
✅ 部署环境与日志检查
如需咨询,请联系我,并注明:PHP 维护咨询。
联系方式:
Telegram:@shuijingwan
微信:13980074657
邮箱:shuijingwanwq@gmail.com

发表回复