get($key); if ($json == -1){ return null; } if ($json) { $data = json_decode($json, true); if (is_array($data) && !array_key_exists('state', $data)) { $data['state'] = 1; } $data = $idx ? $data['guide_chapter_idx'] : $data; } else { $db_data = $this->where('id=' . $referral_id)->find(); if(!empty($db_data)){ $db_data = $db_data->toArray(); $json = json_encode($db_data,JSON_UNESCAPED_UNICODE); $redis->setex($key, 86400, $json); $data = $idx ? $db_data['guide_chapter_idx'] : $db_data; }else{ $data = -1; $redis->setex($key, 86400, $data); $data = null; } } return $data; } public function getWxTypeList() { return ['1' => '已认证', '2' => '未认证']; } public function getTypeList() { return ['1' => '阅读页推广', '2' => '首页推广']; } public function getGuideSexList() { return ['1' => '男频', '2' => '女频']; } public function getWxTypeTextAttr($value, $data) { $value = $value ? $value : $data['wx_type']; $list = $this->getWxTypeList(); return isset($list[$value]) ? $list[$value] : ''; } public function getTypeTextAttr($value, $data) { $value = $value ? $value : $data['type']; $list = $this->getTypeList(); return isset($list[$value]) ? $list[$value] : ''; } public function getPushList() { return ['0' => '外推', '1' => '内推']; } public function getPushTextAttr($value, $data) { $value = $value ? $value : $data['push']; $list = $this->getPushList(); return isset($list[$value]) ? $list[$value] : ''; } // 一对一关联 book表 public function book() { return $this->belongsTo('Book', 'book_id', 'id', [], 'LEFT')->setEagerlyType(0); } /** * @param $referralId * @return int|mixed * @throws \think\db\exception\DataNotFoundException * @throws \think\db\exception\ModelNotFoundException * @throws \think\exception\DbException */ public function getDaoFenChapterId($referralId) { $referral = $this->where('id', '=', $referralId)->find(); return $chapterId = $referral->guide_chapter_idx ?? 10; } /** * 检测VIP链接有效性 * @param $id * @return int */ public function checkVipReferralValid($id) { $state = 1; $key = 'RIV:'.$id; if (Redis::instance()->exists($key)) { $state = Redis::instance()->get($key); } else { $library = model("ReferralLibrary")->where('id', 'eq', $id)->find(); if ($library) { $referral = $this->getone($library['referral_id'], false); $state = $referral['state']; } else { $state = 0; } Redis::instance()->set($key, $state, 600); } return $state; } public function mkParamsForInsert(ReferralObject $oReferral) { return [ 'push' => $oReferral->push, 'manage_title_id' => $oReferral->manage_title_id, 'manage_cover_id' => $oReferral->manage_cover_id, 'manage_template_id' => $oReferral->manage_template_id, 'manage_preview_id' => $oReferral->manage_preview_id, 'book_id' => $oReferral->book_id, 'chapter_id' => $oReferral->chapter_id, 'chapter_name' => $oReferral->chapter_name, 'chapter_idx' => $oReferral->chapter_idx, 'guide_chapter_idx' => $oReferral->guide_chapter_idx, 'admin_id' => $oReferral->admin_id, 'name' => $oReferral->name, 'cost' => $oReferral->cost, 'wx_type' => $oReferral->wx_type, 'type' => $oReferral->type, 'source_url' => $oReferral->source_url, 'short_url_qq' => $oReferral->short_url_qq, 'short_url_weibo' => $oReferral->short_url_weibo, 'createtime' => $oReferral->createtime??time(), 'updatetime' => $oReferral->updatetime??time(), 'state' => $oReferral->state ?? 1, 'short_id' => $oReferral->short_id, 'guide_sex' => $oReferral->guide_sex, 'guide_idx' => $oReferral->guide_idx, 'guide_title' => $oReferral->guide_title, 'guide_image' => $oReferral->guide_image, 'utime' => $oReferral->utime, 'share_title' => $oReferral->share_title, 'share_image' => $oReferral->share_image, 'is_collect' => $oReferral->is_collect, ]; } public function mkParamsForUpdate(ReferralObject $oReferral) { return [ 'type' => $oReferral->type, 'wx_type' => $oReferral->wx_type, 'name' => $oReferral->name, 'push' => $oReferral->push, 'guide_chapter_idx' => $oReferral->guide_chapter_idx, 'chapter_id' => $oReferral->chapter_id, 'chapter_idx' => $oReferral->chapter_idx, 'chapter_name' => $oReferral->chapter_name, 'book_id' => $oReferral->book_id, 'share_title' => $oReferral->share_title, 'share_image' => $oReferral->share_image, 'updatetime' => time(), ]; } }