CustomerController.php 5.0 KB

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