添加热销榜单和新品推荐
This commit is contained in:
parent
6680ce989d
commit
3a5edfe0f8
79
app/admin/controller/HotList.php
Normal file
79
app/admin/controller/HotList.php
Normal file
@ -0,0 +1,79 @@
|
||||
<?php
|
||||
|
||||
namespace app\admin\controller;
|
||||
|
||||
use app\admin\logic\goods\GoodsLogic;
|
||||
use app\admin\logic\HotListLogic;
|
||||
use app\common\basics\AdminBase;
|
||||
use app\common\server\JsonServer;
|
||||
use think\facade\Db;
|
||||
use app\common\enum\GoodsEnum;
|
||||
|
||||
class HotList extends AdminBase
|
||||
{
|
||||
public function lists()
|
||||
{
|
||||
if ($this->request->isAjax()) {
|
||||
$get = $this->request->get();
|
||||
$lists = HotListLogic::lists($get);
|
||||
return JsonServer::success('', $lists);
|
||||
}
|
||||
return view();
|
||||
}
|
||||
|
||||
public function add()
|
||||
{
|
||||
if ($this->request->isAjax()) {
|
||||
$form = $this->request->post();
|
||||
$result = HotListLogic::create($form);
|
||||
if ($result['code'] == 1) {
|
||||
return JsonServer::success('添加成功');
|
||||
}
|
||||
return JsonServer::error($result['msg']);
|
||||
}
|
||||
return view('');
|
||||
}
|
||||
|
||||
// 修改
|
||||
public function audit()
|
||||
{
|
||||
if ($this->request->isAjax()) {
|
||||
$post = $this->request->post();
|
||||
$result = HotListLogic::edit($post);
|
||||
if ($result['code'] == 1) {
|
||||
return JsonServer::success('修改成功');
|
||||
}
|
||||
return JsonServer::error($result['msg']);
|
||||
}
|
||||
|
||||
$id = $this->request->get('id');
|
||||
return view('', [
|
||||
'detail' => HotListLogic::detail($id)
|
||||
]);
|
||||
}
|
||||
|
||||
// 删除
|
||||
public function del()
|
||||
{
|
||||
if ($this->request->isAjax()) {
|
||||
$post = $this->request->post();
|
||||
$result = HotListLogic::del($post['id']);
|
||||
if ($result) {
|
||||
return JsonServer::success('删除成功');
|
||||
}
|
||||
|
||||
return JsonServer::error('删除失败');
|
||||
}
|
||||
}
|
||||
|
||||
// 选择商品
|
||||
public function goods()
|
||||
{
|
||||
if ($this->request->isAjax()) {
|
||||
$get = $this->request->get();
|
||||
return JsonServer::success('', GoodsLogic::lists($get));
|
||||
}
|
||||
|
||||
return view();
|
||||
}
|
||||
}
|
||||
77
app/admin/controller/NewGoods.php
Normal file
77
app/admin/controller/NewGoods.php
Normal file
@ -0,0 +1,77 @@
|
||||
<?php
|
||||
|
||||
namespace app\admin\controller;
|
||||
|
||||
use app\admin\logic\goods\GoodsLogic;
|
||||
use app\common\basics\AdminBase;
|
||||
use app\common\server\JsonServer;
|
||||
use app\admin\logic\NewGoodsLogic;
|
||||
|
||||
class NewGoods extends AdminBase
|
||||
{
|
||||
public function lists()
|
||||
{
|
||||
if ($this->request->isAjax()) {
|
||||
$get = $this->request->get();
|
||||
$lists = NewGoodsLogic::lists($get);
|
||||
return JsonServer::success('', $lists);
|
||||
}
|
||||
return view();
|
||||
}
|
||||
|
||||
public function add()
|
||||
{
|
||||
if ($this->request->isAjax()) {
|
||||
$form = $this->request->post();
|
||||
$result = NewGoodsLogic::create($form);
|
||||
if ($result['code'] == 1) {
|
||||
return JsonServer::success('添加成功');
|
||||
}
|
||||
return JsonServer::error($result['msg']);
|
||||
}
|
||||
return view('');
|
||||
}
|
||||
|
||||
// 修改
|
||||
public function audit()
|
||||
{
|
||||
if ($this->request->isAjax()) {
|
||||
$post = $this->request->post();
|
||||
$result = NewGoodsLogic::edit($post);
|
||||
if ($result['code'] == 1) {
|
||||
return JsonServer::success('修改成功');
|
||||
}
|
||||
return JsonServer::error($result['msg']);
|
||||
}
|
||||
|
||||
$id = $this->request->get('id');
|
||||
return view('', [
|
||||
'detail' => NewGoodsLogic::detail($id)
|
||||
]);
|
||||
}
|
||||
|
||||
// 删除
|
||||
public function del()
|
||||
{
|
||||
if ($this->request->isAjax()) {
|
||||
$post = $this->request->post();
|
||||
$result = NewGoodsLogic::del($post['id']);
|
||||
if ($result) {
|
||||
return JsonServer::success('删除成功');
|
||||
}
|
||||
|
||||
return JsonServer::error('删除失败');
|
||||
}
|
||||
}
|
||||
|
||||
// 选择商品
|
||||
public function goods()
|
||||
{
|
||||
if ($this->request->isAjax()) {
|
||||
$get = $this->request->get();
|
||||
return JsonServer::success('', GoodsLogic::lists($get));
|
||||
}
|
||||
|
||||
return view();
|
||||
}
|
||||
}
|
||||
80
app/admin/view/new_goods/add.html
Normal file
80
app/admin/view/new_goods/add.html
Normal file
@ -0,0 +1,80 @@
|
||||
{layout name="layout2" /}
|
||||
<style>
|
||||
.layui-form {padding: 20px 30px;background-color: #ffffff;}
|
||||
.layui-form-item .layui-form-label { width: 95px; }
|
||||
.layui-form-item .layui-input-inline { width: 240px; }
|
||||
.layui-form-item .map-container{ width: 600px; height: 400px; margin-left: 100px; margin-top: 20px; }
|
||||
#video-block {position: relative; width: 700px;height: 300px}
|
||||
.del-video-btn {
|
||||
visibility: hidden;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
position: absolute;
|
||||
z-index: 100;
|
||||
top: -11px;
|
||||
right: -9px;
|
||||
width: 20px;
|
||||
height: 20px;
|
||||
cursor: pointer;
|
||||
font-size: 14px;
|
||||
color: #FFFFFF;
|
||||
border-radius: 50%;
|
||||
background: hsla(0, 0%, 60%, .6)
|
||||
}
|
||||
.select-goods {margin-left: 10px}
|
||||
</style>
|
||||
|
||||
<div class="layui-card layui-form">
|
||||
<div class="layui-card-body">
|
||||
<div class="layui-form-item">
|
||||
<label class="layui-form-label">商品:</label>
|
||||
<div class="layui-input-inline" style="display: flex">
|
||||
<div id="shop_name"></div>
|
||||
<input type="hidden" id="goods_id" name="goods_id">
|
||||
<a class="layui-btn layui-btn-normal select-goods">选择商品</a>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="layui-form-item">
|
||||
<label for="sort" class="layui-form-label">排序:</label>
|
||||
<div class="layui-input-inline">
|
||||
<input type="text" name="sort" id="sort" autocomplete="off" class="layui-input">
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="layui-form-item layui-hide">
|
||||
<input type="button" lay-submit lay-filter="addSubmit" id="addSubmit" value="确认">
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
||||
<script src="__PUBLIC__/static/common/js/area.js"></script>
|
||||
<script>
|
||||
layui.config({
|
||||
base: "/static/lib/"
|
||||
}).extend({
|
||||
likeedit: "likeedit/likeedit",
|
||||
likeArea: "likeArea/likeArea",
|
||||
txMap: "likeMap/txMap"
|
||||
}).use(["form", "laydate", "likeArea", "txMap", 'likeedit', 'upload', 'element'], function(){
|
||||
var $ = layui.$;
|
||||
var form = layui.form;
|
||||
|
||||
// 选择商品
|
||||
$(document).on('click','.select-goods',function () {
|
||||
layer.open({
|
||||
type: 2
|
||||
,title: '选择商品'
|
||||
,content: '{:url("newGoods/goods")}'
|
||||
,area: ['90%', '90%']
|
||||
,btn: ['确认', '取消']
|
||||
,yes: function(index, layero){
|
||||
var data = window["layui-layer-iframe" + index].callbackdata();
|
||||
$('#shop_name').html(data[0].name)
|
||||
$('#goods_id').val(data[0].id)
|
||||
}
|
||||
})
|
||||
})
|
||||
})
|
||||
</script>
|
||||
@ -302,6 +302,7 @@ class Goods extends Api
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// 2024-07-26 新版获取热销榜单
|
||||
public function hotList()
|
||||
{
|
||||
@ -311,4 +312,15 @@ class Goods extends Api
|
||||
|
||||
return JsonServer::success('获取成功', $list);
|
||||
}
|
||||
|
||||
public function newGoodsList()
|
||||
{
|
||||
// 等于1是获取4条推荐商品 等于2是获取全部的商品
|
||||
$type = $this->request->get('type');
|
||||
$page = $this->request->get('page_no', $this->page_no);
|
||||
$size = $this->request->get('page_size', $this->page_size);
|
||||
|
||||
$list = GoodsLogic::goodsList($type, $page, $size);
|
||||
return JsonServer::success('获取成功', $list);
|
||||
}
|
||||
}
|
||||
@ -897,7 +897,7 @@ class GoodsLogic extends Logic
|
||||
->alias('hl')
|
||||
->join('goods g', 'hl.goods_id = g.id')
|
||||
->where('delete_time', 0)
|
||||
->field('hl.id as hl_id, hl.goods_id, g.id as id, g.name, g.image, g.issuing_price, g.market_price, g.min_price, g.purchase_price, g.wholesale_price')
|
||||
->field('hl.id as hl_id, g.id as id, g.name, g.image, g.issuing_price, g.market_price, g.min_price, g.purchase_price, g.wholesale_price')
|
||||
->select()
|
||||
->toArray();
|
||||
foreach ($hot_list as &$v) {
|
||||
@ -950,4 +950,48 @@ class GoodsLogic extends Logic
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
public static function goodsList($type, $page, $size) {
|
||||
if ($type == 'recommend') {
|
||||
$list = Db::name('new_goods')
|
||||
->alias('ng')
|
||||
->join('goods g', 'ng.goods_id = g.id')
|
||||
->where('delete_time', 0)
|
||||
->field('ng.id as ng_id, g.id as id, g.name, g.image, g.issuing_price, g.market_price, g.min_price, g.purchase_price, g.wholesale_price')
|
||||
->limit(4)
|
||||
->select()
|
||||
->toArray();
|
||||
foreach ($list as &$v) {
|
||||
if (isset($v['image'])) {
|
||||
$v['image'] = UrlServer::getFileUrl($v['image']);
|
||||
}
|
||||
}
|
||||
return $list;
|
||||
} else if ($type == 'all') {
|
||||
$list = Db::name('new_goods')
|
||||
->alias('ng')
|
||||
->join('goods g', 'ng.goods_id = g.id')
|
||||
->where('delete_time', 0)
|
||||
->field('ng.id as ng_id, g.id as id, g.name, g.image, g.issuing_price, g.market_price, g.min_price, g.purchase_price, g.wholesale_price')
|
||||
->select()
|
||||
->toArray();
|
||||
|
||||
$count = Db::name('new_goods')->count();
|
||||
foreach ($list as &$v) {
|
||||
if (isset($v['image'])) {
|
||||
$v['image'] = UrlServer::getFileUrl($v['image']);
|
||||
}
|
||||
}
|
||||
|
||||
$more = is_more($count, $page, $size); //是否有下一页
|
||||
|
||||
return [
|
||||
'lists' => $list,
|
||||
'page_no' => $page,
|
||||
'page_size' => $size,
|
||||
'count' => $count,
|
||||
'more' => $more
|
||||
];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user