123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180 |
- <?php namespace App\Http\Controllers\Admin;
- 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;
- /**
- * 抽奖记录
- *
- * @author 刘相欣
- *
- */
- class LotteryOrderRecord extends Auth{
-
- protected function _initialize(){
- parent::_initialize();
- $this->assign('breadcrumb1','下单抽奖');
- $this->assign('breadcrumb2','抽奖记录');
- }
- /**
- * 列表页
- *
- * */
- 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');
- // 查询条件
- $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( $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()
- ->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))->appends(request()->all());
- // 循环处理数据
- foreach ($list as $key => $value) {
- // 组合数据
- $value['state'] = $Model->getRecordState($value['status'],'name');
- // id转编号
- $value['custom_code'] = $Custom->idToCode($value['custom_uid']);
- // 重组
- $list[$key] = $value;
- }
- // 获取列表
- $statusList = $Model->getRecordStateList();
- // 获取列表
- $lotteryList = $LotteryOrder->query()->get(['id','name'])->toArray();
- // 分配数据
- $this->assign('empty', '<tr><td colspan="20">~~暂无数据</td></tr>');
- $this->assign('list',$list);
- $this->assign('statusList',$statusList);
- $this->assign('lotteryList',$lotteryList);
- // 加载模板
- return $this->fetch();
- }
- /**
- * 修改状态
- *
- * */
- public function set_status(Request $request,Model $Model){
- // 验证参数
- $request->scene('set_status')->validate();
- // 设置状态
- $id = request('id',0);
- $status = request('status',0);
- // 查询用户
- $oldData = $Model->where(['id'=>$id])->first();
- // 如果用户不存在
- if( !$oldData ) return json_send(['code'=>'error','msg'=>'数据不存在']);
- // 执行修改
- $result = $Model->edit($id,['status'=>$status]);
- // 提示新增失败
- if( !$result ) return json_send(['code'=>'error','msg'=>'设置失败']);
- // 记录行为
- $this->addAdminHistory(admin('uid'),$Model->getTable(),$id,2,$oldData,['status'=>$status]);
- // 告知结果
- 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(uniqid().'.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);
- }
- }
|