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 @@
- +
- + (没找到用户则点击按钮创建用户后重新下拉框选用户) diff --git a/application/admin/view/school/classes/blacklist/add.html b/application/admin/view/school/classes/blacklist/add.html new file mode 100644 index 0000000..2dc5223 --- /dev/null +++ b/application/admin/view/school/classes/blacklist/add.html @@ -0,0 +1,22 @@ +
+ +
+ +
+ + + + (没找到用户则点击按钮创建用户后重新下拉框选用户) + 根据手机号生成用户 + + +
+
+ + +
diff --git a/application/admin/view/school/classes/blacklist/edit.html b/application/admin/view/school/classes/blacklist/edit.html new file mode 100644 index 0000000..06efe3c --- /dev/null +++ b/application/admin/view/school/classes/blacklist/edit.html @@ -0,0 +1,22 @@ +
+ +
+ +
+ + + + (没找到用户则点击按钮创建用户后重新下拉框选用户) + 根据手机号生成用户 + + + +
+
+ +
diff --git a/application/admin/view/school/classes/blacklist/index.html b/application/admin/view/school/classes/blacklist/index.html new file mode 100644 index 0000000..a0ee4fa --- /dev/null +++ b/application/admin/view/school/classes/blacklist/index.html @@ -0,0 +1,29 @@ +
+ {:build_heading()} + +
+
+
+ +
+ +
+
+
diff --git a/application/admin/view/school/classes/classes_lib/add.html b/application/admin/view/school/classes/classes_lib/add.html index f18bccf..d1f237d 100644 --- a/application/admin/view/school/classes/classes_lib/add.html +++ b/application/admin/view/school/classes/classes_lib/add.html @@ -10,6 +10,14 @@
+ + + + + (没找到机构则点击按钮创建机构后重新下拉框选机构) + {:__('Add')} + +
@@ -140,7 +148,7 @@
{foreach name="addressTypeList" item="vo"} - + {/foreach} ( 如果选独立位置需填写具体位置信息! )
diff --git a/application/admin/view/school/classes/classes_lib/edit.html b/application/admin/view/school/classes/classes_lib/edit.html index 2bc0ac1..5598bfb 100644 --- a/application/admin/view/school/classes/classes_lib/edit.html +++ b/application/admin/view/school/classes/classes_lib/edit.html @@ -49,6 +49,14 @@
+ + + + + (没找到机构则点击按钮创建机构后重新下拉框选机构) + {:__('Add')} + +
@@ -181,7 +189,7 @@
{foreach name="addressTypeList" item="vo"} - + {/foreach} ( 如果选独立位置需填写具体位置信息! )
diff --git a/application/admin/view/school/classes/teacher/add.html b/application/admin/view/school/classes/teacher/add.html index 5df8909..ee81caa 100644 --- a/application/admin/view/school/classes/teacher/add.html +++ b/application/admin/view/school/classes/teacher/add.html @@ -15,7 +15,7 @@
- + (没找到用户则点击按钮创建用户后重新下拉框选用户) diff --git a/application/admin/view/school/classes/verification/add.html b/application/admin/view/school/classes/verification/add.html index b65bef3..7746a20 100644 --- a/application/admin/view/school/classes/verification/add.html +++ b/application/admin/view/school/classes/verification/add.html @@ -15,7 +15,7 @@
- + (没找到用户则点击按钮创建用户后重新下拉框选用户) diff --git a/application/api/controller/Index.php b/application/api/controller/Index.php index 74f685b..a4a1a26 100644 --- a/application/api/controller/Index.php +++ b/application/api/controller/Index.php @@ -70,8 +70,9 @@ class Index extends Api "site_city"=>config('site.the_city'), "site_timezone"=>config('site.timezone'), ]; + $upload_config = config('upload'); - $this->success('',["base_info"=>$base_info,"home_data"=>$home_data]); + $this->success('',["upload_config"=>$upload_config,"base_info"=>$base_info,"home_data"=>$home_data]); } diff --git a/application/api/controller/User.php b/application/api/controller/User.php index cac98cb..481717e 100644 --- a/application/api/controller/User.php +++ b/application/api/controller/User.php @@ -7,6 +7,7 @@ use app\common\controller\Api; use app\common\library\Ems; use app\common\library\Sms; use app\common\model\dyqc\ManystoreShop; +use app\common\model\manystore\UserAuth; use fast\Random; use think\Cache; use think\Config; @@ -504,4 +505,11 @@ class User extends Api $this->error($this->auth->getError()); } } + + + + + + + } diff --git a/application/api/controller/WechatUtil.php b/application/api/controller/WechatUtil.php index 0ae6acf..495393b 100644 --- a/application/api/controller/WechatUtil.php +++ b/application/api/controller/WechatUtil.php @@ -2,6 +2,7 @@ namespace app\api\controller; +use addons\epay\library\Service; use app\common\controller\Api; use app\common\model\style\HomeImages; @@ -10,7 +11,7 @@ use app\common\model\style\HomeImages; */ class WechatUtil extends Api { - protected $noNeedLogin = ['scheme']; + protected $noNeedLogin = ['scheme','link',"codeunlimit"]; protected $noNeedRight = ['*']; @@ -28,11 +29,14 @@ class WechatUtil extends Api * @ApiSummary(微信小程序生成url-scheme) * @ApiRoute(/api/wechat_util/scheme) * @ApiMethod(POST) - * @ApiParams (name="id", type="integer", required=true, description="会员ID") - * @ApiParams (name="name", type="string", required=true, description="用户名") - * @ApiParams (name="data", type="object", sample="{'user_id':'int','user_name':'string','profile':{'email':'string','age':'integer'}}", description="扩展数据") + * @ApiParams (name="path", type="string", required=false, description="通过 scheme 码进入的小程序页面路径,必须是已经发布的小程序存在的页面,不可携带 query。path 为空时会跳转小程序主页。") + * @ApiParams (name="query", type="string", required=false, description="通过 scheme 码进入小程序时的 query,最大1024个字符,只支持数字,大小写英文以及部分特殊字符") + * @ApiParams (name="env_version", type="string",required=false , description="默认值release。要打开的小程序版本。正式版为release,体验版为trial,开发版为develop,仅在微信外打开时生效。") + * @ApiParams (name="expire_time", type="number",required=false , description="到期失效的 scheme 码的失效时间,为 Unix 时间戳。生成的到期失效 scheme 码在该时间前有效。最长有效期为30天。is_expire 为 true 且 expire_type 为 0 时必填") + * @ApiParams (name="expire_type", type="number",required=false , description="默认值0,到期失效的 scheme 码失效类型,失效时间:0,失效间隔天数:1") + * @ApiParams (name="expire_interval", type="number",required=false , description="到期失效的 scheme 码的失效间隔天数。生成的到期失效 scheme 码在该间隔时间到达前有效。最长间隔天数为30天。is_expire 为 true 且 expire_type 为 1 时必填") * @ApiReturnParams (name="code", type="integer", required=true, sample="0") - * @ApiReturnParams (name="msg", type="string", required=true, sample="返回成功") + * @ApiReturnParams (name="openlink", type="string", required=true, sample="生成的小程序 scheme 码") * @ApiReturn({ "code" => 1, "msg" => "获取成功", @@ -40,26 +44,151 @@ class WechatUtil extends Api *}) */ public function scheme() { + $q_params = []; + $path = $this->request->post('path/s',''); + $query = $this->request->post('query/s',''); + $env_version = $this->request->post('env_version/s','release'); + $expire_time = $this->request->post('expire_time/d',0); + $expire_type = $this->request->post('expire_type/d',0); + $expire_interval = $this->request->post('expire_interval/d',0); + $jump_wxa = compact('env_version'); + if($path)$jump_wxa["path"] = $path; + if($query)$jump_wxa["query"] = $query; + if($expire_time)$q_params["expire_time"] = $expire_time; + if($expire_interval)$q_params["expire_interval"] = $expire_interval; + $q_params["expire_type"] = $expire_type; + $q_params["jump_wxa"] = $jump_wxa; - $home_data = []; - $home_data['top_image'] = [ - 'type' => config('site.home_top_type'), - 'image' => cdnurl(config('site.home_top_image'), true), - 'url' => config('site.home_top_url'), - ]; - //首页轮播图 - $home_data['top_images'] = HomeImages::allList(1, 20); - $base_info = [ - "site_name"=>config('site.name'), -// "site_logo"=>cdnurl(config('site.logo'), true), - "site_beian"=>config('site.beian'), - "site_version"=>''.config('site.version'), - "site_city"=>config('site.the_city'), - "site_timezone"=>config('site.timezone'), - ]; - $this->success('',["base_info"=>$base_info,"home_data"=>$home_data]); + + try { + // 实例对应的接口对象 + $scheme = new \WeMini\Scheme(Service::wechatConfig()); + $res= $scheme->create($q_params); + + } catch (\Exception $e){ +// Log::log($e->getMessage()); + $this->error($e->getMessage(),['errcode'=>$e->getCode()]); + } + $this->success('生成成功', $res); } + + /** + * @ApiTitle(微信小程序生成url-link) + * @ApiSummary(微信小程序生成url-link) + * @ApiRoute(/api/wechat_util/link) + * @ApiMethod(POST) + * @ApiParams (name="path", type="string", required=false, description="通过 URL Link 进入的小程序页面路径,必须是已经发布的小程序存在的页面,不可携带 query 。path 为空时会跳转小程序主页") + * @ApiParams (name="query", type="string", required=false, description="通过 scheme 码进入小程序时的 query,最大1024个字符,只支持数字,大小写英文以及部分特殊字符") + * @ApiParams (name="env_version", type="string",required=false , description="默认值release。要打开的小程序版本。正式版为release,体验版为trial,开发版为develop,仅在微信外打开时生效。") + * @ApiParams (name="expire_time", type="number",required=false , description="到期失效的 scheme 码的失效时间,为 Unix 时间戳。生成的到期失效 scheme 码在该时间前有效。最长有效期为30天。is_expire 为 true 且 expire_type 为 0 时必填") + * @ApiParams (name="expire_type", type="number",required=false , description="默认值0,到期失效的 scheme 码失效类型,失效时间:0,失效间隔天数:1") + * @ApiParams (name="cloud_env", type="string",required=false , description="云开发静态网站自定义 H5 配置参数: 云开发环境") + * @ApiParams (name="cloud_domain", type="string",required=false , description="云开发静态网站自定义 H5 配置参数: 静态网站自定义域名,不填则使用默认域名") + * @ApiParams (name="cloud_path", type="string",required=false , description="云开发静态网站自定义 H5 配置参数: 云开发静态网站 H5 页面路径,不可携带 query") + * @ApiParams (name="cloud_query", type="string",required=false , description="云开发静态网站自定义 H5 配置参数: 云开发静态网站 H5 页面 query 参数,最大 1024 个字符,只支持数字,大小写英文以及部分特殊字符") + * @ApiParams (name="cloud_resource_appid", type="string",required=false , description="云开发静态网站自定义 H5 配置参数: 第三方批量代云开发时必填,表示创建该 env 的 appid (小程序/第三方平台)") + * @ApiReturnParams (name="code", type="integer", required=true, sample="0") + * @ApiReturnParams (name="url_link", type="string", required=true, sample="生成的小程序 URL Link") + * @ApiReturn({ + "code" => 1, + "msg" => "获取成功", + "data" => {} + *}) + */ + public function link() { + $q_params = []; + $path = $this->request->post('path/s',''); + $query = $this->request->post('query/s',''); + $env_version = $this->request->post('env_version/s','release'); + $expire_time = $this->request->post('expire_time/d',0); + $expire_type = $this->request->post('expire_type/d',0); + $expire_interval = $this->request->post('expire_interval/d',0); + $cloud_env = $this->request->post('cloud_env/s',0); + $cloud_domain = $this->request->post('cloud_domain/s',0); + $cloud_path = $this->request->post('cloud_path/s',0); + $cloud_query = $this->request->post('cloud_query/s',0); + $cloud_resource_appid = $this->request->post('cloud_resource_appid/s',0); + + $cloud_base = []; + if($cloud_env)$cloud_base["env"] = $cloud_env; + if($cloud_domain)$cloud_base["domain"] = $cloud_domain; + if($cloud_path)$cloud_base["path"] = $cloud_path; + if($cloud_query)$cloud_base["cloud_query"] = $cloud_query; + if($cloud_resource_appid)$cloud_base["resource_appid"] = $cloud_resource_appid; + + if($path)$q_params["path"] = $path; + if($query)$q_params["query"] = $query; + if($env_version)$q_params["env_version"] = $env_version; + + + if($expire_time)$q_params["expire_time"] = $expire_time; + if($expire_interval)$q_params["expire_interval"] = $expire_interval; + if($expire_type)$q_params["expire_type"] = $expire_type; + if($cloud_base)$q_params["cloud_base"] = $cloud_base; + + try { + // 实例对应的接口对象 + $scheme = new \WeMini\Scheme(Service::wechatConfig()); + $res= $scheme->urlLink($q_params); + + } catch (\Exception $e){ +// Log::log($e->getMessage()); + $this->error($e->getMessage(),['errcode'=>$e->getCode()]); + } + $this->success('生成成功', $res); + } + + + + + + + + + /** + * @ApiTitle(获取不限制的小程序码(太阳码)) + * @ApiSummary(获取不限制的小程序码(太阳码)) + * @ApiRoute(/api/wechat_util/codeunlimit) + * @ApiMethod(POST) + * @ApiParams (name="page", type="string", required=false, description="默认是主页,页面 page,例如 pages/index/index,根路径前不要填加 /,不能携带参数(参数请放在scene字段里),如果不填写这个字段,默认跳主页面。scancode_time为系统保留参数,不允许配置") + * @ApiParams (name="scene", type="string", required=false, description="最大32个可见字符,只支持数字,大小写英文以及部分特殊字符:!#$&'()*+,/:;=?@-._~,其它字符请自行编码为合法字符(因不支持%,中文无法使用 urlencode 处理,请使用其他编码方式)") + * @ApiParams (name="env_version", type="string",required=false , description="默认值release。要打开的小程序版本。正式版为release,体验版为trial,开发版为develop,仅在微信外打开时生效。") + * @ApiParams (name="check_path", type="bool",required=false , description="默认是true,检查page 是否存在,为 true 时 page 必须是已经发布的小程序存在的页面(否则报错);为 false 时允许小程序未发布或者 page 不存在, 但page 有数量上限(60000个)请勿滥用。") + * @ApiParams (name="width", type="number",required=false , description="默认430,二维码的宽度,单位 px,最小 280px,最大 1280px") + * @ApiParams (name="auto_color", type="bool",required=false , description="自动配置线条颜色,如果颜色依然是黑色,则说明不建议配置主色调,默认 false") + * @ApiParams (name="line_color", type="json",required=false , description="默认是{’r’:0,’g’:0,’b’:0} 。auto_color 为 false 时生效,使用 rgb 设置颜色 例如 {’r’:’xxx’,’g’:’xxx’,’b’:’xxx’} 十进制表示") + * @ApiParams (name="is_hyaline", type="bool",required=false , description="默认是false,是否需要透明底色,为 true 时,生成透明底色的小程序") + * @ApiReturn({ + "code" => 1, + "msg" => "获取成功", + "data" => {} + *}) + */ + public function codeunlimit() { + + $page = $this->request->post('page/s',''); + $scene = $this->request->post('scene/s',''); + $env_version = $this->request->post('env_version/s','release'); + $check_path = $this->request->post('check_path/d',1); + $width = $this->request->post('width/d',430); + $auto_color = $this->request->post('auto_color/d',0); + $line_color = $this->request->post('line_color/s',0); + $is_hyaline = $this->request->post('is_hyaline/d',1); + + try { + // 实例对应的接口对象 + $res = \bw\Common::getMiniappCode($scene, $page, $width, $auto_color ? true : false, $line_color, $is_hyaline ? true : false, null, $check_path ? true : false, $env_version,false); + } catch (\Exception $e){ +// Log::log($e->getMessage()); + $this->error($e->getMessage(),['errcode'=>$e->getCode()]); + } + $this->success('生成成功', $res); + } + + + + } diff --git a/application/api/controller/school/Shop.php b/application/api/controller/school/Shop.php index b8cc5fa..af2813f 100644 --- a/application/api/controller/school/Shop.php +++ b/application/api/controller/school/Shop.php @@ -9,7 +9,7 @@ use app\common\model\dyqc\ManystoreShop; */ class Shop extends Base { - protected $noNeedLogin = ["detail",'people','spec']; + protected $noNeedLogin = ["detail",'people','spec','shop_list']; protected $noNeedRight = '*'; protected $model = null; @@ -161,4 +161,77 @@ class Shop extends Base } + + + /** + * @ApiTitle( 通用机构大索索列表) + * @ApiSummary(通用机构大索索列表) + * @ApiMethod(GET) + * @ApiParams(name = "keywords", type = "string",required=false,description = "搜索关键字") + * @ApiParams(name = "page", type = "string",required=true,description = "页数") + * @ApiParams(name = "limit", type = "string",required=true,description = "条数") + * @ApiParams(name = "user_id", type = "int",required=false,description = "主讲师用户id") + * @ApiParams(name = "shop_id", type = "int",required=false,description = "机构店铺id") + * @ApiParams(name = "teacher_id", type = "int",required=false,description = "老师id") + * @ApiParams(name = "keyword", type = "string",required=false,description = "关键字搜索") + * @ApiParams(name = "type", type = "string",required=false,description = "类型:1=个人,2=机构") + * @ApiParams(name = "province", type = "string",required=false,description = "省编号") + * @ApiParams(name = "city", type = "string",required=false,description = "市编号") + * @ApiParams(name = "district", type = "string",required=false,description = "县区编号") + * @ApiParams(name = "status", type = "string",required=false,description = "不传则默认查上架的 审核状态:0=待审核,1=审核通过,2=审核失败") + * @ApiParams(name = "order", type = "string",required=false,description = " normal=综合排序優先,distance=距离优先") + * @ApiParams(name = "nearby", type = "string",required=false,description = "限制最大搜索距离(米)") + * @ApiParams(name = "latitude", type = "string",required=false,description = "latitude") + * @ApiParams(name = "longitude", type = "string",required=false,description = "longitude") + * @ApiReturn({ + * + *}) + */ + public function shop_list() + { + $user_id = 0; + $user = $this->auth->getUser();//登录用户 + if($user)$user_id = $user['id']; + $params =[]; + $params["my_user_id"] = $user_id; + $params["page"] = $this->request->get('page/d', 1); //页数 + $params["limit"] = $this->request->get('limit/d', 10); //条数 + $params["keywords"] = $this->request->get('keywords/s', ''); //搜索关键字 + $params["user_id"] = $this->request->get('user_id/d', ''); //主讲师用户id + $params["id"] = $this->request->get('shop_id/d', ''); //机构店铺id + $params["teacher_id"] = $this->request->get('teacher_id/d', ''); //机构店铺id + $params["keyword"] = $this->request->get('keyword/s', ''); //机构店铺id + $params["type"] = $this->request->get('type/s', ''); //机构店铺id + $params["province"] = $this->request->get('province/s', ''); //机构店铺id + + $params["city"] = $this->request->get('city/s', ''); //机构店铺id + $params["district"] = $this->request->get('district/s', ''); //机构店铺id + $params["status"] = $this->request->get('status/s', ''); //机构店铺id + + + + $params["order"] = $this->request->get('order/s', ''); //机构店铺id + $params["nearby"] = $this->request->get('nearby/s', ''); //机构店铺id + + + $params["latitude"] = $this->request->get('latitude/s', ''); //机构店铺id + $params["longitude"] = $this->request->get('longitude/s', ''); //机构店铺id + +// $type = $this->request->get('type/s', ''); //筛选学员和教练单 + + try{ + //当前申请状态 + $res = $this->model::getVaildList($params); +// if($user_id =='670153'){ +// file_put_contents("ceshi66.txt",(new AppointmentOrder())->getLastSql()); +// } + }catch (\Exception $e){ + + $this->error($e->getMessage()); + } + $this->success('查询成功', ["list"=>$res]); + } + + + } \ No newline at end of file diff --git a/application/api/controller/school/UserAuth.php b/application/api/controller/school/UserAuth.php new file mode 100644 index 0000000..f34b708 --- /dev/null +++ b/application/api/controller/school/UserAuth.php @@ -0,0 +1,132 @@ +model = new UserAuthModel; + parent::_initialize(); + + //判断登录用户是否是员工 + } + + + /** + * @ApiTitle(我的授权详情) + * @ApiSummary(我的授权详情) + * @ApiMethod(GET) + * @ApiParams(name = "id", type = "int",required=true,description = "授权id") + * @ApiReturn({ + * + *}) + */ + public function detail(){ + $id = $this->request->get('id/d',''); + + if(empty($id)){ + $this->error(__('缺少必要参数')); + } + + try { + $res = $this->model->detail($id); + } catch (\Exception $e){ +// Log::log($e->getMessage()); + $this->error($e->getMessage(),['errcode'=>$e->getCode()]); + } + $this->success('获取成功', ['detail' => $res]); + } + + + + + + + + /** + * @ApiTitle( 我的授权信息列表(取决于搜索条件)) + * @ApiSummary(我的授权信息列表(取决于搜索条件)) + * @ApiMethod(GET) + * @ApiParams(name = "page", type = "string",required=true,description = "页数") + * @ApiParams(name = "limit", type = "string",required=true,description = "条数") + * @ApiParams(name = "status", type = "string",required=false,description = "授权状态:1=通过,2=拒绝") + * @ApiParams(name = "shop_id", type = "int",required=false,description = "机构店铺id") + * @ApiReturn({ + * + *}) + */ + public function auth_list() + { + $user_id = 0; + $user = $this->auth->getUser();//登录用户 + if($user)$user_id = $user['id']; + $params=[]; + $page = $this->request->get('page/d', 0); //页数 + $limit = $this->request->get('limit/d', 0); //条数 + $params['status'] = $this->request->get('status/s', ''); //搜索关键字 + $params['shop_id'] = $this->request->get('shop_id/d', ''); //搜索关键字 + $params['user_id'] = $user_id; //搜索关键字 + + +// $type = $this->request->get('type/s', ''); //筛选学员和教练单 + + try{ + //当前申请状态 + $res = $this->model::allList($page, $limit,$params); +// if($user_id =='670153'){ +// file_put_contents("ceshi66.txt",(new AppointmentOrder())->getLastSql()); +// } + }catch (\Exception $e){ + + $this->error($e->getMessage()); + } + $this->success('查询成功', $res); + } + + + /** + * @ApiTitle( 用户机构授权) + * @ApiSummary(支持用户主动授权和确认表单两种形式) + * @ApiMethod(POST) + * @ApiParams(name = "id", type = "int",required=false,description = "非必填,确认表单才需要填") + * @ApiParams(name = "shop_id", type = "int",required=true,description = "机构店铺id") + * @ApiParams(name = "status", type = "int",required=true,description = "授权操作:1=通过,2=拒绝") + * @ApiReturn({ + * + *}) + */ + public function authorization(){ + $user_id = 0; + $user = $this->auth->getUser();//登录用户 + if($user)$user_id = $user['id']; + + $id = $this->request->post('id/d', 0); //搜索关键字 + $shop_id = $this->request->post('shop_id/d', 0); //搜索关键字 + $status = $this->request->post('status/d', 0); //搜索关键字 + + try{ + $res = UserAuth::auth($id,$shop_id,$user_id,$status,'user',$user_id,true); + }catch (\Throwable $e){ + $this->error($e->getMessage()); + } + $this->success('操作成功', $res); + } + +} + diff --git a/application/api/controller/school/worker/HourOrder.php b/application/api/controller/school/worker/HourOrder.php index 1152d8d..0070f5a 100644 --- a/application/api/controller/school/worker/HourOrder.php +++ b/application/api/controller/school/worker/HourOrder.php @@ -265,7 +265,7 @@ class HourOrder extends Base * @ApiParams(name = "page", type = "string",required=true,description = "页数") * @ApiParams(name = "limit", type = "string",required=true,description = "条数") * @ApiParams(name = "status", type = "string",required=false,description = "订单状态:-3=已取消,-1=已报名待审核,0=已预约,3=已完成") - * @ApiParams(name = "classes_order_id", type = "int",required=false,description = "课程订单id") + * @ApiParams(name = "classes_order_id", type = "string",required=false,description = "课程订单id") * @ApiParams(name = "classes_lib_id", type = "int",required=false,description = "课程id") * @ApiParams(name = "start_time", type = "string",required=false,description = "按开始时间区间查(传值格式:Y/m/d H:M:S-Y/m/d H:M:S)") * @ApiParams(name = "createtime", type = "string",required=false,description = "按创建时间区间查(传值格式:Y/m/d H:M:S-Y/m/d H:M:S)") @@ -295,6 +295,7 @@ class HourOrder extends Base try{ //当前申请状态 $res = $this->model::workList($page, $limit,$keywords,$status,$classes_order_id,0,$this->classes_lib_ids,$classes_lib_ids,$start_time,$createtime); +// var_dump($this->model->getLastSql());die; // if($user_id =='670153'){ // file_put_contents("ceshi66.txt",(new AppointmentOrder())->getLastSql()); // } diff --git a/application/api/controller/school/worker/Order.php b/application/api/controller/school/worker/Order.php index 2152a37..a7cebae 100644 --- a/application/api/controller/school/worker/Order.php +++ b/application/api/controller/school/worker/Order.php @@ -41,7 +41,7 @@ class Order extends Base *}) */ public function detail(){ - $id = $this->request->get('id/d',''); + $id = $this->request->get('id/s',''); if(empty($id)){ $this->error(__('缺少必要参数')); diff --git a/application/common/hooks.php b/application/common/hooks.php index 611469b..8148ada 100644 --- a/application/common/hooks.php +++ b/application/common/hooks.php @@ -95,6 +95,21 @@ $classesHooks = [ +//用户事件钩子 +$userHooks = [ + 'user_auth_need_after' => [ // 发起用户授权 + 'app\\common\\listener\\user\\UserHook' + ], + 'user_auth_success_after' => [ // 用户授权机构通过 + 'app\\common\\listener\\user\\UserHook' + ], + 'user_auth_fail_after' => [ // 用户授权机构不通过 + 'app\\common\\listener\\user\\UserHook' + ], +]; + + + // //if (file_exists(ROOT_PATH . 'addons/shopro/listener/commission')) { // $defaultHooks = array_merge_recursive($defaultHooks, $commissionHooks); @@ -102,5 +117,6 @@ $classesHooks = [ $defaultHooks = array_merge_recursive($defaultHooks, $hourHooks); $defaultHooks = array_merge_recursive($defaultHooks, $manystoreHooks); $defaultHooks = array_merge_recursive($defaultHooks, $classesHooks); +$defaultHooks = array_merge_recursive($defaultHooks, $userHooks); return $defaultHooks; diff --git a/application/common/listener/classes/ClassesHook.php b/application/common/listener/classes/ClassesHook.php index 40997f7..c571635 100644 --- a/application/common/listener/classes/ClassesHook.php +++ b/application/common/listener/classes/ClassesHook.php @@ -59,7 +59,7 @@ class ClassesHook } // 课程审核失败后 - public function classesFailNeedAfter(&$params) + public function classesAuthFailAfter(&$params) { ['classes' => $classes] = $params; diff --git a/application/common/listener/user/UserHook.php b/application/common/listener/user/UserHook.php new file mode 100644 index 0000000..dd92382 --- /dev/null +++ b/application/common/listener/user/UserHook.php @@ -0,0 +1,86 @@ + $user_auth,"oper_type"=>$oper_type,"oper_id"=>$oper_id] = $params; + +// //课程推送给老师 +// $desc = "您的新课程{$classes['title']}已审核通过,可以在后台操作课程上架!"; +// +// $title = "新课程审核成功"; +// $mini_type = "classes_apply"; +// $to_type="user"; +// $to_id = $classes["user_id"]; +// $status ="classes"; +// $platform="user"; +// $oper_id=0; +// $oper_type="system"; +// $params=[ +// "event"=>"classes_auth_success_after", +// "classes_lib_id"=>$classes["id"], +// ]; +// Message::send($title,$desc,$mini_type,$to_id,$to_type,$status,$platform,$params,$oper_id,$oper_type); + + } + + + // 用户授权机构通过 + public function userAuthSuccessAfter(&$params) + { + ['user_auth' => $user_auth,"oper_type"=>$oper_type,"oper_id"=>$oper_id] = $params; + +// //课程推送给老师 +// $desc = "您的新课程{$classes['title']}已审核通过,可以在后台操作课程上架!"; +// +// $title = "新课程审核成功"; +// $mini_type = "classes_apply"; +// $to_type="user"; +// $to_id = $classes["user_id"]; +// $status ="classes"; +// $platform="user"; +// $oper_id=0; +// $oper_type="system"; +// $params=[ +// "event"=>"classes_auth_success_after", +// "classes_lib_id"=>$classes["id"], +// ]; +// Message::send($title,$desc,$mini_type,$to_id,$to_type,$status,$platform,$params,$oper_id,$oper_type); + + } + + // 用户授权机构不通过 + public function userAuthFailAfter(&$params) + { + ['user_auth' => $user_auth,"oper_type"=>$oper_type,"oper_id"=>$oper_id] = $params; + +// +// //课程推送给老师 +// $desc = "您的新课程{$classes['title']}审核未通过,未通过原因为:{$classes['reason']},整改后,可以在后台重新提交!"; +// +// $title = "新课程审核不通过"; +// $mini_type = "classes_apply"; +// $to_type="user"; +// $to_id = $classes["user_id"]; +// $status ="classes"; +// $platform="user"; +// $oper_id=0; +// $oper_type="system"; +// $params=[ +// "event"=>"classes_auth_success_after", +// "classes_lib_id"=>$classes["id"], +// ]; +// Message::send($title,$desc,$mini_type,$to_id,$to_type,$status,$platform,$params,$oper_id,$oper_type); + + + + + } + +} \ No newline at end of file diff --git a/application/common/model/dyqc/ManystoreShop.php b/application/common/model/dyqc/ManystoreShop.php index a3eb1a5..aa5f1a0 100644 --- a/application/common/model/dyqc/ManystoreShop.php +++ b/application/common/model/dyqc/ManystoreShop.php @@ -178,6 +178,11 @@ class ManystoreShop extends BaseModel return $this->belongsTo('app\admin\model\Admin', 'admin_id', 'id', [], 'LEFT')->setEagerlyType(0); } + public function user() + { + return $this->belongsTo('app\common\model\User', 'user_id', 'id', [], 'LEFT')->setEagerlyType(0); + } + public function checkFull($id){ $self = $this->get($id,['teachers']); @@ -523,6 +528,120 @@ public static function getAuthInfo($user_id){ + /** + * 获取所有课程列表 + */ + public static function getVaildList($params) { + extract($params); + $a = (new self)->getWithAlisaName().'.'; + // 查询自提点 + if(isset($status) && in_array($status, [1,2,0])){ + $selfetch = self::with(['user']); + }else{ + $selfetch = self::with(['user'])->where($a.'status', '1')->where("{$a}auth_status",1); + } + + + $order = $order?? 'normal'; + $per_page = $limit ?? 10; + + + $field = "{$a}id,{$a}name,{$a}user_id,{$a}logo,{$a}image,{$a}images,{$a}address_city,{$a}city,{$a}province,{$a}district,{$a}address,{$a}address_detail,{$a}longitude,{$a}latitude,{$a}type,{$a}tel,{$a}status,{$a}create_time,{$a}update_time,{$a}weigh"; + + //得到距离 + if (isset($latitude) && isset($longitude) && $latitude && $longitude) { + $field .= ', '.getDistanceBuilder($latitude, $longitude); + }else{ + $field .= ', 0 as distance'; + } + + //得到每个 + + + $selfetch = $selfetch->field($field); + if (isset($keyword) && $keyword) { + $selfetch = $selfetch->where("{$a}name|{$a}address|{$a}address_detail|{$a}address_city", 'like', '%' . $keyword . '%'); + } + + if (isset($user_id) && $user_id) { + $selfetch = $selfetch->where("{$a}user_id", 'in', ''.$user_id); + } + + if (isset($my) && $my && isset($my_user_id) && $my_user_id) { + $selfetch = $selfetch->where("{$a}user_id", 'in', ''.$my_user_id); + } + + + if (isset($id) && $id) { + $selfetch = $selfetch->where("{$a}id", 'in', ''.$id); + } + + + if (isset($teacher_id) && $teacher_id) { + $teacher = Teacher::where("id",$teacher_id)->find(); + if($teacher){ + $selfetch = $selfetch->where("{$a}id", 'in', ''.$teacher["shop_id"]); + } + } + + if (isset($type) && $type) { + $selfetch = $selfetch->where("{$a}type", 'in', ''.$type); + } + + if (isset($status) && $status) { + $selfetch = $selfetch->where("{$a}status", 'in', ''.$status); + } + + + + //区域搜索 + if (isset($province) && $province) { + $selfetch = $selfetch->where("{$a}province", 'in', ''.$province); + } + + + if (isset($city) && $city) { + $selfetch = $selfetch->where("{$a}city", 'in', ''.$city); + } + + if (isset($district) && $district) { + $selfetch = $selfetch->where("{$a}district", 'in', ''.$district); + } + + + + + //排序 + switch ($order) { + case "normal": //综合排序(推薦優先) + $selfetch = $selfetch->order("{$a}weigh desc,{$a}id desc"); + break; + case "distance": //距离优先 权重 + $selfetch = $selfetch->order("distance asc,{$a}weigh desc,{$a}id desc"); + break; + default: + throw new \Exception("不支持的排序类型"); + } + + if(isset($nearby) && $nearby) { + $selfetch = $selfetch->having("distance <= {$nearby}"); + } + + + + + $selfetch = $selfetch->paginate($per_page); + + //额外附加数据 +// foreach ($selfetch as $row) { //迭代器魔术方法遍历,填值自动引用传值 +// //设置是否已收藏 +// $row->is_collect = in_array($row->id,$collect_classes_lib_ids) ? 1 : 0; +// } + + return $selfetch; + } + + } diff --git a/application/common/model/manystore/UserAuth.php b/application/common/model/manystore/UserAuth.php index 1175860..072aea4 100644 --- a/application/common/model/manystore/UserAuth.php +++ b/application/common/model/manystore/UserAuth.php @@ -2,10 +2,12 @@ namespace app\common\model\manystore; +use app\common\model\BaseModel; +use app\common\model\User; use think\Model; -class UserAuth extends Model +class UserAuth extends BaseModel { @@ -80,4 +82,200 @@ class UserAuth extends Model { return $this->belongsTo('app\admin\model\User', 'user_id', 'id', [], 'LEFT')->setEagerlyType(0); } + + public static function authcheck($shop_id,$user_id){ + $usercheck = UserAuth::where("user_id",$user_id) + ->where("shop_id",$shop_id) + ->where("status",1)->find(); + if(!$usercheck) return false; + return $usercheck; + } + + + + /**用户授权机构 + * @param $id + * @param int $user_id + * @param int $status 授权状态:0=待确认,1=通过,2=拒绝 + * @param bool $check + * @param bool $trans + * @throws \Exception + */ + public static function auth($id,$shop_id,$user_id,$status,$oper_type='user',$oper_id=0,$trans=false){ + + $create = false; + if($id){ + $classes_lib = self::where("id",$id)->where("status","in",[0,2])->find(); + if(!$classes_lib)throw new \Exception("找不到待授权记录!"); + } + if($shop_id && $user_id){ + $shop_info = Shop::get($shop_id); + if(!$shop_info)throw new \Exception("找不到店铺!"); + $classes_lib = self::where("shop_id",$shop_id)->where("user_id",$user_id)->find(); + if(!$classes_lib){ + $create = true; + }else{ + if(!in_array($classes_lib["status"],[0,2]))throw new \Exception("已授权!"); + } + } + + if(!$create && !$classes_lib)throw new \Exception("找不到待授权记录!缺失必要参数!"); + + if($user_id){ + $user_info = User::get($user_id); + if(!$user_info)throw new \Exception("找不到用户!"); + if($classes_lib && $classes_lib["user_id"]!=$user_id)throw new \Exception("用户与授权记录不匹配!"); + } + //判断逻辑 + if($trans){ + self::beginTrans(); + } + + try{ + + + //更新授权记录 + $data = [ + "shop_id"=>$shop_id, + "user_id"=>$user_id, + "status"=>0, + ]; + //没创建先创建 + if($create){ + $classes_lib = self::create($data); + //调用事件 + $datas = ['user_auth' => $classes_lib,"oper_type"=>$oper_type,"oper_id"=>$oper_id]; + \think\Hook::listen('user_auth_need_after', $datas); + } + + $data["status"] = $status; + + $equa = true; + //for循环数据变更检测 + foreach ($data as $key=>$value){ + if($value!=$classes_lib[$key]){ + $equa = false;break; + } + } + + if(!$create && $equa) throw new \Exception("无变更无需更新!"); + + //事务逻辑 + if($status == 1){ + $classes_lib["status"] = $status; + $classes_lib["auth_time"] = time(); + $classes_lib->save(); + + + //调用事件 + $datas = ['user_auth' => $classes_lib,"oper_type"=>$oper_type,"oper_id"=>$oper_id]; + \think\Hook::listen('user_auth_success_after', $datas); + + }elseif($status == 2){ + //拒绝 + $classes_lib["status"] = $status; + $classes_lib["auth_time"] = time(); + $classes_lib->save(); + + //调用事件 + $datas = ['user_auth' => $classes_lib,"oper_type"=>$oper_type,"oper_id"=>$oper_id]; + \think\Hook::listen('user_auth_fail_after', $datas); + }else{ +// throw new \Exception("状态错误!"); + } + + if($trans){ + self::commitTrans(); + } + }catch (\Exception $e){ + if($trans){ + self::rollbackTrans(); + } + throw new \Exception($e->getMessage()); + } + + return $classes_lib; + } + + + + + + + + public function detail($id){ + $self = $this->get($id,["shop"]); + $self["shop"]->visible(['name',"logo","image"]); + return $self; + } + + + + + + /**得到基础条件 + * @param $status + * @param null $model + * @param string $alisa + */ + public static function getBaseWhere($whereData = [], $model = null, $alisa = '',$with = false) + { + + if (!$model) { + $model = new static; + if ($alisa&&!$with) $model = $model->alias($alisa); + } + if ($alisa) $alisa = $alisa . '.'; + $tableFields = (new static)->getTableFields(); + foreach ($tableFields as $fields) + { + if(in_array($fields, ['status']))continue; +// if (isset($whereData[$fields]) && $whereData[$fields]) $model = $model->where("{$alisa}{$fields}", '=', $whereData[$fields]); + + if (isset($whereData[$fields]) && $whereData[$fields]){ + if(is_array($whereData[$fields])){ + $model = $model->where("{$alisa}{$fields}", $whereData[$fields][0], $whereData[$fields][1]); + }else{ + $model = $model->where("{$alisa}{$fields}", '=', $whereData[$fields]); + } + + } + + + } + if (isset($whereData['status']) && $whereData['status']) $model = $model->where("{$alisa}status", 'in', $whereData['status']); + if (isset($whereData['not_status']) && $whereData['not_status']) $model = $model->where("{$alisa}status", 'not in', $whereData['not_status']); + +// if (isset($whereData['keywords'])&&$whereData['keywords']) $model = $model->where("{$alisa}name|{$alisa}id", '=', $whereData['keywords']); + if (isset($whereData['time'])&&$whereData['time']){ + $model = $model->time(['auth_time',$whereData['time']]); + } + if (isset($whereData['user_id']) && $whereData['user_id']) $model = $model->where("{$alisa}user_id", '=', $whereData['user_id']); + + if (isset($whereData['shop_id']) && $whereData['shop_id']) $model = $model->where("{$alisa}shop_id", 'in', $whereData['shop_id']); + + return $model; + } + + + + + + + public static function allList($page, $limit,$params=[]){ + $with_field = [ + 'user'=>['nickname','mobile','avatar','realname'], + 'shop'=>['name','logo','image','images'], + 'base'=>['*'], + ]; + $alisa = (new self)->getWithAlisaName(); + $sort = "{$alisa}.status asc,{$alisa}.id desc"; +// if(!empty($params['status'])){ +// $params['status'] = '1'; +// } + return (new self)->getBaseList($params, $page, $limit,$sort,$with_field); + } + + + } diff --git a/application/common/model/school/classes/ClassesLib.php b/application/common/model/school/classes/ClassesLib.php index 919b83b..22121bb 100644 --- a/application/common/model/school/classes/ClassesLib.php +++ b/application/common/model/school/classes/ClassesLib.php @@ -526,6 +526,12 @@ $user_unpaid_order = $user_paid_order =null; $selfetch = $selfetch->where("{$a}user_id", 'in', ''.$user_id); } + if (isset($my) && $my && isset($my_user_id) && $my_user_id) { + $selfetch = $selfetch->where("{$a}user_id", 'in', ''.$my_user_id); + } + + + if (isset($teacher_id) && $teacher_id) { $selfetch = $selfetch->where("{$a}teacher_id", 'in', ''.$teacher_id); } @@ -599,7 +605,7 @@ $user_unpaid_order = $user_paid_order =null; $classes_label_ids = implode("|",explode(',',$classes_label_ids)); $selfetch = $selfetch->whereRaw(" {$a}classes_label_ids REGEXP '({$classes_label_ids})'"); } - $collect_classes_lib_ids = []; + $collect_classes_lib_ids = [-1]; //需登录查询条件: if(isset($my_user_id) && $my_user_id){ //得到我收藏的课程ids diff --git a/application/common/model/school/classes/hourorder/Order.php b/application/common/model/school/classes/hourorder/Order.php index bf3f731..f61c616 100644 --- a/application/common/model/school/classes/hourorder/Order.php +++ b/application/common/model/school/classes/hourorder/Order.php @@ -3,6 +3,7 @@ namespace app\common\model\school\classes\hourorder; use app\admin\model\Admin; +use app\admin\model\school\classes\Blacklist; use app\common\model\school\classes\ClassesLib; use app\common\model\school\classes\ClassesSpec; use app\common\model\User; @@ -911,6 +912,54 @@ class Order extends BaseModel if($order_info) throw new \Exception("当前时间区间内,您已预约课程{$order_info['detail']['title']},无法再预约其他课程"); } + //执行免费课黑名单判断 + //免费课才进行判断 + if($lib && $lib['feel']=='1'){ + self::checkBlackList($user_id,true); + } + + //过期课时无法下单(结束时间小于等于当前时间) + if($classes_lib_spec_info["end_time"] <= time()){ + throw new \Exception("该课时已过期结束,无法预约!"); + } + + + + } + + //执行免费课黑名单判断 + public static function checkBlackList($user_id,$check=false){ + $as = (new self)->getWithAlisaName(); + //黑名单配置 + $black_limit = config("site.free_classes_not_verify_num"); + //如果免费课程报名通过后到结束时间不去核销N次 ,则进入黑名单 + $order_count = self::with("detail")->where("{$as}.status",'in',["0"]) + ->where("detail.feel",'1') + ->where("{$as}.user_id",$user_id) + ->where("{$as}.end_time" ,'<=',time()) + ->count(); + //已达到进入黑名单条件 + if($order_count >= $black_limit){ + $where = [ + "user_id"=>$user_id + ]; + $blacklist = Blacklist::where($where)->find(); + if(!$blacklist){ + $blacklist = new Blacklist(); + } + $blacklist->save($where); + + } + + if($check){ + //判断用户是否在黑名单中 + $where = [ + "user_id"=>$user_id + ]; + $blacklist = Blacklist::where($where)->find(); + + if($blacklist)throw new \Exception("您已进入黑名单,无法进行其他免费课时报名!"); + } } diff --git a/application/extra/upload.php b/application/extra/upload.php index 8a1c922..50e57ab 100644 --- a/application/extra/upload.php +++ b/application/extra/upload.php @@ -17,7 +17,7 @@ return [ /** * 最大可上传大小 */ - 'maxsize' => '100mb', + 'maxsize' => '5mb', /** * 可上传的文件类型 */ diff --git a/application/manystore/controller/general/Attachment.php b/application/manystore/controller/general/Attachment.php index 3ed4a81..bc49d86 100644 --- a/application/manystore/controller/general/Attachment.php +++ b/application/manystore/controller/general/Attachment.php @@ -54,6 +54,7 @@ class Attachment extends ManystoreBase $list = $this->model ->where($mimetypeQuery) + ->whereRaw("`filename` NOT REGEXP '^[0-9A-Fa-f]{32}'") ->where($where) ->order($sort, $order) ->paginate($limit); diff --git a/application/manystore/controller/manystore/UserAuth.php b/application/manystore/controller/manystore/UserAuth.php index 45ede7e..ddab723 100644 --- a/application/manystore/controller/manystore/UserAuth.php +++ b/application/manystore/controller/manystore/UserAuth.php @@ -3,6 +3,13 @@ namespace app\manystore\controller\manystore; use app\common\controller\ManystoreBase; +use app\common\model\User; +use app\manystore\model\Manystore; +use think\Db; +use think\Exception; +use think\exception\PDOException; +use think\exception\ValidateException; + /** * 授权机构用户 @@ -17,11 +24,14 @@ class UserAuth extends ManystoreBase * @var \app\manystore\model\manystore\UserAuth */ protected $model = null; + protected $qSwitch = true; + protected $qFields = ["shop_id","user_id"]; public function _initialize() { + $this->model = new \app\manystore\model\manystore\UserAuth; parent::_initialize(); - $this->model = new \app\manystore\model\manystore\UserAuth; + $this->view->assign("statusList", $this->model->getStatusList()); } @@ -62,10 +72,19 @@ class UserAuth extends ManystoreBase foreach ($list as $row) { $row->getRelation('manystoreshop')->visible(['name']); - $row->getRelation('user')->visible(['nickname','avatar']); + $row->getRelation('user')->visible(['nickname','avatar','mobile']); + } + $rows = $list->items(); + foreach ($list as $row) { + + if($row["status"]!=1){ + $row->user->mobile = "需授权通过"; + } } - $result = array("total" => $list->total(), "rows" => $list->items()); + + + $result = array("total" => $list->total(), "rows" => $rows); return json($result); } @@ -101,4 +120,206 @@ class UserAuth extends ManystoreBase return $this->view->fetch(); } + + + + + protected function updateCheck($id,$params=[],$row=null){ + + // 课程存在售后订单则不允许操作 + } + + + protected function update_check(&$params,$row=null) + { + + $shop_id = SHOP_ID; + $manystore = Manystore::where("shop_id", $shop_id)->find(); + if (!$manystore) { + $this->error("店铺不存在"); + } +// $params["manystore_id"] = $manystore["id"]; + $params["shop_id"] = $shop_id; + $user = User::where("nickname|realname|mobile", $params["user_id"])->find(); + if(!$user) $this->error("未找到用户请先让用户登录小程序再提交表单"); + $params["user_id"] = $user["id"]; + + $user_id = $params["user_id"]; + //修改 + 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("已向用户发起过授权申请!"); + } + } + + + } + + + + /** + * 添加 + * + * @return string + * @throws \think\Exception + */ + public function add() + { + if ($this->request->isPost()) { + $params = $this->request->post("row/a"); + if ($params) { + $params = $this->preExcludeFields($params); + + if($this->storeIdFieldAutoFill && STORE_ID ){ + $params['store_id'] = STORE_ID; + } + + if($this->shopIdAutoCondition && SHOP_ID){ + $params['shop_id'] = SHOP_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(true)->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"],0,'shop',$this->auth->id); + + Db::commit(); + } catch (ValidateException $e) { + Db::rollback(); + $this->error($e->getMessage()); + } catch (PDOException $e) { + Db::rollback(); + $this->error($e->getMessage()); + } catch (\Exception $e) { + Db::rollback(); + $this->error($e->getMessage()); + } + if ($result !== false) { + $this->success(); + } else { + $this->error(__('No rows were inserted')); + } + } + $this->error(__('Parameter %s can not be empty', '')); + } + return $this->view->fetch(); + } + + /** + * 编辑 + */ + public function edit($ids = null) + { + if($this->shopIdAutoCondition){ + $this->model->where(array('shop_id'=>SHOP_ID)); + } + $row = $this->model->where(array('id'=>$ids))->find(); + if (!$row) { + $this->error(__('No Results were found')); + } + + if ($this->request->isPost()) { + $params = $this->request->post("row/a"); + if ($params) { + $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(true)->validate($validate); + } + $this->update_check($params,$row); + + +// $result = $row->allowField(true)->save($params); + Db::commit(); + } catch (ValidateException $e) { + Db::rollback(); + $this->error($e->getMessage()); + } catch (PDOException $e) { + Db::rollback(); + $this->error($e->getMessage()); + } catch (\Exception $e) { + Db::rollback(); + $this->error($e->getMessage()); + } + if ($result !== false) { + $this->success(); + } else { + $this->error(__('No rows were updated')); + } + } + $this->error(__('Parameter %s can not be empty', '')); + } + + + $user = User::where("id", $row["user_id"])->find(); +// if(!$user) $this->error("未找到用户请先让用户登录小程序再提交表单"); + $row["user_id"] = $user["mobile"]?? ""; //nickname|realname|mobile + $this->view->assign("row", $row); + return $this->view->fetch(); + } + + /** + * 删除 + */ + public function del($ids = "") + { + if (!$this->request->isPost()) { + $this->error(__("Invalid parameters")); + } + $ids = $ids ? $ids : $this->request->post("ids"); + if ($ids) { + $pk = $this->model->getPk(); + if($this->shopIdAutoCondition){ + $this->model->where(array('shop_id'=>SHOP_ID)); + } + $list = $this->model->where($pk, 'in', $ids)->select(); + foreach ($list as $item) { + $this->updateCheck($item->id); + } + $count = 0; + Db::startTrans(); + try { + foreach ($list as $k => $v) { + $count += $v->delete(); + } + Db::commit(); + } catch (PDOException $e) { + Db::rollback(); + $this->error($e->getMessage()); + } catch (Exception $e) { + Db::rollback(); + $this->error($e->getMessage()); + } + if ($count) { + $this->success(); + } else { + $this->error(__('No rows were deleted')); + } + } + $this->error(__('Parameter %s can not be empty', 'ids')); + } + + } diff --git a/application/manystore/controller/school/classes/Teacher.php b/application/manystore/controller/school/classes/Teacher.php index e145cde..363b80b 100644 --- a/application/manystore/controller/school/classes/Teacher.php +++ b/application/manystore/controller/school/classes/Teacher.php @@ -3,6 +3,7 @@ namespace app\manystore\controller\school\classes; use app\common\controller\ManystoreBase; +use app\common\model\manystore\UserAuth; use app\common\model\User; use app\manystore\model\Manystore; use think\Db; @@ -25,7 +26,7 @@ class Teacher extends ManystoreBase protected $model = null; protected $qSwitch = true; - protected $qFields = ["manystore_id","shop_id"]; + protected $qFields = ["manystore_id","shop_id","user_id"]; public function _initialize() { @@ -102,6 +103,14 @@ class Teacher extends ManystoreBase $params["shop_id"] = $shop_id; $user = User::where("nickname|realname|mobile", $params["user_id"])->find(); if(!$user) $this->error("未找到用户请先让用户登录小程序再提交表单"); + + //如果开启了检测用户授权,则检测用户是否授权 + if(config("site.shop_auth_user_check")){ + if(!UserAuth::authcheck($shop_id,$user["id"])) $this->error("用户未授权当前机构!请先让用户授权同意您再操作!"); + } + + + $params["user_id"] = $user["id"]; $user_id = $params["user_id"]; diff --git a/application/manystore/controller/school/classes/Verification.php b/application/manystore/controller/school/classes/Verification.php index 7997138..ec07577 100644 --- a/application/manystore/controller/school/classes/Verification.php +++ b/application/manystore/controller/school/classes/Verification.php @@ -3,6 +3,7 @@ namespace app\manystore\controller\school\classes; use app\common\controller\ManystoreBase; +use app\common\model\manystore\UserAuth; use app\common\model\User; use app\manystore\model\Manystore; use think\Db; @@ -24,7 +25,7 @@ class Verification extends ManystoreBase */ protected $model = null; protected $qSwitch = true; - protected $qFields = ["manystore_id","shop_id"]; + protected $qFields = ["manystore_id","shop_id","user_id"]; public function _initialize() { @@ -103,6 +104,13 @@ class Verification extends ManystoreBase $params["shop_id"] = $shop_id; $user = User::where("nickname|realname|mobile", $params["user_id"])->find(); if(!$user) $this->error("未找到用户请先让用户登录小程序再提交表单"); + + + //如果开启了检测用户授权,则检测用户是否授权 + if(config("site.shop_auth_user_check")){ + if(!UserAuth::authcheck($shop_id,$user["id"])) $this->error("用户未授权当前机构!请先让用户授权同意您再操作!"); + } + $params["user_id"] = $user["id"]; $user_id = $params["user_id"]; diff --git a/application/manystore/lang/zh-cn/manystore/user_auth.php b/application/manystore/lang/zh-cn/manystore/user_auth.php index 221acd5..b090031 100644 --- a/application/manystore/lang/zh-cn/manystore/user_auth.php +++ b/application/manystore/lang/zh-cn/manystore/user_auth.php @@ -7,6 +7,11 @@ return [ 'Status 0' => '待确认', 'Status 1' => '通过', 'Status 2' => '拒绝', + 'Add' => '添加用户授权申请', + 'Delete'=>'取消授权', + 'Del'=>'取消授权', + 'User.mobile'=>'用户手机号', + 'Auth_time' => '授权确认时间', 'Createtime' => '发起时间', 'Update_time' => '修改时间', diff --git a/application/manystore/lang/zh-cn/school/classes/classes_lib.php b/application/manystore/lang/zh-cn/school/classes/classes_lib.php index c7e0b18..7983756 100644 --- a/application/manystore/lang/zh-cn/school/classes/classes_lib.php +++ b/application/manystore/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/manystore/library/ManystoreAuth.php b/application/manystore/library/ManystoreAuth.php index c9e47c3..f0d2451 100644 --- a/application/manystore/library/ManystoreAuth.php +++ b/application/manystore/library/ManystoreAuth.php @@ -95,9 +95,9 @@ class ManystoreAuth } // 获取用户需要验证的所有有效规则列表 $rulelist = $this->getRuleList($uid); - if (in_array('*', $rulelist)) { - return true; - } +// if (in_array('*', $rulelist)) { +// return true; +// } if (is_string($name)) { $name = strtolower($name); diff --git a/application/manystore/view/manystore/user_auth/add.html b/application/manystore/view/manystore/user_auth/add.html index 7bb14ca..92ce40a 100644 --- a/application/manystore/view/manystore/user_auth/add.html +++ b/application/manystore/view/manystore/user_auth/add.html @@ -3,33 +3,38 @@
- + + + + (没找到用户则点击按钮创建用户后重新填入用户手机号) + 根据手机号生成用户 +
-
- -
- -
- {foreach name="statusList" item="vo"} - - {/foreach} -
+ + + + + + + + + -
-
-
- -
- -
-
-
- -
- -
-
+ + + + + + + + + + + + + +