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
12bfe357
Commit
12bfe357
authored
Jun 15, 2021
by
luhongguang
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
update:添加商品
parent
06e13e25
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
67 additions
and
39 deletions
+67
-39
GoodsAddValidate.php
application/library/Validate/GoodsAddValidate.php
+27
-0
GoodsSpu.php
application/models/goods/mysql/GoodsSpu.php
+9
-0
Goods.php
application/modules/Goods/controllers/Goods.php
+2
-18
GoodsService.php
application/services/goods/GoodsService.php
+29
-21
No files found.
application/library/Validate/GoodsAddValidate.php
0 → 100644
View file @
12bfe357
<?php
namespace
Validate
;
/**
* Class GoodsAddValidate
*
* @package Validate
*/
class
GoodsAddValidate
extends
BaseValidate
{
protected
$rule
=
[
// 'goods_spu_id' => 'require',
// 'online_status' => 'require',
// 'uid' => 'require',
// 'username' => 'require',
];
protected
$message
=
[
"goods_spu_id"
=>
"商品id不能为空"
,
"online_status"
=>
"商品上下架状态不能为空"
,
"uid"
=>
"用户id不能为空"
,
"username"
=>
"用户username不能为空"
,
];
}
\ No newline at end of file
application/models/goods/mysql/GoodsSpu.php
View file @
12bfe357
...
@@ -14,6 +14,15 @@ class GoodsSpu extends MysqlBase
...
@@ -14,6 +14,15 @@ class GoodsSpu extends MysqlBase
const
TABLE_NAME
=
'goods_spu'
;
const
TABLE_NAME
=
'goods_spu'
;
const
CONFIG_INDEX
=
'goods'
;
const
CONFIG_INDEX
=
'goods'
;
const
TYPE_VIRTUAL
=
1
;
//虚拟商品
const
TYPE_ENTITY
=
2
;
//实体商品
const
SUB_TYPE_TO_SHOP
=
1
;
//到店
const
SUB_TYPE_ONLINE
=
2
;
//线上
const
SALE_TYPE_NO_COMBINATION
=
1
;
//非组合商品(无套餐)
const
SALE_TYPE_COMBINATION
=
2
;
//组合商品(有套餐)
public
static
function
getRecord
(
$where
,
$colums
=
[])
public
static
function
getRecord
(
$where
,
$colums
=
[])
{
{
if
(
empty
(
$colums
))
{
if
(
empty
(
$colums
))
{
...
...
application/modules/Goods/controllers/Goods.php
View file @
12bfe357
...
@@ -23,24 +23,8 @@ class GoodsController extends Base
...
@@ -23,24 +23,8 @@ class GoodsController extends Base
*/
*/
public
function
addAction
()
public
function
addAction
()
{
{
$lifeAccountId
=
111
;
$params
=
$this
->
params
;
$params
=
[
GoodsService
::
addGoods
(
$params
);
"name"
=>
"商品name"
,
"url"
=>
"url1, url2, url3"
,
"desc"
=>
"描述描述"
,
"category_1_id"
=>
1
,
"category_2_id"
=>
13
,
"expiration_time"
=>
"2021-06-10 12:20:30"
,
"rule_limit"
=>
3
,
"rule_date_type"
=>
1
,
"rule_start_time"
=>
"2021-06-11 12:20:30"
,
"rule_end_time"
=>
"2021-06-12 12:20:30"
,
"rule_desc"
=>
"规则描述"
,
"inventory_total"
=>
10
,
"original_price"
=>
1500
,
"price"
=>
500
,
];
GoodsService
::
addGoods
(
$lifeAccountId
,
$params
);
$this
->
success
();
$this
->
success
();
}
}
...
...
application/services/goods/GoodsService.php
View file @
12bfe357
...
@@ -40,31 +40,21 @@ class GoodsService
...
@@ -40,31 +40,21 @@ class GoodsService
/**
/**
* 添加商品
* 添加商品
* @param $lifeAccountId
* @param array $params
* @param array $params
* @return mixed
* @return mixed
* @throws GoodsException
* @throws GoodsException
*/
*/
public
static
function
addGoods
(
$
lifeAccountId
,
$
params
=
[])
public
static
function
addGoods
(
$params
=
[])
{
{
//todo:: 获取 $lifeAccount信息
$lifeAccount
=
[
"life_account_id"
=>
111
,
"merchant_id"
=>
1
,
"life_account_name"
=>
"测试测试"
,
];
GoodsSpu
::
beginTransaction
();
GoodsSpu
::
beginTransaction
();
$shopId
=
self
::
addShop
(
$lifeAccount
);
$lifeAccount
=
[
"life_account_id"
=>
$params
[
"life_account_id"
],
$spuData
=
[
"merchant_id"
=>
$params
[
"merchant_id"
],
"name"
=>
$params
[
"name"
],
"url"
=>
$params
[
"url"
],
"desc"
=>
$params
[
"desc"
],
];
];
$spuId
=
self
::
addGoodsSpu
(
$shopId
,
$spuData
);
$shopId
=
self
::
addShop
(
$lifeAccount
);
$skuId
=
self
::
addGoodsSku
(
$spuId
,
$shopId
,
$lifeAccountId
,
$params
);
$spuId
=
self
::
addGoodsSpu
(
$shopId
,
$params
);
$skuId
=
self
::
addGoodsSku
(
$spuId
,
$shopId
,
$params
);
if
(
!
GoodsSpu
::
commit
())
{
if
(
!
GoodsSpu
::
commit
())
{
GoodsSpu
::
rollback
();
GoodsSpu
::
rollback
();
...
@@ -87,12 +77,23 @@ class GoodsService
...
@@ -87,12 +77,23 @@ class GoodsService
throw
new
GoodsException
([
'cus'
=>
2
]);
throw
new
GoodsException
([
'cus'
=>
2
]);
}
}
$spuId
=
$res
[
0
];
$spuId
=
$res
[
0
];
GoodsSpu
::
save
([
GoodsSpu
::
save
([
"goods_spu_id"
=>
$spuId
,
"goods_spu_id"
=>
$spuId
,
"shop_id"
=>
$shopId
,
"shop_id"
=>
$shopId
,
"life_account_id"
=>
$spuData
[
"life_account_id"
],
"name"
=>
$spuData
[
"name"
],
"name"
=>
$spuData
[
"name"
],
"url"
=>
$spuData
[
"url"
],
"url"
=>
$spuData
[
"url"
],
"desc"
=>
$spuData
[
"desc"
],
"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"
],
]);
]);
return
$spuId
;
return
$spuId
;
}
}
...
@@ -106,18 +107,19 @@ class GoodsService
...
@@ -106,18 +107,19 @@ class GoodsService
* @return mixed
* @return mixed
* @throws GoodsException
* @throws GoodsException
*/
*/
private
static
function
addGoodsSku
(
$spuId
,
$shopId
,
$
lifeAccountId
,
$
skuData
=
[])
private
static
function
addGoodsSku
(
$spuId
,
$shopId
,
$skuData
=
[])
{
{
$res
=
self
::
getIdgenId
(
substr
(
$shopId
,
-
2
),
"goods"
);
$res
=
self
::
getIdgenId
(
substr
(
$shopId
,
-
2
),
"goods"
);
if
(
empty
(
$res
))
{
if
(
empty
(
$res
))
{
throw
new
GoodsException
([
'cus'
=>
2
]);
throw
new
GoodsException
([
'cus'
=>
2
]);
}
}
$skuId
=
$res
[
0
];
$skuId
=
$res
[
0
];
GoodsSku
::
save
([
$skuParams
=
[
"goods_spu_id"
=>
$spuId
,
"goods_spu_id"
=>
$spuId
,
"goods_sku_id"
=>
$skuId
,
"goods_sku_id"
=>
$skuId
,
"shop_id"
=>
$shopId
,
"shop_id"
=>
$shopId
,
"life_account_id"
=>
$
lifeAccountId
,
"life_account_id"
=>
$
skuData
[
"life_account_id"
]
,
"category_1_id"
=>
$skuData
[
"category_1_id"
],
"category_1_id"
=>
$skuData
[
"category_1_id"
],
"category_2_id"
=>
$skuData
[
"category_2_id"
],
"category_2_id"
=>
$skuData
[
"category_2_id"
],
"name"
=>
$skuData
[
"name"
],
"name"
=>
$skuData
[
"name"
],
...
@@ -129,10 +131,16 @@ class GoodsService
...
@@ -129,10 +131,16 @@ class GoodsService
"rule_start_time"
=>
$skuData
[
"rule_start_time"
],
"rule_start_time"
=>
$skuData
[
"rule_start_time"
],
"rule_end_time"
=>
$skuData
[
"rule_end_time"
],
"rule_end_time"
=>
$skuData
[
"rule_end_time"
],
"rule_desc"
=>
$skuData
[
"rule_desc"
],
"rule_desc"
=>
$skuData
[
"rule_desc"
],
"rule_refund"
=>
$skuData
[
"rule_refund"
],
"inventory_total"
=>
$skuData
[
"inventory_total"
],
"inventory_total"
=>
$skuData
[
"inventory_total"
],
"inventory_rest"
=>
$skuData
[
"inventory_total"
],
"original_price"
=>
$skuData
[
"original_price"
],
"original_price"
=>
$skuData
[
"original_price"
],
"price"
=>
$skuData
[
"price"
],
"price"
=>
$skuData
[
"price"
],
]);
];
if
(
!
empty
(
$skuData
[
"setmeal"
]))
{
$skuParams
[
"setmeal"
]
=
$skuData
[
"setmeal"
];
}
GoodsSku
::
save
(
$skuParams
);
return
$skuId
;
return
$skuId
;
}
}
...
...
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