123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772 |
- <?php
- /**
- * Created by Sublime.
- * User: hao
- * Date: 19/08/30
- * Time: 上午11:20
- */
- namespace App\Http\Controllers\Admin;
- use App\Http\Controllers\Controller;
- use App\Logs;
- use App\CustTotal;
- use App\CustDetail;
- use App\AdCost;
- use App\Oplog;
- use App\Order;
- use App\Admin;
- use Illuminate\Http\Request;
- use Illuminate\Support\Facades\DB;
- use PHPExcel_Reader_Excel2007;
- use PHPExcel_Reader_Excel5;
- use PHPExcel_Reader_CSV;
- class custReportController extends Controller
- {
- public function totalindex(Request $request){
- $page = (int)$request->input('page');
- $pageSize = 20;
- if($page<=0){
- $page = 1;
- }
- $offset = ($page-1) * $pageSize;
- $team_id = (int)$request->input('team_id');
- $stime = $request->input('stime');
- $etime = $request->input('etime');
- $count = CustTotal::where(function($query) use($team_id, $stime, $etime){
- if($team_id) $query->where('team_id', $team_id);
- if($stime) $query->where('dtime', '>=', $stime);
- if($etime) $query->where('dtime', '<=', $etime);
- })->where('is_del',0)->count();
- if ($count > 1) {
- // 总页数
- $pages = ceil($count/$pageSize);
- }else{
- // 总页数
- $pages = 1;
- }
- $result = CustTotal::where(function($query) use($team_id, $stime, $etime){
- if($team_id) $query->where('team_id', $team_id);
- if($stime) $query->where('dtime', '>=', $stime);
- if($etime) $query->where('dtime', '<=', $etime);
- })->where('is_del',0)->orderBy('id', 'desc')->offset($offset)->limit($pageSize)->get();
- $result = json_decode(json_encode($result),true);
- foreach($result as $k=>&$v){
- if($v['team_id']>0){
- $team = DB::table('teams')->select('name')->where('id', $v['team_id'])->first();
- $v['team_name'] = isset($team->name) ? $team->name : '';
- }else{
- $v['team_name'] = '';
- }
- }
- $teamList = DB::table('teams')->select('id', 'name')->where('type', 1)->get();
- $teamList = json_decode(json_encode($teamList), true);
- return view('custreport/totallist', ['result' =>$result,
- 'page' =>$page,
- 'count' =>$count,
- 'pages' =>$pages,
- 'teamlist' =>$teamList,
- 'stime' =>$stime,
- 'etime' =>$etime,
- 'team_id' =>$team_id,
- ]);
- }
- /**
- * 添加订单
- * @return \Illuminate\View\View
- */
- public function totalcreate(Request $request)
- {
- $teamList = DB::table('teams')->select('id', 'name')->where('type', 1)->get();
- $teamList = json_decode(json_encode($teamList), true);
- return view('custreport/totalcreate',['teamlist'=>$teamList]);
- }
- /**
- * 分组管理-进行添加操作
- * @param Request $request
- * @return \Illuminate\Http\RedirectResponse
- */
- public function totalstore(Request $request)
- {
- $team_id = (int)$request->input('team_id');
- $this->validate($request, [
- 'total_cost' => 'required',
- 'total_fan_add' => 'required',
- 'team_id' => 'required',
- 'dtime' => 'required|unique:cust_day_total,dtime,1,is_del,team_id,'.$team_id,
- ], [
- 'total_cost.required' => '总成本不能为空',
- 'total_fan_add.required' => '总加粉数不能为空',
- 'dtime.required' => '日期不能为空',
- 'team_id.required' => '团队不能为空',
- 'dtime.unique' => '指定日期已经添加过',
- ]);
- //数据库-新增数据
- $custreport = array();
-
- $custreport['total_cost'] = $request->input('total_cost');
- $custreport['total_fan_add'] = $request->input('total_fan_add');
- $custreport['dtime'] = $request->input('dtime');
- $custreport['team_id'] = $team_id;
-
- $res = DB::table('cust_day_total')->insertGetId($custreport);
- if($res){
- #记录操作日志
- $self_id = session('admin_id');
- $self_name = session('real_name');
- $context = "运营上报投放数据";
- $type = 0;
- $tables = 'cust_day_total';
- $data_id = $res;
- Oplog::addLog($self_id, $self_name, $context, $type, $tables, $data_id);
- }
- return redirect('/admin/custreport/totalindex')->with('info', '添加成功');
-
- }
- /**
- * 分组管理-编辑分组界面
- * @param $id
- * @return \Illuminate\View\View
- */
- public function totaledit($id,Request $request)
- {
-
- $data = CustTotal::where('id', $id)->first();
- $teamList = DB::table('teams')->select('id', 'name')->where('type', 1)->get();
- $teamList = json_decode(json_encode($teamList), true);
- return view('custreport/totaledit', [
- 'custreport' => $data,
- 'teamlist' => $teamList,
- ]);
- }
- /**
- * 分组管理-进行编辑操作
- * @param Request $request
- * @return \Illuminate\Http\RedirectResponse
- */
- public function totalupdate(Request $request)
- {
- $team_id = (int)$request->input('team_id');
- $id = (int)$request->input('id');
- $this->validate($request, [
- 'id' => 'required',
- 'total_cost' => 'required',
- 'total_fan_add' => 'required',
- 'team_id' => 'required',
- 'dtime' => 'required|unique:cust_day_total,dtime,'.$id.',id,team_id,'.$team_id,
- ], [
- 'id.required' => 'id不能为空',
- 'total_cost.required' => '总成本不能为空',
- 'total_fan_add.required' => '总加粉数不能为空',
- 'team_id.required' => '团队不能为空',
- 'dtime.required' => '日期不能为空',
- 'dtime.unique' => '指定日期已存在',
- ]);
-
- $custreport = array();
- $custreport['total_cost'] = $request->input('total_cost');
- $custreport['total_fan_add'] = $request->input('total_fan_add');
- $custreport['dtime'] = $request->input('dtime');
- $custreport['team_id'] = $team_id;
- $res = DB::table('cust_day_total')->where('id', $id)->update($custreport);
- if($res){
- #记录操作日志
- $self_id = session('admin_id');
- $self_name = session('real_name');
- $context = "修改运营上报数据";
- $type = 0;
- $tables = 'cust_day_total';
- $data_id = $id;
- Oplog::addLog($self_id, $self_name, $context, $type, $tables, $data_id);
- }
- return redirect('/admin/custreport/totalindex')->with('info', '更新成功');
- }
- /**
- * 分组管理-进行删除操作
- * @param Request $request
- * @return \Illuminate\Http\RedirectResponse
- */
- public function totaldelete($id)
- {
- $custreport = CustTotal::find($id);
- $custreport->is_del = 1;
- if ($custreport ->save()){
- #记录操作日志
- $self_id = session('admin_id');
- $self_name = session('real_name');
- $context = "删除运营上报数据";
- $type = 0;
- $tables = 'cust_day_total';
- $data_id = $id;
- Oplog::addLog($self_id, $self_name, $context, $type, $tables, $data_id);
- return redirect('/admin/custreport/totalindex')->with('info', '删除成功');
- }
- }
- public function total_export(Request $request){
-
- $self_role = session('role_name');
- if($self_role == '超级管理员' || $self_role == '团队主管' || $self_role == '售后管理员'){
- $admin_id = $request->input('admin_id');
- }else{
- $admin_id = session('admin_id');
- }
- $stime = $request->input('stime');
- $etime = $request->input('etime');
- $result = custreport::where(function($query) use($admin_id, $stime, $etime){
- if($admin_id) $query->where('admin_id', $admin_id);
- if($stime) $query->where('createTime', '>=', $stime);
- if($etime) $query->where('createTime', '<=', $etime);
- })->where('is_del',0)->custreportBy('id', 'desc')->get();
- $result = json_decode(json_encode($result),true);
- $filename="订单数据.xls";
- header("Content-type:application/vnd.ms-excel");
- Header("Accept-Ranges:bytes");
- Header("Content-Disposition:attachment;filename=".$filename); //$filename导出的文件名
- header("Pragma: no-cache");
- header("Expires: 0");
- $data_str = '<html xmlns:o="urn:schemas-microsoft-com:office:office"
- xmlns:x="urn:schemas-microsoft-com:office:excel"
- xmlns="http://www.w3.org/TR/REC-html40">
- <head>
- <meta http-equiv="expires" content="Mon, 06 Jan 1999 00:00:01 GMT">
- <meta http-equiv=Content-Type content="text/html; charset=gb2312">
- <!--[if gte mso 9]><xml>
- <x:ExcelWorkbook>
- <x:ExcelWorksheets>
- <x:ExcelWorksheet>
- <x:Name></x:Name>
- <x:WorksheetOptions>
- <x:DisplayGridlines/>
- </x:WorksheetOptions>
- </x:ExcelWorksheet>
- </x:ExcelWorksheets>
- </x:ExcelWorkbook>
- </xml><![endif]-->
- </head>';
- $data_str .= "
- <table>
- <tr>
- <th>".iconv("UTF-8", "GB2312//IGNORE","销售微信号")."</th>
- <th>".iconv("UTF-8", "GB2312//IGNORE","销售团队")."</th>
- <th>".iconv("UTF-8", "GB2312//IGNORE","销售")."</th>
- <th>".iconv("UTF-8", "GB2312//IGNORE","订单时间")."</th>
- <th>".iconv("UTF-8", "GB2312//IGNORE","加粉时间")."</th>
- <th>".iconv("UTF-8", "GB2312//IGNORE","是否复购")."</th>
- <th>".iconv("UTF-8", "GB2312//IGNORE","订单金额")."</th>
- <th>".iconv("UTF-8", "GB2312//IGNORE","订单商品")."</th>
- <th>".iconv("UTF-8", "GB2312//IGNORE","是否退补单")."</th>
- <th>".iconv("UTF-8", "GB2312//IGNORE","配送地址")."</th>
- <th>".iconv("UTF-8", "GB2312//IGNORE","配送姓名")."</th>
- <th>".iconv("UTF-8", "GB2312//IGNORE","配送电话")."</th>
- <th>".iconv("UTF-8", "GB2312//IGNORE","供应商成本")."</th>
- <th>".iconv("UTF-8", "GB2312//IGNORE","顺丰单号")."</th>
- </tr>";
- foreach ($result as $k => $v)
- {
- #销售
- $admin = DB::table('admin')->where('id', $v['admin_id'])->first();
- $v['wx_id'] = isset($admin->wx_id) ? $admin->wx_id : '';
- #team
- $team = DB::table('teams')->where('id', $v['team_id'])->first();
- $v['team_name'] = isset($team->name) ? $team->name : '';
- #加粉时间
- $customr = DB::table('customers')->where('phone', $v['receiverMobile'])->first();
- $v['fanTime'] = isset($customr->fanTime) ? $customr->fanTime : '';
- $v['receiverMobile'] = substr($v['receiverMobile'], 0, 3).'****'.substr($v['receiverMobile'], 7);
- $fugou = $v['is_fugou']==1? '是' : '否';
- $is_refund = $v['is_refund']==1? '是' : '否';
- $address = $v['receiverState'].$v['receiverCity'].$v['receiverDistrict'].$v['receiverAddress'];
- $data_str .= "<tr>";
- $data_str .= "<td>".$v['wx_id']."</td>";
- $data_str .= "<td>".iconv("UTF-8", "GB2312//IGNORE", $v["team_name"])."</td>";
- $data_str .= "<td>".iconv("UTF-8", "GB2312//IGNORE", $v["admin_name"])."</td>";
- $data_str .= "<td>".$v['createTime']."</td>";
- $data_str .= "<td>".$v['fanTime']."</td>";
- $data_str .= "<td>".iconv("UTF-8", "GB2312//IGNORE", $fugou)."</td>";
- $data_str .= "<td>".$v['receivedAmount']."</td>";
- $data_str .= "<td>".iconv("UTF-8", "GB2312//IGNORE", $v["goods_note"])."</td>";
- $data_str .= "<td>".iconv("UTF-8", "GB2312//IGNORE", $is_refund)."</td>";
- $data_str .= "<td>".iconv("UTF-8", "GB2312//IGNORE", $address)."</td>";
- $data_str .= "<td>".iconv("UTF-8", "GB2312//IGNORE", $v["receiverName"])."</td>";
- $data_str .= "<td>".$v['receiverMobile']."</td>";
- $data_str .= "<td>".$v['cost']."</td>";
- $data_str .= "<td style='vnd.ms-excel.numberformat:@'>".$v["logistics_id"]."</td>";
- $data_str .= "</tr>";
- }
- $data_str .= "</table>";
- echo $data_str;
- exit;
- }
- public function detailindex(Request $request){
- $page = (int)$request->input('page');
- $pageSize = 20;
- if($page<=0){
- $page = 1;
- }
- $offset = ($page-1) * $pageSize;
- $team_id = (int)$request->input('team_id');
- $admin_id = (int)$request->input('admin_id');
- $search_admin = 1;
- #只能看自己团队的
- $self_role = session('role_name');
- if($self_role != '超级管理员' && $self_role != '售后管理员'){
- $self_id = session('admin_id');
- $team_id = DB::table('admin')->where('id', $self_id)->pluck('team_id');
- }
- if($admin_id>0 && !$team_id){
- $team_id = DB::table('admin')->where('id', $admin_id)->pluck('team_id');
- }
- if($self_role == '销售' || $self_role == '分销销售'){
- $search_admin = 0;
- $admin_id = $self_id;
- }
- //假如有团队筛选,检索销售队员
- $sale_ids = null;
- if($team_id>0 && !$admin_id){
- $sale_ids = DB::table('admin')->where('team_id', $team_id)->lists('id');
- }
-
- $stime = $request->input('stime');
- $etime = $request->input('etime');
- $count = CustDetail::where(function($query) use($admin_id, $stime, $etime, $sale_ids){
- if($admin_id) $query->where('admin_id', $admin_id);
- if($stime) $query->where('dtime', '>=', $stime);
- if($etime) $query->where('dtime', '<=', $etime);
- if($sale_ids !== null) $query->whereIn('admin_id', $sale_ids);
- })->where('is_del',0)->count();
- if ($count > 1) {
- // 总页数
- $pages = ceil($count/$pageSize);
- }else{
- // 总页数
- $pages = 1;
- }
- $result = CustDetail::where(function($query) use($admin_id, $stime, $etime, $sale_ids){
- if($admin_id) $query->where('admin_id', $admin_id);
- if($stime) $query->where('dtime', '>=', $stime);
- if($etime) $query->where('dtime', '<=', $etime);
- if($sale_ids !== null) $query->whereIn('admin_id', $sale_ids);
- })->where('is_del',0)->orderBy('id', 'desc')->offset($offset)->limit($pageSize)->get();
- $result = json_decode(json_encode($result),true);
- $teamList = DB::table('teams')->select('id', 'name')->where(function($query) use($self_role, $team_id){
- if($team_id>0 && $self_role != '超级管理员' && $self_role != '售后管理员') $query->where('id', $team_id);
- })->where('type', 1)->get();
- $teamList = json_decode(json_encode($teamList), true);
- $adminList = DB::table('admin')->select('id', 'realname', 'username')->where('id','>', 1)->where('is_use',1)->where(function($query) use($self_role, $team_id){
- if($team_id>0 && $self_role != '超级管理员' && $self_role != '售后管理员') $query->where('team_id', $team_id);
- })->get();
- $adminList = json_decode(json_encode($adminList), true);
- //未上报数据销售
- $noReportSaler = $this->noReportSaler();
- $no_height = '100';
- if($no_num = count($noReportSaler)) $no_height += round($no_num * 37);
- return view('custreport/detaillist', ['result' =>$result,
- 'page' =>$page,
- 'count' =>$count,
- 'pages' =>$pages,
- 'stime' =>$stime,
- 'etime' =>$etime,
- 'admin_id' =>$admin_id,
- 'team_id' =>$team_id,
- 'search_admin' =>$search_admin,
- 'adminlist' =>$adminList,
- 'teamlist' =>$teamList,
- 'noReportSaler' =>$noReportSaler,
- 'no_height' =>$no_height,
- 'self_role' =>$self_role,
- ]);
- }
- /**
- * 添加订单
- * @return \Illuminate\View\View
- */
- public function detailcreate(Request $request)
- {
- $adminList = DB::table('admin')->select('id', 'realname', 'username')->where('id','>', 1)->where('is_use',1)->get();
- $adminList = json_decode(json_encode($adminList), true);
- $teamList = DB::table('teams')->select('id', 'name')->where('type', 1)->get();
- $teamList = json_decode(json_encode($teamList), true);
- $self_role = session('role_name');
- return view('custreport/detailcreate',['adminlist'=>$adminList, 'teamlist'=>$teamList, 'self_role'=>$self_role]);
- }
- /**
- * 分组管理-进行添加操作
- * @param Request $request
- * @return \Illuminate\Http\RedirectResponse
- */
- public function detailstore(Request $request)
- {
- $admin_id = (int)$request->input('admin_id');
- if(!$admin_id){
- $admin_id = session('admin_id');
- }
- $this->validate($request, [
- 'old_consult' => 'required',
- 'new_consult' => 'required',
- 'fan_add' => 'required',
- 'dtime' => 'required|unique:cust_day_detail,dtime,1,is_del,admin_id,'.$admin_id,
- ], [
- 'old_consult.required' => '老粉咨询不能为空',
- 'new_consult.required' => '新粉咨询数不能为空',
- 'fan_add.required' => '加粉数不能为空',
- 'dtime.required' => '日期不能为空',
- 'dtime.unique' => '指定日期已经添加过',
- ]);
- //数据库-新增数据
- $custreport = array();
-
- $custreport['old_consult'] = $request->input('old_consult');
- $custreport['new_consult'] = $request->input('new_consult');
- $custreport['fan_add'] = $request->input('fan_add');
- $custreport['new_reply'] = $request->input('new_reply');
- $custreport['dtime'] = $request->input('dtime');
-
- if($admin_id>0){
- $admin_info = DB::table('admin')->select('realname', 'team_id')->where('id', $admin_id)->first();
- $custreport['admin_id'] = $admin_id;
- $custreport['admin_name'] = $admin_info->realname;
- }else{
- $custreport['admin_id'] = session('admin_id');
- $custreport['admin_name'] = session('real_name');
- }
- $custreport['reporter_id'] = session('admin_id');
- $res = DB::table('cust_day_detail')->insertGetId($custreport);
- if($res){
- #记录操作日志
- $self_id = session('admin_id');
- $self_name = session('real_name');
- $context = "销售上报加粉数据";
- $type = 0;
- $tables = 'cust_day_detail';
- $data_id = $res;
- Oplog::addLog($self_id, $self_name, $context, $type, $tables, $data_id);
- }
- return redirect('/admin/custreport/detailindex')->with('info', '添加成功');
-
- }
- /**
- * 分组管理-编辑分组界面
- * @param $id
- * @return \Illuminate\View\View
- */
- public function detailedit($id,Request $request)
- {
-
- $data = CustDetail::where('id', $id)->first();
- $adminList = DB::table('admin')->select('id', 'realname', 'username')->where('is_use',1)->where('id','>', 1)->get();
- $adminList = json_decode(json_encode($adminList), true);
- $teamList = DB::table('teams')->select('id', 'name')->where('type', 1)->get();
- $teamList = json_decode(json_encode($teamList), true);
- $self_role = session('role_name');
- return view('custreport/detailedit', [
- 'custreport' => $data,
- 'adminlist' => $adminList,
- 'teamlist' => $teamList,
- 'self_role' => $self_role,
- ]);
- }
- /**
- * 分组管理-进行编辑操作
- * @param Request $request
- * @return \Illuminate\Http\RedirectResponse
- */
- public function detailupdate(Request $request)
- {
- $id = (int)$request->input('id');
- $admin_id = (int)$request->input('admin_id');
- if(!$admin_id){
- $admin_id = session('admin_id');
- }
- $this->validate($request, [
- 'id' => 'required',
- 'old_consult' => 'required',
- 'new_consult' => 'required',
- 'fan_add' => 'required',
- 'dtime' => 'required|unique:cust_day_detail,dtime,'.$id.',id,admin_id,'.$admin_id,
- ], [
- 'id.required' => 'id不能为空',
- 'old_consult.required' => '老粉咨询不能为空',
- 'new_consult.required' => '新粉咨询数不能为空',
- 'fan_add.required' => '加粉数不能为空',
- 'dtime.required' => '日期不能为空',
- 'dtime.unique' => '指定日期已经存在',
- ]);
- //数据库-新增数据
- $custreport = array();
- $custreport['old_consult'] = $request->input('old_consult');
- $custreport['new_consult'] = $request->input('new_consult');
- $custreport['fan_add'] = $request->input('fan_add');
- $custreport['new_reply'] = $request->input('new_reply');
- $custreport['dtime'] = $request->input('dtime');
- $admin_id = (int)$request->input('admin_id');
- if($admin_id>0){
- $admin_info = DB::table('admin')->select('realname', 'team_id')->where('id', $admin_id)->first();
- $custreport['admin_id'] = $admin_id;
- $custreport['admin_name'] = $admin_info->realname;
- }
- $res = DB::table('cust_day_detail')->where('id', $id)->update($custreport);
- if($res){
- #记录操作日志
- $self_id = session('admin_id');
- $self_name = session('real_name');
- $context = "修改销售上报数据";
- $type = 0;
- $tables = 'cust_day_detail';
- $data_id = $id;
- Oplog::addLog($self_id, $self_name, $context, $type, $tables, $data_id);
- }
- return redirect('/admin/custreport/detailindex')->with('info', '更新成功');
- }
- /**
- * 分组管理-进行删除操作
- * @param Request $request
- * @return \Illuminate\Http\RedirectResponse
- */
- public function detaildelete($id)
- {
- $custreport = CustDetail::find($id);
- $custreport->is_del = 1;
- if ($custreport ->save()){
-
- #记录操作日志
- $self_id = session('admin_id');
- $self_name = session('real_name');
- $context = "删除销售上报数据";
- $type = 0;
- $tables = 'cust_day_detail';
- $data_id = $id;
- Oplog::addLog($self_id, $self_name, $context, $type, $tables, $data_id);
-
- return redirect('/admin/custreport/detailindex')->with('info', '删除成功');
- }
- }
- public function detail_export(Request $request){
-
- $team_id = (int)$request->input('team_id');
- $admin_id = (int)$request->input('admin_id');
- $search_admin = 1;
- #只能看自己团队的
- $self_role = session('role_name');
- if($self_role != '超级管理员' && $self_role != '售后管理员'){
- $self_id = session('admin_id');
- $team_id = DB::table('admin')->where('id', $self_id)->pluck('team_id');
- }
- if($admin_id>0 && !$team_id){
- $team_id = DB::table('admin')->where('id', $admin_id)->pluck('team_id');
- }
- if($self_role == '销售' || $self_role == '分销销售'){
- $search_admin = 0;
- $admin_id = $self_id;
- }
- //假如有团队筛选,检索销售队员
- $sale_ids = null;
- if($team_id>0 && !$admin_id){
- $sale_ids = DB::table('admin')->where('team_id', $team_id)->lists('id');
- }
- $stime = $request->input('stime');
- $etime = $request->input('etime');
- $result = CustDetail::where(function($query) use($admin_id, $stime, $etime, $sale_ids){
- if($admin_id) $query->where('admin_id', $admin_id);
- if($stime) $query->where('dtime', '>=', $stime);
- if($etime) $query->where('dtime', '<=', $etime);
- if($sale_ids !== null) $query->whereIn('admin_id', $sale_ids);
- })->where('is_del',0)->orderBy('id', 'desc')->get();
- $result = json_decode(json_encode($result),true);
- $indexKey = ['dtime','fan_add','new_reply','old_consult','new_consult','admin_name'];
- $title = ['日期', '加粉数', '新粉回复数', '老粉询价数', '新粉询价数','所属销售'];
-
- $filename = 'xiaoshoushangbao_'.date('Y-m-d_H').'.xlsx';
- return Order::export_excel($result, $filename, $indexKey, $title);
- }
- /**
- * 地域投入数据
- */
- public function disCostList(Request $request){
- $page = (int)$request->input('page');
- $pageSize = 20;
- if($page<=0){
- $page = 1;
- }
- $offset = ($page-1) * $pageSize;
- $stime = $request->input('stime');
- $etime = $request->input('etime');
- $count = AdCost::where(function($query) use($stime, $etime){
- if($stime) $query->where('ad_time', '>=', $stime);
- if($etime) $query->where('ad_time', '<=', $etime);
- })->count();
- if ($count > 1) {
- // 总页数
- $pages = ceil($count/$pageSize);
- }else{
- // 总页数
- $pages = 1;
- }
- $result = AdCost::where(function($query) use($stime, $etime){
- if($stime) $query->where('ad_time', '>=', $stime);
- if($etime) $query->where('ad_time', '<=', $etime);
- })->orderBy('id', 'desc')->offset($offset)->limit($pageSize)->get();
- $result = json_decode(json_encode($result),true);
- $today = date('Y-m-d');
- return view('custreport/discostlist', ['result' =>$result,
- 'page' =>$page,
- 'count' =>$count,
- 'pages' =>$pages,
- 'stime' =>$stime,
- 'etime' =>$etime,
- 'today' =>$today,
- ]);
- }
- /**
- * excel导入每日地域投入信息
- * @param Request $request
- */
- public function importDisCost(Request $request) {
- $wexin_appid = trim($request->input('wexin_appid'));
- $ad_time = $request->input('ad_time');
- $excelFile = $request->file('dataFile');
- //实例化Excel读取类
- $objReader = new PHPExcel_Reader_Excel2007();
- if(!$objReader->canRead($excelFile)){
- $objReader = new PHPExcel_Reader_Excel5();
- if(!$objReader->canRead($excelFile)){
- $objReader = new PHPExcel_Reader_CSV();
- $objReader->setInputEncoding('UTF-8');
- $objReader->setDelimiter(',');
- if(!$objReader->canRead($excelFile)){
- echo "\n".'无法识别的Excel文件!';
- return false;
- }
- }
- }
- $objPHPExcel=$objReader->load($excelFile);
- $worksheet=$objPHPExcel->getSheet(0);//获取第一个工作表
- $highestRow=$worksheet->getHighestRow();//取得总行数
- $highestColumn=$worksheet->getHighestColumn(); //取得总列数
- $lines = $highestRow - 1;
- if ($lines <= 0) {
- //'Excel表格中没有数据';
- return false;
- }
- $errorArr=[];
- $okStr = '';
- for ($row = 2; $row <= $highestRow; ++$row) {
- $params = array();
- $params['wexin_appid'] = $wexin_appid;
- $params['ad_time'] = $ad_time;
- $params['city'] = trim($worksheet->getCellByColumnAndRow(0, $row)->getValue());
- $params['cost'] = trim($worksheet->getCellByColumnAndRow(1, $row)->getValue());
- $params['exposure_times'] = intval($worksheet->getCellByColumnAndRow(2, $row)->getValue());
- $params['click_times'] = intval($worksheet->getCellByColumnAndRow(3, $row)->getValue());
- $params['click_rate'] = trim($worksheet->getCellByColumnAndRow(4, $row)->getValue());
- $params['conversion_times'] = intval($worksheet->getCellByColumnAndRow(5, $row)->getValue());
- $params['conversion_cost'] = trim($worksheet->getCellByColumnAndRow(6, $row)->getValue());
- //判断是否已存在
- $if_data = AdCost::where('wexin_appid', $params['wexin_appid'])->where('ad_time', $params['ad_time'])->where('city', $params['city'])->first();
- if(isset($if_data->id)){
- $result = AdCost::where('id', $if_data->id)->update($params);
- }else{
- $result = AdCost::insert($params);
- }
- }
- return redirect('admin/custreport/disCostList')->with('info','导入成功');
- }
- /**
- * 未上报数据销售
- */
- public function noReportSaler(){
- $today = date('Y-m-d');
- //销售列表
- //销售团队
- $team_ids = Admin::getTeams();
- $ids = DB::table('admin_role')->where('user_id','!=',3)->whereIn('role_name', ['销售', '分销销售', '管理员'])->lists('user_id');
- //销售名字
- $salers = DB::table('admin')->whereIn('id', $ids)->lists('realname', 'id');
-
- $stime = date('Y-m-d', strtotime('-15 day'));
- //查每日上报数据销售
- $result = DB::table('cust_day_detail')->select('admin_id', 'dtime')->where('dtime','<',$today)->where('dtime','>=',$stime)->where('is_del', 0)->orderBy('dtime', 'desc')->get();
- $result = json_decode(json_encode($result), true);
- $data = array();
- foreach($result as $k=>$v){
- $data[$v['dtime']][] = $v['admin_id'];
- }
- $ret = array();
- foreach($data as $k=>$v){
- $ids = DB::table('admin')->whereIn('id', $ids)->where('is_use', 1)->whereIn('team_id', $team_ids)->where('create_time','<',$k)->lists('id');
- $diff = array_diff($ids, $v);
- if(!empty($diff)){
- //名字带入
- foreach($diff as &$nid){
- $nid = $salers[$nid];
- }
- $ret[$k] = implode(',', $diff);
- }
- }
- return $ret;
- }
- }
|