123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654 |
- <?php
- namespace app\admin\controller\referral;
- use app\admin\service\ExclusiveService;
- use app\common\controller\Backend;
- use app\common\library\Redis;
- use app\common\library\WeChatObject;
- use think\Config;
- use think\Exception;
- use app\main\constants\AdminConstants;
- /**
- * 小说中心
- * @icon fa fa-book
- */
- class Book extends Backend
- {
- /**
- * @var \app\common\model\Book
- */
- protected $model = null;
- /**
- * @var \app\common\model\BookCategory
- */
- protected $bookCategoryModel = null;
- protected $relationSearch = true;
- protected $searchFields = 'id,name';
- //Multi方法可批量修改的字段
- protected $multiFields = 'state';
- protected $modelValidate = true;
- protected $modelSceneValidate = true;
- public function _initialize()
- {
- parent::_initialize();
- $this->model = model('Book');
- $this->bookCategoryModel = model('BookCategory');
- $this->view->assign("stateList", $this->model->getStateList());
- $this->view->assign("sexList", $this->model->getSexList());
- $this->view->assign("billingTypeList", $this->model->getBillingTypeList());
- $this->view->assign("isFinishList", $this->model->getIsFinishList());
- }
- public function index()
- {
- //设置过滤方法
- $this->request->filter(['strip_tags']);
- if ($this->request->isAjax()) {
- //赛选标签条件
- //Log::write($_GET,'cctest');
- $whereTip = [];
- $whereSearch = false;
- $wordWhere = false;
- if(!empty($_GET)){
- if(array_key_exists('name',$_GET) && $_GET['name']){
- $name = $_GET['name'];
- $whereSearch = function ($query) use ($name) {
- $query->where('id', $name)
- ->whereOr('name', 'like', '%' . $name . '%')
- ->whereOr('keywords', 'like', '%' . $name . '%');
- };
- }
- if ($_GET) {
- foreach ($_GET as $k => $v) {
- if ($v === '') {
- continue;
- }
- if ($k == 'corner_mark') {
- if ($v == 'free') {
- $whereTip['free_stime'] = ['<=', time()];
- $whereTip['free_etime'] = ['>=', time()];
- } else {
- $whereTip['corner_mark'] = (string)$_GET[$k];
- }
- continue;
- } elseif ($k == 'state') {
- if ($v !== '') {
- $whereTip[$k] = $v;
- } else {
- $whereTip[$k] = ['neq', '0'];
- }
- continue;
- } elseif (in_array($k, ['is_finish', 'len', 'sex', 'book_category_id', 'state'])) {
- $whereTip[$k] = (string)$_GET[$k];
- } elseif ($k == 'idx') {
- $whereTip[$k] = ['between', $v];
- } elseif ($k == 'word_count') {
- $p = explode(',', $v);
- $wordWhere = "cast($k as UNSIGNED) between $p[0] and $p[1]";
- }
- }
- }
- }
- //Log::write($whereTip,'cctest');
- //如果发送的来源是Selectpage,则转发到Selectpage
- if ($this->request->request('pkey_name')) {
- return $this->selectpage();
- }
- list($where, $sort, $order, $offset, $limit) = $this->buildparams();
- $map = [];
- if($this->group>2) {
- $map['cansee'] = 1;
- }
- //获取独家书籍
- ExclusiveService::instance()->getExclusiveNotidsWithWhere($this->group, $this->auth->id,$map);
- $total = $this->model
- ->where($where)
- ->where($whereTip)
- ->where($whereSearch)
- ->where($wordWhere)
- ->where($map)
- ->order('book.idx desc,book.idxx desc')
- ->count();
- $list = $this->model
- ->where($where)
- ->where($whereTip)
- ->where($whereSearch)
- ->where($wordWhere)
- ->where($map)
- ->order('book.idx desc,book.idxx desc')
- ->limit($offset, $limit)
- ->select();
- if ($list) {
- foreach ($list as $k => $item) {
- $list[$k]['book_tags_text'] = $this->getBookTags($item['book_tags']);
- }
- }
- $result = array("total" => $total, "rows" => $list);
- return json($result);
- }
- $this->assignconfig('site',config('site'));
- $this->assign('filter', $this->searchFilter());
- $this->assignconfig('filter', $this->searchFilter());
- //dump($this->searchFilter());die;
- return $this->view->fetch();
- }
- public function getBookTags($book_tags_ids)
- {
- $html = '';
- if ($book_tags_ids) {
- $tag_arr = explode(',', $book_tags_ids);
- if ($tag_arr) {
- foreach ($tag_arr as $k => $item) {
- $tag_obj = model('BookTags')->getBookTagById($item);
- if ($tag_obj && $tag_obj['status'] == 'normal') {
- $html .= '<span class="tag_rb" style="background: ' . $tag_obj['color'] . '">' . $tag_obj['name'] . '</span>';
- }
- }
- }
- }
- return $html;
- }
- private function searchFilter()
- {
- $sex = [['id' => '', 'name' => '全部','active'=>true], ['id' => 1, 'name' => '男频'], ['id' => 2, 'name' => '女频']];
- $state = [['id' => '', 'name' => '全部','active'=>true], ['id' => 1, 'name' => '上架'], ['id' => -1, 'name' => '入库']];
- $isFinish = [['id' => '', 'name' => '全部','active'=>true], ['id' => 1, 'name' => '完结'], ['id' => 0, 'name' => '连载']];
- $idx = [['id' => '', 'name' => '全部','active'=>true], ['id' => '91,100', 'name' => '100-91'], ['id' => '81,90', 'name' => '90-81'], ['id' => '61,80', 'name' => '80-61'], ['id' => '0,60', 'name' => '60以下']];
- $len = [['id' => '', 'name' => '全部','active'=>true], ['id' => 1, 'name' => '长篇'], ['id' => 2, 'name' => '短篇']];
- $property = [['id' => '', 'name' => '全部','active'=>true], ['id' => 'exclusive', 'name' => '独家'], ['id' => 'hot', 'name' => '火热在推'], ['id' => 'new', 'name' => '新书'], ['id' => 'free', 'name' => '免费']];
- $word_count = [['id' => '', 'name' => '全部','active'=>true], ['id' => '0,300000', 'name' => '30万以下'], ['id' => '300000,500000', 'name' => '30万-50万'], ['id' => '500000,1000000', 'name' => '50万-100万'], ['id' => '1000000,5000000', 'name' => '100万-500万'], ['id' => '5000000,100000000', 'name' => '500万以上']];
- // 'hot', 'exclusive', 'new', ''
- $categoryAll = collection($this->bookCategoryModel
- ->where(['status' => 'normal'])
- ->order('sex', 'asc')
- ->order('weigh', 'desc')
- ->select())->toArray();
- $categoryGirl = collection($this->bookCategoryModel
- ->where(['status' => 'normal','sex'=>'2'])
- ->order('weigh', 'desc')
- ->select())->toArray();
- $categoryBoy = collection($this->bookCategoryModel
- ->where(['status' => 'normal','sex'=>'1'])
- ->order('weigh', 'desc')
- ->select())->toArray();
- array_unshift($categoryAll,['id'=>'','name'=>'全部','active'=>true,'sex'=>'-1']);
- array_unshift($categoryGirl,['id'=>'','name'=>'全部','active'=>true,'sex'=>'2']);
- array_unshift($categoryBoy,['id'=>'','name'=>'全部','active'=>true,'sex'=>'1']);
- $filter = ['sex' => $sex, 'is_finish' => $isFinish, 'category_all' => $categoryAll, 'category_boy' => $categoryBoy, 'category_girl' => $categoryGirl, 'idx' => $idx, 'len' => $len, 'property' => $property, 'state' => $state, 'word_count'=>$word_count];
- return $filter;
- }
- private function categorylist()
- {
- $list = $this->bookCategoryModel
- ->where(['status' => 'normal'])
- ->order('sex', 'asc')
- ->order('weigh', 'desc')
- ->select();
- return $list;
- }
- /**
- * 频道下拉列表
- */
- public function sexList()
- {
- $result = $this->model->getSexList();
- $searchlist = [];
- foreach ($result as $key => $value) {
- $searchlist[] = ['id' => $key, 'name' => $value];
- }
- $data = ['searchlist' => $searchlist];
- $this->success('', null, $data);
- }
- /**
- * 书籍信息
- */
- public function info()
- {
- $this->request->filter(['strip_tags']);
- if ($this->request->isAjax()) {
- try {
- $filter = $this->request->param('filter');
- $filter = json_decode($filter, true);
- if (is_array($filter) && isset($filter['id'])) {
- $id = $filter['id'];
- } else {
- $this->error('ajax参数错误,缺少id!');
- }
- $book = model('Book')::get($id);
- if($book['cansee']==0 && $this->group > 2)
- $this->error('数据错误');
- $offset = $this->request->get('offset', 0);
- $limit = $this->request->get('limit', 10);
- $page_num = ($offset/$limit)+1;
- $search = '';
- if (array_key_exists('chapter_name', $filter)) {
- $search = $filter['chapter_name'];
- }
- $data = model('Book')::searchChapterByName($id, $page_num, $limit, $search);
- if($data['code']){
- $this->error($data['msg']);
- }
- $chapters = $data['data']['data'];
- $chapter_ids = array_column($chapters, 'id');
- if ($chapter_ids) {
- $chapterList = model('chapter_uv_rate')
- ->where('channel_id', $this->auth->id)
- ->where('book_id', $id)
- ->whereIn('chapter_id', $chapter_ids)
- ->column('chapter_id,uv,uv_rate');
- if ($chapterList) {
- foreach ($chapters as $index => $chapter) {
- if (array_key_exists($chapter['id'], $chapterList)) {
- $chapters[$index]['uv'] = $chapterList[$chapter['id']]['uv'];
- $chapters[$index]['uv_rate'] = round($chapterList[$chapter['id']]['uv_rate'] * 100, 2);
- }
- }
- }
- }
- $result = array("total" => $data['data']['totalNum'], "rows" => $chapters, 'list'=>$chapters);
- return json($result);
- } catch (Exception $e) {
- $this->error('接口数据异常!');
- }
- }
- if($this->auth->agent_id || $this->group == 3){
- if(!model('AdminConfig')->checkWechatConfig($this->auth->id)){
- $this->error('请先授权微信服务号给本系统,正在跳转授权设置页面~', url('admin/config'));
- }
- }
- $id = input('id');
- $book = model('Book')::get($id);
- $price = $book['price']?$book['price']:Config::get("site.book_chapter_price");
- $this->assignconfig("price",$price);
- if($book['cansee']==0 && $this->group > 2)
- $this->error('数据错误');
- $book['category_name'] = model('Book')->getCategoryName($book['book_category_id']);
-
- // $config= $this->getConfig();
- $this->assignconfig('site',config('site'));
- $this->assignconfig('agent_distribute',false);
- if($this->group == 3 || $this->auth->agent_id ){
- $this->assignconfig('agent_distribute',true);
- }
- $this->assign('book', $book);
- $this->assignconfig('bookinfo',$book);
- $this->assignconfig('book_id', $id);
- $guide_switch = false;
- $guideResult = model('Guide')->where(['admin_id' => $this->auth->id, 'book_id' => $id])->find();
- if (isset($guideResult['chapter_idx'])) {
- $guide_chapter_idx = $guideResult['chapter_idx'];
- } else {
- $adminConfigResult = model('AdminConfig')->where(['admin_id' => $this->auth->channel_id])->find();
- if (isset($adminConfigResult['book_guide_chapter_idx'])) {
- $guide_chapter_idx = $adminConfigResult['book_guide_chapter_idx'];
- } else {
- $guide_chapter_idx = config('site.book_guide_chapter_idx');
- }
- }
- if($this->auth->agent_id){
- $channel_id = $this->auth->agent_id;
- }else{
- $channel_id = $this->auth->channel_id;
- }
- $adminConfigResult = model('AdminConfig')->where(['admin_id' => $channel_id])->find();
- if(isset($adminConfigResult['guide_domain']) && $adminConfigResult['guide_domain']){
- $guide_switch = true;
- }
- $showAllSelect = 1;
- if (in_array($this->group, [7,8])) {
- $showAllSelect = 0;
- }
- $not_ban = 0;
- //独家书籍
- if (in_array($this->group, [3, 4])) {
- $exclusive_books = model('Book')->getExclusiveBookIds($channel_id);
- if (in_array($id, $exclusive_books)) {
- $not_ban = 1;
- }
- }
- if(in_array($this->group, [7, 8])){
- $bind_channel_ids = model('Exclusive')->getAllBindChannelIds();
- if(!empty($bind_channel_ids)) {
- $adminIds = model("VipAdminBind")->getChannelIds($this->auth->id);//获取服务号id
- if(empty(array_intersect($bind_channel_ids,$adminIds)) && empty(array_intersect($adminIds,$bind_channel_ids))){
- $exclusive = model('Book')->getExclusiveBookIds($this->auth->id);
- if(!empty($exclusive) && in_array($id,$exclusive)){
- $not_ban = 1;
- }
- }else{
- $exclusive = model('Book')->getVipExclusiveBookIds($adminIds);
- if(!empty($exclusive) && in_array($id,$exclusive)){
- $not_ban = 1;
- }
- }
- }
- }
- $this->assignconfig('not_ban',$not_ban);
- $this->assignconfig('guide_switch',$guide_switch);
- $this->assignconfig('show_all_select',$showAllSelect);
- $this->assignconfig('guide_chapter_idx', $guide_chapter_idx); //关注章节序
- $this->assignconfig('free_chapter_num', $book['free_chapter_num'] >0 ? $book['free_chapter_num'] : config('site.book_free_chapter_num')); //关注章节序
- return $this->view->fetch();
- }
- /**
- * 获取章节内容
- */
- public function chapter()
- {
- $book_id = input('book_id');
- if ($this->group != AdminConstants::ADMIN_GROUP_ID_SUPER_ADMIN && $this->group != AdminConstants::ADMIN_GROUP_ID_OPERATOR) {
- $bind_channel_ids = model('Exclusive')->getAllBindChannelIds();
- if(!empty($bind_channel_ids)) {
- if($this->group == AdminConstants::ADMIN_GROUP_ID_VIP || $this->group == AdminConstants::ADMIN_GROUP_ID_VIP_OPERATOR){
- $adminIds = model("VipAdminBind")->getChannelIds($this->auth->id);//获取服务号id
- if(empty(array_intersect($bind_channel_ids,$adminIds)) && empty(array_intersect($adminIds,$bind_channel_ids))){
- $exclusive = model('Book')->getExclusiveBookIds($this->auth->id);
- if(!empty($exclusive) && in_array($book_id,$exclusive)){
- $this->error('此书籍为渠道独家书籍');
- }
- }else{
- $exclusive = model('Book')->getVipExclusiveBookIds($adminIds);
- if(!empty($exclusive) && in_array($book_id,$exclusive)){
- $this->error('此书籍为渠道独家书籍');
- }
- }
- }else{
- $exclusive = model('Book')->getExclusiveBookIds($this->auth->id);
- if(!empty($exclusive) && in_array($book_id,$exclusive)){
- $this->error('此书籍为渠道独家书籍');
- }
- }
- }
- }
- $chapter_id = input('chapter_id');
- $data = model('Book')::getChapterInfo($book_id,$chapter_id);
- if($data['code']){
- $this->error($data['msg']);
- }
- if ($this->request->isAjax()) {
- return json($data);
- }
- $this->assign('data', $data);
- return $this->view->fetch();
- }
- public function createQRCode(){
- $params = $this->request->param();
- $book_id = $this->request->get('book_id');
- $chapter_id = $this->request->get('chapter_id');
- if(isset($params['essay_id'])){
- /**
- * 图片序号的生成格式
- */
- $imgSize = [
- 1 => [
- 'size' => 143, //二维码宽度
- 'x' => 376, //水印x
- 'y' => 35 //水印y
- ],
- 2 => [
- 'size' => 147, //二维码宽度
- 'x' => 374, //水印x
- 'y' => 33 //水印y
- ],
- 3 => [
- 'size' => 135, //二维码宽度
- 'x' => 372, //水印x
- 'y' => 46 //水印y
- ],
- 4 => [
- 'size' => 179, //二维码宽度
- 'x' => 356, //水印x
- 'y' => 15 //水印y
- ],
- 5 => [
- 'size' => 179, //二维码宽度
- 'x' => 356, //水印x
- 'y' => 15 //水印y
- ],
- 6 => [
- 'size' => 179, //二维码宽度
- 'x' => 356, //水印x
- 'y' => 15 //水印y
- ]
- ];
- $qrcodeRes = model('CustomQrcode')->where(['admin_id'=>$this->auth->id,'book_id'=>$params['book_id'],'chapter_id'=>$params['chapter_id']])->select();
- $imgList = array();
- if($qrcodeRes){
- foreach($qrcodeRes as $val){
- if(strpos($val['url'], 'mp.weixin.qq.com') === false){
- $tmp = explode('_',basename($val['url'],".png"));
- $imgList[$tmp[2]] = $val['url'];
- }else{
- $imgList[0] = $val['url'];
- }
- }
- }
- if(!isset($imgList[$params['essay_id']])){
- //获取微信永久二维码
- $data['index'] = 1;
- $last_index = model('CustomQrcode')->field('index')->where(['admin_id'=>$this->auth->id])->order('`index` desc')->find();
- if($last_index){
- if($last_index['index'] >= 100000){
- $this->error(__('WeChat QRCode Max 100000'));
- }
- $data['index'] = ($last_index['index'] + 1);
- }
- $channel_id = $this->auth->agent_id ? $this->auth->agent_id : $this->auth->channel_id;
- $adminConfig = model('AdminConfig')->getAdminInfoAll($channel_id);
- $wechat = new WeChatObject($adminConfig);
- $officialAccount = $wechat->getOfficialAccount();
- $result = $officialAccount->qrcode->forever($data['index']);
- if(empty($result) || isset($result['errcode'])){
- $this->error(__('Get WeChat QRCode Error'));
- }
- $data['url'] = $officialAccount->qrcode->url($result['ticket']);
- $res = null;
- if($params['essay_id'] != 0){
- $image_1 = imagecreatefrompng(ROOT_PATH . "public/assets/img/essay/qrcode_{$params['essay_id']}.png"); //底图
- // $image_2 = imagecreatefromjpeg($data['url']); //二维码图片
- $image_2 = $this->createThumbnail($data['url'],$imgSize[$params['essay_id']]['size'],$imgSize[$params['essay_id']]['size']);
- imagecopymerge($image_1, $image_2, $imgSize[$params['essay_id']]['x'], $imgSize[$params['essay_id']]['y'], 0, 0, imagesx($image_2),
- imagesy($image_2), 100);
- $imgPath = ROOT_PATH . 'public/uploads/qrcode/'; //图片保存路径
- if (!file_exists($imgPath)) { //创建文件夹
- mkdir($imgPath, 0700, true);
- clearstatcache();
- }
- $imgPath = $imgPath .$book_id.'_'.$chapter_id .'_' . $params['essay_id'] .'_'.$this->auth->id.'_'.time().'.png';
- $imgUrl = cdnurl("/uploads/qrcode/" . $book_id .'_'.$chapter_id . '_' . $params['essay_id'] .'_'.$this->auth->id.'_'.time().'.png');
- $res = imagepng($image_1, $imgPath);
- $data['url'] = $res ? $imgUrl : $data['url'];
- imagedestroy($image_1);
- imagedestroy($image_2);
- }
- $data['type'] = 2;
- $data['title'] = $params['book_name'].'-'.$params['chapter_name'].'-模板'.$params['essay_id'];
- $data['admin_id'] = $this->auth->id;
- $data['book_id'] = $params['book_id'];
- $data['book_name'] = $params['book_name'];
- $data['chapter_id'] = $params['chapter_id'];
- if(model('CustomQrcode')->allowField(true)->save($data)){
- $this->success("关注二维码生成成功");
- }else{
- $this->error("生成失败");
- }
- }else{
- $this->success("关注二维码生成成功");
- }
- }else{
- if(!$book_id || !$chapter_id){
- $this->error('参数错误!');
- }
- $qrcodeRes = model('CustomQrcode')->where(['admin_id'=>$this->auth->id,'book_id'=>$params['book_id'],'chapter_id'=>$params['chapter_id']])->select();
- $imgList = array();
- if($qrcodeRes){
- foreach($qrcodeRes as $val){
- if(strpos($val['url'], 'mp.weixin.qq.com') === false){
- $tmp = explode('_',basename($val['url'],".png"));
- $imgList[$tmp[2]] = $val['url'];
- }else{
- $imgList[0] = $val['url'];
- }
- }
- }
- $this->assign('imgList',$imgList);
- $this->assign('book_info', $params); //关注章节序
- return $this->view->fetch();
- }
- }
- /**
- * 生成保持原图纵横比的缩略图,支持.png .jpg .gif
- * 缩略图类型统一为.png格式
- * $srcFile 原图像文件名称
- * $toW 缩略图宽
- * $toH 缩略图高
- * @return bool
- */
- private function createThumbnail($srcFile, $toW, $toH)
- {
- $toW += 20;
- $toH += 20;
- $info = "";
- //返回含有4个单元的数组,0-宽,1-高,2-图像类型,3-宽高的文本描述。
- //失败返回false并产生警告。
- $data = getimagesize($srcFile, $info);
- if (!$data)
- return false;
- //将文件载入到资源变量im中
- switch ($data[2]) //1-GIF,2-JPG,3-PNG
- {
- case 1:
- if(!function_exists("imagecreatefromgif"))
- {
- echo "the GD can't support .gif, please use .jpeg or .png! <a href='javascript:history.back();'>back</a>";
- exit();
- }
- $im = imagecreatefromgif($srcFile);
- break;
- case 2:
- if(!function_exists("imagecreatefromjpeg"))
- {
- echo "the GD can't support .jpeg, please use other picture! <a href='javascript:history.back();'>back</a>";
- exit();
- }
- $im = imagecreatefromjpeg($srcFile);
- break;
- case 3:
- $im = imagecreatefrompng($srcFile);
- break;
- }
- //计算缩略图的宽高
- $srcW = imagesx($im);
- $srcH = imagesy($im);
- $toWH = $toW / $toH;
- $srcWH = $srcW / $srcH;
- if ($toWH <= $srcWH)
- {
- $ftoW = $toW;
- $ftoH = (int)($ftoW * ($srcH / $srcW));
- }
- else
- {
- $ftoH = $toH;
- $ftoW = (int)($ftoH * ($srcW / $srcH));
- }
- if (function_exists("imagecreatetruecolor"))
- {
- $ni = imagecreatetruecolor($ftoW, $ftoH); //新建一个真彩色图像
- if ($ni)
- {
- //重采样拷贝部分图像并调整大小 可保持较好的清晰度
- imagecopyresampled($ni, $im, 0, 0, 0, 0, $ftoW, $ftoH, $srcW, $srcH);
- }
- else
- {
- //拷贝部分图像并调整大小
- $ni = imagecreate($ftoW, $ftoH);
- imagecopyresized($ni, $im, 0, 0, 0, 0, $ftoW, $ftoH, $srcW, $srcH);
- }
- }
- else
- {
- $ni = imagecreate($ftoW, $ftoH);
- imagecopyresized($ni, $im, 0, 0, 0, 0, $ftoW, $ftoH, $srcW, $srcH);
- }
- ImageDestroy($im);
- return $ni;
- }
- /**
- * 设置关注章节
- */
- public function setGuideChapterIdx()
- {
- $book_id = $this->request->get('book_id');
- $chapter_idx = $this->request->get('chapter_idx');
- if (!$book_id || !$chapter_idx) {
- $this->error('参数错误!');
- }
- $where = [
- 'book_id' => $book_id,
- 'admin_id' => $this->auth->id
- ];
- $guideModel = model('Guide');
- $row = $guideModel::get($where);
- if ($row) {
- $row->chapter_idx = $chapter_idx;
- $res = $row->save();
- } else {
- $data = array_merge($where, ['chapter_idx' => $chapter_idx]);
- $res = model('Guide')->save($data);
- }
- if ($res) {
- $redis = Redis::instance();
- $key = 'GUIDE:' . $this->auth->id;
- $redis->del($key);
- $this->success('操作成功!', '', ['guide_chapter_idx' => $chapter_idx]);
- } else {
- $this->error('保存失败!');
- }
- }
- }
|