新增商品管理

This commit is contained in:
彭桃 2023-02-21 17:03:11 +08:00
parent a1c32e2269
commit b4a2dd1446
9 changed files with 1159 additions and 0 deletions

View File

@ -140,6 +140,13 @@ function get_admin_rule()
return $rule;
}
//读取商品分类
function get_store_category()
{
$store_category = Db::connect('shop')->table('eb_store_category')->field('store_category_id as id,pid,cate_name as title,sort,level')->where(['is_show' => 1])->select()->toArray();
return $store_category;
}
//读取模块列表
function get_admin_module()
{

View File

@ -0,0 +1,145 @@
<?php
/**
* @copyright Copyright (c) 2021 勾股工作室
* @license https://opensource.org/licenses/Apache-2.0
* @link https://www.gougucms.com
*/
declare (strict_types = 1);
namespace app\admin\controller;
use app\admin\BaseController;
use app\admin\model\StoreProduct as StoreProductModel;
use app\admin\validate\StoreProductValidate;
use think\exception\ValidateException;
use think\facade\Db;
use think\facade\View;
class StoreProduct extends BaseController
{
/**
* 构造函数
*/
public function __construct()
{
$this->model = new StoreProductModel();
$this->uid = get_login_admin('id');
}
/**
* 数据列表
*/
public function datalist()
{
if (request()->isAjax()) {
$param = get_params();
$where = [];
if (isset($param['keywords']) && !empty($param['keywords'])){
$where[]=['store_name','like','%'.$param['keywords'].'%'];
}
$list = $this->model->getStoreProductList($where,$param);
return table_assign(0, '', $list);
}
else{
return view();
}
}
/**
* 添加
*/
public function add()
{
if (request()->isAjax()) {
$param = get_params();
// 检验完整性
try {
validate(StoreProductValidate::class)->check($param);
} catch (ValidateException $e) {
// 验证失败 输出错误信息
return to_assign(1, $e->getError());
}
$this->model->addStoreProduct($param);
}else{
$store_brand= Db::connect('shop')->table('eb_store_brand')->where(['is_show' => 1])
->select();
View::assign('store_brand', $store_brand);
return view();
}
}
/**
* 编辑
*/
public function edit()
{
$param = get_params();
if (request()->isAjax()) {
// 检验完整性
try {
validate(StoreProductValidate::class)->check($param);
} catch (ValidateException $e) {
// 验证失败 输出错误信息
return to_assign(1, $e->getError());
}
$this->model->editStoreProduct($param);
}else{
$product_id = isset($param['product_id']) ? $param['product_id'] : 0;
$detail = $this->model->getStoreProductById($product_id);
if (!empty($detail)) {
$detail['content'] = Db::table('cms_store_product_content')->where('product_id',$detail['product_id'])->value('content');
View::assign('detail', $detail);
$store_brand= Db::connect('shop')->table('eb_store_brand')->where(['is_show' => 1])
->select();
View::assign('store_brand', $store_brand);
return view();
}
else{
throw new \think\exception\HttpException(404, '找不到页面');
}
}
}
/**
* 查看信息
*/
public function read()
{
$param = get_params();
$product_id = isset($param['product_id']) ? $param['product_id'] : 0;
$detail = $this->model->getStoreProductById($product_id);
if (!empty($detail)) {
$detail['content'] = Db::table('cms_store_product_content')->where('product_id',$detail['product_id'])->value('content');
View::assign('detail', $detail);
$store_brand= Db::connect('shop')->table('eb_store_brand')->where(['is_show' => 1])
->select();
View::assign('store_brand', $store_brand);
return view();
}
else{
throw new \think\exception\HttpException(404, '找不到页面');
}
}
/**
* 删除
* type=0,逻辑删除,默认
* type=1,物理删除
*/
public function del()
{
$param = get_params();
$product_id = isset($param['product_id']) ? $param['product_id'] : 0;
$type = isset($param['type']) ? $param['type'] : 0;
$this->model->delStoreProductById($product_id,$type);
}
}

View File

@ -0,0 +1,106 @@
<?php
/**
* @copyright Copyright (c) 2021 勾股工作室
* @license https://opensource.org/licenses/Apache-2.0
* @link https://www.gougucms.com
*/
namespace app\admin\model;
use think\model;
use think\facade\Db;
class StoreProduct extends Model
{
/**
* 获取分页列表
* @param $where
* @param $param
*/
public function getStoreProductList($where, $param)
{
$rows = empty($param['limit']) ? get_config('app . page_size') : $param['limit'];
$order = empty($param['order']) ? 'product_id desc' : $param['order'];
$list = self::where($where)->field('product_id,mer_id,store_name,store_info,keyword,brand_id,cate_id,unit_name,sort,sales,price,cost,ot_price,stock,is_hot,is_benefit,temp_id,spec_type,image,slider_image,once_max_count,once_min_count,integral_rate,integral_total,integral_price_total,labels,delivery_free,type,extend,pay_limit,svip_price_type,svip_price,mer_svip_status,param_temp_id')->order($order)->paginate($rows, false, ['query' => $param]);
return $list;
}
/**
* 添加数据
* @param $param
*/
public function addStoreProduct($param)
{
$insertId = 0;
try {
$param['create_time'] = date('Y-m-d H:i:s');
$param['status'] = 1;
$insertId = self::strict(false)->field(true)->insertGetId($param);
// 写入商品详情表
$data['product_id'] = $insertId;
$data['content'] = $param['content'];
Db::table('cms_store_product_content')->strict(false)->field(true)->insertGetId($data);
add_log('add', $insertId, $param);
} catch(\Exception $e) {
return to_assign(1, '操作失败,原因:'.$e->getMessage());
}
return to_assign(0,'操作成功',['aid'=>$insertId]);
}
/**
* 编辑信息
* @param $param
*/
public function editStoreProduct($param)
{
try {
// $param['update_time'] = time();
self::where('product_id', $param['product_id'])->strict(false)->field(true)->update($param);
// 修改商品详情表
$data['content'] = $param['content'];
Db::table('cms_store_product_content')->where('product_id', $param['product_id'])->strict(false)->field(true)->update($data);
add_log('edit', $param['product_id'], $param);
} catch(\Exception $e) {
return to_assign(1, '操作失败,原因:'.$e->getMessage());
}
return to_assign();
}
/**
* 根据id获取信息
* @param $id
*/
public function getStoreProductById($id)
{
$info = self::where('product_id', $id)->find();
return $info;
}
/**
* 删除信息
* @param $id
* @return array
*/
public function delStoreProductById($id,$type=0)
{
if($type==0){
//逻辑删除
try {
$param['delete_time'] = time();
self::where('product_id', $id)->update(['delete_time'=>time()]);
add_log('delete', $id);
} catch(\Exception $e) {
return to_assign(1, '操作失败,原因:'.$e->getMessage());
}
}
else{
//物理删除
try {
self::where('product_id', $id)->delete();
add_log('delete', $id);
} catch(\Exception $e) {
return to_assign(1, '操作失败,原因:'.$e->getMessage());
}
}
return to_assign();
}
}

View File

@ -0,0 +1,20 @@
<?php
/**
* @copyright Copyright (c) 2021 勾股工作室
* @license https://opensource.org/licenses/Apache-2.0
* @link https://www.gougucms.com
*/
namespace app\admin\validate;
use think\Validate;
class StoreProductValidate extends Validate
{
protected $rule = [
'store_name' => 'require',
];
protected $message = [
'store_name.require' => '商品名称不能为空',
];
}

View File

@ -0,0 +1,222 @@
{extend name="common/base"/}
{block name="style"}
<style type="text/css">
.editormd-code-toolbar select {
display: inline-block
}
.editormd li {
list-style: inherit;
}
</style>
{/block}
<!-- 主体 -->
{block name="body"}
<form class="layui-form p-4">
<h3 class="pb-3">添加</h3>
<table class="layui-table layui-table-form">
<tr>
<td class="layui-td-gray">商品名称<font>*</font></td>
<td colspan="7"><input type="text" name="store_name" lay-verify="required" lay-reqText="请输入商品名称"
autocomplete="off" placeholder="请输入商品名称" class="layui-input"></td>
</tr>
<!-- <tr>-->
<!-- <td class="layui-td-gray">平台商品分类<font>*</font></td>-->
<!-- <td colspan="3">-->
<!-- <div class="layui-col-md6">-->
<!-- <select name="cate_id" lay-verify="required" lay-search="">-->
<!-- <option value="" >请选择</option>-->
<!-- {volist name=':set_recursion(get_store_category())' id='vo'}-->
<!-- <option value="{$vo.id}" >{$vo.title}</option>-->
<!-- {/volist}-->
<!-- </select>-->
<!-- </div>-->
<!-- </td>-->
<!-- </tr>-->
<tr>
<td class="layui-td-gray">平台商品分类<font>*</font></td>
<td colspan="3">
<div class="layui-col-md6">
<select name="cate_id" lay-verify="required" lay-search="">
<option value="" >请选择</option>
{volist name=':set_recursion(get_store_category())' id='vo'}
<option value="{$vo.id}" >{$vo.title}</option>
{/volist}
</select>
</div>
</td>
</tr>
<tr>
<td class="layui-td-gray">品牌选择<font>*</font></td>
<td colspan="3">
<div class="layui-col-md6">
<select name="brand_id" lay-verify="required" lay-search="">
<option value="" >请选择</option>
{volist name='store_brand' id='vo'}
<option value="{$vo.brand_id}" >{$vo.brand_name}</option>
{/volist}
</select>
</div>
</td>
</tr>
<tr>
<td class="layui-td-gray" style="vertical-align:top;">商品封面图</td>
<td>
<div class="layui-upload">
<button type="button" class="layui-btn layui-btn-sm" id="upload_btn_thumb">
上传缩略图(尺寸:428x270)
</button>
<div class="layui-upload-list" id="upload_box_thumb"
style="width: 428px; height:270px; overflow: hidden;">
<img src=""
onerror="javascript:this.src='{__GOUGU__}/gougu/images/nonepic600x360.jpg';this.onerror=null;"
width="100" style="max-width: 100%; height:66px;"/>
<input type="hidden" name="image" value="">
</div>
</div>
</td>
</tr>
<tr>
<td class="layui-td-gray" style="vertical-align:top;">商品轮播图</td>
<td>
<div class="layui-upload">
<button type="button" class="layui-btn layui-btn-sm" id="upload_btn_thumb2">
上传缩略图(尺寸:428x270)
</button>
<div class="layui-upload-list" id="upload_box_thumb2"
style="width: 428px; height:270px; overflow: hidden;">
<img src=""
onerror="javascript:this.src='{__GOUGU__}/gougu/images/nonepic600x360.jpg';this.onerror=null;"
width="100" style="max-width: 100%; height:66px;"/>
<input type="hidden" name="slider_image" value="">
</div>
</div>
</td>
</tr>
<tr>
<td class="layui-td-gray">单位<font>*</font></td>
<td colspan="7"><input type="text" name="unit_name" lay-verify="required" lay-reqText="请输入单位"
autocomplete="off" placeholder="请输入单位" class="layui-input"></td>
</tr>
<tr>
<td class="layui-td-gray">商品关键字<font>*</font></td>
<td colspan="7"><input type="text" name="keyword" lay-verify="required" lay-reqText="请输入商品关键字"
autocomplete="off" placeholder="请输入商品关键字" class="layui-input"></td>
</tr>
<tr>
<td class="layui-td-gray">售价<font>*</font></td>
<td colspan="7"><input type="text" name="price" lay-verify="required" lay-reqText="请输入商品关键字"
autocomplete="off" placeholder="请输入商品关键字" class="layui-input"></td>
</tr>
<tr>
<td class="layui-td-gray">成本价<font>*</font></td>
<td colspan="7"><input type="text" name="cost" lay-verify="required" lay-reqText="请输入商品关键字"
autocomplete="off" placeholder="请输入商品关键字" class="layui-input"></td>
</tr>
<tr>
<td class="layui-td-gray">市场价<font>*</font></td>
<td colspan="7"><input type="text" name="ot_price" lay-verify="required" lay-reqText="请输入商品关键字"
autocomplete="off" placeholder="请输入商品关键字" class="layui-input"></td>
</tr>
<tr>
<td class="layui-td-gray">库存<font>*</font></td>
<td colspan="7"><input type="text" name="stock" lay-verify="required" lay-reqText="请输入商品关键字"
autocomplete="off" placeholder="请输入商品关键字" class="layui-input"></td>
</tr>
<tr>
<td class="layui-td-gray" style="text-align:left">商品简介</td>
<td colspan="6">
<textarea class="layui-textarea" name="store_info"></textarea>
</td>
</tr>
<tr>
<td class="layui-td-gray" style="text-align:left">商品详情</td>
<td colspan="6">
<textarea class="layui-textarea" id="container_content"></textarea>
</td>
</tr>
</table>
<div class="pt-3">
<button class="layui-btn layui-btn-normal" lay-submit="" lay-filter="webform">立即提交</button>
<button type="reset" class="layui-btn layui-btn-primary">重置</button>
</div>
</form>
{/block}
<!-- /主体 -->
<!-- 脚本 -->
{block name="script"}
<script src="/static/assets/js/xm-select.js"></script>
<script>
var moduleInit = ['tool', 'tagpicker', 'tinymce'];
var group_access = "{:session('gougu_admin')['group_access']}"
function gouguInit() {
var form = layui.form, tool = layui.tool, tagspicker = layui.tagpicker;
//上传缩略图
var upload_thumb = layui.upload.render({
elem: '#upload_btn_thumb',
url: '/admin/api/upload',
done: function (res) {
//如果上传失败
if (res.code == 1) {
return layer.msg('上传失败');
}
//上传成功
$('#upload_box_thumb input').attr('value', res.data.filepath);
$('#upload_box_thumb img').attr('src', res.data.filepath);
}
});
//上传商品轮播图
var upload_thumb = layui.upload.render({
elem: '#upload_btn_thumb2',
url: '/admin/api/upload',
done: function (res) {
//如果上传失败
if (res.code == 1) {
return layer.msg('上传失败');
}
//上传成功
$('#upload_box_thumb2 input').attr('value', res.data.filepath);
$('#upload_box_thumb2 img').attr('src', res.data.filepath);
}
});
var editor = layui.tinymce;
var edit = editor.render({
selector: "#container_content",
height: 500
});
//监听提交
form.on('submit(webform)', function (data) {
data.field.content = tinyMCE.editors['container_content'].getContent();
if (data.field.content == '') {
layer.msg('请先完善商品详情');
return false;
}
let callback = function (e) {
layer.msg(e.msg);
if (e.code == 0) {
tool.tabRefresh(71);
tool.sideClose(1000);
}
}
tool.post('/admin/store_product/add', data.field, callback);
return false;
});
}
</script>
{/block}
<!-- /脚本 -->

View File

@ -0,0 +1,173 @@
{extend name="common/base"/}
<!-- 主体 -->
{block name="body"}
<div class="p-3">
<form class="layui-form gg-form-bar border-t border-x">
<div class="layui-input-inline" style="width:300px;">
<input type="text" name="keywords" placeholder="请输入关键字" class="layui-input" autocomplete="off" />
</div>
<button class="layui-btn layui-btn-normal" lay-submit="" lay-filter="searchform">提交搜索</button>
</form>
<table class="layui-hide" id="store_product" lay-filter="store_product"></table>
</div>
<script type="text/html" id="toolbarDemo">
<div class="layui-btn-container">
<span class="layui-btn layui-btn-sm" lay-event="add" data-title="添加商品">+ 添加商品</span>
</div>
</script>
<script type="text/html" id="barDemo">
<div class="layui-btn-group"><a class="layui-btn layui-btn-normal layui-btn-xs" lay-event="read">查看</a><a class="layui-btn layui-btn-xs" lay-event="edit">编辑</a><a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">删除</a></div>
</script>
{/block}
<!-- /主体 -->
<!-- 脚本 -->
{block name="script"}
<script>
const moduleInit = ['tool'];
function gouguInit() {
var table = layui.table,tool = layui.tool, form = layui.form;
layui.pageTable = table.render({
elem: '#store_product',
title: '商品表列表',
toolbar: '#toolbarDemo',
url: '/admin/store_product/datalist',
page: true,
limit: 20,
cellMinWidth: 300,
cols: [
[
{
fixed: 'left',
field: 'product_id',
title: '编号',
align: 'center',
width: 80
},{
field: 'image',
title: '商品图片',
align: 'center',
width: 100,
templet: '<div><img src="{{ d.image }}" style="width:30px; height:30px;"></div>',
},{
field: 'store_name',
title: '商品名称',
align: 'center',
width: 100
},{
field: 'store_info',
title: '商品简介',
align: 'center',
width: 100
},{
field: 'keyword',
title: '关键字',
align: 'center',
width: 100
},{
field: 'brand_id',
title: '品牌 id',
align: 'center',
width: 100
},{
field: 'cate_id',
title: '分类',
align: 'center',
width: 100
},{
field: 'unit_name',
title: '单位名',
align: 'center',
width: 100
},{
field: 'sales',
title: '销量',
align: 'center',
width: 100
},{
field: 'price',
title: '最低价格',
align: 'center',
width: 100
},{
field: 'cost',
title: '成本价',
align: 'center',
width: 100
},{
field: 'ot_price',
title: '原价',
align: 'center',
width: 100
},{
field: 'stock',
title: '总库存',
align: 'center',
width: 100
}, {
fixed: 'right',
field: 'right',
title: '操作',
toolbar: '#barDemo',
width: 136,
align: 'center'
}
]
]
});
//监听表头工具栏事件
table.on('toolbar(store_product)', function(obj){
if (obj.event === 'add') {
tool.side("/admin/store_product/add");
return false;
}
});
//监听表格行工具事件
table.on('tool(store_product)', function(obj) {
var data = obj.data;
if (obj.event === 'read') {
tool.side('/admin/store_product/read?product_id='+obj.data.product_id);
}
else if (obj.event === 'edit') {
tool.side('/admin/store_product/edit?product_id='+obj.data.product_id);
}
else if (obj.event === 'del') {
layer.confirm('确定要删除该记录吗?', {
icon: 3,
title: '提示'
}, function(index) {
let callback = function (e) {
layer.msg(e.msg);
if (e.code == 0) {
obj.del();
}
}
tool.delete("/admin/store_product/del", { product_id: data.product_id }, callback);
layer.close(index);
});
}
return false;
});
//监听搜索提交
form.on('submit(searchform)', function(data) {
layui.pageTable.reload({
where: {
keywords: data.field.keywords
},
page: {
curr: 1
}
});
return false;
});
}
</script>
{/block}
<!-- /脚本 -->

View File

@ -0,0 +1,222 @@
{extend name="common/base"/}
{block name="style"}
<style type="text/css">
.editormd-code-toolbar select {
display: inline-block
}
.editormd li {
list-style: inherit;
}
</style>
{/block}
<!-- 主体 -->
{block name="body"}
<form class="layui-form p-4">
<h3 class="pb-3">编辑文章表</h3>
<table class="layui-table layui-table-form">
<tr>
<td class="layui-td-gray">商品名称<font>*</font></td>
<td colspan="7"><input type="text" name="store_name" lay-verify="required" lay-reqText="请输入商品名称"
autocomplete="off" placeholder="请输入商品名称" class="layui-input" value="{$detail.store_name}"></td>
</tr>
<!-- <tr>-->
<!-- <td class="layui-td-gray">平台商品分类<font>*</font></td>-->
<!-- <td colspan="3">-->
<!-- <div class="layui-col-md6">-->
<!-- <select name="cate_id" lay-verify="required" lay-search="">-->
<!-- <option value="" >请选择</option>-->
<!-- {volist name=':set_recursion(get_store_category())' id='vo'}-->
<!-- <option value="{$vo.id}" >{$vo.title}</option>-->
<!-- {/volist}-->
<!-- </select>-->
<!-- </div>-->
<!-- </td>-->
<!-- </tr>-->
<tr>
<td class="layui-td-gray">平台商品分类<font>*</font></td>
<td colspan="3">
<div class="layui-col-md6">
<select name="cate_id" lay-verify="required" lay-search="">
<option value="" >请选择</option>
{volist name=':set_recursion(get_store_category())' id='vo'}
<option value="{$vo.id}" {if $detail.cate_id==$vo.id} selected {/if}>{$vo.title}</option>
{/volist}
</select>
</div>
</td>
</tr>
<tr>
<td class="layui-td-gray">品牌选择<font>*</font></td>
<td colspan="3">
<div class="layui-col-md6">
<select name="brand_id" lay-verify="required" lay-search="">
<option value="" >请选择</option>
{volist name='store_brand' id='vo'}
<option value="{$vo.brand_id}" {if $detail.brand_id==$vo.brand_id} selected {/if}>{$vo.brand_name}</option>
{/volist}
</select>
</div>
</td>
</tr>
<tr>
<td class="layui-td-gray" style="vertical-align:top;">商品封面图</td>
<td>
<div class="layui-upload">
<button type="button" class="layui-btn layui-btn-sm" id="upload_btn_thumb">
上传缩略图(尺寸:428x270)
</button>
<div class="layui-upload-list" id="upload_box_thumb"
style="width: 428px; height:270px; overflow: hidden;">
<img src="{$detail.image}"
onerror="javascript:this.src='{__GOUGU__}/gougu/images/nonepic600x360.jpg';this.onerror=null;"
width="100" style="max-width: 100%; height:66px;"/>
<input type="hidden" name="image" value="{$detail.image}">
</div>
</div>
</td>
</tr>
<tr>
<td class="layui-td-gray" style="vertical-align:top;">商品轮播图</td>
<td>
<div class="layui-upload">
<button type="button" class="layui-btn layui-btn-sm" id="upload_btn_thumb2">
上传缩略图(尺寸:428x270)
</button>
<div class="layui-upload-list" id="upload_box_thumb2"
style="width: 428px; height:270px; overflow: hidden;">
<img src="{$detail.slider_image}"
onerror="javascript:this.src='{__GOUGU__}/gougu/images/nonepic600x360.jpg';this.onerror=null;"
width="100" style="max-width: 100%; height:66px;"/>
<input type="hidden" name="slider_image" value="{$detail.slider_image}">
</div>
</div>
</td>
</tr>
<tr>
<td class="layui-td-gray">单位<font>*</font></td>
<td colspan="7"><input type="text" name="unit_name" lay-verify="required" lay-reqText="请输入单位"
autocomplete="off" placeholder="请输入单位" class="layui-input" value="{$detail.unit_name}"></td>
</tr>
<tr>
<td class="layui-td-gray">商品关键字<font>*</font></td>
<td colspan="7"><input type="text" name="keyword" lay-verify="required" lay-reqText="请输入商品关键字"
autocomplete="off" placeholder="请输入商品关键字" class="layui-input" value="{$detail.keyword}"></td>
</tr>
<tr>
<td class="layui-td-gray">售价<font>*</font></td>
<td colspan="7"><input type="text" name="price" lay-verify="required" lay-reqText="请输入商品关键字"
autocomplete="off" placeholder="请输入商品关键字" class="layui-input" value="{$detail.price}"></td>
</tr>
<tr>
<td class="layui-td-gray">成本价<font>*</font></td>
<td colspan="7"><input type="text" name="cost" lay-verify="required" lay-reqText="请输入商品关键字"
autocomplete="off" placeholder="请输入商品关键字" class="layui-input" value="{$detail.cost}"></td>
</tr>
<tr>
<td class="layui-td-gray">市场价<font>*</font></td>
<td colspan="7"><input type="text" name="ot_price" lay-verify="required" lay-reqText="请输入商品关键字"
autocomplete="off" placeholder="请输入商品关键字" class="layui-input" value="{$detail.ot_price}"></td>
</tr>
<tr>
<td class="layui-td-gray">库存<font>*</font></td>
<td colspan="7"><input type="text" name="stock" lay-verify="required" lay-reqText="请输入商品关键字"
autocomplete="off" placeholder="请输入商品关键字" class="layui-input" value="{$detail.stock}"></td>
</tr>
<tr>
<td class="layui-td-gray" style="text-align:left">商品简介</td>
<td colspan="6">
<textarea class="layui-textarea" name="store_info">{$detail.store_info}</textarea>
</td>
</tr>
<tr>
<td class="layui-td-gray" style="text-align:left">商品详情</td>
<td colspan="6">
<textarea class="layui-textarea" id="container_content">{$detail.content}</textarea>
</td>
</tr>
</table>
<div class="pt-3">
<input type="hidden" name="product_id" value="{$detail.product_id}"/>
<button class="layui-btn layui-btn-normal" lay-submit="" lay-filter="webform">立即提交</button>
<button type="reset" class="layui-btn layui-btn-primary">重置</button>
</div>
</form>
{/block}
<!-- /主体 -->
<!-- 脚本 -->
{block name="script"}
<script src="/static/assets/js/xm-select.js"></script>
<script>
var moduleInit = ['tool', 'tagpicker', 'tinymce'];
var group_access = "{:session('gougu_admin')['group_access']}"
function gouguInit() {
var form = layui.form, tool = layui.tool, tagpicker = layui.tagpicker;
//上传缩略图
var upload_thumb = layui.upload.render({
elem: '#upload_btn_thumb',
url: '/admin/api/upload',
done: function (res) {
//如果上传失败
if (res.code == 1) {
layer.msg('上传失败');
return false;
}
//上传成功
$('#upload_box_thumb input').attr('value', res.data.filepath);
$('#upload_box_thumb img').attr('src', res.data.filepath);
}
});
//上传商品轮播图
var upload_thumb = layui.upload.render({
elem: '#upload_btn_thumb2',
url: '/admin/api/upload',
done: function (res) {
//如果上传失败
if (res.code == 1) {
return layer.msg('上传失败');
}
//上传成功
$('#upload_box_thumb2 input').attr('value', res.data.filepath);
$('#upload_box_thumb2 img').attr('src', res.data.filepath);
}
});
var editor = layui.tinymce;
var edit = editor.render({
selector: "#container_content",
height: 500
});
//监听提交
form.on('submit(webform)', function (data) {
data.field.content = tinyMCE.editors['container_content'].getContent();
if (data.field.content == '') {
layer.msg('请先完善商品详情');
return false;
}
let callback = function (e) {
layer.msg(e.msg);
if (e.code == 0) {
tool.sideClose(1000);
}
}
tool.post("/admin/store_product/edit", data.field, callback);
return false;
});
}
</script>
{/block}
<!-- /脚本 -->

View File

@ -0,0 +1,144 @@
{extend name="common/base"/}
{block name="style"}
<style>
.content-article img{max-width:88%!important; height:auto!important; margin:6px 0!important; border-radius:4px;}
</style>
{/block}
<!-- 主体 -->
{block name="body"}
<div class="layui-form p-4">
<h3 class="pb-3">文章详情</h3>
<table class="layui-table layui-table-form">
<tr>
<td class="layui-td-gray">商品名称<font>*</font></td>
<td colspan="7"><input type="text" name="store_name" lay-verify="required" lay-reqText="请输入商品名称"
autocomplete="off" placeholder="请输入商品名称" class="layui-input" value="{$detail.store_name}"></td>
</tr>
<!-- <tr>-->
<!-- <td class="layui-td-gray">平台商品分类<font>*</font></td>-->
<!-- <td colspan="3">-->
<!-- <div class="layui-col-md6">-->
<!-- <select name="cate_id" lay-verify="required" lay-search="">-->
<!-- <option value="" >请选择</option>-->
<!-- {volist name=':set_recursion(get_store_category())' id='vo'}-->
<!-- <option value="{$vo.id}" >{$vo.title}</option>-->
<!-- {/volist}-->
<!-- </select>-->
<!-- </div>-->
<!-- </td>-->
<!-- </tr>-->
<tr>
<td class="layui-td-gray">商户商品分类<font>*</font></td>
<td colspan="3">
<div class="layui-col-md6">
<select name="cate_id" lay-verify="required" lay-search="">
<option value="" >请选择</option>
{volist name=':set_recursion(get_store_category())' id='vo'}
<option value="{$vo.id}" {if $detail.cate_id==$vo.id} selected {/if}>{$vo.title}</option>
{/volist}
</select>
</div>
</td>
</tr>
<tr>
<td class="layui-td-gray">品牌选择<font>*</font></td>
<td colspan="3">
<div class="layui-col-md6">
<select name="brand_id" lay-verify="required" lay-search="">
<option value="" >请选择</option>
{volist name='store_brand' id='vo'}
<option value="{$vo.brand_id}" {if $detail.brand_id==$vo.brand_id} selected {/if}>{$vo.brand_name}</option>
{/volist}
</select>
</div>
</td>
</tr>
<tr>
<td class="layui-td-gray" style="vertical-align:top;">商品封面图</td>
<td>
<div class="layui-upload">
<button type="button" class="layui-btn layui-btn-sm" id="upload_btn_thumb">
上传缩略图(尺寸:428x270)
</button>
<div class="layui-upload-list" id="upload_box_thumb"
style="width: 428px; height:270px; overflow: hidden;">
<img src="{$detail.image}"
onerror="javascript:this.src='{__GOUGU__}/gougu/images/nonepic600x360.jpg';this.onerror=null;"
width="100" style="max-width: 100%; height:66px;"/>
<input type="hidden" name="image" value="{$detail.image}">
</div>
</div>
</td>
</tr>
<tr>
<td class="layui-td-gray" style="vertical-align:top;">商品轮播图</td>
<td>
<div class="layui-upload">
<button type="button" class="layui-btn layui-btn-sm" id="upload_btn_thumb2">
上传缩略图(尺寸:428x270)
</button>
<div class="layui-upload-list" id="upload_box_thumb2"
style="width: 428px; height:270px; overflow: hidden;">
<img src="{$detail.slider_image}"
onerror="javascript:this.src='{__GOUGU__}/gougu/images/nonepic600x360.jpg';this.onerror=null;"
width="100" style="max-width: 100%; height:66px;"/>
<input type="hidden" name="slider_image" value="{$detail.slider_image}">
</div>
</div>
</td>
</tr>
<tr>
<td class="layui-td-gray">单位<font>*</font></td>
<td colspan="7"><input type="text" name="unit_name" lay-verify="required" lay-reqText="请输入单位"
autocomplete="off" placeholder="请输入单位" class="layui-input" value="{$detail.unit_name}"></td>
</tr>
<tr>
<td class="layui-td-gray">商品关键字<font>*</font></td>
<td colspan="7"><input type="text" name="keyword" lay-verify="required" lay-reqText="请输入商品关键字"
autocomplete="off" placeholder="请输入商品关键字" class="layui-input" value="{$detail.keyword}"></td>
</tr>
<tr>
<td class="layui-td-gray">售价<font>*</font></td>
<td colspan="7"><input type="text" name="price" lay-verify="required" lay-reqText="请输入商品关键字"
autocomplete="off" placeholder="请输入商品关键字" class="layui-input" value="{$detail.price}"></td>
</tr>
<tr>
<td class="layui-td-gray">成本价<font>*</font></td>
<td colspan="7"><input type="text" name="cost" lay-verify="required" lay-reqText="请输入商品关键字"
autocomplete="off" placeholder="请输入商品关键字" class="layui-input" value="{$detail.cost}"></td>
</tr>
<tr>
<td class="layui-td-gray">市场价<font>*</font></td>
<td colspan="7"><input type="text" name="ot_price" lay-verify="required" lay-reqText="请输入商品关键字"
autocomplete="off" placeholder="请输入商品关键字" class="layui-input" value="{$detail.ot_price}"></td>
</tr>
<tr>
<td class="layui-td-gray">库存<font>*</font></td>
<td colspan="7"><input type="text" name="stock" lay-verify="required" lay-reqText="请输入商品关键字"
autocomplete="off" placeholder="请输入商品关键字" class="layui-input" value="{$detail.stock}"></td>
</tr>
<tr>
<td class="layui-td-gray" style="text-align:left">商品简介</td>
<td colspan="6">
<textarea class="layui-textarea" name="store_info">{$detail.store_info}</textarea>
</td>
</tr>
<tr>
<td class="layui-td-gray" style="text-align:left">商品详情</td>
<td colspan="6">
<textarea class="layui-textarea" id="container_content">{$detail.content}</textarea>
</td>
</tr>
</table>
</div>
{/block}
<!-- /主体 -->

View File

@ -0,0 +1,120 @@
<?php
namespace app\api\controller;
use app\api\BaseController;
use app\api\middleware\Auth;
use think\exception\ValidateException;
use think\facade\Db;
/**
* 商品接口
*/
class StoreProduct extends BaseController
{
/**
* 控制器中间件 [不需要鉴权]
* @var array
*/
protected $middleware = [
Auth::class => ['except' => ['list','add'] ]
];
/**
* 商品列表
*/
public function list($page=0,$limit=10){
$post = get_params();
$where[] = ['status','=',1];
$where[] = ['is_del','=',0];
$where[] = ['is_show','=',1];
if(empty($post['mer_id'])){
$this->apiError('缺少参数');
}
$log = Db::table('cms_store_add_log')->where('mer_id',$post['mer_id'])->column('product_id');
if($log){
$where[] = ['product_id','not in',$log];
}
$res = Db::table('cms_store_product')
->where($where)
->page($page,$limit)
->order('sort desc id desc')
->select();
$this->apiSuccess('OK',$res);
}
/**
* 一键导入商品
*/
public function add(){
$post = get_params();
if(empty($post['mer_id']) || empty($post['product_ids'])){
$this->apiError('缺少参数');
}
Db::startTrans();
try {
$where[] = ['product_id','in',$post['product_ids']];
$data = Db::table('cms_store_product')->where($where)->select()->toArray();
if($data){
$day = date('Y-m-d H:i:s');
$log['mer_id'] = $post['mer_id'];
$log['create_time'] = $day;
foreach ($data as $k =>$v){
//写入导入记录
$log['product_id'] = $v['product_id'];
Db::table('cms_store_add_log')->insert($log);
$old_product_id = $v['product_id'];
unset($v['product_id']);
//导入商品表
$v['mer_id'] = $post['mer_id'];
$product_id = Db::connect('shop')->table('eb_store_product')->insertGetId($v);
// 写入商品搜索信息表
$store_spu['mer_id'] = $post['mer_id'];
$store_spu['product_id'] = $product_id;
$store_spu['status'] = 1;
$store_spu['store_name'] = $v['store_name'];
$store_spu['keyword'] = $v['mer_id'];
$store_spu['price'] = $v['price'];
$store_spu['rank'] = $v['sort'];
$store_spu['create_time'] = $day;
$store_spu['temp_id'] = $v['temp_id'];
Db::connect('shop')->table('eb_store_spu')->insert($store_spu);
// 写入商品详情表
$ccc = Db::table('cms_store_product_content')->where('product_id',$old_product_id)->value('content');
$content['content'] = $ccc ??'';
$content['product_id'] = $product_id;
Db::connect('shop')->table('eb_store_product_content')->insert($content);
// 写入SKU表
$attr['product_id'] = $product_id;
$attr['sku'] = ' '; //库存
$attr['stock'] = $v['stock']; //库存
$attr['image'] = $v['image'];
$attr['cost'] = $v['cost'];//成本价
$attr['ot_price'] = $v['ot_price'];//原价
$attr['price'] = $v['price'];//价格
$attr['unique'] = set_salt(12);//唯一值
$attr['svip_price'] = $v['svip_price'];//会员价
Db::connect('shop')->table('eb_store_product_attr_value')->insert($attr);
// 写入商品商户分类关联表
$cate['product_id'] = $product_id;
$cate['mer_cate_id'] = $v['cate_id'];
$cate['mer_id'] = $post['mer_id'];
Db::connect('shop')->table('eb_store_product_cate')->insert($cate);
}
}
Db::commit();
$this->apiSuccess('操作成功');
} catch (ValidateException $e) {
Db::rollback();
$this->apiError($e->getMessage());
}
}
}