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)]); } } }