...
|
...
|
@@ -3,7 +3,12 @@ |
|
|
namespace app\admin\controller\user;
|
|
|
|
|
|
use app\common\controller\Backend;
|
|
|
use Endroid\QrCode\QrCode;
|
|
|
use Exception;
|
|
|
use fast\Random;
|
|
|
use think\Db;
|
|
|
use think\exception\PDOException;
|
|
|
use think\exception\ValidateException;
|
|
|
|
|
|
/**
|
|
|
* 会员管理
|
...
|
...
|
@@ -61,6 +66,75 @@ class User extends Backend |
|
|
return $this->view->fetch();
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 添加
|
|
|
*/
|
|
|
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 {
|
|
|
$params['pwd'] = $params['password'];
|
|
|
$params['salt'] = Random::alnum();
|
|
|
$params['password'] = md5(md5($params['password']) . $params['salt']);
|
|
|
$params['status'] = 'normal';
|
|
|
$params['createtime'] = $params['updatetime'] = time();
|
|
|
$params['joinip'] = request()->ip();
|
|
|
$result = $this->model->validate('User.add')->save($params);
|
|
|
//生成二维码
|
|
|
$id = $this->model->id;
|
|
|
$page = '/pages/myIndex/myIndex?user_id='.$id;
|
|
|
$thumbnail = $this->qrcode($page,$id);
|
|
|
Db::name('user')->where('id',$id)->update(['thumbnail'=>$thumbnail]);
|
|
|
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($this->model->getError());
|
|
|
}
|
|
|
}
|
|
|
$this->error(__('Parameter %s can not be empty', ''));
|
|
|
}
|
|
|
return $this->view->fetch();
|
|
|
}
|
|
|
|
|
|
//生成二维码
|
|
|
private function qrcode($url,$user_id)
|
|
|
{
|
|
|
$qrCode = new QrCode('Life is too short to be generating QR codes');
|
|
|
$qrCode
|
|
|
->setText($url)
|
|
|
->setSize(450)
|
|
|
->setPadding(10)
|
|
|
->setErrorCorrection('high')
|
|
|
->setForegroundColor(['r' => 0, 'g' => 0, 'b' => 0, 'a' => 0])
|
|
|
->setBackgroundColor(['r' => 255, 'g' => 255, 'b' => 255, 'a' => 0])
|
|
|
->setImageType(QrCode::IMAGE_TYPE_PNG);
|
|
|
$file_path = "code".$user_id.".png";
|
|
|
|
|
|
$qrCode->save(ROOT_PATH . 'public' . DS . 'upload/code' . DS . $file_path);
|
|
|
$qrcodeurl = request()->domain().'/upload/code/code'.$user_id.'.png';
|
|
|
return $qrcodeurl;
|
|
|
}
|
|
|
|
|
|
// public function edit($ids = NULL)
|
|
|
// {
|
|
|
// $row = $this->model->get($ids);
|
...
|
...
|
|