充值赠送现金抵扣红包
This commit is contained in:
parent
e856c4c32a
commit
ea531d68aa
@ -15,6 +15,7 @@ class StoreConsumption extends BaseModel
|
|||||||
const TYPE_OWNER_CONSUMPTION = 13; //个人消费金
|
const TYPE_OWNER_CONSUMPTION = 13; //个人消费金
|
||||||
const TYPE_PULL_CONSUMPTION = 14; //拉新消费金
|
const TYPE_PULL_CONSUMPTION = 14; //拉新消费金
|
||||||
const TYPE_FIRST_ORDER_COMMISSION = 15; //首单佣金
|
const TYPE_FIRST_ORDER_COMMISSION = 15; //首单佣金
|
||||||
|
const TYPE_RECHARGE = 16; //充值赠送
|
||||||
|
|
||||||
public static function tablePk(): string
|
public static function tablePk(): string
|
||||||
{
|
{
|
||||||
|
@ -13,7 +13,10 @@
|
|||||||
|
|
||||||
namespace app\common\repositories\user;
|
namespace app\common\repositories\user;
|
||||||
|
|
||||||
|
use app\common\dao\store\consumption\StoreConsumptionUserDao;
|
||||||
use app\common\dao\user\UserRechargeDao;
|
use app\common\dao\user\UserRechargeDao;
|
||||||
|
use app\common\model\store\consumption\StoreConsumption;
|
||||||
|
use app\common\model\store\consumption\StoreConsumptionUser;
|
||||||
use app\common\model\user\User;
|
use app\common\model\user\User;
|
||||||
use app\common\model\user\UserRecharge;
|
use app\common\model\user\UserRecharge;
|
||||||
use app\common\repositories\BaseRepository;
|
use app\common\repositories\BaseRepository;
|
||||||
@ -126,8 +129,41 @@ class UserRechargeRepository extends BaseRepository
|
|||||||
$recharge->user->now_money = bcadd($recharge->user->now_money, $price, 2);
|
$recharge->user->now_money = bcadd($recharge->user->now_money, $price, 2);
|
||||||
$recharge->user->save();
|
$recharge->user->save();
|
||||||
$recharge->save();
|
$recharge->save();
|
||||||
|
|
||||||
|
$consumption = StoreConsumption::where('status', 1)->where('type', StoreConsumption::TYPE_RECHARGE)->find();
|
||||||
|
if (!empty($consumption)) {
|
||||||
|
$amount = min($recharge->price, 100000);
|
||||||
|
$rate = $this->getRate($amount);
|
||||||
|
$storeConsumptionUserDao = new StoreConsumptionUserDao();
|
||||||
|
$storeConsumptionUserDao->send($consumption, $rate, $recharge->uid, $recharge->recharge_id, $amount, StoreConsumptionUser::STATUS_UNUSED, StoreConsumptionUser::TYPE_TWO);
|
||||||
|
}
|
||||||
});
|
});
|
||||||
Queue::push(SendSmsJob::class,['tempId' => 'USER_BALANCE_CHANGE', 'id' =>$orderId]);
|
Queue::push(SendSmsJob::class,['tempId' => 'USER_BALANCE_CHANGE', 'id' =>$orderId]);
|
||||||
event('user.recharge',compact('recharge'));
|
event('user.recharge',compact('recharge'));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 按充值金额获取赠送比例
|
||||||
|
* @param $amount
|
||||||
|
* @return int
|
||||||
|
*/
|
||||||
|
public function getRate($amount)
|
||||||
|
{
|
||||||
|
$rateArray = [
|
||||||
|
['start' => 1000, 'end' => 4999, 'rate' => 0.05],
|
||||||
|
['start' => 5000, 'end' => 9999, 'rate' => 0.1],
|
||||||
|
['start' => 10000, 'end' => 49999, 'rate' => 0.15],
|
||||||
|
['start' => 50000, 'end' => 100000, 'rate' => 0.2],
|
||||||
|
];
|
||||||
|
$rate = 0;
|
||||||
|
foreach ($rateArray as $item) {
|
||||||
|
if ($amount >=$item['start'] && $amount <= $item['end']) {
|
||||||
|
$rate = $item['rate'];
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return $rate;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user