作者 何书鹏
1 个管道 的构建 通过 耗费 6 秒

规格修改

<?php
namespace app\admin\controller;
use app\common\controller\Backend;
/**
* 商品评价管理
*
* @icon fa fa-circle-o
*/
class Appraise extends Backend
{
/**
* Appraise模型对象
* @var \app\admin\model\Appraise
*/
protected $model = null;
public function _initialize()
{
parent::_initialize();
$this->model = new \app\admin\model\Appraise;
}
public function import()
{
parent::import();
}
/**
* 默认生成的控制器所继承的父类中有index/add/edit/del/multi五个基础方法、destroy/restore/recyclebin三个回收站方法
* 因此在当前控制器中可不用编写增删改查的代码,除非需要自己控制这部分逻辑
* 需要将application/admin/library/traits/Backend.php中对应的方法复制到当前控制器,然后进行修改
*/
/**
* 查看
*/
public function index()
{
//当前是否为关联查询
$this->relationSearch = false;
//设置过滤方法
$this->request->filter(['strip_tags', 'trim']);
if ($this->request->isAjax())
{
//如果发送的来源是Selectpage,则转发到Selectpage
if ($this->request->request('keyField'))
{
return $this->selectpage();
}
list($where, $sort, $order, $offset, $limit) = $this->buildparams();
$total = $this->model
->where($where)
->order($sort, $order)
->count();
$list = $this->model
->where($where)
->order($sort, $order)
->limit($offset, $limit)
->select();
foreach ($list as $row) {
$row->visible(['id','appraise_content','appraise_images','appraise_star','user_id','createtime']);
}
$list = collection($list)->toArray();
$result = array("total" => $total, "rows" => $list);
return json($result);
}
return $this->view->fetch();
}
}
... ...
... ... @@ -117,7 +117,7 @@ class Goods extends Backend
// 添加商品与规格关系记录
$goods_spec->addGoodsSpecRel($this->model['id'], $spec_many['spec_attr']);
// 添加商品sku
$goods_spec->addSkuList($this->model['id'], $spec_many['spec_list']);
$goods_spec->addSkuList($this->model['id'], $spec_many['goods_spec_list']);
}
Db::commit();
} catch (ValidateException $e) {
... ... @@ -172,16 +172,17 @@ class Goods extends Backend
$result = $row->allowField(true)->save($params);
// 更新模式: 先删除所有规格
$goods_spec = new \app\admin\model\GoodsSpec;
$goods_spec->removeAll($params['id']);
$goods_spec->removeAll($row['id']);
// 添加规格数据
if ($params['spec_type'] == '1') {
// 单规格
$row->spec()->save($data['spec']);
$row->spec()->save($params['spec']);
} else if ($params['spec_type'] == '2') {
$spec_many = json_decode($params['spec_many'],true);
// 添加商品与规格关系记录
$goods_spec->addGoodsSpecRel($params['id'], $params['spec_many']['spec_attr']);
$goods_spec->addGoodsSpecRel($row['id'], $spec_many['spec_attr']);
// 添加商品sku
$goods_spec->addSkuList($params['id'], $params['spec_many']['spec_list']);
$goods_spec->addSkuList($row['id'], $spec_many['goods_spec_list']);
}
Db::commit();
} catch (ValidateException $e) {
... ... @@ -203,7 +204,7 @@ class Goods extends Backend
$this->error(__('Parameter %s can not be empty', ''));
}
$this->view->assign("row", $row);
$this->assignconfig('specData', $row['spec_type'] == '2' ? json_encode($row->getManySpecData($row['spec_rel'], $row['spec'])) : []);
$this->assignconfig('specData', $row['spec_type'] == '2' ? $row->getManySpecData($row['spec_rel'], $row['spec']) : null);
return $this->view->fetch();
}
... ...
<?php
return [
'Appraise_content' => '评价内容',
'Appraise_images' => '评价图片',
'Appraise_star' => '评价星级',
'User_id' => '用户id',
'Goods_id' => '商品id',
'Order_id' => '订单id',
'Createtime' => '创建时间'
];
... ...
<?php
namespace app\admin\model;
use think\Model;
class Appraise extends Model
{
// 表名
protected $name = 'appraise';
// 自动写入时间戳字段
protected $autoWriteTimestamp = 'int';
// 定义时间戳字段名
protected $createTime = 'createtime';
protected $updateTime = false;
protected $deleteTime = false;
// 追加属性
protected $append = [
];
}
... ...
... ... @@ -130,25 +130,25 @@ class Goods extends Model
{
// spec_attr
$specAttrData = [];
foreach ($spec_rel->toArray() as $item) {
foreach ($spec_rel as $item) {
if (!isset($specAttrData[$item['spec_id']])) {
$specAttrData[$item['spec_id']] = [
'group_id' => $item['spec']['spec_id'],
'group_name' => $item['spec']['spec_name'],
'spec_items' => [],
'spec_id' => $item['spec']['id'],
'spec_name' => $item['spec']['spec_name'],
'spec_value_list' => [],
];
}
$specAttrData[$item['spec_id']]['spec_items'][] = [
'item_id' => $item['spec_value_id'],
'spec_value' => $item['spec_value'],
$specAttrData[$item['spec_id']]['spec_value_list'][] = [
'spec_value_id' => $item['id'],
'spec_value_name' => $item['spec_value_name'],
];
}
// spec_list
$specListData = [];
foreach ($skuData->toArray() as $item) {
$specListData[] = [
'goods_spec_id' => $item['goods_spec_id'],
$goods_spec_list = [];
foreach ($skuData as $item) {
$goods_spec_list[] = [
'goods_spec_id' => $item['id'],
'spec_sku_id' => $item['spec_sku_id'],
'rows' => [],
'form' => [
... ... @@ -158,7 +158,7 @@ class Goods extends Model
],
];
}
return ['spec_attr' => array_values($specAttrData), 'spec_list' => $specListData];
return ['spec_attr' => array_values($specAttrData), 'goods_spec_list' => $goods_spec_list];
}
}
... ...
... ... @@ -48,10 +48,10 @@ class GoodsSpec extends Model
array_map(function ($item) use (&$val, &$data, $goods_id) {
$data[] = [
'goods_id' => $goods_id,
'spec_id' => $val['group_id'],
'spec_value_id' => $item['item_id'],
'spec_id' => $val['spec_id'],
'spec_value_id' => $item['spec_value_id'],
];
}, $val['spec_items']);
}, $val['spec_value_list']);
}, $spec_attr);
$model = new GoodsSpecRel;
return $model->saveAll($data);
... ...
... ... @@ -23,4 +23,12 @@ class GoodsSpecRel extends Model
protected $updateTime = false;
protected $deleteTime = false;
/**
* 关联规格组
*/
public function spec()
{
return $this->belongsTo('Spec');
}
}
... ...
... ... @@ -18,10 +18,15 @@ class SpecValue extends Model
protected $deleteTime = false;
/**
* 新增规格值
*/
public function spec()
{
return $this->belongsTo('Spec');
}
/**
* 根据规格组名称查询规格id
* @param $spec_id
* @param $spec_value
* @return mixed
*/
public function getSpecValueIdByName($spec_id, $spec_value_name)
{
... ... @@ -30,9 +35,6 @@ class SpecValue extends Model
/**
* 新增规格值
* @param $spec_id
* @param $spec_value
* @return false|int
*/
public function add($spec_id, $spec_value_name)
{
... ...
<?php
namespace app\admin\validate;
use think\Validate;
class Appraise extends Validate
{
/**
* 验证规则
*/
protected $rule = [
];
/**
* 提示消息
*/
protected $message = [
];
/**
* 验证场景
*/
protected $scene = [
'add' => [],
'edit' => [],
];
}
... ...
<form id="add-form" class="form-horizontal" role="form" data-toggle="validator" method="POST" action="">
<div class="form-group">
<label class="control-label col-xs-12 col-sm-2">{:__('Appraise_content')}:</label>
<div class="col-xs-12 col-sm-8">
<input id="c-appraise_content" data-rule="required" class="form-control" name="row[appraise_content]" type="text" value="">
</div>
</div>
<div class="form-group">
<label class="control-label col-xs-12 col-sm-2">{:__('Appraise_images')}:</label>
<div class="col-xs-12 col-sm-8">
<div class="input-group">
<input id="c-appraise_images" data-rule="required" class="form-control" size="50" name="row[appraise_images]" type="text" value="">
<div class="input-group-addon no-border no-padding">
<span><button type="button" id="plupload-appraise_images" class="btn btn-danger plupload" data-input-id="c-appraise_images" data-mimetype="image/gif,image/jpeg,image/png,image/jpg,image/bmp" data-multiple="true" data-preview-id="p-appraise_images"><i class="fa fa-upload"></i> {:__('Upload')}</button></span>
<span><button type="button" id="fachoose-appraise_images" class="btn btn-primary fachoose" data-input-id="c-appraise_images" data-mimetype="image/*" data-multiple="true"><i class="fa fa-list"></i> {:__('Choose')}</button></span>
</div>
<span class="msg-box n-right" for="c-appraise_images"></span>
</div>
<ul class="row list-inline plupload-preview" id="p-appraise_images"></ul>
</div>
</div>
<div class="form-group">
<label class="control-label col-xs-12 col-sm-2">{:__('Appraise_star')}:</label>
<div class="col-xs-12 col-sm-8">
<input id="c-appraise_star" data-rule="required" class="form-control" name="row[appraise_star]" type="number" value="0">
</div>
</div>
<div class="form-group">
<label class="control-label col-xs-12 col-sm-2">{:__('User_id')}:</label>
<div class="col-xs-12 col-sm-8">
<input id="c-user_id" data-rule="required" data-source="user/user/index" data-field="nickname" class="form-control selectpage" name="row[user_id]" type="text" value="">
</div>
</div>
<div class="form-group">
<label class="control-label col-xs-12 col-sm-2">{:__('Goods_id')}:</label>
<div class="col-xs-12 col-sm-8">
<input id="c-goods_id" data-rule="required" data-source="goods/index" class="form-control selectpage" name="row[goods_id]" type="text" value="">
</div>
</div>
<div class="form-group">
<label class="control-label col-xs-12 col-sm-2">{:__('Order_id')}:</label>
<div class="col-xs-12 col-sm-8">
<input id="c-order_id" data-rule="required" data-source="order/index" class="form-control selectpage" name="row[order_id]" type="text" value="">
</div>
</div>
<div class="form-group layer-footer">
<label class="control-label col-xs-12 col-sm-2"></label>
<div class="col-xs-12 col-sm-8">
<button type="submit" class="btn btn-success btn-embossed disabled">{:__('OK')}</button>
<button type="reset" class="btn btn-default btn-embossed">{:__('Reset')}</button>
</div>
</div>
</form>
... ...
<form id="edit-form" class="form-horizontal" role="form" data-toggle="validator" method="POST" action="">
<div class="form-group">
<label class="control-label col-xs-12 col-sm-2">{:__('Appraise_content')}:</label>
<div class="col-xs-12 col-sm-8">
<input id="c-appraise_content" data-rule="required" class="form-control" name="row[appraise_content]" type="text" value="{$row.appraise_content|htmlentities}">
</div>
</div>
<div class="form-group">
<label class="control-label col-xs-12 col-sm-2">{:__('Appraise_images')}:</label>
<div class="col-xs-12 col-sm-8">
<div class="input-group">
<input id="c-appraise_images" data-rule="required" class="form-control" size="50" name="row[appraise_images]" type="text" value="{$row.appraise_images|htmlentities}">
<div class="input-group-addon no-border no-padding">
<span><button type="button" id="plupload-appraise_images" class="btn btn-danger plupload" data-input-id="c-appraise_images" data-mimetype="image/gif,image/jpeg,image/png,image/jpg,image/bmp" data-multiple="true" data-preview-id="p-appraise_images"><i class="fa fa-upload"></i> {:__('Upload')}</button></span>
<span><button type="button" id="fachoose-appraise_images" class="btn btn-primary fachoose" data-input-id="c-appraise_images" data-mimetype="image/*" data-multiple="true"><i class="fa fa-list"></i> {:__('Choose')}</button></span>
</div>
<span class="msg-box n-right" for="c-appraise_images"></span>
</div>
<ul class="row list-inline plupload-preview" id="p-appraise_images"></ul>
</div>
</div>
<div class="form-group">
<label class="control-label col-xs-12 col-sm-2">{:__('Appraise_star')}:</label>
<div class="col-xs-12 col-sm-8">
<input id="c-appraise_star" data-rule="required" class="form-control" name="row[appraise_star]" type="number" value="{$row.appraise_star|htmlentities}">
</div>
</div>
<div class="form-group">
<label class="control-label col-xs-12 col-sm-2">{:__('User_id')}:</label>
<div class="col-xs-12 col-sm-8">
<input id="c-user_id" data-rule="required" data-source="user/user/index" data-field="nickname" class="form-control selectpage" name="row[user_id]" type="text" value="{$row.user_id|htmlentities}">
</div>
</div>
<div class="form-group">
<label class="control-label col-xs-12 col-sm-2">{:__('Goods_id')}:</label>
<div class="col-xs-12 col-sm-8">
<input id="c-goods_id" data-rule="required" data-source="goods/index" class="form-control selectpage" name="row[goods_id]" type="text" value="{$row.goods_id|htmlentities}">
</div>
</div>
<div class="form-group">
<label class="control-label col-xs-12 col-sm-2">{:__('Order_id')}:</label>
<div class="col-xs-12 col-sm-8">
<input id="c-order_id" data-rule="required" data-source="order/index" class="form-control selectpage" name="row[order_id]" type="text" value="{$row.order_id|htmlentities}">
</div>
</div>
<div class="form-group layer-footer">
<label class="control-label col-xs-12 col-sm-2"></label>
<div class="col-xs-12 col-sm-8">
<button type="submit" class="btn btn-success btn-embossed disabled">{:__('OK')}</button>
<button type="reset" class="btn btn-default btn-embossed">{:__('Reset')}</button>
</div>
</div>
</form>
... ...
<div class="panel panel-default panel-intro">
{:build_heading()}
<div class="panel-body">
<div id="myTabContent" class="tab-content">
<div class="tab-pane fade active in" id="one">
<div class="widget-body no-padding">
<div id="toolbar" class="toolbar">
<a href="javascript:;" class="btn btn-primary btn-refresh" title="{:__('Refresh')}" ><i class="fa fa-refresh"></i> </a>
<a href="javascript:;" class="btn btn-success btn-add {:$auth->check('appraise/add')?'':'hide'}" title="{:__('Add')}" ><i class="fa fa-plus"></i> {:__('Add')}</a>
<a href="javascript:;" class="btn btn-success btn-edit btn-disabled disabled {:$auth->check('appraise/edit')?'':'hide'}" title="{:__('Edit')}" ><i class="fa fa-pencil"></i> {:__('Edit')}</a>
<a href="javascript:;" class="btn btn-danger btn-del btn-disabled disabled {:$auth->check('appraise/del')?'':'hide'}" title="{:__('Delete')}" ><i class="fa fa-trash"></i> {:__('Delete')}</a>
<a href="javascript:;" class="btn btn-danger btn-import {:$auth->check('appraise/import')?'':'hide'}" title="{:__('Import')}" id="btn-import-file" data-url="ajax/upload" data-mimetype="csv,xls,xlsx" data-multiple="false"><i class="fa fa-upload"></i> {:__('Import')}</a>
<div class="dropdown btn-group {:$auth->check('appraise/multi')?'':'hide'}">
<a class="btn btn-primary btn-more dropdown-toggle btn-disabled disabled" data-toggle="dropdown"><i class="fa fa-cog"></i> {:__('More')}</a>
<ul class="dropdown-menu text-left" role="menu">
<li><a class="btn btn-link btn-multi btn-disabled disabled" href="javascript:;" data-params="status=normal"><i class="fa fa-eye"></i> {:__('Set to normal')}</a></li>
<li><a class="btn btn-link btn-multi btn-disabled disabled" href="javascript:;" data-params="status=hidden"><i class="fa fa-eye-slash"></i> {:__('Set to hidden')}</a></li>
</ul>
</div>
</div>
<table id="table" class="table table-striped table-bordered table-hover table-nowrap"
data-operate-edit="{:$auth->check('appraise/edit')}"
data-operate-del="{:$auth->check('appraise/del')}"
width="100%">
</table>
</div>
</div>
</div>
</div>
</div>
... ...
... ... @@ -102,23 +102,22 @@
</div>
<!--规格-->
<style>
.goods-spec-many { display: none; /* 添加规格组 */ /* sku容器 */ }
.goods-spec-many { margin-top: 15px; border: 1px solid #e4e4e4; padding: 20px; border-radius: 4px; }
.goods-spec-many { display: none; margin-top: 15px; border: 1px solid #e4e4e4; padding: 20px; border-radius: 4px; /* 添加规格组 */ /* sku容器 */ }
.goods-spec-many input { font-size: 1.3rem !important; padding-left: 10px !important; border: 1px solid #e3e2e5 !important; }
.goods-spec-many input.am-field-error { border-color: #dd514c !important; }
.goods-spec-many .spec-group-item { margin-bottom: 25px; }
.goods-spec-many .spec-group-item .spec-group-name { margin-bottom: 15px; }
.goods-spec-many .spec-group-item .spec-group-name span { font-size: 1.5rem; }
.goods-spec-many .spec-group-item .spec-group-name .icon-shanchu1 { display: inline-block; }
.goods-spec-many .spec-group-item .spec-list .spec-item { margin-right: 12px; margin-bottom: 12px; }
.goods-spec-many .spec-group-item .spec-list .spec-item span { min-width: 50px; display: inline-block; border: 1px solid #ddd; text-align: center; padding: 0 15px; border-radius: 2px; font-size: 1.3rem; line-height: 30px; }
.goods-spec-many .spec-group-item .spec-item-add input { width: 110px; border-top-left-radius: 4px; border-bottom-left-radius: 4px; }
.goods-spec-many .spec-group-item .spec-item-add button { display: table-cell; height: 32px; font-size: 1.3rem; border-color: #e3e2e5; border-left: none; border-top-right-radius: 4px; border-bottom-right-radius: 4px; outline: none; }
.goods-spec-many .spec-group-button button { color: #2589ff; background-color: #fff; border-color: #2589ff; font-size: 12px; border-radius: 4px; outline: 0; font-weight: 400; padding: .6em 1em; outline: none !important; }
.goods-spec-many .spec-group-button button:hover, .goods-spec-many .spec-group-button button:focus { color: #fbfbfb; background-color: #19a7f0; }
.goods-spec-many .spec-group-add { display: none; }
.goods-spec-many .spec-group-add .spec-group-add-item { margin-bottom: 10px; }
.goods-spec-many .spec-group-add .spec-group-add-item input { width: 160px; border-radius: 4px; display: inline-block; margin-left: 12px; }
.goods-spec-many .spec { margin-bottom: 25px; }
.goods-spec-many .spec .spec-name { margin-bottom: 15px; }
.goods-spec-many .spec .spec-name span { font-size: 1.5rem; }
.goods-spec-many .spec .spec-name .icon-shanchu1 { display: inline-block; }
.goods-spec-many .spec .spec-value-list .spec-value { margin-right: 12px; margin-bottom: 12px; }
.goods-spec-many .spec .spec-value-list .spec-value span { min-width: 50px; display: inline-block; border: 1px solid #ddd; text-align: center; padding: 0 15px; border-radius: 2px; font-size: 1.3rem; line-height: 30px; }
.goods-spec-many .spec .spec-value-add input { width: 110px; border-top-left-radius: 4px; border-bottom-left-radius: 4px; }
.goods-spec-many .spec .spec-value-add button { display: table-cell; height: 32px; font-size: 1.3rem; border-color: #e3e2e5; border-left: none; border-top-right-radius: 4px; border-bottom-right-radius: 4px; outline: none; }
.goods-spec-many .spec-button button { color: #2589ff; background-color: #fff; border-color: #2589ff; font-size: 12px; border-radius: 4px; outline: 0; font-weight: 400; padding: .6em 1em; outline: none !important; }
.goods-spec-many .spec-button button:hover, .goods-spec-many .spec-button button:focus { color: #fbfbfb; background-color: #19a7f0; }
.goods-spec-many .spec-add { display: none; }
.goods-spec-many .spec-add .spec-add-item { margin-bottom: 10px; }
.goods-spec-many .spec-add .spec-add-item input { width: 160px; border-radius: 4px; display: inline-block; margin-left: 12px; }
.goods-spec-many .goods-sku { display: none; /* 批量设置sku */ /* 商品sku表格 */ }
.goods-spec-many .goods-sku .goods-spec-line { border: 1px dashed #e3e2e5; }
.goods-spec-many .goods-sku .spec-batch { margin-bottom: 2rem; }
... ... @@ -147,27 +146,27 @@
<div class="spec-attr"></div>
<!-- 添加规格:按钮 -->
<div class="spec-group-button">
<a href="javascript:;" class="btn btn-sm btn-success btn-addSpecGroup" style=""><i class="fa fa-plus"></i> 添加规格</a>
<div class="spec-button">
<a href="javascript:;" class="btn btn-sm btn-success btn-addSpec" style=""><i class="fa fa-plus"></i> 添加规格</a>
</div>
<!-- 添加规格:表单 -->
<div class="spec-group-add">
<div class="form-group spec-group-add-item">
<div class="spec-add">
<div class="form-group spec-add-value">
<label class="control-label col-xs-12 col-sm-3">规格名 </label>
<!-- <input type="text" class="input-specName tpl-form-input" placeholder="请输入规格名称"> -->
<div class="col-xs-12 col-sm-8">
<input class="form-control input-specName" type="text" placeholder="请输入规格名称">
</div>
</div>
<div class="spec-group-add-item form-group">
<div class="spec-add-value form-group">
<label class="control-label col-xs-12 col-sm-3">规格值 </label>
<!-- <input type="text" class="input-specValue tpl-form-input" placeholder="请输入规格值"> -->
<div class="col-xs-12 col-sm-8">
<input class="form-control input-specValue" type="text" placeholder="请输入规格值">
</div>
</div>
<div class="col-xs-12 col-sm-8 spec-group-add-item">
<div class="col-xs-12 col-sm-8 spec-add-value">
<button type="button" class="btn btn-success btn-embossed btn-addSpecName">确定</button>
<button type="button" class="btn btn-default btn-embossed btn-cancleAddSpecName">取消</button>
</div>
... ...
... ... @@ -102,29 +102,28 @@
</div>
<!--规格-->
<style>
.goods-spec-many { display: none; /* 添加规格组 */ /* sku容器 */ }
.goods-spec-many { margin-top: 15px; border: 1px solid #e4e4e4; padding: 20px; border-radius: 4px; }
.goods-spec-many { display: none; margin-top: 15px; border: 1px solid #e4e4e4; padding: 20px; border-radius: 4px; /* 添加规格组 */ /* sku容器 */ }
.goods-spec-many input { font-size: 1.3rem !important; padding-left: 10px !important; border: 1px solid #e3e2e5 !important; }
.goods-spec-many input.am-field-error { border-color: #dd514c !important; }
.goods-spec-many .spec-group-item { margin-bottom: 25px; }
.goods-spec-many .spec-group-item .spec-group-name { margin-bottom: 15px; }
.goods-spec-many .spec-group-item .spec-group-name span { font-size: 1.5rem; }
.goods-spec-many .spec-group-item .spec-group-name .icon-shanchu1 { display: inline-block; }
.goods-spec-many .spec-group-item .spec-list .spec-item { margin-right: 12px; margin-bottom: 12px; }
.goods-spec-many .spec-group-item .spec-list .spec-item span { min-width: 50px; display: inline-block; border: 1px solid #ddd; text-align: center; padding: 0 15px; border-radius: 2px; font-size: 1.3rem; line-height: 30px; }
.goods-spec-many .spec-group-item .spec-item-add input { width: 110px; border-top-left-radius: 4px; border-bottom-left-radius: 4px; }
.goods-spec-many .spec-group-item .spec-item-add button { display: table-cell; height: 32px; font-size: 1.3rem; border-color: #e3e2e5; border-left: none; border-top-right-radius: 4px; border-bottom-right-radius: 4px; outline: none; }
.goods-spec-many .spec-group-button button { color: #2589ff; background-color: #fff; border-color: #2589ff; font-size: 12px; border-radius: 4px; outline: 0; font-weight: 400; padding: .6em 1em; outline: none !important; }
.goods-spec-many .spec-group-button button:hover, .goods-spec-many .spec-group-button button:focus { color: #fbfbfb; background-color: #19a7f0; }
.goods-spec-many .spec-group-add { display: none; }
.goods-spec-many .spec-group-add .spec-group-add-item { margin-bottom: 10px; }
.goods-spec-many .spec-group-add .spec-group-add-item input { width: 160px; border-radius: 4px; display: inline-block; margin-left: 12px; }
.goods-spec-many .spec { margin-bottom: 25px; }
.goods-spec-many .spec .spec-name { margin-bottom: 15px; }
.goods-spec-many .spec .spec-name span { font-size: 1.5rem; }
.goods-spec-many .spec .spec-name .icon-shanchu1 { display: inline-block; }
.goods-spec-many .spec .spec-value-list .spec-value { margin-right: 12px; margin-bottom: 12px; }
.goods-spec-many .spec .spec-value-list .spec-value span { min-width: 50px; display: inline-block; border: 1px solid #ddd; text-align: center; padding: 0 15px; border-radius: 2px; font-size: 1.3rem; line-height: 30px; }
.goods-spec-many .spec .spec-value-add input { width: 110px; border-top-left-radius: 4px; border-bottom-left-radius: 4px; }
.goods-spec-many .spec .spec-value-add button { display: table-cell; height: 32px; font-size: 1.3rem; border-color: #e3e2e5; border-left: none; border-top-right-radius: 4px; border-bottom-right-radius: 4px; outline: none; }
.goods-spec-many .spec-button button { color: #2589ff; background-color: #fff; border-color: #2589ff; font-size: 12px; border-radius: 4px; outline: 0; font-weight: 400; padding: .6em 1em; outline: none !important; }
.goods-spec-many .spec-button button:hover, .goods-spec-many .spec-button button:focus { color: #fbfbfb; background-color: #19a7f0; }
.goods-spec-many .spec-add { display: none; }
.goods-spec-many .spec-add .spec-add-item { margin-bottom: 10px; }
.goods-spec-many .spec-add .spec-add-item input { width: 160px; border-radius: 4px; display: inline-block; margin-left: 12px; }
.goods-spec-many .goods-sku { display: none; /* 批量设置sku */ /* 商品sku表格 */ }
.goods-spec-many .goods-sku .goods-spec-line { border: 1px dashed #e3e2e5; }
.goods-spec-many .goods-sku .spec-batch { margin-bottom: 2rem; }
.goods-spec-many .goods-sku .spec-batch .am-form-label { padding-top: 0; }
.goods-spec-many .goods-sku .spec-batch .am-form-group { margin-left: .6rem; }
.goods-spec-many .goods-sku .spec-batch .am-form-group input { width: 140px; }
.goods-spec-many .goods-sku .spec-batch .form-group { margin-left: 0.6rem; }
.goods-spec-many .goods-sku .spec-batch .form-group input { width: 140px; }
.goods-spec-many .goods-sku .spec-sku-tabel td.td-spec-value { padding: .7rem 1.3rem !important; }
.goods-spec-many .goods-sku .spec-sku-tabel input { display: inline-block !important; }
.goods-spec-many .goods-sku .spec-sku-tabel input.ipt-goods-no { width: 140px; }
... ... @@ -141,32 +140,33 @@
</select>
<div class="form-group goods-spec-many">
<input type="hidden" name="row[spec_many]" value="0">
<div class="goods-spec-box col-xs-12 col-sm-8">
<!-- 规格属性 -->
<div class="spec-attr"></div>
<!-- 添加规格:按钮 -->
<div class="spec-group-button">
<a href="javascript:;" class="btn btn-sm btn-success btn-addSpecGroup" style=""><i class="fa fa-plus"></i> 添加规格</a>
<div class="spec-button">
<a href="javascript:;" class="btn btn-sm btn-success btn-addSpec" style=""><i class="fa fa-plus"></i> 添加规格</a>
</div>
<!-- 添加规格:表单 -->
<div class="spec-group-add">
<div class="form-group spec-group-add-item">
<div class="spec-add">
<div class="form-group spec-add-value">
<label class="control-label col-xs-12 col-sm-3">规格名 </label>
<!-- <input type="text" class="input-specName tpl-form-input" placeholder="请输入规格名称"> -->
<div class="col-xs-12 col-sm-8">
<input class="form-control input-specName" type="text" placeholder="请输入规格名称">
</div>
</div>
<div class="spec-group-add-item form-group">
<div class="spec-add-value form-group">
<label class="control-label col-xs-12 col-sm-3">规格值 </label>
<!-- <input type="text" class="input-specValue tpl-form-input" placeholder="请输入规格值"> -->
<div class="col-xs-12 col-sm-8">
<input class="form-control input-specValue" type="text" placeholder="请输入规格值">
</div>
</div>
<div class="col-xs-12 col-sm-8 spec-group-add-item">
<div class="col-xs-12 col-sm-8 spec-add-value">
<button type="button" class="btn btn-success btn-embossed btn-addSpecName">确定</button>
<button type="button" class="btn btn-default btn-embossed btn-cancleAddSpecName">取消</button>
</div>
... ...
... ... @@ -48,6 +48,8 @@ class Cart extends Api
* @ApiParams (name="goods_num", type="integer", required=true, description="商品数量")
* @ApiParams (name="goods_style", type="object", sample="{'1':'11','5':'15','7':'2','14':'25','15':'\/uploads\/20200711\/3689359dcdf1146d234930cae4958110.jpg','13':'21','12':'18'}", description="商品规格 {'风格ID':'风格值'}")
* @ApiParams (name="user_size_id", type="integer", description="用户尺寸ID")
* @ApiParams (name="spec_sku_id", type="string", description="商品sku")
* @ApiParams (name="isbuynow", type="string", description="是否立即购买:0=否,1=是")
* @ApiReturnParams (name="code", type="integer", required=true, sample="0")
* @ApiReturnParams (name="msg", type="string", required=true, sample="返回成功")
* @ApiReturnParams (name="data", type="object", description="扩展数据返回")
... ... @@ -191,7 +193,11 @@ class Cart extends Api
empty($data['cart_ids']) && $this->error(__('参数【cart_ids】不能为空'));
$order = $this->model->getList($this->user,['id'=>['in',$data['cart_ids']]],$data);
if (!$this->request->isPost()) {
return $this->success(__('成功'),$order);
$this->success(__('成功'),$order);
}
// 生成订单信息错误
if ($order->hasError()) {
$this->error($order->getError());
}
// 创建订单
$model = new \app\common\model\Order;
... ...
... ... @@ -40,6 +40,36 @@ class Category extends Api
$tree = Tree::instance();
$tree->init(collection($list)->toArray(), 'pid');
$list = $tree->getTreeArray(0);
// 拼接全部分类,方便前端展示
$all_list = [];
foreach($list as $v){
if($v['pid'] == 0){
$v['childlist'] = [];
$all_list[] = $v;
}
}
$all = [
"id" => 0,
"pid" => 0,
"name" => "全部",
"image" => "http://www.silk.top/uploads/20200715/a9c98c6c32fe55481fff5a0f730f9e0d.png",
"type_text" => "商品分类",
"flag_text" => "",
"spacer" => "",
"childlist" => [
[
"id" => 0,
"pid" => 0,
"name" => "全部",
"image" => "http://www.silk.top/uploads/20200715/a9c98c6c32fe55481fff5a0f730f9e0d.png",
"type_text" => "商品分类",
"flag_text" => "",
"spacer" => "",
"childlist" => $all_list
]
]
];
array_unshift($list,$all);
$this->success(__('成功'),compact('list'));
}
... ...
... ... @@ -49,9 +49,9 @@ class Index extends Api
}
$category_list = collection($category_list)->toArray();
// 会员专区
$member_goods_list = Goods::getList(['ismember'=>'1'],1,2);
$member_goods_list = Goods::getList(['ismember'=>'1'],1,2)['list'];
// 热卖爆品
$hot_goods_list = Goods::getList(['ishot'=>'1'],1,1000);
$hot_goods_list = Goods::getList(['ishot'=>'1'],1,1000)['list'];
// 返回结果
$this->success(__('成功'),compact(
'banner_list',
... ... @@ -211,16 +211,22 @@ class Index extends Api
$goods = Goods::get($goods_id);
empty($goods) && $this->error(__('商品不存在'));
$goods['issale'] == '0' && $this->error(__('商品已下架'));
$goods_style = GoodsStyle::get(['goods_id'=>$goods_id]);
if($goods_style){
$goods['goods_price'] = $goods['goods_price'] + $goods_style['goods_style_price'];
$goods['goods_style'] = $goods_style['goods_style'];
}else{
$goods['goods_style'] = '';
$goods['goods_style'] = '';
$goods['size'] = [];
if($goods['ismake'] == '1'){
$goods_style = GoodsStyle::get(['goods_id'=>$goods_id]);
if($goods_style){
$goods['goods_price'] = $goods['goods_price'] + $goods_style['goods_style_price'];
$goods['goods_style'] = $goods_style['goods_style'];
}
$user_size = UserSize::where(['user_id'=>$this->user['id'],'isdefault'=>'1'])->field('id,name')->find();
if($user_size){
$goods['size'] = $user_size;
}
}
// 定制项 1模特款 2自定义
$goods['make_type'] = '1';
$goods['size'] = UserSize::where(['user_id'=>$this->user['id'],'isdefault'=>'1'])->field('id,name')->find();
$goods['appraise'] = \app\common\model\Appraise::getList(['goods_id'=>$goods_id],1,1);
$goods['spec_data'] = $goods['spec_type'] == '2' ? $goods->getManySpecData($goods['spec_rel'], $goods['spec']) : null;
$goods->hidden(['spec','spec_rel'])->toArray();
// 返回结果
$this->success(__('成功'),compact('goods'));
}
... ...
... ... @@ -60,24 +60,31 @@ class User extends Api
{
$code = $this->request->request('code');
$user_info = $this->request->request('user_info');
$session = Wechat::miniProgram()->auth->session($code);
// 自动注册用户
$userInfo = json_decode(htmlspecialchars_decode($user_info), true);
if (!$user = UserModel::get(['openid' => $session['openid']])) {
$user = new UserModel;
$userInfo['openid'] = $session['openid'];
}
$userInfo['nickname'] = preg_replace('/[\xf0-\xf7].{3}/', '', $userInfo['nickname']);
if (!$user->allowField(true)->save($userInfo)) {
$this->error('用户注册失败');
}
// $session = Wechat::miniProgram()->auth->session($code);
// // 自动注册用户
// $userInfo = json_decode(htmlspecialchars_decode($user_info), true);
// if (!$user = UserModel::get(['openid' => $session['openid']])) {
// $user = new UserModel;
// $userInfo['openid'] = $session['openid'];
// }
// $userInfo['nickname'] = preg_replace('/[\xf0-\xf7].{3}/', '', $userInfo['nickname']);
// if (!$user->allowField(true)->save($userInfo)) {
// $this->error('用户登录失败');
// }
$session = [
'openid' => 'test',
];
$user = UserModel::get(['openid' => $session['openid']]);
// 生成token (session3rd)
$guid = guidv4();// 生成一个不会重复的随机字符串
$timeStamp = microtime(true);// 当前时间戳 (精确到毫秒)
$salt = 'token_salt';// 自定义一个盐
$token = md5("{$timeStamp}_{$session['openid']}_{$guid}_{$salt}");
$this->auth->direct($user['id'],$token);
$this->success(__('Sign up successful'),compact('token'));
$this->success(__('登录成功'),[
'token' => $token,
'avatar' => $user['avatar']
]);
}
/**
... ...
... ... @@ -36,14 +36,14 @@ class Appraise extends Model
/**
* 评价列表
*/
public static function getList($where,$page,$list_rows=15)
public static function getList($where,$page,$rows=15)
{
$list = self::with(['user'])
->where($where)
->order(['appraise_star'=>'desc'])
->paginate($list_rows,false,['page'=>$page])
->paginate($rows,false,['page'=>$page])
->each(function($v){
$v->getRelation('user')->visible(['name','avatar']);
$v->getRelation('user')->visible(['nickname','avatar']);
$v->createtime = date('Y-m-d',$v->createtime);
})->toArray();
return ['total'=>$list['total'],'list'=>$list['data']];
... ...
... ... @@ -18,7 +18,7 @@ class Banner extends Model
{
$list = Banner::order('weigh desc')->select();
foreach($list as $v){
$v->visible(['banner_image','banner_url']);
$v->visible(['id','banner_image','banner_url']);
}
return collection($list)->toArray();
}
... ...
... ... @@ -76,6 +76,7 @@ class Cart extends Model
$this->setError(__('抱歉,该商品只有会员才能购买'));
return false;
}
// 定制品
if($goods['ismake'] == '1'){
$user_size = UserSize::get(['user_id'=>$user['id'],'id'=>$data['user_size_id']]);
if(empty($user_size)){
... ... @@ -96,21 +97,47 @@ class Cart extends Model
$goods_style = json_decode($data['goods_style'],true);
$data['goods_price'] = $goods['goods_price'] + array_sum(StyleValue::where('id','in',$goods_style)->column('style_value_price'));
}
$stock_num = 9999999;
}else{
$data['goods_price'] = $goods['goods_price'];
// 非定制
$spec_sku_id = 0;
if($goods['spec_type'] == '2'){
if(empty($data['goods_sku_id'])){
$this->setError(__('请选择规格'));
return false;
}
$spec_sku_id = $data['goods_sku_id'];
}
$goods_sku = $goods->getGoodsSku($spec_sku_id);
$data['make_type'] = '0';
$data['goods_price'] = $goods_sku['goods_price'];
$stock_num = $goods_sku['stock_num'];
}
// 加入购物车
if(empty($data['isbuynow'])){
$cart = $this->get([
'goods_style' => $data['goods_style'],
'user_id' => $user['id'],
'goods_id' => $goods['id'],
'goods_id' => $data['goods_id'],
'spec_sku_id' => $data['spec_sku_id'],
'goods_style' => $data['goods_style'],
'isbuynow' => '0'
]);
if($cart){
$this->where('id',$cart['id'])->setInc('goods_num',$data['goods_num']);
if(!empty($cart)){
$cart_goods_num = $data['goods_num'] + $cart['goods_num'];
if($cart_goods_num > $stock_num){
$this->setError('很抱歉,商品库存不足');
return false;
}
$cart->goods_num = $cart_goods_num;
$cart->save();
return $cart['id'];
}
}
// 首次加入购物车或立即购买
if($data['goods_num'] > $stock_num){
$this->setError('很抱歉,商品库存不足');
return false;
}
$this->allowField(true)->save(array_merge([
'user_id'=>$user['id']
],$data));
... ... @@ -128,14 +155,27 @@ class Cart extends Model
$cart_list = [];
foreach ($list as $key => $cart) {
// 判断商品不存在则自动删除
$goods = Goods::get($cart['goods_id']);
$goods = $cart['goods'];
if (!$goods) {
$this->where('goods_id',$cart['goods_id'])->delete();
continue;
}
// 商品sku不存在则自动删除
if (!$cart['goods_sku'] = $goods->getGoodsSku($cart['goods_sku_id'])) {
$this->where(['goods_id'=>$cart['goods_id'],'goods_sku_id'=>$cart['goods_sku_id']])->delete();
continue;
}
// 判断商品是否下架
if ($goods['issale'] != '1') {
$this->setError('很抱歉,商品 [' . $goods['goods_name'] . '] 已下架');
}
// 判断商品库存
if ($cart['goods_num'] > $cart['goods_sku']['stock_num']) {
$this->setError('很抱歉,商品 [' . $goods['goods_name'] . '] 库存不足');
}
$total_num += $cart['goods_num'];
$total_price += $cart['goods_total_price'] = bcmul($cart['goods_price'], $cart['goods_num'], 2);
$cart->goods->visible(['goods_name','goods_image','goods_weight','category_ids']);
$cart->goods->visible(['goods_name','goods_image','category_ids']);
if(!$cart->user_size){
$cart->user_size = [];
}else{
... ... @@ -152,7 +192,8 @@ class Cart extends Model
'goods',
'user_size'
])->append([
'goods_total_price'
'goods_total_price',
'goods_sku'
])->toArray();
}
// 地址
... ... @@ -160,7 +201,6 @@ class Cart extends Model
if(!empty($data['user_address_id'])){
if(!$address = UserAddress::get($data['user_address_id'])){
$this->setError('地址不存在');
return false;
}
}
// 优惠券
... ... @@ -191,7 +231,7 @@ class Cart extends Model
$score['score_price'] = $user['score'] * $scoreprice;
}
// 运费
$total_goods_weight = array_sum(array_column(array_column($cart_list, 'goods'),'goods_weight'));
$total_goods_weight = array_sum(array_column(array_column($cart_list, 'goods_sku'),'goods_weight'));
$express = config('site.express');
krsort($express);
$express_price = 0;
... ... @@ -253,17 +293,16 @@ class Cart extends Model
}
$coupon_ids = implode(',', $coupon_id_arr) ?: '0';
return collection(UserCoupon::alias('uc')
$list = UserCoupon::alias('uc')
->join('coupon c','c.id = uc.coupon_id')
->with('coupon')
->where('uc.user_id',$user['id'])
->where('uc.status','1')
->where('c.expiretime','>',time())
->field("
uc.id user_coupon_id,
c.id,
c.coupon_name,
c.coupon_price,
c.limit_price,
uc.id,
uc.coupon_id,
uc.status,
from_unixtime(c.expiretime,'%Y-%m-%d') expiretime,
CASE
WHEN c.id in ({$coupon_ids}) THEN '1'
... ... @@ -271,7 +310,12 @@ class Cart extends Model
END isusable
")
->order(['isusable'=>'desc','c.coupon_price'=>'desc'])
->select())->toArray();
->select();
foreach($list as $v){
$v->visible(['id','status','expiretime','isusable','coupon']);
$v->getRelation('coupon')->visible(['id','coupon_name','coupon_price','limit_price','category_ids','rule']);
}
return $list;
}
/**
... ...
... ... @@ -7,11 +7,53 @@ use think\Model;
class Coupon extends Model
{
/**
* 隐藏字段
* @var array
*/
protected $append = [
'rule',
];
/**
* 优惠券状态
*/
public function getStatusAttr($value,$data)
{
$now_time = time();
$soon_expire_time = $now_time + 86400 * 3;
if($data['expiretime'] > $soon_expire_time){
return 'normal';
}
if($data['expiretime'] > $now_time && $data['expiretime'] <= $soon_expire_time){
return 'soon_expire';
}
if($data['expiretime'] < $now_time){
return 'expired';
}
}
/**
* 优惠券使用规则
*/
public function getRuleAttr($value,$data)
{
if(empty($data['category_ids'])){
return '全场通用';
}
$category_name_arr = Category::where('id','in',$data['category_ids'])->column('name');
if(!empty($category_name_arr)){
return implode('、', $category_name_arr).'品类';
}
return '优惠券不可用';
}
/**
* 优惠券列表
*/
public static function couponList($user){
$user_id = !$user ? 0 : $user['id'];
return self::alias('c')
->join('user_coupon uc','uc.coupon_id = c.id and uc.user_id = '.$user['id'],'left')
->join('user_coupon uc','uc.coupon_id = c.id and uc.user_id = '.$user_id,'left')
->where('c.expiretime','>',time())
->field("
c.id,
... ...
... ... @@ -16,10 +16,27 @@ class Goods extends Model
];
protected $append = [
'goods_image'
'goods_image',
'goods_price'
];
/**
* 关联商品规格表
*/
public function spec()
{
return $this->hasMany('GoodsSpec');
}
/**
* 关联商品规格关系表
*/
public function specRel()
{
return $this->belongsToMany('SpecValue', 'GoodsSpecRel');
}
/**
* 商品单图
*/
public function getGoodsImageAttr($value, $data)
... ... @@ -41,6 +58,14 @@ class Goods extends Model
}
/**
* 商品价格
*/
public function getGoodsPriceAttr($value, $data)
{
return $this['spec'][0]['goods_price'];
}
/**
* 买家秀
*/
public function getBuyerImagesAttr($value, $data)
... ... @@ -57,14 +82,74 @@ class Goods extends Model
*/
public static function getList($where,$page,$rows=15)
{
$list = self::where('issale','1')
$list = self::where('issale','1')
->where($where)
->page($page,$rows)
->order(['updatetime'=>'desc'])
->select();
foreach($list as $v){
$v->visible(['id','goods_image','goods_name','goods_price','ismake']);
->paginate($rows,false,['page'=>$page])
->each(function($v){
$v->visible(['id','goods_image','goods_name','goods_price','ismake']);
})->toArray();
return ['total'=>$list['total'],'list'=>$list['data']];
}
/**
* 获取规格信息
*/
public function getManySpecData($spec_rel, $skuData)
{
// spec_attr
$specAttrData = [];
foreach ($spec_rel as $item) {
if (!isset($specAttrData[$item['spec_id']])) {
$specAttrData[$item['spec_id']] = [
'spec_id' => $item['spec']['id'],
'spec_name' => $item['spec']['spec_name'],
'spec_value_list' => [],
];
}
$specAttrData[$item['spec_id']]['spec_value_list'][] = [
'spec_value_id' => $item['id'],
'spec_value_name' => $item['spec_value_name'],
];
}
// spec_list
$goods_spec_list = [];
foreach ($skuData as $item) {
$goods_spec_list[] = [
'goods_spec_id' => $item['id'],
'spec_sku_id' => $item['spec_sku_id'],
'rows' => [],
'form' => [
'goods_price' => $item['goods_price'],
'goods_weight' => $item['goods_weight'],
'stock_num' => $item['stock_num'],
],
];
}
return ['spec_attr' => array_values($specAttrData), 'goods_spec_list' => $goods_spec_list];
}
/**
* 商品多规格信息
*/
public function getGoodsSku($goods_sku_id)
{
$goodsSkuData = array_column($this['spec']->toArray(), null, 'spec_sku_id');
if (!isset($goodsSkuData[$goods_sku_id])) {
return false;
}
$goods_sku = $goodsSkuData[$goods_sku_id];
// 多规格文字内容
$goods_sku['goods_attr'] = '';
if ($this['spec_type'] == '2') {
$attrs = explode('_', $goods_sku['spec_sku_id']);
$spec_rel = array_column($this['spec_rel']->toArray(), null, 'spec_value_id');
foreach ($attrs as $specValueId) {
$goods_sku['goods_attr'] .= $spec_rel[$specValueId]['spec']['spec_name'] . ':'
. $spec_rel[$specValueId]['spec_value_name'] . '; ';
}
}
return collection($list)->toArray();
return $goods_sku;
}
}
... ...
<?php
namespace app\common\model;
use think\Model;
class GoodsSpec extends Model
{
}
... ...
<?php
namespace app\common\model;
use think\Model;
class GoodsSpecRel extends Model
{
/**
* 关联商品规格表
*/
public function spec()
{
return $this->blongsTo('spec');
}
}
... ...
<?php
namespace app\common\model;
use think\Model;
class Spec extends Model
{
}
... ...
<?php
namespace app\common\model;
use think\Model;
class SpecValue extends Model
{
/**
* 新增规格值
*/
public function spec()
{
return $this->belongsTo('Spec');
}
}
... ...
... ... @@ -15,10 +15,18 @@ class UserCoupon extends Model
}
/**
* 优惠券
*/
public function getStatusAttr($value,$data)
{
return $data['status'] == '2' ? 'used' : $this['coupon']['status'];
}
/**
* 优惠券列表
*/
public static function couponList($user,$status='all'){
// 筛选条件
// 筛选条件
$filter = [];
$now_time = time();
$soon_expire_time = $now_time + 86400 * 3;
... ... @@ -27,42 +35,39 @@ class UserCoupon extends Model
case 'all':
break;
case 'normal':
$filter['uc.status'] = '1';
$filter['uc.status'] = '1';
$filter['c.expiretime'] = ['>',$soon_expire_time];
break;
case 'soon_expire';
$filter['uc.status'] = '1';
$filter['uc.status'] = '1';
$filter['c.expiretime'] = ['>',$now_time];
$filter['c.expiretime'] = ['<=',$soon_expire_time];
break;
case 'expired';
$filter['uc.status'] = '1';
$filter['uc.status'] = '1';
$filter['c.expiretime'] = ['<',$now_time];
break;
case 'used';
$filter['uc.status'] = '2';
break;
}
return self::alias('uc')
$list = self::alias('uc')
->join('coupon c','c.id = uc.coupon_id')
->with('coupon')
->where('uc.user_id',$user['id'])
->where($filter)
->field("
uc.id user_coupon_id,
c.id,
c.coupon_name,
c.coupon_price,
c.limit_price,
from_unixtime(c.expiretime,'%Y-%m-%d') expiretime,
CASE
WHEN uc.status = 1 and c.expiretime > {$soon_expire_time} THEN 'normal'
WHEN uc.status = 1 and c.expiretime > {$now_time} and c.expiretime <= {$soon_expire_time} THEN 'soon_expire'
WHEN uc.status = 1 and c.expiretime < {$now_time} THEN 'expired'
WHEN uc.status = 2 THEN 'used'
ELSE 'normal'
END status
")
uc.id,
uc.coupon_id,
uc.status,
from_unixtime(c.expiretime,'%Y-%m-%d') expiretime
")
->order('c.expiretime asc')
->select();
foreach($list as $v){
$v->visible(['id','status','expiretime','coupon']);
$v->getRelation('coupon')->visible(['id','coupon_name','coupon_price','limit_price','category_ids','rule']);
}
return $list;
}
}
... ...
... ... @@ -444,6 +444,18 @@
<td></td>
<td>用户尺寸ID</td>
</tr>
<tr>
<td>spec_sku_id</td>
<td>string</td>
<td></td>
<td>商品sku</td>
</tr>
<tr>
<td>isbuynow</td>
<td>string</td>
<td></td>
<td>是否立即购买:0=否,1=是</td>
</tr>
</tbody>
</table>
</div>
... ... @@ -490,6 +502,14 @@
<input type="integer" class="form-control input-sm" id="user_size_id" required placeholder="用户尺寸ID" name="user_size_id">
</div>
<div class="form-group">
<label class="control-label" for="spec_sku_id">spec_sku_id</label>
<input type="string" class="form-control input-sm" id="spec_sku_id" required placeholder="商品sku" name="spec_sku_id">
</div>
<div class="form-group">
<label class="control-label" for="isbuynow">isbuynow</label>
<input type="string" class="form-control input-sm" id="isbuynow" required placeholder="是否立即购买:0=否,1=是" name="isbuynow">
</div>
<div class="form-group">
<button type="submit" class="btn btn-success send" rel="1">提交</button>
<button type="reset" class="btn btn-info" rel="1">重置</button>
</div>
... ... @@ -7615,7 +7635,7 @@
<div class="row mt0 footer">
<div class="col-md-6" align="left">
Generated on 2020-07-20 17:42:49 </div>
Generated on 2020-07-23 21:50:49 </div>
<div class="col-md-6" align="right">
<a href="./" target="_blank">我的网站</a>
</div>
... ...
define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {
var Controller = {
index: function () {
// 初始化表格参数配置
Table.api.init({
extend: {
index_url: 'appraise/index' + location.search,
add_url: 'appraise/add',
edit_url: 'appraise/edit',
del_url: 'appraise/del',
multi_url: 'appraise/multi',
import_url: 'appraise/import',
table: 'appraise',
}
});
var table = $("#table");
// 初始化表格
table.bootstrapTable({
url: $.fn.bootstrapTable.defaults.extend.index_url,
pk: 'id',
sortName: 'id',
columns: [
[
{checkbox: true},
{field: 'id', title: __('Id')},
{field: 'appraise_content', title: __('Appraise_content')},
{field: 'appraise_images', title: __('Appraise_images'), events: Table.api.events.image, formatter: Table.api.formatter.images},
{field: 'appraise_star', title: __('Appraise_star')},
{field: 'user_id', title: __('User_id')},
{field: 'createtime', title: __('Createtime'), operate:'RANGE', addclass:'datetimerange', formatter: Table.api.formatter.datetime},
{field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate}
]
]
});
// 为表格绑定事件
Table.api.bindevent(table);
},
add: function () {
Controller.api.bindevent();
},
edit: function () {
Controller.api.bindevent();
},
api: {
bindevent: function () {
Form.api.bindevent($("form[role=form]"));
}
}
};
return Controller;
});
\ No newline at end of file
... ...
... ... @@ -110,6 +110,27 @@ define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefin
var specMany = new GoodsSpec({
container: '.goods-spec-many'
}, Config.specData);
Form.api.bindevent($("form[role=form]"), function(data, ret){
//如果我们需要在提交表单成功后做跳转,可以在此使用location.href="链接";进行跳转
Toastr.success("成功");
}, function(data, ret){
Toastr.error("失败");
}, function(success, error){
//bindevent的第三个参数为提交前的回调
//如果我们需要在表单提交前做一些数据处理,则可以在此方法处理
//注意如果我们需要阻止表单,可以在此使用return false;即可
//如果我们处理完成需要再次提交表单则可以使用submit提交,如下
//Form.api.submit(this, success, error);
var specType = $('select[name="row[spec_type]"]').val();
if (specType === '2') {
var isEmpty = specMany.isEmptySkuList();
isEmpty === true && Toastr.error('商品规格不能为空');
$('input[name="row[spec_many]"]').val(JSON.stringify(specMany.getData()));
return !isEmpty;
}
return true;
});
});
// 切换单/多规格
... ...
... ... @@ -3,7 +3,7 @@
// 商品规格数据
var data = {
spec_attr: [],
spec_list: []
goods_spec_list: []
}
// 配置信息
... ... @@ -28,18 +28,18 @@
// 注册html容器
this.$container = $(setting.container);
this.$specAttr = this.$container.find('.spec-attr');
// 显示添加规则组表单事件
this.showAddSpecGroupEvent();
// 确认新增规则组事件
this.submitAddSpecGroupEvent();
// 取消新增规则组事件
this.cancelAddSpecGroupEvent();
// 注册添加规格元素事件
this.addSpecItemEvent();
// 注册删除规则组事件
this.deleteSpecGroupEvent();
// 注册删除规则元素事件
this.deleteSpecItemEvent();
// 显示添加规格事件
this.showAddSpecEvent();
// 确认新增规格事件
this.submitAddSpecEvent();
// 取消新增规格事件
this.cancelAddSpecEvent();
// 注册添加规格值事件
this.addSpecValueEvent();
// 注册删除规格事件
this.deleteSpecEvent();
// 注册删除规格值事件
this.deleteSpecValueEvent();
// 注册批量设置sku事件
this.batchUpdateSku();
// 注册表格input数据修改事件
... ... @@ -49,27 +49,27 @@
},
/**
* 显示添加规则组表单
* 显示添加规
*/
showAddSpecGroupEvent: function () {
showAddSpecEvent: function () {
// 显示添加规则组表单
this.$container.on('click', '.btn-addSpecGroup', function () {
var $specGroupButton = $(this).parent()
, $specGroupAdd = $specGroupButton.next();
$specGroupButton.hide();
$specGroupAdd.show();
this.$container.on('click', '.btn-addSpec', function () {
var $specButton = $(this).parent()
, $specAdd = $specButton.next();
$specButton.hide();
$specAdd.show();
});
},
/**
* 确认新增规则组
* 确认新增规
*/
submitAddSpecGroupEvent: function () {
submitAddSpecEvent: function () {
var _this = this;
// 确认添加
_this.$container.on('click', '.btn-addSpecName', function () {
var $specGroupAdd = $(this).parent().parent()
, $specGroupButton = $specGroupAdd.prev()
var $specAdd = $(this).parent().parent()
, $specButton = $specAdd.prev()
, $specNameInput = _this.$container.find('.input-specName')
, $specValueInput = _this.$container.find('.input-specValue')
, specValueInputValue = $specValueInput.val()
... ... @@ -93,54 +93,54 @@
$specNameInput.val('') && $specValueInput.val('');
// 记录规格数据
data.spec_attr.push({
group_id: result.data.spec_id,
group_name: specNameInputValue,
spec_items: [{
item_id: result.data.spec_value_id,
spec_id: result.data.spec_id,
spec_name: specNameInputValue,
spec_value_list: [{
spec_value_id: result.data.spec_value_id,
spec_value_name: specValueInputValue
}]
});
// 渲染规格属性html
_this.renderHtml();
// 隐藏添加规格组表单
$specGroupAdd.hide() && $specGroupButton.show();
$specAdd.hide() && $specButton.show();
});
});
},
/**
* 取消新增规格
* 取消新增规格
*/
cancelAddSpecGroupEvent: function () {
cancelAddSpecEvent: function () {
this.$container.on('click', '.btn-cancleAddSpecName', function () {
var $specGroupAdd = $(this).parent().parent()
, $specGroupButton = $specGroupAdd.prev();
var $specAdd = $(this).parent().parent()
, $specButton = $specAdd.prev();
// 隐藏添加规格组表单
$specGroupAdd.hide() && $specGroupButton.show()
$specAdd.hide() && $specButton.show()
});
},
/**
* 添加规则元素事件
* 添加规格值事件
*/
addSpecItemEvent: function () {
addSpecValueEvent: function () {
var _this = this;
_this.$container.on('click', '.btn-addSpecItem', function () {
_this.$container.on('click', '.btn-addSpecValue', function () {
var $this = $(this)
, $iptSpecItem = $this.prev('.ipt-specItem')
, specItemInputValue = $iptSpecItem.val()
, $specItemAddContainer = $this.parent()
, $specGroup = $specItemAddContainer.parent().parent();
if (specItemInputValue === '') {
, $iptSpecValue = $this.prev('.ipt-specValue')
, specValueInputValue = $iptSpecValue.val()
, $specValueAddContainer = $this.parent()
, $spec = $specValueAddContainer.parent().parent();
if (specValueInputValue === '') {
layer.msg('规格值不能为空');
return false;
}
// 添加到数据库
var load = layer.load();
$.post('spec/addSpecValue', {
spec_id: $specGroup.data('group-id'),
spec_value_name: specItemInputValue
spec_id: $spec.data('group-id'),
spec_value_name: specValueInputValue
}, function (result) {
layer.close(load);
if (result.code !== 1) {
... ... @@ -148,9 +148,9 @@
return false;
}
// 记录规格数据
data.spec_attr[$specGroup.data('index')].spec_items.push({
item_id: result.data.spec_value_id,
spec_value_name: specItemInputValue
data.spec_attr[$spec.data('index')].spec_value_list.push({
spec_value_id: result.data.spec_value_id,
spec_value_name: specValueInputValue
});
// 渲染规格属性html
_this.renderHtml();
... ... @@ -161,9 +161,9 @@
/**
* 删除规则组事件
*/
deleteSpecGroupEvent: function () {
deleteSpecEvent: function () {
var _this = this;
_this.$container.on('click', '.spec-group-delete', function () {
_this.$container.on('click', '.spec-delete', function () {
// 规则组索引
var index = $(this).parent().parent().attr('data-index');
layer.confirm('确定要删除该规则组吗?确认后不可恢复请谨慎操作', function (layerIndex) {
... ... @@ -177,18 +177,18 @@
},
/**
* 删除规则组事件
* 删除规格值事件
*/
deleteSpecItemEvent: function () {
deleteSpecValueEvent: function () {
var _this = this;
_this.$container.on('click', '.spec-item-delete', function () {
var $item = $(this).parent()
, $specGroup = $item.parent().parent()
, groupIndex = $specGroup.attr('data-index')
, itemIndex = $item.attr('data-item-index');
_this.$container.on('click', '.spec-value-delete', function () {
var $specValue = $(this).parent()
, $spec = $specValue.parent().parent()
, specIndex = $spec.attr('data-index')
, specValueIndex = $specValue.attr('data-item-index');
layer.confirm('确定要删除该规则吗?确认后不可恢复请谨慎操作', function (layerIndex) {
// 删除指定规则组
data.spec_attr[groupIndex].spec_items.splice(itemIndex, 1);
data.spec_attr[specIndex].spec_value_list.splice(specValueIndex, 1);
// 重新渲染规格属性html
_this.renderHtml();
layer.close(layerIndex);
... ... @@ -213,8 +213,8 @@
}
});
if (!$.isEmptyObject(formData)) {
data.spec_list.forEach(function (item, index) {
data.spec_list[index].form = $.extend({}, data.spec_list[index].form, formData);
data.goods_spec_list.forEach(function (item, index) {
data.goods_spec_list[index].form = $.extend({}, data.goods_spec_list[index].form, formData);
});
// 渲染商品规格table
_this.renderTabelHtml();
... ... @@ -229,21 +229,21 @@
// 渲染商品规格元素
var html_spec_attr = '';
$.each(data.spec_attr,function(index,value){
html_spec_attr += '<div class="spec-group-item" data-index="'+index+'" data-group-id="'+value.group_id+'">'+
'<div class="spec-group-name">'+
'<span>'+value.group_name+'</span>'+
'<i class="spec-group-delete glyphicon glyphicon-remove" title="点击删除"></i>'+
html_spec_attr += '<div class="spec" data-index="'+index+'" data-group-id="'+value.spec_id+'">'+
'<div class="spec-name">'+
'<span>'+value.spec_name+'</span>'+
'<i class="spec-delete glyphicon glyphicon-remove" title="点击删除"></i>'+
'</div>'+
'<div class="spec-list am-cf">';
$.each(value.spec_items,function(key,item){
html_spec_attr += '<div class="spec-item am-fl" data-item-index="'+key+'">'+
'<div class="spec-value-list am-cf">';
$.each(value.spec_value_list,function(key,item){
html_spec_attr += '<div class="spec-value am-fl" data-item-index="'+key+'">'+
'<span>'+item.spec_value_name+'</span>'+
'<i class="spec-item-delete glyphicon glyphicon-remove-circle" title="点击删除"></i>'+
'<i class="spec-value-delete glyphicon glyphicon-remove-circle" title="点击删除"></i>'+
'</div>';
})
html_spec_attr += '<div class="spec-item-add am-cf am-fl">'+
'<input type="text" class="ipt-specItem am-fl am-field-valid">'+
'<button type="button" class="btn-addSpecItem am-btn am-fl">添加</button>'+
html_spec_attr += '<div class="spec-value-add am-cf am-fl">'+
'<input type="text" class="ipt-specValue am-fl am-field-valid">'+
'<button type="button" class="btn-addSpecValue am-btn am-fl">添加</button>'+
'</div>'+
'</div>'+
'</div>';
... ... @@ -271,13 +271,13 @@
var html_spec_table = '<tbody>'+
'<tr>';
$.each(data.spec_attr,function(index,value){
html_spec_table += '<th>'+value.group_name+'</th>';
html_spec_table += '<th>'+value.spec_name+'</th>';
})
html_spec_table += '<th>商品价格</th>'+
'<th>库存</th>'+
'<th>重量(kg)</th>'+
'</tr>';
$.each(data.spec_list,function(index,item){
$.each(data.goods_spec_list,function(index,item){
html_spec_table += '<tr data-index="'+index+'" data-sku-id="'+item.spec_sku_id+'">';
$.each(item.rows,function(itemKey,td){
html_spec_table += '<td class="td-spec-value am-text-middle" rowspan="'+td.rowspan+'">'
... ... @@ -308,47 +308,47 @@
// 规格组合总数 (table行数)
var totalRow = 1;
for (var i = 0; i < data.spec_attr.length; i++) {
totalRow *= data.spec_attr[i].spec_items.length;
totalRow *= data.spec_attr[i].spec_value_list.length;
}
// 遍历tr 行
var spec_list = [];
var goods_spec_list = [];
for (i = 0; i < totalRow; i++) {
var rowData = [], rowCount = 1, specSkuIdAttr = [];
// 遍历td 列
for (var j = 0; j < data.spec_attr.length; j++) {
var skuValues = data.spec_attr[j].spec_items;
var skuValues = data.spec_attr[j].spec_value_list;
rowCount *= skuValues.length;
var anInterBankNum = (totalRow / rowCount)
, point = ((i / anInterBankNum) % skuValues.length);
if (0 === (i % anInterBankNum)) {
rowData.push({
rowspan: anInterBankNum,
item_id: skuValues[point].item_id,
spec_value_id: skuValues[point].spec_value_id,
spec_value_name: skuValues[point].spec_value_name
});
}
specSkuIdAttr.push(skuValues[parseInt(point.toString())].item_id);
specSkuIdAttr.push(skuValues[parseInt(point.toString())].spec_value_id);
}
spec_list.push({
goods_spec_list.push({
spec_sku_id: specSkuIdAttr.join('_'),
rows: rowData,
form: {}
});
}
// 合并旧sku数据
if (data.spec_list.length > 0 && spec_list.length > 0) {
for (i = 0; i < spec_list.length; i++) {
var overlap = data.spec_list.filter(function (val) {
return val.spec_sku_id === spec_list[i].spec_sku_id;
if (data.goods_spec_list.length > 0 && goods_spec_list.length > 0) {
for (i = 0; i < goods_spec_list.length; i++) {
var overlap = data.goods_spec_list.filter(function (val) {
return val.spec_sku_id === goods_spec_list[i].spec_sku_id;
});
if (overlap.length > 0) spec_list[i].form = overlap[0].form;
if (overlap.length > 0) goods_spec_list[i].form = overlap[0].form;
}
}
data.spec_list = spec_list;
data.goods_spec_list = goods_spec_list;
},
/**
* 输入规格信息自动同步更新spec_list
* 输入规格信息自动同步更新goods_spec_list
*/
updateSpecInputEvent: function () {
var _this = this;
... ... @@ -356,7 +356,7 @@
var $this = $(this)
, dataType = $this.attr('name')
, specIndex = $this.parent().parent().data('index');
data.spec_list[specIndex].form[dataType] = $this.val();
data.goods_spec_list[specIndex].form[dataType] = $this.val();
});
},
... ... @@ -372,7 +372,7 @@
* @returns {boolean}
*/
isEmptySkuList: function () {
return !data.spec_list.length;
return !data.goods_spec_list.length;
}
};
... ...