完善回复功能

This commit is contained in:
JaguarJack 2020-06-29 22:04:40 +08:00
parent 655541210a
commit 57d26f8003
3 changed files with 73 additions and 7 deletions

View File

@ -24,23 +24,51 @@ class Reply extends CatchController
$this->reply = $reply; $this->reply = $reply;
} }
/**
* 列表
*
* @time 2020年06月29日
* @param CatchRequest $request
* @return \think\response\Json
*/
public function index(CatchRequest $request) public function index(CatchRequest $request)
{ {
return CatchResponse::paginate($this->reply->getList()); return CatchResponse::paginate($this->reply->getList());
} }
/**
* 保存
*
* @time 2020年06月29日
* @param CatchRequest $request
* @return \think\response\Json
*/
public function save(CatchRequest $request) public function save(CatchRequest $request)
{ {
return CatchResponse::success($this->reply->storeBy($request->param())); 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) public function delete($id)
{ {
return CatchResponse::success($this->reply->deleteBy($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));
}
} }

View File

@ -12,6 +12,7 @@ namespace catchAdmin\wechat\repository;
use catchAdmin\wechat\model\WechatReply; use catchAdmin\wechat\model\WechatReply;
use catcher\base\CatchRepository; use catcher\base\CatchRepository;
use catcher\library\WeChat;
class WechatReplyRepository extends CatchRepository class WechatReplyRepository extends CatchRepository
{ {
@ -29,6 +30,40 @@ class WechatReplyRepository extends CatchRepository
public function storeBy(array $data) 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 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)) : '';
}
} }

View File

@ -34,9 +34,12 @@ $router->group('wechat', function () use ($router){
}); });
// 微信回复管理 // 微信回复管理
$router->group('official/reply', 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('<id>', '\catchAdmin\wechat\controller\Reply@delete');
$router->put('enable/<id>', '\catchAdmin\wechat\controller\Reply@disOrEnable');
}); });
// 微信回复管理 // 微信上传
$router->group('official/upload', function () use ($router){ $router->group('official/upload', function () use ($router){
$router->post('/image', '\catchAdmin\wechat\controller\Upload@image'); $router->post('/image', '\catchAdmin\wechat\controller\Upload@image');
$router->post('/file', '\catchAdmin\wechat\controller\Upload@file'); $router->post('/file', '\catchAdmin\wechat\controller\Upload@file');