My.php 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
  4. // +----------------------------------------------------------------------
  5. // | Copyright (c) 2016~2022 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 Api\Express;
  13. use app\wap\model\special\SpecialRecord;
  14. use app\wap\model\special\SpecialLog;
  15. use app\wap\model\special\SpecialBuy;
  16. use app\wap\model\special\SpecialSource;
  17. use app\wap\model\special\SpecialRelation;
  18. use app\admin\model\questions\Relation;
  19. use app\wap\model\user\SmsCode;
  20. use app\wap\model\store\StoreOrderCartInfo;
  21. use app\wap\model\recommend\Recommend;
  22. use app\wap\model\store\StoreOrder;
  23. use app\wap\model\user\PhoneUser;
  24. use app\wap\model\user\User;
  25. use app\wap\model\user\UserBill;
  26. use app\wap\model\user\UserExtract;
  27. use app\wap\model\user\UserAddress;
  28. use app\wap\model\user\UserSign;
  29. use service\GroupDataService;
  30. use service\JsonService;
  31. use service\SystemConfigService;
  32. use service\UtilService;
  33. use think\Cookie;
  34. use think\Request;
  35. use think\Session;
  36. use think\Url;
  37. /**my 控制器
  38. * Class My
  39. * @package app\wap\controller
  40. */
  41. class My extends AuthController
  42. {
  43. /*
  44. * 白名单
  45. * */
  46. public static function WhiteList()
  47. {
  48. return [
  49. 'index',
  50. 'about_us',
  51. 'getPersonalCenterMenu',
  52. 'questionModule'
  53. ];
  54. }
  55. /**
  56. * 退出手机号码登录
  57. */
  58. public function logout()
  59. {
  60. Cookie::delete('__login_phone');
  61. Session::delete('__login_phone_num' . $this->uid, 'wap');
  62. Session::delete('loginUid', 'wap');
  63. return JsonService::successful('已退出登录');
  64. }
  65. /**
  66. * 获取获取个人中心菜单
  67. */
  68. public function getPersonalCenterMenu()
  69. {
  70. $store_brokerage_statu = SystemConfigService::get('store_brokerage_statu');
  71. if ($store_brokerage_statu == 1) {
  72. if (isset($this->userInfo['is_promoter'])) $is_statu = $this->userInfo['is_promoter'] > 0 ? 1 : 0;
  73. else $is_statu = 0;
  74. } else if ($store_brokerage_statu == 2) {
  75. $is_statu = 1;
  76. }
  77. $is_write_off = isset($this->userInfo['is_write_off']) ? $this->userInfo['is_write_off'] : 0;
  78. $business = isset($this->userInfo['business']) ? $this->userInfo['business'] : 0;
  79. return JsonService::successful(Recommend::getPersonalCenterMenuList($is_statu, $is_write_off, $business, $this->uid));
  80. }
  81. /**
  82. * 题库模块
  83. */
  84. public function questionModule()
  85. {
  86. $question = GroupDataService::getData('question_bank_module', 2);
  87. return JsonService::successful($question);
  88. }
  89. /**我的赠送
  90. * @return mixed
  91. */
  92. public function my_gift()
  93. {
  94. return $this->fetch();
  95. }
  96. /**我的报名
  97. * @return mixed
  98. */
  99. public function sign_list()
  100. {
  101. return $this->fetch();
  102. }
  103. /**获取核销订单信息
  104. * @param int $type
  105. * @param string $order_id
  106. * @return mixed|void
  107. * @throws \think\db\exception\DataNotFoundException
  108. * @throws \think\db\exception\ModelNotFoundException
  109. * @throws \think\exception\DbException
  110. */
  111. public function sign_order($type = 2, $order_id = '')
  112. {
  113. if ($type == 2 && !$this->userInfo['is_write_off']) return $this->failed('您没有权限!');
  114. $this->assign(['type' => $type, 'order_id' => $order_id]);
  115. return $this->fetch();
  116. }
  117. /**报名详情
  118. * @param string $order_id
  119. * @return mixed|void
  120. * @throws \think\db\exception\DataNotFoundException
  121. * @throws \think\db\exception\ModelNotFoundException
  122. * @throws \think\exception\DbException
  123. */
  124. public function sign_my_order($order_id = '')
  125. {
  126. $this->assign(['order_id' => $order_id]);
  127. return $this->fetch('order_verify');
  128. }
  129. /**我的信息
  130. * @return mixed
  131. */
  132. public function user_info()
  133. {
  134. return $this->fetch();
  135. }
  136. public function verify_activity()
  137. {
  138. return $this->fetch();
  139. }
  140. /**
  141. * 手机号验证
  142. */
  143. public function validate_code()
  144. {
  145. list($phone, $code,) = UtilService::getMore([
  146. ['phone', ''],
  147. ['code', ''],
  148. ], $this->request, true);
  149. if (!$phone) return JsonService::fail('请输入手机号码');
  150. if (!$code) return JsonService::fail('请输入验证码');
  151. $code = md5('is_phone_code' . $code);
  152. if (!SmsCode::CheckCode($phone, $code)) return JsonService::fail('验证码验证失败');
  153. SmsCode::setCodeInvalid($phone, $code);
  154. return JsonService::successful('验证成功');
  155. }
  156. /**
  157. * 信息保存
  158. */
  159. public function save_user_info()
  160. {
  161. $data = UtilService::postMore([
  162. ['avatar', ''],
  163. ['nickname', ''],
  164. ['realname', ''],
  165. ['comment', ''],
  166. ['grade_id', 0]
  167. ], $this->request);
  168. if ($data['nickname'] != strip_tags($data['nickname'])) {
  169. $data['nickname'] = htmlspecialchars($data['nickname']);
  170. }
  171. if (!$data['nickname']) return JsonService::fail('用户昵称不能为空');
  172. if (User::update($data, ['uid' => $this->uid]))
  173. return JsonService::successful('保存成功');
  174. else
  175. return JsonService::fail('保存失败');
  176. }
  177. /**
  178. * 保存手机号码
  179. * @return mixed|void
  180. * @throws \think\db\exception\DataNotFoundException
  181. * @throws \think\db\exception\ModelNotFoundException
  182. * @throws \think\exception\DbException
  183. * @throws \think\exception\PDOException
  184. */
  185. public function save_phone()
  186. {
  187. if ($this->request->isAjax()) {
  188. list($phone, $code, $type) = UtilService::getMore([
  189. ['phone', ''],
  190. ['code', ''],
  191. ['type', 0],
  192. ], $this->request, true);
  193. if (!$phone) return JsonService::fail('请输入手机号码');
  194. if (!$code) return JsonService::fail('请输入验证码');
  195. $code = md5('is_phone_code' . $code);
  196. if (!SmsCode::CheckCode($phone, $code)) return JsonService::fail('验证码验证失败');
  197. SmsCode::setCodeInvalid($phone, $code);
  198. $user = User::where(['phone' => $phone, 'is_h5user' => 0])->find();
  199. if ($type && $user) {
  200. if ($user['uid'] == $this->uid) {
  201. return JsonService::fail('不能绑定相同手机号');
  202. } else if ($user['uid'] != $this->uid) {
  203. return JsonService::fail('当前手机号码已绑定微信用户');
  204. }
  205. } else if ($type == 0 && $user) {
  206. if ($user) return JsonService::fail('当前手机号码已绑定微信用户');
  207. }
  208. //查找H5手机号码账户
  209. $phoneUser = PhoneUser::where(['phone' => $phone])->find();
  210. //H5页面有注册过
  211. if ($phoneUser && $phoneUser['uid'] != $this->uid) {
  212. //检测当前用户是否是H5用户
  213. if (User::where('uid', $phoneUser['uid'])->value('is_h5user')) {
  214. $res = User::setUserRelationInfos($phone, $phoneUser['uid'], $this->uid);
  215. if ($res === false) return JsonService::fail(User::getErrorInfo());
  216. }
  217. } else if ($phoneUser && $phoneUser['uid'] == $this->uid) {
  218. return JsonService::fail('不能绑定相同手机号');
  219. }
  220. if (!isset($res)) User::update(['phone' => $phone], ['uid' => $this->uid]);
  221. return JsonService::successful('绑定成功');
  222. } else {
  223. $this->assign('user_phone', $this->userInfo['phone']);
  224. return $this->fetch();
  225. }
  226. }
  227. /**
  228. * 个人中心
  229. * @return mixed
  230. * @throws \think\Exception
  231. */
  232. public function index()
  233. {
  234. $store_brokerage_statu = SystemConfigService::get('store_brokerage_statu');
  235. if ($store_brokerage_statu == 1) {
  236. if (isset($this->userInfo['is_promoter'])) $is_statu = $this->userInfo['is_promoter'] > 0 ? 1 : 0;
  237. else $is_statu = 0;
  238. } else if ($store_brokerage_statu == 2) {
  239. $is_statu = 1;
  240. }
  241. if (isset($this->userInfo['overdue_time'])) $overdue_time = date('Y-m-d', $this->userInfo['overdue_time']);
  242. else $overdue_time = 0;
  243. $this->assign([
  244. 'store_switch' => SystemConfigService::get('store_switch'),
  245. 'collectionNumber' => SpecialRelation::where('uid', $this->uid)->count(),
  246. 'recordNumber' => SpecialRecord::where('uid', $this->uid)->count(),
  247. 'overdue_time' => $overdue_time,
  248. 'is_statu' => $is_statu,
  249. ]);
  250. return $this->fetch();
  251. }
  252. /**虚拟币明细
  253. * @return mixed
  254. */
  255. public function gold_coin()
  256. {
  257. $gold_name = SystemConfigService::get('gold_name');//虚拟币名称
  258. $this->assign(compact('gold_name'));
  259. return $this->fetch('coin_detail');
  260. }
  261. /**签到
  262. * @return mixed
  263. */
  264. public function sign_in()
  265. {
  266. $urls = SystemConfigService::get('site_url') . '/';
  267. $gold_name = SystemConfigService::get('gold_name');//虚拟币名称
  268. $gold_coin = SystemConfigService::get('single_gold_coin');//签到获得虚拟币
  269. $signed = UserSign::checkUserSigned($this->uid);//今天是否签到
  270. $sign_image = $urls . "uploads/" . "poster_sign_" . $this->uid . ".png";
  271. $signCount = UserSign::userSignedCount($this->uid);//累记签到天数
  272. $this->assign(compact('signed', 'signCount', 'gold_name', 'gold_coin', 'sign_image'));
  273. return $this->fetch();
  274. }
  275. /**签到明细
  276. * @return mixed
  277. */
  278. public function sign_in_list()
  279. {
  280. return $this->fetch();
  281. }
  282. /**地址列表
  283. * @return mixed
  284. */
  285. public function address()
  286. {
  287. $address = UserAddress::getUserValidAddressList($this->uid, 'id,real_name,phone,province,city,district,detail,is_default');
  288. $this->assign([
  289. 'address' => json_encode($address)
  290. ]);
  291. return $this->fetch();
  292. }
  293. /**修改或添加地址
  294. * @param string $addressId
  295. * @return mixed
  296. * @throws \think\Exception
  297. * @throws \think\db\exception\DataNotFoundException
  298. * @throws \think\db\exception\ModelNotFoundException
  299. * @throws \think\exception\DbException
  300. */
  301. public function edit_address($addressId = '', $cartId = 0)
  302. {
  303. if ($addressId && is_numeric($addressId) && UserAddress::be(['is_del' => 0, 'id' => $addressId, 'uid' => $this->uid])) {
  304. $addressInfo = UserAddress::find($addressId)->toArray();
  305. } else {
  306. $addressInfo = [];
  307. }
  308. $addressInfo = json_encode($addressInfo);
  309. $this->assign(compact('addressInfo', 'cartId'));
  310. return $this->fetch();
  311. }
  312. /**订单详情
  313. * @param string $uni
  314. * @return mixed|void
  315. */
  316. public function order($uni = '')
  317. {
  318. if (!$uni || !$order = StoreOrder::getUserOrderDetail($this->uid, $uni)) return $this->failed('查询订单不存在!');
  319. $this->assign([
  320. 'gold_name' => SystemConfigService::get('gold_name'),
  321. 'order' => StoreOrder::tidyOrder($order, true)
  322. ]);
  323. return $this->fetch();
  324. }
  325. public function orderPinkOld($uni = '')
  326. {
  327. if (!$uni || !$order = StoreOrder::getUserOrderDetail($this->uid, $uni)) return $this->failed('查询订单不存在!');
  328. $this->assign([
  329. 'order' => StoreOrder::tidyOrder($order, true)
  330. ]);
  331. return $this->fetch('order');
  332. }
  333. /**获取订单
  334. * @param int $type
  335. * @param int $page
  336. * @param int $limit
  337. * @throws \think\Exception
  338. * @throws \think\db\exception\DataNotFoundException
  339. * @throws \think\db\exception\ModelNotFoundException
  340. * @throws \think\exception\DbException
  341. */
  342. public function get_order_list($type = -1, $page = 1, $limit = 10)
  343. {
  344. return JsonService::successful(StoreOrder::getSpecialOrderList((int)$type, (int)$page, (int)$limit, $this->uid));
  345. }
  346. /**我的拼课订单
  347. * @return mixed
  348. */
  349. public function order_list()
  350. {
  351. return $this->fetch();
  352. }
  353. /**申请退款
  354. * @param string $order_id
  355. * @return mixed
  356. */
  357. public function refund_apply($order_id = '')
  358. {
  359. if (!$order_id || !$order = StoreOrder::getUserOrderDetail($this->uid, $order_id)) return $this->failed('查询订单不存在!');
  360. $this->assign([
  361. 'order' => StoreOrder::tidyOrder($order, true, true),
  362. 'order_id' => $order_id
  363. ]);
  364. return $this->fetch();
  365. }
  366. /**评论页面
  367. * @param string $unique
  368. * @return mixed|void
  369. * @throws \think\db\exception\DataNotFoundException
  370. * @throws \think\db\exception\ModelNotFoundException
  371. * @throws \think\exception\DbException
  372. */
  373. public function order_reply($unique = '')
  374. {
  375. if (!$unique || !StoreOrderCartInfo::be(['unique' => $unique]) || !($cartInfo = StoreOrderCartInfo::where('unique', $unique)->find())) return $this->failed('评价产品不存在!');
  376. $this->assign(['cartInfo' => $cartInfo]);
  377. return $this->fetch();
  378. }
  379. /**物流查询
  380. * @param string $uni
  381. * @return mixed|void
  382. * @throws \think\db\exception\DataNotFoundException
  383. * @throws \think\db\exception\ModelNotFoundException
  384. * @throws \think\exception\DbException
  385. */
  386. public function express($uni = '')
  387. {
  388. if (!$uni || !($order = StoreOrder::getUserOrderDetail($this->uid, $uni))) return $this->failed('查询订单不存在!');
  389. if ($order['delivery_type'] != 'express' || !$order['delivery_id']) return $this->failed('该订单不存在快递单号!');
  390. $this->assign(['order' => StoreOrder::tidyOrder($order, true, true)]);
  391. return $this->fetch();
  392. }
  393. public function commission()
  394. {
  395. $uid = (int)Request::instance()->get('uid', 0);
  396. if (!$uid) return $this->failed('用户不存在!');
  397. $this->assign(['uid' => $uid]);
  398. return $this->fetch();
  399. }
  400. /**
  401. * 关于我们
  402. * @return mixed
  403. */
  404. public function about_us()
  405. {
  406. $this->assign([
  407. 'content' => get_config_content('about_us'),
  408. 'title' => '关于我们'
  409. ]);
  410. return $this->fetch('index/agree');
  411. }
  412. public function getUserGoldBill()
  413. {
  414. $user_info = $this->userInfo;
  415. list($page, $limit) = UtilService::getMore([
  416. ['page', 1],
  417. ['limit', 20],
  418. ], $this->request, true);
  419. $where['uid'] = $user_info['uid'];
  420. $where['category'] = "gold_num";
  421. return JsonService::successful(UserBill::getUserGoldBill($where, $page, $limit));
  422. }
  423. /**
  424. * 余额明细
  425. */
  426. public function bill_detail()
  427. {
  428. return $this->fetch();
  429. }
  430. /**
  431. * 我的关注
  432. */
  433. public function follow_lecturer()
  434. {
  435. return $this->fetch();
  436. }
  437. /**
  438. * 课程浏览历史
  439. */
  440. public function special_log($page = 1, $limit = 20, $op = '') {
  441. if ($op == 'list') {
  442. $model = SpecialLog::alias('sl')->where('sl.mid', $this->uid)->page((int)$page, (int)$limit);
  443. $model = $model->join('Special s', 's.id = sl.sid');
  444. $model = $model->join('specialSubject ss', 's.subject_id = ss.id');
  445. $orderList = $model->order('sl.add_time DESC')->field('s.*, sl.add_time as log_time, ss.name as subject_name')->select();
  446. $orderList = count($orderList) > 0 ? $orderList->toArray() : [];
  447. foreach ($orderList as &$item) {
  448. if (!isset($item['money'])) $item['money'] = 0;
  449. $item['money'] = (float)$item['money'];
  450. $item['image'] = get_oss_process($item['image'], 0);
  451. $item['count'] = 0;
  452. $specialSourceId = SpecialSource::getSpecialSource($item['id']);
  453. if ($specialSourceId) $item['count'] = count($specialSourceId);
  454. else $item['count'] = 0;
  455. }
  456. return JsonService::successful($orderList);
  457. }
  458. return $this->fetch();
  459. }
  460. /**
  461. * 我的学分
  462. */
  463. public function credit(){
  464. return $this->fetch();
  465. }
  466. /**
  467. * 学籍档案-学习记录
  468. */
  469. public function history($page = 1, $limit = 10000, $op = ''){
  470. if ($op == 'xuefenlist'){
  471. $model = SpecialBuy::alias('sb')->where('sb.uid', $this->uid)->page((int)$page, (int)$limit);
  472. $model = $model->join('Special s', 's.id = sb.special_id');
  473. $model = $model->join('specialSubject ss', 's.subject_id = ss.id');
  474. $orderList = $model->order('sb.add_time DESC')->field('s.*, sb.add_time as log_time, ss.name as subject_name')->select();
  475. $orderList = count($orderList) > 0 ? $orderList->toArray() : [];
  476. $orderList1 = [];
  477. foreach ($orderList as &$item) {
  478. $flag = 1;
  479. if (!isset($item['money'])) $item['money'] = 0;
  480. $item['money'] = (float)$item['money'];
  481. $item['image'] = get_oss_process($item['image'], 0);
  482. $item['count'] = 0;
  483. $specialSourceId = SpecialSource::alias('ss')
  484. ->where('ss.special_id', $item['id'])
  485. ->field('ss.*, sw.viewing_time, sw.percentage')
  486. ->join('specialWatch sw', 'ss.special_id = sw.special_id and sw.uid = ' . $this->uid, 'left')
  487. ->select();
  488. if ($specialSourceId) $item['count'] = count($specialSourceId);
  489. foreach ($specialSourceId as $v) {
  490. if ($v['percentage'] < 100) {
  491. $flag = 0;
  492. break;
  493. }
  494. }
  495. if ($flag == 1){
  496. //关联试题
  497. //判断是否有考试
  498. $join1 = [
  499. ['ExaminationRecord er', 'er.test_id = r.relation_id and er.uid = ' . $this->uid, 'left'],
  500. ];
  501. $examlist = Relation::alias('r')
  502. ->where('r.relationship_id', $item['id'])
  503. ->where('r.relationship', 2)
  504. ->field('r.relation_id as test_id, er.score')->join($join1)->select();
  505. if ($examlist) {
  506. foreach ($examlist as $v) {
  507. if ($v['score'] < 60) {
  508. $flag = 0;
  509. break;
  510. }
  511. }
  512. }
  513. }
  514. if ($flag == 1) {
  515. $orderList1[] = $item;
  516. }
  517. }
  518. return JsonService::successful($orderList1);
  519. }
  520. //时长获取
  521. if ($op == 'shichanglist'){
  522. $model = SpecialBuy::alias('sb')->where('sb.uid', $this->uid)->page((int)$page, (int)$limit);
  523. $model = $model->join('Special s', 's.id = sb.special_id');
  524. $model = $model->join('specialSubject ss', 's.subject_id = ss.id');
  525. $orderList = $model->order('sb.add_time DESC')->field('s.*, sb.add_time as log_time, ss.name as subject_name')->select();
  526. $orderList = count($orderList) > 0 ? $orderList->toArray() : [];
  527. foreach ($orderList as &$item) {
  528. if (!isset($item['money'])) $item['money'] = 0;
  529. $item['money'] = (float)$item['money'];
  530. $item['image'] = get_oss_process($item['image'], 0);
  531. $item['count'] = 0;
  532. $item['shichang'] = 0;
  533. $specialSourceId = SpecialSource::alias('ss')
  534. ->where('ss.special_id', $item['id'])
  535. ->field('ss.*, sw.viewing_time, sw.percentage')
  536. ->join('specialWatch sw', 'ss.special_id = sw.special_id and sw.uid = ' . $this->uid, 'left')
  537. ->select();
  538. if ($specialSourceId) $item['count'] = count($specialSourceId);
  539. foreach ($specialSourceId as $v) {
  540. $item['shichang'] += $v['viewing_time'];
  541. }
  542. }
  543. return JsonService::successful($orderList);
  544. }
  545. return $this->fetch();
  546. }
  547. }