修复漏洞

This commit is contained in:
15090180611 2025-01-04 18:09:51 +08:00
parent 6f4aff0648
commit af55bd020b
37 changed files with 745 additions and 46 deletions

View File

@ -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();
}
}

View File

@ -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();
}
}

View File

@ -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();
}
}

View File

@ -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();
}
}

View File

@ -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){

View File

@ -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']);
}
/**

View File

@ -26,6 +26,7 @@ class HourOrder extends Base
parent::_initialize();
//判断登录用户是否是员工
$this->setUrlLock();
}

View File

@ -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);
}

View File

@ -28,7 +28,7 @@ class Pay extends Base
$this->model = new OrderModel;
parent::_initialize();
$this->setUrlLock();
//判断登录用户是否是员工
}

View File

@ -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()]);

View File

@ -27,6 +27,7 @@ class Order extends Base
parent::_initialize();
//判断登录用户是否是员工
$this->setUrlLock();
}

View File

@ -29,7 +29,7 @@ class Pay extends Base
$this->model = new OrderModel;
parent::_initialize();
$this->setUrlLock();
//判断登录用户是否是员工
}

View File

@ -28,6 +28,7 @@ class HourOrder extends Base
parent::_initialize();
//判断登录用户是否是员工
$this->setUrlLock();
}

View File

@ -27,6 +27,7 @@ class Order extends Base
parent::_initialize();
//判断登录用户是否是员工
$this->setUrlLock();
}

View File

@ -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);

View File

@ -28,6 +28,7 @@ class Order extends Base
parent::_initialize();
//判断登录用户是否是员工
$this->setUrlLock();
}

View File

@ -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

View File

@ -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");
}
}

View File

@ -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]);
}
}

View File

@ -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]);
}
}

View File

@ -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]);
}
}

View File

@ -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]);
}
}

View File

@ -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();
}
}

View File

@ -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();
}
}

View File

@ -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();
}
}

View File

@ -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();
}
}

View File

@ -105,6 +105,15 @@
{:token()}
<div class="panel-body">
<div class="box-body box-profile">
<div class="profile-avatar-container">
<!-- <img class="profile-user-img img-responsive img-circle plupload"-->
<!-- src="{$manystore.avatar|cdnurl|htmlentities}" alt="">-->
<a href="javascript:"><img class=" profile-user-img img-responsive img-center" src="{$miniqrcode_link}"></a>
</div>
<h3 class="profile-username text-center">微信小程序端展示效果</h3>
<p class="text-muted text-center">打开微信扫一扫,扫码即可在手机端查看</p><br><br><br>
{$check_full_msg}

View File

@ -26,6 +26,7 @@ use app\common\model\Attachment;
use addons\xftts\library\Tts;
use addons\xftts\library\WebSocket\Client;
use addons\xftts\library\WebSocket\Exception;
use think\Response;
use traits\CacheTrait;
/** 商城工具类
@ -414,7 +415,10 @@ class Common
* @throws \Endroid\QrCode\Exception\InvalidPathException
* @throws \app\common\exception\UploadException
*/
public static function getQrcode($params,$stream = false,$cache = true){
public static function getQrcode($params,$stream = false,$cache = true,$response = false){
if($response){
return self::getQRcodeResponse($params);
}
$qrCode = \addons\qrcode\library\Service::qrcode($params);
if($stream)return $qrCode;
// 写入到文件
@ -1106,5 +1110,38 @@ class Common
return $xftts;
}
/** 生成并直接返回二维码http响应而不存储
* @param $text
* @param $label
* @param $params
* @return Response|\think\response\Json|\think\response\Jsonp|\think\response\Redirect|\think\response\View|\think\response\Xml
* @throws \Endroid\QrCode\Exception\InvalidPathException
*/
public static function getQRcodeResponse($params=[]){
$params = array_intersect_key($params, array_flip(['text', 'size', 'padding', 'errorlevel', 'foreground', 'background', 'logo', 'logosize', 'logopath', 'label', 'labelfontsize', 'labelalignment']));
// $params['text'] = $text;
// $params['label'] = $label;
$qrCode = \addons\qrcode\library\Service::qrcode($params);
$mimetype = 'image/png';
$response = Response::create()->header("Content-Type", $mimetype);
// 直接显示二维码
header('Content-Type: ' . $qrCode->getContentType());
// 设置缓存过期时间例如30天
$expiresTime = strtotime('+30 days');
header('Expires: ' . gmdate('D, d M Y H:i:s', $expiresTime) . ' GMT');
header('Cache-Control: max-age=' . (30 * 24 * 60 * 60));
$response->content($qrCode->writeString());
return $response;
}
}

View File

