diff --git a/application/admin/controller/general/Attachment.php b/application/admin/controller/general/Attachment.php index 7c4cdfc..e3c1b9b 100644 --- a/application/admin/controller/general/Attachment.php +++ b/application/admin/controller/general/Attachment.php @@ -62,8 +62,10 @@ class Attachment extends Backend $list = $this->model ->where($mimetypeQuery) ->where($where) + ->whereRaw("`filename` NOT REGEXP '^[0-9A-Fa-f]{32}'") ->order($sort, $order) ->paginate($limit); +// var_dump($this->model->getLastSql()); $cdnurl = preg_replace("/\/(\w+)\.php$/i", '', $this->request->root()); foreach ($list as $k => &$v) { diff --git a/application/admin/controller/manystore/UserAuth.php b/application/admin/controller/manystore/UserAuth.php index 731de21..1d00b8f 100644 --- a/application/admin/controller/manystore/UserAuth.php +++ b/application/admin/controller/manystore/UserAuth.php @@ -4,6 +4,18 @@ namespace app\admin\controller\manystore; 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; + /** * 授权机构用户 * @@ -17,11 +29,14 @@ class UserAuth extends Backend * @var \app\admin\model\manystore\UserAuth */ protected $model = null; + protected $qSwitch = true; + protected $qFields = ["shop_id","user_id"]; public function _initialize() { + $this->model = new \app\admin\model\manystore\UserAuth; parent::_initialize(); - $this->model = new \app\admin\model\manystore\UserAuth; + $this->view->assign("statusList", $this->model->getStatusList()); } @@ -59,7 +74,7 @@ class UserAuth extends Backend foreach ($list as $row) { $row->getRelation('shop')->visible(['name']); - $row->getRelation('user')->visible(['nickname','avatar']); + $row->getRelation('user')->visible(['nickname','avatar','mobile']); } $result = array("total" => $list->total(), "rows" => $list->items()); @@ -69,4 +84,197 @@ class UserAuth extends Backend return $this->view->fetch(); } + + + 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("shop_id",$shop_id)->where("id","<>",$row["id"])->find(); + if($teacher_user){ + $this->error("已向用户发起过授权申请!"); + } + }else{ + //新增 + //用户已是教师(搜索) + $teacher_user = $this->model->where("user_id",$user_id)->where("shop_id",$shop_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); + + $result = \app\common\model\manystore\UserAuth::auth(0,$params["shop_id"],$params["user_id"],$params["status"],'admin',$this->auth->id); + + 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); + $result = \app\common\model\manystore\UserAuth::auth($row["id"],$params["shop_id"],$params["user_id"],$params["status"],'admin',$this->auth->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(); + } + + /** + * 删除 + * + * @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/Blacklist.php b/application/admin/controller/school/classes/Blacklist.php new file mode 100644 index 0000000..a5db744 --- /dev/null +++ b/application/admin/controller/school/classes/Blacklist.php @@ -0,0 +1,73 @@ +model = new \app\admin\model\school\classes\Blacklist; + parent::_initialize(); + + } + + + + /** + * 默认生成的控制器所继承的父类中有index/add/edit/del/multi五个基础方法、destroy/restore/recyclebin三个回收站方法 + * 因此在当前控制器中可不用编写增删改查的代码,除非需要自己控制这部分逻辑 + * 需要将application/admin/library/traits/Backend.php中对应的方法复制到当前控制器,然后进行修改 + */ + + + /** + * 查看 + */ + public function index() + { + //当前是否为关联查询 + $this->relationSearch = true; + //设置过滤方法 + $this->request->filter(['strip_tags', 'trim']); + if ($this->request->isAjax()) { + //如果发送的来源是Selectpage,则转发到Selectpage + if ($this->request->request('keyField')) { + return $this->selectpage(); + } + list($where, $sort, $order, $offset, $limit) = $this->buildparams(); + + $list = $this->model + ->with(['user']) + ->where($where) + ->order($sort, $order) + ->paginate($limit); + + foreach ($list as $row) { + + $row->getRelation('user')->visible(['nickname','realname','mobile','avatar']); + } + + $result = array("total" => $list->total(), "rows" => $list->items()); + + return json($result); + } + return $this->view->fetch(); + } + +} diff --git a/application/admin/controller/school/classes/Teacher.php b/application/admin/controller/school/classes/Teacher.php index d7fd856..23a77bd 100644 --- a/application/admin/controller/school/classes/Teacher.php +++ b/application/admin/controller/school/classes/Teacher.php @@ -3,6 +3,7 @@ namespace app\admin\controller\school\classes; use app\common\controller\Backend; +use app\common\model\manystore\UserAuth; use app\common\model\User; use app\manystore\model\Manystore; use fast\Tree; @@ -33,7 +34,7 @@ class Teacher extends Backend protected $searchFields = 'id,name,user_id'; protected $qSwitch = true; - protected $qFields = ["manystore_id","shop_id"]; + protected $qFields = ["manystore_id","shop_id","user_id"]; public function _initialize() { @@ -254,6 +255,14 @@ class Teacher extends Backend $this->error("用户不存在"); } + + //如果开启了检测用户授权,则检测用户是否授权 + if(config("site.shop_auth_user_check")){ + if(!UserAuth::authcheck($shop_id,$user["id"])) $this->error("用户未授权当前机构!请先让用户授权同意您再操作!"); + } + + + //修改 if($row){ //用户已是其他的教师(搜索) diff --git a/application/admin/controller/school/classes/Verification.php b/application/admin/controller/school/classes/Verification.php index 1eb3121..4f9694e 100644 --- a/application/admin/controller/school/classes/Verification.php +++ b/application/admin/controller/school/classes/Verification.php @@ -3,6 +3,7 @@ namespace app\admin\controller\school\classes; use app\common\controller\Backend; +use app\common\model\manystore\UserAuth; use app\common\model\User; use app\manystore\model\Manystore; use think\Db; @@ -28,7 +29,7 @@ class Verification extends Backend protected $model = null; protected $qSwitch = true; - protected $qFields = ["manystore_id","shop_id"]; + protected $qFields = ["manystore_id","shop_id","user_id"]; public function _initialize() { @@ -106,6 +107,10 @@ class Verification extends Backend $this->error("用户不存在"); } + if(config("site.shop_auth_user_check")){ + if(!UserAuth::authcheck($shop_id,$user["id"])) $this->error("用户未授权当前机构!请先让用户授权同意您再操作!"); + } + //修改 if($row){ //用户已是其他的教师(搜索) diff --git a/application/admin/controller/user/User.php b/application/admin/controller/user/User.php index 948664b..982b856 100644 --- a/application/admin/controller/user/User.php +++ b/application/admin/controller/user/User.php @@ -265,6 +265,7 @@ class User extends Backend if(!$user)$user = (new \app\common\model\User)->addUserByMobile($people_mobile,$people_name); $user['nickname'] = $people_name; $user->save(); + }catch (\Exception $e){ $this->error($e->getMessage()); } diff --git a/application/admin/lang/zh-cn/manystore/user_auth.php b/application/admin/lang/zh-cn/manystore/user_auth.php index 35be48f..a820a9e 100644 --- a/application/admin/lang/zh-cn/manystore/user_auth.php +++ b/application/admin/lang/zh-cn/manystore/user_auth.php @@ -15,5 +15,9 @@ return [ 'Update_time' => '修改时间', 'Shop.name' => '店铺名称', 'User.nickname' => '昵称', - 'User.avatar' => '头像' + 'User.avatar' => '头像', + 'Add' => '添加用户授权申请', + 'Delete'=>'取消授权', + 'Del'=>'取消授权', + 'User.mobile'=>'用户手机号', ]; diff --git a/application/admin/lang/zh-cn/school/classes/blacklist.php b/application/admin/lang/zh-cn/school/classes/blacklist.php new file mode 100644 index 0000000..e8a0905 --- /dev/null +++ b/application/admin/lang/zh-cn/school/classes/blacklist.php @@ -0,0 +1,11 @@ + '授权用户', + 'Createtime' => '发起时间', + 'Updatetime' => '修改时间', + 'User.nickname' => '昵称', + 'User.realname' => '真实姓名', + 'User.mobile' => '手机号', + 'User.avatar' => '头像' +]; 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 a586afc..5216d0c 100644 --- a/application/admin/lang/zh-cn/school/classes/classes_lib.php +++ b/application/admin/lang/zh-cn/school/classes/classes_lib.php @@ -17,7 +17,7 @@ return [ 'Type' => '地点类型', 'Type out' => '户外', 'Type in' => '室内', - 'Classes_num' => '课时数', + 'Classes_num' => '多少节课', 'Address_type' => '地址类型', 'Address_type 1' => '按机构', 'Address_type 2' => '独立位置', diff --git a/application/admin/model/school/classes/Blacklist.php b/application/admin/model/school/classes/Blacklist.php new file mode 100644 index 0000000..a95697c --- /dev/null +++ b/application/admin/model/school/classes/Blacklist.php @@ -0,0 +1,44 @@ +belongsTo('app\admin\model\User', 'user_id', 'id', [], 'LEFT')->setEagerlyType(0); + } +} diff --git a/application/admin/validate/school/classes/Blacklist.php b/application/admin/validate/school/classes/Blacklist.php new file mode 100644 index 0000000..2d52cb3 --- /dev/null +++ b/application/admin/validate/school/classes/Blacklist.php @@ -0,0 +1,27 @@ + [], + 'edit' => [], + ]; + +} diff --git a/application/admin/view/manystore/user_auth/add.html b/application/admin/view/manystore/user_auth/add.html index 18b283c..58656ed 100644 --- a/application/admin/view/manystore/user_auth/add.html +++ b/application/admin/view/manystore/user_auth/add.html @@ -3,13 +3,13 @@