Studyplan.php 2.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  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 app\admin\model\study\Plan;
  13. use app\admin\model\study\PlanSteps;
  14. use app\admin\model\study\PlanItems;
  15. use app\wap\model\special\Special as SpecialModel;
  16. use service\JsonService;
  17. use think\Url;
  18. /**商品控制器
  19. * Class Store
  20. * @package app\wap\controller
  21. */
  22. class Studyplan extends AuthController{
  23. /*
  24. * 白名单
  25. * */
  26. public static function WhiteList(){
  27. return [
  28. 'index',
  29. 'detail',
  30. ];
  31. }
  32. public function index($page = 1, $limit = 20, $op = ''){
  33. if ($op == 'list') {
  34. $model = Plan::alias('p')->where('p.is_del', 0)->page((int)$page, (int)$limit);
  35. $model = $model->join('PlanBuy pb', 'pb.uid = ' . $this->uid .' and pb.planid = p.id ', 'left');
  36. $orderList = $model->order('p.shelf_time DESC')->field('p.*, pb.id as isbuy')->select();
  37. $orderList = count($orderList) > 0 ? $orderList->toArray() : [];
  38. return JsonService::successful($orderList);
  39. }
  40. return $this->fetch();
  41. }
  42. public function details($id = 0) {
  43. if (!$id) $this->failed('缺少参数,无法访问', Url::build('index/index'));
  44. $planinfo = Plan::get($id);
  45. if (!$planinfo) $this->failed('参数错误,无法访问', Url::build('index/index'));
  46. $planinfo['introduction'] = htmlspecialchars_decode($planinfo['introduction']);
  47. $steps = PlanSteps::where('is_del', 0)->where('pid', $id)->select();
  48. $stepids = [];
  49. foreach($steps as $v){
  50. $stepids[] = $v['id'];
  51. }
  52. $itemsList = [];
  53. $join = [
  54. ['special s', 's.id = it.cid and s.is_del = 0 and s.status = 1']
  55. ];
  56. $items = PlanItems::alias('it')->field('s.*, it.stepsid,it.pid')
  57. ->join($join)
  58. ->where('pid', $id)
  59. ->where('stepsid', 'in', $stepids)
  60. ->select();
  61. foreach ($items as $v) {
  62. $v['count'] = SpecialModel::numberChapters($v['type'], $v['id']);
  63. $itemsList[$v['stepsid']][] = $v->toArray();
  64. }
  65. $this->assign('steps', json_encode($steps));
  66. $this->assign('itemsList', json_encode($itemsList));
  67. $this->assign('planinfo', json_encode($planinfo));
  68. return $this->fetch();
  69. }
  70. }