| | |
| | | */ |
| | | class User extends UserModel |
| | | { |
| | | public static function checkExistByGradeId($grade_id) |
| | | { |
| | | self::where('grade_id',$grade_id)->find(); |
| | | } |
| | | |
| | | /** |
| | | * 获取股东用户列表 |
| | | */ |
| | |
| | | // 先获取所有股东 |
| | | $model = new static; |
| | | $shareholders = $model->where('is_delete', '=', 0)->with(['grade'])->select(); |
| | | |
| | | // 如果没有设置分红条件,返回所有股东 |
| | | if (empty($setting['consumption_amount']) && empty($setting['condition_purchase_count'])) { |
| | | return $shareholders; |
| | | } |
| | | |
| | | |
| | | // 过滤满足条件的股东 |
| | | $eligibleShareholders = []; |
| | | foreach ($shareholders as $shareholder) { |
| | | $userId = $shareholder['user_id']; |
| | | $isEligible = true; |
| | | |
| | | |
| | | // 检查消费金额条件 |
| | | if (!empty($setting['consumption_amount'])) { |
| | | $totalConsumption = (new OrderModel)->getUserTotalConsumption($userId,$bonusData); |
| | |
| | | |
| | | // 检查购买次数条件 |
| | | if (!empty($setting['condition_purchase_count']) && $isEligible) { |
| | | $purchaseCount = (new OrderProductModel)::getPurchaseCount($userId,$bonusData,$shareholder['product_ids']); |
| | | $purchaseCount = (new OrderProductModel)::getPurchaseCount($userId,$bonusData); |
| | | if ($purchaseCount < $setting['condition_purchase_count']) { |
| | | $isEligible = false; |
| | | } |