...
|
...
|
@@ -4,6 +4,7 @@ namespace app\admin\controller; |
|
|
|
|
|
use app\common\controller\Backend;
|
|
|
use app\admin\model\TeamCategory;
|
|
|
use EasyWeChat\Foundation\Application;
|
|
|
use think\Db;
|
|
|
use think\Exception;
|
|
|
use think\exception\PDOException;
|
...
|
...
|
@@ -84,6 +85,54 @@ class Team extends Backend |
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 添加
|
|
|
*/
|
|
|
public function add()
|
|
|
{
|
|
|
if ($this->request->isPost()) {
|
|
|
$params = $this->request->post("row/a");
|
|
|
if ($params) {
|
|
|
$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(true)->validate($validate);
|
|
|
}
|
|
|
$result = $this->model->allowField(true)->save($params);
|
|
|
// 生成二维码
|
|
|
$qrcode = $this->createQrcode($this->model->id);
|
|
|
$this->model->save(['team_qrcode' => '/'.$qrcode]);
|
|
|
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 match()
|
...
|
...
|
@@ -233,4 +282,35 @@ class Team extends Backend |
|
|
}
|
|
|
$this->error(__('Parameter %s can not be empty', 'ids'));
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 生成小程序二维码
|
|
|
*/
|
|
|
public function createQrcode($id)
|
|
|
{
|
|
|
// 本地路径
|
|
|
$dir = 'uploads/team';
|
|
|
if (!file_exists($dir)){
|
|
|
mkdir($dir,0777,true);
|
|
|
}
|
|
|
|
|
|
// 用户小程序码
|
|
|
$qrcode = $dir.'/'.$id.'.png';
|
|
|
$qrcode_width = 430;
|
|
|
if(!file_exists($qrcode) || imagesx(imagecreatefromjpeg(ROOT_PATH.'public/'.$qrcode)) != $qrcode_width){
|
|
|
// 获取小程序配置
|
|
|
$miniprogram = [
|
|
|
'mini_program' => \config('miniprogram.basic')
|
|
|
];
|
|
|
$app = new Application($miniprogram);
|
|
|
$miniProgram = $app->mini_program;
|
|
|
$response = $miniProgram->qrcode->appCodeUnlimit($id, 'pages/index/index', $qrcode_width);
|
|
|
$contents = $response->__toString();
|
|
|
if (empty($contents) || '{' === $contents[0]) {
|
|
|
$this->error('Invalid media response content.');
|
|
|
}
|
|
|
file_put_contents($qrcode, $contents);
|
|
|
}
|
|
|
return $qrcode;
|
|
|
}
|
|
|
} |
...
|
...
|
|