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 @@