完善回复功能
This commit is contained in:
parent
655541210a
commit
57d26f8003
@ -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));
|
||||
}
|
||||
}
|
@ -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)) : '';
|
||||
}
|
||||
}
|
@ -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('<id>', '\catchAdmin\wechat\controller\Reply@delete');
|
||||
$router->put('enable/<id>', '\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');
|
||||
|
Loading…
x
Reference in New Issue
Block a user