Pets.php 8.4 KB
Newer Older
G
gongfuxiang 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
<?php
// +----------------------------------------------------------------------
// | ShopXO 国内领先企业级B2C免费开源电商系统
// +----------------------------------------------------------------------
// | Copyright (c) 2011~2019 http://shopxo.net All rights reserved.
// +----------------------------------------------------------------------
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
// +----------------------------------------------------------------------
// | Author: Devil
// +----------------------------------------------------------------------
namespace app\plugins\petscms;

use think\Controller;
use app\plugins\petscms\Service;
use app\service\PluginsService;
G
gongfuxiang 已提交
16
use app\service\UserService;
G
gongfuxiang 已提交
17 18 19 20 21 22 23 24 25 26

/**
 * 宠物管理系统 - 用户宠物管理
 * @author   Devil
 * @blog     http://gong.gg/
 * @version  0.0.1
 * @datetime 2016-12-01T21:51:08+0800
 */
class Pets extends Controller
{
G
gongfuxiang 已提交
27 28
    private $user;

G
gongfuxiang 已提交
29
    /**
D
devil_gong 已提交
30 31 32 33 34 35 36 37 38 39
     * 构造方法
     * @author   Devil
     * @blog    http://gong.gg/
     * @version 1.0.0
     * @date    2019-03-15
     * @desc    description
     */
    public function __construct()
    {
        parent::__construct();
G
gongfuxiang 已提交
40 41

        $this->user = UserService::LoginUserInfo();
D
devil_gong 已提交
42 43 44 45
    }

    /**
     * 我的宠物
G
gongfuxiang 已提交
46 47 48 49 50 51 52 53
     * @author   Devil
     * @blog     http://gong.gg/
     * @version  1.0.0
     * @datetime 2019-03-15T23:51:50+0800
     * @param   [array]          $params [输入参数]
     */
    public function index($params = [])
    {
G
gongfuxiang 已提交
54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83
        // 参数
        $params['user'] = $this->user;

        // 分页
        $number = 10;

        // 条件
        $where = Service::PetsListWhere($params);

        // 获取总数
        $total = Service::PetsTotal($where);

        // 分页
        $page_params = array(
                'number'    =>  $number,
                'total'     =>  $total,
                'where'     =>  $params,
                'page'      =>  isset($params['page']) ? intval($params['page']) : 1,
                'url'       =>  PluginsHomeUrl('petscms', 'pets', 'index'),
            );
        $page = new \base\Page($page_params);
        $this->assign('page_html', $page->GetPageHtml());

        // 获取列表
        $data_params = array(
            'm'         => $page->GetPageStarNumber(),
            'n'         => $number,
            'where'     => $where,
        );
        $data = Service::PetsList($data_params);
D
应用  
devil_gong 已提交
84 85
        unset($params['user']);
        $this->assign('params', $params);
G
gongfuxiang 已提交
86
        $this->assign('data_list', $data['data']);
D
应用  
devil_gong 已提交
87
        $this->assign('pets_attribute_status_list', Service::$pets_attribute_status_list);
D
devil_gong 已提交
88 89 90
        $this->assign('pets_attribute_is_text_list', Service::$pets_attribute_is_text_list);
        $this->assign('pets_attribute_gender_list', Service::$pets_attribute_gender_list);
        $this->assign('pets_attribute_type_list', Service::$pets_attribute_type_list);
G
gongfuxiang 已提交
91 92
        return $this->fetch('../../../plugins/view/petscms/pets/index');
    }
D
devil_gong 已提交
93 94 95 96 97 98 99 100 101 102 103

