diff --git a/catch/wechat/controller/Reply.php b/catch/wechat/controller/Reply.php index ba25d90..07e1345 100644 --- a/catch/wechat/controller/Reply.php +++ b/catch/wechat/controller/Reply.php @@ -36,6 +36,18 @@ class Reply extends CatchController return CatchResponse::paginate($this->reply->getList()); } + /** + * 读取 + * + * @time 2020年09月13日 + * @param $id + * @return \think\response\Json + */ + public function read($id) + { + return CatchResponse::success($this->reply->findBy($id)); + } + /** * 保存 * @@ -48,6 +60,18 @@ class Reply extends CatchController return CatchResponse::success($this->reply->storeBy($request->param())); } + /** + * 更新 + * + * @time 2020年09月13日 + * @param $id + * @param CatchRequest $request + * @return \think\response\Json + */ + public function update($id, CatchRequest $request) + { + return CatchResponse::success($this->reply->updateBy($id, $request->param())); + } /** * 删除 * diff --git a/catch/wechat/repository/WechatReplyRepository.php b/catch/wechat/repository/WechatReplyRepository.php index 4f74ed0..6f122ab 100644 --- a/catch/wechat/repository/WechatReplyRepository.php +++ b/catch/wechat/repository/WechatReplyRepository.php @@ -28,6 +28,13 @@ class WechatReplyRepository extends CatchRepository return $this->reply; } + /** + * 存储 + * + * @time 2020年09月13日 + * @param array $data + * @return mixed + */ public function storeBy(array $data) { $material = WeChat::officialAccount()->material; @@ -55,6 +62,41 @@ class WechatReplyRepository extends CatchRepository return parent::storeBy($data); // TODO: Change the autogenerated stub } + /** + * 更新 + * + * @time 2020年09月13日 + * @param int $id + * @param array $data + * @return mixed + */ + public function updateBy(int $id, array $data) + { + $material = WeChat::officialAccount()->material; + + $mediaUrl = $this->getLocalPath($data['media_url'] ?? ''); + $imageUrl = $this->getLocalPath($data['image_url'] ?? ''); + + if ($imageUrl) { + // 音乐 + if ($data['type'] == WechatReply::MUSIC) { + $data['media_id'] = $material->uploadThumb($imageUrl)['media_id']; + } else { + // $data['media_id'] = $material->uploadImage($imageUrl)['media_id']; + } + } + // 语音 + if ($data['type'] == WechatReply::VOICE) { + $data['media_id'] = $material->uploadVoice($mediaUrl)['media_id']; + } + // 视频 + if ($data['type'] == WechatReply::VIDEO) { + $data['media_id'] = $material->uploadVideo($mediaUrl, $data['title'], $data['content'])['media_id']; + } + + return parent::updateBy($id, $data); // TODO: Change the autogenerated stub + } + /** * 获取本地地址 * diff --git a/catch/wechat/route.php b/catch/wechat/route.php index 45770d4..86fd556 100644 --- a/catch/wechat/route.php +++ b/catch/wechat/route.php @@ -34,9 +34,7 @@ $router->group('wechat', function () use ($router){ }); // 微信回复管理 $router->group('official/reply', function () use ($router){ - $router->get('', '\catchAdmin\wechat\controller\Reply@index'); - $router->post('', '\catchAdmin\wechat\controller\Reply@save'); - $router->delete('', '\catchAdmin\wechat\controller\Reply@delete'); + $router->resource('', '\catchAdmin\wechat\controller\Reply'); $router->put('enable/', '\catchAdmin\wechat\controller\Reply@disOrEnable'); }); // 微信上传