From a4b369c59dead423bd3486fd2afa197b6f0bc64c Mon Sep 17 00:00:00 2001 From: 15090180611 <215509543@qq.com> Date: Thu, 14 Nov 2024 18:40:04 +0800 Subject: [PATCH] =?UTF-8?q?1=EF=BC=8C=E8=AF=BE=E6=97=B6=E7=AE=A1=E7=90=86?= =?UTF-8?q?=EF=BC=88=E6=9C=BA=E6=9E=84=E7=AB=AF=E5=92=8C=E6=80=BB=E5=90=8E?= =?UTF-8?q?=E5=8F=B0=E7=AB=AF=EF=BC=89=202=EF=BC=8C=E6=95=99=E5=B8=88?= =?UTF-8?q?=E7=AE=A1=E7=90=86=EF=BC=88=E6=9C=BA=E6=9E=84=E7=AB=AF=E5=92=8C?= =?UTF-8?q?=E6=80=BB=E5=90=8E=E5=8F=B0=E7=AB=AF=EF=BC=89=203=EF=BC=8C?= =?UTF-8?q?=E8=AF=BE=E7=A8=8B=E7=94=9F=E6=88=90=E8=99=9A=E6=8B=9F=E5=8F=82?= =?UTF-8?q?=E4=B8=8E=E8=80=85=EF=BC=88=E6=9C=BA=E6=9E=84=E7=AB=AF=E5=92=8C?= =?UTF-8?q?=E6=80=BB=E5=90=8E=E5=8F=B0=E7=AB=AF=EF=BC=89=204=EF=BC=8C?= =?UTF-8?q?=E8=AF=BE=E7=A8=8B=E6=89=A9=E5=B1=95=E5=85=8D=E8=B4=B9=E8=AF=BE?= =?UTF-8?q?=E7=A8=8B=E5=B9=B6=E5=AE=9E=E7=8E=B0=E6=9C=BA=E6=9E=84=E7=AB=AF?= =?UTF-8?q?=E8=AF=BE=E7=A8=8B=E6=8F=90=E4=BA=A4=E5=AE=A1=E6=A0=B8=205?= =?UTF-8?q?=EF=BC=8C=E8=AE=BE=E8=AE=A1=E6=8E=88=E6=9D=83=E6=9C=BA=E6=9E=84?= =?UTF-8?q?=E7=94=A8=E6=88=B7=E9=80=BB=E8=BE=91=E8=A1=A8=E5=92=8C=E7=AB=99?= =?UTF-8?q?=E5=86=85=E4=BF=A1=E8=A1=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../admin/controller/famysql/Field.php | 2 +- .../controller/school/classes/ClassesLib.php | 58 ++++- .../controller/school/classes/ClassesSpec.php | 7 +- .../controller/school/classes/Teacher.php | 201 ++++++++++++++++- .../controller/school/classes/VirtualUser.php | 57 ++++- application/admin/controller/user/User.php | 147 ++++++++++++- .../lang/zh-cn/school/classes/classes_lib.php | 2 +- .../view/school/classes/classes_lib/add.html | 1 + .../view/school/classes/classes_lib/edit.html | 1 + .../view/school/classes/classes_spec/add.html | 26 +-- .../school/classes/classes_spec/edit.html | 24 +- .../view/school/classes/teacher/add.html | 16 +- .../view/school/classes/teacher/edit.html | 14 +- .../view/school/classes/virtual_user/add.html | 22 +- application/common/controller/Backend.php | 52 +++++ .../common/controller/ManystoreBase.php | 80 ++++++- application/common/library/Virtual.php | 2 + .../common/model/dyqc/ManystoreShop.php | 128 ++++++++++- .../model/school/classes/order/Order.php | 9 +- .../controller/school/classes/ClassesLib.php | 88 +++++++- .../controller/school/classes/ClassesSpec.php | 6 +- .../controller/school/classes/Teacher.php | 208 +++++++++++++++++- .../controller/school/classes/VirtualUser.php | 64 +++++- .../lang/zh-cn/school/classes/teacher.php | 2 +- .../view/school/classes/classes_lib/add.html | 58 ++--- .../view/school/classes/classes_lib/edit.html | 27 ++- .../school/classes/classes_lib/index.html | 5 + .../view/school/classes/classes_spec/add.html | 26 +-- .../school/classes/classes_spec/edit.html | 26 +-- .../view/school/classes/teacher/add.html | 16 +- .../view/school/classes/teacher/edit.html | 15 +- .../view/school/classes/virtual_user/add.html | 64 +++--- .../school/classes/virtual_user/edit.html | 3 +- .../js/backend/school/classes/classes_lib.js | 86 +++++++- .../js/backend/school/classes/classes_spec.js | 4 +- .../js/backend/school/classes/teacher.js | 4 +- .../js/backend/school/classes/virtual_user.js | 6 +- .../manystore/school/classes/classes_lib.js | 86 +++++++- .../manystore/school/classes/classes_spec.js | 11 +- .../js/manystore/school/classes/teacher.js | 35 +-- .../manystore/school/classes/virtual_user.js | 10 +- 41 files changed, 1473 insertions(+), 226 deletions(-) diff --git a/application/admin/controller/famysql/Field.php b/application/admin/controller/famysql/Field.php index 3f7781c..00cc4ea 100644 --- a/application/admin/controller/famysql/Field.php +++ b/application/admin/controller/famysql/Field.php @@ -576,7 +576,7 @@ class Field extends Backend return $typeList; } - protected function getCommonFields($fields = '') + public function getCommonFields($fields = '') { $fieldList = include ADDON_PATH . 'famysql' . DS . 'data' . DS . 'fields.php'; diff --git a/application/admin/controller/school/classes/ClassesLib.php b/application/admin/controller/school/classes/ClassesLib.php index 1b74ba2..a2e269c 100644 --- a/application/admin/controller/school/classes/ClassesLib.php +++ b/application/admin/controller/school/classes/ClassesLib.php @@ -180,7 +180,8 @@ class ClassesLib extends Backend protected function update_check(&$params,$row=null) { - $shop_id = $row["shop_id"]; + + $shop_id = $params["shop_id"]; $manystore = Manystore::where("shop_id",$shop_id)->find(); if(!$manystore){ $this->error("店铺不存在"); @@ -189,7 +190,7 @@ class ClassesLib extends Backend //验证老师id - $teacher_id = $row['teacher_id']; + $teacher_id = $params['teacher_id']; $teacher = \app\admin\model\school\classes\Teacher::where("id",$teacher_id)->find(); if(!$teacher){ $this->error("老师不存在"); @@ -215,11 +216,48 @@ class ClassesLib extends Backend || empty($params["longitude"]) || empty($params["latitude"])) $this->error("独立地点需传定位信息"); + }else{ + //地址取机构的 + $shop = ManystoreShop::where("id",$shop_id)->find(); + if(!$shop){ + $this->error("店铺不存在"); + } + if(empty($shop["address_city"]) + || empty($shop["province"]) + || empty($shop["city"]) + || empty($shop["district"]) + || empty($shop["longitude"]) + || empty($shop["latitude"])) $this->error("当前机构地址并未完善,请在机构处完善!"); + + + + $params["address_city"] = $shop["address_city"]; + $params["province"] = $shop["province"]; + $params["city"] = $shop["city"]; + $params["district"] = $shop["district"]; + $params["longitude"] = $shop["longitude"]; + $params["latitude"] = $shop["latitude"]; + } //特有认证判断 $this->authClasses($params,$row); // var_dump($row);die; + + //收费免费判断 + if($params["price"]==0){ + $params["feel"] = "1"; + }else{ + + //个人认证无法下付费课程 + $shop = ManystoreShop::where("id",$shop_id)->find(); + if($shop["type"]=="1"){ + $this->error("这个机构属于个人认证,无法发布付费课程!"); + } + + $params["feel"] = "0"; + } + //更新 if($row){ $this->have_auth = false; @@ -234,10 +272,26 @@ class ClassesLib extends Backend } $this->updateCheck($row->id,$params,$row); + + + //名称title不能与其他课程重复 + $check_title = $this->model->where('id','<>',$row["id"])->where('title',$params["title"])->find(); + if($check_title){ + $this->error("课程名称已存在或被其他机构占用,请更改!"); + } + + }else{ //新增 $params["add_type"] = '2'; $params["add_id"] = $this->auth->id; + + + //名称title不能重复 + $check_title = $this->model->where('title',$params["title"])->find(); + if($check_title){ + $this->error("课程名称已存在或被其他机构占用,请更改!"); + } } } diff --git a/application/admin/controller/school/classes/ClassesSpec.php b/application/admin/controller/school/classes/ClassesSpec.php index 8140743..9cf5910 100644 --- a/application/admin/controller/school/classes/ClassesSpec.php +++ b/application/admin/controller/school/classes/ClassesSpec.php @@ -18,10 +18,15 @@ class ClassesSpec extends Backend */ protected $model = null; + protected $qSwitch = true; + protected $qFields = ["classes_lib_id"]; + + public function _initialize() { - parent::_initialize(); $this->model = new \app\admin\model\school\classes\ClassesSpec; + parent::_initialize(); + $this->view->assign("statusList", $this->model->getStatusList()); } diff --git a/application/admin/controller/school/classes/Teacher.php b/application/admin/controller/school/classes/Teacher.php index 2a6b2e1..b6dadd9 100644 --- a/application/admin/controller/school/classes/Teacher.php +++ b/application/admin/controller/school/classes/Teacher.php @@ -3,7 +3,16 @@ namespace app\admin\controller\school\classes; use app\common\controller\Backend; +use app\common\model\User; +use app\manystore\model\Manystore; use fast\Tree; +use think\Db; +use think\db\exception\DataNotFoundException; +use think\db\exception\ModelNotFoundException; +use think\Exception; +use think\exception\DbException; +use think\exception\PDOException; +use think\exception\ValidateException; use think\Model; /** @@ -23,11 +32,14 @@ class Teacher extends Backend protected $selectpageFields = 'id,name,head_image,manystore_id,shop_id,user_id'; protected $searchFields = 'id,name,user_id'; + protected $qSwitch = true; + protected $qFields = ["manystore_id","shop_id"]; public function _initialize() { - parent::_initialize(); $this->model = new \app\admin\model\school\classes\Teacher; + parent::_initialize(); + $this->view->assign("statusList", $this->model->getStatusList()); } @@ -218,4 +230,191 @@ class Teacher extends Backend return json(['list' => $list, 'total' => $total]); } + + + protected function updateCheck($id,$params=[],$row=null){ + + // 课程存在售后订单则不允许操作 + } + + + protected function update_check(&$params,$row=null) + { + + $shop_id = $params["shop_id"]; + $manystore = Manystore::where("shop_id",$shop_id)->find(); + if(!$manystore){ + $this->error("店铺不存在"); + } + //用户不存在 + $user_id = $params["user_id"]; + $user = User::where("id",$user_id)->find(); + if(!$user){ + $this->error("用户不存在"); + } + + //修改 + if($row){ + //用户已是其他的教师(搜索) + $teacher_user = $this->model->where("user_id",$user_id)->where("id","<>",$row["id"])->find(); + if($teacher_user){ + $this->error("用户已存在或已是其他授权机构教师!"); + } + }else{ + //新增 + //用户已是教师(搜索) + $teacher_user = $this->model->where("user_id",$user_id)->find(); + if($teacher_user){ + $this->error("用户已存在或已是其他授权机构教师!"); + } + } + + + + + + + + $params["manystore_id"] = $manystore["id"]; + } + + + /** + * 添加 + * + * @return string + * @throws \think\Exception + */ + public function add() + { + if (false === $this->request->isPost()) { + return $this->view->fetch(); + } + $params = $this->request->post('row/a'); + if (empty($params)) { + $this->error(__('Parameter %s can not be empty', '')); + } + $params = $this->preExcludeFields($params); + + if ($this->dataLimit && $this->dataLimitFieldAutoFill) { + $params[$this->dataLimitField] = $this->auth->id; + } + $result = false; + Db::startTrans(); + try { + //是否采用模型验证 + if ($this->modelValidate) { + $name = str_replace("\\model\\", "\\validate\\", get_class($this->model)); + $validate = is_bool($this->modelValidate) ? ($this->modelSceneValidate ? $name . '.add' : $name) : $this->modelValidate; + $this->model->validateFailException()->validate($validate); + } + $this->update_check($params,$row=null); + $result = $this->model->allowField(true)->save($params); + Db::commit(); + } catch (ValidateException|PDOException|Exception $e) { + Db::rollback(); + $this->error($e->getMessage()); + } + if ($result === false) { + $this->error(__('No rows were inserted')); + } + $this->success(); + } + + /** + * 编辑 + * + * @param $ids + * @return string + * @throws DbException + * @throws \think\Exception + */ + public function edit($ids = null) + { + $row = $this->model->get($ids); + if (!$row) { + $this->error(__('No Results were found')); + } + $adminIds = $this->getDataLimitAdminIds(); + if (is_array($adminIds) && !in_array($row[$this->dataLimitField], $adminIds)) { + $this->error(__('You have no permission')); + } + if (false === $this->request->isPost()) { + $this->view->assign('row', $row); + return $this->view->fetch(); + } + $params = $this->request->post('row/a'); + if (empty($params)) { + $this->error(__('Parameter %s can not be empty', '')); + } + $params = $this->preExcludeFields($params); + $result = false; + Db::startTrans(); + try { + //是否采用模型验证 + if ($this->modelValidate) { + $name = str_replace("\\model\\", "\\validate\\", get_class($this->model)); + $validate = is_bool($this->modelValidate) ? ($this->modelSceneValidate ? $name . '.edit' : $name) : $this->modelValidate; + $row->validateFailException()->validate($validate); + } + $this->update_check($params,$row); + $result = $row->allowField(true)->save($params); + Db::commit(); + } catch (ValidateException|PDOException|Exception $e) { + Db::rollback(); + $this->error($e->getMessage()); + } + if (false === $result) { + $this->error(__('No rows were updated')); + } + $this->success(); + } + + /** + * 删除 + * + * @param $ids + * @return void + * @throws DbException + * @throws DataNotFoundException + * @throws ModelNotFoundException + */ + public function del($ids = null) + { + if (false === $this->request->isPost()) { + $this->error(__("Invalid parameters")); + } + $ids = $ids ?: $this->request->post("ids"); + if (empty($ids)) { + $this->error(__('Parameter %s can not be empty', 'ids')); + } + $pk = $this->model->getPk(); + $adminIds = $this->getDataLimitAdminIds(); + if (is_array($adminIds)) { + $this->model->where($this->dataLimitField, 'in', $adminIds); + } + $list = $this->model->where($pk, 'in', $ids)->select(); + foreach ($list as $item) { + $this->updateCheck($item->id); + } + + + $count = 0; + Db::startTrans(); + try { + foreach ($list as $item) { + $count += $item->delete(); + } + Db::commit(); + } catch (PDOException|Exception $e) { + Db::rollback(); + $this->error($e->getMessage()); + } + if ($count) { + $this->success(); + } + $this->error(__('No rows were deleted')); + } + + } diff --git a/application/admin/controller/school/classes/VirtualUser.php b/application/admin/controller/school/classes/VirtualUser.php index a35ccc2..41a0b06 100644 --- a/application/admin/controller/school/classes/VirtualUser.php +++ b/application/admin/controller/school/classes/VirtualUser.php @@ -3,6 +3,11 @@ namespace app\admin\controller\school\classes; use app\common\controller\Backend; +use app\common\library\Virtual; +use think\Db; +use think\Exception; +use think\exception\PDOException; +use think\exception\ValidateException; /** * 课程虚拟参与者 @@ -17,11 +22,14 @@ class VirtualUser extends Backend * @var \app\admin\model\school\classes\VirtualUser */ protected $model = null; + protected $qSwitch = true; + protected $qFields = ["classes_lib_id"]; public function _initialize() { - parent::_initialize(); $this->model = new \app\admin\model\school\classes\VirtualUser; + parent::_initialize(); + $this->view->assign("jointypeList", $this->model->getJointypeList()); $this->view->assign("havetypeList", $this->model->getHavetypeList()); } @@ -70,4 +78,51 @@ class VirtualUser extends Backend return $this->view->fetch(); } + + + + /** + * 添加 + * + * @return string + * @throws \think\Exception + */ + public function add() + { + if (false === $this->request->isPost()) { + return $this->view->fetch(); + } + $params = $this->request->post('row/a'); + if (empty($params)) { + $this->error(__('Parameter %s can not be empty', '')); + } + $params = $this->preExcludeFields($params); + + if ($this->dataLimit && $this->dataLimitFieldAutoFill) { + $params[$this->dataLimitField] = $this->auth->id; + } + $result = false; + Db::startTrans(); + try { + //是否采用模型验证 +// if ($this->modelValidate) { +// $name = str_replace("\\model\\", "\\validate\\", get_class($this->model)); +// $validate = is_bool($this->modelValidate) ? ($this->modelSceneValidate ? $name . '.add' : $name) : $this->modelValidate; +// $this->model->validateFailException()->validate($validate); +// } +// $result = $this->model->allowField(true)->save($params); + if(!$params["classes_lib_id"])throw new Exception( "请选择课程"); + $res = (new Virtual)->getVirtualUser($params["num"],$params["classes_lib_id"],$params["time"],true); + $result = true; + Db::commit(); + } catch (ValidateException|PDOException|Exception $e) { + Db::rollback(); + $this->error($e->getMessage().$e->getFile().$e->getLine()); + } + if ($result === false) { + $this->error(__('No rows were inserted')); + } + $this->success(); + } + } diff --git a/application/admin/controller/user/User.php b/application/admin/controller/user/User.php index 6908ad6..3ce698a 100644 --- a/application/admin/controller/user/User.php +++ b/application/admin/controller/user/User.php @@ -4,6 +4,8 @@ namespace app\admin\controller\user; use app\common\controller\Backend; use app\common\library\Auth; +use fast\Tree; +use think\Model; /** * 会员管理 @@ -15,7 +17,7 @@ class User extends Backend protected $relationSearch = true; protected $searchFields = 'id,username,nickname'; - + protected $selectpageFields = '*'; /** * @var \app\admin\model\User */ @@ -102,4 +104,147 @@ class User extends Backend $this->success(); } + + + /** + * Selectpage的实现方法 + * + * 当前方法只是一个比较通用的搜索匹配,请按需重载此方法来编写自己的搜索逻辑,$where按自己的需求写即可 + * 这里示例了所有的参数,所以比较复杂,实现上自己实现只需简单的几行即可 + * + */ + protected function selectpage() + { + //设置过滤方法 + $this->request->filter(['trim', 'strip_tags', 'htmlspecialchars']); + + //搜索关键词,客户端输入以空格分开,这里接收为数组 + $word = (array)$this->request->request("q_word/a"); + //当前页 + $page = $this->request->request("pageNumber"); + //分页大小 + $pagesize = $this->request->request("pageSize"); + //搜索条件 + $andor = $this->request->request("andOr", "and", "strtoupper"); + //排序方式 + $orderby = (array)$this->request->request("orderBy/a"); + //显示的字段 + $field = $this->request->request("showField"); + //主键 + $primarykey = $this->request->request("keyField"); + //主键值 + $primaryvalue = $this->request->request("keyValue"); + //搜索字段 + $searchfield = (array)$this->request->request("searchField/a"); + //自定义搜索条件 + $custom = (array)$this->request->request("custom/a"); + //是否返回树形结构 + $istree = $this->request->request("isTree", 0); + $ishtml = $this->request->request("isHtml", 0); + if ($istree) { + $word = []; + $pagesize = 999999; + } + $order = []; + foreach ($orderby as $k => $v) { + $order[$v[0]] = $v[1]; + } + $field = $field ? $field : 'name'; + + //如果有primaryvalue,说明当前是初始化传值 + if ($primaryvalue !== null) { + $where = [$primarykey => ['in', $primaryvalue]]; + $pagesize = 999999; + } else { + $where = function ($query) use ($word, $andor, $field, $searchfield, $custom) { + $logic = $andor == 'AND' ? '&' : '|'; + $searchfield = is_array($searchfield) ? implode($logic, $searchfield) : $searchfield; + $searchfield = str_replace(',', $logic, $searchfield); + $word = array_filter(array_unique($word)); + if (count($word) == 1) { + $query->where($searchfield, "like", "%" . reset($word) . "%"); + } else { + $query->where(function ($query) use ($word, $searchfield) { + foreach ($word as $index => $item) { + $query->whereOr(function ($query) use ($item, $searchfield) { + $query->where($searchfield, "like", "%{$item}%"); + }); + } + }); + } + if ($custom && is_array($custom)) { + foreach ($custom as $k => $v) { + if (is_array($v) && 2 == count($v)) { + $query->where($k, trim($v[0]), $v[1]); + } else { + $query->where($k, '=', $v); + } + } + } + }; + } + $adminIds = $this->getDataLimitAdminIds(); + if (is_array($adminIds)) { + $this->model->where($this->dataLimitField, 'in', $adminIds); + } + $list = []; + $total = $this->model->where($where)->count(); + if ($total > 0) { + if (is_array($adminIds)) { + $this->model->where($this->dataLimitField, 'in', $adminIds); + } + + $fields = is_array($this->selectpageFields) ? $this->selectpageFields : ($this->selectpageFields && $this->selectpageFields != '*' ? explode(',', $this->selectpageFields) : []); + + //如果有primaryvalue,说明当前是初始化传值,按照选择顺序排序 + if ($primaryvalue !== null && preg_match("/^[a-z0-9_\-]+$/i", $primarykey)) { + $primaryvalue = array_unique(is_array($primaryvalue) ? $primaryvalue : explode(',', $primaryvalue)); + //修复自定义data-primary-key为字符串内容时,给排序字段添加上引号 + $primaryvalue = array_map(function ($value) { + return '\'' . $value . '\''; + }, $primaryvalue); + + $primaryvalue = implode(',', $primaryvalue); + + $this->model->orderRaw("FIELD(`{$primarykey}`, {$primaryvalue})"); + } else { + $this->model->order($order); + } + + $datalist = $this->model->where($where) + ->page($page, $pagesize) + ->select(); + + foreach ($datalist as $index => $item) { + unset($item['password'], $item['salt']); + if ($this->selectpageFields == '*') { + $result = [ + $primarykey => $item[$primarykey] ?? '', + $field => $item[$field] ?? '', + 'nickname' => isset($item['nickname']) ? $item['nickname'] : '', + 'mobile' => isset($item['mobile']) ? $item['mobile'] : '', + 'realname' => isset($item['realname']) ? $item['realname'] : '', + ]; + } else { + $result = array_intersect_key(($item instanceof Model ? $item->toArray() : (array)$item), array_flip($fields)); + } + $result['pid'] = isset($item['pid']) ? $item['pid'] : (isset($item['parent_id']) ? $item['parent_id'] : 0); + $list[] = $result; + } + if ($istree && !$primaryvalue) { + $tree = Tree::instance(); + $tree->init(collection($list)->toArray(), 'pid'); + $list = $tree->getTreeList($tree->getTreeArray(0), $field); + if (!$ishtml) { + foreach ($list as &$item) { + $item = str_replace(' ', ' ', $item); + } + unset($item); + } + } + } + //这里一定要返回有list这个字段,total是可选的,如果total<=list的数量,则会隐藏分页按钮 + return json(['list' => $list, 'total' => $total]); + } + } diff --git a/application/admin/lang/zh-cn/school/classes/classes_lib.php b/application/admin/lang/zh-cn/school/classes/classes_lib.php index e94ca9f..48ad08f 100644 --- a/application/admin/lang/zh-cn/school/classes/classes_lib.php +++ b/application/admin/lang/zh-cn/school/classes/classes_lib.php @@ -43,7 +43,7 @@ return [ 'Set status to 1' => '设为上架', 'Status 2' => '下架', 'Set status to 2' => '设为下架', - 'Status 3' => '平台下架', + 'Status 3' => '(审核课程)平台下架', 'Set status to 3' => '设为平台下架', 'Auth_status' => '审核状态', 'Auth_status 0' => '待审核', diff --git a/application/admin/view/school/classes/classes_lib/add.html b/application/admin/view/school/classes/classes_lib/add.html index 94740c8..8261553 100644 --- a/application/admin/view/school/classes/classes_lib/add.html +++ b/application/admin/view/school/classes/classes_lib/add.html @@ -224,6 +224,7 @@