添加红包获取记录

This commit is contained in:
luofei 2024-01-19 11:41:01 +08:00
parent 92da0baa39
commit 55384b2c45
3 changed files with 58 additions and 0 deletions

View File

@ -157,4 +157,27 @@ class StoreActivityUserDao extends BaseDao
return ['amount' => $userConsumption['coupon_price'], 'end_time' => $userConsumption['end_time']];
}
/**
* 红包获取记录
* @param int $userId
* @return array
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
*/
public function record(int $userId)
{
$consumption = StoreConsumption::select()->toArray();
$record = StoreConsumptionUser::where('uid', $userId)
->whereIn('coupon_id', array_column($consumption, 'coupon_id'))
->where('status', '>=', StoreConsumptionUser::STATUS_UNUSED)
->field('coupon_price,order_amount,create_time')
->select()->toArray();
$totalAmount = 0;
foreach ($record as $item) {
$totalAmount = bcadd($totalAmount, $item['coupon_price'], 2);
}
return ['total_amount' => $totalAmount, 'record' => $record];
}
}

View File

@ -0,0 +1,20 @@
<?php
namespace app\common\model\store\consumption;
use app\common\model\BaseModel;
class StoreConsumptionDetail extends BaseModel
{
public static function tablePk(): string
{
return 'id';
}
public static function tableName(): string
{
return 'store_consumption_detail';
}
}

View File

@ -69,4 +69,19 @@ class StoreActivity extends BaseController
return app('json')->success($result);
}
/**
* 红包获取记录
* @param StoreActivityUserDao $dao
* @return mixed
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
*/
public function record(StoreActivityUserDao $dao)
{
$userId = $this->request->uid();
$result = $dao->record($userId);
return app('json')->success($result);
}
}