From af55bd020b750ab9bdb5160f9bb65e7589903b38 Mon Sep 17 00:00:00 2001 From: 15090180611 <215509543@qq.com> Date: Sat, 4 Jan 2025 18:09:51 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E6=BC=8F=E6=B4=9E?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../admin/controller/manystore/Index.php | 70 ++++++++++++++++++- .../controller/school/classes/ClassesLib.php | 57 +++++++++++++++ .../controller/school/classes/Teacher.php | 63 ++++++++++++++++- .../school/classes/activity/Activity.php | 61 +++++++++++++++- application/admin/model/Admin.php | 7 +- application/api/controller/Demo.php | 47 ++++++++++++- .../api/controller/school/HourOrder.php | 1 + application/api/controller/school/Order.php | 12 +++- application/api/controller/school/Pay.php | 2 +- .../api/controller/school/ServiceOrder.php | 3 +- .../api/controller/school/activity/Order.php | 1 + .../api/controller/school/activity/Pay.php | 2 +- .../controller/school/worker/HourOrder.php | 1 + .../api/controller/school/worker/Order.php | 1 + .../controller/school/worker/ServiceOrder.php | 7 +- .../school/worker/activity/Order.php | 1 + application/common/controller/Api.php | 17 +++++ application/common/library/Virtual.php | 45 ++++++++++++ .../common/model/dyqc/ManystoreShop.php | 4 ++ .../model/school/classes/ClassesLib.php | 4 +- .../common/model/school/classes/Teacher.php | 4 ++ .../school/classes/activity/Activity.php | 4 ++ .../manystore/controller/general/Profile.php | 63 +++++++++++++++-- .../controller/school/classes/ClassesLib.php | 57 ++++++++++++++- .../controller/school/classes/Teacher.php | 63 ++++++++++++++++- .../school/classes/activity/Activity.php | 64 ++++++++++++++++- .../manystore/view/general/profile/index.html | 9 +++ extend/bw/Common.php | 39 ++++++++++- extend/traits/CacheTrait.php | 8 ++- extend/traits/ModelTrait.php | 16 +++++ public/assets/js/backend/manystore/index.js | 7 +- .../school/classes/activity/activity.js | 9 ++- .../js/backend/school/classes/classes_lib.js | 8 ++- .../js/backend/school/classes/teacher.js | 8 ++- .../school/classes/activity/activity.js | 8 ++- .../manystore/school/classes/classes_lib.js | 10 ++- .../js/manystore/school/classes/teacher.js | 8 ++- 37 files changed, 745 insertions(+), 46 deletions(-) diff --git a/application/admin/controller/manystore/Index.php b/application/admin/controller/manystore/Index.php index b9aefb0..13f49ab 100644 --- a/application/admin/controller/manystore/Index.php +++ b/application/admin/controller/manystore/Index.php @@ -24,6 +24,7 @@ use fast\Random; use fast\Tree; use think\Exception; use think\Hook; +use think\Url; use think\Validate; /** @@ -34,7 +35,7 @@ use think\Validate; */ class Index extends Backend { - + protected $noNeedLogin = ["miniqrcode"]; /** * @var \app\manystore\model\Manystore */ @@ -219,6 +220,7 @@ class Index extends Backend foreach ($list as $k => &$v){ $v["check_full"] = (new \app\common\model\dyqc\ManystoreShop)->checkFull($v["shop"]["id"]); + $v["miniqrcode_link"] = Url::build("/manystore/index/miniqrcode", ["ids" => $v["shop"]["id"]]); } @@ -719,8 +721,19 @@ class Index extends Backend if($this->request->isPost()){ try{ if(isset($param['ids']))$ids = $param['ids']; + + $row = $this->model->get(['id' => $ids,'is_main'=>1]); + if (!$row) { + $this->error(__('No Results were found')); + } + $shop_info = $this->shopModel->get(array('id'=>$row['shop_id'])); + if(!$shop_info){ + $this->error(__('商家信息资料不存在')); + } + + //设置模拟资格 - $url = \app\common\model\dyqc\ManystoreShop::getPath($ids); + $url = \app\common\model\dyqc\ManystoreShop::getPath($row['shop_id']); }catch (\Exception $e){ $this->error($e->getMessage()); @@ -731,4 +744,57 @@ class Index extends Backend $this->view->assign('vo', $row); return $this->view->fetch(); } + + + /** + * 微信小程序码 + * @return string + * @throws \think\Exception + * @throws \think\db\exception\BindParamException + * @throws \think\exception\DbException + * @throws \think\exception\PDOException + */ + public function miniqrcode($ids = ''){ + $param = $this->request->param(); + try{ + if(isset($param['ids']))$ids = $param['ids']; + //设置模拟资格 + $url = \app\common\model\dyqc\ManystoreShop::getMiniQrcodeLink($ids); + + }catch (\Exception $e){ + $this->error($e->getMessage()); + } + + return $url["response"]; + } + + + + + /** + * 查看微信小程序码 + * @return string + * @throws \think\Exception + * @throws \think\db\exception\BindParamException + * @throws \think\exception\DbException + * @throws \think\exception\PDOException + */ + public function lookminiqrcode($ids = ''){ + $param = $this->request->param(); + if($this->request->isPost()){ + try{ + if(isset($param['ids']))$ids = $param['ids']; + //设置模拟资格 + $url = \app\common\model\dyqc\ManystoreShop::getMiniQrcodeLink($ids); + + }catch (\Exception $e){ + $this->error($e->getMessage()); + } + $this->success("生成小程序码成功",null,$url); + } + $row = $this->model->get($ids); + $this->view->assign('vo', $row); + return $this->view->fetch(); + } + } diff --git a/application/admin/controller/school/classes/ClassesLib.php b/application/admin/controller/school/classes/ClassesLib.php index 31f8bf6..b3ca495 100644 --- a/application/admin/controller/school/classes/ClassesLib.php +++ b/application/admin/controller/school/classes/ClassesLib.php @@ -18,6 +18,7 @@ use think\exception\PDOException; use think\exception\ValidateException; use think\Loader; use think\Model; +use think\Url; /** * 机构课程库 @@ -27,6 +28,7 @@ use think\Model; class ClassesLib extends Backend { + protected $noNeedLogin = ["miniqrcode"]; protected $qSwitch = true; protected $qFields = ["teacher_id","user_id","shop_id","manystore_id"]; /** @@ -141,6 +143,7 @@ class ClassesLib extends Backend foreach ($rows as $k => &$v) { $v["classes_type_name"] = $types[$v["classes_type"]] ?? "无"; + $v["miniqrcode_link"] = Url::build("/school/classes/classes_lib/miniqrcode", ["ids" => $v["id"]]); } $result = array("total" => $list->total(), "rows" => $rows); @@ -1080,4 +1083,58 @@ class ClassesLib extends Backend } + + + /** + * 微信小程序码 + * @return string + * @throws \think\Exception + * @throws \think\db\exception\BindParamException + * @throws \think\exception\DbException + * @throws \think\exception\PDOException + */ + public function miniqrcode($ids = ''){ + $param = $this->request->param(); + try{ + if(isset($param['ids']))$ids = $param['ids']; + //设置模拟资格 + $url = \app\common\model\school\classes\ClassesLib::getMiniQrcodeLink($ids); + + }catch (\Exception $e){ + $this->error($e->getMessage()); + } + + return $url["response"]; + } + + + + + /** + * 查看微信小程序码 + * @return string + * @throws \think\Exception + * @throws \think\db\exception\BindParamException + * @throws \think\exception\DbException + * @throws \think\exception\PDOException + */ + public function lookminiqrcode($ids = ''){ + $param = $this->request->param(); + if($this->request->isPost()){ + try{ + if(isset($param['ids']))$ids = $param['ids']; + //设置模拟资格 + $url = \app\common\model\school\classes\ClassesLib::getMiniQrcodeLink($ids); + + }catch (\Exception $e){ + $this->error($e->getMessage()); + } + $this->success("生成小程序码成功",null,$url); + } + $row = $this->model->get($ids); + $this->view->assign('vo', $row); + return $this->view->fetch(); + } + + } diff --git a/application/admin/controller/school/classes/Teacher.php b/application/admin/controller/school/classes/Teacher.php index 658dd68..aa8bfd7 100644 --- a/application/admin/controller/school/classes/Teacher.php +++ b/application/admin/controller/school/classes/Teacher.php @@ -16,6 +16,7 @@ use think\exception\DbException; use think\exception\PDOException; use think\exception\ValidateException; use think\Model; +use think\Url; /** * 机构老师 @@ -24,7 +25,7 @@ use think\Model; */ class Teacher extends Backend { - + protected $noNeedLogin = ["miniqrcode"]; /** * Teacher模型对象 * @var \app\admin\model\school\classes\Teacher @@ -86,7 +87,12 @@ class Teacher extends Backend $row->getRelation('shop')->visible(['name','logo','image','address_city','province','city','district','address','address_detail']); } - $result = array("total" => $list->total(), "rows" => $list->items()); + $rows = $list->items(); + foreach ($rows as $k=>&$v){ + $v["miniqrcode_link"] = Url::build("/school/classes/teacher/miniqrcode", ["ids" => $v["id"]]); + } + + $result = array("total" => $list->total(), "rows" => $rows); return json($result); } @@ -342,4 +348,57 @@ class Teacher extends Backend } + /** + * 微信小程序码 + * @return string + * @throws \think\Exception + * @throws \think\db\exception\BindParamException + * @throws \think\exception\DbException + * @throws \think\exception\PDOException + */ + public function miniqrcode($ids = ''){ + $param = $this->request->param(); + try{ + if(isset($param['ids']))$ids = $param['ids']; + //设置模拟资格 + $url = \app\common\model\school\classes\Teacher::getMiniQrcodeLink($ids); + + }catch (\Exception $e){ + $this->error($e->getMessage()); + } + + return $url["response"]; + } + + + + + /** + * 查看微信小程序码 + * @return string + * @throws \think\Exception + * @throws \think\db\exception\BindParamException + * @throws \think\exception\DbException + * @throws \think\exception\PDOException + */ + public function lookminiqrcode($ids = ''){ + $param = $this->request->param(); + if($this->request->isPost()){ + try{ + if(isset($param['ids']))$ids = $param['ids']; + //设置模拟资格 + $url = \app\common\model\school\classes\Teacher::getMiniQrcodeLink($ids); + + }catch (\Exception $e){ + $this->error($e->getMessage()); + } + $this->success("生成小程序码成功",null,$url); + } + $row = $this->model->get($ids); + $this->view->assign('vo', $row); + return $this->view->fetch(); + } + + + } diff --git a/application/admin/controller/school/classes/activity/Activity.php b/application/admin/controller/school/classes/activity/Activity.php index 145ee84..0d27388 100644 --- a/application/admin/controller/school/classes/activity/Activity.php +++ b/application/admin/controller/school/classes/activity/Activity.php @@ -11,6 +11,7 @@ use think\Exception; use think\exception\DbException; use think\exception\PDOException; use think\exception\ValidateException; +use think\Url; /** * 课程活动 @@ -29,6 +30,7 @@ class Activity extends Backend protected $qSwitch = true; protected $qFields = ["user_id","shop_id","manystore_id"]; + protected $noNeedLogin = ["miniqrcode"]; //不用审核允许修改的字段 @@ -143,8 +145,11 @@ class Activity extends Backend $row->getRelation('manystore')->visible(['nickname']); $row->getRelation('shop')->visible(['name','logo']); } - - $result = array("total" => $list->total(), "rows" => $list->items()); + $rows = $list->items(); + foreach ($rows as $k=>&$v){ + $v["miniqrcode_link"] = Url::build("/school/classes/activity/activity/miniqrcode", ["ids" => $v["id"]]); + } + $result = array("total" => $list->total(), "rows" => $rows); return json($result); } @@ -456,4 +461,56 @@ class Activity extends Backend } + /** + * 微信小程序码 + * @return string + * @throws \think\Exception + * @throws \think\db\exception\BindParamException + * @throws \think\exception\DbException + * @throws \think\exception\PDOException + */ + public function miniqrcode($ids = ''){ + $param = $this->request->param(); + try{ + if(isset($param['ids']))$ids = $param['ids']; + //设置模拟资格 + $url = \app\common\model\school\classes\activity\Activity::getMiniQrcodeLink($ids); + + }catch (\Exception $e){ + $this->error($e->getMessage()); + } + + return $url["response"]; + } + + + + + /** + * 查看微信小程序码 + * @return string + * @throws \think\Exception + * @throws \think\db\exception\BindParamException + * @throws \think\exception\DbException + * @throws \think\exception\PDOException + */ + public function lookminiqrcode($ids = ''){ + $param = $this->request->param(); + if($this->request->isPost()){ + try{ + if(isset($param['ids']))$ids = $param['ids']; + //设置模拟资格 + $url = \app\common\model\school\classes\activity\Activity::getMiniQrcodeLink($ids); + + }catch (\Exception $e){ + $this->error($e->getMessage()); + } + $this->success("生成小程序码成功",null,$url); + } + $row = $this->model->get($ids); + $this->view->assign('vo', $row); + return $this->view->fetch(); + } + + } diff --git a/application/admin/model/Admin.php b/application/admin/model/Admin.php index b01f3df..79975f5 100644 --- a/application/admin/model/Admin.php +++ b/application/admin/model/Admin.php @@ -60,10 +60,11 @@ class Admin extends Model } public static function getHaveCity($adminId){ - $admin = self::get($adminId); - if(!$admin)throw new \Exception("管理员不存在"); - $area_json = $admin->area_json; $provinces = $citys = $districts = $address_citys = []; + $admin = self::get($adminId); + if(!$admin)return compact("provinces","citys","districts","address_citys"); + $area_json = $admin->area_json; + if($area_json){ $searchCity = SearchCity::where("id","in",$area_json)->select(); foreach ($searchCity as $item){ diff --git a/application/api/controller/Demo.php b/application/api/controller/Demo.php index 17555b3..e862836 100644 --- a/application/api/controller/Demo.php +++ b/application/api/controller/Demo.php @@ -2,8 +2,12 @@ namespace app\api\controller; +use app\admin\model\school\help\Cate; use app\common\controller\Api; use app\common\job\test\DemoJob; +use app\common\model\appointment\car\MockOrder; +use bw\UrlLock; +use think\Cache; /** * 示例接口 @@ -16,7 +20,7 @@ class Demo extends Api //如果接口已经设置无需登录,那也就无需鉴权了 // // 无需登录的接口,*表示全部 - protected $noNeedLogin = ['test', 'test1']; + protected $noNeedLogin = ['test', 'test1','test2']; // 无需鉴权的接口,*表示全部 protected $noNeedRight = ['test2']; @@ -51,6 +55,32 @@ class Demo extends Api */ public function test1() { + + try{ + + $lock = new UrlLock(1,"mock-create-lock-suffix",120,"您的请求过于频繁,请您稍后再试!请求最大锁定间隔5秒/一次!"); + $lock->lock(); + //往缓存里取出数字 + $num = cache('test'); + if(!$num){ + $num = 1; + cache('test',$num); + }else{ + $num++; + cache('test',$num); + } + //数字加1 + //再存入缓存 + //再写入test.txt文件末尾(记得回车换行) + file_put_contents("test.txt",$num."\r\n",FILE_APPEND); + + }catch (\Throwable $e){ + $lock->free(); +// file_put_contents("test.txt",$e->getMessage().$e->getFile().$e->getLine());//写入文件,一般做正式环境测试 + $this->error($e->getMessage()); + } + $lock->free(); + $this->success('返回成功', ['action' => 'test1']); } @@ -60,7 +90,20 @@ class Demo extends Api */ public function test2() { - $this->success('返回成功', ['action' => 'test2']); + try{ + + $lock = new UrlLock(1,"mock-create-lock-suffix",120,"您的请求过于频繁,请您稍后再试!请求最大锁定间隔5秒/一次!"); + $lock->lock(); + var_dump(time()); + sleep(5); + }catch (\Throwable $e){ + $lock->free(); +// file_put_contents("test.txt",$e->getMessage().$e->getFile().$e->getLine());//写入文件,一般做正式环境测试 + $this->error($e->getMessage()); + } + $lock->free(); + + $this->success('返回成功', ['action' => 'test1']); } /** diff --git a/application/api/controller/school/HourOrder.php b/application/api/controller/school/HourOrder.php index bfd8ec0..67ab88f 100644 --- a/application/api/controller/school/HourOrder.php +++ b/application/api/controller/school/HourOrder.php @@ -26,6 +26,7 @@ class HourOrder extends Base parent::_initialize(); //判断登录用户是否是员工 + $this->setUrlLock(); } diff --git a/application/api/controller/school/Order.php b/application/api/controller/school/Order.php index 5a87ee0..52cf78a 100644 --- a/application/api/controller/school/Order.php +++ b/application/api/controller/school/Order.php @@ -4,6 +4,8 @@ namespace app\api\controller\school; use app\common\model\school\classes\order\Order as OrderModel; use app\common\model\school\classes\Teacher as Teachermodel; +use bw\UrlLock; +use think\Loader; /** * 用户端:课程订单接口 @@ -25,7 +27,9 @@ class Order extends Base $this->model = new OrderModel; parent::_initialize(); - //判断登录用户是否是员工 + $this->setUrlLock(); + + } @@ -115,15 +119,21 @@ class Order extends Base if($user)$user_id = $user['id']; $order_no = $this->request->post('order_no/s', ''); //订单号 $remark = $this->request->post('remark/s', ''); //下单备注 + // repeat_filter("appointment\order\create".$user_id, 2); try{ +// $lock = new UrlLock($user_id,"class-order-create-lock-suffix",120,"您的请求过于频繁,请您稍后再试!请求最大锁定间隔120秒!"); +// $lock->lock(); + //当前申请状态 $res = $this->model->cacheCreateOrder($order_no,$user_id,$remark,true); }catch (\Throwable $e){ // file_put_contents("test.txt",$e->getMessage().$e->getFile().$e->getLine());//写入文件,一般做正式环境测试 // Log::log($e->getMessage()); +// if(isset($lock))$lock->free(); $this->error($e->getMessage(),['errcode'=>$e->getCode()]);; } +// if(isset($lock))$lock->free(); $this->success('订单创建成功,缓存key被消耗', $res); } diff --git a/application/api/controller/school/Pay.php b/application/api/controller/school/Pay.php index 25c4a62..6e3a660 100644 --- a/application/api/controller/school/Pay.php +++ b/application/api/controller/school/Pay.php @@ -28,7 +28,7 @@ class Pay extends Base $this->model = new OrderModel; parent::_initialize(); - + $this->setUrlLock(); //判断登录用户是否是员工 } diff --git a/application/api/controller/school/ServiceOrder.php b/application/api/controller/school/ServiceOrder.php index 25ce894..aa73a7a 100644 --- a/application/api/controller/school/ServiceOrder.php +++ b/application/api/controller/school/ServiceOrder.php @@ -26,6 +26,7 @@ class ServiceOrder extends Base parent::_initialize(); //判断登录用户是否是员工 + $this->setUrlLock(); } @@ -46,7 +47,7 @@ class ServiceOrder extends Base } try { - $res = OrderModel::getDetail($id); + $res = $this->model::getDetail($id); } catch (\Exception $e){ // Log::log($e->getMessage()); $this->error($e->getMessage(),['errcode'=>$e->getCode()]); diff --git a/application/api/controller/school/activity/Order.php b/application/api/controller/school/activity/Order.php index da38029..98de2e1 100644 --- a/application/api/controller/school/activity/Order.php +++ b/application/api/controller/school/activity/Order.php @@ -27,6 +27,7 @@ class Order extends Base parent::_initialize(); //判断登录用户是否是员工 + $this->setUrlLock(); } diff --git a/application/api/controller/school/activity/Pay.php b/application/api/controller/school/activity/Pay.php index d195656..fa3f567 100644 --- a/application/api/controller/school/activity/Pay.php +++ b/application/api/controller/school/activity/Pay.php @@ -29,7 +29,7 @@ class Pay extends Base $this->model = new OrderModel; parent::_initialize(); - + $this->setUrlLock(); //判断登录用户是否是员工 } diff --git a/application/api/controller/school/worker/HourOrder.php b/application/api/controller/school/worker/HourOrder.php index da6e6c2..de4b3c0 100644 --- a/application/api/controller/school/worker/HourOrder.php +++ b/application/api/controller/school/worker/HourOrder.php @@ -28,6 +28,7 @@ class HourOrder extends Base parent::_initialize(); //判断登录用户是否是员工 + $this->setUrlLock(); } diff --git a/application/api/controller/school/worker/Order.php b/application/api/controller/school/worker/Order.php index f3cd8a5..ea8f2ba 100644 --- a/application/api/controller/school/worker/Order.php +++ b/application/api/controller/school/worker/Order.php @@ -27,6 +27,7 @@ class Order extends Base parent::_initialize(); //判断登录用户是否是员工 + $this->setUrlLock(); } diff --git a/application/api/controller/school/worker/ServiceOrder.php b/application/api/controller/school/worker/ServiceOrder.php index d1edcc4..9af23cd 100644 --- a/application/api/controller/school/worker/ServiceOrder.php +++ b/application/api/controller/school/worker/ServiceOrder.php @@ -27,6 +27,7 @@ class ServiceOrder extends Base parent::_initialize(); //判断登录用户是否是员工 + $this->setUrlLock(); } @@ -47,7 +48,7 @@ class ServiceOrder extends Base } try { - $res = OrderModel::getDetail($id,$this->classes_lib_ids); + $res = $this->model::getDetail($id,$this->classes_lib_ids); if(!$res)throw new \Exception('您无操作权限!',40003); } catch (\Exception $e){ // Log::log($e->getMessage()); @@ -241,8 +242,8 @@ class ServiceOrder extends Base $status = "yes"; $reject_reason = ""; $reject_images = ""; - $model = (new \app\common\model\school\classes\order\ServiceOrder()); - $model->shopConfirmation($res["order_no"],$status,$price,$reject_reason,$reject_images,0,true,'user',$user_id,true); +// $model = (new \app\common\model\school\classes\order\ServiceOrder()); + $this->model->shopConfirmation($res["order_no"],$status,$price,$reject_reason,$reject_images,0,true,'user',$user_id,true); diff --git a/application/api/controller/school/worker/activity/Order.php b/application/api/controller/school/worker/activity/Order.php index f18d180..717fca5 100644 --- a/application/api/controller/school/worker/activity/Order.php +++ b/application/api/controller/school/worker/activity/Order.php @@ -28,6 +28,7 @@ class Order extends Base parent::_initialize(); //判断登录用户是否是员工 + $this->setUrlLock(); } diff --git a/application/common/controller/Api.php b/application/common/controller/Api.php index 3b05fbe..49b4b85 100644 --- a/application/common/controller/Api.php +++ b/application/common/controller/Api.php @@ -87,6 +87,23 @@ class Api } } + + public function setUrlLock(){ + if($this->request->isPost() && !empty($this->model)){ + $user_id = 0; + $user = $this->auth->getUser();//登录用户 + if($user)$user_id = $user['id']; + + $modulename = $this->request->module(); + $controllername = Loader::parseName($this->request->controller()); + $actionname = strtolower($this->request->action()); + $path = $modulename . '/' . str_replace('.', '/', $controllername) . '/' . $actionname; + $this->model::$url_lock_key = $user_id; + $this->model::$url_lock_suffix = $path."lock-suffix"; + $this->model::$url_lock = true; + } + } + /** * 初始化操作 * @access protected diff --git a/application/common/library/Virtual.php b/application/common/library/Virtual.php index ba05763..6ac68f9 100644 --- a/application/common/library/Virtual.php +++ b/application/common/library/Virtual.php @@ -2,6 +2,7 @@ namespace app\common\library; +use addons\epay\library\Service; use app\common\model\school\Area; use app\common\model\school\classes\VirtualHead; use app\common\model\school\classes\VirtualUser; @@ -171,5 +172,49 @@ class Virtual return $template; } + public static function getMiniQrcodeLink($key,$params=[],$expression = '{{KEYWORD}}'){ + $path = self::getPath($key,$params,$expression); + //如果路径开头有斜杠则去除 + if(substr($path,0,1) == "/"){ + $path = substr($path,1); + } + //解析该路径,获取url参数和除去参数的url + $url_params = []; + $url = ""; + if(strpos($path,"?") !== false){ + $url_params = explode("?",$path); + $url = $url_params[0]; + $url_params = $url_params[1]; + }else{ + $url = $path; + } + + + $q_params = []; + //生成小程序二维码 + $query = $url_params; + $q_params["path"] = $url; + if($query)$q_params["query"] = $query; + + // 实例对应的接口对象 + $scheme = new \WeMini\Scheme(Service::wechatConfig()); + $res= $scheme->urlLink($q_params); + if(!isset($res["url_link"]))throw new \Exception("生成小程序二维码失败"); + $url_link = $res["url_link"]; + //链接生成二维码 + //二维码 + $response = Common::getQrcode([ + 'text' => $url_link, + 'size' => 200, + ],false,false,true); + //全返回 + return compact("url_link","response"); + } + + + + + + } \ No newline at end of file diff --git a/application/common/model/dyqc/ManystoreShop.php b/application/common/model/dyqc/ManystoreShop.php index daaf4bd..0d51295 100644 --- a/application/common/model/dyqc/ManystoreShop.php +++ b/application/common/model/dyqc/ManystoreShop.php @@ -1162,5 +1162,9 @@ public function adminCreateShop($admin_id){ return Virtual::getPath("shop",["shop_id"=>$id]); } + public static function getMiniQrcodeLink($id){ + return Virtual::getMiniQrcodeLink("shop",["shop_id"=>$id]); + } + } diff --git a/application/common/model/school/classes/ClassesLib.php b/application/common/model/school/classes/ClassesLib.php index 31def7e..f551289 100644 --- a/application/common/model/school/classes/ClassesLib.php +++ b/application/common/model/school/classes/ClassesLib.php @@ -1886,6 +1886,8 @@ $user_unpaid_order = $user_paid_order =null; return Virtual::getPath("classes",["classes_id"=>$id]); } - + public static function getMiniQrcodeLink($id){ + return Virtual::getMiniQrcodeLink("classes",["classes_id"=>$id]); + } } diff --git a/application/common/model/school/classes/Teacher.php b/application/common/model/school/classes/Teacher.php index 28861ce..634db2f 100644 --- a/application/common/model/school/classes/Teacher.php +++ b/application/common/model/school/classes/Teacher.php @@ -167,4 +167,8 @@ class Teacher extends BaseModel return Virtual::getPath("teacher",["teacher_id"=>$id]); } + public static function getMiniQrcodeLink($id){ + return Virtual::getMiniQrcodeLink("teacher",["teacher_id"=>$id]); + } + } diff --git a/application/common/model/school/classes/activity/Activity.php b/application/common/model/school/classes/activity/Activity.php index 29846da..5573d60 100644 --- a/application/common/model/school/classes/activity/Activity.php +++ b/application/common/model/school/classes/activity/Activity.php @@ -1599,4 +1599,8 @@ class Activity extends BaseModel return Virtual::getPath("activity",["activity_id"=>$id]); } + public static function getMiniQrcodeLink($id){ + return Virtual::getMiniQrcodeLink("activity",["activity_id"=>$id]); + } + } diff --git a/application/manystore/controller/general/Profile.php b/application/manystore/controller/general/Profile.php index 68b7fdd..a35a4e4 100644 --- a/application/manystore/controller/general/Profile.php +++ b/application/manystore/controller/general/Profile.php @@ -8,6 +8,7 @@ use app\common\controller\ManystoreBase; use fast\Random; use think\Exception; use think\Session; +use think\Url; use think\Validate; /** @@ -17,7 +18,7 @@ use think\Validate; */ class Profile extends ManystoreBase { - + protected $noNeedLogin = ["miniqrcode"]; /** * 查看 */ @@ -33,6 +34,7 @@ class Profile extends ManystoreBase $this->view->assign('check_full_msg',(new \app\common\model\dyqc\ManystoreShop)->checkFullMsg(SHOP_ID)); $this->getCity(); + $this->view->assign('miniqrcode_link',Url::build("/manystore/general/profile/miniqrcode", ["ids" => SHOP_ID])); return $this->view->fetch(); } @@ -72,9 +74,7 @@ class Profile extends ManystoreBase Session::set("manystore", $manystore->toArray()); - //调用事件 - $data = ['shop' => $manystore]; - \think\Hook::listen('shop_update_after', $data); + $this->success(); } $this->error(); @@ -92,9 +92,64 @@ class Profile extends ManystoreBase $shopModel = new ManystoreShop(); $shopModel->save($shop,array('id'=>SHOP_ID)); + //调用事件 + $data = ['shop' => $shopModel]; + \think\Hook::listen('shop_update_after', $data); $this->success(); } $this->error(); } + + + /** + * 微信小程序码 + * @return string + * @throws \think\Exception + * @throws \think\db\exception\BindParamException + * @throws \think\exception\DbException + * @throws \think\exception\PDOException + */ + public function miniqrcode($ids = ''){ + $param = $this->request->param(); + try{ + if(isset($param['ids']))$ids = $param['ids']; + //设置模拟资格 + $url = \app\common\model\dyqc\ManystoreShop::getMiniQrcodeLink($ids); + + }catch (\Exception $e){ + $this->error($e->getMessage()); + } + + return $url["response"]; + } + + + + + /** + * 查看微信小程序码 + * @return string + * @throws \think\Exception + * @throws \think\db\exception\BindParamException + * @throws \think\exception\DbException + * @throws \think\exception\PDOException + */ + public function lookminiqrcode($ids = ''){ + $param = $this->request->param(); + if($this->request->isPost()){ + try{ + if(isset($param['ids']))$ids = $param['ids']; + //设置模拟资格 + $url = \app\common\model\dyqc\ManystoreShop::getMiniQrcodeLink($ids); + + }catch (\Exception $e){ + $this->error($e->getMessage()); + } + $this->success("生成小程序码成功",null,$url); + } + $row = $this->model->get($ids); + $this->view->assign('vo', $row); + return $this->view->fetch(); + } } diff --git a/application/manystore/controller/school/classes/ClassesLib.php b/application/manystore/controller/school/classes/ClassesLib.php index 4a8726f..dd37c2c 100644 --- a/application/manystore/controller/school/classes/ClassesLib.php +++ b/application/manystore/controller/school/classes/ClassesLib.php @@ -15,6 +15,7 @@ use think\Exception; use think\exception\DbException; use think\exception\PDOException; use think\exception\ValidateException; +use think\Url; /** * 机构课程库 @@ -23,7 +24,7 @@ use think\exception\ValidateException; */ class ClassesLib extends ManystoreBase { - + protected $noNeedLogin = ["miniqrcode"]; protected $qSwitch = true; protected $qFields = ["teacher_id","user_id","shop_id","manystore_id"]; /** @@ -146,6 +147,7 @@ class ClassesLib extends ManystoreBase foreach ($rows as $k=>&$v){ $v["classes_type_name"] = $types[$v["classes_type"]] ?? "无" ; + $v["miniqrcode_link"] = Url::build("/manystore/school/classes/classes_lib/miniqrcode", ["ids" => $v["id"]]); } $result = array("total" => $list->total(), "rows" => $rows); @@ -649,4 +651,57 @@ class ClassesLib extends ManystoreBase } + + /** + * 微信小程序码 + * @return string + * @throws \think\Exception + * @throws \think\db\exception\BindParamException + * @throws \think\exception\DbException + * @throws \think\exception\PDOException + */ + public function miniqrcode($ids = ''){ + $param = $this->request->param(); + try{ + if(isset($param['ids']))$ids = $param['ids']; + //设置模拟资格 + $url = \app\common\model\school\classes\ClassesLib::getMiniQrcodeLink($ids); + + }catch (\Exception $e){ + $this->error($e->getMessage()); + } + + return $url["response"]; + } + + + + + /** + * 查看微信小程序码 + * @return string + * @throws \think\Exception + * @throws \think\db\exception\BindParamException + * @throws \think\exception\DbException + * @throws \think\exception\PDOException + */ + public function lookminiqrcode($ids = ''){ + $param = $this->request->param(); + if($this->request->isPost()){ + try{ + if(isset($param['ids']))$ids = $param['ids']; + //设置模拟资格 + $url = \app\common\model\school\classes\ClassesLib::getMiniQrcodeLink($ids); + + }catch (\Exception $e){ + $this->error($e->getMessage()); + } + $this->success("生成小程序码成功",null,$url); + } + $row = $this->model->get($ids); + $this->view->assign('vo', $row); + return $this->view->fetch(); + } + + } diff --git a/application/manystore/controller/school/classes/Teacher.php b/application/manystore/controller/school/classes/Teacher.php index 6e75745..806f3c7 100644 --- a/application/manystore/controller/school/classes/Teacher.php +++ b/application/manystore/controller/school/classes/Teacher.php @@ -10,6 +10,7 @@ use think\Db; use think\Exception; use think\exception\PDOException; use think\exception\ValidateException; +use think\Url; /** * 机构老师 @@ -18,7 +19,7 @@ use think\exception\ValidateException; */ class Teacher extends ManystoreBase { - + protected $noNeedLogin = ["miniqrcode"]; /** * Teacher模型对象 * @var \app\manystore\model\school\classes\Teacher @@ -78,7 +79,12 @@ class Teacher extends ManystoreBase $row->getRelation('manystoreshop')->visible(['name','image','address_city','province','city','district','address','address_detail']); } - $result = array("total" => $list->total(), "rows" => $list->items()); + $rows = $list->items(); + foreach ($rows as $k=>&$v){ + $v["miniqrcode_link"] = Url::build("/manystore/school/classes/teacher/miniqrcode", ["ids" => $v["id"]]); + } + + $result = array("total" => $list->total(), "rows" => $rows); return json($result); } @@ -310,4 +316,57 @@ class Teacher extends ManystoreBase $this->error(__('Parameter %s can not be empty', 'ids')); } + + + /** + * 微信小程序码 + * @return string + * @throws \think\Exception + * @throws \think\db\exception\BindParamException + * @throws \think\exception\DbException + * @throws \think\exception\PDOException + */ + public function miniqrcode($ids = ''){ + $param = $this->request->param(); + try{ + if(isset($param['ids']))$ids = $param['ids']; + //设置模拟资格 + $url = \app\common\model\school\classes\Teacher::getMiniQrcodeLink($ids); + + }catch (\Exception $e){ + $this->error($e->getMessage()); + } + + return $url["response"]; + } + + + + + /** + * 查看微信小程序码 + * @return string + * @throws \think\Exception + * @throws \think\db\exception\BindParamException + * @throws \think\exception\DbException + * @throws \think\exception\PDOException + */ + public function lookminiqrcode($ids = ''){ + $param = $this->request->param(); + if($this->request->isPost()){ + try{ + if(isset($param['ids']))$ids = $param['ids']; + //设置模拟资格 + $url = \app\common\model\school\classes\Teacher::getMiniQrcodeLink($ids); + + }catch (\Exception $e){ + $this->error($e->getMessage()); + } + $this->success("生成小程序码成功",null,$url); + } + $row = $this->model->get($ids); + $this->view->assign('vo', $row); + return $this->view->fetch(); + } + } diff --git a/application/manystore/controller/school/classes/activity/Activity.php b/application/manystore/controller/school/classes/activity/Activity.php index 5acdf38..c0e3807 100644 --- a/application/manystore/controller/school/classes/activity/Activity.php +++ b/application/manystore/controller/school/classes/activity/Activity.php @@ -11,6 +11,7 @@ use think\Db; use think\Exception; use think\exception\PDOException; use think\exception\ValidateException; +use think\Url; /** * 课程活动 @@ -31,7 +32,7 @@ class Activity extends ManystoreBase protected $qFields = ["user_id","shop_id","manystore_id"]; //不用审核允许修改的字段 protected $no_auth_fields = ['headimage','images',"status"]; - + protected $noNeedLogin = ["miniqrcode"]; protected $need_auth = true; public function _initialize() @@ -146,7 +147,12 @@ class Activity extends ManystoreBase $row->getRelation('manystoreshop')->visible(['name','logo']); } - $result = array("total" => $list->total(), "rows" => $list->items()); + $rows = $list->items(); + foreach ($rows as $k=>&$v){ + $v["miniqrcode_link"] = Url::build("/manystore/school/classes/activity/activity/miniqrcode", ["ids" => $v["id"]]); + } + + $result = array("total" => $list->total(), "rows" => $rows); return json($result); } @@ -457,4 +463,58 @@ class Activity extends ManystoreBase $this->error(__('Parameter %s can not be empty', 'ids')); } + /** + * 微信小程序码 + * @return string + * @throws \think\Exception + * @throws \think\db\exception\BindParamException + * @throws \think\exception\DbException + * @throws \think\exception\PDOException + */ + public function miniqrcode($ids = ''){ + $param = $this->request->param(); + try{ + if(isset($param['ids']))$ids = $param['ids']; + //设置模拟资格 + $url = \app\common\model\school\classes\activity\Activity::getMiniQrcodeLink($ids); + + }catch (\Exception $e){ + $this->error($e->getMessage()); + } + + return $url["response"]; + } + + + + + /** + * 查看微信小程序码 + * @return string + * @throws \think\Exception + * @throws \think\db\exception\BindParamException + * @throws \think\exception\DbException + * @throws \think\exception\PDOException + */ + public function lookminiqrcode($ids = ''){ + $param = $this->request->param(); + if($this->request->isPost()){ + try{ + if(isset($param['ids']))$ids = $param['ids']; + //设置模拟资格 + $url = \app\common\model\school\classes\activity\Activity::getMiniQrcodeLink($ids); + + }catch (\Exception $e){ + $this->error($e->getMessage()); + } + $this->success("生成小程序码成功",null,$url); + } + $row = $this->model->get($ids); + $this->view->assign('vo', $row); + return $this->view->fetch(); + } + + + + } diff --git a/application/manystore/view/general/profile/index.html b/application/manystore/view/general/profile/index.html index db0c695..fa683a9 100644 --- a/application/manystore/view/general/profile/index.html +++ b/application/manystore/view/general/profile/index.html @@ -105,6 +105,15 @@ {:token()}
打开微信扫一扫,扫码即可在手机端查看