123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137 |
- <?php
- namespace app\Nutrition\controller;
- use app\common\model\User;
- use app\common\model\UserLearn;
- use library\Controller;
- use think\Db;
- /**
- * 会员学习服务
- * Class Label
- * @package app\utrition\controller
- */
- class Learn extends Controller
- {
- /**
- * 绑定数据表
- * @var string
- */
- protected $table = 'UserLearn';
- /**
- * 列表
- * @auth true
- * @menu true
- * @throws \think\Exception
- * @throws \think\db\exception\DataNotFoundException
- * @throws \think\db\exception\ModelNotFoundException
- * @throws \think\exception\DbException
- * @throws \think\exception\PDOException
- */
- public function index()
- {
- $this->title = '列表';
- $where= [];
- $where[] = ['type','=',input('type',1)];
- $where[] = ['l.is_deleted','in','0,1'];
- if(input('first_id')) $where[] = ['first_id','=',input('first_id')];
- if(input('second_id')) $where[] = ['second_id','=',input('second_id')];
- $query = $this->_query($this->table)
- ->alias('l')
- ->field('l.*,m.name,m.headimg')
- ->leftJoin('store_member m','m.id = l.user_id')
- ->where($where);
- $query->order(' sort desc , id desc')->page();
- }
- /**
- * 数据列表处理
- * @auth true
- * @menu true
- * @param array $data
- * @throws \think\db\exception\DataNotFoundException
- * @throws \think\db\exception\ModelNotFoundException
- * @throws \think\exception\DbException
- */
- protected function _index_page_filter(&$data)
- {
- }
- protected function _form_filter(&$data)
- {
- if($this->request->isGet() && $this->request->action() == 'edit')
- {
- $info = UserLearn::where('id',input('id'))->find()->toArray();
- $user_info = User::where('id',$info['user_id'])->find()->toArray();
- $data['phone'] = $user_info['phone'] ? $user_info['phone'] : $user_info['email'];
- $this->first_id =$info['first_id'];
- $this->second_id =$info['second_id'];
- $this->type =$info['type'];
- }
- if($this->request->isPost()){
- $phone = input('phone');
- $user_id = User::where('phone|email',$phone)->value('id');
- if(!$user_id)$this->error('用户不存在');
- if(empty($data['end_time']))$this->error('请选择时间');
- $data['user_id'] = $user_id;
- if(isset($data['end_time'])) $data['end_int'] = strtotime($data['end_time']);
- }
- }
- /**
- * 添加
- * @auth true
- * @menu true
- * @throws \think\Exception
- * @throws \think\db\exception\DataNotFoundException
- * @throws \think\db\exception\ModelNotFoundException
- * @throws \think\exception\DbException
- * @throws \think\exception\PDOException
- */
- public function add()
- {
- $this->title = '添加';
- $this->first_id = input('first_id');
- $this->second_id = input('second_id');
- $this->type = input('type');
- $this->_form($this->table, 'form');
- }
- /**
- * 标签
- * @auth true
- * @menu true
- * @throws \think\Exception
- * @throws \think\db\exception\DataNotFoundException
- * @throws \think\db\exception\ModelNotFoundException
- * @throws \think\exception\DbException
- * @throws \think\exception\PDOException
- */
- public function edit()
- {
- $this->title = '编辑';
- $this->_form($this->table, 'form');
- }
- /**
- * 删除
- * @auth true
- * @menu true
- * @throws \think\Exception
- * @throws \think\exception\PDOException
- */
- public function del()
- {
- $this->_delete($this->table);
- }
- }
|