94 lines
2.4 KiB
PHP
94 lines
2.4 KiB
PHP
<?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());
|
||
|
|
}
|
||
|
|
}
|
||
|
|
}
|