<?php


namespace app\wechat\controller;


use app\wechat\IndexController;
use app\wechat\service\CustomService;
use app\wechat\validate\CustomValidate;
use support\Request;

class CustomController extends IndexController
{

    public function __construct()
    {
        $this->validateClass = new CustomValidate();
    }

    /**
     * Notes: 选项配置
     * User: yb
     * Date: 2024/8/8
     * Time: 15:08
     * @return \support\Response
     */
    public function options()
    {
        return json_success('请求成功', CustomService::config());
    }

    /**
     * Notes:新增客户
     * User: yb
     * Date: 2024/8/8
     * Time: 15:08
     */
    public function addCustom(Request $request)
    {
        $params = $request->post();
        if (!$this->validateClass->scene('add')->check($params)) {
            return json_fail($this->validateClass->getError());
        }
        return CustomService::add($params);
    }

    /**
     * Notes: 客户列表
     * User: yb
     * Date: 2024/8/12
     * Time: 10:57
     */
    public function customList(Request $request)
    {
        $params = $request->post();
        return CustomService::index($params);
    }

    /**
     * Notes: 编辑客户
     * User: yb
     * Date: 2024/8/12
     * Time: 10:36
     * @param Request $request
     */
    public function editCustom(Request $request)
    {
        $params = $request->post();
        if (!$this->validateClass->scene('update')->check($params)) {
            return json_fail($this->validateClass->getError());
        }
        return CustomService::edit($params);
    }

    /**
     * Notes: 客户详情
     * User: yb
     * Date: 2024/8/8
     * Time: 15:48
     */
    public function customInfo(Request $request)
    {
        $params = $request->post();
        if (empty($params['id'])) {
            return json_fail('客户id不能为空');
        }
        return CustomService::info($params['id']);
    }

    /**
     * Notes: 选择客户
     * User: yb
     * Date: 2024/8/13
     * Time: 15:20
     * @param Request $request
     */
    public function selectList(Request $request)
    {
        $params = $request->post();
        return CustomService::myCustomList($params);
    }

    /**
     * Notes: 更新客户状态
     * User: yb
     * Date: 2024/8/14
     * Time: 13:21
     * @param Request $request
     */
    public function updateStatus(Request $request)
    {
        $params = $request->post();
        if (!$this->validateClass->scene('status')->check($params)) {
            return json_fail($this->validateClass->getError());
        }
        return CustomService::updateStatus($params);
    }

    /**
     * Notes: 移交客户
     * User: yb
     * Date: 2024/8/15
     * Time: 14:36
     * @param Request $request
     */
    public function moveCustom(Request $request)
    {
        $params = $request->post();
        if (empty($params['consultant_id'])) {
            return json_fail('请选择目标顾问');
        }
        if (empty($params['move_market_customer_id']) && empty($params['move_consultant_id'])) {
            return json_fail('请选择需要转移的客户或顾问');
        }
        return CustomService::moveCustom($params);
    }

    /**
     * Notes: 移交记录
     * User: yb
     * Date: 2024/8/15
     * Time: 14:36
     * @param Request $request
     */
    public function moveLogs(Request $request)
    {
        $params = $request->post();
        if (empty($params['custom_id'])) {
            return json_fail('客户id不能为空');
        }
        return CustomService::moveLogs($params);
    }

    /**
     * Notes: 审核客户
     * User: yb
     * Date: 2024/8/16
     * Time: 11:38
     */
    public function checkCustom(Request $request)
    {
        $params = $request->post();
        if (!$this->validateClass->scene('check')->check($params)) {
            return json_fail($this->validateClass->getError());
        }
        return CustomService::checkCustom($params);
    }

    /**
     * Notes: 校验客户是否已经登记
     * User: yb
     * Date: 2024/8/21
     * Time: 9:37
     * @param Request $request
     */
    public function checkMobile(Request $request)
    {
        $params = $request->post();
        return CustomService::checkPhone($params);
    }

    /**
     * Notes: 指定顾问
     * User: yb
     * Date: 2024/9/5
     * Time: 12:51
     */
    public function appointConsultant(Request $request)
    {
        $params = $request->post();
        return CustomService::appoint($params);
    }
}