    /**
     * 宠物添加/编辑页面
     * @author   Devil
     * @blog     http://gong.gg/
     * @version  1.0.0
     * @datetime 2019-03-15T23:51:50+0800
     * @param   [array]          $params [输入参数]
     */
    public function saveinfo($params = [])
    {
D
应用  
devil_gong 已提交
104 105 106 107 108 109 110 111 112 113
        // 获取数据
        $data = [];
        if(!empty($params['id']))
        {
            $data_params = array(
                'm'         => 0,
                'n'         => 1,
                'where'     => ['id' => intval($params['id'])],
            );
            $ret = Service::PetsList($data_params);
D
devil_gong 已提交
114 115 116 117 118
            if(!empty($ret['data'][0]))
            {
                $ret['data'][0]['lose_features'] = str_replace('<br />', "\n", $ret['data'][0]['lose_features']);
                $data = $ret['data'][0];
            }
D
应用  
devil_gong 已提交
119 120 121 122 123
            unset($params['id']);
        }
        $this->assign('data', $data);
        $this->assign('params', $params);
        $this->assign('pets_attribute_status_list', Service::$pets_attribute_status_list);
D
devil_gong 已提交
124 125 126 127 128 129
        $this->assign('pets_attribute_is_text_list', Service::$pets_attribute_is_text_list);
        $this->assign('pets_attribute_gender_list', Service::$pets_attribute_gender_list);
        $this->assign('pets_attribute_type_list', Service::$pets_attribute_type_list);
        return $this->fetch('../../../plugins/view/petscms/pets/saveinfo');
    }

G
gongfuxiang 已提交
130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148
    /**
     * 宠物详情
     * @author   Devil
     * @blog     http://gong.gg/
     * @version  1.0.0
     * @datetime 2019-03-15T23:51:50+0800
     * @param   [array]          $params [输入参数]
     */
    public function detail($params = [])
    {
        // 获取数据
        $data = [];
        if(empty($params['id']))
        {
            return '宠物id有误';
        }
        $data_params = array(
            'm'         => 0,
            'n'         => 1,
D
devil_gong 已提交
149
            'where'     => ['id' => intval($params['id']), 'status'=>[0,1,2]],
G
gongfuxiang 已提交
150 151 152 153 154 155 156 157 158
        );
        $ret = Service::PetsList($data_params);
        $data = empty($ret['data'][0]) ? [] : $ret['data'][0];

        $this->assign('data', $data);
        $this->assign('params', $params);
        return $this->fetch('../../../plugins/view/petscms/pets/detail');
    }

D
devil_gong 已提交
159 160 161 162 163 164 165 166 167 168
    /**
     * 宠物添加/编辑
     * @author   Devil
     * @blog     http://gong.gg/
     * @version  1.0.0
     * @datetime 2019-03-15T23:51:50+0800
     * @param   [array]          $params [输入参数]
     */
    public function save($params = [])
    {
G
gongfuxiang 已提交
169 170 171 172 173 174 175
        // 是否ajax请求
        if(!IS_AJAX)
        {
            return $this->error('非法访问');
        }

        // 用户
D
应用  
devil_gong 已提交
176
        $params['user_id'] = $this->user['id'];
G
gongfuxiang 已提交
177
        return Service::PestSave($params);
D
devil_gong 已提交
178
    }
D
devil_gong 已提交
179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196

    /**
     * 丢失提供信息添加/编辑
     * @author   Devil
     * @blog     http://gong.gg/
     * @version  1.0.0
     * @datetime 2019-03-15T23:51:50+0800
     * @param   [array]          $params [输入参数]
     */
    public function helpsave($params = [])
    {
        // 是否ajax请求
        if(!IS_AJAX)
        {
            return $this->error('非法访问');
        }

        // 用户
D
应用  
devil_gong 已提交
197
        $params['user_id'] = $this->user['id'];
D
devil_gong 已提交
198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267
        return Service::HelpSave($params);
    }

    /**
     * 宠物帮助数据列表
     * @author   Devil
     * @blog     http://gong.gg/
     * @version  1.0.0
     * @datetime 2019-03-15T23:51:50+0800
     * @param   [array]          $params [输入参数]
     */
    public function help($params = [])
    {
        // 参数
        $params = input();
        if(empty($params['pets_id']))
        {
            $this->assign('msg', '参数有误');
            return $this->fetch('public/tips_error');
        }

        // 分页
        $number = 10;

        // 条件
        $where = [
            'user_id'   => $this->user['id'],
            'pets_id'   => intval($params['pets_id']),
        ];

        // 获取总数
        $total = Service::HelpTotal($where);

        // 分页
        $page_params = array(
                'number'    =>  $number,
                'total'     =>  $total,
                'where'     =>  $params,
                'page'      =>  isset($params['page']) ? intval($params['page']) : 1,
                'url'       =>  PluginsHomeUrl('petscms', 'pets', 'index'),
            );
        $page = new \base\Page($page_params);
        $this->assign('page_html', $page->GetPageHtml());

        // 获取列表
        $data_params = array(
            'm'         => $page->GetPageStarNumber(),
            'n'         => $number,
            'where'     => $where,
        );
        $data = Service::HelpList($data_params);
        $this->assign('data_list', $data['data']);
        return $this->fetch('../../../plugins/view/petscms/pets/help');
    }

    /**
     * 宠物帮助数据地图展示
     * @author   Devil
     * @blog     http://gong.gg/
     * @version  1.0.0
     * @datetime 2019-03-15T23:51:50+0800
     * @param   [array]          $params [输入参数]
     */
    public function helpmap($params = [])
    {
        // 隐藏头尾
        $this->assign('is_header', 0);
        $this->assign('is_footer', 0);

        // 参数
D
devil_gong 已提交
268 269 270 271 272 273 274 275 276 277
        $params = input();
        if(!empty($params['lng']))
        {
            $params['lng'] = base64_decode($params['lng']);
        }
        if(!empty($params['lat']))
        {
            $params['lat'] = base64_decode($params['lat']);
        }
        $this->assign('params', $params);
D
devil_gong 已提交
278 279
        return $this->fetch('../../../plugins/view/petscms/pets/helpmap');
    }
G
gongfuxiang 已提交
280 281
}
?>