CustomerController.php 5.0 KB

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