No Description

CustReportController.php 21KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501
  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 Illuminate\Http\Request;
  14. use Illuminate\Support\Facades\DB;
  15. class custReportController extends Controller
  16. {
  17. public function totalindex(Request $request){
  18. $page = (int)$request->input('page');
  19. $pageSize = 20;
  20. if($page<=0){
  21. $page = 1;
  22. }
  23. $offset = ($page-1) * $pageSize;
  24. $stime = $request->input('stime');
  25. $etime = $request->input('etime');
  26. $count = CustTotal::where(function($query) use($stime, $etime){
  27. if($stime) $query->where('dtime', '>=', $stime);
  28. if($etime) $query->where('dtime', '<=', $etime);
  29. })->where('is_del',0)->count();
  30. if ($count > 1) {
  31. // 总页数
  32. $pages = ceil($count/$pageSize);
  33. }else{
  34. // 总页数
  35. $pages = 1;
  36. }
  37. $result = CustTotal::where(function($query) use($stime, $etime){
  38. if($stime) $query->where('dtime', '>=', $stime);
  39. if($etime) $query->where('dtime', '<=', $etime);
  40. })->where('is_del',0)->orderBy('id', 'desc')->offset($offset)->limit($pageSize)->get();
  41. $result = json_decode(json_encode($result),true);
  42. return view('custreport/totallist', ['result' =>$result,
  43. 'page' =>$page,
  44. 'count' =>$count,
  45. 'pages' =>$pages,
  46. 'stime' =>$stime,
  47. 'etime' =>$etime,
  48. ]);
  49. }
  50. /**
  51. * 添加订单
  52. * @return \Illuminate\View\View
  53. */
  54. public function totalcreate(Request $request)
  55. {
  56. return view('custreport/totalcreate');
  57. }
  58. /**
  59. * 分组管理-进行添加操作
  60. * @param Request $request
  61. * @return \Illuminate\Http\RedirectResponse
  62. */
  63. public function totalstore(Request $request)
  64. {
  65. $this->validate($request, [
  66. 'total_cost' => 'required',
  67. 'total_fan_add' => 'required',
  68. 'dtime' => 'required',
  69. ], [
  70. 'total_cost.required' => '总成本不能为空',
  71. 'total_fan_add.required' => '总加粉数不能为空',
  72. 'dtime.required' => '日期不能为空',
  73. ]);
  74. //数据库-新增数据
  75. $custreport = array();
  76. $custreport['total_cost'] = $request->input('total_cost');
  77. $custreport['total_fan_add'] = $request->input('total_fan_add');
  78. $custreport['dtime'] = $request->input('dtime');
  79. $res = DB::table('cust_day_total')->insert($custreport);
  80. return redirect('/admin/custreport/totalindex')->with('info', '添加成功');
  81. }
  82. /**
  83. * 分组管理-编辑分组界面
  84. * @param $id
  85. * @return \Illuminate\View\View
  86. */
  87. public function totaledit($id,Request $request)
  88. {
  89. $data = CustTotal::where('id', $id)->first();
  90. return view('custreport/totaledit', [
  91. 'custreport' => $data,
  92. ]);
  93. }
  94. /**
  95. * 分组管理-进行编辑操作
  96. * @param Request $request
  97. * @return \Illuminate\Http\RedirectResponse
  98. */
  99. public function totalupdate(Request $request)
  100. {
  101. $this->validate($request, [
  102. 'id' => 'required',
  103. 'total_cost' => 'required',
  104. 'total_fan_add' => 'required',
  105. 'dtime' => 'required',
  106. ], [
  107. 'id.required' => 'id不能为空',
  108. 'total_cost.required' => '总成本不能为空',
  109. 'total_fan_add.required' => '总加粉数不能为空',
  110. 'dtime.required' => '日期不能为空',
  111. ]);
  112. $custreport = array();
  113. $custreport['total_cost'] = $request->input('total_cost');
  114. $custreport['total_fan_add'] = $request->input('total_fan_add');
  115. $custreport['dtime'] = $request->input('dtime');
  116. $id = (int)$request->input('id');
  117. $res = DB::table('cust_day_total')->where('id', $id)->update($custreport);
  118. return redirect('/admin/custreport/totalindex')->with('info', '更新成功');
  119. }
  120. /**
  121. * 分组管理-进行删除操作
  122. * @param Request $request
  123. * @return \Illuminate\Http\RedirectResponse
  124. */
  125. public function totaldelete($id)
  126. {
  127. $custreport = CustTotal::find($id);
  128. $custreport->is_del = 1;
  129. if ($custreport ->save()){
  130. return redirect('/admin/custreport/totalindex')->with('info', '删除成功');
  131. }
  132. }
  133. public function total_export(Request $request){
  134. $self_role = session('role_name');
  135. if($self_role == '超级管理员' || $self_role == '团队主管'){
  136. $admin_id = $request->input('admin_id');
  137. }else{
  138. $admin_id = session('admin_id');
  139. }
  140. $stime = $request->input('stime');
  141. $etime = $request->input('etime');
  142. $result = custreport::where(function($query) use($admin_id, $stime, $etime){
  143. if($admin_id) $query->where('admin_id', $admin_id);
  144. if($stime) $query->where('createTime', '>=', $stime);
  145. if($etime) $query->where('createTime', '<=', $etime);
  146. })->where('is_del',0)->custreportBy('id', 'desc')->get();
  147. $result = json_decode(json_encode($result),true);
  148. $filename="订单数据.xls";
  149. header("Content-type:application/vnd.ms-excel");
  150. Header("Accept-Ranges:bytes");
  151. Header("Content-Disposition:attachment;filename=".$filename); //$filename导出的文件名
  152. header("Pragma: no-cache");
  153. header("Expires: 0");
  154. $data_str = '<html xmlns:o="urn:schemas-microsoft-com:office:office"
  155. xmlns:x="urn:schemas-microsoft-com:office:excel"
  156. xmlns="http://www.w3.org/TR/REC-html40">
  157. <head>
  158. <meta http-equiv="expires" content="Mon, 06 Jan 1999 00:00:01 GMT">
  159. <meta http-equiv=Content-Type content="text/html; charset=gb2312">
  160. <!--[if gte mso 9]><xml>
  161. <x:ExcelWorkbook>
  162. <x:ExcelWorksheets>
  163. <x:ExcelWorksheet>
  164. <x:Name></x:Name>
  165. <x:WorksheetOptions>
  166. <x:DisplayGridlines/>
  167. </x:WorksheetOptions>
  168. </x:ExcelWorksheet>
  169. </x:ExcelWorksheets>
  170. </x:ExcelWorkbook>
  171. </xml><![endif]-->
  172. </head>';
  173. $data_str .= "
  174. <table>
  175. <tr>
  176. <th>".iconv("UTF-8", "GB2312//IGNORE","销售微信号")."</th>
  177. <th>".iconv("UTF-8", "GB2312//IGNORE","销售团队")."</th>
  178. <th>".iconv("UTF-8", "GB2312//IGNORE","销售")."</th>
  179. <th>".iconv("UTF-8", "GB2312//IGNORE","订单时间")."</th>
  180. <th>".iconv("UTF-8", "GB2312//IGNORE","加粉时间")."</th>
  181. <th>".iconv("UTF-8", "GB2312//IGNORE","是否复购")."</th>
  182. <th>".iconv("UTF-8", "GB2312//IGNORE","订单金额")."</th>
  183. <th>".iconv("UTF-8", "GB2312//IGNORE","订单商品")."</th>
  184. <th>".iconv("UTF-8", "GB2312//IGNORE","是否退补单")."</th>
  185. <th>".iconv("UTF-8", "GB2312//IGNORE","配送地址")."</th>
  186. <th>".iconv("UTF-8", "GB2312//IGNORE","配送姓名")."</th>
  187. <th>".iconv("UTF-8", "GB2312//IGNORE","配送电话")."</th>
  188. <th>".iconv("UTF-8", "GB2312//IGNORE","供应商成本")."</th>
  189. <th>".iconv("UTF-8", "GB2312//IGNORE","顺丰单号")."</th>
  190. </tr>";
  191. foreach ($result as $k => $v)
  192. {
  193. #销售
  194. $admin = DB::table('admin')->where('id', $v['admin_id'])->first();
  195. $v['wx_id'] = isset($admin->wx_id) ? $admin->wx_id : '';
  196. #team
  197. $team = DB::table('teams')->where('id', $v['team_id'])->first();
  198. $v['team_name'] = isset($team->name) ? $team->name : '';
  199. #加粉时间
  200. $customr = DB::table('customers')->where('phone', $v['receiverMobile'])->first();
  201. $v['fanTime'] = isset($customr->fanTime) ? $customr->fanTime : '';
  202. $v['receiverMobile'] = substr($v['receiverMobile'], 0, 3).'****'.substr($v['receiverMobile'], 7);
  203. $fugou = $v['is_fugou']==1? '是' : '否';
  204. $is_refund = $v['is_refund']==1? '是' : '否';
  205. $address = $v['receiverState'].$v['receiverCity'].$v['receiverDistrict'].$v['receiverAddress'];
  206. $data_str .= "<tr>";
  207. $data_str .= "<td>".$v['wx_id']."</td>";
  208. $data_str .= "<td>".iconv("UTF-8", "GB2312//IGNORE", $v["team_name"])."</td>";
  209. $data_str .= "<td>".iconv("UTF-8", "GB2312//IGNORE", $v["admin_name"])."</td>";
  210. $data_str .= "<td>".$v['createTime']."</td>";
  211. $data_str .= "<td>".$v['fanTime']."</td>";
  212. $data_str .= "<td>".iconv("UTF-8", "GB2312//IGNORE", $fugou)."</td>";
  213. $data_str .= "<td>".$v['receivedAmount']."</td>";
  214. $data_str .= "<td>".iconv("UTF-8", "GB2312//IGNORE", $v["goods_note"])."</td>";
  215. $data_str .= "<td>".iconv("UTF-8", "GB2312//IGNORE", $is_refund)."</td>";
  216. $data_str .= "<td>".iconv("UTF-8", "GB2312//IGNORE", $address)."</td>";
  217. $data_str .= "<td>".iconv("UTF-8", "GB2312//IGNORE", $v["receiverName"])."</td>";
  218. $data_str .= "<td>".$v['receiverMobile']."</td>";
  219. $data_str .= "<td>".$v['cost']."</td>";
  220. $data_str .= "<td style='vnd.ms-excel.numberformat:@'>".$v["logistics_id"]."</td>";
  221. $data_str .= "</tr>";
  222. }
  223. $data_str .= "</table>";
  224. echo $data_str;
  225. exit;
  226. }
  227. public function detailindex(Request $request){
  228. $page = (int)$request->input('page');
  229. $pageSize = 20;
  230. if($page<=0){
  231. $page = 1;
  232. }
  233. $offset = ($page-1) * $pageSize;
  234. $self_role = session('role_name');
  235. if($self_role == '超级管理员' || $self_role == '团队主管'){
  236. $admin_id = $request->input('admin_id');
  237. $search_admin = 1;
  238. }else{
  239. $admin_id = session('admin_id');
  240. $search_admin = 0;
  241. }
  242. $stime = $request->input('stime');
  243. $etime = $request->input('etime');
  244. $count = CustDetail::where(function($query) use($admin_id, $stime, $etime){
  245. if($admin_id) $query->where('admin_id', $admin_id);
  246. if($stime) $query->where('dtime', '>=', $stime);
  247. if($etime) $query->where('dtime', '<=', $etime);
  248. })->where('is_del',0)->count();
  249. if ($count > 1) {
  250. // 总页数
  251. $pages = ceil($count/$pageSize);
  252. }else{
  253. // 总页数
  254. $pages = 1;
  255. }
  256. $result = CustDetail::where(function($query) use($admin_id, $stime, $etime){
  257. if($admin_id) $query->where('admin_id', $admin_id);
  258. if($stime) $query->where('dtime', '>=', $stime);
  259. if($etime) $query->where('dtime', '<=', $etime);
  260. })->where('is_del',0)->orderBy('id', 'desc')->offset($offset)->limit($pageSize)->get();
  261. $result = json_decode(json_encode($result),true);
  262. $adminList = DB::table('admin')->select('id', 'realname', 'username')->where('id','>', 1)->get();
  263. $adminList = json_decode(json_encode($adminList), true);
  264. return view('custreport/detaillist', ['result' =>$result,
  265. 'page' =>$page,
  266. 'count' =>$count,
  267. 'pages' =>$pages,
  268. 'stime' =>$stime,
  269. 'etime' =>$etime,
  270. 'admin_id' =>$admin_id,
  271. 'search_admin' =>$search_admin,
  272. 'adminlist' =>$adminList,
  273. ]);
  274. }
  275. /**
  276. * 添加订单
  277. * @return \Illuminate\View\View
  278. */
  279. public function detailcreate(Request $request)
  280. {
  281. return view('custreport/detailcreate');
  282. }
  283. /**
  284. * 分组管理-进行添加操作
  285. * @param Request $request
  286. * @return \Illuminate\Http\RedirectResponse
  287. */
  288. public function detailstore(Request $request)
  289. {
  290. $this->validate($request, [
  291. 'old_consult' => 'required',
  292. 'new_consult' => 'required',
  293. 'fan_add' => 'required',
  294. 'dtime' => 'required',
  295. ], [
  296. 'old_consult.required' => '老粉咨询不能为空',
  297. 'new_consult.required' => '新粉咨询数不能为空',
  298. 'fan_add.required' => '加粉数不能为空',
  299. 'dtime.required' => '日期不能为空',
  300. ]);
  301. //数据库-新增数据
  302. $custreport = array();
  303. $custreport['old_consult'] = $request->input('old_consult');
  304. $custreport['new_consult'] = $request->input('new_consult');
  305. $custreport['fan_add'] = $request->input('fan_add');
  306. $custreport['dtime'] = $request->input('dtime');
  307. $custreport['admin_id'] = session('admin_id');
  308. $custreport['admin_name'] = session('real_name');
  309. $res = DB::table('cust_day_detail')->insert($custreport);
  310. return redirect('/admin/custreport/detailindex')->with('info', '添加成功');
  311. }
  312. /**
  313. * 分组管理-编辑分组界面
  314. * @param $id
  315. * @return \Illuminate\View\View
  316. */
  317. public function detailedit($id,Request $request)
  318. {
  319. $data = CustDetail::where('id', $id)->first();
  320. return view('custreport/detailedit', [
  321. 'custreport' => $data,
  322. ]);
  323. }
  324. /**
  325. * 分组管理-进行编辑操作
  326. * @param Request $request
  327. * @return \Illuminate\Http\RedirectResponse
  328. */
  329. public function detailupdate(Request $request)
  330. {
  331. $this->validate($request, [
  332. 'id' => 'required',
  333. 'old_consult' => 'required',
  334. 'new_consult' => 'required',
  335. 'fan_add' => 'required',
  336. 'dtime' => 'required',
  337. ], [
  338. 'id.required' => 'id不能为空',
  339. 'old_consult.required' => '老粉咨询不能为空',
  340. 'new_consult.required' => '新粉咨询数不能为空',
  341. 'fan_add.required' => '加粉数不能为空',
  342. 'dtime.required' => '日期不能为空',
  343. ]);
  344. //数据库-新增数据
  345. $custreport = array();
  346. $custreport['old_consult'] = $request->input('old_consult');
  347. $custreport['new_consult'] = $request->input('new_consult');
  348. $custreport['fan_add'] = $request->input('fan_add');
  349. $custreport['dtime'] = $request->input('dtime');
  350. $id = (int)$request->input('id');
  351. $res = DB::table('cust_day_detail')->where('id', $id)->update($custreport);
  352. return redirect('/admin/custreport/detailindex')->with('info', '更新成功');
  353. }
  354. /**
  355. * 分组管理-进行删除操作
  356. * @param Request $request
  357. * @return \Illuminate\Http\RedirectResponse
  358. */
  359. public function detaildelete($id)
  360. {
  361. $custreport = CustDetail::find($id);
  362. $custreport->is_del = 1;
  363. if ($custreport ->save()){
  364. return redirect('/admin/custreport/detailindex')->with('info', '删除成功');
  365. }
  366. }
  367. public function detail_export(Request $request){
  368. $self_role = session('role_name');
  369. if($self_role == '超级管理员' || $self_role == '团队主管'){
  370. $admin_id = $request->input('admin_id');
  371. }else{
  372. $admin_id = session('admin_id');
  373. }
  374. $stime = $request->input('stime');
  375. $etime = $request->input('etime');
  376. $result = CustDetail::where(function($query) use($admin_id, $stime, $etime){
  377. if($admin_id) $query->where('admin_id', $admin_id);
  378. if($stime) $query->where('createTime', '>=', $stime);
  379. if($etime) $query->where('createTime', '<=', $etime);
  380. })->where('is_del',0)->orderBy('id', 'desc')->get();
  381. $result = json_decode(json_encode($result),true);
  382. $filename="粉丝数据分日统计.xls";
  383. header("Content-type:application/vnd.ms-excel");
  384. Header("Accept-Ranges:bytes");
  385. Header("Content-Disposition:attachment;filename=".$filename); //$filename导出的文件名
  386. header("Pragma: no-cache");
  387. header("Expires: 0");
  388. $data_str = "
  389. <table>
  390. <tr>
  391. <th>".iconv("UTF-8", "GB2312//IGNORE","销售微信号")."</th>
  392. <th>".iconv("UTF-8", "GB2312//IGNORE","销售团队")."</th>
  393. <th>".iconv("UTF-8", "GB2312//IGNORE","销售")."</th>
  394. <th>".iconv("UTF-8", "GB2312//IGNORE","订单时间")."</th>
  395. <th>".iconv("UTF-8", "GB2312//IGNORE","加粉时间")."</th>
  396. <th>".iconv("UTF-8", "GB2312//IGNORE","是否复购")."</th>
  397. <th>".iconv("UTF-8", "GB2312//IGNORE","订单金额")."</th>
  398. <th>".iconv("UTF-8", "GB2312//IGNORE","订单商品")."</th>
  399. <th>".iconv("UTF-8", "GB2312//IGNORE","是否退补单")."</th>
  400. <th>".iconv("UTF-8", "GB2312//IGNORE","配送地址")."</th>
  401. <th>".iconv("UTF-8", "GB2312//IGNORE","配送姓名")."</th>
  402. <th>".iconv("UTF-8", "GB2312//IGNORE","配送电话")."</th>
  403. <th>".iconv("UTF-8", "GB2312//IGNORE","供应商成本")."</th>
  404. <th>".iconv("UTF-8", "GB2312//IGNORE","顺丰单号")."</th>
  405. </tr>";
  406. foreach ($result as $k => $v)
  407. {
  408. #销售
  409. $admin = DB::table('admin')->where('id', $v['admin_id'])->first();
  410. $v['wx_id'] = isset($admin->wx_id) ? $admin->wx_id : '';
  411. #team
  412. $team = DB::table('teams')->where('id', $v['team_id'])->first();
  413. $v['team_name'] = isset($team->name) ? $team->name : '';
  414. #加粉时间
  415. $customr = DB::table('customers')->where('phone', $v['receiverMobile'])->first();
  416. $v['fanTime'] = isset($customr->fanTime) ? $customr->fanTime : '';
  417. $v['receiverMobile'] = substr($v['receiverMobile'], 0, 3).'****'.substr($v['receiverMobile'], 7);
  418. $fugou = $v['is_fugou']==1? '是' : '否';
  419. $is_refund = $v['is_refund']==1? '是' : '否';
  420. $address = $v['receiverState'].$v['receiverCity'].$v['receiverDistrict'].$v['receiverAddress'];
  421. $data_str .= "<tr>";
  422. $data_str .= "<td>".$v['wx_id']."</td>";
  423. $data_str .= "<td>".iconv("UTF-8", "GB2312//IGNORE", $v["team_name"])."</td>";
  424. $data_str .= "<td>".iconv("UTF-8", "GB2312//IGNORE", $v["admin_name"])."</td>";
  425. $data_str .= "<td>".$v['createTime']."</td>";
  426. $data_str .= "<td>".$v['fanTime']."</td>";
  427. $data_str .= "<td>".iconv("UTF-8", "GB2312//IGNORE", $fugou)."</td>";
  428. $data_str .= "<td>".$v['receivedAmount']."</td>";
  429. $data_str .= "<td>".iconv("UTF-8", "GB2312//IGNORE", $v["goods_note"])."</td>";
  430. $data_str .= "<td>".iconv("UTF-8", "GB2312//IGNORE", $is_refund)."</td>";
  431. $data_str .= "<td>".iconv("UTF-8", "GB2312//IGNORE", $address)."</td>";
  432. $data_str .= "<td>".iconv("UTF-8", "GB2312//IGNORE", $v["receiverName"])."</td>";
  433. $data_str .= "<td>".$v['receiverMobile']."</td>";
  434. $data_str .= "<td>".$v['cost']."</td>";
  435. $data_str .= "<td style='vnd.ms-excel.numberformat:@'>".$v["logistics_id"]."</td>";
  436. $data_str .= "</tr>";
  437. }
  438. $data_str .= "</table>";
  439. echo $data_str;
  440. exit;
  441. }
  442. }