diff --git a/catch/wechat/controller/Reply.php b/catch/wechat/controller/Reply.php index a73f2a2..ba25d90 100644 --- a/catch/wechat/controller/Reply.php +++ b/catch/wechat/controller/Reply.php @@ -24,23 +24,51 @@ class Reply extends CatchController $this->reply = $reply; } + /** + * 列表 + * + * @time 2020年06月29日 + * @param CatchRequest $request + * @return \think\response\Json + */ public function index(CatchRequest $request) { return CatchResponse::paginate($this->reply->getList()); } + /** + * 保存 + * + * @time 2020年06月29日 + * @param CatchRequest $request + * @return \think\response\Json + */ public function save(CatchRequest $request) { return CatchResponse::success($this->reply->storeBy($request->param())); } - public function update($id, CatchRequest $request) - { - return CatchResponse::success($this->reply->updateBy($id, $request->param())); - } - + /** + * 删除 + * + * @time 2020年06月29日 + * @param $id + * @return \think\response\Json + */ public function delete($id) { return CatchResponse::success($this->reply->deleteBy($id)); } + + /** + * 禁用启用 + * + * @time 2020年06月29日 + * @param $id + * @return \think\response\Json + */ + public function disOrEnable($id) + { + return CatchResponse::success($this->reply->disOrEnable($id)); + } } \ No newline at end of file diff --git a/catch/wechat/repository/WechatReplyRepository.php b/catch/wechat/repository/WechatReplyRepository.php index 85a1f5a..94475fc 100644 --- a/catch/wechat/repository/WechatReplyRepository.php +++ b/catch/wechat/repository/WechatReplyRepository.php @@ -12,6 +12,7 @@ namespace catchAdmin\wechat\repository; use catchAdmin\wechat\model\WechatReply; use catcher\base\CatchRepository; +use catcher\library\WeChat; class WechatReplyRepository extends CatchRepository { @@ -29,6 +30,40 @@ class WechatReplyRepository extends CatchRepository public function storeBy(array $data) { + $material = WeChat::officialAccount()->material; + + $mediaUrl = $this->getLocalPath($data['media_url'] ?? ''); + $imageUrl = $this->getLocalPath($data['imageUrl'] ?? ''); + + 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::storeBy($data); // TODO: Change the autogenerated stub } + + /** + * 获取本地地址 + * + * @time 2020年06月29日 + * @param $url + * @return string + */ + protected function getLocalPath($url) + { + return $url ? '.' . trim(str_replace(config('filesystem.disks.local.domain'), '', $url)) : ''; + } } \ No newline at end of file diff --git a/catch/wechat/route.php b/catch/wechat/route.php index e3e61ad..66be840 100644 --- a/catch/wechat/route.php +++ b/catch/wechat/route.php @@ -34,9 +34,12 @@ $router->group('wechat', function () use ($router){ }); // 微信回复管理 $router->group('official/reply', function () use ($router){ - $router->resource('', '\catchAdmin\wechat\controller\Reply'); + $router->get('', '\catchAdmin\wechat\controller\Reply@index'); + $router->post('', '\catchAdmin\wechat\controller\Reply@save'); + $router->delete('', '\catchAdmin\wechat\controller\Reply@delete'); + $router->put('enable/', '\catchAdmin\wechat\controller\Reply@disOrEnable'); }); - // 微信回复管理 + // 微信上传 $router->group('official/upload', function () use ($router){ $router->post('/image', '\catchAdmin\wechat\controller\Upload@image'); $router->post('/file', '\catchAdmin\wechat\controller\Upload@file');