Index.php 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274
  1. <?php
  2. namespace app\clientweb\controller;
  3. use app\common\controller\ClientWeb;
  4. use app\main\constants\PayConstants;
  5. use app\main\helper\ArrayHelper;
  6. use app\main\service\ClientAppService;
  7. use app\main\service\GoodsService;
  8. use think\Config;
  9. use think\Controller;
  10. use think\Cookie;
  11. use think\Request;
  12. use think\Url;
  13. /**
  14. * Created by PhpStorm.
  15. * User: lytian
  16. * Date: 2019/4/11
  17. * Time: 18:14
  18. */
  19. class Index extends ClientWeb
  20. {
  21. protected $layout = '';
  22. protected $tpname = ['1' => 'lunbo', '2' => 'cainixihuan', '3' => 'remenshuangwen', '4' => 'nav', '5' => 'searchbox', '6' => 'blcoknav', '7' => 'changxiao','8'=>'recently'];
  23. //1=轮播,2=横4,3=竖4,4=标题导航,5=搜索,6=块导航,7=榜单
  24. public function index()
  25. {
  26. $rencently = [];
  27. $sex = '1';
  28. $avatar = '/assets/img/frontend/icon/nav_icon_4.png';
  29. $isVip = false;
  30. $type = 'boy';
  31. if ($this->isLogin) {
  32. if ($this->userInfo['sex'] && $this->userInfo['sex'] == 2) {
  33. $type = 'girl';
  34. $sex = '2';
  35. }
  36. if ($this->userInfo['avatar']) {
  37. $avatar = $this->userInfo['avatar'];
  38. }
  39. $isVip = $this->userInfo['vip_endtime'] > time();
  40. $res = model('UserRecentlyRead')->getRecentlyRead(0, 10, $this->userInfo['id'], true);
  41. $rencently = $res['totalNum'] == 0 ? [] : $res['data'];
  42. }
  43. $pagesex = isset($this->params['type']) ? $this->params['type'] : $type;
  44. if ($pagesex == 'boy') {
  45. //男频
  46. $tag = 1;
  47. } else {
  48. //女频
  49. $tag = 2;
  50. }
  51. $indexTitle = '书城';
  52. if ($pagesex == 'girl') {
  53. $sexid = 2;
  54. } else {
  55. $sexid = 1;
  56. }
  57. //运营活动位
  58. $pagedata = ClientAppService::instance()->pageBlockResource($pagesex);
  59. $ranklist = ClientAppService::instance()->rankList($pagesex);
  60. $this->assign('rencently', $rencently);
  61. $this->assign('title', $indexTitle);
  62. $this->view->assign('sexid', $sexid);
  63. $this->view->assign('type', $pagesex);
  64. $this->view->assign('pagedata', $pagedata);
  65. $this->view->assign('ranklist', $ranklist);
  66. $this->view->assign('sex', $sex);
  67. $this->view->assign('avatar', $avatar);
  68. $this->view->assign('isVip', $isVip);
  69. return $this->view->fetch();
  70. }
  71. /**
  72. * 搜索页
  73. * @param int $sex 频道标示
  74. */
  75. public function search()
  76. {
  77. $userId = 0;
  78. if ($this->isLogin) {
  79. $userId = $this->userInfo['id'];
  80. }
  81. $books = model('User')->getLike($userId);
  82. $categoryArr = model("BookCategory")->getCategoryList();
  83. foreach ($books as $k=>$v){
  84. $books[$k]['author'] = $categoryArr[$v['book_category_id']];
  85. }
  86. if($this->request->isAjax()){
  87. return json_encode($books);
  88. }else{
  89. $sex = input('sex');
  90. $this->assign('sex', $sex);
  91. $pagedata['name'] = '精彩推荐';
  92. $pagedata['block_resource'] = $books;
  93. $this->view->assign('value', $pagedata);
  94. return $this->view->fetch();
  95. }
  96. }
  97. /*
  98. * 主编推荐列表
  99. */
  100. public function recommendList($book_id)
  101. {
  102. $userid = 0;
  103. if ($this->isLogin) {
  104. $userid = $this->userInfo['id'];
  105. }
  106. $pagedata = ClientAppService::instance()->recommendList($book_id, $userid);
  107. return $pagedata;
  108. }
  109. /**
  110. * 弹框配置H5
  111. */
  112. public function popuptemp()
  113. {
  114. $id = $this->urlParams['id'];
  115. if (empty($id)) {
  116. $this->error("缺少参数");
  117. }
  118. $row = model("ClientConfig")->getOne($id);
  119. if ($row['fun_type'] != '2') {
  120. $this->error("类型有误");
  121. }
  122. switch ($row['type']) {
  123. case "1":
  124. //url
  125. $link = ClientAppService::instance()->parseAppUrl('url', ['url' => $row['url']]);
  126. break;
  127. case "2":
  128. //书籍详情
  129. $link = ClientAppService::instance()->parseAppUrl('bookinfo', ['book_id' => $row['book_id']]);
  130. break;
  131. case "3":
  132. //阅读器
  133. $link = ClientAppService::instance()->parseAppUrl('chapter', ['book_id' => $row['book_id']]);
  134. break;
  135. case "4":
  136. //活动
  137. $actUrl = '/clientWeb/activity/index?id='.$row['client_activity_id'];
  138. $link = ClientAppService::instance()->parseAppUrl('activity', ['url' => $actUrl]);
  139. break;
  140. }
  141. $this->view->engine->layout(false);
  142. $this->assign('img', $row['pic_url']);
  143. $this->assign('link', $link);
  144. return $this->fetch('popuptemp');
  145. }
  146. /**
  147. * 绑定手机弹窗
  148. * @return mixed
  149. */
  150. public function bindpopup()
  151. {
  152. $this->view->engine->layout(false);
  153. return $this->fetch('bindpopup');
  154. }
  155. /**
  156. * 开通VIP弹窗
  157. * @return mixed
  158. */
  159. public function vippopup()
  160. {
  161. //获取VIP的商品id
  162. $goodsId = Config::get('site.app_vip_popup');
  163. $this->view->engine->layout(false);
  164. $this->assign('goods_id', $goodsId);
  165. return $this->fetch('vippopup');
  166. }
  167. /**
  168. * 调试APPjs方法
  169. */
  170. public function appjstest()
  171. {
  172. $this->view->engine->layout(false);
  173. $this->assign('url1', 'http://www.baidu.com');
  174. $this->assign('url2', ClientAppService::instance()->parseAppUrl('url', ['url' => '/clientweb/index?type=girl', 'showTitleBar' => false]));
  175. $this->assign('url3', ClientAppService::instance()->parseAppUrl('bookinfo', ['book_id' => '11000000258']));
  176. $this->assign('url4', ClientAppService::instance()->parseAppUrl('shelf', []));
  177. $this->assign('url5', ClientAppService::instance()->parseAppUrl('chapter', ['book_id' => '11000000258']));
  178. $this->assign('url6', ClientAppService::instance()->parseAppUrl('dialog', ['url' => 'http://aa.lkety.cn/clientweb/index/vippopup']));
  179. $this->assign('url7', ClientAppService::instance()->parseAppUrl('account', []));
  180. $this->assign('url8', ClientAppService::instance()->parseAppUrl('book', []));
  181. $this->assign('url9', ClientAppService::instance()->parseAppUrl('dialog', ['url' => '/clientweb/index/paymethodselect?goods_id=45']));
  182. $this->assign('url10', ClientAppService::instance()->parseAppUrl('dialog', ['url' => '/clientweb/index/bindpopup']));
  183. return $this->fetch('appjstest');
  184. }
  185. /**
  186. * 选择充值方式
  187. * @return mixed
  188. */
  189. public function paymethodselect()
  190. {
  191. $aid = $this->urlParams['aid'] ?? 0;
  192. $goods_id = $this->urlParams['goods_id'] ?? 0;
  193. if (empty($goods_id)) {
  194. $this->error('缺少参数');
  195. }
  196. if (!$goodsInfo = GoodsService::instance()->getGoodsModel()->getGoodsInfoById($goods_id)) {
  197. $this->error('商品不存在');
  198. }
  199. $pay_list = model('Wxpay')->getListByBusiness(PayConstants::BUSINESS_APP);
  200. $pay_list = ArrayHelper::extractColumn($pay_list, ['id', 'payment_method', 'p_desc', 'icon']);
  201. $data = [
  202. 'pay_list' => $pay_list,
  203. 'aid' => $aid,
  204. 'goods_id' => $goods_id,
  205. 'money' => $goodsInfo['money'],
  206. ];
  207. $this->view->engine->layout(false);
  208. $this->view->assign('data', $data);
  209. return $this->fetch('paymethodselect');
  210. }
  211. /**
  212. * 查看cookie
  213. */
  214. public function dev()
  215. {
  216. echo '<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0,user-scalable=no">';
  217. echo "<a href='/clientweb/index/clear'>清除cookie</a><br><br>";
  218. echo '<pre>';
  219. var_dump(Cookie::get());
  220. }
  221. /**
  222. * 清除cookie
  223. */
  224. public function clear()
  225. {
  226. echo '<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0,user-scalable=no">';
  227. foreach (Cookie::get() as $key => $value) {
  228. Cookie::delete($key);
  229. }
  230. echo "<a href='/clientweb/index/dev'>访问dev</a><br><br>";
  231. echo "cookie已清除!";
  232. }
  233. }