<?php

namespace app\workerapi\controller;

use app\adminapi\logic\goods_category\GoodsCategoryLogic;
use app\common\logic\MasterWorkerExamineLogic;
use app\common\model\dict\DictData;
use app\workerapi\lists\MasterWorkerLists;
use app\workerapi\lists\ServiceWorkLists;
use app\workerapi\lists\TeamServiceWorkLists;
use app\workerapi\logic\LoginLogic;
use app\workerapi\logic\MasterWorkerInfoLogic;
use app\workerapi\logic\MasterWorkerLogic;
use app\workerapi\logic\MasterWorkerTeamLogic;
use app\workerapi\validate\BankAccountValidate;
use app\workerapi\validate\MasterWokerInfoValidate;
use app\workerapi\validate\MasterWokerTeamValidate;
use app\workerapi\validate\MasterWokerValidate;

class MasterWorkerTeamController extends BaseApiController
{
    public array $notNeedLogin = [''];

    /**
     * 获取团队信息
     * @return \think\response\Json
     */
    public function getTeamInfo()
    {
        $result = MasterWorkerTeamLogic::getDetail($this->userId);
        return $this->data($result);
    }
    /**
     * 获取所有分类
     * @return \think\response\Json
     */
    public function getCategory()
    {
        $result = GoodsCategoryLogic::getTreeData();
        return $this->data($result);
    }
    /**
     * 团队成员列表展示和分配
     * @return \think\response\Json
     */
    public function getMemberList()
    {
        return $this->dataLists(new MasterWorkerLists());
    }

    /**
     * 添加团队成员
     * @return \think\response\Json
     */
    public function addTeamMember()
    {
        $params = (new MasterWokerTeamValidate())->post()->goCheck('add');
        /*$res = LoginLogic::confirmMobile($params);
        if(!$res){
            return $this->fail(LoginLogic::getError());
        }*/
        $result = MasterWorkerTeamLogic::addTeamMember($params,$this->userId);
        if($result === false){
            return $this->fail(MasterWorkerTeamLogic::getError());
        }
        return $this->success('', [], 1, 1);
    }
    /**
     * 编辑团队成员
     * @return \think\response\Json
     */
    public function upTeamMember()
    {
        $params = (new MasterWokerTeamValidate())->post()->goCheck('edit');
        $result = MasterWorkerTeamLogic::upTeamMember($params,$params['master_worker_id'],$this->userId);
        if($result === false){
            return $this->fail(MasterWorkerTeamLogic::getError());
        }
        return $this->success('', [], 1, 1);
    }


    /**
     * 分配工单给团队成员
     * @return \think\response\Json
     */
    public function allocation()
    {
        $params = (new MasterWokerTeamValidate())->post()->goCheck('allocation');
        $result = MasterWorkerTeamLogic::allocation($params,$this->userInfo);
        if($result === false){
            return $this->fail(MasterWorkerTeamLogic::getError());
        }
        return $this->success('', [], 1, 1);
    }
    /**
     * 团队工单状态统计
     * @return \think\response\Json
     */
    public function getTeamWorkCount()
    {
        $result = MasterWorkerTeamLogic::MemberWorkStatistics($this->userInfo);
        $day_data = MasterWorkerTeamLogic::TeamOrderStatistics($this->userInfo);
        return $this->data(['work_status_data'=>$result,'day_data'=>$day_data]);
    }

    /**
     * 团队工单查询
     * @return \think\response\Json
     */
    public function getTeamWorkLists()
    {
        return $this->dataLists(new TeamServiceWorkLists());
    }
    /**
     * 日历团队工单查询
     * @return \think\response\Json
     */
    public function getCalendarTeamOrder()
    {
        $params = request()->get();
        return $this->data(MasterWorkerTeamLogic::TeamOrderStatistics($this->userInfo,0,$params['date']??''));
    }

}