MappController.php 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373
  1. <?php
  2. namespace api\controllers;
  3. use app\common\controllers\AController;
  4. use app\common\controllers\CController;
  5. use app\models\Nav;
  6. use app\modules\admin\models\Config;
  7. use app\modules\ad\models\AdData;
  8. use app\modules\doc\models\DocReal;
  9. use app\modules\ucenter\models\UserNum;
  10. use app\assets\WapAsset;
  11. use app\modules\cms\models\Category;
  12. use app\common\components\MultiSearchUrl;
  13. use app\modules\cms\models\Page;
  14. use Yii;
  15. class MappController extends AController
  16. {
  17. public $assetsUrl;
  18. public $optional1 = [
  19. 'config',
  20. 'index',
  21. 'catlist',
  22. 'catconfig',
  23. 'doclist',
  24. 'search',
  25. ];
  26. public function init()
  27. {
  28. $this->optional = array_merge($this->optional,$this->optional1);
  29. $view = $this->getView();
  30. $assets = WapAsset::register($view);
  31. $this->assetsUrl = API_URL.ltrim($assets->baseUrl,'/').'/';
  32. parent::init();
  33. }
  34. //读取小程序配置
  35. public function actionConfig()
  36. {
  37. $request_from = $this->get['request_from'];
  38. //百度小程序
  39. if($request_from==3)
  40. {
  41. $configResult = Config::find()->where("name = 'bdapp'")->limit(1)->one();
  42. }
  43. //微信小程序
  44. if($request_from==4)
  45. {
  46. $configResult = Config::find()->where("name = 'wxapp'")->limit(1)->one();
  47. }
  48. $config = string2array($configResult->value);
  49. $config['logo'] = getFileUrl($config['logo']);
  50. $config['shortlogo'] = getFileUrl($config['shortlogo']);
  51. //附加配置
  52. $hotWords = \app\models\SearchRecord::find()->where("recommend=1")->orderBy(['times'=>SORT_DESC])->limit(5)->all();
  53. $config['hotWords'] = $hotWords;
  54. $config['docname'] = $this->docconfig['docname']?$this->docconfig['docname']:'文档';
  55. $config['colname'] = $this->docconfig['colname']?$this->docconfig['colname']:'合辑';
  56. $config['coin_name'] = $this->coinconfig['coin_name'];
  57. $config['doc_model_id'] = $this->docconfig['content_model_id'];
  58. $config['assetsUrl'] = $this->assetsUrl;
  59. $config['fastAccountType'] = $this->openauthconfig['fastAccountType'];
  60. $config['commonAccountType'] = $this->openauthconfig['commonAccountType'];
  61. if($config['fastAccountType']=='mobile')
  62. {
  63. $config['fastAccountTip'] = '手机号';
  64. }
  65. else if($config['fastAccountType']=='email')
  66. {
  67. $config['fastAccountTip'] = '邮箱';
  68. }
  69. else if($config['fastAccountType']=='all')
  70. {
  71. $config['fastAccountTip'] = '手机号/邮箱';
  72. }
  73. if($config['commonAccountType']=='mobile')
  74. {
  75. $config['commonAccountTip'] = '手机号';
  76. }
  77. else if($config['commonAccountType']=='email')
  78. {
  79. $config['commonAccountTip'] = '邮箱';
  80. }
  81. else if($config['commonAccountType']=='all')
  82. {
  83. $config['commonAccountTip'] = '手机号/邮箱';
  84. }
  85. $config['certTimeOut'] = $this->smsconfig['certTimeOut'];
  86. $config['certValidTime'] = $this->smsconfig['certValidTime'].'分钟';
  87. $config['user_model_id'] = getSysconfigValue('default_user_model');
  88. $config['share_arg_name'] = Yii::$app->params['shareArgName'];
  89. $config['refer_page_name'] = Yii::$app->params['referPageName'];
  90. $agreements = Page::findOne(getSysconfigValue('user_agreements_cat_id'));
  91. $privacy = Page::findOne(getSysconfigValue('privacy_agreements_cat_id'));
  92. $config['agreements'] = $agreements;
  93. $config['privacy'] = $privacy;
  94. return [
  95. 'error' => 0,
  96. 'msg' => '操作成功',
  97. 'data' => ['config'=>$config],
  98. 'code'=>200
  99. ];
  100. }
  101. //首页
  102. public function actionIndex()
  103. {
  104. $request_from = $this->get['request_from'];
  105. //首页BANNER
  106. $bannerList = $this->_getAdData(12);
  107. if(is_array($bannerList))foreach($bannerList as $k=>$banner)
  108. {
  109. $bannerList[$k]['thumb'] = getFileUrl($banner['thumb']);
  110. }
  111. //文档数量
  112. $totalNum = DocReal::find()->where('is_delete=0 and status=1')->count();
  113. $totalNum = $totalNum + $this->docconfig['virtualnum'];
  114. $preDate = get_date(strtotime("-1 day"),"Y-m-d");
  115. $predayNum = UserNum::find()->where("date='".$preDate."'")->sum('doc_uploadnum');
  116. $predayNum = $predayNum+$this->docconfig['virtualaddnum'];
  117. //首页菜单
  118. if($request_from==3)//百度小程序
  119. {
  120. $menuList = Nav::find()->where("type=81 and disabled=0")->orderBy(['list_order'=>SORT_ASC])->asArray()->all();
  121. }
  122. if($request_from==4)//微信小程序
  123. {
  124. $menuList = Nav::find()->where("type=91 and disabled=0")->orderBy(['list_order'=>SORT_ASC])->asArray()->all();
  125. }
  126. //首页横幅广告
  127. $adList = $this->_getAdData(13);
  128. if(is_array($adList))foreach($adList as $k=>$ad)
  129. {
  130. $adList[$k]['thumb'] = getFileUrl($ad['thumb']);
  131. }
  132. //最新文档
  133. $newDocList = DocReal::find()->where("is_new=1 and status=1 and is_delete=0 and doc_type!=2")->orderBy(['create_time'=>SORT_DESC])->limit(10)->asArray()->all();
  134. foreach($newDocList as $k=>$newDoc)
  135. {
  136. $newDocList[$k]['thumb'] = $this->makeThumb($newDoc['thumb'],320,340);
  137. $newDocList[$k]['icon'] = $this->assetsUrl.'images/icon/'.DocReal::getExtImgName($newDoc['ext']).'.png';
  138. $newDocList[$k]['views'] = $this->getDocView($newDoc['views']);
  139. $newDocList[$k]['downs'] = $this->getDocDowns($newDoc['downs']);
  140. }
  141. //最新合辑
  142. $newColList = DocReal::find()->where("is_new=1 and status=1 and is_delete=0 and doc_type=2")->orderBy(['create_time'=>SORT_DESC])->limit(10)->asArray()->all();
  143. foreach($newColList as $k=>$newCol)
  144. {
  145. $newColList[$k]['thumb'] = $this->makeThumb($newCol['thumb'],354,254);
  146. $newColList[$k]['icon'] = $this->assetsUrl.'images/icon/'.DocReal::getExtImgName($newCol['ext']).'.png';
  147. $newColList[$k]['views'] = $this->getDocView($newCol['views']);
  148. $newColList[$k]['downs'] = $this->getDocDowns($newCol['downs']);
  149. }
  150. $tabTitle[] = $this->docconfig['docname']?$this->docconfig['docname']:'文档';
  151. $tabTitle[] = $this->docconfig['colname']?$this->docconfig['colname']:'合辑';
  152. return [
  153. 'error' => 0,
  154. 'msg' => '操作成功',
  155. 'data' => ['bannerList'=>$bannerList,'adList'=>$adList,'menuList'=>$menuList,'totalNum'=>$totalNum,'predayNum'=>$predayNum,'tabTitle'=>$tabTitle,'newDocList'=>$newDocList,'newColList'=>$newColList,'assetsUrl'=>$this->assetsUrl],
  156. 'code'=>200
  157. ];
  158. }
  159. //获取栏目列表
  160. public function actionCatlist()
  161. {
  162. $level = $this->docconfig['catlevel'];
  163. $menuList = Category::getDocCatMenus($this->docconfig['content_model_id']);
  164. foreach($menuList as $i=>$menu)
  165. {
  166. if(empty($menu['childs']))
  167. {
  168. $menuList[$i]['childs'][] = ['title'=>$menu['title'],'cat_id'=>$menu['cat_id']];
  169. }
  170. else
  171. {
  172. foreach($menu['childs'] as $k=>$subMenu)
  173. {
  174. if(empty($subMenu['childs']))
  175. {
  176. $menuList[$i]['childs'][$k]['childs'][] = ['title'=>$subMenu['title'],'cat_id'=>$subMenu['cat_id']];
  177. }
  178. }
  179. }
  180. }
  181. return [
  182. 'error' => 0,
  183. 'msg' => '操作成功',
  184. 'data' => ['menuList'=>$menuList,'level'=>$level],
  185. 'code'=>200
  186. ];
  187. }
  188. //获取栏目配置
  189. public function actionCatconfig()
  190. {
  191. $cat_id = $this->get['cat_id'];
  192. $controller = new \app\common\controllers\FController('default','web');
  193. $controller->initFilterConfig();
  194. $docFilterConfig = $controller->filterConfig['doc'];
  195. if($cat_id>0)
  196. {
  197. $category = Category::findOne($cat_id);
  198. //栏目扩展配置(加入SEO)
  199. $extConfigList = $category->getExtconfig($docFilterConfig['xConfig']);
  200. }
  201. return [
  202. 'error' => 0,
  203. 'msg' => '操作成功',
  204. 'data' => ['extConfigList'=>$extConfigList,'spConfig'=>$docFilterConfig['spConfig'],'vpConfig'=>$docFilterConfig['vpConfig'],'sortConfig'=>$docFilterConfig['sortConfigWap']],
  205. 'code'=>200
  206. ];
  207. }
  208. //文档列表
  209. public function actionDoclist()
  210. {
  211. $doc_type = $this->get['doc_type'];
  212. $searchConditions = [];
  213. if(is_array($this->get))foreach($this->get as $k=>$v)
  214. {
  215. if($v==0)continue;
  216. $searchConditions[] = $k.$v;
  217. }
  218. //序列化筛选条件
  219. $controller = new \app\common\controllers\FController('default','web');
  220. $controller->initFilterConfig();
  221. $docFilterConfig = $controller->filterConfig['doc'];
  222. $multiSearch = MultiSearchUrl::getSelfInstance(array('fieldConfig'=> $docFilterConfig['fieldConfig'],'sortConfig'=>$docFilterConfig['sortConfig']));
  223. $multiSearch->existConditions = $searchConditions;
  224. $sqlInfo = $multiSearch->sqllizeConditions();
  225. $catId = $multiSearch->getConditionValueByType($searchConditions,'c');
  226. $st = $multiSearch->getConditionValueByType($searchConditions,'st');
  227. if($catId)
  228. {
  229. $category = Category::findOne($catId);
  230. //栏目扩展配置(加入SEO)
  231. $extConfigList = $category->getExtconfig($docFilterConfig['xConfig']);
  232. if(is_array($extConfigList))foreach($extConfigList as $extname=>$extConfig){
  233. if(is_array($extConfig['options']))foreach($extConfig['options'] as $k=>$v){
  234. if(in_array($extConfig['key'].$k,$searchConditions)){
  235. $$extname = $v;
  236. }
  237. }
  238. }
  239. //栏目SEO设置
  240. $seosettingsPre = 'wap_';
  241. $cat_name = $category->cat_name;
  242. $categorySeoSettings = Category::getCatSeoSettings($catId,$seosettingsPre);
  243. $_replaceconfig = array(
  244. 'targets'=>['{brand}','{cat_name}','{ext_type_1}','{ext_type_2}','{ext_type_3}','{ext_type_4}','{ext_type_5}'],
  245. 'values'=>[$this->baseconfig['brand'],$cat_name,$ext_type_1,$ext_type_2,$ext_type_3,$ext_type_4,$ext_type_5],
  246. 'pre'=>$seosettingsPre
  247. );
  248. $metaInfo = seoSettings($categorySeoSettings,$_replaceconfig);
  249. }
  250. else
  251. {
  252. $metaInfo = [$this->docconfig['meta_title'],$this->docconfig['meta_keywords'],$this->docconfig['meta_description']];
  253. }
  254. //初始化查询语句
  255. $query = DocReal::find()->asArray();
  256. $sql = " 1=1 ";
  257. if($sqlInfo['where']) $sql.= $sqlInfo['where'];
  258. if($doc_type==2)
  259. {
  260. $sql .= " and doc_type=2 and status=1 and is_delete=0";
  261. }
  262. else
  263. {
  264. $sql .= " and doc_type!=2 and status=1 and is_delete=0";
  265. }
  266. $currentPage = Yii::$app->request->get('page',1);
  267. $return = $controller->doList($query,$sql,$sqlInfo,'doc',10,$this->higherconfig);
  268. $pages = $return['pages'];
  269. $resultList = $return['resultList'];
  270. if(is_array($resultList))foreach($resultList as $k=>$result)
  271. {
  272. $tempDocType = $result['doc_type1']?$result['doc_type1']:$result['doc_type'];
  273. if($tempDocType==2)
  274. {
  275. $resultList[$k]['thumb'] = $this->makeThumb($result['thumb'],354,254);
  276. }
  277. else
  278. {
  279. $resultList[$k]['thumb'] = $this->makeThumb($result['thumb'],320,340);
  280. }
  281. $resultList[$k]['icon'] = $this->assetsUrl.'images/icon/'.DocReal::getExtImgName($result['ext']).'.png';
  282. $resultList[$k]['views'] = $this->getDocView($result['views']);
  283. $resultList[$k]['downs'] = $this->getDocDowns($result['downs']);
  284. $resultList[$k]['doc_type'] = $tempDocType;
  285. $resultList[$k]['doc_num'] = $result['doc_num'];
  286. $resultList[$k]['coin_price'] = number_format($result['coin_price'],1);
  287. }
  288. return [
  289. 'error' => 0,
  290. 'msg' => '请求成功',
  291. 'data' => ['resultList'=>$resultList,'count'=>$pages->totalCount,'pageCount'=>$pages->getPageCount(),'currentPage'=>$currentPage,'pageSize'=>$pages->pageSize,'metaInfo'=>$metaInfo],
  292. 'code'=>200
  293. ];
  294. }
  295. //搜索
  296. public function actionSearch()
  297. {
  298. $kw = safe_replace(urldecode($_GET['kw']));
  299. $model_id = intval($_GET['model_id']);
  300. if($kw&&$model_id)
  301. {
  302. $controller = new \app\common\controllers\FController('default','web');
  303. $controller->initFilterConfig();
  304. $searchReturn = $controller->doSearch($kw,$model_id,$this->higherconfig);
  305. extract($searchReturn);
  306. return [
  307. 'error' => 0,
  308. 'msg' => '请求成功',
  309. 'data' => ['resultList'=>$resultList,'count'=>$count,'pageCount'=>$pageCount,'currentPage'=>$currentPage,'pageSize'=>$pageSize],
  310. 'code'=>200
  311. ];
  312. }
  313. }
  314. //获取用户信息
  315. public function actionUserinfo()
  316. {
  317. $this->userInfo['avatar'] = getFileUrl($this->user['avatar']);
  318. return [
  319. 'error' => 0,
  320. 'msg' => '请求成功',
  321. 'data' => ['userInfo'=>$this->userInfo],
  322. 'code'=>200
  323. ];
  324. }
  325. //返回文档浏览数
  326. public function getDocView($views)
  327. {
  328. $virtualViews = $views+intval($this->docconfig['virtualviews']);
  329. return $virtualViews>=999?'999+':$virtualViews;
  330. }
  331. //返回文档下载数
  332. public function getDocDowns($downs)
  333. {
  334. $virtualDowns = $downs+intval($this->docconfig['virtualdowns']);
  335. return $virtualDowns>=99?'99+':$virtualDowns;
  336. }
  337. //获取广告数据
  338. private function _getAdData($space_id)
  339. {
  340. $dataList = AdData::find()->where("space_id='".$space_id."' and status=1 and end_time>".TIMESTAMP)->orderBy(['list_order'=>SORT_ASC])->asArray()->all();
  341. return $dataList;
  342. }
  343. }