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
5485d479
Commit
5485d479
authored
Aug 09, 2021
by
luhongguang
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
update:商品sku_id调整
parent
64f4f005
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
98 additions
and
10 deletions
+98
-10
GoodsException.php
application/exception/custom/GoodsException.php
+1
-0
GoodsService.php
application/services/goods/GoodsService.php
+10
-4
MarketingPindanGoodsService.php
application/services/goods/MarketingPindanGoodsService.php
+2
-2
GoodsSkuId.php
vendor/api/php_utils/src/Common/GoodsSkuId.php
+85
-4
No files found.
application/exception/custom/GoodsException.php
View file @
5485d479
...
...
@@ -55,5 +55,6 @@ class GoodsException extends BaseException
self
::
PRINTER_ALREADY_EXIST
=>
'打印机已被%s绑定'
,
self
::
EMPTY_OTA_ID
=>
'供应商id为空'
,
self
::
OTA_NOT_EXIST
=>
'供应商不存在'
,
39
=>
'商品id非法'
,
];
}
\ No newline at end of file
application/services/goods/GoodsService.php
View file @
5485d479
...
...
@@ -863,12 +863,18 @@ class GoodsService
*/
public
static
function
getGoodsSkuInfo
(
$params
=
[])
{
$marketingType
=
!
empty
(
$params
[
'marketing_type'
])
?
$params
[
'marketing_type'
]
:
0
;
if
(
$marketingType
==
Marketing
::
MARKETING_TYPE_PINDAN
)
{
return
MarketingPindanGoodsService
::
pindanGoodsInfo
(
$params
);
$goodsSukParams
=
GoodsSkuId
::
getGoodsSkuIdParams
(
$params
[
"goods_sku_id"
]);
if
(
!
empty
(
$goodsSukParams
))
{
if
(
isset
(
$goodsSukParams
[
"table_tag"
])
&&
(
$goodsSukParams
[
"table_tag"
]
==
GoodsSkuId
::
TABLE_TAG_PINDAN
||
$goodsSukParams
[
"category_1_id"
]
==
"00"
))
{
return
MarketingPindanGoodsService
::
pindanGoodsInfo
(
$params
);
}
else
{
return
self
::
generalGoodsInfo
(
$params
);
}
}
else
{
return
self
::
generalGoodsInfo
(
$params
);
throw
new
GoodsException
([
"cus"
=>
39
]
);
}
}
/**
...
...
application/services/goods/MarketingPindanGoodsService.php
View file @
5485d479
...
...
@@ -68,7 +68,7 @@ class MarketingPindanGoodsService
"life_account_id"
=>
$params
[
"life_account_id"
],
"merchant_id"
=>
$lifeAccountRes
[
"response"
][
"result"
][
"merchant_id"
],
];
$shopId
=
GoodsService
::
addShop
(
$lifeAccount
);
$spuData
=
self
::
addGoodsSpu
(
$shopId
,
$params
);
$skuId
=
self
::
addGoodsSku
(
$spuData
,
$shopId
,
$params
);
...
...
@@ -173,7 +173,7 @@ class MarketingPindanGoodsService
if
(
empty
(
$res
))
{
throw
new
GoodsException
([
'cus'
=>
2
]);
}
$skuId
=
GoodsSkuId
::
generateGoodSkuId
(
$res
[
0
],
0
,
0
,
$spuData
[
"goods_type"
],
$spuData
[
"belong_type"
]
);
$skuId
=
GoodsSkuId
::
generateGoodSkuId
(
$res
[
0
],
"00"
,
"000"
,
$spuData
[
"goods_type"
],
$spuData
[
"belong_type"
],
"001"
);
if
(
$skuData
[
"price"
]
<=
0
)
{
throw
new
GoodsException
([
'cus'
=>
33
]);
...
...
vendor/api/php_utils/src/Common/GoodsSkuId.php
View file @
5485d479
...
...
@@ -5,22 +5,28 @@ namespace Api\PhpUtils\Common;
class
GoodsSkuId
{
const
TABLE_TAG_GENERAL
=
"000"
;
//普通表 goods_sku 商品
const
TABLE_TAG_PINDAN
=
"001"
;
//接龙表 pindan_goods_sku 商品
/**
* 生成加密后的 sku_id
* id 非雪花算法生成的sku_id
* category_1_id 一级分类的id,两位,不足两位在十位补零
* category_2_id 二级分类的id,两位,不足三位在百位补零
* spu 商品类型,1虚拟商品,2实体商品
* goodsType 1、(默认)第三方商品 2、自营商品
* goodsType 商品类型,1虚拟商品,2实体商品 占一位
* belongType 1、(默认)第三方商品 2、自营商品 占一位
* tableTag 数据所在表: 000: goods_sku, 001: pindan_goods_sku
*
* @param $id
* @param $category1Id
* @param $category2Id
* @param $spuType
* @param $goodsType
* @param $belongType
* @param $tableTag
* @return string
*/
public
static
function
generateGoodSkuId
(
$id
,
$category1Id
,
$category2Id
,
$
spuType
,
$goodsType
=
1
)
public
static
function
generateGoodSkuId
(
$id
,
$category1Id
,
$category2Id
,
$
goodsType
,
$belongType
=
1
,
$tableTag
=
"000"
)
{
if
(
strlen
(
$category1Id
)
==
1
)
{
$category1Id
=
"0"
.
$category1Id
;
...
...
@@ -28,7 +34,7 @@ class GoodsSkuId
if
(
strlen
(
$category2Id
)
==
2
)
{
$category2Id
=
"0"
.
$category2Id
;
}
$idStr
=
$id
.
$category1Id
.
$category2Id
.
$
spuType
.
$goodsType
;
$idStr
=
$id
.
$category1Id
.
$category2Id
.
$
goodsType
.
$belongType
.
$tableTag
;
//转62进制
$tmp
=
BaseConvert
::
decToOther
(
$idStr
);
...
...
@@ -97,4 +103,79 @@ class GoodsSkuId
return
$ret
===
$code
;
}
/**
* 恢复加密前的订单号
* @param $str
* @return bool|int|string
*/
public
static
function
recoverGoodSkuId
(
$str
)
{
$strlen
=
strlen
(
$str
);
$chklen
=
2
;
$code
=
substr
(
$str
,
-
$chklen
);
$str
=
substr
(
$str
,
0
,
$strlen
-
$chklen
);
$strlen
-=
$chklen
;
$base
=
'0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz'
;
if
(
$strlen
%
2
==
1
)
{
$str
=
'0'
.
$str
;
$strlen
+=
1
;
}
$sum
=
0
;
$len
=
$strlen
/
2
;
for
(
$i
=
0
;
$i
<
$len
;
$i
++
)
{
$sum
*=
137
;
$sum
+=
ord
(
$str
[
$i
])
^
ord
(
$str
[
$strlen
-
$i
-
1
]);
}
$ret
=
''
;
for
(
$i
=
$chklen
;
$i
>
0
;
$i
--
)
{
$idx
=
$sum
%
62
;
$sum
=
(
$sum
-
$idx
)
/
62
;
$ret
=
$base
[
$idx
]
.
$ret
;
}
if
(
$ret
===
$code
)
{
$codeLen
=
strlen
(
$code
);
return
BaseConvert
::
otherToDec
(
$str
);
}
return
""
;
}
/**
* 根据skuId获取对应的参数
* @param $goodsSkuId
* @return array
*/
public
static
function
getGoodsSkuIdParams
(
$goodsSkuId
)
{
$goodsSkuIdNum
=
self
::
recoverGoodSkuId
(
$goodsSkuId
);
$data
=
[];
if
(
!
empty
(
$goodsSkuIdNum
))
{
$idgenId
=
substr
(
$goodsSkuIdNum
,
0
,
20
);
$category1Id
=
substr
(
$goodsSkuIdNum
,
20
,
2
);
$category2Id
=
substr
(
$goodsSkuIdNum
,
22
,
3
);
$goodsType
=
substr
(
$goodsSkuIdNum
,
25
,
1
);
$belongType
=
substr
(
$goodsSkuIdNum
,
26
,
1
);
$tableTag
=
substr
(
$goodsSkuIdNum
,
27
,
3
);
$data
=
[
"idgent_id"
=>
$idgenId
,
"category_1_id"
=>
$category1Id
,
"category_2_id"
=>
$category2Id
,
"goods_type"
=>
$goodsType
,
"belong_type"
=>
$belongType
,
"table_tag"
=>
$tableTag
,
];
}
return
$data
;
}
}
\ 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