Learn.php 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  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. $where[] = ['l.is_deleted','in','0,1'];
  35. if(input('first_id')) $where[] = ['first_id','=',input('first_id')];
  36. if(input('second_id')) $where[] = ['second_id','=',input('second_id')];
  37. $query = $this->_query($this->table)
  38. ->alias('l')
  39. ->field('l.*,m.name,m.headimg')
  40. ->leftJoin('store_member m','m.id = l.user_id')
  41. ->where($where);
  42. $query->order(' sort desc , id desc')->page();
  43. }
  44. /**
  45. * 数据列表处理
  46. * @auth true
  47. * @menu true
  48. * @param array $data
  49. * @throws \think\db\exception\DataNotFoundException
  50. * @throws \think\db\exception\ModelNotFoundException
  51. * @throws \think\exception\DbException
  52. */
  53. protected function _index_page_filter(&$data)
  54. {
  55. }
  56. protected function _form_filter(&$data)
  57. {
  58. if($this->request->isGet() && $this->request->action() == 'edit')
  59. {
  60. $info = UserLearn::where('id',input('id'))->find()->toArray();
  61. $user_info = User::where('id',$info['user_id'])->find()->toArray();
  62. $data['phone'] = $user_info['phone'] ? $user_info['phone'] : $user_info['email'];
  63. $this->first_id =$info['first_id'];
  64. $this->second_id =$info['second_id'];
  65. $this->type =$info['type'];
  66. }
  67. if($this->request->isPost()){
  68. $phone = input('phone');
  69. $user_id = User::where('phone|email',$phone)->value('id');
  70. if(!$user_id)$this->error('用户不存在');
  71. if(empty($data['end_time']))$this->error('请选择时间');
  72. $data['user_id'] = $user_id;
  73. if(isset($data['end_time'])) $data['end_int'] = strtotime($data['end_time']);
  74. }
  75. }
  76. /**
  77. * 添加
  78. * @auth true
  79. * @menu true
  80. * @throws \think\Exception
  81. * @throws \think\db\exception\DataNotFoundException
  82. * @throws \think\db\exception\ModelNotFoundException
  83. * @throws \think\exception\DbException
  84. * @throws \think\exception\PDOException
  85. */
  86. public function add()
  87. {
  88. $this->title = '添加';
  89. $this->first_id = input('first_id');
  90. $this->second_id = input('second_id');
  91. $this->type = input('type');
  92. $this->_form($this->table, 'form');
  93. }
  94. /**
  95. * 标签
  96. * @auth true
  97. * @menu true
  98. * @throws \think\Exception
  99. * @throws \think\db\exception\DataNotFoundException
  100. * @throws \think\db\exception\ModelNotFoundException
  101. * @throws \think\exception\DbException
  102. * @throws \think\exception\PDOException
  103. */
  104. public function edit()
  105. {
  106. $this->title = '编辑';
  107. $this->_form($this->table, 'form');
  108. }
  109. /**
  110. * 删除
  111. * @auth true
  112. * @menu true
  113. * @throws \think\Exception
  114. * @throws \think\exception\PDOException
  115. */
  116. public function del()
  117. {
  118. $this->_delete($this->table);
  119. }
  120. }