setMenu(); $this->model_id = $model_id = 20; $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']); $map['type'] ="news"; if(session('user_auth.group')!=999){ $map['uid'] = array('in',$this->agentUser(session('user_auth.uid'))); if(session('wxmpid')){ $map['wxmpid'] =session('wxmpid'); } } $list = $this->model->where($map)->order($order)->paginate($this->modelInfo['list_row']); $info = array(); foreach($list as $k=>$v){ $info[$k]=$v; //新增用户 $info[$k]['usernum']=$this->newUser($v['uid'],$v['id']); //新增关注 $info[$k]['attention']=$this->newUser($v['uid'],$v['id'],1); //充值金额 $info[$k]['pay']= db('order')->where('iscontrol',0)->where(array('status'=>1,'wxkeywordid'=>$v['id']))->sum('money'); } //获取授权用户组 $access = config('cartoon_access'); //获取当前用户组 $group = session('user_auth.group'); $data = array( 'grid' => $grid_list, 'list' => $info, 'page' => $list->render(), 'group' => $group, 'access' => $access, ); if ($this->modelInfo['template_list']) { $template = 'content/' . $this->modelInfo['template_list']; } else { $template = 'content/index'; } $this->assign($data); $this->setMeta($this->modelInfo['title'] . "列表"); return $this->fetch($template); } /** * 内容添加 * @author netlife <40150501@qq.com> */ public function add() { if (IS_POST) { $uid= session('user_auth.uid'); $wxmpid= session('wxmpid'); $appid = get_appid($uid,$wxmpid); $keys = db('wechat_keys')->where(['appid'=>$appid,'keys'=>$this->param['keys']])->find(); if($keys){ return $this->error("关键词已经存在!"); } $this->param['create_at'] = time(); $this->param['appid'] =$appid; $this->param['uid'] = $uid; $this->param['wxmpid'] = $wxmpid; $result = $this->model->save($this->param); if ($result) { return $this->success("添加成功!", url('admin/keys/index', array('model_id' =>20))); } else { return $this->error($this->model->getError(), url('admin/keys/index', array('model_id' =>20))); } } else { $info = array( 'model_id' => $this->modelInfo['id'], 'news_id' => 0, 'volumeid' =>0, ); $articles_covers = db('articles_covers')->where("status=1")->field('id,cover_url')->select(); $novel = db('novel')->where(array('status'=>1))->field('id,title')->select(); $data = array( 'info' => $info, 'novel' => $novel, 'fieldGroup' => $this->getField($this->modelInfo), ); $this->assign("covers",$articles_covers); $this->assign($data); $this->setMeta("添加" . $this->modelInfo['title']); return $this->fetch('keys/edit'); } } /** * 内容修改 * @author netlife <40150501@qq.com> */ public function edit($id) { if (IS_POST) { $result = db('WechatKeys')->update($this->param); if ($result !== false) { return $this->success("修改成功!", url('admin/keys/index')); } else { return $this->error($this->model->getError(), url('admin/keys/edit', array('model_id' => 20,'id'=>$id))); } } else { if (!$id) { return $this->error("非法操作!"); } $info = $this->model->find($id); $articles_covers = db('articles_covers')->where("status=1")->field('id,cover_url')->select(); if (!$info) { return $this->error($this->model->getError()); } $info['model_id'] = $this->modelInfo['id']; $novel = db('novel')->where(array('status'=>1))->field('id,title')->select(); $volume = array(); if($info['news_id']){ $volume = db('chapter')->where('articleid = '.$info['news_id'])->field('id ,chaptername as volumename')->select(); } $data = array( 'info' => $info, 'novel' => $novel, 'volume' => $volume, 'fieldGroup' => $this->getField($this->modelInfo), ); $template = 'keys/edit'; $this->assign($data); $this->assign("covers",$articles_covers); $this->setMeta("编辑" . $this->modelInfo['title']); return $this->fetch($template); } } /** * 内容删除 * @author netlife <40150501@qq.com> */ public function del() { $id = $this->getArrayParam('id'); $cartoonid = $this->request->param('cartoonid'); if (empty($id)) { return $this->error("非法操作!"); } $map['id'] = array('IN', $id); $result = $this->model->where($map)->delete(); if (false !== $result) { //更新漫画章节最新信息 $data = db('volume')->where(array('cartoonid'=>$cartoonid))->order('id desc')->limit(1)->find(); if($data){ db('cartoon')->where(array('id'=>$cartoonid))->update(array('volumes'=>$data['volumeorder'],'lastvolumeid'=>$data['id'],'lastvolume'=>$data['volumename'])); }else{ db('cartoon')->where(array('id'=>$cartoonid))->update(array('volumes'=>0,'lastvolumeid'=>0,'lastvolume'=>'')); } //记录行为 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 朱亚杰 */ 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 ajaxvolume() { $novel_id = $this->param['novel_id']; $result = db('chapter')->where('articleid = '.$novel_id." and status=1 and chaptertype=0")->field('id,chaptername as volumename')->order('chapterorder ASC')->limit('0,20')->select(); if($result){ echo json_encode(array('code'=>200,'content'=>$result)); }else{ echo json_encode(array('code'=>200)); } exit(); } /** * newUser [新增用户] * * @param type $attention [已关注] * @param type $pay [已付费] * * @return type **/ public function newUser($uid,$wxkeywordid,$attention=0,$pay=0) { $map['status'] = 1; $map['agentid'] = $uid; $map['wxkeywordid'] = $wxkeywordid; if($attention){ $map['is_attention'] = $attention; } if($pay){ $map['pay'] = array('egt',$pay); } $map['group'] =99; $sum = db('member')->where($map)->cache(true,600)->count(); return $sum; } /** * agentUser [各等级代理商用户] * * @return type **/ protected function agentUser($uid) { $member = db('member')->where('uid='.$uid)->find(); if($member['is_top']==1){ $map['s_uid'] = $uid; }/***elseif($member['is_top']==0 && empty($member['t_uid'])){ $map['t_uid'] = $uid; }***/else{ return $uid; } $map['status'] =1; $map['group'] =array('IN','3,4'); $daili = db('member')->where($map)->column('uid'); $daili[]=$uid; $agentid = implode(",",$daili); return $agentid; } }