123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397 |
- <?php
- namespace app\admin\controller;
- use app\admin\service\ExclusiveService;
- use app\common\controller\Backend;
- use app\common\library\Redis;
- use app\main\constants\AdminConstants;
- use app\main\constants\BookConstants;
- use app\main\constants\CacheConstants;
- use app\main\constants\UcCacheConstants;
- use app\main\service\AdminService;
- use app\main\service\BookService;
- use think\Config;
- use think\db\Query;
- use think\Exception;
- /**
- * 头条落地页
- *
- * @icon fa fa-circle-o
- */
- class Uclandingpage extends Backend
- {
- /**
- * @var \app\admin\model\ToutiaoLandingPage
- */
- protected $model = null;
- protected $noNeedRight = ['tpl', 'editwx', 'callbacktime', 'autocompletebookname'];
- public function _initialize()
- {
- parent::_initialize();
- $this->model = model('UcLandingPage');
- $this->assignconfig('scheme', Config::get('site.scheme'));
- }
- /**
- * 默认生成的控制器所继承的父类中有index/add/edit/del/multi五个方法
- * 因此在当前控制器中可不用编写增删改查的代码,如果需要自己控制这部分逻辑
- * 需要将application/admin/library/traits/Backend.php中对应的方法复制到当前控制器,然后进行修改
- */
- /**
- * 查看
- */
- public function index()
- {
- //设置过滤方法
- $this->request->filter(['strip_tags']);
- if ($this->request->isAjax()) {
- //如果发送的来源是Selectpage,则转发到Selectpage
- if ($this->request->request('pkey_name')) {
- return $this->selectpage();
- }
- [$where, $sort, $order, $offset, $limit] = $this->buildparams('title');
- $total = $this->model
- ->where($where)
- ->where('admin_id', $this->auth->id)
- ->order($sort, $order)
- ->count();
- $list = $this->model
- ->where($where)
- ->where('admin_id', $this->auth->id)
- ->order($sort, $order)
- ->limit($offset, $limit)
- ->select();
- $book_ids = array_column($list, 'book_id');
- $books = BookService::instance()->getBookModel()->getBooksInfo($book_ids);
- foreach ($list as $index => $item) {
- if (array_key_exists($item['book_id'], $books)) {
- $list[$index]['book_name'] = $books[$item['book_id']]['name'];
- $payCount = (float)Redis::instance()->get(UcCacheConstants::getGuideWxPayCount($item['id']));
- $payMoney = (float)Redis::instance()->get(UcCacheConstants::getGuideWxPayMoney($item['id']));
- $new = (float)Redis::instance()->get(UcCacheConstants::getGuideWxNewCount($item['id']));
- $payDayCount = (float)Redis::instance()->get(UcCacheConstants::getGuideWxDayPayCount($item['id']));
- $payDayMoney = (float)Redis::instance()->get(UcCacheConstants::getGuideWxDayPayMoney($item['id']));
- $newDay = (float)Redis::instance()->get(UcCacheConstants::getGuideWxDayNewCount($item['id']));
- $list[$index]['new'] = $newDay . '/' . $new;
- $list[$index]['payCount'] = $payDayCount . '/' . $payCount;
- $list[$index]['payMoney'] = $payDayMoney . '/' . $payMoney;
- }
- }
- $result = array("total" => $total, "rows" => $list);
- return json($result);
- }
- $this->assignconfig('pay_url', getCurrentDomain($this->auth->id, '/index/user/ucpaytest'));
- return $this->view->fetch();
- }
- /**
- * 添加
- */
- public function add()
- {
- if ($this->request->isPost()) {
- $cacheKey = UcCacheConstants::getGuideWxSetting($this->auth->id);
- $data = Redis::instance()->hGetAll($cacheKey);
- if (empty($data)) {
- $this->error('请先配置微信号与随机码');
- }
- $params = $this->request->post("row/a");
- if($params['focus_status']==2){
- if(!isset($data['biz']) || empty($data['biz'])){
- $this->error('请先配置微信号biz码');
- }
- }
- if ($params) {
- /*
- * 已经弃用,如果为了兼容老版可取消注释
- foreach ($params as $k => &$v)
- {
- $v = is_array($v) ? implode(',', $v) : $v;
- }
- */
- if ($this->dataLimit) {
- $params[$this->dataLimitField] = $this->auth->id;
- }
- $params['admin_id'] = $this->auth->id;
- try {
- //是否采用模型验证
- if ($this->modelValidate) {
- $name = basename(str_replace('\\', '/', get_class($this->model)));
- $validate = is_bool($this->modelValidate) ? ($this->modelSceneValidate ? $name . '.add' : true) : $this->modelValidate;
- $this->model->validate($validate);
- }
- $params['createtime'] = $params['updatetime'] = time();
- $result = $this->model->allowField(true)->insertGetId($params);
- if ($result !== false) {
- $params['id'] = $result;
- $adminInfo = AdminService::instance()->getAdminConfigModel()->getAdminInfoAll($this->auth->id);
- $chapters = model('Book')::getHeadChapters($params['book_id'], $params['chapter_num']);
- $params['chapters'] = $chapters['data'];
- $params['admin'] = $adminInfo['json']['authorizer_info'];
- $params['appid'] = $adminInfo['appid'];
- if (!array_key_exists('head_img', $params['admin'])) {
- $params['admin']['head_img'] = asset('/img/avatar.png');
- }
- $params['admin']['admin_card'] = 'https://mp.weixin.qq.com/mp/getmasssendmsg?__biz='.$data['biz'].'#wechat_webview_type=1&wechat_redirect';
- $cdn_url = '';
- if (Config::get('site.cdnurl')) {
- $cdn_url = Config::get('site.cdnurl');
- }
- $params['company'] = $this->getTtSetting($params['domain']);
- $params['cdn_url'] = $cdn_url;
- $params['setting'] = $data;
- $this->assign($params);
- if($params['focus_status'] == 0){
- //点击关注
- $content = $this->fetch(APP_PATH . 'admin/view/uclandingpage/tpl.html');
- }elseif($params['focus_status'] == 1){
- // 长按复制关注
- $content = $this->fetch(APP_PATH . 'admin/view/uclandingpage/tpl_v2.html');
- }elseif($params['focus_status'] == 2){
- //朋友圈关注
- $content = $this->fetch(APP_PATH . 'admin/view/uclandingpage/tpl_v3.html');
- }
- //$content = $this->fetch(APP_PATH . 'admin/view/uclandingpage/tpl.html');
- @file_put_contents(ROOT_PATH . 'public/uploads/static/uc/' . $result . '.html', $content);
- $this->success();
- } else {
- $this->error($this->model->getError());
- }
- } catch (\think\exception\PDOException $e) {
- $this->error($e->getMessage());
- }
- }
- $this->error(__('Parameter %s can not be empty', ''));
- }
- $domain = [];
- $tt_url = Config::get('site.uc_url');
- if ($tt_url) {
- $list = explode(',', $tt_url);
- foreach ($list as $item) {
- $item_li = explode('/', $item);
- $domain[$item_li[0]] = $item_li[1];
- }
- }
- $this->view->assign('domain', $domain);
- return $this->view->fetch();
- }
- /**
- * 编辑
- */
- public function edit($ids = null)
- {
- $row = $this->model->get($ids);
- if (!$row) {
- $this->error(__('No Results were found'));
- }
- $adminIds = $this->getDataLimitAdminIds();
- if (is_array($adminIds)) {
- if (!in_array($row[$this->dataLimitField], $adminIds)) {
- $this->error(__('You have no permission'));
- }
- }
- $cacheKey = UcCacheConstants::getGuideWxSetting($this->auth->id);
- $data = Redis::instance()->hGetAll($cacheKey);
- if (empty($data)) {
- $this->error('请先配置微信号与随机码');
- }
- if($row['focus_status'] == 2){
- if(!isset($data['biz']) || empty($data['biz'])){
- $this->error('请先配置微信号biz码');
- }
- }
- if ($this->request->isPost()) {
- $params = $this->request->post("row/a");
- if ($params) {
- /*
- * 已经弃用,如果为了兼容老版可取消注释
- foreach ($params as $k => &$v)
- {
- $v = is_array($v) ? implode(',', $v) : $v;
- }
- */
- try {
- //是否采用模型验证
- if ($this->modelValidate) {
- $name = basename(str_replace('\\', '/', get_class($this->model)));
- $validate = is_bool($this->modelValidate) ? ($this->modelSceneValidate ? $name . '.edit' : true) : $this->modelValidate;
- $row->validate($validate);
- }
- $result = $row->allowField(true)->save($params);
- if ($result !== false) {
- $params = array_merge($row->getData(), $params);
- $params['id'] = $ids;
- $adminInfo = AdminService::instance()->getAdminConfigModel()->getAdminInfoAll($this->auth->id);
- $chapters = model('Book')::getHeadChapters($params['book_id'], $params['chapter_num']);
- $params['chapters'] = $chapters['data'];
- $params['admin'] = $adminInfo['json']['authorizer_info'];
- $params['appid'] = $adminInfo['appid'];
- if (!array_key_exists('head_img', $params['admin'])) {
- $params['admin']['head_img'] = asset('/img/avatar.png');
- }
- if($params['focus_status'] == 2){
- $params['admin']['admin_card'] = 'https://mp.weixin.qq.com/mp/getmasssendmsg?__biz='.$data['biz'].'#wechat_webview_type=1&wechat_redirect';
- }
- $cdn_url = '';
- if (Config::get('site.cdnurl')) {
- $cdn_url = Config::get('site.cdnurl');
- }
- $params['company'] = $this->getTtSetting($params['domain']);
- $params['cdn_url'] = $cdn_url;
- $params['setting'] = $data;
- $this->assign($params);
- if($params['focus_status'] == 0){
- //点击关注
- $content = $this->fetch(APP_PATH . 'admin/view/uclandingpage/tpl.html');
- }elseif($params['focus_status'] == 1){
- // 长按复制关注
- $content = $this->fetch(APP_PATH . 'admin/view/uclandingpage/tpl_v2.html');
- }elseif($params['focus_status'] == 2){
- //朋友圈关注
- $content = $this->fetch(APP_PATH . 'admin/view/uclandingpage/tpl_v3.html');
- }
- //$data = $this->fetch(APP_PATH . 'admin/view/uclandingpage/tpl.html');
- @file_put_contents(ROOT_PATH . 'public/uploads/static/uc/' . $ids . '.html', $content);
- $this->success();
- } else {
- $this->error($row->getError());
- }
- } catch (\think\exception\PDOException $e) {
- $this->error($e->getMessage());
- }
- }
- $this->error(__('Parameter %s can not be empty', ''));
- }
- $row['book_id'] = $row['book_id'] > 0 ? $row['book_id'] : '';
- $this->view->assign("row", $row);
- $domain = [];
- $tt_url = Config::get('site.uc_url');
- if ($tt_url) {
- $list = explode(',', $tt_url);
- foreach ($list as $item) {
- $item_li = explode('/', $item);
- $domain[$item_li[0]] = $item_li[1];
- }
- }
- $bnotin = [];
- ExclusiveService::instance()->getExclusiveNotidsWithoutWhere($this->group, $this->auth->id,$bnotin);
- $this->assignconfig('bnotin',$bnotin);
- $this->view->assign('domain', $domain);
- return $this->view->fetch();
- }
- /**
- * 删除
- */
- public function del($ids = "")
- {
- if ($ids) {
- $pk = $this->model->getPk();
- $adminIds = $this->getDataLimitAdminIds();
- if (is_array($adminIds)) {
- $count = $this->model->where($this->dataLimitField, 'in', $adminIds);
- }
- $list = $this->model->where($pk, 'in', $ids)->select();
- $count = 0;
- foreach ($list as $k => $v) {
- @unlink(ROOT_PATH . 'public/uploads/static/uc/' . $v['id'] . '.html');
- $count += $v->delete();
- }
- if ($count) {
- $this->success();
- } else {
- $this->error(__('No rows were deleted'));
- }
- }
- $this->error(__('Parameter %s can not be empty', 'ids'));
- }
- public function editwx()
- {
- $cacheKey = UcCacheConstants::getGuideWxSetting($this->auth->id);
- if ($this->request->isPost()) {
- Redis::instance()->hMSet($cacheKey, $this->request->post());
- $this->success();
- }
- $data = Redis::instance()->hGetAll($cacheKey);
- $data = array_merge(['gzh' => '', 'mask' => '', 'biz' => ''], $data);
- $this->assign($data);
- return $this->view->fetch();
- }
- public function callbacktime()
- {
- $adminConfig = AdminService::instance()->getAdminConfigModel()->getAdminInfoAll($this->auth->id);
- if ($this->request->isAjax()) {
- AdminService::instance()->getAdminConfigModel()->update($this->request->post(), ['admin_id' => $this->auth->id]);
- model('AdminConfig')->delAdminInfoAllCache($this->auth->id);
- $this->success();
- }
- $this->view->assign('admin', $adminConfig);
- $adminConfig['callback_time_uc'] = $adminConfig['callback_time_uc'] ?? AdminConstants::CALLBACK_TIME_ONCE_24;
- return $this->view->fetch();
- }
- public function getTtSetting($domain)
- {
- $setting = Config::get('site.uc_url');
- $list = explode(',', $setting);
- $default = Config::get('site.uc_company');
- foreach ($list as $item) {
- $item_l = explode('/', $item);
- if (count($item_l) == 3) {
- $target = $item_l[2];
- } else {
- $target = $default;
- }
- if ($domain == $item_l[0]) {
- return $target;
- }
- }
- return $default;
- }
- public function autocompletebookname()
- {
- if ($this->request->isAjax()) {
- $keyword = $this->request->post('name') ?? $this->request->param('pkey_value');
- $data = [];
- $keyword = trim($keyword);
- $bookModel = model('Book');
- $map = [];
- if ($this->group > 2) {
- $map['cansee'] = 1;
- }
- //获取独家书籍id
- ExclusiveService::instance()->getExclusiveNotidsWithWhere($this->group, $this->auth->id,$map);
- if (!empty($keyword)) {
- $bookList = $bookModel
- ->where('state', 'neq', BookConstants::BOOK_STATE_OFF_SALE)
- ->where($map)
- ->where(function (Query $query) use ($keyword) {
- $query->where('name', 'like', "%{$keyword}%")
- ->whereOr('id', $keyword);
- })
- ->limit(0, 10)->select();
- } else {
- $bookList = $bookModel->where('state', 'neq',
- BookConstants::BOOK_STATE_OFF_SALE)->where($map)->order('book.idx desc,book.idxx desc')->limit(0, 10)->select();
- }
- $data = $bookList;
- return json(['list' => $data, 'total' => count($data)]);
- }
- }
- }
|