1 line
2.9 KiB
PHP
Executable File
1 line
2.9 KiB
PHP
Executable File
<?php
|
|
namespace app\applet\controller\wechat;
|
|
|
|
use app\applet\controller\Controller;
|
|
use app\applet\model\WechatBatchSend as WechatBatchSendModel;
|
|
use app\applet\model\Wechat as WechatModel;
|
|
use think\facade\View;
|
|
|
|
/**
|
|
* 微信群发消息控制器
|
|
*/
|
|
class Send extends Controller
|
|
{
|
|
/**
|
|
* 首页
|
|
*/
|
|
public function index()
|
|
{
|
|
$wechat = WechatModel::detail($this->applet_id);
|
|
$model = new WechatBatchSendModel;
|
|
$list = $model->getList($this->applet_id);
|
|
return View::fetch('../../admin/view/wechat/send/index', compact('list','wechat'));
|
|
}
|
|
|
|
/**
|
|
* 添加
|
|
*/
|
|
public function add()
|
|
{
|
|
if ($this->request->isPost()) {
|
|
if(!$wechat = WechatModel::detail($this->applet_id)){
|
|
return $this->renderError('还未绑定公众号');
|
|
}
|
|
if($wechat['status']['value'] == 0){
|
|
return $this->renderError('还未绑定公众号');
|
|
}
|
|
$model = new WechatBatchSendModel;
|
|
// 新增记录
|
|
if ($model->add($this->postData('data'),$this->applet_id)) {
|
|
return $this->renderSuccess('添加成功,预览消息已发送到管理员微信', url('wechat.send/index'));
|
|
}
|
|
$error = $model->getError() ?: '添加失败';
|
|
return $this->renderError($error);
|
|
}
|
|
return redirect(url('wechat.send/index'));
|
|
}
|
|
|
|
/**
|
|
* 删除
|
|
*/
|
|
public function delete($id)
|
|
{
|
|
$model = WechatBatchSendModel::get($id);
|
|
if ($model->remove($this->applet_id)) {
|
|
return $this->renderSuccess('删除成功');
|
|
}
|
|
$error = $model->getError() ?: '删除失败';
|
|
return $this->renderError($error);
|
|
}
|
|
|
|
/**
|
|
* 群发
|
|
*/
|
|
public function status($id)
|
|
{
|
|
if(!$wechat = WechatModel::detail($this->applet_id)){
|
|
return $this->renderError('还未绑定公众号');
|
|
}
|
|
if($wechat['status']['value'] == 0){
|
|
return $this->renderError('还未绑定公众号');
|
|
}
|
|
$model = WechatBatchSendModel::get($id);
|
|
if ($model->send($this->applet_id)){
|
|
return $this->renderSuccess('群发成功');
|
|
}
|
|
$error = $model->getError() ?: '群发失败';
|
|
return $this->renderError($error);
|
|
}
|
|
|
|
/**
|
|
* 编辑
|
|
*/
|
|
public function edit($id)
|
|
{
|
|
$model = WechatBatchSendModel::get($id);
|
|
if ($this->request->isGet()) {
|
|
if($model){
|
|
return $this->renderSuccess('', '', compact('model'));
|
|
}
|
|
return $this->renderError('获取失败');
|
|
}
|
|
// 更新记录
|
|
if ($model->edit($this->postData('data'),$this->applet_id)) {
|
|
return $this->renderSuccess('更新成功', url('wechat.send/index'));
|
|
}
|
|
$error = $model->getError() ?: '更新失败';
|
|
return $this->renderError($error);
|
|
}
|
|
}
|
|
|