|
@@ -253,12 +253,94 @@ class LotteryRecordService
|
|
|
|
|
|
/**
|
|
|
* 获取抽奖记录详情
|
|
|
+ *
|
|
|
+ * @param int $drawRecordId 抽奖记录ID
|
|
|
+ * @param int $userId 用户ID(可选,用于验证权限)
|
|
|
+ * @return LotteryDrawRecord|null 抽奖记录详情,包含关联信息
|
|
|
*/
|
|
|
- public static function getDrawRecordDetail($drawRecordId)
|
|
|
+ public static function getDrawRecordDetail($drawRecordId, $userId = 0)
|
|
|
{
|
|
|
- return LotteryDrawRecord::where('id', $drawRecordId)
|
|
|
- ->with(['activity', 'user', 'prize', 'winRecord', 'order'])
|
|
|
+ // 1. 查询抽奖记录基础信息
|
|
|
+ $query = LotteryDrawRecord::where('id', $drawRecordId);
|
|
|
+
|
|
|
+ // 如果指定了用户ID,则验证权限
|
|
|
+ if ($userId) {
|
|
|
+ $query->where('user_id', $userId);
|
|
|
+ }
|
|
|
+
|
|
|
+ $record = $query->field('id,activity_id,user_id,prize_id,is_win,trigger_type,trigger_order_id,
|
|
|
+ trigger_amount,draw_time,remark,status,createtime')
|
|
|
+ ->find();
|
|
|
+
|
|
|
+ if (!$record) {
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+
|
|
|
+ // 2. 查询关联的活动信息
|
|
|
+ $activity = LotteryActivity::where('id', $record->activity_id)
|
|
|
+ ->field('id,name,type,status,lottery_type,lottery_time')
|
|
|
->find();
|
|
|
+
|
|
|
+ // 3. 查询关联的奖品信息
|
|
|
+ $prize = null;
|
|
|
+ if ($record->prize_id > 0) {
|
|
|
+ $prize = LotteryPrize::where('id', $record->prize_id)
|
|
|
+ ->field('id,name,image,type')
|
|
|
+ ->find();
|
|
|
+ }
|
|
|
+
|
|
|
+ // 4. 查询关联的中奖记录信息(仅限中奖记录)
|
|
|
+ $winRecord = null;
|
|
|
+ if ($record->is_win) {
|
|
|
+ $winRecord = LotteryWinRecord::where('draw_record_id', $record->id)
|
|
|
+ ->field('id,draw_record_id,prize_name,prize_type,deliver_status,
|
|
|
+ deliver_time,receiver_name,receiver_mobile,receiver_address,
|
|
|
+ express_company,express_number,exchange_code,code_used_time')
|
|
|
+ ->find();
|
|
|
+ }
|
|
|
+
|
|
|
+ // 5. 将关联数据作为字段附加到记录中
|
|
|
+ // 附加活动信息字段
|
|
|
+ $record->activity_name = $activity ? $activity->name : '';
|
|
|
+ $record->activity_type = $activity ? $activity->type : 0;
|
|
|
+ $record->activity_status = $activity ? $activity->status : 0;
|
|
|
+ $record->activity_lottery_type = $activity ? $activity->lottery_type : 0;
|
|
|
+ $record->activity_lottery_time = $activity ? $activity->lottery_time : 0;
|
|
|
+
|
|
|
+ // 附加奖品信息字段
|
|
|
+ $record->prize_name = $prize ? $prize->name : '';
|
|
|
+ $record->prize_image = $prize ? cdnurl($prize->image) : '';
|
|
|
+ $record->prize_type = $prize ? $prize->type : 0;
|
|
|
+ // 附加中奖记录信息字段
|
|
|
+ if ($winRecord) {
|
|
|
+ $record->win_record_id = $winRecord->id;
|
|
|
+ $record->win_prize_name = $winRecord->prize_name;
|
|
|
+ $record->win_prize_type = $winRecord->prize_type;
|
|
|
+ $record->deliver_status = $winRecord->deliver_status;
|
|
|
+ $record->deliver_time = $winRecord->deliver_time;
|
|
|
+ $record->receiver_name = $winRecord->receiver_name;
|
|
|
+ $record->receiver_mobile = $winRecord->receiver_mobile;
|
|
|
+ $record->receiver_address = $winRecord->receiver_address;
|
|
|
+ $record->express_company = $winRecord->express_company;
|
|
|
+ $record->express_number = $winRecord->express_number;
|
|
|
+ $record->exchange_code = $winRecord->exchange_code;
|
|
|
+ $record->code_used_time = $winRecord->code_used_time;
|
|
|
+ } else {
|
|
|
+ $record->win_record_id = 0;
|
|
|
+ $record->win_prize_name = '';
|
|
|
+ $record->win_prize_type = 0;
|
|
|
+ $record->deliver_status = 0;
|
|
|
+ $record->deliver_time = 0;
|
|
|
+ $record->receiver_name = '';
|
|
|
+ $record->receiver_mobile = '';
|
|
|
+ $record->receiver_address = '';
|
|
|
+ $record->express_company = '';
|
|
|
+ $record->express_number = '';
|
|
|
+ $record->exchange_code = '';
|
|
|
+ $record->code_used_time = 0;
|
|
|
+ }
|
|
|
+
|
|
|
+ return $record;
|
|
|
}
|
|
|
|
|
|
/**
|