2020-06-30 19:31:09 +08:00
|
|
|
<?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\service;
|
|
|
|
|
|
|
|
use think\Db;
|
|
|
|
use app\service\ResourcesService;
|
|
|
|
use app\service\UserService;
|
2020-08-19 23:38:47 +08:00
|
|
|
use app\service\GoodsService;
|
2020-06-30 19:31:09 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* 商品浏览服务层
|
|
|
|
* @author Devil
|
|
|
|
* @blog http://gong.gg/
|
|
|
|
* @version 1.0.0
|
|
|
|
* @date 2018-10-09
|
|
|
|
* @desc description
|
|
|
|
*/
|
|
|
|
class GoodsBrowseService
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* 商品浏览保存
|
|
|
|
* @author Devil
|
|
|
|
* @blog http://gong.gg/
|
|
|
|
* @version 1.0.0
|
|
|
|
* @date 2018-10-15
|
|
|
|
* @desc description
|
|
|
|
* @param [array] $params [输入参数]
|
|
|
|
*/
|
|
|
|
public static function GoodsBrowseSave($params = [])
|
|
|
|
{
|
|
|
|
// 请求参数
|
|
|
|
$p = [
|
|
|
|
[
|
|
|
|
'checked_type' => 'empty',
|
|
|
|
'key_name' => 'goods_id',
|
|
|
|
'error_msg' => '商品id有误',
|
|
|
|
],
|
|
|
|
[
|
|
|
|
'checked_type' => 'is_array',
|
|
|
|
'key_name' => 'user',
|
|
|
|
'error_msg' => '用户信息有误',
|
|
|
|
],
|
|
|
|
];
|
|
|
|
$ret = ParamsChecked($params, $p);
|
|
|
|
if($ret !== true)
|
|
|
|
{
|
|
|
|
return DataReturn($ret, -1);
|
|
|
|
}
|
|
|
|
|
|
|
|
$where = ['goods_id'=>intval($params['goods_id']), 'user_id'=>$params['user']['id']];
|
|
|
|
$temp = Db::name('GoodsBrowse')->where($where)->find();
|
|
|
|
|
|
|
|
$data = [
|
|
|
|
'goods_id' => intval($params['goods_id']),
|
|
|
|
'user_id' => $params['user']['id'],
|
|
|
|
];
|
|
|
|
if(empty($temp))
|
|
|
|
{
|
|
|
|
$data['add_time'] = time();
|
|
|
|
$status = Db::name('GoodsBrowse')->insertGetId($data) > 0;
|
|
|
|
} else {
|
|
|
|
$data['upd_time'] = time();
|
|
|
|
$status = Db::name('GoodsBrowse')->where($where)->update($data) !== false;
|
|
|
|
}
|
|
|
|
if($status)
|
|
|
|
{
|
|
|
|
return DataReturn('添加成功', 0);
|
|
|
|
}
|
|
|
|
return DataReturn('添加失败', -100);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 前端商品浏览列表条件
|
|
|
|
* @author Devil
|
|
|
|
* @blog http://gong.gg/
|
|
|
|
* @version 1.0.0
|
|
|
|
* @date 2018-09-29
|
|
|
|
* @desc description
|
|
|
|
* @param [array] $params [输入参数]
|
|
|
|
*/
|
|
|
|
public static function UserGoodsBrowseListWhere($params = [])
|
|
|
|
{
|
|
|
|
$where = [
|
|
|
|
['g.is_delete_time', '=', 0]
|
|
|
|
];
|
|
|
|
|
|
|
|
// 用户id
|
|
|
|
if(!empty($params['user']))
|
|
|
|
{
|
|
|
|
$where[] = ['b.user_id', '=', $params['user']['id']];
|
|
|
|
}
|
|
|
|
|
|
|
|
if(!empty($params['keywords']))
|
|
|
|
{
|
|
|
|
$where[] = ['g.title|g.model|g.simple_desc|g.seo_title|g.seo_keywords|g.seo_keywords', 'like', '%'.$params['keywords'].'%'];
|
|
|
|
}
|
|
|
|
|
|
|
|
return $where;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 商品浏览总数
|
|
|
|
* @author Devil
|
|
|
|
* @blog http://gong.gg/
|
|
|
|
* @version 1.0.0
|
|
|
|
* @date 2018-09-29
|
|
|
|
* @desc description
|
|
|
|
* @param [array] $where [条件]
|
|
|
|
*/
|
|
|
|
public static function GoodsBrowseTotal($where = [])
|
|
|
|
{
|
|
|
|
return (int) Db::name('GoodsBrowse')->alias('b')->join(['__GOODS__'=>'g'], 'g.id=b.goods_id')->where($where)->count();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 商品浏览列表
|
|
|
|
* @author Devil
|
|
|
|
* @blog http://gong.gg/
|
|
|
|
* @version 1.0.0
|
|
|
|
* @date 2018-09-29
|
|
|
|
* @desc description
|
|
|
|
* @param [array] $params [输入参数]
|
|
|
|
*/
|
|
|
|
public static function GoodsBrowseList($params = [])
|
|
|
|
{
|
|
|
|
$where = empty($params['where']) ? [] : $params['where'];
|
|
|
|
$m = isset($params['m']) ? intval($params['m']) : 0;
|
|
|
|
$n = isset($params['n']) ? intval($params['n']) : 10;
|
|
|
|
$order_by = empty($params['order_by']) ? 'b.id desc' : $params['order_by'];
|
|
|
|
$field = 'b.*, g.title, g.original_price, g.price, g.min_price, g.images';
|
|
|
|
|
|
|
|
// 获取数据
|
|
|
|
$data = Db::name('GoodsBrowse')->alias('b')->join(['__GOODS__'=>'g'], 'g.id=b.goods_id')->field($field)->where($where)->limit($m, $n)->order($order_by)->select();
|
|
|
|
if(!empty($data))
|
|
|
|
{
|
|
|
|
foreach($data as &$v)
|
|
|
|
{
|
|
|
|
// 用户信息
|
|
|
|
if(isset($v['user_id']))
|
|
|
|
{
|
|
|
|
if(isset($params['is_public']) && $params['is_public'] == 0)
|
|
|
|
{
|
|
|
|
$v['user'] = UserService::GetUserViewInfo($v['user_id']);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-08-19 23:38:47 +08:00
|
|
|
// 无封面图片
|
|
|
|
if(empty($v['images']))
|
|
|
|
{
|
|
|
|
$v['images'] = ResourcesService::AttachmentPathHandle(GoodsService::GoodsImagesCoverHandle($v['goods_id']));
|
|
|
|
}
|
|
|
|
|
2020-06-30 19:31:09 +08:00
|
|
|
// 商品信息
|
|
|
|
$v['images_old'] = $v['images'];
|
|
|
|
$v['images'] = ResourcesService::AttachmentPathViewHandle($v['images']);
|
|
|
|
$v['goods_url'] = MyUrl('index/goods/index', ['id'=>$v['goods_id']]);
|
|
|
|
|
|
|
|
// 时间
|
|
|
|
$v['add_time_time'] = date('Y-m-d H:i:s', $v['add_time']);
|
|
|
|
$v['add_time_date'] = date('Y-m-d', $v['add_time']);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return DataReturn('处理成功', 0, $data);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 商品浏览删除
|
|
|
|
* @author Devil
|
|
|
|
* @blog http://gong.gg/
|
|
|
|
* @version 1.0.0
|
|
|
|
* @date 2018-09-14
|
|
|
|
* @desc description
|
|
|
|
* @param [array] $params [输入参数]
|
|
|
|
*/
|
|
|
|
public static function GoodsBrowseDelete($params = [])
|
|
|
|
{
|
|
|
|
// 请求参数
|
|
|
|
$p = [
|
|
|
|
[
|
|
|
|
'checked_type' => 'empty',
|
|
|
|
'key_name' => 'ids',
|
|
|
|
'error_msg' => '操作id有误',
|
|
|
|
],
|
|
|
|
];
|
|
|
|
$ret = ParamsChecked($params, $p);
|
|
|
|
if($ret !== true)
|
|
|
|
{
|
|
|
|
return DataReturn($ret, -1);
|
|
|
|
}
|
|
|
|
|
|
|
|
// 是否数组
|
|
|
|
if(!is_array($params['ids']))
|
|
|
|
{
|
|
|
|
$params['ids'] = explode(',', $params['ids']);
|
|
|
|
}
|
|
|
|
|
|
|
|
// 条件
|
|
|
|
$where = ['id' => $params['ids']];
|
|
|
|
|
|
|
|
// 用户id
|
|
|
|
if(!empty($params['user']))
|
|
|
|
{
|
|
|
|
$where['user_id'] = $params['user']['id'];
|
|
|
|
}
|
|
|
|
|
|
|
|
// 删除
|
|
|
|
if(Db::name('GoodsBrowse')->where($where)->delete())
|
|
|
|
{
|
|
|
|
return DataReturn('删除成功', 0);
|
|
|
|
}
|
|
|
|
return DataReturn('删除失败', -100);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
?>
|