<?php

namespace app\admin\controller;

use app\admin\AdminBaseController;
use app\common\model\InfoModel;
use app\common\model\UserFollowModel;
use app\common\model\UserModel;
use app\admin\validate\UserValidate;
use think\exception\ValidateException;

class Info extends AdminBaseController
{
    /**
     * 列表
     */
    public function index()
    {
        return view('', [
            'type_list' => InfoModel::TYPE,
        ]);
    }

    public function listInfo()
    {
        $map   = $this->dealEqualInput(['type'], $this->dealLikeInput(['name', 'mobile']));
        $list  = InfoModel::where($map)
            ->order('id', 'desc')
            ->limit(input('limit'))
            ->page(input('page'))
            ->append(['type_text','sex_text'])->select();
        $count = InfoModel::where($map)->count();
        if ($count == 0) {
            ajax_return(1, '未查询到数据');
        }
        list_return($list, $count);
    }

    /**
     * 用户跟进记录
     */
    public function follow()
    {
        $id   = input('id/d');
        $info = InfoModel::find($id);
        $list = UserFollowModel::where('info_id', $id)->order('id', 'desc')->limit(100)->select();
        return view('', [
            'info'      => $info,
            'list'      => $list,
            'type_list' => UserFollowModel::TYPE,
        ]);
    }

    public function editFollow()
    {
        $id      = input('id/d', 0);
        $user_id = input('user_id/d', 0);
        $info    = InfoModel::find($id);
        if (empty($info) || empty($user_id)) {
            ajax_return(1, '用户信息不存在。');
        }
        UserFollowModel::create([
            'user_id' => $user_id,
            'info_id' => $id,
            'type'    => input('type/d', 1),
            'remark'  => input('remark/s', ""),
        ]);
        ajax_return();
    }
}