|
@@ -4,6 +4,8 @@ use App\Http\Requests\Admin\Lottery\OrderReward as Request;
|
|
|
use App\Models\Custom;
|
|
|
use App\Models\Lottery\OrderRecord as Model;
|
|
|
use App\Models\Lottery\Order as LotteryOrder;
|
|
|
+use Illuminate\Support\Facades\DB;
|
|
|
+
|
|
|
/**
|
|
|
* 抽奖记录
|
|
|
*
|
|
@@ -23,10 +25,10 @@ class LotteryOrderRecord extends Auth{
|
|
|
*
|
|
|
* */
|
|
|
public function index(Model $Model,LotteryOrder $LotteryOrder,Custom $Custom){
|
|
|
- // 接受参数
|
|
|
// 接受参数
|
|
|
$lotteryId = request('lottery_id',0);
|
|
|
$customCode = request('custom_code','');
|
|
|
+ $rewardName = request('reward_name','');
|
|
|
$startTime = request('start_time','');
|
|
|
$endTime = request('end_time','');
|
|
|
$status = request('status');
|
|
@@ -34,13 +36,20 @@ class LotteryOrderRecord extends Auth{
|
|
|
$map = [];
|
|
|
// 编码转ID
|
|
|
$customUid = $customCode ? $Custom->codeToId($customCode) : 0;
|
|
|
- if( $customUid ) $map[] = ['custom_uid','=',$customUid];
|
|
|
- if( $lotteryId ) $map[] = ['lottery_id','=',$lotteryId];
|
|
|
- if( $startTime ) $map[] = ['insert_time','>=',strtotime($startTime)];
|
|
|
- if( $endTime ) $map[] = ['insert_time','<=',strtotime($endTime)];
|
|
|
- if( !is_null($status) ) $map[] = ['status','=',$status];
|
|
|
+ if( $customUid ) $map[] = ['lottery_order_record.custom_uid','=',$customUid];
|
|
|
+ if( $lotteryId ) $map[] = ['lottery_order_record.lottery_id','=',$lotteryId];
|
|
|
+ if( $rewardName ) $map[] = ['lottery_order_record.reward_name','=',$rewardName];
|
|
|
+ if( $startTime ) $map[] = ['lottery_order_record.insert_time','>=',strtotime($startTime)];
|
|
|
+ if( $endTime ) $map[] = ['lottery_order_record.insert_time','<=',strtotime($endTime)];
|
|
|
+ if( !is_null($status) ) $map[] = ['lottery_order_record.status','=',$status];
|
|
|
// 查询数据
|
|
|
- $list = $Model->query()->where($map)->orderByDesc('id')->paginate(config('page_num',10));
|
|
|
+ $list = $Model->query()
|
|
|
+ ->join('lottery_order','lottery_order.id','=','lottery_order_record.lottery_id')
|
|
|
+ ->join('custom','custom.uid','=','lottery_order_record.custom_uid')
|
|
|
+ ->where($map)
|
|
|
+ ->select(['lottery_order_record.*','custom.weiban_extid','custom.username','lottery_order.name as active_name'])
|
|
|
+ ->orderByDesc('id')
|
|
|
+ ->paginate(config('page_num',10));
|
|
|
// 循环处理数据
|
|
|
foreach ($list as $key => $value) {
|
|
|
// 组合数据
|
|
@@ -88,4 +97,84 @@ class LotteryOrderRecord extends Auth{
|
|
|
return json_send(['code'=>'success','msg'=>'设置成功','path'=>'']);
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 导出表格
|
|
|
+ *
|
|
|
+ * */
|
|
|
+ public function down_excel(Model $Model,Custom $Custom){
|
|
|
+ // 接受参数
|
|
|
+ $lotteryId = request('lottery_id',0);
|
|
|
+ $customCode = request('custom_code','');
|
|
|
+ $startTime = request('start_time','');
|
|
|
+ $endTime = request('end_time','');
|
|
|
+ $status = request('status');
|
|
|
+ // 查询条件
|
|
|
+ $map = [];
|
|
|
+ // 编码转ID
|
|
|
+ $customUid = $customCode ? $Custom->codeToId($customCode) : 0;
|
|
|
+ if( $customUid ) $map[] = ['lottery_order_record.custom_uid','=',$customUid];
|
|
|
+ if( $lotteryId ) $map[] = ['lottery_order_record.lottery_id','=',$lotteryId];
|
|
|
+ if( $startTime ) $map[] = ['lottery_order_record.insert_time','>=',strtotime($startTime)];
|
|
|
+ if( $endTime ) $map[] = ['lottery_order_record.insert_time','<=',strtotime($endTime)];
|
|
|
+ if( !is_null($status) ) $map[] = ['lottery_order_record.status','=',$status];
|
|
|
+ // 查询数据
|
|
|
+ $list = $Model->query()
|
|
|
+ ->join('lottery_order','lottery_order.id','=','lottery_order_record.lottery_id')
|
|
|
+ ->join('custom','custom.uid','=','lottery_order_record.custom_uid')
|
|
|
+ ->where($map)
|
|
|
+ ->select([
|
|
|
+ 'lottery_order_record.id',
|
|
|
+ 'lottery_order.id as active_id',
|
|
|
+ 'lottery_order.name as active_name',
|
|
|
+ 'custom.uid as custom_uid',
|
|
|
+ 'custom.username',
|
|
|
+ 'lottery_order_record.reward_name',
|
|
|
+ 'lottery_order_record.status',
|
|
|
+ 'lottery_order_record.contact_name',
|
|
|
+ 'lottery_order_record.contact_phone',
|
|
|
+ 'lottery_order_record.contact_province',
|
|
|
+ 'lottery_order_record.contact_city',
|
|
|
+ 'lottery_order_record.contact_area',
|
|
|
+ 'lottery_order_record.contact_addr',
|
|
|
+ 'lottery_order_record.insert_time',
|
|
|
+ 'custom.weiban_extid',
|
|
|
+ ])
|
|
|
+ ->orderByDesc('id')->get()->toArray();
|
|
|
+ // 循环处理数据
|
|
|
+ foreach ($list as $key => $value) {
|
|
|
+ // 组合数据
|
|
|
+ $value['status'] = $Model->getRecordState($value['status'],'name');
|
|
|
+ $value['custom_uid'] = $Custom->idToCode($value['custom_uid']);
|
|
|
+ $value['contact_addr'] = $value['contact_phone'] ? $value['contact_province'].'/'.$value['contact_city'].'/'.$value['contact_area'].'/'.$value['contact_addr'].' '.$value['contact_name'].' '.$value['contact_phone'] : '';
|
|
|
+ $value['username'] = hide_phone($value['username']);
|
|
|
+ $value['insert_time'] = date('Y-m-d H:i:s',$value['insert_time']);
|
|
|
+ // 删除数据
|
|
|
+ unset($value['contact_province'],$value['contact_city'],$value['contact_area'],$value['contact_name'],$value['contact_phone']);
|
|
|
+ // 重组
|
|
|
+ $list[$key] = $value;
|
|
|
+ }
|
|
|
+ // 去下载
|
|
|
+ $this->toDown($list);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 去下载
|
|
|
+ */
|
|
|
+ private function toDown($data){
|
|
|
+ // xlsx文件保存路径
|
|
|
+ $excel = new \Vtiful\Kernel\Excel(['path' =>public_path().'/uploads/']);
|
|
|
+ $filePath = $excel->fileName('tutorial01.xlsx', 'sheet1')->header(['记录ID','活动ID','活动名称','客户编码','客户昵称','奖品名称','收货信息','中奖时间','微伴ID'])->data($data)->output();
|
|
|
+ header("Content-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet");
|
|
|
+ header('Content-Disposition: attachment;filename="下单抽奖中奖记录'.date('Y-m-d His').'.xlsx"');
|
|
|
+ header('Content-Length: ' . filesize($filePath));
|
|
|
+ header('Content-Transfer-Encoding: binary');
|
|
|
+ header('Cache-Control: must-revalidate');
|
|
|
+ header('Cache-Control: max-age=0');
|
|
|
+ header('Pragma: public');
|
|
|
+ ob_clean();
|
|
|
+ flush();
|
|
|
+ // 输出文件,成功删除文件路径
|
|
|
+ if ( copy($filePath, 'php://output') ) @unlink($filePath);
|
|
|
+ }
|
|
|
+
|
|
|
}
|