添加:业绩是否达标接口
This commit is contained in:
parent
14623f2d98
commit
756dddf042
|
|
@ -5,6 +5,7 @@ namespace Yunshop\TeamDividend\Api;
|
||||||
|
|
||||||
use app\common\components\ApiController;
|
use app\common\components\ApiController;
|
||||||
use app\common\models\Member;
|
use app\common\models\Member;
|
||||||
|
use app\common\models\Order;
|
||||||
use Illuminate\Support\Facades\DB;
|
use Illuminate\Support\Facades\DB;
|
||||||
use Yunshop\TeamDividend\admin\models\MemberChild;
|
use Yunshop\TeamDividend\admin\models\MemberChild;
|
||||||
use Yunshop\TeamDividend\models\CodeRecordModel;
|
use Yunshop\TeamDividend\models\CodeRecordModel;
|
||||||
|
|
@ -275,4 +276,41 @@ class IndexController extends ApiController
|
||||||
return $this->errorJson('激活码使用失败');
|
return $this->errorJson('激活码使用失败');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// 业绩是否完成
|
||||||
|
public function performanceComplete(){
|
||||||
|
// 基本参数
|
||||||
|
$target = 500000;
|
||||||
|
$isComplete = 0;
|
||||||
|
$memberId = \YunShop::app()->getMemberId();
|
||||||
|
$areaAmount = 0;
|
||||||
|
if($memberId > 0){
|
||||||
|
// 获取直推下级列表
|
||||||
|
$subIds = MemberChild::uniacid()
|
||||||
|
->where('level',1)
|
||||||
|
->where('member_id',$memberId)
|
||||||
|
->pluck('child_id')
|
||||||
|
->toArray();
|
||||||
|
$subPerformance = [];// 每条线的业绩
|
||||||
|
foreach($subIds as $subUid){
|
||||||
|
$lineAllUid = MemberChild::uniacid()->where('member_id',$subUid)->pluck('child_id')->toArray();
|
||||||
|
$lineAllUid[] = $subUid;
|
||||||
|
$subPerformance[$subUid] = Order::whereIn('uid',$lineAllUid)->where('status','>=',0)->sum('yz_order.price');
|
||||||
|
}
|
||||||
|
// 计算业绩
|
||||||
|
$teamAmount = (float)sprintf("%.2f",array_sum($subPerformance));// 总业绩
|
||||||
|
$maxAmount = max($subPerformance);// 最大一条线的业绩
|
||||||
|
$areaAmount = (float)sprintf("%.2f",$teamAmount - $maxAmount);// 小区业绩 = 总业绩 - 最大一条线的业绩
|
||||||
|
$isComplete = $areaAmount >= $target ? 1 : 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
return $this->successJson('业绩是否完成', [
|
||||||
|
'is_complete' => $isComplete,
|
||||||
|
'area_amount' => $areaAmount
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
Loading…
Reference in New Issue