Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
G
goods
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
bp
goods
Commits
1f4ff8d9
Commit
1f4ff8d9
authored
Jun 15, 2021
by
luhongguang
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
update:商品编辑
parent
12bfe357
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
80 additions
and
1 deletion
+80
-1
GoodsException.php
application/exception/custom/GoodsException.php
+1
-0
Goods.php
application/modules/Goods/controllers/Goods.php
+3
-1
GoodsService.php
application/services/goods/GoodsService.php
+76
-0
No files found.
application/exception/custom/GoodsException.php
View file @
1f4ff8d9
...
@@ -26,5 +26,6 @@ class GoodsException extends BaseException
...
@@ -26,5 +26,6 @@ class GoodsException extends BaseException
12
=>
'审核状态错误'
,
12
=>
'审核状态错误'
,
13
=>
'无权限操作'
,
13
=>
'无权限操作'
,
14
=>
'当前商品不是审核通过状态,无法做上下架操作'
,
14
=>
'当前商品不是审核通过状态,无法做上下架操作'
,
15
=>
'当前商品不存在'
,
];
];
}
}
\ No newline at end of file
application/modules/Goods/controllers/Goods.php
View file @
1f4ff8d9
...
@@ -33,7 +33,9 @@ class GoodsController extends Base
...
@@ -33,7 +33,9 @@ class GoodsController extends Base
*/
*/
public
function
editAction
()
public
function
editAction
()
{
{
$params
=
$this
->
params
;
GoodsService
::
editGoods
(
$params
);
$this
->
success
();
}
}
/**
/**
...
...
application/services/goods/GoodsService.php
View file @
1f4ff8d9
...
@@ -318,4 +318,80 @@ class GoodsService
...
@@ -318,4 +318,80 @@ class GoodsService
}
}
return
[
"can_use"
=>
$nameCanUse
];
return
[
"can_use"
=>
$nameCanUse
];
}
}
/**
* 编辑商品
* @param array $params
* @return bool
* @throws GoodsException
*/
public
static
function
editGoods
(
$params
=
[])
{
$goodsSpuId
=
$params
[
"goods_spu_id"
];
$goodsSpu
=
GoodsSpu
::
get
(
"*"
,
[
"goods_spu_id"
=>
$goodsSpuId
]);
if
(
empty
(
$goodsSpu
))
{
throw
new
GoodsException
([
"cus"
=>
15
]);
}
GoodsSpu
::
beginTransaction
();
self
::
editGoodsSpu
(
$goodsSpuId
,
$params
);
$goodsSkuList
=
GoodsSku
::
select
(
"*"
,
[
"goods_spu_id"
=>
$goodsSpuId
]);
if
(
!
empty
(
$goodsSkuList
))
{
foreach
(
$goodsSkuList
as
$sku
)
{
self
::
editGoodsSku
(
$sku
[
"goods_sku_id"
],
$sku
,
$params
);
}
}
if
(
!
GoodsSpu
::
commit
())
{
GoodsSpu
::
rollback
();
throw
new
GoodsException
([
"cus"
=>
0
]);
}
return
true
;
}
private
static
function
editGoodsSpu
(
$goodsSpuId
,
$spuData
=
[])
{
return
GoodsSpu
::
save
([
"name"
=>
$spuData
[
"name"
],
"url"
=>
$spuData
[
"url"
],
"desc"
=>
$spuData
[
"desc"
],
"type"
=>
GoodsSpu
::
TYPE_VIRTUAL
,
"sub_type"
=>
GoodsSpu
::
SUB_TYPE_TO_SHOP
,
"sale_type"
=>
empty
(
$spuData
[
"setmeal"
])
?
GoodsSpu
::
SALE_TYPE_NO_COMBINATION
:
GoodsSpu
::
SALE_TYPE_COMBINATION
,
"rule_limit"
=>
$spuData
[
"rule_limit"
],
"rule_date_type"
=>
$spuData
[
"rule_date_type"
],
"rule_start_time"
=>
$spuData
[
"rule_start_time"
],
"rule_end_time"
=>
$spuData
[
"rule_end_time"
],
"rule_desc"
=>
$spuData
[
"rule_desc"
],
"rule_refund"
=>
$spuData
[
"rule_refund"
],
],
[
"goods_spu_id"
=>
$goodsSpuId
]);
}
private
static
function
editGoodsSku
(
$goodsSkuId
,
$skuData
,
$params
=
[])
{
$skuParams
=
[
"category_1_id"
=>
$params
[
"category_1_id"
],
"category_2_id"
=>
$params
[
"category_2_id"
],
"name"
=>
$params
[
"name"
],
"url"
=>
$params
[
"url"
],
"desc"
=>
$params
[
"desc"
],
"expiration_time"
=>
$params
[
"expiration_time"
],
"rule_limit"
=>
$params
[
"rule_limit"
],
"rule_date_type"
=>
$params
[
"rule_date_type"
],
"rule_start_time"
=>
$params
[
"rule_start_time"
],
"rule_end_time"
=>
$params
[
"rule_end_time"
],
"rule_desc"
=>
$params
[
"rule_desc"
],
"rule_refund"
=>
$params
[
"rule_refund"
],
"inventory_total"
=>
$params
[
"inventory_total"
],
"inventory_rest"
=>
$params
[
"inventory_total"
],
"original_price"
=>
$params
[
"original_price"
]
*
100
,
"price"
=>
$params
[
"price"
]
*
100
,
"version"
=>
(
int
)
$skuData
[
"version"
]
+
1
,
];
if
(
!
empty
(
$params
[
"setmeal"
]))
{
$skuParams
[
"setmeal"
]
=
$params
[
"setmeal"
];
}
return
GoodsSku
::
save
(
$skuParams
,
[
"goods_sku_id"
=>
$goodsSkuId
]);
}
}
}
\ No newline at end of file
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment