推广分佣功能开发

This commit is contained in:
Dev
2026-10-14 14:44:01 +08:00
parent da26eb5306
commit 1754df972d
34 changed files with 1414 additions and 16 deletions
@@ -4,6 +4,7 @@ namespace app\api\controller;
use app\common\controller\Api;
use app\common\model\User;
use app\common\service\PromotionService;
use app\common\service\UserService;
use think\exception\HttpResponseException;
use think\Validate;
@@ -65,6 +66,8 @@ class Auth extends Api
$this->error('参数错误');
}
$user = UserService::wxLogin($code);
//通过分享链接/小程序码进入时携带推广人ID,首次进入即绑定
PromotionService::bindPromoter(intval($user->id), intval($this->request->post('promoter_id', 0)));
$this->auth->direct($user->id);
$userInfo = $this->auth->getUserinfo();
$this->success('登录成功', ['userinfo' => $this->auth->getUserinfo(), 'token' => $userInfo['token']]);
@@ -0,0 +1,93 @@
<?php
namespace app\api\controller;
use app\common\controller\Api;
use app\common\service\PromotionService;
use think\exception\HttpResponseException;
/**
* 推广分佣
*/
class Promotion extends Api
{
protected $noNeedLogin = [];
protected $noNeedRight = ['*'];
/**
* 绑定推广人(已登录用户通过分享进入时调用,已绑定过则忽略)
*
* @ApiMethod (POST)
* @param int $promoter_id 推广人用户ID
*/
public function bind()
{
try {
$promoterId = intval($this->request->post('promoter_id', 0));
$res = PromotionService::bindPromoter(intval($this->auth->id), $promoterId);
$this->success('', ['bound' => $res]);
} catch (\Exception $e) {
if ($e instanceof HttpResponseException) {
throw $e;
}
$this->error($e->getMessage());
}
}
/**
* 推广中心概览
*
* @ApiMethod (GET)
*/
public function info()
{
try {
$this->success('', PromotionService::getOverview(intval($this->auth->id)));
} catch (\Exception $e) {
if ($e instanceof HttpResponseException) {
throw $e;
}
$this->error($e->getMessage());
}
}
/**
* 推广订单列表
*
* @ApiMethod (GET)
* @param int $page 页码
* @param int $pageSize 每页条数
*/
public function orders()
{
try {
$pageSize = min(max(intval($this->request->get('pageSize', 10)), 1), 50);
$this->success('', PromotionService::getOrderList(intval($this->auth->id), $pageSize));
} catch (\Exception $e) {
if ($e instanceof HttpResponseException) {
throw $e;
}
$this->error($e->getMessage());
}
}
/**
* 推广小程序码
*
* @ApiMethod (GET)
* @param string $envVersion 小程序版本 release|trial|develop
*/
public function qrcode()
{
try {
$envVersion = (string)$this->request->get('envVersion', 'release');
$qrcode = PromotionService::getQrcode(intval($this->auth->id), $envVersion);
$this->success('', ['qrcode' => $qrcode]);
} catch (\Exception $e) {
if ($e instanceof HttpResponseException) {
throw $e;
}
$this->error($e->getMessage());
}
}
}