Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
P
php_utils
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
php_utils
Commits
866e88e9
Commit
866e88e9
authored
Aug 11, 2021
by
wanjilong
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'master' of
https://gitlab.yidian-inc.com/bp/php_utils
parents
d0e1aa8a
15534ea4
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
106 additions
and
20 deletions
+106
-20
GoodsSkuId.php
src/Common/GoodsSkuId.php
+85
-4
FileLog.php
src/Log/FileLog.php
+5
-16
Email.php
src/Message/Email.php
+16
-0
No files found.
src/Common/GoodsSkuId.php
View file @
866e88e9
...
...
@@ -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
src/Log/FileLog.php
View file @
866e88e9
...
...
@@ -62,21 +62,10 @@ class FileLog
$exception_info
=
''
;
}
$log
.=
' [exception info: ]'
.
$exception_info
;
$log
.=
' [debug_backtrace info: ]'
.
print_r
(
debug_backtrace
(),
1
);
error_log
(
$log
);
if
(
empty
(
$mail_to
))
{
$mail_to
=
[
'wangdanfeng@yidian-inc.com'
,
'cuiweifeng@yidian-inc.com'
,
'luhongguang@yidian-inc.com'
,
'wangdong1@yidian-inc.com'
,
'wanjilong@yidian-inc.com'
,
'jianghaiming@yidian-inc.com'
,
'songxiaohang@yidian-inc.com'
,
'genghongfei@yidian-inc.com'
,
'mengweifu@yidian-inc.com'
,
'guozhiyuan@yidian-inc.com'
,
'suntengda@yidian-inc.com'
];
$mail_to
=
'bp-server@yidian-inc.com'
;
}
$subject
=
'App api #'
.
$signature
.
'# '
.
$_SERVER
[
'SERVER_NAME'
]
.
' ('
.
$_SERVER
[
'SERVER_ADDR'
]
.
') Alert Message'
;
$body
=
'Error: '
.
$signature
.
"
\n\n
"
;
...
...
@@ -94,7 +83,7 @@ class FileLog
}
}
p
rivate
static
function
accessLog
()
p
ublic
static
function
accessLog
()
{
$url
=
'http://'
.
$_SERVER
[
'SERVER_NAME'
]
.
$_SERVER
[
'SCRIPT_NAME'
];
$query
=
http_build_query
(
$_GET
,
''
,
'&'
);
...
...
@@ -120,7 +109,7 @@ class FileLog
fclose
(
$log_file
);
}
p
rivate
static
function
ip
()
p
ublic
static
function
ip
()
{
if
(
isset
(
$_SERVER
[
'IPV6_REMOTE_ADDR'
])
&&
!
empty
(
$_SERVER
[
'IPV6_REMOTE_ADDR'
])
&&
trim
(
$_SERVER
[
'IPV6_REMOTE_ADDR'
])
!==
'-'
)
{
// 如果没有ipv6地址, 运维会传一个占位符“-”
$ips
=
$_SERVER
[
'IPV6_REMOTE_ADDR'
];
...
...
@@ -137,7 +126,7 @@ class FileLog
return
$ip
[
0
];
}
p
rivate
static
function
shouldSendEmail
(
$key
)
p
ublic
static
function
shouldSendEmail
(
$key
)
{
$result
=
true
;
// 每分钟发一条
...
...
src/Message/Email.php
View file @
866e88e9
...
...
@@ -2,6 +2,8 @@
namespace
Api\PhpUtils\Message
;
use
Yaf\Application
;
class
Email
{
/**
...
...
@@ -19,6 +21,10 @@ class Email
if
(
empty
(
$to
))
{
return
false
;
}
$env
=
Application
::
app
()
->
environ
();
if
(
$env
!=
'test'
&&
$env
!=
'prod'
&&
$env
!=
'perf'
){
return
false
;
}
if
(
empty
(
$from
))
{
$from
=
'noreply@yidian-inc.com'
;
}
...
...
@@ -30,6 +36,16 @@ class Email
fwrite
(
$sock
,
"HELO "
.
$domain
.
"
\r\n
"
);
fgets
(
$sock
);
fwrite
(
$sock
,
"auth login
\r\n
"
);
fgets
(
$sock
);
fwrite
(
$sock
,
"YnAtbm9yZXBseQ==
\r\n
"
);
fgets
(
$sock
);
fwrite
(
$sock
,
"VlhObGNtNWhiJFclVTY=
\r\n
"
);
fgets
(
$sock
);
fwrite
(
$sock
,
"MAIL FROM:<"
.
$from
.
">
\r\n
"
);
fgets
(
$sock
);
if
(
!
is_array
(
$to
))
{
...
...
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