461 lines
12 KiB
PHP
461 lines
12 KiB
PHP
<?php
|
||
// +----------------------------------------------------------------------
|
||
// | 小说系统 [ WE CAN DO IT JUST THINK IT ]
|
||
// +----------------------------------------------------------------------
|
||
|
||
namespace app\admin\controller;
|
||
use app\common\controller\Admin;
|
||
use think\Cache;
|
||
|
||
class Wxopenaccount extends Admin {
|
||
|
||
public function _initialize() {
|
||
parent::_initialize();
|
||
//$this->getContentMenu();
|
||
//$this->model_id = $model_id = $this->request->param('model_id');
|
||
$this->model_id = $model_id =66;
|
||
$list = db('Model')->column('*', 'id');
|
||
|
||
if (empty($list[$model_id])) {
|
||
return $this->error("无此模型!");
|
||
} else {
|
||
$this->modelInfo = $list[$model_id];
|
||
$this->model = M($this->modelInfo['name']);
|
||
}
|
||
|
||
$this->assign('model_id', $model_id);
|
||
$this->assign('model_list', $list);
|
||
}
|
||
|
||
/**
|
||
* 内容列表
|
||
* @return [html] [页面内容]
|
||
* @author netlife <40150501@qq.com>
|
||
*/
|
||
public function index() {
|
||
if ($this->modelInfo['list_grid'] == '') {
|
||
return $this->error("列表定义不正确!", url('admin/model/edit', array('id' => $this->modelInfo['id'])));
|
||
}
|
||
$grid_list = get_grid_list($this->modelInfo['list_grid']);
|
||
|
||
// 关键字搜索
|
||
$search_key =$this->modelInfo['search_key']?$this->modelInfo['search_key']:'title';
|
||
|
||
$order = "id desc";
|
||
$map = $this->buildMap($search_key);
|
||
$field = array_filter($grid_list['fields']);
|
||
|
||
$list = $this->model->where($map)->order($order)->paginate($this->modelInfo['list_row']);
|
||
|
||
$data = array(
|
||
'grid' => $grid_list,
|
||
'list' => $list,
|
||
'page' => $list->render(),
|
||
);
|
||
|
||
|
||
$this->assign($data);
|
||
$this->setMeta($this->modelInfo['title'] . "列表");
|
||
return $this->fetch();
|
||
}
|
||
|
||
// 微信回復設置
|
||
public function push(){
|
||
$id = input('id');
|
||
$content = input('content');
|
||
if($content){
|
||
$is = db('wxreply_message')->where('wxid',$id)->value('id');
|
||
if($is){
|
||
$res = db('wxreply_message')->where('wxid',$id)->update(array(
|
||
'content'=>$content,
|
||
'addtime'=>time()
|
||
));
|
||
}else{
|
||
$res = db('wxreply_message')->where('wxid',$id)->insert(array(
|
||
'content'=>$content,
|
||
'addtime'=>time(),
|
||
'wxid'=>$id
|
||
));
|
||
}
|
||
if($res){
|
||
exit(json_encode(array('status'=>1,'reg'=>'保存成功')));
|
||
}else{
|
||
exit(json_encode(array('status'=>2,'reg'=>'错误')));
|
||
}
|
||
}else{
|
||
$data = array(
|
||
'id' => $id,
|
||
);
|
||
$this->assign($data);
|
||
$this->setMeta('回复设置');
|
||
return $this->fetch();
|
||
}
|
||
}
|
||
|
||
/**
|
||
* 内容添加
|
||
* @author netlife <40150501@qq.com>
|
||
*/
|
||
public function add() {
|
||
if (IS_POST) {
|
||
$result = $this->model->save($this->param);
|
||
if ($result) {
|
||
//记录行为
|
||
action_log('add_content', 'content', $result, session('user_auth.uid'));
|
||
return $this->success("添加成功!", url('admin/wxopenaccount/index', array('model_id' => $this->modelInfo['id'])));
|
||
} else {
|
||
return $this->error($this->model->getError(), url('admin/wxopenaccount/add', array('model_id' => $this->modelInfo['id'])));
|
||
}
|
||
} else {
|
||
|
||
$info = array(
|
||
'model_id' => $this->modelInfo['id'],
|
||
);
|
||
$data = array(
|
||
'info' => $info,
|
||
'fieldGroup' => $this->getField($this->modelInfo),
|
||
);
|
||
|
||
if ($this->modelInfo['template_add']) {
|
||
$template = 'content/' . $this->modelInfo['template_add'];
|
||
} else {
|
||
$template = 'public/nostyleedit';
|
||
}
|
||
$this->assign($data);
|
||
$this->setMeta("添加" . $this->modelInfo['title']);
|
||
return $this->fetch($template);
|
||
}
|
||
}
|
||
|
||
/**
|
||
* 内容修改
|
||
* @author netlife <40150501@qq.com>
|
||
*/
|
||
public function edit($id) {
|
||
if (IS_POST) {
|
||
$result = $this->model->save($this->param, array('id'=> $id));
|
||
if ($result !== false) {
|
||
//记录行为
|
||
action_log('update_content', 'content', $result, session('user_auth.uid'));
|
||
return $this->success("更新成功!", url('admin/wxopenaccount/index', array('model_id' => $this->modelInfo['id'])));
|
||
} else {
|
||
return $this->error($this->model->getError(), url('admin/wxopenaccount/edit', array('model_id' => $this->modelInfo['id'], 'id' => $id)));
|
||
}
|
||
} else {
|
||
if (!$id) {
|
||
return $this->error("非法操作!");
|
||
}
|
||
$info = $this->model->find($id);
|
||
if (!$info) {
|
||
return $this->error($this->model->getError());
|
||
}
|
||
$info['model_id'] = $this->modelInfo['id'];
|
||
$data = array(
|
||
'info' => $info,
|
||
'fieldGroup' => $this->getField($this->modelInfo),
|
||
);
|
||
|
||
if ($this->modelInfo['template_edit']) {
|
||
$template = 'content/' . $this->modelInfo['template_edit'];
|
||
} else {
|
||
$template = 'public/nostyleedit';
|
||
}
|
||
$this->assign($data);
|
||
$this->setMeta("编辑" . $this->modelInfo['title']);
|
||
return $this->fetch($template);
|
||
}
|
||
}
|
||
|
||
|
||
|
||
/**
|
||
* 内容删除
|
||
* @author netlife <40150501@qq.com>
|
||
*/
|
||
public function del() {
|
||
$id = $this->getArrayParam('id');
|
||
if (empty($id)) {
|
||
return $this->error("非法操作!");
|
||
}
|
||
|
||
$map['id'] = array('IN', $id);
|
||
$result = $this->model->where($map)->delete();
|
||
|
||
if (false !== $result) {
|
||
//记录行为
|
||
action_log('delete_content', 'content', $result, session('user_auth.uid'));
|
||
return $this->success("删除成功!");
|
||
} else {
|
||
return $this->error("删除失败!");
|
||
}
|
||
}
|
||
|
||
/**
|
||
* 设置状态
|
||
* @author netlife <40150501@qq.com>
|
||
*/
|
||
public function status($id, $status) {
|
||
$map['id'] = $id;
|
||
$result = $this->model->where($map)->setField('status', $status);
|
||
if (false !== $result) {
|
||
return $this->success("操作成功!");
|
||
} else {
|
||
return $this->error("操作失败!!");
|
||
}
|
||
}
|
||
|
||
/**
|
||
* 设置置顶
|
||
* @author netlife <40150501@qq.com>
|
||
*/
|
||
public function settop($id, $is_top) {
|
||
$map['id'] = $id;
|
||
$result = $this->model->where($map)->setField('is_top', $is_top);
|
||
if (false !== $result) {
|
||
return $this->success("操作成功!");
|
||
} else {
|
||
return $this->error("操作失败!!");
|
||
}
|
||
}
|
||
|
||
/**
|
||
* 获取字段信息
|
||
* @return array 字段数组
|
||
* @author netlife <40150501@qq.com>
|
||
*/
|
||
protected function getField() {
|
||
$field_group = parse_config_attr($this->modelInfo['attribute_group']);
|
||
|
||
$map['model_id'] = $this->modelInfo['id'];
|
||
if ($this->request->action() == 'add') {
|
||
$map['is_show'] = array('in', array('1', '2'));
|
||
} elseif ($this->request->action() == 'edit') {
|
||
$map['is_show'] = array('in', array('1', '3'));
|
||
}
|
||
|
||
//获得数组的第一条数组
|
||
$rows = model('Attribute')->getFieldlist($map, 'id');
|
||
if (!empty($rows)) {
|
||
foreach ($rows as $key => $value) {
|
||
$list[$value['group_id']][] = $value;
|
||
}
|
||
foreach ($field_group as $key => $value) {
|
||
$fields[$value] = isset($list[$key]) ? $list[$key] : array();
|
||
}
|
||
}else{
|
||
$fields = array();
|
||
}
|
||
return $fields;
|
||
}
|
||
|
||
/**
|
||
* 创建搜索
|
||
* @return [array] [查询条件]
|
||
*/
|
||
protected function buildMap($search_key) {
|
||
$map = array();
|
||
$data = $this->request->param();
|
||
foreach ($data as $key => $value) {
|
||
if ($value) {
|
||
if ($key == 'keyword') {
|
||
$map[$search_key] = array("LIKE", "%$value%");
|
||
} elseif ($key == 'category') {
|
||
$map['category_id'] = $value;
|
||
} elseif ($key == 'create_time') {
|
||
$map['create_time'] = array('BETWEEN', array(strtotime($value[0]), strtotime($value[1])));
|
||
} else {
|
||
$map[$key] = $value;
|
||
}
|
||
}
|
||
}
|
||
|
||
if (isset($map['page'])) {
|
||
unset($map['page']);
|
||
}
|
||
if (isset($map['model_id'])) {
|
||
unset($map['model_id']);
|
||
}
|
||
$this->assign($data);
|
||
return $map;
|
||
}
|
||
|
||
/**
|
||
* 检测需要动态判断的文档类目有关的权限
|
||
*
|
||
* @return boolean|null
|
||
* 返回true则表示当前访问有权限
|
||
* 返回false则表示当前访问无权限
|
||
* 返回null,则会进入checkRule根据节点授权判断权限
|
||
*
|
||
* @author 朱亚杰 <xcoolcc@gmail.com>
|
||
*/
|
||
protected function checkDynamic() {
|
||
$model_id = $this->request->param('model_id');
|
||
if (IS_ROOT) {
|
||
return true; //管理员允许访问任何页面
|
||
}
|
||
$models = model('AuthGroup')->getAuthModels(session('user_auth.uid'));
|
||
if (!$model_id) {
|
||
return false;
|
||
} elseif (in_array($model_id, $models)) {
|
||
//返回null继续判断操作权限
|
||
return null;
|
||
} else {
|
||
return false; //无权限
|
||
}
|
||
return false;
|
||
}
|
||
|
||
//客服消息管理
|
||
public function kefu(){
|
||
$data = input('');
|
||
if($data){
|
||
$imgurl = request()->file('imgurl');
|
||
if($imgurl){
|
||
$img = $imgurl->move(ROOT_PATH . 'public' . DS . 'uploads');
|
||
if($img){
|
||
$imageurl = config('web_site_url').'/public'.'/'.'uploads'.'/'.$img->getSaveName();
|
||
compressedImage(ROOT_PATH.'/public'.'/'.'uploads'.'/'.$img->getSaveName(), ROOT_PATH.'/public'.'/'.'uploads'.'/'.$img->getSaveName(), 40);
|
||
@unlink(parseurl($data['gurl']));
|
||
}else{
|
||
echo $file->getError();
|
||
}
|
||
}else{
|
||
$imageurl = $data['gurl'];
|
||
}
|
||
|
||
$arr = array(
|
||
'title'=>$data['title'],
|
||
'd'=>$data['d'],
|
||
'url'=>$data['url'],
|
||
'imgurl'=>$imageurl,
|
||
'wxlist'=>empty($data['wxlist'])?0:$data['wxlist']
|
||
);
|
||
$res = db('wxregpush')->where('id',3)->update($arr);
|
||
if($res){
|
||
exit(json_encode(array('status'=>1,'reg'=>'成功')));
|
||
}else{
|
||
exit(json_encode(array('status'=>2,'reg'=>'保存失败')));
|
||
}
|
||
|
||
}else{
|
||
$info = db('wxregpush')->where('id',3)->find();
|
||
//微信列表
|
||
$wxlist = db('wxopen_account')->field('id,title')->select();
|
||
if(empty($info['wxlist'])){
|
||
$checkArr = 0;
|
||
}else{
|
||
$checkArr = explode(',',$info['wxlist']);
|
||
}
|
||
$this->assign('checkArr',$checkArr);
|
||
$this->assign('wxlist',$wxlist);
|
||
$this->assign('info',$info);
|
||
$this->setMeta('客服消息管理');
|
||
return $this->fetch();
|
||
}
|
||
}
|
||
|
||
//单个图文测试推送
|
||
public function onepush(){
|
||
$id = input('id');
|
||
if($id){
|
||
import("Wechatpush.Wechatpush", EXTEND_PATH,'.php');
|
||
$wxid = db('member')->where('uid',$id)->value('wxid');
|
||
if($wxid!=0){
|
||
$wx_config = db('wxopen_account')->field('appid,appsecret')->where('id',$wxid)->find();
|
||
$appid = $wx_config['appid'];
|
||
$secret= $wx_config['appsecret'];
|
||
$wx = new \Wechatpush($appid,$secret);
|
||
$data = db('wxregpush')->where('id',3)->find();
|
||
$openid[] = db('member_userapi')->where('uid',$id)->value('wxmpid');
|
||
$wx->kefuImg($openid,$data['title'],$data['d'],$data['url'],$data['imgurl']);
|
||
exit(json_encode(array('status'=>1,'reg'=>'推送成功')));
|
||
}else{
|
||
exit(json_encode(array('status'=>2,'reg'=>'未绑定公众号')));
|
||
}
|
||
}
|
||
}
|
||
|
||
// 群发客服消息
|
||
public function allpush(){
|
||
$a = input('a');
|
||
if($a=='pushall'){
|
||
$ip = "http://127.0.0.1:9509";
|
||
$data = array('type'=>'all');
|
||
//通过TCP投掷任务
|
||
pushMessageToClient($ip,json_encode($data));
|
||
exit(json_encode(array('status'=>1,'reg'=>'开始推送')));
|
||
}
|
||
}
|
||
|
||
// 定时群发客服消息
|
||
public function timing(){
|
||
$data = input('');
|
||
if($data){
|
||
if(time()>$data['tasktime']){
|
||
exit(json_encode(array('status'=>2,'reg'=>'时间错误')));
|
||
}
|
||
$log = array(
|
||
'addtime'=>time(),
|
||
'tasktime'=>$data['tasktime'],
|
||
'type'=>1
|
||
);
|
||
$logId = db('timed_kefulist')->insertGetId($log);
|
||
$ip = "http://127.0.0.1:9509";
|
||
$pushInfo = db('wxregpush')->where('id',3)->find();
|
||
$pushtime = time();
|
||
Cache::store('redis')->set('pushInfo'.$pushtime,json_encode($pushInfo) , 864000);
|
||
|
||
$pushdata = array(
|
||
'type'=>$data['type'],
|
||
'tasktime'=>$data['tasktime'],
|
||
'logid'=>$logId,
|
||
'pushtime'=>$pushtime,
|
||
);
|
||
//通过TCP投掷任务
|
||
pushMessageToClient($ip,json_encode($pushdata));
|
||
$ptim = date("Y-m-d H:i:s",$data['tasktime']);
|
||
exit(json_encode(array('status'=>1,'reg'=>$ptim.' 开始推送')));
|
||
}
|
||
}
|
||
|
||
// 推文群发记录
|
||
public function recording(){
|
||
$data = db('ordinary_push_history')->order('id desc')->paginate(10);
|
||
$page = $data->render();
|
||
$this->assign('page', $page);
|
||
$this->assign('res',$data);
|
||
$this->setMeta("小说推送记录");
|
||
return $this->fetch();
|
||
}
|
||
|
||
// 定时推送记录
|
||
public function timedkefulist(){
|
||
$data = db('timed_kefulist')->order('id desc')->paginate(10);
|
||
$page = $data->render();
|
||
$this->assign('page', $page);
|
||
$this->assign('res',$data);
|
||
$this->setMeta("定时推送记录");
|
||
return $this->fetch();
|
||
}
|
||
|
||
// 删除定时推送
|
||
public function deltimedkefu($id){
|
||
$res = db('timed_kefulist')->where('id',$id)->delete();
|
||
if($res){
|
||
exit(json_encode(array('status'=>1,'reg'=>'成功')));
|
||
}else{
|
||
exit(json_encode(array('status'=>2,'reg'=>'失败')));
|
||
}
|
||
}
|
||
|
||
|
||
// 秒数转时间格式 $t = 秒数
|
||
public function timestr($t){
|
||
$seconds = $t;
|
||
$hours = intval($seconds/3600);
|
||
$time = $hours."小时".gmdate('i分钟s秒', $seconds);
|
||
return $time;
|
||
}
|
||
|
||
} |