shopxo/application/service/AppCenterNavService.php

294 lines
9.9 KiB
PHP
Raw Normal View History

2018-12-28 18:58:37 +08:00
<?php
// +----------------------------------------------------------------------
// | ShopXO 国内领先企业级B2C免费开源电商系统
// +----------------------------------------------------------------------
2019-02-18 13:52:07 +08:00
// | Copyright (c) 2011~2019 http://shopxo.net All rights reserved.
2018-12-28 18:58:37 +08:00
// +----------------------------------------------------------------------
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
// +----------------------------------------------------------------------
// | Author: Devil
// +----------------------------------------------------------------------
namespace app\service;
use think\Db;
use app\service\ResourcesService;
2018-12-28 18:58:37 +08:00
/**
2019-07-03 21:03:28 +08:00
* APP用户中心导航服务层
2018-12-28 18:58:37 +08:00
* @author Devil
* @blog http://gong.gg/
* @version 0.0.1
* @datetime 2016-12-01T21:51:08+0800
*/
2019-07-03 21:03:28 +08:00
class AppCenterNavService
2018-12-28 18:58:37 +08:00
{
/**
2019-07-03 21:03:28 +08:00
* 用户中心导航列表
2018-12-28 18:58:37 +08:00
* @author Devil
* @blog http://gong.gg/
* @version 0.0.1
* @datetime 2016-12-06T21:31:53+0800
* @param [array] $params [输入参数]
*/
2019-07-03 21:03:28 +08:00
public static function AppCenterNavList($params = [])
2018-12-28 18:58:37 +08:00
{
$where = empty($params['where']) ? [] : $params['where'];
$field = empty($params['field']) ? '*' : $params['field'];
$order_by = empty($params['order_by']) ? 'sort asc' : trim($params['order_by']);
$m = isset($params['m']) ? intval($params['m']) : 0;
$n = isset($params['n']) ? intval($params['n']) : 10;
// 获取品牌列表
2019-07-03 21:03:28 +08:00
$data = Db::name('AppCenterNav')->where($where)->order($order_by)->limit($m, $n)->select();
2018-12-28 18:58:37 +08:00
if(!empty($data))
{
$common_platform_type = lang('common_platform_type');
$common_app_event_type = lang('common_app_event_type');
foreach($data as &$v)
{
// 平台类型
if(isset($v['platform']))
{
$v['platform_text'] = $common_platform_type[$v['platform']]['name'];
}
// 事件类型
if(isset($v['event_type']) && $v['event_type'] != -1)
{
$v['event_type_text'] = $common_app_event_type[$v['event_type']]['name'];
}
// 图片地址
if(isset($v['images_url']))
{
$v['images_url_old'] = $v['images_url'];
$v['images_url'] = ResourcesService::AttachmentPathViewHandle($v['images_url']);
2018-12-28 18:58:37 +08:00
}
// 时间
if(isset($v['add_time']))
{
2020-06-20 22:04:28 +08:00
$v['add_time'] = date('Y-m-d H:i:s', $v['add_time']);
2018-12-28 18:58:37 +08:00
}
if(isset($v['upd_time']))
{
2020-06-20 22:04:28 +08:00
$v['upd_time'] = empty($v['upd_time']) ? '' : date('Y-m-d H:i:s', $v['upd_time']);
2018-12-28 18:58:37 +08:00
}
}
}
return DataReturn('处理成功', 0, $data);
}
/**
2019-07-03 21:03:28 +08:00
* 用户中心导航总数
2018-12-28 18:58:37 +08:00
* @author Devil
* @blog http://gong.gg/
* @version 0.0.1
* @datetime 2016-12-10T22:16:29+0800
* @param [array] $where [条件]
*/
2019-07-03 21:03:28 +08:00
public static function AppCenterNavTotal($where)
2018-12-28 18:58:37 +08:00
{
2019-07-03 21:03:28 +08:00
return (int) Db::name('AppCenterNav')->where($where)->count();
2018-12-28 18:58:37 +08:00
}
/**
2019-07-03 21:03:28 +08:00
* 用户中心导航数据保存
2018-12-28 18:58:37 +08:00
* @author Devil
* @blog http://gong.gg/
* @version 1.0.0
* @date 2018-12-19
* @desc description
* @param [array] $params [输入参数]
*/
2019-07-03 21:03:28 +08:00
public static function AppCenterNavSave($params = [])
2018-12-28 18:58:37 +08:00
{
// 请求类型
$p = [
[
'checked_type' => 'length',
'key_name' => 'name',
'checked_data' => '2,60',
'error_msg' => '名称长度 2~60 个字符',
],
[
'checked_type' => 'in',
'key_name' => 'platform',
'checked_data' => array_column(lang('common_platform_type'), 'value'),
'error_msg' => '平台类型有误',
],
[
'checked_type' => 'in',
'key_name' => 'event_type',
'checked_data' => array_column(lang('common_app_event_type'), 'value'),
'is_checked' => 2,
'error_msg' => '事件值类型有误',
],
[
'checked_type' => 'length',
'key_name' => 'event_value',
'checked_data' => '255',
'error_msg' => '事件值最多 255 个字符',
],
[
'checked_type' => 'empty',
'key_name' => 'images_url',
'checked_data' => '255',
'error_msg' => '请上传图片',
],
2019-07-03 21:03:28 +08:00
[
'checked_type' => 'length',
'key_name' => 'desc',
'checked_data' => '18',
'error_msg' => '描述最多 18 个字符',
],
2018-12-28 18:58:37 +08:00
[
'checked_type' => 'length',
'key_name' => 'sort',
'checked_data' => '3',
'error_msg' => '顺序 0~255 之间的数值',
],
];
$ret = ParamsChecked($params, $p);
if($ret !== true)
{
return DataReturn($ret, -1);
}
// 附件
$data_fields = ['images_url'];
$attachment = ResourcesService::AttachmentParams($params, $data_fields);
// 数据
$data = [
'name' => $params['name'],
'platform' => $params['platform'],
'event_type' => isset($params['event_type']) ? intval($params['event_type']) : -1,
'event_value' => $params['event_value'],
'images_url' => $attachment['data']['images_url'],
2019-07-03 21:03:28 +08:00
'desc' => empty($params['desc']) ? '' : $params['desc'],
2018-12-28 18:58:37 +08:00
'sort' => intval($params['sort']),
'is_enable' => isset($params['is_enable']) ? intval($params['is_enable']) : 0,
];
if(empty($params['id']))
{
$data['add_time'] = time();
2019-07-03 21:03:28 +08:00
if(Db::name('AppCenterNav')->insertGetId($data) > 0)
2018-12-28 18:58:37 +08:00
{
return DataReturn('添加成功', 0);
}
return DataReturn('添加失败', -100);
} else {
$data['upd_time'] = time();
2019-07-03 21:03:28 +08:00
if(Db::name('AppCenterNav')->where(['id'=>intval($params['id'])])->update($data))
2018-12-28 18:58:37 +08:00
{
return DataReturn('编辑成功', 0);
}
return DataReturn('编辑失败', -100);
}
}
/**
2019-07-03 21:03:28 +08:00
* 用户中心导航删除
2018-12-28 18:58:37 +08:00
* @author Devil
* @blog http://gong.gg/
* @version 1.0.0
* @date 2018-12-18
* @desc description
* @param [array] $params [输入参数]
*/
2019-07-03 21:03:28 +08:00
public static function AppCenterNavDelete($params = [])
2018-12-28 18:58:37 +08:00
{
2020-06-20 22:04:28 +08:00
// 参数是否有误
if(empty($params['ids']))
2018-12-28 18:58:37 +08:00
{
2020-06-20 22:04:28 +08:00
return DataReturn('操作id有误', -1);
}
// 是否数组
if(!is_array($params['ids']))
{
$params['ids'] = explode(',', $params['ids']);
2018-12-28 18:58:37 +08:00
}
// 删除操作
2020-06-20 22:04:28 +08:00
if(Db::name('AppCenterNav')->where(['id'=>$params['ids']])->delete())
2018-12-28 18:58:37 +08:00
{
return DataReturn('删除成功');
}
2020-06-20 22:04:28 +08:00
return DataReturn('删除失败', -100);
2018-12-28 18:58:37 +08:00
}
/**
2019-07-03 21:03:28 +08:00
* 用户中心导航状态更新
2018-12-28 18:58:37 +08:00
* @author Devil
* @blog http://gong.gg/
* @version 0.0.1
* @datetime 2016-12-06T21:31:53+0800
* @param [array] $params [输入参数]
*/
2019-07-03 21:03:28 +08:00
public static function AppCenterNavStatusUpdate($params = [])
2018-12-28 18:58:37 +08:00
{
// 请求参数
$p = [
[
'checked_type' => 'empty',
'key_name' => 'id',
'error_msg' => '操作id有误',
],
2019-04-22 14:41:20 +08:00
[
'checked_type' => 'empty',
'key_name' => 'field',
'error_msg' => '操作字段有误',
],
2018-12-28 18:58:37 +08:00
[
'checked_type' => 'in',
'key_name' => 'state',
'checked_data' => [0,1],
'error_msg' => '状态有误',
],
];
$ret = ParamsChecked($params, $p);
if($ret !== true)
{
return DataReturn($ret, -1);
}
// 数据更新
2020-06-20 22:04:28 +08:00
if(Db::name('AppCenterNav')->where(['id'=>intval($params['id'])])->update([$params['field']=>intval($params['state']), 'upd_time'=>time()]))
2018-12-28 18:58:37 +08:00
{
2020-06-20 22:04:28 +08:00
return DataReturn('操作成功');
2018-12-28 18:58:37 +08:00
}
2020-06-20 22:04:28 +08:00
return DataReturn('操作失败', -100);
2018-12-28 18:58:37 +08:00
}
/**
2019-07-03 21:03:28 +08:00
* APP获取用户中心导航
2018-12-28 18:58:37 +08:00
* @author Devil
* @blog http://gong.gg/
* @version 1.0.0
* @date 2018-11-19
* @desc description
* @param array $params [description]
*/
2019-07-03 21:03:28 +08:00
public static function AppCenterNav($params = [])
2018-12-28 18:58:37 +08:00
{
2019-04-22 14:41:20 +08:00
$client_type = (APPLICATION_CLIENT_TYPE == 'pc') ? (IsMobile() ? 'h5' : 'pc') : APPLICATION_CLIENT_TYPE;
2020-06-20 22:04:28 +08:00
$field = 'id,name,images_url,event_value,event_type,desc';
$order_by = 'sort asc,id desc';
$data = Db::name('AppCenterNav')->field($field)->where(['platform'=>$client_type, 'is_enable'=>1])->order($order_by)->select();
2018-12-28 18:58:37 +08:00
if(!empty($data))
{
foreach($data as &$v)
{
$v['images_url_old'] = $v['images_url'];
$v['images_url'] = ResourcesService::AttachmentPathViewHandle($v['images_url']);
2018-12-28 18:58:37 +08:00
$v['event_value'] = empty($v['event_value']) ? null : $v['event_value'];
}
}
return $data;
}
}
?>