Index.php 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
  4. // +----------------------------------------------------------------------
  5. // | Copyright (c) 2016~2020 https://www.crmeb.com All rights reserved.
  6. // +----------------------------------------------------------------------
  7. // | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
  8. // +----------------------------------------------------------------------
  9. // | Author: CRMEB Team <admin@crmeb.com>
  10. // +----------------------------------------------------------------------
  11. namespace app\wap\controller;
  12. use app\admin\model\special\RecommendBanner;
  13. use app\admin\model\wechat\WechatQrcode;
  14. use app\wap\model\activity\EventRegistration;
  15. use app\wap\model\live\LiveStudio;
  16. use app\wap\model\special\Lecturer;
  17. use app\wap\model\user\SmsCode;
  18. use app\wap\model\recommend\Recommend;
  19. use app\wap\model\special\SpecialSubject;
  20. use app\wap\model\user\PhoneUser;
  21. use app\wap\model\user\User;
  22. use app\wap\model\wap\Search;
  23. use service\GroupDataService;
  24. use service\JsonService;
  25. use service\SystemConfigService;
  26. use service\UploadService as Upload;
  27. use service\UtilService;
  28. use think\cache\driver\Redis;
  29. use think\Config;
  30. use think\Session;
  31. use think\Cookie;
  32. use think\Url;
  33. use think\Db;
  34. class Index extends AuthController
  35. {
  36. /*
  37. * 白名单
  38. * */
  39. public static function WhiteList()
  40. {
  41. return [
  42. 'agree',
  43. 'index',
  44. 'get_recommend',
  45. 'get_content_recommend',
  46. 'get_host_search',
  47. 'go_search',
  48. 'login',
  49. 'user_login',
  50. 'search',
  51. 'get_unifiend_list',
  52. 'get_recommend_info',
  53. 'more_list',
  54. 'get_more_list',
  55. 'unified_list',
  56. 'qcode_login',
  57. 'get_search_history',
  58. ];
  59. }
  60. /**
  61. * @return mixed
  62. */
  63. public function agree()
  64. {
  65. $this->assign('title', SystemConfigService::get('site_name') . '支付用户协议');
  66. $this->assign('content', get_config_content('user_agreement'));
  67. return $this->fetch();
  68. }
  69. /**
  70. * 主页
  71. * @return mixed
  72. */
  73. public function index()
  74. {
  75. $site_name = SystemConfigService::get('site_name');
  76. $seo_title = SystemConfigService::get('seo_title');
  77. $site_logo = SystemConfigService::get('home_logo');
  78. $live_one_id=Session::get('live_one_id');
  79. $this->assign([
  80. 'banner' => json_encode(GroupDataService::getData('store_home_banner') ?: []),
  81. 'title' => SystemConfigService::get('site_name'),
  82. 'activity' => json_encode(GroupDataService::getData('home_activity')),
  83. 'liveOne' => json_encode(LiveStudio::getLiveOne($live_one_id)),
  84. ]);
  85. $this->assign('confing', compact('site_name', 'seo_title', 'site_logo'));
  86. return $this->fetch();
  87. }
  88. /**
  89. * 上传图片
  90. * @return \think\response\Json
  91. */
  92. public function upload($name = 'file', $link = 'master')
  93. {
  94. $res = Upload::image($name, $link);
  95. $thumbPath = Upload::thumb($res->dir);
  96. if ($res->status == 200)
  97. return JsonService::successful('图片上传成功!', ['name' => $res->fileInfo->getSaveName(), 'url' => Upload::pathToUrl($thumbPath)]);
  98. else
  99. return JsonService::fail($res->error);
  100. }
  101. /**
  102. * @param int $qcode_id
  103. * @throws \think\exception\DbException
  104. */
  105. public function qcode_login($qcode_id = 0)
  106. {
  107. $qcodeInfo = WechatQrcode::get($qcode_id);
  108. if ($qcodeInfo) {
  109. if ($qcodeInfo->scan_id) {
  110. Session::set('loginUid', $qcodeInfo->scan_id, 'wap');
  111. Cookie::set('__login_phone', 1);
  112. Session::set('__login_phone_num' . $qcodeInfo->scan_id, User::where('uid', $qcodeInfo->scan_id)->value('phone'));
  113. return JsonService::successful();
  114. }
  115. }
  116. return JsonService::fail('');
  117. }
  118. /**
  119. * 手机号码登录
  120. * @throws \think\db\exception\DataNotFoundException
  121. * @throws \think\db\exception\ModelNotFoundException
  122. * @throws \think\exception\DbException
  123. */
  124. public function login()
  125. {
  126. list($phone, $code) = UtilService::postMore([
  127. ['phone', ''], ['code', '']
  128. ], $this->request, true);
  129. if (!$phone) return JsonService::fail('请输入手机号码');
  130. $userphone = User::where(['uid' => $this->uid])->value('phone');
  131. if ($userphone) {
  132. if ($userphone != $phone) return JsonService::fail('当前手机号码尚未绑定此用户');
  133. }
  134. if (!$code) return JsonService::fail('请输入验证码');
  135. if (!SmsCode::CheckCode($phone, $code) && !in_array($phone, Config::get('white_phone', []))) return JsonService::fail('验证码验证失败');
  136. SmsCode::setCodeInvalid($phone, $code);
  137. if (!$userphone) {
  138. //检查手机号码不存在时
  139. $phoneUser = PhoneUser::where(['phone' => $phone])->find();
  140. //H5页面有注册过
  141. if ($phoneUser) {
  142. //检测当前用户是否是H5用户
  143. if (User::where('uid', $phoneUser['uid'])->value('is_h5user')) {
  144. $res = User::setUserRelationInfos($phone, $phoneUser['uid'], $this->uid);
  145. if ($res === false) return JsonService::fail(User::getErrorInfo());
  146. }
  147. }
  148. if (!isset($res)) {
  149. if(!user::be(['phone' => $phone])){
  150. User::update(['phone' => $phone], ['uid' => $this->uid]);
  151. }else{
  152. return JsonService::fail('手机号已被使用');
  153. }
  154. }
  155. }
  156. Cookie::set('__login_phone', 1);
  157. Session::set('__login_phone_num' . $this->uid, $phone, 'wap');
  158. return JsonService::successful('登录成功');
  159. }
  160. /**
  161. * 获取手机号码登录状态
  162. * */
  163. public function user_login()
  164. {
  165. if ($this->phone)
  166. return JsonService::successful('');
  167. else
  168. return JsonService::fail('请先登录,在进行购买!');
  169. }
  170. public function login_user()
  171. {
  172. if ($this->uid)
  173. return JsonService::successful();
  174. else
  175. return JsonService::fail('请登录!');
  176. }
  177. /**
  178. * 获取主页导航图标
  179. */
  180. public function get_recommend()
  181. {
  182. return JsonService::successful(Recommend::getRecommend());
  183. }
  184. /**
  185. * 获取主页推荐列表
  186. * @param int $page
  187. * @param int $limit
  188. */
  189. public function get_content_recommend($page = 1, $limit = 10)
  190. {
  191. //获取推荐列表
  192. $exists_recommend_reids = $this->redisModel->HEXISTS($this->subjectUrl."wap_index_has","recommend_list");
  193. if (!$exists_recommend_reids) {
  194. $recommend_list = json_encode(Recommend::getContentRecommend((int)$page, (int)$limit, $this->uid));
  195. $this->redisModel->hset($this->subjectUrl."wap_index_has","recommend_list", $recommend_list);
  196. $this->redisModel->expire($this->subjectUrl."wap_index_has",120);
  197. }else{
  198. $recommend_list = $this->redisModel->hget($this->subjectUrl."wap_index_has","recommend_list");
  199. }
  200. return JsonService::successful(json_decode($recommend_list,true));
  201. }
  202. /**
  203. * 获取热搜词
  204. */
  205. public function get_host_search()
  206. {
  207. return JsonService::successful(Search::getHostSearch());
  208. }
  209. /**
  210. * 清除缓存
  211. */
  212. public function del_search_history()
  213. {
  214. $uid=$this->userInfo['uid'] ? $this->userInfo['uid'] : 0;
  215. if($uid) {
  216. $res=Db::name('search_history')->where('uid',$uid)->delete();
  217. $res1=$this->redisModel->hdel($this->subjectUrl."wap_index_has","search_history_".$uid);
  218. if($res && $res1){
  219. return JsonService::successful('清除成功!');
  220. }else{
  221. return JsonService::fail('清除失败!');
  222. }
  223. }
  224. return JsonService::successful('ok');
  225. }
  226. /**
  227. * 查找搜索历史内容
  228. * */
  229. public function get_search_history($search = '', $limit = 0)
  230. {
  231. $uid=$this->userInfo['uid'] ? $this->userInfo['uid'] : 0;
  232. if($uid) {
  233. $exists_search_reids = $this->redisModel->HEXISTS($this->subjectUrl."wap_index_has","search_history_".$uid);
  234. if (!$exists_search_reids) {
  235. $search_list = Search::userSearchHistory($uid) ? json_encode(Search::userSearchHistory($uid)) : [];
  236. if ($search_list) {
  237. $this->redisModel->hset($this->subjectUrl."wap_index_has","search_history_".$uid, $search_list);
  238. $this->redisModel->expire($this->subjectUrl."wap_index_has",120);
  239. }else{
  240. $this->redisModel->hdel($this->subjectUrl."wap_index_has","search_history_".$uid);
  241. }
  242. }else{
  243. $search_list = $this->redisModel->hget($this->subjectUrl."wap_index_has","search_history_".$uid);
  244. }
  245. }else{
  246. $search_list=[];
  247. }
  248. return JsonService::successful($search_list ? json_decode($search_list, true) : []);
  249. }
  250. /**
  251. * 查找搜索内容
  252. * */
  253. public function go_search($search = '', $limit = 0)
  254. {
  255. $uid=$this->userInfo['uid'] ? $this->userInfo['uid'] : 0;
  256. return JsonService::successful(Search::getSearchContent($search, $limit,$uid));
  257. }
  258. /**
  259. * 搜索页面
  260. * */
  261. public function search()
  262. {
  263. return $this->fetch();
  264. }
  265. /**
  266. * 搜索页面查看更多
  267. * */
  268. public function more_list($type = 0, $search = '')
  269. {
  270. if ($search == '') $this->failed('没有查找相关数据,点我返回上一页', Url::build('index/index'));
  271. $this->assign(compact('type', 'search'));
  272. return $this->fetch();
  273. }
  274. /**
  275. * 分页获取搜索更多内容
  276. * */
  277. public function get_more_list()
  278. {
  279. $where = UtilService::getMore([
  280. ['type', 0],
  281. ['search', ''],
  282. ['page', 1],
  283. ['limit', 10],
  284. ]);
  285. return JsonService::successful(Search::getMoerList($where));
  286. }
  287. public function get_recommend_info($recommend_id = 0)
  288. {
  289. return JsonService::successful(Recommend::get($recommend_id));
  290. }
  291. /**
  292. * 主页标签详情
  293. * @param int $type
  294. * @param string $title
  295. * @param int $recommend_id
  296. * @return mixed
  297. * @throws \think\db\exception\DataNotFoundException
  298. * @throws \think\db\exception\ModelNotFoundException
  299. * @throws \think\exception\DbException
  300. */
  301. public function unified_list($type = 0, $title = '', $recommend_id = 0)
  302. {
  303. if (!$recommend_id) $this->failed('您查看的页面走丢了', Url::build('index/index'));
  304. $recommend = Recommend::get($recommend_id);
  305. if (!$recommend) $this->failed('您查看的栏目不存在', Url::build('index/index'));
  306. if ($recommend->is_show == 0) $this->failed('您查看的栏目不存在', Url::build('index/index'));
  307. $banner = RecommendBanner::valiWhere()->where('recommend_id', $recommend_id)->select();
  308. $Recommendlist = SpecialSubject::where('is_show', 1)->where('is_del', 0)->where('grade_id', $recommend['grade_id'])->field(['name as title', 'id'])->order('sort desc')->select();
  309. if ($recommend->typesetting == 4) {
  310. $recommend->typesetting = 3;
  311. }
  312. $this->assign([
  313. 'type' => (int)$type,
  314. 'title' => $title,
  315. 'grade_id' => (int)$recommend->grade_id,
  316. 'image' => $recommend->image,
  317. 'recommend_id' => (int)$recommend_id,
  318. 'typesetting' => (int)$recommend->typesetting,
  319. 'banner' => json_encode($banner),
  320. 'Recommendlist' => json_encode($Recommendlist),
  321. ]);
  322. return $this->fetch();
  323. }
  324. /**
  325. * 标签详情列表获取
  326. * */
  327. public function get_unifiend_list()
  328. {
  329. $where = UtilService::getMore([
  330. ['page', 1],
  331. ['limit', 10],
  332. ['recommend_id', 0],
  333. ['type', 0],
  334. ['typesetting', 0],
  335. ['subject_id', 0],
  336. ]);
  337. return JsonService::successful(Search::getUnifiendList($where));
  338. }
  339. public function date_empty()
  340. {
  341. \think\Session::clear();
  342. \think\Cookie::clear();
  343. }
  344. }