调整补贴发放
This commit is contained in:
parent
e95efacd95
commit
29060c709a
13
app/common/Enum.php
Normal file
13
app/common/Enum.php
Normal file
@ -0,0 +1,13 @@
|
||||
<?php
|
||||
|
||||
namespace app\common;
|
||||
class Enum
|
||||
{
|
||||
|
||||
/** 消费金状态 */
|
||||
const CONSUMPTION_STATUS_REPEAL = -1; //未激活
|
||||
const CONSUMPTION_STATUS_AUDIT = 0; //审核中
|
||||
const CONSUMPTION_STATUS_CONFIRM = 1; //待确认
|
||||
const CONSUMPTION_STATUS_FINISHED = 2; //已完成
|
||||
|
||||
}
|
@ -281,34 +281,36 @@ class StoreActivityUserDao extends BaseDao
|
||||
/**
|
||||
* 红包余额统计
|
||||
* @param int $userId
|
||||
* @return array
|
||||
* @return array|array[]
|
||||
* @throws \think\db\exception\DataNotFoundException
|
||||
* @throws \think\db\exception\DbException
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
*/
|
||||
public function total(int $userId)
|
||||
{
|
||||
$totalAmount = StoreConsumptionUser::where('uid', $userId)
|
||||
->whereIn('type', [StoreConsumptionUser::TYPE_ONE, StoreConsumptionUser::TYPE_TWO])
|
||||
->where('status', StoreConsumptionUser::STATUS_UNUSED)
|
||||
->field('SUM(balance) as total_amount,type')
|
||||
->group('type')
|
||||
->whereIn('status', [StoreConsumptionUser::STATUS_UNUSED, StoreConsumptionUser::STATUS_REPEAL])
|
||||
->field('balance,type')
|
||||
->select()->toArray();
|
||||
$totalAmount = reset_index($totalAmount, 'type');
|
||||
$result = [
|
||||
[
|
||||
'1' => [
|
||||
'type' => 1,
|
||||
'total_amount' => 0.00
|
||||
'total_amount' => 0.00,
|
||||
'type_cn' => StoreConsumptionUser::TYPE_MAP[1],
|
||||
],
|
||||
[
|
||||
'2' => [
|
||||
'type' => 2,
|
||||
'total_amount' => 0.00
|
||||
'total_amount' => 0.00,
|
||||
'type_cn' => StoreConsumptionUser::TYPE_MAP[2],
|
||||
]
|
||||
];
|
||||
foreach ($result as &$item) {
|
||||
if (isset($totalAmount[$item['type']])) {
|
||||
$item['total_amount'] = $totalAmount[$item['type']]['total_amount'];
|
||||
foreach ($totalAmount as $item) {
|
||||
if (isset($result[$item['type']])) {
|
||||
$result[$item['type']]['total_amount']= bcadd($result[$item['type']]['total_amount'], $item['balance'], 2);
|
||||
}
|
||||
$item['type_cn'] = StoreConsumptionUser::TYPE_MAP[$item['type']];
|
||||
}
|
||||
return $result;
|
||||
return array_values($result);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -52,6 +52,7 @@ class StoreConsumptionUserDao extends BaseDao
|
||||
public $startTime;
|
||||
public $endTime;
|
||||
public $billExtra;
|
||||
public $onlyBill = false; // 是否只写入用户账单
|
||||
|
||||
protected function getModel(): string
|
||||
{
|
||||
@ -241,10 +242,12 @@ class StoreConsumptionUserDao extends BaseDao
|
||||
$model = StoreConsumptionUser::where('uid', $userId)->where('type', StoreConsumptionUser::TYPE_TWO)->find();
|
||||
$couponPrice = bcmul($amount, $rate, 2);
|
||||
if (!empty($model) && $model['type'] == $type) {
|
||||
$model->coupon_price = bcadd($model->coupon_price, $couponPrice, 2);
|
||||
$model->balance = bcadd($model->balance, $couponPrice, 2);
|
||||
if ($model->status != StoreConsumptionUser::STATUS_UNUSED) {
|
||||
$model->status = StoreConsumptionUser::STATUS_UNUSED;
|
||||
if (!$this->onlyBill) {
|
||||
$model->coupon_price = bcadd($model->coupon_price, $couponPrice, 2);
|
||||
$model->balance = bcadd($model->balance, $couponPrice, 2);
|
||||
if ($model->status != StoreConsumptionUser::STATUS_UNUSED) {
|
||||
$model->status = StoreConsumptionUser::STATUS_UNUSED;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
$model = new StoreConsumptionUser();
|
||||
@ -260,6 +263,9 @@ class StoreConsumptionUserDao extends BaseDao
|
||||
$model->end_time = $this->endTime ?: '2026-01-15 23:59:59';
|
||||
$model->type = $type;
|
||||
$model->status = $status;
|
||||
if ($this->onlyBill === true) {
|
||||
$model->status = StoreConsumptionUser::STATUS_REPEAL;
|
||||
}
|
||||
}
|
||||
if (!$model->save()) {
|
||||
throw new \Exception('发放失败');
|
||||
|
@ -844,10 +844,11 @@ class StoreOrderRepository extends BaseRepository
|
||||
$money = bcsub($money, $refundPrice, 2);
|
||||
//订单确认收货,增加商户销售金额
|
||||
Merchant::where('mer_id', $order->mer_id)->update(['sale_amount' => Db::raw('sale_amount+' . $money)]);
|
||||
$field = $order->merchant['type_id'] == 22 ? 'official_purchase_amount' : 'purchase_amount';
|
||||
//订单确认收货,增加商户采购金额
|
||||
$merId = Merchant::where('uid', $order->uid)->value('mer_id');
|
||||
if (!empty($merId)) {
|
||||
Merchant::where('mer_id', $merId)->update(['purchase_amount' => Db::raw('purchase_amount+' . $money)]);
|
||||
Merchant::where('mer_id', $merId)->update([$field => Db::raw("{$field}+" . $money)]);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
@ -3,6 +3,7 @@
|
||||
namespace crmeb\listens;
|
||||
|
||||
use app\common\dao\store\consumption\StoreConsumptionUserDao;
|
||||
use app\common\Enum;
|
||||
use app\common\model\store\consumption\StoreConsumption;
|
||||
use app\common\model\store\consumption\StoreConsumptionUser;
|
||||
use app\common\model\system\merchant\Merchant;
|
||||
@ -23,10 +24,12 @@ class SendSubsidyCouponListen extends TimerService implements ListenerInterface
|
||||
$count = 0;
|
||||
if ($consumption) {
|
||||
foreach ($consumption['config'] as $item) {
|
||||
$purchaseAmount = $item['amount'] * 0.5;
|
||||
$purchaseAmount = $item['amount'] * 0.2; //普通店铺采购金额
|
||||
$officialPurchaseAmount = $item['amount'] * 0.3; //官方店铺采购金额
|
||||
$merchants = Merchant::whereIn('type_id', $item['type_id'])
|
||||
->where('sale_amount', '>=', $item['amount'])
|
||||
->where('purchase_amount', '>=', $purchaseAmount)
|
||||
->where('official_purchase_amount', '>=', $officialPurchaseAmount)
|
||||
->select();
|
||||
foreach ($merchants as $merchant) {
|
||||
//商户已获得的补贴金额
|
||||
@ -43,7 +46,10 @@ class SendSubsidyCouponListen extends TimerService implements ListenerInterface
|
||||
'coupon_id' => $consumption['coupon_id'],
|
||||
'sale_amount' => $item['amount'],
|
||||
'purchase_amount' => $purchaseAmount,
|
||||
'official_purchase_amount' => $officialPurchaseAmount,
|
||||
'status' => Enum::CONSUMPTION_STATUS_REPEAL,
|
||||
];
|
||||
$consumptionRepo->onlyBill = true;
|
||||
$consumptionRepo->send($consumption, 1, $merchant->uid, 0, $amount, StoreConsumptionUser::STATUS_UNUSED, StoreConsumptionUser::TYPE_TWO);
|
||||
$count++;
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user