添加生成二维码

This commit is contained in:
luofei 2024-02-27 15:06:56 +08:00
parent 8c5a87a337
commit 10919fb275
3 changed files with 69 additions and 23 deletions

View File

@ -39,6 +39,7 @@ use crmeb\basic\BaseController;
use crmeb\services\AlipayService; use crmeb\services\AlipayService;
use crmeb\services\CopyCommand; use crmeb\services\CopyCommand;
use crmeb\services\MiniProgramService; use crmeb\services\MiniProgramService;
use crmeb\services\QrcodeService;
use crmeb\services\UploadService; use crmeb\services\UploadService;
use crmeb\services\WechatService; use crmeb\services\WechatService;
use Exception; use Exception;
@ -673,4 +674,34 @@ class Common extends BaseController
return app('json')->success(); return app('json')->success();
} }
/**
* 生成二维码
*/
public function Qrcode($data)
{
$siteUrl = systemConfig('site_url');
$name = 'orcode'.$data['id'] .md5(date('Ymd')) . '.png';
$attachmentRepository = app()->make(AttachmentRepository::class);
$imageInfo = $attachmentRepository->getWhere(['attachment_name' => $name]);
if (isset($imageInfo['attachment_src']) && strstr($imageInfo['attachment_src'], 'http') !== false && curl_file_exist($imageInfo['attachment_src']) === false) {
$imageInfo->delete();
$imageInfo = null;
}
if (!$imageInfo) {
$imageInfo = app()->make(QrcodeService::class)->getQRCodePath($data['code'], $name,['code'=>1]);
if (is_string($imageInfo)) throw new ValidateException('二维码生成失败');
$imageInfo['dir'] = tidy_url($imageInfo['dir'], null, $siteUrl);
$attachmentRepository->create(systemConfig('upload_type') ?: 1, -2, $data['id'], [
'attachment_category_id' => 0,
'attachment_name' => $imageInfo['name'],
'attachment_src' => $imageInfo['dir']
]);
$urlCode = $imageInfo['dir'];
} else $urlCode = $imageInfo['attachment_src'];
return $urlCode;
}
} }

View File

