<?php
/**
 * @Statement: [ An Ordinary Person ]
 * @Author: 闻子 < QQ：270988107 >
 * @Copyright: 闻子 2016-2019 All rights reserved.
 *
 *    .--,       .--,
 *   ( (  \.---./  ) )
 *    '.__/o   o\__.'
 *       {=  ^  =}
 *        >  -  <
 *       /       \
 *      //       \
 *     //|   .   |\
 *     "'\       /'"_.-~^`'-.
 *        \  _  /--'         `
 *      ___)( )(___
 *     (((__) (__)))    高山仰止,景行行止.虽不能至,心向往之.
 *
 */

namespace app\common\logic;

use think\Db;

class Link extends Basedata
{
    /**
     * 定义模型
     * @Author 闻子 <270988107@qq.com>
     */
    public static $LinkModel = null;

    /**
     * 实例化模型
     * @Author 闻子 <270988107@qq.com>
     */
    public function __construct()
    {
        parent::__construct();
        self::$LinkModel = model($this->name);
    }

    /**
     * 获取友情链接数据逻辑
     * @Author 闻子 <270988107@qq.com>
     */
    public function getLinkInfo($where = [], $field = true)
    {
        return self::$LinkModel->getInfo($where, $field);
    }

    /**
     * 获取友情链接列表逻辑
     * @Author 闻子 <270988107@qq.com>
     */
    public function getLinkList($where = [], $data = '')
    {
        return self::$LinkModel->getWhereOrder($where, $data);
    }

    /**
     * 友情链接统计数据逻辑
     * @Author 闻子 <270988107@qq.com>
     */
    public function getLinkCount($where = [])
    {
        return self::$LinkModel->stat($where);
    }

    /**
     * 友情链接数据提交逻辑
     * @Author 闻子 <270988107@qq.com>
     */
    public function formdata($data)
    {
        $url = url('/ohbbs/config/link');
        return self::$LinkModel->setInfo($data) ? [RESULT_SUCCESS, '提交成功', $url] : [RESULT_ERROR, self::$LinkModel->getError()];
    }

    /**
     * 友情链接编辑逻辑
     * @Author 闻子 <270988107@qq.com>
     */
    public function getedit($data)
    {
        $url = url('/ohbbs/config/link');
        return self::$LinkModel->setInfo($data) ? ['code' => 1, 'msg' => '提交成功', 'data' => '', 'url' => $url] : ['code' => 0, 'msg' => '提交失败', 'data' => '', 'url' => $url];
    }

    /**
     * 友情链接删除逻辑
     * @Author 闻子 <270988107@qq.com>
     */
    public function getLinkDel($id)
    {
        if (empty($id)) {
            return ["ERROR", '参数异常'];
        }
        $data['id'] = $id;
        $url = url('/ohbbs/config/link');
        return self::$LinkModel->deleteyi($data) ? ['code' => 1, 'msg' => '删除成功', 'data' => '', 'url' => $url] : ['code' => 0, 'msg' => '删除失败', 'data' => '', 'url' => $url];
    }

    /**
     * 批量删除友情链接逻辑
     * @Author 闻子 <270988107@qq.com>
     */
    public function getLinkalldel($data)
    {
        $str = rtrim($data, ","); 
        $row = self::$LinkModel->deleteyi($str);
        $url = url('/ohbbs/config/link');
        return $row ? ['code' => 1, 'msg' => '删除成功', 'data' => '', 'url' => $url] : ['code' => 1, 'msg' => '删除失败', 'data' => '', 'url' => $url];
    }

}