From 771460f16dc95d5778a2954f1aba46143b80ca9b Mon Sep 17 00:00:00 2001 From: 15090180611 <215509543@qq.com> Date: Wed, 13 Nov 2024 19:04:06 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A4=9A=E6=A0=B7=E9=9D=92=E6=98=A5=E5=A4=9C?= =?UTF-8?q?=E6=A0=A1=201=EF=BC=8C=E8=AF=BE=E6=97=B6=E9=A2=84=E7=BA=A6?= =?UTF-8?q?=E8=AE=A2=E5=8D=95=E6=9B=B4=E6=96=B0=E8=AF=BE=E6=97=B6=E4=BF=A1?= =?UTF-8?q?=E6=81=AF=EF=BC=88=E5=91=98=E5=B7=A5=E7=AB=AF=E6=8E=A5=E5=8F=A3?= =?UTF-8?q?=EF=BC=89=202=EF=BC=8C=E8=AF=BE=E6=97=B6=E9=A2=84=E7=BA=A6?= =?UTF-8?q?=E8=AE=A2=E5=8D=95=E6=A0=B8=E9=94=80=E5=AE=8C=E6=88=90=EF=BC=88?= =?UTF-8?q?=E5=91=98=E5=B7=A5=E7=AB=AF=E6=8E=A5=E5=8F=A3=EF=BC=89=203?= =?UTF-8?q?=EF=BC=8C=E8=AF=BE=E7=A8=8B=E4=B8=8A=E6=96=B0=EF=BC=88=E6=80=BB?= =?UTF-8?q?=E5=90=8E=E5=8F=B0=EF=BC=89=204=EF=BC=8C=E8=AF=BE=E7=A8=8B?= =?UTF-8?q?=E4=B8=8A=E6=96=B0=EF=BC=88=E6=9C=BA=E6=9E=84=E5=90=8E=E5=8F=B0?= =?UTF-8?q?=EF=BC=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../admin/controller/school/SearchCity.php | 37 + .../admin/controller/school/classes/Cate.php | 1 + .../controller/school/classes/ClassesLib.php | 303 +++++++ .../controller/school/classes/Teacher.php | 148 +++ .../admin/lang/zh-cn/school/classes/cate.php | 3 + .../admin/lang/zh-cn/school/search_city.php | 9 + application/admin/model/school/SearchCity.php | 40 + .../admin/model/school/classes/Cate.php | 18 +- .../admin/model/school/classes/ClassesLib.php | 24 +- .../admin/validate/school/SearchCity.php | 27 + .../admin/view/school/classes/cate/add.html | 14 + .../admin/view/school/classes/cate/edit.html | 15 + .../view/school/classes/classes_lib/add.html | 142 ++- .../view/school/classes/classes_lib/edit.html | 145 +-- .../admin/view/school/search_city/add.html | 20 + .../admin/view/school/search_city/edit.html | 20 + .../admin/view/school/search_city/index.html | 29 + .../view/school/search_city/recyclebin.html | 25 + application/api/controller/school/Order.php | 24 + .../controller/school/worker/HourOrder.php | 91 +- .../api/controller/school/worker/Order.php | 31 +- application/common/model/school/Area.php | 21 + .../model/school/classes/hourorder/Order.php | 157 ++++ .../model/school/classes/order/Order.php | 142 ++- .../controller/school/classes/ClassesLib.php | 326 ++++++- .../lang/zh-cn/school/classes/classes_lib.php | 2 +- .../model/school/classes/ClassesLib.php | 23 +- .../view/school/classes/classes_lib/add.html | 345 +++---- .../view/school/classes/classes_lib/edit.html | 344 +++---- public/assets/css/frontend.css | 852 +----------------- public/assets/css/skins/skin-black.css | 60 +- public/assets/js/addons.js | 4 + .../assets/js/backend/dyqc/manystore_shop.js | 73 ++ public/assets/js/backend/example/tablelink.js | 81 -- public/assets/js/backend/famysql/field.js | 159 +--- public/assets/js/backend/famysql/table.js | 359 +------- .../assets/js/backend/general/attachment.js | 159 +--- .../assets/js/backend/school/classes/cate.js | 1 + .../js/backend/school/classes/classes_lib.js | 139 ++- .../assets/js/backend/school/search_city.js | 131 +++ .../manystore/school/classes/classes_lib.js | 151 +++- public/assets/less/bootstrap/grid.less | 84 -- 42 files changed, 2481 insertions(+), 2298 deletions(-) create mode 100644 application/admin/controller/school/SearchCity.php create mode 100644 application/admin/lang/zh-cn/school/search_city.php create mode 100644 application/admin/model/school/SearchCity.php create mode 100644 application/admin/validate/school/SearchCity.php create mode 100644 application/admin/view/school/search_city/add.html create mode 100644 application/admin/view/school/search_city/edit.html create mode 100644 application/admin/view/school/search_city/index.html create mode 100644 application/admin/view/school/search_city/recyclebin.html create mode 100644 application/common/model/school/Area.php create mode 100644 public/assets/js/backend/dyqc/manystore_shop.js create mode 100644 public/assets/js/backend/school/search_city.js diff --git a/application/admin/controller/school/SearchCity.php b/application/admin/controller/school/SearchCity.php new file mode 100644 index 0000000..dc97ed7 --- /dev/null +++ b/application/admin/controller/school/SearchCity.php @@ -0,0 +1,37 @@ +model = new \app\admin\model\school\SearchCity; + + } + + + + /** + * 默认生成的控制器所继承的父类中有index/add/edit/del/multi五个基础方法、destroy/restore/recyclebin三个回收站方法 + * 因此在当前控制器中可不用编写增删改查的代码,除非需要自己控制这部分逻辑 + * 需要将application/admin/library/traits/Backend.php中对应的方法复制到当前控制器,然后进行修改 + */ + + +} diff --git a/application/admin/controller/school/classes/Cate.php b/application/admin/controller/school/classes/Cate.php index 2c7e1f1..5a335f5 100644 --- a/application/admin/controller/school/classes/Cate.php +++ b/application/admin/controller/school/classes/Cate.php @@ -23,6 +23,7 @@ class Cate extends Backend parent::_initialize(); $this->model = new \app\admin\model\school\classes\Cate; $this->view->assign("statusList", $this->model->getStatusList()); + $this->view->assign("hotList", $this->model->getHotList()); } diff --git a/application/admin/controller/school/classes/ClassesLib.php b/application/admin/controller/school/classes/ClassesLib.php index d6f8f03..1b74ba2 100644 --- a/application/admin/controller/school/classes/ClassesLib.php +++ b/application/admin/controller/school/classes/ClassesLib.php @@ -2,7 +2,17 @@ namespace app\admin\controller\school\classes; +use app\admin\model\dyqc\ManystoreShop; use app\common\controller\Backend; +use app\common\model\school\classes\Order; +use app\manystore\model\Manystore; +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; /** * 机构课程库 @@ -18,6 +28,15 @@ class ClassesLib extends Backend */ protected $model = null; + //不用审核允许修改的字段 + protected $no_auth_fields = ['headimage','images','notice','content',"virtual_num","virtual_collect","underline_price"]; + + //更新数据是否需要触发审核开关 + protected $need_auth = false; + protected $have_auth = false; + + protected $success_auth = false; + public function _initialize() { parent::_initialize(); @@ -79,4 +98,288 @@ class ClassesLib extends Backend return $this->view->fetch(); } + + protected function authClasses(&$params,$row=null){ + //审核失败需填写原因 + if($params["auth_status"] == '2' && empty($params["reason"])){ + $this->error("审核失败需填写原因"); + } + + if($params["auth_status"] == '2'){ + //审核不通过会平台下架 + $params["status"] = '3'; + } + + //更新 + if($row){ + + if($params["auth_status"] != '1' && $row["auth_status"] == '1'){ + $this->error("审核已通过的课程不允许再修改审核状态!"); + } + + if($params["auth_status"] != '0' && $row["auth_status"] == '0'){ + //填写审核时间和审核人 + $params["auth_time"] = time(); + $params["admin_id"] = $this->auth->id; + if($params["auth_status"] == '1'){ + //审核通过 + $this->success_auth = true; + } + } + //审核通过 + if($this->success_auth){ + //如果是平台下架,则更新成正常下架 + if($params["status"] == '3') $params["status"] = '2'; + } + + }else{ + //新增 + } + + } + + protected function no_auth_fields_check($params,$row){ + + foreach ($params as $k=>$v){ + + //说明数值有变动 + //$params[$k] 去掉两端空格 + $params[$k] = trim($v); + + if($row[$k]!=$params[$k]){ + //当修改参数不在允许修改的字段中 + if(!in_array($k,$this->no_auth_fields)){ + + $this->have_auth = true;break; + + } + } + + } + + return $this->have_auth; + + } + + protected function updateCheck($id,$params=[],$row=null){ + if($params && $row){ + + if(!$this->no_auth_fields_check($params,$row)){ + return true; + } + } + + // 课程存在未完成订单则不允许操作 + $order = Order::where("classes_lib_id",$id)->where("status","in","0,3")->find(); + if($order)$this->error("存在正在使用中的课程订单或存在正在售后中的课程订单无法继续操作!"); + // 课程存在售后订单则不允许操作 + } + + + + protected function update_check(&$params,$row=null) + { + + $shop_id = $row["shop_id"]; + $manystore = Manystore::where("shop_id",$shop_id)->find(); + if(!$manystore){ + $this->error("店铺不存在"); + } + $params["manystore_id"] = $manystore["id"]; + + + //验证老师id + $teacher_id = $row['teacher_id']; + $teacher = \app\admin\model\school\classes\Teacher::where("id",$teacher_id)->find(); + if(!$teacher){ + $this->error("老师不存在"); + } + if(!$teacher["user_id"]){ + $this->error("当前老师没有前端用户!请换一个!"); + } + //老师与当前机构id不一致 + if($teacher["manystore_id"] != $manystore["id"]){ + $this->error("当前老师与当前机构不匹配,请换一个老师!"); + } + + + $params["user_id"] = $teacher["user_id"]; + + + //独立地点需传定位信息 + if($params["address_type"] == "2"){ + if(empty($params["address_city"]) + || empty($params["province"]) + || empty($params["city"]) + || empty($params["district"]) + || empty($params["longitude"]) + || empty($params["latitude"])) $this->error("独立地点需传定位信息"); + + } + + //特有认证判断 + $this->authClasses($params,$row); +// var_dump($row);die; + //更新 + if($row){ + $this->have_auth = false; + if($this->need_auth){ + //判断更新的变动数据 + $this->no_auth_fields_check($params,$row); + + if($this->have_auth){ + $params['status'] = "3"; + $params['auth_status'] = "0"; + } + } + + $this->updateCheck($row->id,$params,$row); + }else{ + //新增 + $params["add_type"] = '2'; + $params["add_id"] = $this->auth->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/Teacher.php b/application/admin/controller/school/classes/Teacher.php index 9de468e..2a6b2e1 100644 --- a/application/admin/controller/school/classes/Teacher.php +++ b/application/admin/controller/school/classes/Teacher.php @@ -3,6 +3,8 @@ namespace app\admin\controller\school\classes; use app\common\controller\Backend; +use fast\Tree; +use think\Model; /** * 机构老师 @@ -18,6 +20,10 @@ class Teacher extends Backend */ protected $model = null; + protected $selectpageFields = 'id,name,head_image,manystore_id,shop_id,user_id'; + protected $searchFields = 'id,name,user_id'; + + public function _initialize() { parent::_initialize(); @@ -70,4 +76,146 @@ class Teacher extends Backend return $this->view->fetch(); } + + + + /** + * 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] ?? '', + + ]; + } 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/cate.php b/application/admin/lang/zh-cn/school/classes/cate.php index 29e7fc8..33cf25a 100644 --- a/application/admin/lang/zh-cn/school/classes/cate.php +++ b/application/admin/lang/zh-cn/school/classes/cate.php @@ -2,6 +2,9 @@ return [ 'Name' => '分类名', + 'Hot' => '平台热门', + 'Hot 0' => '否', + 'Hot 1' => '是', 'Status' => '状态', 'Status 1' => '上架', 'Set status to 1'=> '设为上架', diff --git a/application/admin/lang/zh-cn/school/search_city.php b/application/admin/lang/zh-cn/school/search_city.php new file mode 100644 index 0000000..485980c --- /dev/null +++ b/application/admin/lang/zh-cn/school/search_city.php @@ -0,0 +1,9 @@ + '城市选择', + 'Province' => '省编号', + 'City' => '市编号', + 'District' => '县区编号', + 'Deletetime' => '删除时间' +]; diff --git a/application/admin/model/school/SearchCity.php b/application/admin/model/school/SearchCity.php new file mode 100644 index 0000000..b0f69be --- /dev/null +++ b/application/admin/model/school/SearchCity.php @@ -0,0 +1,40 @@ + __('Hot 0'), '1' => __('Hot 1')]; + } + + + public function getHotTextAttr($value, $data) + { + $value = $value ? $value : (isset($data['hot']) ? $data['hot'] : ''); + $list = $this->getHotList(); + return isset($list[$value]) ? $list[$value] : ''; + } } diff --git a/application/admin/model/school/classes/ClassesLib.php b/application/admin/model/school/classes/ClassesLib.php index 2d5e784..a5e313f 100644 --- a/application/admin/model/school/classes/ClassesLib.php +++ b/application/admin/model/school/classes/ClassesLib.php @@ -34,8 +34,30 @@ class ClassesLib extends Model 'recommend_text', 'hot_text', 'new_text', - 'selfhot_text' + 'selfhot_text', + 'classes_cate_title', + 'classes_label_title', ]; + + public function getClassesCateTitleAttr($value, $data) + { + $classes_cate_ids = (isset($data['classes_cate_ids']) ? $data['classes_cate_ids'] : ''); + if(!$classes_cate_ids) return ''; + //$classes_cate_ids 查询分类表 names 已逗号拼接返回 + $classes_cate_title = Cate::where('id','in',$classes_cate_ids)->column('name'); + return implode(',',$classes_cate_title); + } + + public function getClassesLabelTitleAttr($value, $data) + { + $classes_cate_ids = (isset($data['classes_label_ids']) ? $data['classes_label_ids'] : ''); + if(!$classes_cate_ids) return ''; + //$classes_cate_ids 查询分类表 names 已逗号拼接返回 + $classes_cate_title = Label::where('id','in',$classes_cate_ids)->column('name'); + return implode(',',$classes_cate_title); + } + + protected static function init() diff --git a/application/admin/validate/school/SearchCity.php b/application/admin/validate/school/SearchCity.php new file mode 100644 index 0000000..d0e5f35 --- /dev/null +++ b/application/admin/validate/school/SearchCity.php @@ -0,0 +1,27 @@ + [], + 'edit' => [], + ]; + +} diff --git a/application/admin/view/school/classes/cate/add.html b/application/admin/view/school/classes/cate/add.html index 6d8c4f6..578bda2 100644 --- a/application/admin/view/school/classes/cate/add.html +++ b/application/admin/view/school/classes/cate/add.html @@ -6,6 +6,20 @@ + +