From 63bf6801dcc7b8363f3cfffe8e62fb5dc2ae2b25 Mon Sep 17 00:00:00 2001 From: 15090180611 <215509543@qq.com> Date: Thu, 21 Nov 2024 18:03:23 +0800 Subject: [PATCH] =?UTF-8?q?1=EF=BC=8C=E4=BF=AE=E6=94=B9=E9=80=BB=E8=BE=91?= =?UTF-8?q?=E5=85=8D=E8=B4=B9=E8=AF=BE=E5=BC=80=E5=A7=8B=E5=92=8C=E7=BB=93?= =?UTF-8?q?=E6=9D=9F=E6=97=B6=E9=97=B4=E6=9C=89=E4=BA=A4=E5=8F=A0=E6=97=A0?= =?UTF-8?q?=E6=B3=95=E4=B8=8B=E9=A2=84=E7=BA=A6=202=EF=BC=8C=E4=BF=AE?= =?UTF-8?q?=E6=94=B9=E9=80=BB=E8=BE=91=E8=AF=BE=E7=A8=8B=E6=B7=BB=E5=8A=A0?= =?UTF-8?q?=E8=AF=BE=E6=97=B6=E6=97=B6=EF=BC=8C=E5=A6=82=E6=9E=9C=E5=BC=80?= =?UTF-8?q?=E5=A7=8B=E7=BB=93=E6=9D=9F=E6=97=B6=E9=97=B4=E5=92=8C=E5=85=B6?= =?UTF-8?q?=E4=BB=96=E8=AF=BE=E6=97=B6=E9=87=8D=E5=8F=A0=E5=BA=94=E8=AF=A5?= =?UTF-8?q?=E6=8B=92=E7=BB=9D=203=EF=BC=8C=E7=BC=96=E5=86=99=E6=97=A5?= =?UTF-8?q?=E5=8E=86=E6=8E=A5=E5=8F=A3=204,=20=E4=BC=98=E5=8C=96=E6=9C=BA?= =?UTF-8?q?=E6=9E=84=E5=90=8E=E5=8F=B0=E9=80=BB=E8=BE=91=EF=BC=8C=E6=B7=BB?= =?UTF-8?q?=E5=8A=A0=E6=97=B6=E8=87=AA=E5=8A=A8=E7=94=9F=E6=88=90=E8=99=9A?= =?UTF-8?q?=E6=8B=9F=E5=8F=82=E4=B8=8E=E4=BA=BA=E6=95=B0=205=EF=BC=8C?= =?UTF-8?q?=E6=9C=BA=E6=9E=84=E7=AB=AF=E5=A2=9E=E5=8A=A0=E6=8A=A5=E5=90=8D?= =?UTF-8?q?=E4=BA=BA=E6=9F=A5=E7=9C=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../admin/controller/school/Message.php | 5 +- .../controller/school/classes/ClassesLib.php | 53 +++++++- .../controller/school/classes/ClassesSpec.php | 68 ++++++++++ .../controller/school/classes/VirtualUser.php | 62 ++++++++- application/admin/model/school/Message.php | 3 +- .../admin/model/school/classes/ClassesLib.php | 3 +- .../model/school/classes/ClassesSpec.php | 3 +- .../view/school/classes/classes_lib/add.html | 12 +- .../view/school/classes/classes_lib/edit.html | 68 ++++++---- application/admin/view/user/user/edit.html | 21 +++ application/api/controller/Common.php | 27 +++- .../common/controller/ManystoreBase.php | 6 +- application/common/hooks.php | 16 +++ application/common/library/Virtual.php | 27 +++- .../common/listener/classes/ClassesHook.php | 84 +++++------- .../model/school/classes/ClassesLib.php | 27 ++++ .../model/school/classes/ClassesSpec.php | 2 +- .../model/school/classes/hourorder/Order.php | 58 ++++++++ .../controller/school/classes/ClassesLib.php | 27 +++- .../controller/school/classes/ClassesSpec.php | 68 ++++++++++ .../controller/school/classes/VirtualUser.php | 60 ++++++++ .../manystore/controller/user/User.php | 72 ++++++++++ .../manystore/lang/zh-cn/user/user.php | 35 +++++ .../model/school/classes/ClassesLib.php | 3 +- .../model/school/classes/ClassesSpec.php | 3 +- application/manystore/model/user/User.php | 87 ++++++++++++ application/manystore/validate/user/User.php | 27 ++++ .../manystore/view/general/profile/index.html | 3 + .../view/school/classes/classes_lib/add.html | 24 ++-- .../view/school/classes/classes_lib/edit.html | 76 ++++++----- application/manystore/view/user/user/add.html | 108 +++++++++++++++ .../manystore/view/user/user/edit.html | 122 +++++++++++++++++ .../manystore/view/user/user/index.html | 34 +++++ public/assets/js/backend/manystore/index.js | 28 +++- .../js/backend/school/classes/classes_lib.js | 23 +++- .../backend/school/classes/hourorder/order.js | 26 ++++ public/assets/js/backend/school/message.js | 2 +- public/assets/js/backend/user/user.js | 68 +++++++++- .../manystore/school/classes/classes_lib.js | 20 ++- .../school/classes/hourorder/order.js | 27 ++++ public/assets/js/manystore/user/user.js | 128 ++++++++++++++++++ 41 files changed, 1452 insertions(+), 164 deletions(-) create mode 100644 application/manystore/controller/user/User.php create mode 100644 application/manystore/lang/zh-cn/user/user.php create mode 100644 application/manystore/model/user/User.php create mode 100644 application/manystore/validate/user/User.php create mode 100644 application/manystore/view/user/user/add.html create mode 100644 application/manystore/view/user/user/edit.html create mode 100644 application/manystore/view/user/user/index.html create mode 100644 public/assets/js/manystore/user/user.js diff --git a/application/admin/controller/school/Message.php b/application/admin/controller/school/Message.php index 728d563..fb6d67d 100644 --- a/application/admin/controller/school/Message.php +++ b/application/admin/controller/school/Message.php @@ -54,11 +54,12 @@ class Message extends Backend return $this->selectpage(); } list($where, $sort, $order, $offset, $limit) = $this->buildparams(); - + $as = $this->model->getWithAlisaName(); $list = $this->model ->with(['admin','user']) ->where($where) - ->order($sort, $order) +// ->order($sort, $order) + ->order("{$as}.weigh DESC,{$as}.id DESC") ->paginate($limit); foreach ($list as $row) { diff --git a/application/admin/controller/school/classes/ClassesLib.php b/application/admin/controller/school/classes/ClassesLib.php index 9eabad6..a0725a5 100644 --- a/application/admin/controller/school/classes/ClassesLib.php +++ b/application/admin/controller/school/classes/ClassesLib.php @@ -105,6 +105,7 @@ class ClassesLib extends Backend } + protected function authClasses(&$params,$row=null){ //审核失败需填写原因 if($params["auth_status"] == '2' && empty($params["reason"])){ @@ -233,6 +234,10 @@ class ClassesLib extends Backend $params["user_id"] = $teacher["user_id"]; + //课时必须大于等于1 + if($params["classes_num"] < 1) $this->error("课时必须大于等于1"); + if($params["price"] < 0) $this->error("售价必须大于0"); + //独立地点需传定位信息 if($params["address_type"] == "2"){ @@ -322,8 +327,20 @@ class ClassesLib extends Backend } } + //如果是上架,判断是否拥有课时规格,没有则无法上架 + if($params["status"]=="1"){ + if(!$row)$this->error("新添加的课程请先至少添加一个课时规格后再上架!"); + //判断是否拥有课时规格,没有则无法上架 + $check_spec = \app\common\model\school\classes\ClassesSpec::where("classes_lib_id",$row->id)->count(); + if(!$check_spec)$this->error("新添加的课程请先至少添加一个课时规格后再上架!"); + + } + } + protected function update_classes($classes_lib_id){ + \app\common\model\school\classes\ClassesLib::update_classes($classes_lib_id); + } /** @@ -357,6 +374,31 @@ class ClassesLib extends Backend } $this->update_check($params,$row=null); $result = $this->model->allowField(true)->save($params); + \app\common\model\school\classes\ClassesLib::add_virtual_init($this->model["id"]); + $this->update_classes($this->model["id"]); + + if($this->have_auth){ + //调用通过事件 + $data = ['classes' => $this->model]; + \think\Hook::listen('classes_auth_need_after', $data); + + } + + if($this->success_auth){ + //调用通过事件 + $data = ['classes' => $this->model]; + \think\Hook::listen('classes_auth_success_after', $data); + } + + + if($this->error_auth){ + //调用通过事件 + $data = ['classes' => $this->model]; + \think\Hook::listen('classes_auth_fail_after', $data); + + } + + Db::commit(); } catch (ValidateException|PDOException|Exception $e) { Db::rollback(); @@ -406,7 +448,13 @@ class ClassesLib extends Backend } $this->update_check($params,$row); $result = $row->allowField(true)->save($params); + $this->update_classes($row["id"]); + if($this->have_auth){ + //调用通过事件 + $data = ['classes' => $row]; + \think\Hook::listen('classes_auth_need_after', $data); + } if($this->success_auth){ //调用通过事件 @@ -422,12 +470,7 @@ class ClassesLib extends Backend } // protected $have_auth = false; - if($this->have_auth){ - //调用通过事件 - $data = ['classes' => $row]; - \think\Hook::listen('classes_auth_need_after', $data); - } diff --git a/application/admin/controller/school/classes/ClassesSpec.php b/application/admin/controller/school/classes/ClassesSpec.php index fe3644e..3b7aff2 100644 --- a/application/admin/controller/school/classes/ClassesSpec.php +++ b/application/admin/controller/school/classes/ClassesSpec.php @@ -134,11 +134,79 @@ class ClassesSpec extends Backend protected function update_check(&$params,$row=null) { + + //开始和结束时间不能为空 + $start_time = $params["start_time"]; + $end_time = $params["end_time"]; + if(empty($start_time) || empty($end_time)){ + $this->error("请选择开始和结束时间"); + } + //转化时间戳 + $start_time = $params["start_time"] && !is_numeric($params["start_time"]) ? strtotime($params["start_time"]) : $params["start_time"]; + $end_time = $params["end_time"] && !is_numeric($params["end_time"]) ? strtotime($params["end_time"]) : $params["end_time"]; + //结束时间不能小于开始时间 + if($end_time<=$start_time){ + $this->error("结束时间不能小于开始时间"); + } + + //结束时间不能是已经过去的时间 + $now_time = time(); + if($end_time<=$now_time){ + $this->error("结束时间不能是已经过去的时间"); + } + + + $orderTimeTableName = $this->model->getWithAlisaName(); //修改 if($row){ $this->updateCheck($row->id,$params,$row); + //规格名字不能一样(同课程下) + $spec_name = $params["name"]; + $classes_lib_id = $params["classes_lib_id"]; + $spec_name_exist = $this->model::where("name",$spec_name)->where("classes_lib_id",$classes_lib_id)->where("id","<>",$row->id)->find(); + if($spec_name_exist){ + $this->error("该课程下已存在该课时规格名称,请重新输入"); + } + //同课程下,各个课时的开始和结束时间不能有重叠(出现时间交叠也不行) + $spec_time_exist = $this->model::where(function ($query) use ($orderTimeTableName,$start_time,$end_time) { + //兩個時間區間重合 存在任意交集 都不行 + $query->where("start_time BETWEEN {$start_time} AND {$end_time}"); + $query->whereOr("end_time BETWEEN {$start_time} AND {$end_time}"); + $query->whereOr("start_time <= {$start_time} AND end_time >= {$end_time}"); + $query->whereOr("start_time >= {$start_time} AND end_time <= {$end_time}"); + }) + ->where("classes_lib_id",$classes_lib_id) + ->where("id","<>",$row->id)->find(); + + if($spec_time_exist){ + $this->error("该课程下,{$spec_time_exist['name']}课时的开始和结束时间与你有重叠"); + } + + }else{ //新增 + //规格名字不能一样(同课程下) + $spec_name = $params["name"]; + $classes_lib_id = $params["classes_lib_id"]; + $spec_name_exist = $this->model::where("name",$spec_name)->where("classes_lib_id",$classes_lib_id)->find(); + if($spec_name_exist){ + $this->error("该课程下已存在该课时规格名称,请重新输入"); + } + + //同课程下,各个课时的开始和结束时间不能有重叠(出现时间交叠也不行) + $spec_time_exist = $this->model::where(function ($query) use ($orderTimeTableName,$start_time,$end_time) { + //兩個時間區間重合 存在任意交集 都不行 + $query->where("start_time BETWEEN {$start_time} AND {$end_time}"); + $query->whereOr("end_time BETWEEN {$start_time} AND {$end_time}"); + $query->whereOr("start_time <= {$start_time} AND end_time >= {$end_time}"); + $query->whereOr("start_time >= {$start_time} AND end_time <= {$end_time}"); + }) + ->where("classes_lib_id",$classes_lib_id) + ->find(); + + if($spec_time_exist){ + $this->error("该课程下,{$spec_time_exist['name']}课时的开始和结束时间与你有重叠"); + } } diff --git a/application/admin/controller/school/classes/VirtualUser.php b/application/admin/controller/school/classes/VirtualUser.php index 41a0b06..2e8adee 100644 --- a/application/admin/controller/school/classes/VirtualUser.php +++ b/application/admin/controller/school/classes/VirtualUser.php @@ -34,7 +34,9 @@ class VirtualUser extends Backend $this->view->assign("havetypeList", $this->model->getHavetypeList()); } - + protected function update_classes($classes_lib_id){ + \app\common\model\school\classes\ClassesLib::update_classes($classes_lib_id); + } /** * 默认生成的控制器所继承的父类中有index/add/edit/del/multi五个基础方法、destroy/restore/recyclebin三个回收站方法 @@ -81,6 +83,9 @@ class VirtualUser extends Backend + + + /** * 添加 * @@ -113,6 +118,8 @@ class VirtualUser extends Backend // $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); + + $this->update_classes($params["classes_lib_id"]); $result = true; Db::commit(); } catch (ValidateException|PDOException|Exception $e) { @@ -125,4 +132,57 @@ class VirtualUser extends Backend $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); + } + $result = $row->allowField(true)->save($params); + $this->update_classes($row["classes_lib_id"]); + + Db::commit(); + } catch (ValidateException|PDOException|Exception $e) { + Db::rollback(); + $this->error($e->getMessage()); + } + if (false === $result) { + $this->error(__('No rows were updated')); + } + $this->success(); + } + } diff --git a/application/admin/model/school/Message.php b/application/admin/model/school/Message.php index e9c6ab0..32d46c1 100644 --- a/application/admin/model/school/Message.php +++ b/application/admin/model/school/Message.php @@ -2,10 +2,11 @@ namespace app\admin\model\school; +use app\common\model\BaseModel; use think\Model; -class Message extends Model +class Message extends BaseModel { diff --git a/application/admin/model/school/classes/ClassesLib.php b/application/admin/model/school/classes/ClassesLib.php index a5e313f..6b3bba2 100644 --- a/application/admin/model/school/classes/ClassesLib.php +++ b/application/admin/model/school/classes/ClassesLib.php @@ -2,6 +2,7 @@ namespace app\admin\model\school\classes; +use app\manystore\model\Manystore; use think\Model; use traits\model\SoftDelete; @@ -203,7 +204,7 @@ class ClassesLib extends Model public function manystore() { - return $this->belongsTo('app\admin\model\Manystore', 'manystore_id', 'id', [], 'LEFT')->setEagerlyType(0); + return $this->belongsTo(Manystore::class, 'manystore_id', 'id', [], 'LEFT')->setEagerlyType(0); } diff --git a/application/admin/model/school/classes/ClassesSpec.php b/application/admin/model/school/classes/ClassesSpec.php index c049492..2b7a62c 100644 --- a/application/admin/model/school/classes/ClassesSpec.php +++ b/application/admin/model/school/classes/ClassesSpec.php @@ -2,10 +2,11 @@ namespace app\admin\model\school\classes; +use app\common\model\BaseModel; use think\Model; use traits\model\SoftDelete; -class ClassesSpec extends Model +class ClassesSpec extends BaseModel { use SoftDelete; diff --git a/application/admin/view/school/classes/classes_lib/add.html b/application/admin/view/school/classes/classes_lib/add.html index ddc36d2..f18bccf 100644 --- a/application/admin/view/school/classes/classes_lib/add.html +++ b/application/admin/view/school/classes/classes_lib/add.html @@ -215,12 +215,12 @@ -
{$manystore.email|htmlentities}
+ +所属前端用户ID: [{$manystore.user_id|htmlentities}]
+