| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425 | 
							- <?php
 
- namespace app\admin\controller;
 
- use app\admin\AdminBaseController;
 
- use app\common\model\SoldierModel;
 
- use app\common\model\SoldierVideoModel;
 
- use app\common\model\SoldierVideoSeriesModel;
 
- use app\common\model\SoldierVideoWatchModel;
 
- use app\common\validate\SoldierUserValidate;
 
- use app\common\validate\SoldierVideoSeriesValidate;
 
- use app\common\validate\SoldierVideoValidate;
 
- use think\exception\ValidateException;
 
- class Soldier extends AdminBaseController
 
- {
 
-     /**
 
-      * 用户列表
 
-      */
 
-     public function user()
 
-     {
 
-         return view('', [
 
-             'status_list' => SoldierModel::STATUS,
 
-         ]);
 
-     }
 
-     public function listUser()
 
-     {
 
-         $map   = $this->dealEqualInput(['status'], $this->dealLikeInput(['keywords' => 'name|mobile']));
 
-         $list  = SoldierModel::where($map)
 
-             ->order('id', 'desc')
 
-             ->limit(input('limit'))
 
-             ->page(input('page'))
 
-             ->append(['status_text'])->select();
 
-         $count = SoldierModel::where($map)->count();
 
-         if ($count == 0) {
 
-             ajax_return(1, '未查询到数据');
 
-         }
 
-         list_return($list, $count);
 
-     }
 
-     public function delUser()
 
-     {
 
-         $id = input('id/d', 0);
 
-         if (empty($id)) {
 
-             ajax_return(1, '未查询到数据');
 
-         }
 
-         SoldierModel::destroy($id);
 
-         SoldierVideoWatchModel::destroy(['user_id' => $id]);
 
-         ajax_return();
 
-     }
 
-     /**
 
-      * 编辑用户
 
-      */
 
-     public function userForm()
 
-     {
 
-         $id   = input('id/d', 0);
 
-         $info = SoldierModel::find($id);
 
-         return view('', [
 
-             'info'        => $info,
 
-             'status_list' => SoldierModel::STATUS,
 
-         ]);
 
-     }
 
-     public function editUser()
 
-     {
 
-         $data = input('post.');
 
-         try {
 
-             validate(SoldierUserValidate::class)->check($data);
 
-         } catch (ValidateException $e) {
 
-             ajax_return(1, $e->getError());
 
-         }
 
-         //手机号
 
-         $check_mobile_where = [['mobile', '=', $data['mobile']]];
 
-         if (!empty($data['id'])) {
 
-             $check_mobile_where[] = ['id', '<>', $data['id']];
 
-         }
 
-         $check_mobile = SoldierModel::where($check_mobile_where)->find();
 
-         if (!empty($check_mobile)) {
 
-             ajax_return(1, '手机号已存在');
 
-         }
 
-         //密码
 
-         if (empty($data['id']) && empty($data['password'])) {
 
-             ajax_return(1, '请输入一个初始密码');
 
-         }
 
-         if (empty($data['password'])) {
 
-             unset($data['password']);
 
-         } else {
 
-             $data['salt']     = rand_str();
 
-             $data['password'] = md5(md5($data['salt']) . $data['password']);
 
-         }
 
-         if (empty($data['id'])) {
 
-             SoldierModel::create($data);
 
-         } else {
 
-             SoldierModel::update($data, ['id' => $data['id']]);
 
-         }
 
-         ajax_return();
 
-     }
 
-     /**
 
-      * 用户导入
 
-      */
 
-     public function importUser()
 
-     {
 
-         return view('public/import', [
 
-             'url'           => url('soldier/importUserPost'),
 
-             'last_table'    => 'lay-soldier-user-table',
 
-             'template_file' => '/static/common/exl/soldier_user.xls',
 
-         ]);
 
-     }
 
-     /**
 
-      * 用户导入提交
 
-      */
 
-     public function importUserPost()
 
-     {
 
-         $file_url = input('file_url/s', "");
 
-         if (!file_exists($file_url)) {
 
-             ajax_return(1, '文件不存在');
 
-         }
 
-         //初始化数据
 
-         $data = ['name', 'mobile', 'password'];
 
-         $list = import_exl($file_url, $data, 1);
 
-         if (empty($list)) {
 
-             ajax_return(1, '请上传有数据的文件');
 
-         }
 
-         $empty_check = [
 
-             'name'     => '姓名',
 
-             'mobile'   => '手机号',
 
-             'password' => '密码',
 
-         ];
 
-         //获取手机号
 
-         $mobile_list       = array_column($list, 'mobile');
 
-         $mobile_check_list = SoldierModel::where('mobile', 'in', $mobile_list)->column('mobile');
 
-         //错误判断
 
-         $validate = \think\facade\Validate::rule('mobile', 'mobile');
 
-         foreach ($list as $k => $v) {
 
-             foreach ($empty_check as $key => $value) {
 
-                 if (empty($v[$key])) {
 
-                     return ajax_return(1, '第' . ($k + 2) . '行的' . $value . '不能为空');
 
-                 }
 
-             }
 
-             if (!$validate->check($v)) {
 
-                 return ajax_return(1, '第' . ($k + 2) . '行的手机号格式不对');
 
-             }
 
-             if (!empty(in_array($v['mobile'], $mobile_check_list))) {
 
-                 return ajax_return(1, '第' . ($k + 2) . '行的手机号已存在');
 
-             }
 
-             $list[$k]['salt']     = rand_str();
 
-             $list[$k]['password'] = md5(md5($list[$k]['salt']) . $v['password']);
 
-         }
 
-         SoldierModel::insertAll($list);
 
-         ajax_return(0);
 
-     }
 
-     /**
 
-      * 视频系列列表
 
-      */
 
-     public function videoSeries()
 
-     {
 
-         return view('', [
 
-             'status_list' => SoldierVideoSeriesModel::STATUS,
 
-         ]);
 
-     }
 
-     public function listVideoSeries()
 
-     {
 
-         $map   = $this->dealEqualInput(['status'], $this->dealLikeInput(['title']));
 
-         $list  = SoldierVideoSeriesModel::where($map)
 
-             ->order('priority desc,id desc')
 
-             ->limit(input('limit'))
 
-             ->page(input('page'))
 
-             ->append(['status_text'])->select();
 
-         $count = SoldierVideoSeriesModel::where($map)->count();
 
-         if ($count == 0) {
 
-             ajax_return(1, '未查询到数据');
 
-         }
 
-         list_return($list, $count);
 
-     }
 
-     public function delVideoSeries()
 
-     {
 
-         $id = input('id/d', 0);
 
-         if (empty($id)) {
 
-             ajax_return(1, '未查询到数据');
 
-         }
 
-         $check = SoldierVideoModel::where('series_id', $id)->find();
 
-         if (!empty($check)) {
 
-             ajax_return(1, '该系列下有视频,无法删除');
 
-         }
 
-         SoldierVideoSeriesModel::destroy($id);
 
-         ajax_return();
 
-     }
 
-     /**
 
-      * 编辑视频系列
 
-      */
 
-     public function videoSeriesForm()
 
-     {
 
-         $id   = input('id/d', 0);
 
-         $info = SoldierVideoSeriesModel::find($id);
 
-         return view('', [
 
-             'info'        => $info,
 
-             'status_list' => SoldierVideoSeriesModel::STATUS,
 
-         ]);
 
-     }
 
-     public function editVideoSeries()
 
-     {
 
-         $data = input('post.');
 
-         try {
 
-             validate(SoldierVideoSeriesValidate::class)->check($data);
 
-         } catch (ValidateException $e) {
 
-             ajax_return(1, $e->getError());
 
-         }
 
-         if (empty($data['id'])) {
 
-             SoldierVideoSeriesModel::create($data);
 
-         } else {
 
-             SoldierVideoSeriesModel::update($data);
 
-         }
 
-         ajax_return();
 
-     }
 
-     /**
 
-      * 视频列表
 
-      */
 
-     public function video()
 
-     {
 
-         $series_list = SoldierVideoSeriesModel::where('status', SoldierVideoSeriesModel::STATUS_SHOW)->order('priority desc')->select();
 
-         return view('', [
 
-             'status_list'  => SoldierVideoModel::STATUS,
 
-             'is_must_list' => SoldierVideoModel::IS_MUST,
 
-             'series_list'  => $series_list,
 
-         ]);
 
-     }
 
-     public function listVideo()
 
-     {
 
-         $map   = $this->dealEqualInput(['status', 'series_id', 'is_must'], $this->dealLikeInput(['title']));
 
-         $list  = SoldierVideoModel::with(['series'])
 
-             ->where($map)
 
-             ->order('priority desc,id desc')
 
-             ->limit(input('limit'))
 
-             ->page(input('page'))
 
-             ->append(['status_text', 'is_must_text'])->select();
 
-         $count = SoldierVideoModel::where($map)->count();
 
-         if ($count == 0) {
 
-             ajax_return(1, '未查询到数据');
 
-         }
 
-         list_return($list, $count);
 
-     }
 
-     public function fieldVideo()
 
-     {
 
-         $id   = input('id/d');
 
-         $cate = SoldierVideoModel::find($id);
 
-         if (empty($cate)) {
 
-             ajax_return(1, '视频信息不存在');
 
-         } else {
 
-             $cate->save([
 
-                 input('field/s') => input('value/s', ""),
 
-             ]);
 
-         }
 
-         ajax_return();
 
-     }
 
-     public function delVideo()
 
-     {
 
-         $id = input('id/d', 0);
 
-         if (empty($id)) {
 
-             ajax_return(1, '未查询到数据');
 
-         }
 
-         $check = SoldierVideoWatchModel::where('video_id', $id)->find();
 
-         if (!empty($check)) {
 
-             ajax_return(1, '该视频下有观看记录,无法删除');
 
-         }
 
-         SoldierVideoModel::destroy($id);
 
-         ajax_return();
 
-     }
 
-     /**
 
-      * 编辑视频
 
-      */
 
-     public function videoForm()
 
-     {
 
-         $id          = input('id/d', 0);
 
-         $series_list = SoldierVideoSeriesModel::where('status', SoldierVideoSeriesModel::STATUS_SHOW)->order('priority desc')->select();
 
-         $info        = SoldierVideoModel::find($id);
 
-         return view('', [
 
-             'info'         => $info,
 
-             'status_list'  => SoldierVideoModel::STATUS,
 
-             'is_must_list' => SoldierVideoModel::IS_MUST,
 
-             'series_list'  => $series_list,
 
-         ]);
 
-     }
 
-     public function editVideo()
 
-     {
 
-         $data = input('post.');
 
-         try {
 
-             validate(SoldierVideoValidate::class)->check($data);
 
-         } catch (ValidateException $e) {
 
-             ajax_return(1, $e->getError());
 
-         }
 
-         if (empty($data['id'])) {
 
-             SoldierVideoModel::create($data);
 
-         } else {
 
-             SoldierVideoModel::update($data);
 
-         }
 
-         ajax_return();
 
-     }
 
-     /**
 
-      * 观看记录
 
-      */
 
-     public function videoWatch()
 
-     {
 
-         $id = input('id/d', 0);
 
-         if (empty($id)) {
 
-             return '请选择视频';
 
-         }
 
-         return view('', [
 
-             'id' => $id,
 
-         ]);
 
-     }
 
-     public function listVideoWatch()
 
-     {
 
-         $id = input('id/d', 0);
 
-         if (empty($id)) {
 
-             ajax_return(1, '请选择视频');
 
-         }
 
-         $list  = SoldierVideoWatchModel::with(['user'])
 
-             ->where('video_id', $id)
 
-             ->limit(input('limit'))
 
-             ->page(input('page'))
 
-             ->append(['status_text'])
 
-             ->select();
 
-         $count = SoldierVideoWatchModel::where('video_id', $id)->count();
 
-         if ($count == 0) {
 
-             ajax_return(1, '未查询到数据');
 
-         }
 
-         list_return($list, $count);
 
-     }
 
-     public function exportVideoWatch()
 
-     {
 
-         $id = input('id/d', 0);
 
-         if (empty($id)) {
 
-             ajax_return(1, '请选择视频');
 
-         }
 
-         $video = SoldierVideoModel::find($id);
 
-         $list  = SoldierVideoWatchModel::with(['user'])->where('video_id', $id)->append(['status_text'])->select();
 
-         foreach ($list as $v) {
 
-             $v['user_name'] = $v['user']['name'];
 
-         }
 
-         $xlsCell = [
 
-             ['id', '表ID'],
 
-             ['user_name', '姓名'],
 
-             ['status_text', '状态'],
 
-             ['create_time', '首次学习时间'],
 
-             ['update_time', '最后学习时间'],
 
-         ];
 
-         export_exl($video['title'] . "的观看记录", $xlsCell, $list);
 
-     }
 
-     public function exportUserVideoWatch()
 
-     {
 
-         $id = input('id/d', 0);
 
-         if (empty($id)) {
 
-             ajax_return(1, '请选择视频');
 
-         }
 
-         $user       = SoldierModel::find($id);
 
-         $video_list = SoldierVideoModel::with('series')->where('status', SoldierVideoModel::STATUS_SHOW)->append(['is_must_text'])->order('priority desc,id desc')->select();
 
-         $watch_list = SoldierVideoWatchModel::where('user_id', $id)->column('*', 'video_id');
 
-         foreach ($video_list as $v) {
 
-             $v['series_name'] = $v['series']['title'];
 
-             if (empty($watch_list[$v['id']])) {
 
-                 $v['watch_status_text'] = SoldierVideoWatchModel::STATUS[SoldierVideoWatchModel::STATUS_NO_STARTED];
 
-                 $v['fist_time']         = $v['last_time'] = '';
 
-             } else {
 
-                 $v['watch_status_text'] = SoldierVideoWatchModel::STATUS[$watch_list[$v['id']]['status']];
 
-                 $v['fist_time']         = date('Y-m-d H:i:s', $watch_list[$v['id']]['create_time']);
 
-                 $v['last_time']         = date('Y-m-d H:i:s', $watch_list[$v['id']]['update_time']);
 
-             }
 
-         }
 
-         $xlsCell = [
 
-             ['series_name', '系列'],
 
-             ['title', '标题'],
 
-             ['is_must_text', '是否必修'],
 
-             ['watch_status_text', '观看状态'],
 
-             ['fist_time', '首次学习时间'],
 
-             ['last_time', '最后学习时间'],
 
-         ];
 
-         export_exl($user['name'] . "的观看记录", $xlsCell, $video_list);
 
-     }
 
- }
 
 
  |