调整拉新红包发放规则
This commit is contained in:
parent
aa3e1f316e
commit
909f41eaac
@ -29,21 +29,13 @@ class StoreConsumptionUserDao extends BaseDao
|
||||
* @throws \think\db\exception\DbException
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
*/
|
||||
public function check($groupOrderId)
|
||||
public function check(int $groupOrderId)
|
||||
{
|
||||
$groupOrder = StoreGroupOrder::where('group_order_id', $groupOrderId)->where('paid', 1)->where('pay_time', '>=', $this->consumption['start_time'])->find()->toArray();
|
||||
if (!empty($this->consumption['config'])) {
|
||||
$rate = 0;
|
||||
$scope = [];
|
||||
// 根据当前订单金额,计算是否满足消费金发放条件
|
||||
foreach ($this->consumption['config'] as $item) {
|
||||
if ($item['start'] <= $groupOrder['pay_price'] && $item['end'] >= $groupOrder['pay_price']) {
|
||||
$rate = bcdiv($item['rate'], 100, 2);
|
||||
$scope = $item;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if ($rate <= 0) {
|
||||
$scope = $this->getScope($groupOrder['pay_price']);
|
||||
if ($scope['rate'] <= 0) {
|
||||
return false;
|
||||
}
|
||||
Db::startTrans();
|
||||
@ -59,25 +51,27 @@ class StoreConsumptionUserDao extends BaseDao
|
||||
$mineOrderIds = $this->isFinished($groupOrder['uid'], $scope);
|
||||
if ($mineOrderIds !== false) {
|
||||
$mineOrderIds = "{$groupOrder['group_order_id']}," . $mineOrderIds;
|
||||
$this->send($rate, $groupOrder['uid'], $mineOrderIds, $groupOrder['pay_price']);
|
||||
$this->send($scope['rate'], $groupOrder['uid'], $mineOrderIds, $groupOrder['pay_price']);
|
||||
$storeActivityOrderDao->batchRepeal(explode(',', $mineOrderIds));
|
||||
}
|
||||
// 用户作为受邀人且当前订单是首单
|
||||
if ($spreadUserId && $isFirstOrder) {
|
||||
// 查询推荐人满足条件的订单
|
||||
$spreadGroupOrder = StoreActivityOrder::where('user_id', $spreadUserId)->where('status', StoreActivityOrder::STATUS_VALID)->whereBetween('total_amount', $scope['start'], $scope['end'])->find();
|
||||
if (empty($spreadGroupOrder)) {
|
||||
return false;
|
||||
}
|
||||
$spreadOrderIds = $this->isFinished($spreadUserId, $scope);
|
||||
if ($spreadOrderIds !== false) {
|
||||
$spreadOrderIds = "{$spreadGroupOrder['group_order_id']}," . $spreadOrderIds;
|
||||
$this->send($rate, $spreadUserId, $spreadOrderIds, $spreadGroupOrder['total_amount']);
|
||||
$storeActivityOrderDao->batchRepeal(explode(',', $spreadOrderIds));
|
||||
$spreadGroupOrder = StoreActivityOrder::where('user_id', $spreadUserId)->where('status', StoreActivityOrder::STATUS_VALID)->find();
|
||||
if ($spreadGroupOrder) {
|
||||
$spreadScope = $this->getScope($spreadGroupOrder['total_amount']);
|
||||
if ($spreadScope['start'] == $scope['start']) {
|
||||
$spreadOrderIds = $this->isFinished($spreadUserId, $scope);
|
||||
if ($spreadOrderIds !== false) {
|
||||
$spreadOrderIds = "{$spreadGroupOrder['group_order_id']}," . $spreadOrderIds;
|
||||
$this->send($scope['rate'], $spreadUserId, $spreadOrderIds, $spreadGroupOrder['total_amount']);
|
||||
$storeActivityOrderDao->batchRepeal(explode(',', $spreadOrderIds));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
} elseif ($this->consumption['type'] == StoreConsumption::TYPE_OWNER_CONSUMPTION) {
|
||||
$this->send($rate, $groupOrder['uid'], $groupOrder['group_order_id'], $groupOrder['pay_price']);
|
||||
$this->send($scope['rate'], $groupOrder['uid'], $groupOrder['group_order_id'], $groupOrder['pay_price']);
|
||||
$storeActivityOrderDao->repeal($groupOrder['group_order_id']);
|
||||
}
|
||||
Db::commit();
|
||||
@ -87,6 +81,24 @@ class StoreConsumptionUserDao extends BaseDao
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取消费档位区间
|
||||
* @param float $amount
|
||||
* @return array|mixed
|
||||
*/
|
||||
public function getScope(float $amount)
|
||||
{
|
||||
$scope = [];
|
||||
foreach ($this->consumption['config'] as $item) {
|
||||
if ($item['start'] <= $amount && $item['end'] >= $amount) {
|
||||
$item['rate'] = bcdiv($item['rate'], 100, 2);
|
||||
$scope = $item;
|
||||
break;
|
||||
}
|
||||
}
|
||||
return $scope;
|
||||
}
|
||||
|
||||
/**
|
||||
* 判断用户是否满足条件
|
||||
* @param int $userId
|
||||
@ -105,7 +117,7 @@ class StoreConsumptionUserDao extends BaseDao
|
||||
$userOrders[$groupOrder['user_id']] = $groupOrder;
|
||||
}
|
||||
}
|
||||
if (count($userOrders) < 4) {
|
||||
if (count($userOrders) < $scope['num']) {
|
||||
return false;
|
||||
}
|
||||
return implode(',', array_column($userOrders, 'group_order_id'));
|
||||
|
Loading…
x
Reference in New Issue
Block a user