切换导航条
此项目
正在载入...
登录
李忠强
/
temporaryfood
·
提交
转到一个项目
GitLab
转到仪表盘
项目
活动
文件
提交
管道
0
构建
0
图表
里程碑
问题
0
合并请求
0
成员
标记
维基
派生
网络
创建新的问题
下载为
邮件补丁
差异文件
浏览文件
作者
SHW\戥岁。。
3 years ago
提交
009e8953e5e57f534aaf347b17c1bb413e003bde
1 个父辈
cb796507
计算折扣
隐藏空白字符变更
内嵌
并排对比
正在显示
3 个修改的文件
包含
51 行增加
和
44 行删除
application/admin/model/litestore/Litestoregoods.php
application/admin/model/litestore/Litestoregoodsspec.php
application/api/controller/Classification.php
application/admin/model/litestore/Litestoregoods.php
查看文件 @
009e895
...
...
@@ -8,22 +8,22 @@ class Litestoregoods extends Model
{
// 表名
protected
$name
=
'litestore_goods'
;
// 自动写入时间戳字段
protected
$autoWriteTimestamp
=
'int'
;
// 定义时间戳字段名
protected
$createTime
=
'createtime'
;
protected
$updateTime
=
'updatetime'
;
// 追加属性
protected
$append
=
[
'spec_type_text'
,
'deduct_stock_type_text'
,
'goods_status_text'
,
'is_delete_text'
'is_delete_text'
,
];
protected
static
function
init
()
{
...
...
@@ -33,66 +33,66 @@ class Litestoregoods extends Model
});
}
public
function
getSpecTypeList
()
{
return
[
'10'
=>
__
(
'Spec_type 10'
),
'20'
=>
__
(
'Spec_type 20'
)];
}
return
[
'10'
=>
__
(
'Spec_type 10'
),
'20'
=>
__
(
'Spec_type 20'
)];
}
public
function
getDeductStockTypeList
()
{
return
[
'10'
=>
__
(
'Deduct_stock_type 10'
),
'20'
=>
__
(
'Deduct_stock_type 20'
)];
return
[
'10'
=>
__
(
'Deduct_stock_type 10'
),
'20'
=>
__
(
'Deduct_stock_type 20'
)];
}
public
function
getMakeforList
()
{
return
[
'1'
=>
__
(
'Makefor 1'
),
'2'
=>
__
(
'Makefor 2'
)];
return
[
'1'
=>
__
(
'Makefor 1'
),
'2'
=>
__
(
'Makefor 2'
)];
}
public
function
getIsIndexList
()
{
return
[
'0'
=>
__
(
'Is_index 0'
),
'1'
=>
__
(
'Is_index 1'
)];
return
[
'0'
=>
__
(
'Is_index 0'
),
'1'
=>
__
(
'Is_index 1'
)];
}
public
function
getGoodsStatusList
()
{
return
[
'10'
=>
__
(
'Goods_status 10'
),
'20'
=>
__
(
'Goods_status 20'
)];
}
return
[
'10'
=>
__
(
'Goods_status 10'
),
'20'
=>
__
(
'Goods_status 20'
)];
}
public
function
getIsDeleteList
()
{
return
[
'0'
=>
__
(
'Is_delete 0'
),
'1'
=>
__
(
'Is_delete 1'
)];
}
return
[
'0'
=>
__
(
'Is_delete 0'
),
'1'
=>
__
(
'Is_delete 1'
)];
}
public
function
getSpecTypeTextAttr
(
$value
,
$data
)
{
{
$value
=
$value
?
$value
:
(
isset
(
$data
[
'spec_type'
])
?
$data
[
'spec_type'
]
:
''
);
$list
=
$this
->
getSpecTypeList
();
$list
=
$this
->
getSpecTypeList
();
return
isset
(
$list
[
$value
])
?
$list
[
$value
]
:
''
;
}
public
function
getDeductStockTypeTextAttr
(
$value
,
$data
)
{
{
$value
=
$value
?
$value
:
(
isset
(
$data
[
'deduct_stock_type'
])
?
$data
[
'deduct_stock_type'
]
:
''
);
$list
=
$this
->
getDeductStockTypeList
();
$list
=
$this
->
getDeductStockTypeList
();
return
isset
(
$list
[
$value
])
?
$list
[
$value
]
:
''
;
}
public
function
getGoodsStatusTextAttr
(
$value
,
$data
)
{
{
$value
=
$value
?
$value
:
(
isset
(
$data
[
'goods_status'
])
?
$data
[
'goods_status'
]
:
''
);
$list
=
$this
->
getGoodsStatusList
();
$list
=
$this
->
getGoodsStatusList
();
return
isset
(
$list
[
$value
])
?
$list
[
$value
]
:
''
;
}
public
function
getIsDeleteTextAttr
(
$value
,
$data
)
{
{
$value
=
$value
?
$value
:
(
isset
(
$data
[
'is_delete'
])
?
$data
[
'is_delete'
]
:
''
);
$list
=
$this
->
getIsDeleteList
();
$list
=
$this
->
getIsDeleteList
();
return
isset
(
$list
[
$value
])
?
$list
[
$value
]
:
''
;
}
...
...
@@ -118,7 +118,7 @@ class Litestoregoods extends Model
*/
public
function
spec
()
{
return
$this
->
hasMany
(
'Litestoregoodsspec'
,
'goods_id'
,
'goods_id'
);
return
$this
->
hasMany
(
'Litestoregoodsspec'
,
'goods_id'
,
'goods_id'
);
}
/**
...
...
@@ -126,7 +126,7 @@ class Litestoregoods extends Model
*/
public
function
specRel
()
{
return
$this
->
belongsToMany
(
'Litestorespecvalue'
,
'litestore_goods_spec_rel'
,
'spec_value_id'
,
'goods_id'
);
return
$this
->
belongsToMany
(
'Litestorespecvalue'
,
'litestore_goods_spec_rel'
,
'spec_value_id'
,
'goods_id'
);
}
/**
...
...
@@ -146,7 +146,7 @@ class Litestoregoods extends Model
* @param $isUpdate
* @throws \Exception
*/
public
function
addGoodsSpec
(
&
$data
,
$params
,
$specparams
,
$isUpdate
=
false
)
public
function
addGoodsSpec
(
&
$data
,
$params
,
$specparams
,
$isUpdate
=
false
)
{
// 更新模式: 先删除所有规格
$model
=
new
Litestoregoodsspec
;
...
...
@@ -154,19 +154,22 @@ class Litestoregoods extends Model
// 添加规格数据
if
(
$data
[
'spec_type'
]
===
'10'
)
{
// 单规格
$specparams
[
'discount'
]
=
(
round
(
$specparams
[
'line_price'
]
/
$specparams
[
'goods_price'
],
2
)
*
100
)
.
'折'
;
$this
->
spec
()
->
save
(
$specparams
);
}
else
if
(
$data
[
'spec_type'
]
===
'20'
)
{
// 添加商品与规格关系记录
$model
->
addGoodsSpecRel
(
$this
[
'goods_id'
],
$params
[
'spec_attr'
]);
$model
->
addGoodsSpecRel
(
$this
[
'goods_id'
],
$params
[
'spec_attr'
]);
// 添加商品sku
$model
->
addSkuList
(
$this
[
'goods_id'
],
$params
[
'spec_list'
]);
$model
->
addSkuList
(
$this
[
'goods_id'
],
$params
[
'spec_list'
]);
}
}
public
function
removesku
(){
public
function
removesku
()
{
// 删除商品sku
(
new
Litestoregoodsspec
)
->
removeAll
(
$this
[
'goods_id'
]);
}
/**
* 获取规格信息
*/
...
...
@@ -177,13 +180,13 @@ class Litestoregoods extends Model
foreach
(
$spec_rel
as
$item
)
{
if
(
!
isset
(
$specAttrData
[
$item
[
'spec_id'
]]))
{
$specAttrData
[
$item
[
'spec_id'
]]
=
[
'group_id'
=>
$item
[
'spec'
][
'id'
],
'group_id'
=>
$item
[
'spec'
][
'id'
],
'group_name'
=>
$item
[
'spec'
][
'spec_name'
],
'spec_items'
=>
[],
];
}
$specAttrData
[
$item
[
'spec_id'
]][
'spec_items'
][]
=
[
'item_id'
=>
$item
[
'pivot'
][
'spec_value_id'
],
'item_id'
=>
$item
[
'pivot'
][
'spec_value_id'
],
'spec_value'
=>
$item
[
'spec_value'
],
];
}
...
...
@@ -193,15 +196,15 @@ class Litestoregoods extends Model
foreach
(
$skuData
as
$item
)
{
$specListData
[]
=
[
'goods_spec_id'
=>
$item
[
'goods_spec_id'
],
'spec_sku_id'
=>
$item
[
'spec_sku_id'
],
'rows'
=>
[],
'form'
=>
[
'goods_no'
=>
$item
[
'goods_no'
],
'goods_price'
=>
$item
[
'goods_price'
],
'spec_sku_id'
=>
$item
[
'spec_sku_id'
],
'rows'
=>
[],
'form'
=>
[
'goods_no'
=>
$item
[
'goods_no'
],
'goods_price'
=>
$item
[
'goods_price'
],
'goods_weight'
=>
$item
[
'goods_weight'
],
'line_price'
=>
$item
[
'line_price'
],
'stock_num'
=>
$item
[
'stock_num'
],
'spec_image'
=>
$item
[
'spec_image'
],
'line_price'
=>
$item
[
'line_price'
],
'stock_num'
=>
$item
[
'stock_num'
],
'spec_image'
=>
$item
[
'spec_image'
],
],
];
}
...
...
application/admin/model/litestore/Litestoregoodsspec.php
查看文件 @
009e895
<?php
namespace
app\admin\model\litestore
;
use
think\Model
;
class
Litestoregoodsspec
extends
Model
...
...
@@ -8,7 +9,7 @@ class Litestoregoodsspec extends Model
// 表名
protected
$name
=
'litestore_goods_spec'
;
// 自动写入时间戳字段
protected
$autoWriteTimestamp
=
'int'
;
...
...
@@ -29,7 +30,9 @@ class Litestoregoodsspec extends Model
foreach
(
$spec_list
as
$item
)
{
$data
[]
=
array_merge
(
$item
[
'form'
],
[
'spec_sku_id'
=>
$item
[
'spec_sku_id'
],
'goods_id'
=>
$goods_id
,
'goods_id'
=>
$goods_id
,
'discount'
=>
(
round
(
$item
[
'form'
][
'line_price'
]
/
$item
[
'form'
][
'goods_price'
],
2
)
*
100
)
.
'折'
,
]);
}
return
$this
->
saveAll
(
$data
);
...
...
@@ -48,8 +51,8 @@ class Litestoregoodsspec extends Model
array_map
(
function
(
$val
)
use
(
&
$data
,
$goods_id
)
{
array_map
(
function
(
$item
)
use
(
&
$val
,
&
$data
,
$goods_id
)
{
$data
[]
=
[
'goods_id'
=>
$goods_id
,
'spec_id'
=>
$val
[
'group_id'
],
'goods_id'
=>
$goods_id
,
'spec_id'
=>
$val
[
'group_id'
],
'spec_value_id'
=>
$item
[
'item_id'
],
];
},
$val
[
'spec_items'
]);
...
...
@@ -66,7 +69,7 @@ class Litestoregoodsspec extends Model
public
function
removeAll
(
$goods_id
)
{
$model
=
new
Litestoregoodsspecrel
;
$model
->
where
(
'goods_id'
,
'='
,
$goods_id
)
->
delete
();
return
$this
->
where
(
'goods_id'
,
'='
,
$goods_id
)
->
delete
();
$model
->
where
(
'goods_id'
,
'='
,
$goods_id
)
->
delete
();
return
$this
->
where
(
'goods_id'
,
'='
,
$goods_id
)
->
delete
();
}
}
...
...
application/api/controller/Classification.php
查看文件 @
009e895
...
...
@@ -134,6 +134,7 @@ class Classification extends Api
->
find
();
$item
[
'price'
]
=
$goods_spec
[
'goods_price'
];
$item
[
'line_price'
]
=
$goods_spec
[
'line_price'
];
$item
[
'discount'
]
=
$goods_spec
[
'discount'
];
// 总库存
$item
->
append
([
'stock_num'
]);
});
...
...
请
注册
或
登录
后发表评论