Files

111 lines
2.5 KiB
PHP

<?php
namespace app\api\model\app\agent;
use think\Model;
use think\Db;
use app\api\model\app\agent\Level;
class Condition extends Model
{
/**
* 检查条件是否满足
* @return void
*/
public static function checkCondition($userId,$type,$value){
$value = floatval($value);
$data = 0;
switch ($type){
case 'agent':
$data = self::getAgent($userId);
break;
case 'customer':
$data = self::getCustomer($userId);
break;
case 'customer_pay':
$data = self::getCustomerPay($userId);
break;
case 'self_pay':
$data = self::getSelfPay($userId);
break;
}
return $data >= $value;
}
/**
* 获取自购金额
* @param $userId
* @return void
*/
public static function getSelfPay($userId){
$value = \app\common\model\order\Order::where([
'status'=>\app\common\constant\order\Status::STATUS_SUCCESS,
'user_id'=>$userId
])->sum('real_pay_price');
if(!$value){
return 0;
}
return $value;
}
/**
* 获取推广金额
* @param $userId
* @return void
*/
public static function getCustomerPay($userId){
$value = \app\common\model\app\agent\Order::where([
'status'=>1,
'beneficiary_user_id'=>$userId
])->sum('brokerage_price');
if(!$value){
return 0;
}
return $value;
}
/**
* 获取客户数量
* @param $userId
* @return int
*/
public static function getAgent($userId){
$value = \app\common\model\app\agent\Relation::where([
'status'=>1,
'parent_id'=>$userId
])->count();
if(!$value){
return 0;
}
return $value;
}
/**
* 获取下级分销员
* @param $userId
* @return int
*/
public static function getCustomer($userId){
$value = \app\common\model\app\agent\Relation::alias('relation')
->join(\app\common\model\app\agent\Member::getTable().' member','relation.user_id = member.user_id')
->where([
'relation.status'=>1,
'member.status'=>1,
'relation.parent_id'=>$userId
])->count();
if(!$value){
return 0;
}
return $value;
}
}