Learn.php 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  1. <?php
  2. namespace app\Nutrition\controller;
  3. use app\common\model\User;
  4. use app\common\model\UserLearn;
  5. use library\Controller;
  6. use think\Db;
  7. /**
  8. * 会员学习服务
  9. * Class Label
  10. * @package app\utrition\controller
  11. */
  12. class Learn extends Controller
  13. {
  14. /**
  15. * 绑定数据表
  16. * @var string
  17. */
  18. protected $table = 'UserLearn';
  19. /**
  20. * 列表
  21. * @auth true
  22. * @menu true
  23. * @throws \think\Exception
  24. * @throws \think\db\exception\DataNotFoundException
  25. * @throws \think\db\exception\ModelNotFoundException
  26. * @throws \think\exception\DbException
  27. * @throws \think\exception\PDOException
  28. */
  29. public function index()
  30. {
  31. $this->title = '列表';
  32. $where= [];
  33. $where[] = ['type','=',input('type',1)];
  34. if(input('first_id')) $where[] = ['first_id','=',input('first_id')];
  35. if(input('second_id')) $where[] = ['second_id','=',input('second_id')];
  36. $query = $this->_query($this->table)
  37. ->alias('l')
  38. ->field('l.*,m.name,m.headimg')
  39. ->leftJoin('store_member m','m.id = l.user_id')
  40. ->where($where);
  41. $query->order(' sort desc , id desc')->page();
  42. }
  43. /**
  44. * 数据列表处理
  45. * @auth true
  46. * @menu true
  47. * @param array $data
  48. * @throws \think\db\exception\DataNotFoundException
  49. * @throws \think\db\exception\ModelNotFoundException
  50. * @throws \think\exception\DbException
  51. */
  52. protected function _index_page_filter(&$data)
  53. {
  54. }
  55. protected function _form_filter(&$data)
  56. {
  57. if($this->request->isGet() && $this->request->action() == 'edit')
  58. {
  59. $info = UserLearn::where('id',input('id'))->find()->toArray();
  60. $user_info = User::where('id',$info['user_id'])->find()->toArray();
  61. $data['phone'] = $user_info['phone'] ? $user_info['phone'] : $user_info['email'];
  62. $this->first_id =$info['first_id'];
  63. $this->second_id =$info['second_id'];
  64. $this->type =$info['type'];
  65. }
  66. if($this->request->isPost()){
  67. $phone = input('phone');
  68. $user_id = User::where('phone|email',$phone)->value('id');
  69. if(!$user_id)$this->error('用户不存在');
  70. if(empty($data['end_time']))$this->error('请选择时间');
  71. $data['user_id'] = $user_id;
  72. if(isset($data['end_time'])) $data['end_int'] = strtotime($data['end_time']);
  73. }
  74. }
  75. /**
  76. * 添加
  77. * @auth true
  78. * @menu true
  79. * @throws \think\Exception
  80. * @throws \think\db\exception\DataNotFoundException
  81. * @throws \think\db\exception\ModelNotFoundException
  82. * @throws \think\exception\DbException
  83. * @throws \think\exception\PDOException
  84. */
  85. public function add()
  86. {
  87. $this->title = '添加';
  88. $this->first_id = input('first_id');
  89. $this->second_id = input('second_id');
  90. $this->type = input('type');
  91. $this->_form($this->table, 'form');
  92. }
  93. /**
  94. * 标签
  95. * @auth true
  96. * @menu true
  97. * @throws \think\Exception
  98. * @throws \think\db\exception\DataNotFoundException
  99. * @throws \think\db\exception\ModelNotFoundException
  100. * @throws \think\exception\DbException
  101. * @throws \think\exception\PDOException
  102. */
  103. public function edit()
  104. {
  105. $this->title = '编辑';
  106. $this->_form($this->table, 'form');
  107. }
  108. /**
  109. * 删除
  110. * @auth true
  111. * @menu true
  112. * @throws \think\Exception
  113. * @throws \think\exception\PDOException
  114. */
  115. public function del()
  116. {
  117. $this->_delete($this->table);
  118. }
  119. }