Пример #1
0
 /**
  * 修改页面 post
  * @author Hanxiang
  * @param PageService $pageService
  * @param ShakeAroundClient $shakeAroundClient
  * @return mixed
  */
 public function updatePost(PageService $pageService, ShakeAroundClient $shakeAroundClient)
 {
     $input = Input::all();
     $validator = Validator::make($input, ['wx-page-id' => 'required', 'txt-title' => 'required', 'txt-subtitle' => 'required', 'txt-url' => 'required', 'txt-comment' => '']);
     if ($validator->fails()) {
         return redirect('/admin/wxpages/update/' . $input['wx-page-id'])->with('result', false)->with('msg', '参数错误');
     }
     $wxPage = WeixinPage::find($input['wx-page-id']);
     if (!$wxPage) {
         return redirect('/admin/wxpages/update/' . $input['wx-page-id'])->with('result', false)->with('msg', '操作失败');
     }
     $pageArray = [];
     $pageArray['page_id'] = $wxPage->page_id;
     $pageArray['title'] = $input['txt-title'];
     $pageArray['description'] = $input['txt-subtitle'];
     $pageArray['url'] = $input['txt-url'];
     $pageArray['comment'] = $input['txt-comment'];
     if (Input::hasFIle('file-icon')) {
         $file = Input::file('file-icon');
         $ext = $file->getClientOriginalExtension();
         $filename = Uuid::v4(false) . ".{$ext}";
         $file->move(public_path("pageicons"), $filename);
         $allFilename = public_path("pageicons/") . $filename;
         try {
             $pageArray['icon_url'] = $pageService->converToUrlOnline($shakeAroundClient, 'local://' . $allFilename);
         } catch (\Exception $e) {
             return redirect('/admin/wxpages/update/' . $input['wx-page-id'])->with('result', false)->with('msg', '操作失败 ' . $e->getMessage() . $e->getCode());
         }
     } else {
         $pageArray['icon_url'] = $wxPage->icon_url;
     }
     $page = new Page($pageArray);
     $page->page_url = $page->url;
     unset($page->url);
     $wxMp = WeixinMp::find($wxPage->wx_mp_id);
     $appid = $wxMp->appid;
     $appsecret = $wxMp->appsecret;
     try {
         $pageService->updatePageOnline($shakeAroundClient, $page, $appid, $appsecret);
     } catch (\Exception $e) {
         return redirect('/admin/wxpages/update/' . $input['wx-page-id'])->with('result', false)->with('msg', '操作失败 ' . $e->getMessage() . $e->getCode());
     }
     unset($page->page_url);
     try {
         $pageService->update($wxPage, $page);
     } catch (\Exception $e) {
         return redirect('/admin/wxpages/update/' . $input['wx-page-id'])->with('result', false)->with('msg', '操作失败 ' . $e->getMessage());
     }
     return redirect('/admin/wxpages')->with('result', true)->with('msg', "操作成功");
 }
Пример #2
0
 /**
  * @param PageService $pageService
  * @param ShakeAroundClient $shakeAroundClient
  * @param null $pageId
  * @return string
  */
 public function update(PageService $pageService, ShakeAroundClient $shakeAroundClient, $pageId = null)
 {
     if (!$pageId) {
         return RestHelp::parametersIllegal("page_id is required");
     }
     $objPage = WeixinPage::find($pageId);
     if (!$objPage) {
         return RestHelp::encodeResult(23001, 'page not found');
     }
     $requestData = json_decode($this->inputData, true);
     $validator = Validator::make($requestData, ['title' => '', 'description' => '', 'icon_url' => '', 'url' => '', 'comment' => '']);
     if ($validator->fails()) {
         return RestHelp::parametersIllegal($validator->messages()->first());
     }
     $arrPage = array();
     $arrPage['page_id'] = $objPage->page_id;
     $arrPage['title'] = isset($requestData['title']) ? $requestData['title'] : $objPage->title;
     $arrPage['description'] = isset($requestData['description']) ? $requestData['description'] : $objPage->description;
     if (isset($requestData['icon_url'])) {
         try {
             $iconUrl = $pageService->converToUrlOnline($shakeAroundClient, $requestData['icon_url']);
         } catch (\Exception $e) {
             return RestHelp::encodeResult($e->getMessage(), $e->getCode());
         }
     }
     $arrPage['icon_url'] = isset($requestData['icon_url']) ? $iconUrl : $objPage->icon_url;
     $arrPage['url'] = isset($requestData['url']) ? $requestData['url'] : $objPage->url;
     $arrPage['comment'] = isset($requestData['comment']) ? $requestData['comment'] : $objPage->comment;
     $page = new Page($arrPage);
     $page->page_url = $page->url;
     try {
         $pageService->updatePageOnline($shakeAroundClient, $page);
     } catch (\Exception $e) {
         return RestHelp::encodeResult($e->getCode(), $e->getMessage());
     }
     unset($page->page_url);
     try {
         $pageService->update($objPage, $page);
     } catch (\Exception $e) {
         return RestHelp::encodeResult($e->getCode(), $e->getMessage());
     }
     return RestHelp::success(['page_id' => $objPage->id]);
 }