Geen omschrijving

CustReportController.php 31KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733
  1. <?php
  2. /**
  3. * Created by Sublime.
  4. * User: hao
  5. * Date: 19/08/30
  6. * Time: 上午11:20
  7. */
  8. namespace App\Http\Controllers\Admin;
  9. use App\Http\Controllers\Controller;
  10. use App\Logs;
  11. use App\CustTotal;
  12. use App\CustDetail;
  13. use App\AdCost;
  14. use App\Oplog;
  15. use Illuminate\Http\Request;
  16. use Illuminate\Support\Facades\DB;
  17. use PHPExcel_Reader_Excel2007;
  18. use PHPExcel_Reader_Excel5;
  19. use PHPExcel_Reader_CSV;
  20. class custReportController extends Controller
  21. {
  22. public function totalindex(Request $request){
  23. $page = (int)$request->input('page');
  24. $pageSize = 20;
  25. if($page<=0){
  26. $page = 1;
  27. }
  28. $offset = ($page-1) * $pageSize;
  29. $team_id = (int)$request->input('team_id');
  30. $stime = $request->input('stime');
  31. $etime = $request->input('etime');
  32. $count = CustTotal::where(function($query) use($team_id, $stime, $etime){
  33. if($team_id) $query->where('team_id', $team_id);
  34. if($stime) $query->where('dtime', '>=', $stime);
  35. if($etime) $query->where('dtime', '<=', $etime);
  36. })->where('is_del',0)->count();
  37. if ($count > 1) {
  38. // 总页数
  39. $pages = ceil($count/$pageSize);
  40. }else{
  41. // 总页数
  42. $pages = 1;
  43. }
  44. $result = CustTotal::where(function($query) use($team_id, $stime, $etime){
  45. if($team_id) $query->where('team_id', $team_id);
  46. if($stime) $query->where('dtime', '>=', $stime);
  47. if($etime) $query->where('dtime', '<=', $etime);
  48. })->where('is_del',0)->orderBy('id', 'desc')->offset($offset)->limit($pageSize)->get();
  49. $result = json_decode(json_encode($result),true);
  50. foreach($result as $k=>&$v){
  51. if($v['team_id']>0){
  52. $team = DB::table('teams')->select('name')->where('id', $v['team_id'])->first();
  53. $v['team_name'] = isset($team->name) ? $team->name : '';
  54. }else{
  55. $v['team_name'] = '';
  56. }
  57. }
  58. $teamList = DB::table('teams')->select('id', 'name')->get();
  59. $teamList = json_decode(json_encode($teamList), true);
  60. return view('custreport/totallist', ['result' =>$result,
  61. 'page' =>$page,
  62. 'count' =>$count,
  63. 'pages' =>$pages,
  64. 'teamlist' =>$teamList,
  65. 'stime' =>$stime,
  66. 'etime' =>$etime,
  67. 'team_id' =>$team_id,
  68. ]);
  69. }
  70. /**
  71. * 添加订单
  72. * @return \Illuminate\View\View
  73. */
  74. public function totalcreate(Request $request)
  75. {
  76. $teamList = DB::table('teams')->select('id', 'name')->get();
  77. $teamList = json_decode(json_encode($teamList), true);
  78. return view('custreport/totalcreate',['teamlist'=>$teamList]);
  79. }
  80. /**
  81. * 分组管理-进行添加操作
  82. * @param Request $request
  83. * @return \Illuminate\Http\RedirectResponse
  84. */
  85. public function totalstore(Request $request)
  86. {
  87. $team_id = (int)$request->input('team_id');
  88. $this->validate($request, [
  89. 'total_cost' => 'required',
  90. 'total_fan_add' => 'required',
  91. 'team_id' => 'required',
  92. 'dtime' => 'required|unique:cust_day_total,dtime,1,is_del,team_id,'.$team_id,
  93. ], [
  94. 'total_cost.required' => '总成本不能为空',
  95. 'total_fan_add.required' => '总加粉数不能为空',
  96. 'dtime.required' => '日期不能为空',
  97. 'team_id.required' => '团队不能为空',
  98. 'dtime.unique' => '指定日期已经添加过',
  99. ]);
  100. //数据库-新增数据
  101. $custreport = array();
  102. $custreport['total_cost'] = $request->input('total_cost');
  103. $custreport['total_fan_add'] = $request->input('total_fan_add');
  104. $custreport['dtime'] = $request->input('dtime');
  105. $custreport['team_id'] = $team_id;
  106. $res = DB::table('cust_day_total')->insertGetId($custreport);
  107. if($res){
  108. #记录操作日志
  109. $self_id = session('admin_id');
  110. $self_name = session('real_name');
  111. $context = "运营上报投放数据";
  112. $type = 0;
  113. $tables = 'cust_day_total';
  114. $data_id = $res;
  115. Oplog::addLog($self_id, $self_name, $context, $type, $tables, $data_id);
  116. }
  117. return redirect('/admin/custreport/totalindex')->with('info', '添加成功');
  118. }
  119. /**
  120. * 分组管理-编辑分组界面
  121. * @param $id
  122. * @return \Illuminate\View\View
  123. */
  124. public function totaledit($id,Request $request)
  125. {
  126. $data = CustTotal::where('id', $id)->first();
  127. $teamList = DB::table('teams')->select('id', 'name')->get();
  128. $teamList = json_decode(json_encode($teamList), true);
  129. return view('custreport/totaledit', [
  130. 'custreport' => $data,
  131. 'teamlist' => $teamList,
  132. ]);
  133. }
  134. /**
  135. * 分组管理-进行编辑操作
  136. * @param Request $request
  137. * @return \Illuminate\Http\RedirectResponse
  138. */
  139. public function totalupdate(Request $request)
  140. {
  141. $team_id = (int)$request->input('team_id');
  142. $id = (int)$request->input('id');
  143. $this->validate($request, [
  144. 'id' => 'required',
  145. 'total_cost' => 'required',
  146. 'total_fan_add' => 'required',
  147. 'team_id' => 'required',
  148. 'dtime' => 'required|unique:cust_day_total,dtime,'.$id.',id,team_id,'.$team_id,
  149. ], [
  150. 'id.required' => 'id不能为空',
  151. 'total_cost.required' => '总成本不能为空',
  152. 'total_fan_add.required' => '总加粉数不能为空',
  153. 'team_id.required' => '团队不能为空',
  154. 'dtime.required' => '日期不能为空',
  155. 'dtime.unique' => '指定日期已存在',
  156. ]);
  157. $custreport = array();
  158. $custreport['total_cost'] = $request->input('total_cost');
  159. $custreport['total_fan_add'] = $request->input('total_fan_add');
  160. $custreport['dtime'] = $request->input('dtime');
  161. $custreport['team_id'] = $team_id;
  162. $res = DB::table('cust_day_total')->where('id', $id)->update($custreport);
  163. if($res){
  164. #记录操作日志
  165. $self_id = session('admin_id');
  166. $self_name = session('real_name');
  167. $context = "修改运营上报数据";
  168. $type = 0;
  169. $tables = 'cust_day_total';
  170. $data_id = $id;
  171. Oplog::addLog($self_id, $self_name, $context, $type, $tables, $data_id);
  172. }
  173. return redirect('/admin/custreport/totalindex')->with('info', '更新成功');
  174. }
  175. /**
  176. * 分组管理-进行删除操作
  177. * @param Request $request
  178. * @return \Illuminate\Http\RedirectResponse
  179. */
  180. public function totaldelete($id)
  181. {
  182. $custreport = CustTotal::find($id);
  183. $custreport->is_del = 1;
  184. if ($custreport ->save()){
  185. #记录操作日志
  186. $self_id = session('admin_id');
  187. $self_name = session('real_name');
  188. $context = "删除运营上报数据";
  189. $type = 0;
  190. $tables = 'cust_day_total';
  191. $data_id = $id;
  192. Oplog::addLog($self_id, $self_name, $context, $type, $tables, $data_id);
  193. return redirect('/admin/custreport/totalindex')->with('info', '删除成功');
  194. }
  195. }
  196. public function total_export(Request $request){
  197. $self_role = session('role_name');
  198. if($self_role == '超级管理员' || $self_role == '团队主管' || $self_role == '售后管理员'){
  199. $admin_id = $request->input('admin_id');
  200. }else{
  201. $admin_id = session('admin_id');
  202. }
  203. $stime = $request->input('stime');
  204. $etime = $request->input('etime');
  205. $result = custreport::where(function($query) use($admin_id, $stime, $etime){
  206. if($admin_id) $query->where('admin_id', $admin_id);
  207. if($stime) $query->where('createTime', '>=', $stime);
  208. if($etime) $query->where('createTime', '<=', $etime);
  209. })->where('is_del',0)->custreportBy('id', 'desc')->get();
  210. $result = json_decode(json_encode($result),true);
  211. $filename="订单数据.xls";
  212. header("Content-type:application/vnd.ms-excel");
  213. Header("Accept-Ranges:bytes");
  214. Header("Content-Disposition:attachment;filename=".$filename); //$filename导出的文件名
  215. header("Pragma: no-cache");
  216. header("Expires: 0");
  217. $data_str = '<html xmlns:o="urn:schemas-microsoft-com:office:office"
  218. xmlns:x="urn:schemas-microsoft-com:office:excel"
  219. xmlns="http://www.w3.org/TR/REC-html40">
  220. <head>
  221. <meta http-equiv="expires" content="Mon, 06 Jan 1999 00:00:01 GMT">
  222. <meta http-equiv=Content-Type content="text/html; charset=gb2312">
  223. <!--[if gte mso 9]><xml>
  224. <x:ExcelWorkbook>
  225. <x:ExcelWorksheets>
  226. <x:ExcelWorksheet>
  227. <x:Name></x:Name>
  228. <x:WorksheetOptions>
  229. <x:DisplayGridlines/>
  230. </x:WorksheetOptions>
  231. </x:ExcelWorksheet>
  232. </x:ExcelWorksheets>
  233. </x:ExcelWorkbook>
  234. </xml><![endif]-->
  235. </head>';
  236. $data_str .= "
  237. <table>
  238. <tr>
  239. <th>".iconv("UTF-8", "GB2312//IGNORE","销售微信号")."</th>
  240. <th>".iconv("UTF-8", "GB2312//IGNORE","销售团队")."</th>
  241. <th>".iconv("UTF-8", "GB2312//IGNORE","销售")."</th>
  242. <th>".iconv("UTF-8", "GB2312//IGNORE","订单时间")."</th>
  243. <th>".iconv("UTF-8", "GB2312//IGNORE","加粉时间")."</th>
  244. <th>".iconv("UTF-8", "GB2312//IGNORE","是否复购")."</th>
  245. <th>".iconv("UTF-8", "GB2312//IGNORE","订单金额")."</th>
  246. <th>".iconv("UTF-8", "GB2312//IGNORE","订单商品")."</th>
  247. <th>".iconv("UTF-8", "GB2312//IGNORE","是否退补单")."</th>
  248. <th>".iconv("UTF-8", "GB2312//IGNORE","配送地址")."</th>
  249. <th>".iconv("UTF-8", "GB2312//IGNORE","配送姓名")."</th>
  250. <th>".iconv("UTF-8", "GB2312//IGNORE","配送电话")."</th>
  251. <th>".iconv("UTF-8", "GB2312//IGNORE","供应商成本")."</th>
  252. <th>".iconv("UTF-8", "GB2312//IGNORE","顺丰单号")."</th>
  253. </tr>";
  254. foreach ($result as $k => $v)
  255. {
  256. #销售
  257. $admin = DB::table('admin')->where('id', $v['admin_id'])->first();
  258. $v['wx_id'] = isset($admin->wx_id) ? $admin->wx_id : '';
  259. #team
  260. $team = DB::table('teams')->where('id', $v['team_id'])->first();
  261. $v['team_name'] = isset($team->name) ? $team->name : '';
  262. #加粉时间
  263. $customr = DB::table('customers')->where('phone', $v['receiverMobile'])->first();
  264. $v['fanTime'] = isset($customr->fanTime) ? $customr->fanTime : '';
  265. $v['receiverMobile'] = substr($v['receiverMobile'], 0, 3).'****'.substr($v['receiverMobile'], 7);
  266. $fugou = $v['is_fugou']==1? '是' : '否';
  267. $is_refund = $v['is_refund']==1? '是' : '否';
  268. $address = $v['receiverState'].$v['receiverCity'].$v['receiverDistrict'].$v['receiverAddress'];
  269. $data_str .= "<tr>";
  270. $data_str .= "<td>".$v['wx_id']."</td>";
  271. $data_str .= "<td>".iconv("UTF-8", "GB2312//IGNORE", $v["team_name"])."</td>";
  272. $data_str .= "<td>".iconv("UTF-8", "GB2312//IGNORE", $v["admin_name"])."</td>";
  273. $data_str .= "<td>".$v['createTime']."</td>";
  274. $data_str .= "<td>".$v['fanTime']."</td>";
  275. $data_str .= "<td>".iconv("UTF-8", "GB2312//IGNORE", $fugou)."</td>";
  276. $data_str .= "<td>".$v['receivedAmount']."</td>";
  277. $data_str .= "<td>".iconv("UTF-8", "GB2312//IGNORE", $v["goods_note"])."</td>";
  278. $data_str .= "<td>".iconv("UTF-8", "GB2312//IGNORE", $is_refund)."</td>";
  279. $data_str .= "<td>".iconv("UTF-8", "GB2312//IGNORE", $address)."</td>";
  280. $data_str .= "<td>".iconv("UTF-8", "GB2312//IGNORE", $v["receiverName"])."</td>";
  281. $data_str .= "<td>".$v['receiverMobile']."</td>";
  282. $data_str .= "<td>".$v['cost']."</td>";
  283. $data_str .= "<td style='vnd.ms-excel.numberformat:@'>".$v["logistics_id"]."</td>";
  284. $data_str .= "</tr>";
  285. }
  286. $data_str .= "</table>";
  287. echo $data_str;
  288. exit;
  289. }
  290. public function detailindex(Request $request){
  291. $page = (int)$request->input('page');
  292. $pageSize = 20;
  293. if($page<=0){
  294. $page = 1;
  295. }
  296. $offset = ($page-1) * $pageSize;
  297. $self_role = session('role_name');
  298. if($self_role == '超级管理员' || $self_role == '团队主管' || $self_role == '运营投放' || $self_role == '售后管理员'){
  299. $admin_id = $request->input('admin_id');
  300. $search_admin = 1;
  301. }else{
  302. $admin_id = session('admin_id');
  303. $search_admin = 0;
  304. }
  305. $stime = $request->input('stime');
  306. $etime = $request->input('etime');
  307. $count = CustDetail::where(function($query) use($admin_id, $stime, $etime){
  308. if($admin_id) $query->where('admin_id', $admin_id);
  309. if($stime) $query->where('dtime', '>=', $stime);
  310. if($etime) $query->where('dtime', '<=', $etime);
  311. })->where('is_del',0)->count();
  312. if ($count > 1) {
  313. // 总页数
  314. $pages = ceil($count/$pageSize);
  315. }else{
  316. // 总页数
  317. $pages = 1;
  318. }
  319. $result = CustDetail::where(function($query) use($admin_id, $stime, $etime){
  320. if($admin_id) $query->where('admin_id', $admin_id);
  321. if($stime) $query->where('dtime', '>=', $stime);
  322. if($etime) $query->where('dtime', '<=', $etime);
  323. })->where('is_del',0)->orderBy('id', 'desc')->offset($offset)->limit($pageSize)->get();
  324. $result = json_decode(json_encode($result),true);
  325. $adminList = DB::table('admin')->select('id', 'realname', 'username')->where('id','>', 1)->get();
  326. $adminList = json_decode(json_encode($adminList), true);
  327. return view('custreport/detaillist', ['result' =>$result,
  328. 'page' =>$page,
  329. 'count' =>$count,
  330. 'pages' =>$pages,
  331. 'stime' =>$stime,
  332. 'etime' =>$etime,
  333. 'admin_id' =>$admin_id,
  334. 'search_admin' =>$search_admin,
  335. 'adminlist' =>$adminList,
  336. ]);
  337. }
  338. /**
  339. * 添加订单
  340. * @return \Illuminate\View\View
  341. */
  342. public function detailcreate(Request $request)
  343. {
  344. $adminList = DB::table('admin')->select('id', 'realname', 'username')->where('id','>', 1)->get();
  345. $adminList = json_decode(json_encode($adminList), true);
  346. $teamList = DB::table('teams')->select('id', 'name')->get();
  347. $teamList = json_decode(json_encode($teamList), true);
  348. $self_role = session('role_name');
  349. return view('custreport/detailcreate',['adminlist'=>$adminList, 'teamlist'=>$teamList, 'self_role'=>$self_role]);
  350. }
  351. /**
  352. * 分组管理-进行添加操作
  353. * @param Request $request
  354. * @return \Illuminate\Http\RedirectResponse
  355. */
  356. public function detailstore(Request $request)
  357. {
  358. $admin_id = (int)$request->input('admin_id');
  359. if(!$admin_id){
  360. $admin_id = session('admin_id');
  361. }
  362. $this->validate($request, [
  363. 'old_consult' => 'required',
  364. 'new_consult' => 'required',
  365. 'fan_add' => 'required',
  366. 'dtime' => 'required|unique:cust_day_detail,dtime,1,is_del,admin_id,'.$admin_id,
  367. ], [
  368. 'old_consult.required' => '老粉咨询不能为空',
  369. 'new_consult.required' => '新粉咨询数不能为空',
  370. 'fan_add.required' => '加粉数不能为空',
  371. 'dtime.required' => '日期不能为空',
  372. 'dtime.unique' => '指定日期已经添加过',
  373. ]);
  374. //数据库-新增数据
  375. $custreport = array();
  376. $custreport['old_consult'] = $request->input('old_consult');
  377. $custreport['new_consult'] = $request->input('new_consult');
  378. $custreport['fan_add'] = $request->input('fan_add');
  379. $custreport['new_reply'] = $request->input('new_reply');
  380. $custreport['dtime'] = $request->input('dtime');
  381. if($admin_id>0){
  382. $admin_info = DB::table('admin')->select('realname', 'team_id')->where('id', $admin_id)->first();
  383. $custreport['admin_id'] = $admin_id;
  384. $custreport['admin_name'] = $admin_info->realname;
  385. }else{
  386. $custreport['admin_id'] = session('admin_id');
  387. $custreport['admin_name'] = session('real_name');
  388. }
  389. $custreport['reporter_id'] = session('admin_id');
  390. $res = DB::table('cust_day_detail')->insertGetId($custreport);
  391. if($res){
  392. #记录操作日志
  393. $self_id = session('admin_id');
  394. $self_name = session('real_name');
  395. $context = "销售上报加粉数据";
  396. $type = 0;
  397. $tables = 'cust_day_detail';
  398. $data_id = $res;
  399. Oplog::addLog($self_id, $self_name, $context, $type, $tables, $data_id);
  400. }
  401. return redirect('/admin/custreport/detailindex')->with('info', '添加成功');
  402. }
  403. /**
  404. * 分组管理-编辑分组界面
  405. * @param $id
  406. * @return \Illuminate\View\View
  407. */
  408. public function detailedit($id,Request $request)
  409. {
  410. $data = CustDetail::where('id', $id)->first();
  411. $adminList = DB::table('admin')->select('id', 'realname', 'username')->where('id','>', 1)->get();
  412. $adminList = json_decode(json_encode($adminList), true);
  413. $teamList = DB::table('teams')->select('id', 'name')->get();
  414. $teamList = json_decode(json_encode($teamList), true);
  415. $self_role = session('role_name');
  416. return view('custreport/detailedit', [
  417. 'custreport' => $data,
  418. 'adminlist' => $adminList,
  419. 'teamlist' => $teamList,
  420. 'self_role' => $self_role,
  421. ]);
  422. }
  423. /**
  424. * 分组管理-进行编辑操作
  425. * @param Request $request
  426. * @return \Illuminate\Http\RedirectResponse
  427. */
  428. public function detailupdate(Request $request)
  429. {
  430. $id = (int)$request->input('id');
  431. $admin_id = (int)$request->input('admin_id');
  432. if(!$admin_id){
  433. $admin_id = session('admin_id');
  434. }
  435. $this->validate($request, [
  436. 'id' => 'required',
  437. 'old_consult' => 'required',
  438. 'new_consult' => 'required',
  439. 'fan_add' => 'required',
  440. 'dtime' => 'required|unique:cust_day_detail,dtime,'.$id.',id,admin_id,'.$admin_id,
  441. ], [
  442. 'id.required' => 'id不能为空',
  443. 'old_consult.required' => '老粉咨询不能为空',
  444. 'new_consult.required' => '新粉咨询数不能为空',
  445. 'fan_add.required' => '加粉数不能为空',
  446. 'dtime.required' => '日期不能为空',
  447. 'dtime.unique' => '指定日期已经存在',
  448. ]);
  449. //数据库-新增数据
  450. $custreport = array();
  451. $custreport['old_consult'] = $request->input('old_consult');
  452. $custreport['new_consult'] = $request->input('new_consult');
  453. $custreport['fan_add'] = $request->input('fan_add');
  454. $custreport['new_reply'] = $request->input('new_reply');
  455. $custreport['dtime'] = $request->input('dtime');
  456. $admin_id = (int)$request->input('admin_id');
  457. if($admin_id>0){
  458. $admin_info = DB::table('admin')->select('realname', 'team_id')->where('id', $admin_id)->first();
  459. $custreport['admin_id'] = $admin_id;
  460. $custreport['admin_name'] = $admin_info->realname;
  461. }
  462. $res = DB::table('cust_day_detail')->where('id', $id)->update($custreport);
  463. if($res){
  464. #记录操作日志
  465. $self_id = session('admin_id');
  466. $self_name = session('real_name');
  467. $context = "修改销售上报数据";
  468. $type = 0;
  469. $tables = 'cust_day_detail';
  470. $data_id = $id;
  471. Oplog::addLog($self_id, $self_name, $context, $type, $tables, $data_id);
  472. }
  473. return redirect('/admin/custreport/detailindex')->with('info', '更新成功');
  474. }
  475. /**
  476. * 分组管理-进行删除操作
  477. * @param Request $request
  478. * @return \Illuminate\Http\RedirectResponse
  479. */
  480. public function detaildelete($id)
  481. {
  482. $custreport = CustDetail::find($id);
  483. $custreport->is_del = 1;
  484. if ($custreport ->save()){
  485. #记录操作日志
  486. $self_id = session('admin_id');
  487. $self_name = session('real_name');
  488. $context = "删除销售上报数据";
  489. $type = 0;
  490. $tables = 'cust_day_detail';
  491. $data_id = $id;
  492. Oplog::addLog($self_id, $self_name, $context, $type, $tables, $data_id);
  493. return redirect('/admin/custreport/detailindex')->with('info', '删除成功');
  494. }
  495. }
  496. public function detail_export(Request $request){
  497. $self_role = session('role_name');
  498. if($self_role == '超级管理员' || $self_role == '团队主管' || $self_role == '运营投放' || $self_role == '售后管理员'){
  499. $admin_id = $request->input('admin_id');
  500. }else{
  501. $admin_id = session('admin_id');
  502. }
  503. $stime = $request->input('stime');
  504. $etime = $request->input('etime');
  505. $result = CustDetail::where(function($query) use($admin_id, $stime, $etime){
  506. if($admin_id) $query->where('admin_id', $admin_id);
  507. if($stime) $query->where('createTime', '>=', $stime);
  508. if($etime) $query->where('createTime', '<=', $etime);
  509. })->where('is_del',0)->orderBy('id', 'desc')->get();
  510. $result = json_decode(json_encode($result),true);
  511. $filename="粉丝数据分日统计.xls";
  512. header("Content-type:application/vnd.ms-excel");
  513. Header("Accept-Ranges:bytes");
  514. Header("Content-Disposition:attachment;filename=".$filename); //$filename导出的文件名
  515. header("Pragma: no-cache");
  516. header("Expires: 0");
  517. $data_str = "
  518. <table>
  519. <tr>
  520. <th>".iconv("UTF-8", "GB2312//IGNORE","销售微信号")."</th>
  521. <th>".iconv("UTF-8", "GB2312//IGNORE","销售团队")."</th>
  522. <th>".iconv("UTF-8", "GB2312//IGNORE","销售")."</th>
  523. <th>".iconv("UTF-8", "GB2312//IGNORE","订单时间")."</th>
  524. <th>".iconv("UTF-8", "GB2312//IGNORE","加粉时间")."</th>
  525. <th>".iconv("UTF-8", "GB2312//IGNORE","是否复购")."</th>
  526. <th>".iconv("UTF-8", "GB2312//IGNORE","订单金额")."</th>
  527. <th>".iconv("UTF-8", "GB2312//IGNORE","订单商品")."</th>
  528. <th>".iconv("UTF-8", "GB2312//IGNORE","是否退补单")."</th>
  529. <th>".iconv("UTF-8", "GB2312//IGNORE","配送地址")."</th>
  530. <th>".iconv("UTF-8", "GB2312//IGNORE","配送姓名")."</th>
  531. <th>".iconv("UTF-8", "GB2312//IGNORE","配送电话")."</th>
  532. <th>".iconv("UTF-8", "GB2312//IGNORE","供应商成本")."</th>
  533. <th>".iconv("UTF-8", "GB2312//IGNORE","顺丰单号")."</th>
  534. </tr>";
  535. foreach ($result as $k => $v)
  536. {
  537. #销售
  538. $admin = DB::table('admin')->where('id', $v['admin_id'])->first();
  539. $v['wx_id'] = isset($admin->wx_id) ? $admin->wx_id : '';
  540. #team
  541. $team = DB::table('teams')->where('id', $v['team_id'])->first();
  542. $v['team_name'] = isset($team->name) ? $team->name : '';
  543. #加粉时间
  544. $customr = DB::table('customers')->where('phone', $v['receiverMobile'])->first();
  545. $v['fanTime'] = isset($customr->fanTime) ? $customr->fanTime : '';
  546. $v['receiverMobile'] = substr($v['receiverMobile'], 0, 3).'****'.substr($v['receiverMobile'], 7);
  547. $fugou = $v['is_fugou']==1? '是' : '否';
  548. $is_refund = $v['is_refund']==1? '是' : '否';
  549. $address = $v['receiverState'].$v['receiverCity'].$v['receiverDistrict'].$v['receiverAddress'];
  550. $data_str .= "<tr>";
  551. $data_str .= "<td>".$v['wx_id']."</td>";
  552. $data_str .= "<td>".iconv("UTF-8", "GB2312//IGNORE", $v["team_name"])."</td>";
  553. $data_str .= "<td>".iconv("UTF-8", "GB2312//IGNORE", $v["admin_name"])."</td>";
  554. $data_str .= "<td>".$v['createTime']."</td>";
  555. $data_str .= "<td>".$v['fanTime']."</td>";
  556. $data_str .= "<td>".iconv("UTF-8", "GB2312//IGNORE", $fugou)."</td>";
  557. $data_str .= "<td>".$v['receivedAmount']."</td>";
  558. $data_str .= "<td>".iconv("UTF-8", "GB2312//IGNORE", $v["goods_note"])."</td>";
  559. $data_str .= "<td>".iconv("UTF-8", "GB2312//IGNORE", $is_refund)."</td>";
  560. $data_str .= "<td>".iconv("UTF-8", "GB2312//IGNORE", $address)."</td>";
  561. $data_str .= "<td>".iconv("UTF-8", "GB2312//IGNORE", $v["receiverName"])."</td>";
  562. $data_str .= "<td>".$v['receiverMobile']."</td>";
  563. $data_str .= "<td>".$v['cost']."</td>";
  564. $data_str .= "<td style='vnd.ms-excel.numberformat:@'>".$v["logistics_id"]."</td>";
  565. $data_str .= "</tr>";
  566. }
  567. $data_str .= "</table>";
  568. echo $data_str;
  569. exit;
  570. }
  571. /**
  572. * 地域投入数据
  573. */
  574. public function disCostList(Request $request){
  575. $page = (int)$request->input('page');
  576. $pageSize = 20;
  577. if($page<=0){
  578. $page = 1;
  579. }
  580. $offset = ($page-1) * $pageSize;
  581. $stime = $request->input('stime');
  582. $etime = $request->input('etime');
  583. $count = AdCost::where(function($query) use($stime, $etime){
  584. if($stime) $query->where('ad_time', '>=', $stime);
  585. if($etime) $query->where('ad_time', '<=', $etime);
  586. })->count();
  587. if ($count > 1) {
  588. // 总页数
  589. $pages = ceil($count/$pageSize);
  590. }else{
  591. // 总页数
  592. $pages = 1;
  593. }
  594. $result = AdCost::where(function($query) use($stime, $etime){
  595. if($stime) $query->where('ad_time', '>=', $stime);
  596. if($etime) $query->where('ad_time', '<=', $etime);
  597. })->orderBy('id', 'desc')->offset($offset)->limit($pageSize)->get();
  598. $result = json_decode(json_encode($result),true);
  599. $today = date('Y-m-d');
  600. return view('custreport/discostlist', ['result' =>$result,
  601. 'page' =>$page,
  602. 'count' =>$count,
  603. 'pages' =>$pages,
  604. 'stime' =>$stime,
  605. 'etime' =>$etime,
  606. 'today' =>$today,
  607. ]);
  608. }
  609. /**
  610. * excel导入每日地域投入信息
  611. * @param Request $request
  612. */
  613. public function importDisCost(Request $request) {
  614. $wexin_appid = trim($request->input('wexin_appid'));
  615. $ad_time = $request->input('ad_time');
  616. $excelFile = $request->file('dataFile');
  617. //实例化Excel读取类
  618. $objReader = new PHPExcel_Reader_Excel2007();
  619. if(!$objReader->canRead($excelFile)){
  620. $objReader = new PHPExcel_Reader_Excel5();
  621. if(!$objReader->canRead($excelFile)){
  622. $objReader = new PHPExcel_Reader_CSV();
  623. $objReader->setInputEncoding('UTF-8');
  624. $objReader->setDelimiter(',');
  625. if(!$objReader->canRead($excelFile)){
  626. echo "\n".'无法识别的Excel文件!';
  627. return false;
  628. }
  629. }
  630. }
  631. $objPHPExcel=$objReader->load($excelFile);
  632. $worksheet=$objPHPExcel->getSheet(0);//获取第一个工作表
  633. $highestRow=$worksheet->getHighestRow();//取得总行数
  634. $highestColumn=$worksheet->getHighestColumn(); //取得总列数
  635. $lines = $highestRow - 1;
  636. if ($lines <= 0) {
  637. //'Excel表格中没有数据';
  638. return false;
  639. }
  640. $errorArr=[];
  641. $okStr = '';
  642. for ($row = 2; $row <= $highestRow; ++$row) {
  643. $params = array();
  644. $params['wexin_appid'] = $wexin_appid;
  645. $params['ad_time'] = $ad_time;
  646. $params['city'] = trim($worksheet->getCellByColumnAndRow(0, $row)->getValue());
  647. $params['cost'] = trim($worksheet->getCellByColumnAndRow(1, $row)->getValue());
  648. $params['exposure_times'] = intval($worksheet->getCellByColumnAndRow(2, $row)->getValue());
  649. $params['click_times'] = intval($worksheet->getCellByColumnAndRow(3, $row)->getValue());
  650. $params['click_rate'] = trim($worksheet->getCellByColumnAndRow(4, $row)->getValue());
  651. $params['conversion_times'] = intval($worksheet->getCellByColumnAndRow(5, $row)->getValue());
  652. $params['conversion_cost'] = trim($worksheet->getCellByColumnAndRow(6, $row)->getValue());
  653. $result = AdCost::insert($params);
  654. }
  655. return redirect('admin/custreport/disCostList')->with('info','导入成功');
  656. }
  657. }