57 lines
2.0 KiB
PHP
57 lines
2.0 KiB
PHP
|
|
<?php
|
||
|
|
// +----------------------------------------------------------------------
|
||
|
|
// | 范氏国香 fsgx — 推荐佣金周期进度 API
|
||
|
|
// +----------------------------------------------------------------------
|
||
|
|
|
||
|
|
namespace app\controller\api\v1\hjf;
|
||
|
|
|
||
|
|
use app\Request;
|
||
|
|
use app\services\order\StoreOrderServices;
|
||
|
|
use app\services\user\UserBrokerageServices;
|
||
|
|
use app\services\user\UserServices;
|
||
|
|
use app\controller\api\AuthController;
|
||
|
|
|
||
|
|
class HjfBrokerage extends AuthController
|
||
|
|
{
|
||
|
|
/**
|
||
|
|
* GET /api/hjf/brokerage/progress
|
||
|
|
* 推荐佣金周期进度聚合接口
|
||
|
|
*/
|
||
|
|
public function progress(Request $request)
|
||
|
|
{
|
||
|
|
$uid = (int)$request->uid();
|
||
|
|
/** @var UserServices $userServices */
|
||
|
|
$userServices = app()->make(UserServices::class);
|
||
|
|
$userInfo = $userServices->get($uid, ['uid', 'brokerage_price', 'spread_uid', 'agent_level']);
|
||
|
|
|
||
|
|
// 周期配置
|
||
|
|
$cycleCount = (int)sys_config('brokerage_cycle_count', 3);
|
||
|
|
$cycleRatesRaw = sys_config('brokerage_cycle_rates', '[20,30,50]');
|
||
|
|
$cycleRates = json_decode($cycleRatesRaw, true) ?: [20, 30, 50];
|
||
|
|
|
||
|
|
// 统计当前用户作为 spread_uid 的下级已完成报单商品有效订单数
|
||
|
|
/** @var \app\dao\order\StoreOrderDao $orderDao */
|
||
|
|
$orderDao = app()->make(\app\dao\order\StoreOrderDao::class);
|
||
|
|
$totalCompleted = $orderDao->count([
|
||
|
|
'spread_uid' => $uid,
|
||
|
|
'is_queue_goods' => 1,
|
||
|
|
'paid' => 1,
|
||
|
|
'is_del' => 0,
|
||
|
|
]);
|
||
|
|
|
||
|
|
// 当前周期内完成人数
|
||
|
|
$cycleCurrent = $totalCompleted % $cycleCount;
|
||
|
|
|
||
|
|
// 累计佣金
|
||
|
|
$totalBrokerage = $userInfo ? (string)($userInfo['brokerage_price'] ?? '0.00') : '0.00';
|
||
|
|
|
||
|
|
return $this->success([
|
||
|
|
'cycle_total' => $cycleCount,
|
||
|
|
'cycle_current' => $cycleCurrent,
|
||
|
|
'cycle_rates' => $cycleRates,
|
||
|
|
'total_brokerage' => $totalBrokerage,
|
||
|
|
'total_completed' => $totalCompleted,
|
||
|
|
]);
|
||
|
|
}
|
||
|
|
}
|