CustomerController.php 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. <?php
  2. namespace App\Http\Controllers;
  3. use App\Services\OwnerReportService;
  4. use Exception;
  5. use Illuminate\Database\Eloquent\Builder;
  6. use Illuminate\Http\Request;
  7. use Illuminate\Http\Response;
  8. use Illuminate\Support\Facades\Gate;
  9. use Illuminate\Support\Facades\Http;
  10. class CustomerController extends Controller
  11. {
  12. /**
  13. * Display a listing of the resource.
  14. * @param Request $request
  15. * @return Response
  16. */
  17. public function projectReport(Request $request)
  18. {
  19. if(!Gate::allows('客户管理-项目-报表')){ return view('customer.index'); }
  20. $withs = ["ownerBillReport","owner"=>function($query){
  21. /** @var Builder $query */
  22. $query->select("id","name","deleted_at","created_at","customer_id","user_owner_group_id")
  23. ->with(["customer","userOwnerGroup"]);
  24. }];
  25. $ownerGroups = app('userOwnerGroupService')->getSelection();
  26. $customers = app('customerService')->getSelection();
  27. $owners = app('ownerService')->getSelection();
  28. $reports = app("ownerReportService")->paginate($request->input(),$withs);
  29. return response()->view('customer.project.report',compact("reports","ownerGroups","customers","owners"));
  30. }
  31. public function projectReportExport(Request $request)
  32. {
  33. if(!Gate::allows('客户管理-项目-报表')){ return '没有权限'; }
  34. /** @var OwnerReportService $service */
  35. $service = app('ownerReportService');
  36. $withs = ["ownerBillReport","owner"=>function($query){
  37. /** @var Builder $query */
  38. $query->select("id","name","deleted_at","created_at","customer_id","user_owner_group_id")
  39. ->with(["customer","userOwnerGroup"]);
  40. }];
  41. if ($request->checkAllSign ?? false){
  42. $params = $request->input();
  43. unset($params['checkAllSign']);
  44. $reports = $service->get($params,$withs);
  45. }else $reports = $service->get(["id"=>$request->data ?? ''],$withs);
  46. $column = ["项目小组","客户","子项目","状态","创建日期","在库时长","结算月","日均单量","结算月上月盘点面积","结算月盘点面积","初始账单金额","确认账单金额","确认日期"];
  47. $list = [];
  48. foreach ($reports as $report){
  49. $list[] = [
  50. $report->owner ? ($report->owner->userOwnerGroup ? $report->owner->userOwnerGroup->name : '') : '',
  51. $report->owner ? ($report->owner->customer ? $report->owner->customer->name : '') : '',
  52. $report->owner ? $report->owner->name : '',
  53. $report->owner ? ($report->owner->deleted_at ? "冻结" : "激活") : '',
  54. $report->owner ? (string)$report->owner->created_at : '',
  55. $report->owner ? ($report->owner->created_at ? ((new \DateTime())->diff(new \DateTime($report->owner->created_at))->days)." 天" : '') : '',
  56. $report->counting_month,
  57. $report->daily_average_order_amount,
  58. $report->last_month_counting_area,
  59. $report->current_month_counting_area,
  60. $report->ownerBillReport ? $report->ownerBillReport->initial_fee : '',
  61. $report->ownerBillReport ? $report->ownerBillReport->confirm_fee : '',
  62. $report->ownerBillReport ? (string)$report->ownerBillReport->updated_at : '',
  63. ];
  64. }
  65. $post = Http::post(config('go.export.url'),['type'=>'base','data'=>json_encode(["row"=>$column,"list"=>$list],JSON_UNESCAPED_UNICODE)]);
  66. if ($post->status() == 500){
  67. throw new Exception($post->header("Msg"));
  68. }
  69. return response($post,200, [
  70. "Content-type"=>"application/octet-stream",
  71. "Content-Disposition"=>"attachment; filename=客户项目报表-".date('ymdHis').'.xlsx',
  72. ]);
  73. }
  74. public function projectIndex()
  75. {
  76. if(!Gate::allows('客户管理-项目-查询')){ return redirect('denied'); }
  77. $customers = app('ownerService')->get();
  78. return response()->view('customer.project.index');
  79. }
  80. public function projectCreate()
  81. {
  82. if(!Gate::allows('客户管理-项目-录入')){ return redirect('denied'); }
  83. return response()->view('customer.project.create');
  84. }
  85. public function projectArea()
  86. {
  87. if(!Gate::allows('客户管理-项目-面积')){ return redirect('denied'); }
  88. return response()->view('customer.project.area');
  89. }
  90. public function financeInstantBill()
  91. {
  92. if(!Gate::allows('客户管理-财务-即时账单')){ return redirect('denied'); }
  93. return response()->view('customer.finance.instantBill');
  94. }
  95. public function financeBillConfirmation()
  96. {
  97. if(!Gate::allows('客户管理-财务-账单确认')){ return redirect('denied'); }
  98. return response()->view('customer.finance.billConfirmation');
  99. }
  100. }