优化微信图文
This commit is contained in:
parent
16a19312a9
commit
051627547e
@ -51,7 +51,7 @@ class Graphic extends CatchController
|
|||||||
return CatchResponse::success($this->graphic->storeBy($request->param()));
|
return CatchResponse::success($this->graphic->storeBy($request->param()));
|
||||||
}
|
}
|
||||||
|
|
||||||
public function update($id, Request $request)
|
public function update($id, CatchRequest $request)
|
||||||
{
|
{
|
||||||
return CatchResponse::success($this->graphic->updateBy($id, $request->param()));
|
return CatchResponse::success($this->graphic->updateBy($id, $request->param()));
|
||||||
}
|
}
|
||||||
|
@ -111,24 +111,28 @@ class WechatGraphicRepository extends CatchRepository
|
|||||||
*/
|
*/
|
||||||
public function updateBy(int $id, array $data)
|
public function updateBy(int $id, array $data)
|
||||||
{
|
{
|
||||||
$articles = $data['articles'];
|
try {
|
||||||
$this->wechatGraphic->startTrans();
|
$this->wechatGraphic->startTrans();
|
||||||
$updateStatus = true;
|
if (!parent::deleteBy($id)) {
|
||||||
foreach ($articles as $article) {
|
throw new FailedException('更新失败');
|
||||||
$id = $article['id'];
|
|
||||||
unset($article['id']);
|
|
||||||
if ($this->wechatGraphic->where('id', $id)
|
|
||||||
->update($article) === false) {
|
|
||||||
$updateStatus = false;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!$updateStatus) {
|
if ($this->wechatGraphic->where('parent_id', $id)->find() && !$this->wechatGraphic->where('parent_id', $id)->delete()) {
|
||||||
$this->wechatGraphic->rollback();
|
|
||||||
throw new FailedException('更新失败');
|
throw new FailedException('更新失败');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
foreach ($data['articles'] as &$article) {
|
||||||
|
unset($article['id']);
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($this->storeBy($data) === false) {
|
||||||
|
throw new FailedException('更新失败');
|
||||||
|
}
|
||||||
|
} catch (\Exception $exception) {
|
||||||
|
$this->wechatGraphic->rollback();
|
||||||
|
throw new FailedException($exception->getMessage());
|
||||||
|
}
|
||||||
|
|
||||||
$this->wechatGraphic->commit();
|
$this->wechatGraphic->commit();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user