<?php


namespace app\admin\controller\consultant;


use app\admin\service\consultant\CustomService;
use app\admin\validate\consultant\MarketCustomerValidate;
use app\controller\Curd;
use app\model\MarketCustomer;
use support\Request;
use support\Response;

class CustomController extends Curd
{
    public function __construct()
    {
        $this->model = new MarketCustomer();
        $this->validate = true;
        $this->validateClass = new MarketCustomerValidate();
    }

    /**
     * Notes: 获取选项配置信息
     * User: yb
     * Date: 2024/8/5
     * Time: 15:35
     */
    public function getOptionConfig()
    {
        return json_success('请求成功', CustomService::config());
    }

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

    /**
     * Notes: 编辑客户
     * User: yb
     * Date: 2024/8/6
     * Time: 16:51
     */
    public function updateCustom(Request $request)
    {
        $params = $request->post();
        if ($this->validate && !$this->validateClass->scene('update')->check($params)) {
            return json_fail($this->validateClass->getError());
        }
        return CustomService::update($params);
    }

    public function select(Request $request): Response
    {
        return CustomService::index($request);
    }

    /**
     * Notes: 删除客户
     * User: yb
     * Date: 2024/8/2
     * Time: 13:34
     * @param Request $request
     * @return Response
     */
    public function deleteCustom(Request $request)
    {
        $params = $request->post();
        if (empty($params['ids'])) {
            return json_fail('请选择要删除的数据');
        }
        return CustomService::delete($params['ids']);
    }

    /**
     * Notes: 跟进记录
     * User: yb
     * Date: 2024/8/7
     * Time: 8:59
     * @param Request $request
     */
    public function followList(Request $request)
    {
        return CustomService::follow($request);
    }

    /**
     * Notes: 删除跟进记录
     * User: yb
     * Date: 2024/8/7
     * Time: 11:32
     * @param Request $request
     */
    public function deleteFollow(Request $request)
    {
        $params = $request->post();
        if (empty($params['ids'])) {
            return json_fail('请选择要删除的数据');
        }
        return CustomService::deleteFollow($params['ids']);
    }

    /**
     * Notes: 转移客户
     * User: yb
     * Date: 2024/8/7
     * Time: 14:22
     * @param Request $request
     */
    public function moveCustom(Request $request)
    {
        $params = $request->post();
        if (empty($params['move_type'])) {
            if (empty($params['consultant_id'])) {
                return json_fail('请选择目标顾问');
            }
        } else {
            if (empty($params['dept_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/9/5
     * Time: 12:51
     */
    public function appointConsultant(Request $request)
    {
        $params = $request->post();
        return CustomService::appoint($params);
    }

    /**
     * Notes: 转移记录
     * User: yb
     * Date: 2024/8/7
     * Time: 15:34
     * @param Request $request
     * @return Response
     */
    public function moveLogs(Request $request)
    {
        return CustomService::moveLogs($request);
    }

    /**
     * Notes: 转到访审核
     * User: yb
     * Date: 2024/8/16
     * Time: 15:55
     * @param Request $request
     */
    public function checkCustom(Request $request)
    {
        $params = $request->post();
        if ($this->validate && !$this->validateClass->scene('check')->check($params)) {
            return json_fail($this->validateClass->getError());
        }
        return CustomService::checkCustom($params);
    }

    /**
     * Notes: 统计分析
     * User: yb
     * Date: 2024/8/17
     * Time: 11:50
     */
    public function statisticsIndex(Request $request)
    {
        return CustomService::statisticsIndex($request);
    }

    /**
     * Notes: 导出
     * User: yb
     * Date: 2024/8/17
     * Time: 13:29
     * @param Request $request
     * @return Response
     */
    public function exportData(Request $request)
    {
        return CustomService::exportData($request);
    }

    /**
     * Notes: 按月统计
     * User: yb
     * Date: 2024/8/21
     * Time: 15:54
     */
    public function statisticsByMonth()
    {
        return CustomService::statisticsMonth();
    }

    /**
     * Notes: 导入客户
     * User: yb
     * Date: 2024/9/10
     * Time: 10:29
     */
    public function importCustom(Request $request)
    {
        $params = $request->post();
        return CustomService::import($params);
    }
}