WeighExceptedController.php 3.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. <?php
  2. namespace App\Http\Controllers;
  3. use App\OrderPackage;
  4. use App\Services\OrderPackageService;
  5. use Exception;
  6. use Illuminate\Http\Request;
  7. use Illuminate\Support\Facades\Gate;
  8. use Illuminate\Support\Facades\Http;
  9. use Oursdreams\Export\Export;
  10. class WeighExceptedController extends Controller
  11. {
  12. /**
  13. * Display a listing of the resource.
  14. * @param Request $request
  15. * @return \Illuminate\Http\Response
  16. */
  17. public function indexCreate(Request $request)
  18. {
  19. if(!Gate::allows('称重管理-查看异常')){ return redirect(url('/')); }
  20. /** @var OrderPackageService */
  21. $weightExcepteds = app('OrderPackageService')->createExceptionPaginate($request->paginate ?? 50);
  22. return view('weight.weightExcepted.index',['weightExcepteds'=>$weightExcepteds,'view'=>'indexCreate']);
  23. }
  24. public function indexIssued(Request $request)
  25. {
  26. if(!Gate::allows('称重管理-查看异常')){ return redirect(url('/')); }
  27. $weightExcepteds=app('OrderPackageService')->issueExceptionPaginate($request->paginate ?? 50);
  28. return view('weight.weightExcepted.index',['weightExcepteds'=>$weightExcepteds,'view'=>'indexIssued']);
  29. }
  30. public function export($type ,Request $request){
  31. if(!Gate::allows('称重管理-查看异常')){ return redirect(url('/')); }
  32. $e = new Export();
  33. $e->setMysqlConnection(config('database.connections.mysql.host'),
  34. config('database.connections.mysql.port'),config('database.connections.mysql.database')
  35. ,config('database.connections.mysql.username'),config('database.connections.mysql.password'));
  36. if ($type == 'indexIssued'){
  37. $e->setFileName("称重异常记录单");
  38. if ($request->checkAllSign){
  39. $params = $request->input();
  40. unset($params['checkAllSign']);
  41. $sql = app('WeighExceptedService')->getIssuedExceptionSql($params);
  42. }else $sql=app('WeighExceptedService')->getIssuedExceptionSql(['id'=>$request->data]);
  43. $mapping = [
  44. "logistic_number"=>"快递单号","logistic_name"=>"承运商",
  45. "measuring_machine_name"=>"设备","weigh_time"=>"称重时间",
  46. "weight"=>"重(KG)","length"=>"长(CM)",
  47. "width"=>"宽(CM)","height"=>"高(CM)","bulk"=>"体积(CM³)",
  48. "paper_box_name"=>"纸箱","status"=>"异常类型"
  49. ];
  50. }else{
  51. $e->setFileName("下发异常记录单");
  52. if ($request->checkAllSign){
  53. $params = $request->input();
  54. unset($params['checkAllSign']);
  55. $sql = app('WeighExceptedService')->getCreateExceptionSql($params);
  56. }else $sql=app('WeighExceptedService')->getCreateExceptionSql(['id'=>$request->data]);
  57. $mapping = [
  58. "logistic_number"=>"快递单号","created_at"=>"下发时间",
  59. "delivery_number"=>"发货单号","batch_number"=>"波次号",
  60. "batch_rule"=>"波次规则","recipient"=>"收件人",
  61. "recipient_mobile"=>"收件人电话","logistic_name"=>"承运商","status"=>"异常类型"
  62. ];
  63. }
  64. return $e->sql($sql,$mapping)->direct();
  65. }
  66. }