其余文件
This commit is contained in:
111
app/admin/logic/goods/BrandLogic.php
Normal file
111
app/admin/logic/goods/BrandLogic.php
Normal file
@ -0,0 +1,111 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | likeshop开源商城系统
|
||||
// +----------------------------------------------------------------------
|
||||
// | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
|
||||
// | gitee下载:https://gitee.com/likeshop_gitee
|
||||
// | github下载:https://github.com/likeshop-github
|
||||
// | 访问官网:https://www.likeshop.cn
|
||||
// | 访问社区:https://home.likeshop.cn
|
||||
// | 访问手册:http://doc.likeshop.cn
|
||||
// | 微信公众号:likeshop技术社区
|
||||
// | likeshop系列产品在gitee、github等公开渠道开源版本可免费商用,未经许可不能去除前后端官方版权标识
|
||||
// | likeshop系列产品收费版本务必购买商业授权,购买去版权授权后,方可去除前后端官方版权标识
|
||||
// | 禁止对系统程序代码以任何目的,任何形式的再发布
|
||||
// | likeshop团队版权所有并拥有最终解释权
|
||||
// +----------------------------------------------------------------------
|
||||
// | author: likeshop.cn.team
|
||||
// +----------------------------------------------------------------------
|
||||
|
||||
|
||||
namespace app\admin\logic\goods;
|
||||
|
||||
|
||||
use app\common\basics\Logic;
|
||||
use app\common\model\goods\GoodsBrand;
|
||||
|
||||
|
||||
/**
|
||||
* 商品品牌
|
||||
* Class GoodsBrandLogic
|
||||
* @package app\admin\logic
|
||||
*/
|
||||
class BrandLogic extends Logic
|
||||
{
|
||||
|
||||
/**
|
||||
* Notes: 列表
|
||||
* @param $get
|
||||
* @author 段誉(2021/4/15 10:53)
|
||||
* @return array
|
||||
* @throws \think\db\exception\DataNotFoundException
|
||||
* @throws \think\db\exception\DbException
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
*/
|
||||
public static function lists($get)
|
||||
{
|
||||
$where[] = ['del', '=', 0];
|
||||
if(isset($get['name']) && $get['name']) {
|
||||
$where[] = ['name','like','%'.$get['name'].'%'];
|
||||
}
|
||||
|
||||
$lists = GoodsBrand::where($where)
|
||||
->order('sort')
|
||||
->paginate([
|
||||
'list_rows'=> $get['limit'],
|
||||
'page'=> $get['page'],
|
||||
]);
|
||||
return ['count' => $lists->total(), 'lists' => $lists->getCollection()];
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Notes: 添加
|
||||
* @param $post
|
||||
* @return GoodsBrand|\think\Model
|
||||
*@author 段誉(2021/4/15 10:54)
|
||||
*/
|
||||
public static function add($post)
|
||||
{
|
||||
return GoodsBrand::create([
|
||||
'name' => $post['name'],
|
||||
'initial' => $post['initial'],
|
||||
'image' => $post['image'] ?? '',
|
||||
'sort' => $post['sort'] ?? 100,
|
||||
'is_show' => $post['is_show'],
|
||||
'remark' => $post['remark'] ?? '',
|
||||
]);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Notes: 编辑
|
||||
* @param $post
|
||||
* @return GoodsBrand
|
||||
*@author 段誉(2021/4/15 10:54)
|
||||
*/
|
||||
public static function edit($post)
|
||||
{
|
||||
return GoodsBrand::update([
|
||||
'name' => $post['name'],
|
||||
'initial' => $post['initial'],
|
||||
'image' => $post['image'] ?? '',
|
||||
'sort' => $post['sort'] ?? 100,
|
||||
'is_show' => $post['is_show'],
|
||||
'remark' => $post['remark'] ?? '',
|
||||
], ['id' => $post['id']]);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Notes: 删除
|
||||
* @param $id
|
||||
* @return GoodsBrand
|
||||
*@author 段誉(2021/4/15 10:54)
|
||||
*/
|
||||
public static function del($id)
|
||||
{
|
||||
return GoodsBrand::update(['del' => 1], ['id' => $id]);
|
||||
}
|
||||
|
||||
}
|
||||
229
app/admin/logic/goods/CategoryLogic.php
Normal file
229
app/admin/logic/goods/CategoryLogic.php
Normal file
@ -0,0 +1,229 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | likeshop开源商城系统
|
||||
// +----------------------------------------------------------------------
|
||||
// | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
|
||||
// | gitee下载:https://gitee.com/likeshop_gitee
|
||||
// | github下载:https://github.com/likeshop-github
|
||||
// | 访问官网:https://www.likeshop.cn
|
||||
// | 访问社区:https://home.likeshop.cn
|
||||
// | 访问手册:http://doc.likeshop.cn
|
||||
// | 微信公众号:likeshop技术社区
|
||||
// | likeshop系列产品在gitee、github等公开渠道开源版本可免费商用,未经许可不能去除前后端官方版权标识
|
||||
// | likeshop系列产品收费版本务必购买商业授权,购买去版权授权后,方可去除前后端官方版权标识
|
||||
// | 禁止对系统程序代码以任何目的,任何形式的再发布
|
||||
// | likeshop团队版权所有并拥有最终解释权
|
||||
// +----------------------------------------------------------------------
|
||||
// | author: likeshop.cn.team
|
||||
// +----------------------------------------------------------------------
|
||||
|
||||
namespace app\admin\logic\goods;
|
||||
|
||||
use app\common\model\goods\GoodsCategory as GoodsCategoryModel;
|
||||
use app\common\server\UrlServer;
|
||||
|
||||
/**
|
||||
* 平台商品分类 逻辑层
|
||||
* Class CategoryLogic
|
||||
* @package app\admin\logic\goods
|
||||
*/
|
||||
class CategoryLogic
|
||||
{
|
||||
/**
|
||||
* 获取分类列表(所有)
|
||||
*/
|
||||
public static function lists()
|
||||
{
|
||||
$lists = GoodsCategoryModel::field('id,name,pid,is_show,level,image, bg_image, sort')
|
||||
->where('del', 0)
|
||||
->order('sort', 'asc')
|
||||
->select()
|
||||
->toArray();
|
||||
|
||||
foreach ($lists as $k => $item){
|
||||
$lists[$k]['image'] = $lists[$k]['image'] ? UrlServer::getFileUrl($item['image']) : '';
|
||||
}
|
||||
// 线性结构转树形结构(顶级分类树)
|
||||
$lists = linear_to_tree($lists);
|
||||
return $lists;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取分类列表(二级)
|
||||
*/
|
||||
public static function categoryTwoTree()
|
||||
{
|
||||
$cateogry_list = GoodsCategoryModel::with('sons')
|
||||
->field('id,name,pid,level')
|
||||
->where(['del' => 0, 'level' => 1])
|
||||
->select()
|
||||
->toArray();
|
||||
|
||||
return self::categoryToSelect($cateogry_list);
|
||||
}
|
||||
|
||||
/**
|
||||
* Desc:将树形结构数组输出
|
||||
* @param $items array 要输出的数组
|
||||
* @param $select_id int 已选中项
|
||||
* @return string
|
||||
*/
|
||||
public static function categoryToSelect($lists, $select_id = 0)
|
||||
{
|
||||
$tree = [];
|
||||
foreach ($lists as $val) {
|
||||
$tree[$val['id']]['level'] = $val['level'];
|
||||
$tree[$val['id']]['name'] = '|----' . $val['name'];
|
||||
if ($val['sons']) {
|
||||
foreach ($val['sons'] as $val_sons) {
|
||||
$tree[$val_sons['id']]['level'] = $val_sons['level'];
|
||||
$tree[$val_sons['id']]['name'] = '|--------' . $val_sons['name'];
|
||||
}
|
||||
}
|
||||
}
|
||||
return $tree;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 添加分类
|
||||
*/
|
||||
public static function add($post)
|
||||
{
|
||||
$level = 0;
|
||||
if ($post['pid']) {
|
||||
$level = GoodsCategoryModel::where(['id' => $post['pid']], ['del' => 0])->value('level');
|
||||
}
|
||||
|
||||
$data = [
|
||||
'name' => trim($post['name']),
|
||||
'pid' => $post['pid'],
|
||||
'sort' => $post['sort'],
|
||||
'is_show' => $post['is_show'],
|
||||
'image' => isset($post['image']) ? clearDomain($post['image']) : '',
|
||||
'bg_image' => isset($post['bg_image']) ? clearDomain($post['bg_image']) : '',
|
||||
'level' => $level + 1,
|
||||
'remark' => $post['remark'],
|
||||
'create_time' => time(),
|
||||
'update_time' => time(),
|
||||
];
|
||||
return GoodsCategoryModel::create($data);
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除分类
|
||||
*/
|
||||
public static function del($post)
|
||||
{
|
||||
return GoodsCategoryModel::update([
|
||||
'id' => $post['id'],
|
||||
'del' => 1,
|
||||
'update_time' => time(),
|
||||
]);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 分类详情
|
||||
*/
|
||||
public static function getCategory($id)
|
||||
{
|
||||
$detail = GoodsCategoryModel::where([
|
||||
'del' => 0,
|
||||
'id' => $id
|
||||
])->find();
|
||||
$detail['image'] = UrlServer::getFileUrl($detail['image']);
|
||||
$detail['bg_image'] = $detail['bg_image'] ? UrlServer::getFileUrl($detail['bg_image']) : '';
|
||||
return $detail;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取叶子分类的级数
|
||||
*/
|
||||
public static function getCategoryLevel($category)
|
||||
{
|
||||
$level = 1;
|
||||
$two_ids = GoodsCategoryModel::where(['pid' => $category['id'], 'del' => 0])->column('id');
|
||||
if ($two_ids) {
|
||||
$level = 2;
|
||||
$three_id = GoodsCategoryModel::where([
|
||||
['pid', 'in', $two_ids],
|
||||
['del', '=', 0]
|
||||
])->column('id');
|
||||
if ($three_id) $level = 3;
|
||||
}
|
||||
return $level;
|
||||
}
|
||||
|
||||
/**
|
||||
* 编辑
|
||||
*/
|
||||
public static function edit($post)
|
||||
{
|
||||
$level = 0;
|
||||
if ($post['pid']) {
|
||||
$level = GoodsCategoryModel::where(['id' => $post['pid']], ['del' => 0])->value('level');
|
||||
}
|
||||
$data = [
|
||||
'name' => $post['name'],
|
||||
'sort' => $post['sort'],
|
||||
'is_show' => $post['is_show'],
|
||||
'image' => isset($post['image']) ? clearDomain($post['image']) : '',
|
||||
'bg_image' => isset($post['bg_image']) ? clearDomain($post['bg_image']) : '',
|
||||
'level' => $level+1,
|
||||
'pid' => $post['pid'],
|
||||
'remark' => $post['remark'],
|
||||
'update_time' => time(),
|
||||
];
|
||||
return GoodsCategoryModel::where(['id'=>$post['id']])->update($data);
|
||||
}
|
||||
|
||||
// 修改分类显示状态
|
||||
public static function switchStatus($post)
|
||||
{
|
||||
$update_data = [
|
||||
'is_show' => $post['status'],
|
||||
'update_time' => time(),
|
||||
];
|
||||
return GoodsCategoryModel::where(['del' =>0,'id' =>$post['id']])->update($update_data);
|
||||
}
|
||||
|
||||
/**
|
||||
* 平台商品分类(三级)
|
||||
*/
|
||||
public static function categoryTreeeTree()
|
||||
{
|
||||
$lists = GoodsCategoryModel::where(['del' => 0])->column('id,name,pid,level', 'id');
|
||||
return self::cateToTree($lists, 0, '|-----', 1);
|
||||
}
|
||||
|
||||
/**
|
||||
* 转树形结构
|
||||
*/
|
||||
public static function cateToTree($lists, $pid = 0, $html = '|-----', $level = 1, $clear = true)
|
||||
{
|
||||
static $tree = [];
|
||||
if ($clear) $tree = [];
|
||||
foreach ($lists as $k => $v) {
|
||||
if ($v['pid'] == $pid) {
|
||||
$v['html'] = str_repeat($html, $level);
|
||||
$tree[] = $v;
|
||||
unset($lists[$k]);
|
||||
self::cateToTree($lists, $v['id'], $html, $level + 1, false);
|
||||
}
|
||||
}
|
||||
return $tree;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取所有分类树形结构
|
||||
*/
|
||||
public static function getAllTree()
|
||||
{
|
||||
$lists = GoodsCategoryModel::field(['name', 'id', 'pid', 'level'])
|
||||
->where(['del' => 0])
|
||||
->order(['sort' => 'desc'])
|
||||
->select();
|
||||
return $lists;
|
||||
}
|
||||
}
|
||||
111
app/admin/logic/goods/ColumnLogic.php
Normal file
111
app/admin/logic/goods/ColumnLogic.php
Normal file
@ -0,0 +1,111 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | likeshop开源商城系统
|
||||
// +----------------------------------------------------------------------
|
||||
// | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
|
||||
// | gitee下载:https://gitee.com/likeshop_gitee
|
||||
// | github下载:https://github.com/likeshop-github
|
||||
// | 访问官网:https://www.likeshop.cn
|
||||
// | 访问社区:https://home.likeshop.cn
|
||||
// | 访问手册:http://doc.likeshop.cn
|
||||
// | 微信公众号:likeshop技术社区
|
||||
// | likeshop系列产品在gitee、github等公开渠道开源版本可免费商用,未经许可不能去除前后端官方版权标识
|
||||
// | likeshop系列产品收费版本务必购买商业授权,购买去版权授权后,方可去除前后端官方版权标识
|
||||
// | 禁止对系统程序代码以任何目的,任何形式的再发布
|
||||
// | likeshop团队版权所有并拥有最终解释权
|
||||
// +----------------------------------------------------------------------
|
||||
// | author: likeshop.cn.team
|
||||
// +----------------------------------------------------------------------
|
||||
|
||||
|
||||
namespace app\admin\logic\goods;
|
||||
|
||||
|
||||
use app\common\basics\Logic;
|
||||
use app\common\model\goods\Goods;
|
||||
use app\common\model\goods\GoodsColumn;
|
||||
|
||||
/**
|
||||
* 商品栏目-逻辑
|
||||
* Class GoodsColumnLogic
|
||||
* @package app\admin\logic
|
||||
*/
|
||||
class ColumnLogic extends Logic
|
||||
{
|
||||
|
||||
/**
|
||||
* Notes: 列表
|
||||
* @param $get
|
||||
* @author 段誉(2021/4/15 10:53)
|
||||
* @return array
|
||||
* @throws \think\db\exception\DataNotFoundException
|
||||
* @throws \think\db\exception\DbException
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
*/
|
||||
public static function lists($get)
|
||||
{
|
||||
$result = GoodsColumn::where(['del' =>0])
|
||||
->order('sort')
|
||||
->paginate([
|
||||
'list_rows'=> $get['limit'],
|
||||
'page'=> $get['page']
|
||||
]);
|
||||
|
||||
return ['count' => $result->total(), 'lists' => $result->getCollection()];
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Notes: 添加
|
||||
* @param $post
|
||||
* @return GoodsColumn|\think\Model
|
||||
*@author 段誉(2021/4/15 10:54)
|
||||
*/
|
||||
public static function add($post)
|
||||
{
|
||||
return GoodsColumn::create([
|
||||
'name' => $post['name'],
|
||||
'remark' => $post['remark'] ?? '',
|
||||
'status' => isset($post['status']) && $post['status'] == 'on' ? 1 : 0,
|
||||
]);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Notes: 编辑
|
||||
* @param $post
|
||||
* @return GoodsColumn
|
||||
*@author 段誉(2021/4/15 10:54)
|
||||
*/
|
||||
public static function edit($post)
|
||||
{
|
||||
return GoodsColumn::update([
|
||||
'name' => $post['name'],
|
||||
'remark' => $post['remark'] ?? '',
|
||||
'status' => isset($post['status']) && $post['status'] == 'on' ? 1 : 0,
|
||||
], ['id' => $post['id']]);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Notes: 删除
|
||||
* @param $id
|
||||
* @author 段誉(2021/6/24 2:51)
|
||||
* @return bool
|
||||
*/
|
||||
public static function del($id)
|
||||
{
|
||||
//栏目删除,则栏目商品都删除
|
||||
GoodsColumn::update(['del' => 1], ['id' => $id]);
|
||||
Goods::whereFindInSet('column_ids', $id)->update(['column_ids' => '']);
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* 列表(不分页)
|
||||
*/
|
||||
public static function getList()
|
||||
{
|
||||
return GoodsColumn::where(['del' => 0])->order('sort', 'desc')->column('id,name');
|
||||
}
|
||||
}
|
||||
163
app/admin/logic/goods/CommentLogic.php
Normal file
163
app/admin/logic/goods/CommentLogic.php
Normal file
@ -0,0 +1,163 @@
|
||||
<?php
|
||||
namespace app\admin\logic\goods;
|
||||
|
||||
use app\common\basics\Logic;
|
||||
use app\common\model\goods\GoodsComment;
|
||||
use app\common\model\user\UserLevel;
|
||||
use app\common\server\UrlServer;
|
||||
|
||||
class CommentLogic extends Logic
|
||||
{
|
||||
public static function lists($get)
|
||||
{
|
||||
$where = [
|
||||
['gc.del', '=', 0],
|
||||
];
|
||||
|
||||
if($get['type'] == 0) { // 待回复
|
||||
$where[] = ['reply', '=', ''];
|
||||
}else{ // 已回复
|
||||
$where[] = ['reply', '<>', ''];
|
||||
}
|
||||
|
||||
// 商家名称
|
||||
if(isset($get['shop_name']) && !empty($get['shop_name'])) {
|
||||
$where[] = ['s.name', 'like', '%'. trim($get['shop_name']) . '%'];
|
||||
}
|
||||
|
||||
// 评价信息
|
||||
if(isset($get['search_word']) && !empty($get['search_word'])) {
|
||||
switch($get['search_type']) {
|
||||
case 'name':
|
||||
$where[] = ['g.name', 'like', '%'. trim($get['search_word']) . '%'];
|
||||
break;
|
||||
case 'sn':
|
||||
$where[] = ['u.sn', '=', trim($get['search_word'])];
|
||||
break;
|
||||
case 'nickname':
|
||||
$where[] = ['u.nickname', '=', trim($get['search_word'])];
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// 评价等级
|
||||
if(isset($get['goods_comment']) && !empty($get['goods_comment'])) {
|
||||
switch ($get['goods_comment']) {
|
||||
case 1:
|
||||
$where[] = ['gc.goods_comment', '>', 3];
|
||||
break;
|
||||
case 2:
|
||||
$where[] = ['gc.goods_comment', '=', 3];
|
||||
break;
|
||||
case 3:
|
||||
$where[] = ['gc.goods_comment', '<', 3];
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// 显示状态
|
||||
if(isset($get['status']) && !empty($get['status'])) {
|
||||
switch ($get['status']) {
|
||||
case 1:
|
||||
$where[] = ['gc.status', '=', 1];
|
||||
break;
|
||||
case 2: // 隐藏状态 前端不使用0的原因:empty()时0会被认为false
|
||||
$where[] = ['gc.status', '=', 0];
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// 日期范围
|
||||
if(isset($get['start_end']) && !empty($get['start_end'])) {
|
||||
$arr = explode('~', $get['start_end']);
|
||||
$start_time = strtotime($arr[0]);
|
||||
$end_time = strtotime($arr[1]);
|
||||
$where[] = ['gc.create_time', '>=', $start_time];
|
||||
$where[] = ['gc.create_time', '<=', $end_time];
|
||||
}
|
||||
|
||||
$lists = GoodsComment::alias('gc')
|
||||
->with(['goods_comment_image'])
|
||||
->field('gc.id,gc.goods_comment,gc.goods_comment as goods_comment_desc,gc.comment,gc.reply,gc.status,gc.status as status_desc,gc.create_time,u.sn,u.nickname,u.avatar,u.level,g.name as goods_name,g.image as goods_image,gi.image as item_image,gi.spec_value_str,s.id as shop_id,s.name as shop_name,s.type as shop_type,s.logo as shop_logo')
|
||||
->leftJoin('user u', 'u.id=gc.user_id')
|
||||
->leftJoin('goods g', 'g.id=gc.goods_id')
|
||||
->leftJoin('goods_item gi', 'gi.id=gc.item_id')
|
||||
->leftJoin('shop s', 's.id=gc.shop_id')
|
||||
->where($where)
|
||||
->order('gc.create_time', 'desc')
|
||||
->page($get['page'], $get['limit'])
|
||||
->select()
|
||||
->toArray();
|
||||
|
||||
$count = GoodsComment::alias('gc')
|
||||
->field('gc.id,gc.goods_comment,gc.goods_comment as goods_comment_desc,gc.comment,gc.reply,gc.status,gc.status as status_desc,gc.create_time,u.sn,u.nickname,u.avatar,u.level,g.name as goods_name,g.image as goods_image,gi.image as item_image,gi.spec_value_str')
|
||||
->leftJoin('user u', 'u.id=gc.user_id')
|
||||
->leftJoin('goods g', 'g.id=gc.goods_id')
|
||||
->leftJoin('goods_item gi', 'gi.id=gc.item_id')
|
||||
->leftJoin('shop s', 's.id=gc.shop_id')
|
||||
->where($where)
|
||||
->count();
|
||||
|
||||
$levelArr = UserLevel::where('del', 0)->column('name', 'id');
|
||||
$shopTypeArr = [1=>'官方自营', 2=>'入驻商家'];
|
||||
foreach($lists as &$item) {
|
||||
// 头像
|
||||
$item['type'] = $get['type'];
|
||||
// 头像
|
||||
$item['avatar'] = UrlServer::getFileUrl($item['avatar']);
|
||||
// 商家图标
|
||||
$item['shop_logo'] = empty($item['shop_logo']) ? '' : UrlServer::getFileUrl($item['shop_logo']);
|
||||
$item['goods_image'] = empty($item['goods_image']) ? '' : UrlServer::getFileUrl($item['goods_image']);
|
||||
$item['item_image'] = empty($item['item_image']) ? '' : UrlServer::getFileUrl($item['item_image']);
|
||||
|
||||
// 会员等级
|
||||
$item['levelName'] = $levelArr[$item['level']] ?? '无等级';
|
||||
// 评价图片
|
||||
$item['comment_image'] = array_column($item['goods_comment_image'], 'uri');
|
||||
foreach($item['comment_image'] as $key => $subItem) {
|
||||
$item['comment_image'][$key] = UrlServer::getFileUrl($subItem);
|
||||
}
|
||||
// 商家类型
|
||||
$item['shop_type_desc'] = $shopTypeArr[$item['shop_type']];
|
||||
}
|
||||
|
||||
return [
|
||||
'count' => $count,
|
||||
'lists' => $lists
|
||||
];
|
||||
}
|
||||
|
||||
public static function changeStatus($post)
|
||||
{
|
||||
try{
|
||||
$goodsComment = GoodsComment::where('id', $post['id'])->findOrEmpty();
|
||||
if($goodsComment->isEmpty()) {
|
||||
throw new \think\Exception('评论不存在');
|
||||
}
|
||||
$goodsComment->status = $goodsComment->status ? 0 : 1;
|
||||
$goodsComment->update_time = time();
|
||||
$goodsComment->save();
|
||||
return true;
|
||||
}catch(\Exception $e) {
|
||||
self::$error = $e->getMessage();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public static function del($post)
|
||||
{
|
||||
try{
|
||||
$goodsComment = GoodsComment::where('id', $post['id'])->findOrEmpty();
|
||||
if($goodsComment->isEmpty()) {
|
||||
throw new \think\Exception('评论不存在');
|
||||
}
|
||||
$goodsComment->del = 1;
|
||||
$goodsComment->update_time = time();
|
||||
$goodsComment->save();
|
||||
return true;
|
||||
}catch(\Exception $e) {
|
||||
self::$error = $e->getMessage();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
371
app/admin/logic/goods/GoodsLogic.php
Normal file
371
app/admin/logic/goods/GoodsLogic.php
Normal file
@ -0,0 +1,371 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | likeshop开源商城系统
|
||||
// +----------------------------------------------------------------------
|
||||
// | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
|
||||
// | gitee下载:https://gitee.com/likeshop_gitee
|
||||
// | github下载:https://github.com/likeshop-github
|
||||
// | 访问官网:https://www.likeshop.cn
|
||||
// | 访问社区:https://home.likeshop.cn
|
||||
// | 访问手册:http://doc.likeshop.cn
|
||||
// | 微信公众号:likeshop技术社区
|
||||
// | likeshop系列产品在gitee、github等公开渠道开源版本可免费商用,未经许可不能去除前后端官方版权标识
|
||||
// | likeshop系列产品收费版本务必购买商业授权,购买去版权授权后,方可去除前后端官方版权标识
|
||||
// | 禁止对系统程序代码以任何目的,任何形式的再发布
|
||||
// | likeshop团队版权所有并拥有最终解释权
|
||||
// +----------------------------------------------------------------------
|
||||
// | author: likeshop.cn.team
|
||||
// +----------------------------------------------------------------------
|
||||
|
||||
|
||||
namespace app\admin\logic\goods;
|
||||
|
||||
|
||||
use app\common\basics\Logic;
|
||||
use app\common\enum\GoodsEnum;
|
||||
use app\common\model\goods\Goods;
|
||||
use app\common\model\goods\GoodsColumn;
|
||||
use app\common\model\goods\GoodsImage;
|
||||
use app\common\model\goods\GoodsItem;
|
||||
use app\common\model\goods\GoodsSpec;
|
||||
use app\common\model\goods\GoodsSpecValue;
|
||||
use app\common\model\goods\Supplier;
|
||||
use app\common\server\UrlServer;
|
||||
use think\facade\Db;
|
||||
use app\common\model\seckill\SeckillGoods;
|
||||
|
||||
|
||||
/**
|
||||
* 商品管理-逻辑
|
||||
* Class GoodsLogic
|
||||
* @package app\shop\logic\goods
|
||||
*/
|
||||
class GoodsLogic extends Logic
|
||||
{
|
||||
/*
|
||||
* 商品统计
|
||||
*/
|
||||
public static function statistics($get = []) {
|
||||
$where = [
|
||||
['del', '<>', GoodsEnum::DEL_TRUE]
|
||||
];
|
||||
|
||||
if(isset($get['goods_column_id']) && $get['goods_column_id'] != '') {
|
||||
$where[] = ['column_ids', '=', $get['goods_column_id']];
|
||||
}
|
||||
|
||||
return [
|
||||
// 销售中商品(含库存预警商品)
|
||||
// 销售状态:上架中;删除状态:正常; 审核状态: 审核通过
|
||||
'sell' => Goods::where($where)
|
||||
->where('del', GoodsEnum::DEL_NORMAL)
|
||||
->where('status', GoodsEnum::STATUS_SHELVES)
|
||||
->where('audit_status', GoodsEnum::AUDIT_STATUS_OK)
|
||||
->count(),
|
||||
// 仓库中商品
|
||||
// 销售状态:仓库中;删除状态:正常; 审核状态: 审核通过
|
||||
'warehouse' => Goods::where($where)
|
||||
->where('del', GoodsEnum::DEL_NORMAL)
|
||||
->where('status', GoodsEnum::STATUS_SOLD_OUT)
|
||||
->where('audit_status', GoodsEnum::AUDIT_STATUS_OK)
|
||||
->count(),
|
||||
// 回收站商品
|
||||
// 销售状态:任意;删除状态:回收站; 审核状态: 审核通过
|
||||
'recycle' => Goods::where($where)
|
||||
->where('del', GoodsEnum::DEL_RECYCLE)
|
||||
->where('audit_status', GoodsEnum::AUDIT_STATUS_OK)
|
||||
->count(),
|
||||
// 待审核商品
|
||||
// 销售状态:任意;删除状态:排除已删除; 审核状态: 待审核
|
||||
'audit_stay' => Goods::where($where)
|
||||
->where('del', '<>', GoodsEnum::DEL_TRUE)
|
||||
->where('audit_status', GoodsEnum::AUDIT_STATUS_STAY)
|
||||
->count(),
|
||||
// 审核未通过商品
|
||||
// 销售状态:任意;删除状态:排除已删除; 审核状态: 审核未通过
|
||||
'audit_refuse'=> Goods::where($where)
|
||||
->where('del', '<>', GoodsEnum::DEL_TRUE)
|
||||
->where('audit_status', GoodsEnum::AUDIT_STATUS_REFUSE)
|
||||
->count(),
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Notes: 列表
|
||||
* @param $get
|
||||
* @author 段誉(2021/4/15 10:53)
|
||||
* @return array
|
||||
* @throws \think\db\exception\DataNotFoundException
|
||||
* @throws \think\db\exception\DbException
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
*/
|
||||
public static function lists($get)
|
||||
{
|
||||
$where = [];
|
||||
if(isset($get['shop_name']) && !($get['shop_name'] == '')) {
|
||||
$where[] = ['s.name','like','%'.$get['shop_name'].'%'];
|
||||
}
|
||||
|
||||
if(isset($get['goods_name']) && !($get['goods_name'] == '')) {
|
||||
$where[] = ['g.name','like','%'.$get['goods_name'].'%'];
|
||||
}
|
||||
if(!empty($get['platform_cate_id'])) {
|
||||
$where[] = ['g.first_cate_id|g.second_cate_id|g.third_cate_id','=', $get['platform_cate_id']];
|
||||
}
|
||||
|
||||
if(isset($get['goods_type']) && $get['goods_type'] != '') {
|
||||
$where[] = ['g.type','=', $get['goods_type']];
|
||||
}
|
||||
|
||||
if(isset($get['goods_column_id']) && $get['goods_column_id'] != '') {
|
||||
$where[] = ['g.column_ids', '=', $get['goods_column_id']];
|
||||
}
|
||||
|
||||
$type = $get['type'] ?? 0;
|
||||
|
||||
switch ($type) {
|
||||
case 1: //销售中
|
||||
$where[] = ['g.status', '=', GoodsEnum::STATUS_SHELVES];//上架
|
||||
$where[] = ['g.del', '=', GoodsEnum::DEL_NORMAL];
|
||||
$where[] = ['g.audit_status', '=', GoodsEnum::AUDIT_STATUS_OK];//审核通过
|
||||
break;
|
||||
case 2: //仓库中
|
||||
$where[] = ['g.status', '=', GoodsEnum::STATUS_SOLD_OUT];//下架
|
||||
$where[] = ['g.del', '=', GoodsEnum::DEL_NORMAL];
|
||||
$where[] = ['g.audit_status', '=', GoodsEnum::AUDIT_STATUS_OK];//审核通过
|
||||
break;
|
||||
case 3: //回收站
|
||||
$where[] = ['g.del', '=', GoodsEnum::DEL_RECYCLE];
|
||||
$where[] = ['g.audit_status', '=', GoodsEnum::AUDIT_STATUS_OK];//审核通过
|
||||
break;
|
||||
case 4: //待审核
|
||||
$where[] = ['g.del', '<>', GoodsEnum::DEL_TRUE];
|
||||
$where[] = ['g.audit_status', '=', GoodsEnum::AUDIT_STATUS_STAY];
|
||||
break;
|
||||
case 5: //审核未通过
|
||||
$where[] = ['g.del', '<>', GoodsEnum::DEL_TRUE];
|
||||
$where[] = ['g.audit_status', '=', GoodsEnum::AUDIT_STATUS_REFUSE];
|
||||
break;
|
||||
default:
|
||||
$where[] = ['g.del', '=', GoodsEnum::DEL_NORMAL];
|
||||
}
|
||||
|
||||
$lists = Goods::alias('g')
|
||||
->field('g.id, g.image, g.spec_type, g.name, g.min_price, g.max_price, g.sales_actual, g.stock, g.sort_weight, g.create_time, g.column_ids, g.audit_status, g.audit_remark,s.id as shop_id, s.name as shop_name, s.logo as shop_logo, s.type as shop_type')
|
||||
->leftJoin('Shop s', 's.id=g.shop_id')
|
||||
->where($where)
|
||||
->page($get['page'], $get['limit'])
|
||||
->order('g.create_time', 'desc')
|
||||
->select();
|
||||
$count = Goods::alias('g')->leftJoin('shop s', 's.id = g.shop_id')->where($where)->count();
|
||||
foreach($lists as &$item) {
|
||||
$item['price'] = $item['spec_type'] == 1 ? $item["min_price"] : $item["min_price"] . " ~ " . $item["max_price"];
|
||||
switch($item['shop_type']) {
|
||||
case 1:
|
||||
$item['shop_type_desc'] = '官方自营';
|
||||
break;
|
||||
case 2:
|
||||
$item['shop_type_desc'] = '入驻商家';
|
||||
break;
|
||||
}
|
||||
$item['shop_logo'] = empty($item['shop_logo']) ? '' : UrlServer::getFileUrl($item['shop_logo']);
|
||||
|
||||
if(!empty($item['column_ids'])) {
|
||||
$columnArr = explode(',', $item['column_ids']);
|
||||
$columnStr = '';
|
||||
foreach($columnArr as $cloumnId) {
|
||||
$columnName = GoodsColumn::where('id', $cloumnId)->value('name');
|
||||
$columnStr = $columnStr . $columnName . ',';
|
||||
}
|
||||
$columnStr = substr($columnStr, 0, strlen($columnStr) -1);
|
||||
$item['columnStr'] = $columnStr;
|
||||
}
|
||||
}
|
||||
if($count) {
|
||||
$lists = $lists->toArray();
|
||||
}else{
|
||||
$lists = [];
|
||||
}
|
||||
return ['count' => $count, 'lists' => $lists];
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取商品信息
|
||||
* @param $goods_id
|
||||
* @return array
|
||||
*/
|
||||
public static function info($goods_id)
|
||||
{
|
||||
// 商品主表
|
||||
$info['base'] = Goods::where(['id' => $goods_id])
|
||||
->withAttr('abs_image', function ($value, $data) {
|
||||
return UrlServer::getFileUrl($data['image']);
|
||||
})
|
||||
->withAttr('content', function ($value){
|
||||
$preg = '/(<img .*?src=")[^https|^http](.*?)(".*?>)/is';
|
||||
$local_url = UrlServer::getFileUrl('/');
|
||||
return preg_replace($preg, "\${1}$local_url\${2}\${3}",$value);
|
||||
})
|
||||
->withAttr('poster', function ($value){
|
||||
return empty($value) ? '' : UrlServer::getFileUrl($value);
|
||||
})
|
||||
->withAttr('abs_video',function ($value,$data){
|
||||
if($data['video']){
|
||||
return UrlServer::getFileUrl($data['video']);
|
||||
}
|
||||
return '';
|
||||
})->append(['abs_image','abs_video'])->find();
|
||||
// 商品轮播图
|
||||
$info['base']['goods_image'] = GoodsImage::where(['goods_id' => $goods_id])
|
||||
->withAttr('abs_image', function ($value, $data) {
|
||||
return UrlServer::getFileUrl($data['uri']);})
|
||||
->append(['abs_image'])
|
||||
->select();
|
||||
// 商品SKU
|
||||
$info['item'] =GoodsItem::where(['goods_id' => $goods_id])
|
||||
->withAttr('abs_image', function ($value, $data) {
|
||||
return $data['image'] ? UrlServer::getFileUrl($data['image']) : '';
|
||||
})->append(['abs_image'])
|
||||
->select();
|
||||
// 商品规格项
|
||||
$info['spec'] = GoodsSpec::where(['goods_id' => $goods_id])->select();
|
||||
// 商品规格值
|
||||
$spec_value = GoodsSpecValue::where(['goods_id' => $goods_id])->select();
|
||||
|
||||
$data = [];
|
||||
foreach ($spec_value as $k => $v) {
|
||||
$data[$v['spec_id']][] = $v;
|
||||
}
|
||||
foreach ($info['spec'] as $k => $v) {
|
||||
$info['spec'][$k]['values'] = isset($data[$v['id']]) ? $data[$v['id']] : [];
|
||||
}
|
||||
return $info;
|
||||
}
|
||||
|
||||
/**
|
||||
* 违规重审
|
||||
* @param $params
|
||||
*/
|
||||
public static function reAudit($params)
|
||||
{
|
||||
Db::startTrans();
|
||||
try{
|
||||
// 更新商品信息
|
||||
$updateData = [
|
||||
'id' => $params['goods_id'],
|
||||
'audit_remark' => trim($params['reason']),
|
||||
'audit_status' => GoodsEnum::AUDIT_STATUS_REFUSE
|
||||
];
|
||||
Goods::update($updateData);
|
||||
// 对应的秒杀商品同步更新为待审核
|
||||
SeckillGoods::where([
|
||||
'del' => 0,
|
||||
'goods_id' => $params['goods_id']
|
||||
])->update([
|
||||
'review_status' => 0,
|
||||
'update_time' => time()
|
||||
]);
|
||||
|
||||
event('UpdateCollect', ['goods_id' => $params['goods_id']]);
|
||||
|
||||
Db::commit();
|
||||
return true;
|
||||
}catch(\Exception $e) {
|
||||
Db::rollback();
|
||||
self::$error = $e->getMessage();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 商品设置
|
||||
*/
|
||||
public static function setInfo($params)
|
||||
{
|
||||
$updateData = [
|
||||
'id' => $params['goods_id'],
|
||||
'sales_virtual' => $params['sales_virtual'],
|
||||
'clicks_virtual' => $params['clicks_virtual'],
|
||||
'sort_weight' => $params['sort_weight'],
|
||||
'column_ids' => $params['select']
|
||||
];
|
||||
return Goods::update($updateData);
|
||||
}
|
||||
|
||||
/**
|
||||
* 审核
|
||||
*/
|
||||
public static function audit($params)
|
||||
{
|
||||
$updateData = [
|
||||
'id' => $params['goods_id'],
|
||||
'audit_status' => $params['audit_status'],
|
||||
'audit_remark' => $params['audit_remark'],
|
||||
];
|
||||
return Goods::update($updateData);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @notes 批量下架
|
||||
* @param $params
|
||||
* @return bool
|
||||
* @author ljj
|
||||
* @date 2022/9/20 6:17 下午
|
||||
*/
|
||||
public static function moreLower($params)
|
||||
{
|
||||
Db::startTrans();
|
||||
try{
|
||||
$ids = explode(',',$params['ids']);
|
||||
foreach ($ids as $id) {
|
||||
// 更新商品信息
|
||||
$updateData = [
|
||||
'id' => $id,
|
||||
'audit_remark' => trim($params['reason']),
|
||||
'audit_status' => GoodsEnum::AUDIT_STATUS_REFUSE
|
||||
];
|
||||
Goods::update($updateData);
|
||||
// 对应的秒杀商品同步更新为待审核
|
||||
SeckillGoods::where([
|
||||
'del' => 0,
|
||||
'goods_id' => $id
|
||||
])->update([
|
||||
'review_status' => 0,
|
||||
'update_time' => time()
|
||||
]);
|
||||
|
||||
event('UpdateCollect', ['goods_id' => $id]);
|
||||
}
|
||||
|
||||
Db::commit();
|
||||
return true;
|
||||
}catch(\Exception $e) {
|
||||
Db::rollback();
|
||||
self::$error = $e->getMessage();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @notes 批量审核
|
||||
* @param $params
|
||||
* @return bool
|
||||
* @author ljj
|
||||
* @date 2022/9/20 6:36 下午
|
||||
*/
|
||||
public static function moreAudit($params)
|
||||
{
|
||||
$ids = explode(',',$params['ids']);
|
||||
foreach ($ids as $id) {
|
||||
$updateData = [
|
||||
'id' => $id,
|
||||
'audit_status' => $params['audit_status'],
|
||||
'audit_remark' => $params['audit_remark'],
|
||||
];
|
||||
Goods::update($updateData);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
98
app/admin/logic/goods/UnitLogic.php
Normal file
98
app/admin/logic/goods/UnitLogic.php
Normal file
@ -0,0 +1,98 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | likeshop开源商城系统
|
||||
// +----------------------------------------------------------------------
|
||||
// | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
|
||||
// | gitee下载:https://gitee.com/likeshop_gitee
|
||||
// | github下载:https://github.com/likeshop-github
|
||||
// | 访问官网:https://www.likeshop.cn
|
||||
// | 访问社区:https://home.likeshop.cn
|
||||
// | 访问手册:http://doc.likeshop.cn
|
||||
// | 微信公众号:likeshop技术社区
|
||||
// | likeshop系列产品在gitee、github等公开渠道开源版本可免费商用,未经许可不能去除前后端官方版权标识
|
||||
// | likeshop系列产品收费版本务必购买商业授权,购买去版权授权后,方可去除前后端官方版权标识
|
||||
// | 禁止对系统程序代码以任何目的,任何形式的再发布
|
||||
// | likeshop团队版权所有并拥有最终解释权
|
||||
// +----------------------------------------------------------------------
|
||||
// | author: likeshop.cn.team
|
||||
// +----------------------------------------------------------------------
|
||||
|
||||
|
||||
namespace app\admin\logic\goods;
|
||||
|
||||
|
||||
use app\common\basics\Logic;
|
||||
use app\common\model\goods\GoodsUnit;
|
||||
|
||||
/**
|
||||
* 商品单位逻辑
|
||||
* Class UnitLogic
|
||||
* @package app\admin\logic\goods
|
||||
*/
|
||||
class UnitLogic extends Logic
|
||||
{
|
||||
|
||||
/**
|
||||
* Notes: 列表
|
||||
* @param $get
|
||||
* @author 段誉(2021/4/15 10:53)
|
||||
* @return array
|
||||
* @throws \think\db\exception\DataNotFoundException
|
||||
* @throws \think\db\exception\DbException
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
*/
|
||||
public static function lists($get)
|
||||
{
|
||||
$result = GoodsUnit::where(['del' =>0])
|
||||
->order('sort')
|
||||
->paginate([
|
||||
'list_rows'=> $get['limit'],
|
||||
'page'=> $get['page']
|
||||
]);
|
||||
|
||||
return ['count' => $result->total(), 'lists' => $result->getCollection()];
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Notes: 添加
|
||||
* @param $post
|
||||
* @return GoodsUnit|\think\Model
|
||||
*@author 段誉(2021/4/15 10:54)
|
||||
*/
|
||||
public static function addUnit($post)
|
||||
{
|
||||
return GoodsUnit::create([
|
||||
'name' => $post['name'],
|
||||
'sort' => $post['sort'] ?? 100,
|
||||
]);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Notes: 编辑
|
||||
* @param $post
|
||||
* @return GoodsUnit
|
||||
*@author 段誉(2021/4/15 10:54)
|
||||
*/
|
||||
public static function editUnit($post)
|
||||
{
|
||||
return GoodsUnit::update([
|
||||
'name' => $post['name'],
|
||||
'sort' => $post['sort'] ?? 100
|
||||
], ['id' => $post['id']]);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Notes: 删除
|
||||
* @param $id
|
||||
* @return GoodsUnit
|
||||
*@author 段誉(2021/4/15 10:54)
|
||||
*/
|
||||
public static function del($id)
|
||||
{
|
||||
return GoodsUnit::update(['del' => 1], ['id' => $id]);
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user