@ -26,6 +26,7 @@ use app\common\repositories\user\UserBillRepository;
use app\common\repositories\user\UserBrokerageRepository; use app\common\repositories\user\UserBrokerageRepository;
use app\common\repositories\user\UserRepository; use app\common\repositories\user\UserRepository;
use app\common\repositories\user\UserVisitRepository; use app\common\repositories\user\UserVisitRepository;
use app\controller\api\Common;
use app\validate\api\UserBaseInfoValidate; use app\validate\api\UserBaseInfoValidate;
use crmeb\basic\BaseController; use crmeb\basic\BaseController;
use crmeb\services\MiniProgramService; use crmeb\services\MiniProgramService;
@ -165,8 +166,8 @@ class User extends BaseController
public function brokerage_list(UserBillRepository $billRepository) public function brokerage_list(UserBillRepository $billRepository)
{ {
[$page, $limit] = $this->getPage(); [$page, $limit] = $this->getPage();
[$start,$stop]= $this->request->params(['start','stop'],true); [$start, $stop] = $this->request->params(['start', 'stop'], true);
$where['date'] = $start&&$stop ? date('Y/m/d',$start).'-'.date('Y/m/d',$stop) : ''; $where['date'] = $start && $stop ? date('Y/m/d', $start) . '-' . date('Y/m/d', $stop) : '';
$where['category'] = 'brokerage'; $where['category'] = 'brokerage';
return app('json')->success($billRepository->userList($where, $this->request->uid(), $page, $limit)); return app('json')->success($billRepository->userList($where, $this->request->uid(), $page, $limit));
} }
@ -182,10 +183,10 @@ class User extends BaseController
public function spread_order() public function spread_order()
{ {
[$page, $limit] = $this->getPage(); [$page, $limit] = $this->getPage();
$where= $this->request->params(['keyword']); $where = $this->request->params(['keyword']);
[$start,$stop]= $this->request->params(['start','stop'],true); [$start, $stop] = $this->request->params(['start', 'stop'], true);
$where['create_time'] = $start&&$stop ? date('Y/m/d',$start).'-'.date('Y/m/d',$stop) : ''; $where['create_time'] = $start && $stop ? date('Y/m/d', $start) . '-' . date('Y/m/d', $stop) : '';
$data = $this->repository->subOrder($this->request->uid(), $page, $limit,$where); $data = $this->repository->subOrder($this->request->uid(), $page, $limit, $where);
return app('json')->success($data); return app('json')->success($data);
} }
@ -239,6 +240,7 @@ class User extends BaseController
$this->repository->update($this->request->uid(), $data); $this->repository->update($this->request->uid(), $data);
return app('json')->success('绑定成功'); return app('json')->success('绑定成功');
} }
/** /**
* @return mixed * @return mixed
* @throws DataNotFoundException * @throws DataNotFoundException
@ -250,14 +252,14 @@ class User extends BaseController
public function spread_list() public function spread_list()
{ {
$where = $this->request->params([ 'sort', 'keyword']); $where = $this->request->params(['sort', 'keyword']);
[$start,$stop]= $this->request->params(['start','stop'],true); [$start, $stop] = $this->request->params(['start', 'stop'], true);
$where['spread_time'] = $start&&$stop ? date('Y/m/d',$start).'-'.date('Y/m/d',$stop) : ''; $where['spread_time'] = $start && $stop ? date('Y/m/d', $start) . '-' . date('Y/m/d', $stop) : '';
$level = $this->request->param('level'); $level = $this->request->param('level');
[$page, $limit] = $this->getPage(); [$page, $limit] = $this->getPage();
return app('json')->success($level == 2 return app('json')->success($level == 2
? $this->repository->getTwoLevelList($this->request->uid(),$where, $page, $limit) ? $this->repository->getTwoLevelList($this->request->uid(), $where, $page, $limit)
: $this->repository->getOneLevelList($this->request->uid(),$where, $page, $limit)); : $this->repository->getOneLevelList($this->request->uid(), $where, $page, $limit));
} }
/** /**
@ -358,7 +360,7 @@ class User extends BaseController
public function changePassword() public function changePassword()
{ {
$data = $this->request->params(['repassword','password', 'sms_code']); $data = $this->request->params(['repassword', 'password', 'sms_code']);
if (!$this->user->phone) if (!$this->user->phone)
return app('json')->fail('请先绑定手机号'); return app('json')->fail('请先绑定手机号');
@ -386,7 +388,7 @@ class User extends BaseController
$data['main_uid'] = 0; $data['main_uid'] = 0;
if ($user) { if ($user) {
if ($this->request->userInfo()->account !== $data['phone']) { if ($this->request->userInfo()->account !== $data['phone']) {
$data['account'] = $this->request->userInfo()->account.'_'.$this->request->uid(); $data['account'] = $this->request->userInfo()->account . '_' . $this->request->uid();
} }
} else { } else {
$data['account'] = $data['phone']; $data['account'] = $data['phone'];
@ -447,9 +449,9 @@ class User extends BaseController
public function services() public function services()
{ {
$uid = $this->user->uid; $uid = $this->user->uid;
$where = $this->request->params(['is_verify', 'customer', 'is_goods', ['is_open',1]]); $where = $this->request->params(['is_verify', 'customer', 'is_goods', ['is_open', 1]]);
$is_sys = $this->request->param('is_sys'); $is_sys = $this->request->param('is_sys');
return app('json')->success(app()->make(StoreServiceRepository::class)->getServices($uid, $where,$is_sys)); return app('json')->success(app()->make(StoreServiceRepository::class)->getServices($uid, $where, $is_sys));
} }
public function memberInfo() public function memberInfo()
@ -469,7 +471,7 @@ class User extends BaseController
$data['next_level'] = $next_level; $data['next_level'] = $next_level;
$makeInteres = app()->make(MemberinterestsRepository::class); $makeInteres = app()->make(MemberinterestsRepository::class);
$data['interests'] = systemConfig('member_interests_status') ? $makeInteres->getInterestsByLevel($makeInteres::TYPE_FREE,$this->user->member_level) : [] ; $data['interests'] = systemConfig('member_interests_status') ? $makeInteres->getInterestsByLevel($makeInteres::TYPE_FREE, $this->user->member_level) : [];
$data['today'] = app()->make(UserBillRepository::class)->search([ $data['today'] = app()->make(UserBillRepository::class)->search([
'category' => 'sys_members', 'category' => 'sys_members',
@ -480,10 +482,10 @@ class User extends BaseController
$config_key = ['member_pay_num', 'member_sign_num', 'member_reply_num', 'member_share_num']; $config_key = ['member_pay_num', 'member_sign_num', 'member_reply_num', 'member_share_num'];
if (systemConfig('community_status')) $config_key[] = 'member_community_num'; if (systemConfig('community_status')) $config_key[] = 'member_community_num';
$config= systemConfig($config_key); $config = systemConfig($config_key);
if ($this->user->is_svip > 0) { if ($this->user->is_svip > 0) {
foreach ($config as $key => $item) { foreach ($config as $key => $item) {
$data['config'][$key] = $item .' x' . $makeInteres->getSvipInterestVal($makeInteres::HAS_TYPE_MEMBER).' '; $data['config'][$key] = $item . ' x' . $makeInteres->getSvipInterestVal($makeInteres::HAS_TYPE_MEMBER) . ' ';
} }
} else { } else {
$data['config'] = $config; $data['config'] = $config;
@ -494,7 +496,7 @@ class User extends BaseController
public function notice() public function notice()
{ {
$type = $this->request->param('type',0); $type = $this->request->param('type', 0);
$arr = [ $arr = [
'0' => 'brokerage_level', '0' => 'brokerage_level',
'1' => 'member_level', '1' => 'member_level',
@ -530,14 +532,14 @@ class User extends BaseController
if (!$nickname && !$avatar) if (!$nickname && !$avatar)
return app('json')->fail('未做任何修改'); return app('json')->fail('未做任何修改');
$user = $this->request->userInfo(); $user = $this->request->userInfo();
if(!empty($nickname)) { if (!empty($nickname)) {
$validate->check(['nickname' => $nickname]); $validate->check(['nickname' => $nickname]);
$data['nickname'] = $nickname; $data['nickname'] = $nickname;
} }
if(!empty($avatar)) { if (!empty($avatar)) {
$data['avatar'] = $avatar; $data['avatar'] = $avatar;
} }
$this->repository->updateBaseInfo($data,$user); $this->repository->updateBaseInfo($data, $user);
return app('json')->success('修改成功'); return app('json')->success('修改成功');
} }
@ -575,4 +577,16 @@ class User extends BaseController
return app('json')->success(['count' => $count, 'list' => $result]); return app('json')->success(['count' => $count, 'list' => $result]);
} }
/**
* 生成二维码
*/
public function qrcode()
{
/** @var Common $common */
$common = app()->make(Common::class);
$siteUrl = systemConfig('site_url');
$data = $common->Qrcode(['code' => $siteUrl . 'download/index.html?code=shop_' . $this->user->uid, 'id' => $this->user->uid]);
return app('json')->success(['url' => $data]);
}
} }

View File

@ -37,6 +37,7 @@ Route::group('api/', function () {
Route::post('logout', 'api.Auth/logout'); Route::post('logout', 'api.Auth/logout');
//用户信息 //用户信息
Route::get('user', 'api.Auth/userInfo'); Route::get('user', 'api.Auth/userInfo');
Route::get('qrcode', 'api.user.User/qrcode');
//绑定推荐人 //绑定推荐人
Route::post('user/spread', 'api.Auth/spread'); Route::post('user/spread', 'api.Auth/spread');