warehouse = config('constants.WAREHOUSE'); $is_fx = env('IS_FX'); if($is_fx > 0) { unset($this->warehouse[1]); unset($this->warehouse[2]); } } /** * 发货财务明细 */ public function sendFinanceList(Request $request){ $team_id = (int)$request->input('team_id'); //分銷商只能看自己团队 $self_id = session('admin_id'); $team_id = Admin::where('id', $self_id)->pluck('team_id'); $stime = $request->input('stime'); $etime = $request->input('etime'); $warehouse = 3; $page = (int)$request->input('page'); $pageSize = 20; if($page<=0){ $page = 1; } $offset = ($page-1) * $pageSize; $count = FxOrder::where(function($query) use($team_id, $stime, $etime, $warehouse){ if($team_id) $query->where('team_id', $team_id); if($warehouse) $query->where('warehouse', $warehouse); if($stime) $query->where('send_time', '>=', $stime); if($etime) $query->where('send_time', '<=', $etime); })->where('is_del', 0)->where('status','>=',2)->where('logistics_id', '>', '')->count(); if ($count > 1) { // 总页数 $pages = ceil($count/$pageSize); }else{ // 总页数 $pages = 1; } $teams = DB::table('teams')->lists('name', 'id'); $resultQuery = FxOrder::select('team_id', 'createTime', 'id', 'receivedAmount', 'cost', 'freight_cost', 'payment_type', 'send_time', 'warehouse', 'receiverName', 'logistics_id')->where(function($query) use($team_id, $stime, $etime, $warehouse){ if($team_id) $query->where('team_id', $team_id); if($warehouse) $query->where('warehouse', $warehouse); if($stime ) $query->where('send_time', '>=', $stime); if($etime ) $query->where('send_time', '<=', $etime); })->where('is_del', 0)->where('status','>=',2)->where('logistics_id', '>', ''); $result = $resultQuery->orderBy('send_time','desc')->offset($offset)->limit($pageSize)->get(); $result = json_decode(json_encode($result), true); $payArr = [1=>'微信支付', 2=>'付款码支付', 3=>'个体户支付', 4=>'充值卡支付']; $wareArr = $this->warehouse; foreach($result as $k=>&$v){ $v['team_name'] = $v['team_id']>0 ? $teams[$v['team_id']] : '';; $v['payment_type'] = $payArr[$v['payment_type']]; $v['ctime'] = $v['send_time']; $v['warehouse'] = $wareArr[$v['warehouse']]; } return view('/fxstatistics/sendFinanceList',[ 'result' => $result, 'team_id' => $team_id, 'stime' => $stime, 'etime' => $etime, 'page' => $page, 'count' => $count, 'pages' => $pages, ]); } /** * 发货财务明细 */ public function sendFinanceList_export(Request $request){ $team_id = (int)$request->input('team_id'); $self_id = session('admin_id'); $team_id = Admin::where('id', $self_id)->pluck('team_id'); $stime = $request->input('stime'); $etime = $request->input('etime'); $warehouse = 3; $teams = DB::table('teams')->lists('name', 'id'); $resultQuery = FxOrder::select('team_id', 'createTime', 'id', 'receivedAmount', 'cost', 'freight_cost', 'payment_type', 'send_time', 'warehouse', 'receiverName', 'logistics_id')->where(function($query) use($team_id, $stime, $etime, $warehouse){ if($team_id) $query->where('team_id', $team_id); if($warehouse) $query->where('warehouse', $warehouse); if($stime ) $query->where('send_time', '>=', $stime); if($etime ) $query->where('send_time', '<=', $etime); })->where('is_del', 0)->where('status','>=',2)->where('logistics_id', '>', ''); $result = $resultQuery->orderBy('send_time','desc')->get(); $result = json_decode(json_encode($result), true); $payArr = [1=>'微信支付', 2=>'付款码支付', 3=>'个体户支付', 4=>'充值卡支付']; $wareArr = $this->warehouse; foreach($result as $k=>&$v){ $v['team_name'] = $v['team_id']>0 ? $teams[$v['team_id']] : '';; $v['payment_type'] = $payArr[$v['payment_type']]; $v['ctime'] = $v['send_time']; $v['warehouse'] = $wareArr[$v['warehouse']]; } $indexKey = ['team_name','ctime','id','receivedAmount', 'cost', 'freight_cost', 'payment_type', 'receiverName', 'logistics_id']; $title = ['团队', '发货时间', '订单编号', '成交金额','货品成本', '物流成本', '支付方式', '收货人', '物流单号']; $filename = 'fahuomingxi_'.date('Y-m-d_H').'.xlsx'; return Order::export_excel($result, $filename, $indexKey, $title); } }