WaveController.php 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  1. <?php
  2. namespace App\Http\Controllers;
  3. use App\Exports\DefaultExport;
  4. use App\Services\WaveService;
  5. use Illuminate\Http\Request;
  6. use Illuminate\Support\Facades\Auth;
  7. use Illuminate\Support\Facades\Gate;
  8. use Maatwebsite\Excel\Facades\Excel;
  9. class WaveController extends Controller
  10. {
  11. public function __construct()
  12. {
  13. app()->bind("WaveService",WaveService::class);
  14. }
  15. // 主页
  16. public function index(Request $request){
  17. if(!Gate::allows('订单管理-波次-查询')){ return redirect(url('/')); }
  18. $waveService = app("WaveService");
  19. $waves = $waveService->queryWave($request);
  20. //$waveStatus = $waveService->getWaveStatus();
  21. $param = $waveService->getPageParameter($request);
  22. $search = $waveService->getSearchCondition($request);
  23. foreach ($waves as $index=>$wave){
  24. $wave->pickerPrint = '';
  25. $wave->pickerPrintTime = '';
  26. $wave->expressPrinting = '';
  27. $wave->expressPrintTime = '';
  28. if(!is_null($wave->userdefine1)){
  29. $str = $wave->userdefine1;
  30. $index = strpos($str,'-PK');
  31. $wave->pickerPrint = substr($str,0,$index);
  32. $wave->pickerPrintTime = substr($str,$index+3);
  33. }
  34. if(!is_null($wave->userdefine2)){
  35. $str = $wave->userdefine2;
  36. if(strpos($str,'-EX')){
  37. $index = strpos($str,'-EX');
  38. $wave->expressPrinting = substr($str,0,$index);
  39. $wave->expressPrintTime = substr($str,$index+3);
  40. }else if(strpos($str,'-Auto')){
  41. $index = strpos($str,'-Auto');
  42. $wave->expressPrinting = substr($str,0,$index);
  43. $wave->expressPrintTime = substr($str,$index+5);
  44. }
  45. }
  46. }
  47. return view("order/wave/search",compact('waves','param','search'));
  48. }
  49. public function create(){
  50. }
  51. // todo
  52. public function store(Request $request){
  53. }
  54. public function edit($id){
  55. }
  56. public function update(Request $request, $id){
  57. }
  58. public function destroy($id){
  59. }
  60. public function cancelPrinting(Request $request){
  61. if(!Gate::allows('订单管理-波次-取消打印标记')){ return ['success'=>false,'fail_info'=>'没有权限,请联系管理员']; }
  62. $waveService = app("WaveService");
  63. $meg = ['success'=>false];
  64. $ids = $request->input("ids");
  65. $meg = $waveService->cancelPrint($ids);
  66. if($meg['fail_info']){
  67. return $meg;
  68. }
  69. $this->log(__METHOD__,'取消打印标记'.__FUNCTION__,json_encode($request->toArray()),Auth::user()['id']);
  70. return $meg;
  71. }
  72. //
  73. public function exportExcelOnParams(Request $request){
  74. $waveService = app("WaveService");
  75. ini_set('max_execution_time',2500);
  76. ini_set('memory_limit','1526M');
  77. $waves = $waveService->downloadExec($request);
  78. $row = $waveService->getExcelFromHead();
  79. $data = [];
  80. foreach ($waves as $index=>$wave){
  81. $arr= [
  82. 'waveNo' => $wave->waveno,
  83. 'codename_c' => $wave->codename_c,
  84. 'waveRule' => $wave->waverule,
  85. 'descr' => $wave->descr,
  86. 'descr_c' => $wave->descr_c,
  87. 'addWho' => $wave->addwho,
  88. 'addTime' => $wave->addtime,
  89. 'pickerPrint'=>'',
  90. 'pickerPrintTime'=>'',
  91. 'expressPrinting'=>'',
  92. 'expressPrintTime'=> ''
  93. ];
  94. if(!is_null($wave->userdefine1)){
  95. $str = $wave->userdefine1;
  96. $index = strpos($str,'-PK');
  97. $arr['pickerPrint'] = substr($str,0,$index);
  98. $arr['pickerPrintTime']= substr($str,$index+3);
  99. }
  100. if(!is_null($wave->userdefine2)){
  101. $str = $wave->userdefine2;
  102. if(strpos($str,'-EX')){
  103. $index = strpos($str,'-EX');
  104. $arr['expressPrinting'] =substr($str,0,$index);
  105. $arr['expressPrintTime'] = substr($str,$index+3);
  106. }else if(strpos($str,'-Auto')){
  107. $index = strpos($str,'-Auto');
  108. $arr['expressPrinting'] =substr($str,0,$index);
  109. $arr['expressPrintTime'] = substr($str,$index+5);
  110. }
  111. }
  112. $data[] = $arr;
  113. }
  114. return Excel::download(new DefaultExport($row,$data),date('YmdHis', time()).'-波次表.xlsx');
  115. }
  116. }