|
|
@@ -4,6 +4,8 @@ namespace App\Http\Controllers;
|
|
|
|
|
|
use App\Components\AsyncResponse;
|
|
|
use App\Owner;
|
|
|
+use App\OwnerAreaReport;
|
|
|
+use App\OwnerReport;
|
|
|
use App\Services\LogService;
|
|
|
use App\Services\OwnerAreaReportService;
|
|
|
use App\Services\OwnerBillReportService;
|
|
|
@@ -420,4 +422,84 @@ class CustomerController extends Controller
|
|
|
{
|
|
|
$this->success($this->validator($request->input())->errors());
|
|
|
}
|
|
|
+
|
|
|
+ public function createReport()
|
|
|
+ {
|
|
|
+ $ids = \request("val");
|
|
|
+ if (!$ids)$this->error("未选择任何项目");
|
|
|
+
|
|
|
+ $reports = OwnerReport::query()->with("owner")
|
|
|
+ ->where("counting_month",">=",date("Y-m")."-01")
|
|
|
+ ->whereIn("owner_id",$ids)->get(["id","owner_id"]);
|
|
|
+ $errors = [];
|
|
|
+ $exist = [];
|
|
|
+ foreach ($reports as $report){
|
|
|
+ $errors[] = "“".($report->owner ? $report->owner->name : $report->owner_id)."”已存在本月报表";
|
|
|
+ $exist[] = $report->owner_id;
|
|
|
+ }
|
|
|
+ $ids = array_diff($ids,$exist);
|
|
|
+ $insert = [];
|
|
|
+ $date = date("Y-m-d H:i:s");
|
|
|
+ foreach ($ids as $id){
|
|
|
+ $insert[] = [
|
|
|
+ "owner_id" => $id,
|
|
|
+ "counting_month" => date("Y-m-d"),
|
|
|
+ "created_at" => $date
|
|
|
+ ];
|
|
|
+ }
|
|
|
+ if ($insert){
|
|
|
+ OwnerReport::query()->insert($insert);
|
|
|
+ LogService::log(__METHOD__,"手动生成报表",json_encode($insert));
|
|
|
+ }
|
|
|
+ $reports = OwnerReport::query()->with(["owner.userOwnerGroup","owner.customer"])
|
|
|
+ ->where("counting_month",">=",date("Y-m")."-01")
|
|
|
+ ->whereIn("owner_id",$ids)->get();
|
|
|
+ $result = [];
|
|
|
+ foreach ($reports as $report){
|
|
|
+ $result[] = [
|
|
|
+ "id" => $report->id,
|
|
|
+ "ownerGroupName" => $report->owner ? ($report->owner->userOwnerGroup ? $report->owner->userOwnerGroup->name : '') : '',
|
|
|
+ "customerName" => $report->owner ? ($report->owner->customer ? $report->owner->customer->name : '') : '',
|
|
|
+ "ownerName" => $report->owner ? $report->owner->name : '',
|
|
|
+ "ownerStatus" => $report->owner ? ($report->owner->deleted_at ? "冻结" : "激活") : '',
|
|
|
+ "ownerStorageDuration" => $report->owner ? ($report->owner->created_at ? ((new \DateTime())->diff(new \DateTime($report->owner->created_at))->days) : '') : '',
|
|
|
+ "ownerCreatedAt" => $report->owner ? $report->owner->created_at : '',
|
|
|
+ "countingMonth" => $report->counting_month,
|
|
|
+ ];
|
|
|
+ }
|
|
|
+ $this->success(["errors"=>$errors,"data"=>$result]);
|
|
|
+ }
|
|
|
+
|
|
|
+ public function createAreaReport()
|
|
|
+ {
|
|
|
+ $ids = \request("val");
|
|
|
+ if (!$ids)$this->error("未选择任何项目");
|
|
|
+
|
|
|
+ /** @var OwnerService $service */
|
|
|
+ $service = app("OwnerService");
|
|
|
+ $owners = $service->get(["id"=>$ids],["ownerStoragePriceModels"],false,true);
|
|
|
+ app("OwnerAreaReportService")->notExistToInsert($owners);
|
|
|
+
|
|
|
+ $reports = OwnerAreaReport::query()
|
|
|
+ ->where("counting_month",">=",date("Y-m")."-01")
|
|
|
+ ->whereIn("owner_id",array_column($owners->toArray(),"id"))->get();
|
|
|
+ $result = [];
|
|
|
+ foreach ($reports as $report){
|
|
|
+ $result[] = [
|
|
|
+ "id" => $report->id,
|
|
|
+ "ownerGroupId" => $report->user_owner_group_id,
|
|
|
+ "ownerName" => $report->owner ? $report->owner->name : '',
|
|
|
+ "customerName" => $report->owner ? ($report->owner->customer ? $report->owner->customer->name : '') : '',
|
|
|
+ "countingMonth" => $report->counting_month,
|
|
|
+ "areaOnTray" => $report->area_on_tray,
|
|
|
+ "areaOnHalfTray" => $report->area_on_half_tray,
|
|
|
+ "areaOnFlat" => $report->area_on_flat,
|
|
|
+ "accountingArea" => $report->accounting_area,
|
|
|
+ "status" => $report->status,
|
|
|
+ "updatedAt" => $report->updated_at,
|
|
|
+ "ownerStoragePriceModel"=> $report->ownerStoragePriceModel ? $report->ownerStoragePriceModel->using_type : '' ,
|
|
|
+ ];
|
|
|
+ }
|
|
|
+ $this->success($result);
|
|
|
+ }
|
|
|
}
|