修改补贴列表

This commit is contained in:
luofei 2024-03-20 11:05:47 +08:00
parent 2c07c80bcc
commit d5a81d6ba4

View File

@ -186,17 +186,41 @@ class Store extends BaseController
} else {
$couponType = StoreCouponRepository::TYPE_SALE_SUBSIDY;
}
$couponId = StoreCoupon::where('type', $couponType)->value('coupon_id');
$coupon = StoreCoupon::where('type', $couponType)->field('coupon_id,config')->find();
$totalAmount = StoreCouponUser::where('uid', $userId)
->where('coupon_type', StoreCouponRepository::TYPE_STORE_COUPON)
->whereIn('status', [StoreCouponUser::STATUS_UNUSED, StoreCouponUser::STATUS_REPEAL])
->value('origin_price');
$totalAmount = empty($totalAmount) ? '0.00' : $totalAmount;
$query = StoreCouponDetail::field('amount coupon_price,create_time,status,send_status,extra')
->where('uid', $userId)
->where('coupon_id', $couponId)
->where('coupon_id', $coupon['coupon_id'])
->where('type', StoreCouponDetail::TYPE_INCOME);
$count = $query->count();
$record = $query->page($page)->limit($limit)->order('id', 'desc')->select()->toArray();
if (empty($record) && $type == 2) {
$merchantTypeId = Merchant::where('mer_id', $this->merId)->value('type_id');
$couponPrice = 0;
$saleTarget = 0;
foreach ($coupon['config'] as $item) {
if (!in_array($merchantTypeId, $item['type_id'])) {
$couponPrice = $item['subsidy'];
$saleTarget = $item['amount'];
break;
}
}
$record[] = [
'coupon_price' => $couponPrice ?? '0.00',
'create_time' => time(),
'status' => StoreCouponDetail::STATUS_INVALID,
'send_status' => StoreCouponDetail::SEND_REPEAL,
'extra' => [
'sale_target' => $saleTarget,
'purchase_target' => bcmul($saleTarget, 0.2, 2),
'official_purchase_target' => bcmul($saleTarget, 0.3, 2),
],
];
}
foreach ($record as &$item) {
$item['status_cn'] = StoreCouponDetail::STATUS_MAP[$item['status']];
$item['send_status_cn'] = StoreCouponDetail::SEND_STATUS_MAP[$item['send_status']];