<?php

namespace App\Services\Complain;

use App\Models\BlackListModel;
use App\Models\Deed\DeedModel;
use App\Models\Fpdx\PairModel;
use App\Services\User\ProfileService;

class PairComplaintHandle extends ComplaintHandle
{


    public function erasing()
    {
        $be_user = $this->getBeUser();
        foreach ($this->fields as $field) {
            switch ($field) {
                case "photo_src":
                case "photo_1":
                case "photo_2":
                case "photo_3":
                case "photo_4":
                    $pfs = new ProfileService();
                    $pfs->deletePhoto($be_user->uid, $field);
                    break;
                case "voice":
                case "weixin":
                case "qq":
                case "school":
                case "home":
                case "address":
                    $userService = new ProfileService();
                    $userService->updateUser($be_user, [$field => '']);
                    break;
                case "sex":
                    $value = 0;
                    $be_user = $this->getBeUser();
                    if ($be_user->sex == 1) {
                        $value = 2;
                    } elseif ($be_user->sex = 2) {
                        $value = 1;
                    }
                    $userService = new ProfileService();
                    $userService->updateUser($be_user, [$field => $value]);
                    break;
            }
        }
    }


    public function reply()
    {
        switch ($this->state) {
            case "1":
                return "仅回复";
                break;
            case "2":
                return "联系客服";
                break;
            case "4":
                $deed = DeedModel::find($this->complaint->value);
                $pair = PairModel::where('assoc_id', $deed->ack)->first();
                if (800 <= $pair->state && $pair->state < 900) {
                    $pair->state -= 300;
                    $pair->save();
                }

                return "修改不满意";
        }
    }


    public function defriend()
    {
        BlackListModel::create([
            'uid' => $this->complaint->be_uid,
            'complaint_id' => $this->complaint->id,
            'end_at' => $this->defriend_at,
            'type' => 'fpdx',
            'state' => $this->defriend_state,
        ]);
    }
}