@ -77,8 +77,10 @@ trait CacheTrait
$redis = $this->getRedis();
$hashKey = $key.$suffix;
// $redis->del($hashKey);
// var_dump($hashKey);die;
//判断锁是否存在,如果存在,返回错误
if ($redis->EXISTS($hashKey)){
if ($redis->exists($hashKey)){
// var_dump(111111222);die;
if($this->cache_lock_thorws_excption){
throw new \Exception($this->cache_lock_error_msg);
}else{
@ -87,7 +89,9 @@ trait CacheTrait
}
//如果不存在创建锁并返回
$redis->set($hashKey, 1,$timeout);
// $redis->set($hashKey, 1,$timeout);//注释掉
//替换成原子操作的命令
$redis->set($hashKey, 1,['nx', 'ex' => $timeout]);
return true;
}

View File

@ -12,11 +12,25 @@ trait ModelTrait
{
protected $withTable = [];
public static $url_enpity = null;
public static $url_lock = false;
public static $url_lock_key = "";
public static $url_lock_suffix = "test-lock-suffix";
public static $url_lock_timeout = 120;
public static $url_error_msg = "您的请求过于频繁,请您稍后再试!";
/**
* 开启事务
*/
public static function beginTrans()
{
if (self::$url_lock) {
self::$url_enpity = new \bw\UrlLock(self::$url_lock_key, self::$url_lock_suffix, self::$url_lock_timeout, self::$url_error_msg);
self::$url_enpity->lock();
}
Db::startTrans();
}
@ -25,6 +39,7 @@ trait ModelTrait
*/
public static function commitTrans()
{
if(self::$url_enpity)self::$url_enpity->free();
Db::commit();
}
@ -33,6 +48,7 @@ trait ModelTrait
*/
public static function rollbackTrans()
{
if(self::$url_enpity)self::$url_enpity->free();
Db::rollback();
}

View File

@ -10,6 +10,9 @@ define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefin
edit_url: 'manystore/index/edit' + location.search,
del_url: 'manystore/index/del',
url_url: 'manystore/index/url',
lookminiqrcode_url: 'manystore/index/lookminiqrcode',
miniqrcode_url: 'manystore/index/miniqrcode',
free_url: 'manystore/index/free',
multi_url: 'manystore/index/multi',
}
@ -22,7 +25,7 @@ define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefin
url: $.fn.bootstrapTable.defaults.extend.index_url,
pk: 'id',
fixedColumns: true,
fixedRightNumber: 1,
fixedRightNumber: 2,
columns: [
[
{checkbox: true},
@ -81,7 +84,7 @@ define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefin
{field: 'logintime', title: __('Login time'), formatter: Table.api.formatter.datetime, operate: 'RANGE', addclass: 'datetimerange', sortable: true},
{field: 'miniqrcode_link', title: __('微信小程序端展示'), operate: false, events: Table.api.events.image, formatter: Table.api.formatter.image},
{field: 'operate', title: __('Operate'),width:180, table: table , buttons: [
{name: 'url',
text: '查看小程序链接',

View File

@ -10,6 +10,11 @@ define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefin
edit_url: 'school/classes/activity/activity/edit'+ location.search,
del_url: 'school/classes/activity/activity/del',
url_url: 'school/classes/activity/activity/url',
lookminiqrcode_url: 'school/classes/activity/activity/lookminiqrcode',
miniqrcode_url: 'school/classes/activity/activity/miniqrcode',
multi_url: 'school/classes/activity/activity/multi',
import_url: 'school/classes/activity/activity/import',
table: 'school_classes_activity',
@ -24,7 +29,7 @@ define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefin
pk: 'id',
sortName: 'weigh',
fixedColumns: true,
fixedRightNumber: 1,
fixedRightNumber: 2,
columns: [
[
{checkbox: true},
@ -77,7 +82,7 @@ define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefin
{field: 'shop.name', title: __('Shop.name'), operate: 'LIKE'},
{field: 'shop.logo', title: __('Shop.logo'), operate: 'LIKE'},
{field: 'miniqrcode_link', title: __('微信小程序端展示'), operate: false, events: Table.api.events.image, formatter: Table.api.formatter.image},
{field: 'operate', title: __('Operate'), table: table , buttons: [
{name: 'url',

View File

@ -11,6 +11,10 @@ define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefin
edit_url: 'school/classes/classes_lib/edit'+ location.search,
copy_url: 'school/classes/classes_lib/copy'+ location.search,
url_url: 'school/classes/classes_lib/url',
lookminiqrcode_url: 'school/classes/classes_lib/lookminiqrcode',
miniqrcode_url: 'school/classes/classes_lib/miniqrcode',
del_url: 'school/classes/classes_lib/del',
multi_url: 'school/classes/classes_lib/multi',
import_url: 'school/classes/classes_lib/import',
@ -26,7 +30,7 @@ define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefin
pk: 'id',
sortName: 'weigh',
fixedColumns: true,
fixedRightNumber: 1,
fixedRightNumber: 2,
columns: [
[
@ -124,7 +128,7 @@ define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefin
{field: 'user.avatar', title: __('User.avatar'),visible:false, operate: 'LIKE', events: Table.api.events.image, formatter: Table.api.formatter.image},
{field: 'admin.nickname', title: __('Admin.nickname'),visible:false, operate: 'LIKE'},
{field: 'miniqrcode_link', title: __('微信小程序端展示'), operate: false, events: Table.api.events.image, formatter: Table.api.formatter.image},
{field: 'operate', title: __('Operate'), table: table , buttons: [
{name: 'url',
text: '查看小程序链接',

View File

@ -12,6 +12,10 @@ define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefin
multi_url: 'school/classes/teacher/multi',
import_url: 'school/classes/teacher/import',
url_url: 'school/classes/teacher/url',
lookminiqrcode_url: 'school/classes/teacher/lookminiqrcode',
miniqrcode_url: 'school/classes/teacher/miniqrcode',
table: 'school_teacher',
}
});
@ -24,7 +28,7 @@ define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefin
pk: 'id',
sortName: 'weigh',
fixedColumns: true,
fixedRightNumber: 1,
fixedRightNumber: 2,
columns: [
[
{checkbox: true},
@ -63,7 +67,7 @@ define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefin
{field: 'shop.district', title: __('Shop.district')},
{field: 'shop.address', title: __('Shop.address'), operate: 'LIKE'},
{field: 'shop.address_detail', title: __('Shop.address_detail'), operate: 'LIKE'},
{field: 'miniqrcode_link', title: __('微信小程序端展示'), operate: false, events: Table.api.events.image, formatter: Table.api.formatter.image},
{field: 'operate', title: __('Operate'), table: table , buttons: [
{name: 'url',
text: '查看小程序链接',

View File

@ -8,6 +8,10 @@ define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefin
index_url: 'school/classes/activity/activity/index' + location.search,
add_url: 'school/classes/activity/activity_auth/add'+ location.search,
edit_url: 'school/classes/activity/activity/edit' + location.search,
lookminiqrcode_url: 'school/classes/activity/activity/lookminiqrcode',
miniqrcode_url: 'school/classes/activity/activity/miniqrcode',
del_url: 'school/classes/activity/activity/del',
multi_url: 'school/classes/activity/activity/multi',
import_url: 'school/classes/activity/activity/import',
@ -23,7 +27,7 @@ define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefin
pk: 'id',
sortName: 'weigh',
fixedColumns: true,
fixedRightNumber: 1,
fixedRightNumber: 2,
columns: [
[
{checkbox: true},
@ -77,7 +81,7 @@ define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefin
{field: 'manystore.nickname', title: __('Manystore.nickname'), operate: 'LIKE'},
{field: 'manystoreshop.name', title: __('Manystoreshop.name'), operate: 'LIKE'},
{field: 'manystoreshop.logo', title: __('Manystoreshop.logo'), operate: 'LIKE'},
{field: 'miniqrcode_link', title: __('微信小程序端展示'), operate: false, events: Table.api.events.image, formatter: Table.api.formatter.image},
{field: 'operate', title: __('Operate'), table: table , buttons: [
{

View File

@ -10,6 +10,11 @@ define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefin
addnew_url: 'school/classes/classes_lib/addnew'+ location.search,
edit_url: 'school/classes/classes_lib/edit'+ location.search,
copy_url: 'school/classes/classes_lib/copy'+ location.search,
lookminiqrcode_url: 'school/classes/classes_lib/lookminiqrcode',
miniqrcode_url: 'school/classes/classes_lib/miniqrcode',
del_url: 'school/classes/classes_lib/del',
multi_url: 'school/classes/classes_lib/multi',
import_url: 'school/classes/classes_lib/import',
@ -25,7 +30,7 @@ define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefin
pk: 'id',
sortName: 'weigh',
fixedColumns: true,
fixedRightNumber: 1,
fixedRightNumber: 2,
columns: [
[
{checkbox: true},
@ -131,8 +136,7 @@ define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefin
{field: 'user.avatar', title: __('User.avatar'),visible:false, operate: 'LIKE', events: Table.api.events.image, formatter: Table.api.formatter.image},
{field: 'admin.nickname', title: __('Admin.nickname'),visible:false, operate: 'LIKE'},
{field: 'miniqrcode_link', title: __('微信小程序端展示'), operate: false, events: Table.api.events.image, formatter: Table.api.formatter.image},
{field: 'operate', title: __('Operate'), table: table , buttons: [
{
name: 'classes_spec',

View File

@ -11,6 +11,10 @@ define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefin
del_url: 'school/classes/teacher/del',
multi_url: 'school/classes/teacher/multi',
import_url: 'school/classes/teacher/import',
lookminiqrcode_url: 'school/classes/teacher/lookminiqrcode',
miniqrcode_url: 'school/classes/teacher/miniqrcode',
table: 'school_teacher',
}
});
@ -23,7 +27,7 @@ define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefin
pk: 'id',
sortName: 'weigh',
fixedColumns: true,
fixedRightNumber: 1,
fixedRightNumber: 2,
columns: [
[
@ -63,7 +67,7 @@ define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefin
// {field: 'manystoreshop.address', title: __('Manystoreshop.address'), operate: 'LIKE'},
// {field: 'manystoreshop.address_detail', title: __('Manystoreshop.address_detail'), operate: 'LIKE'},
// {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate}
{field: 'miniqrcode_link', title: __('微信小程序端展示'), operate: false, events: Table.api.events.image, formatter: Table.api.formatter.image},
{field: 'operate', title: __('Operate'), table: table , buttons: [
{
name: 'classes',