Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
T
taobao-mini-template
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
2
Issues
2
List
Board
Labels
Milestones
Merge Requests
1
Merge Requests
1
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
qinhaitao
taobao-mini-template
Commits
66c67294
Commit
66c67294
authored
Nov 05, 2020
by
qinhaitao
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feat:
🎸
update
parent
551fe6bc
Changes
9
Hide whitespace changes
Inline
Side-by-side
Showing
9 changed files
with
59 additions
and
31 deletions
+59
-31
package.json
v2.0/package.json
+5
-3
task.controller.ts
v2.0/src/controller/task.controller.ts
+0
-1
preUpdate.ts
v2.0/src/decorator/common/preUpdate.ts
+4
-6
base.service.ts
v2.0/src/service/base.service.ts
+1
-1
resultModel.d.ts
v2.0/src/typings/resultModel.d.ts
+1
-1
checkExchangeCreditsTask.ts
v2.0/src/utils/common/check/checkExchangeCreditsTask.ts
+1
-1
format.ts
v2.0/src/utils/common/format.ts
+16
-13
sendTBAward.ts
v2.0/src/utils/common/sendTBAward.ts
+1
-1
yarn.lock
v2.0/yarn.lock
+30
-4
No files found.
v2.0/package.json
View file @
66c67294
...
@@ -8,10 +8,12 @@
...
@@ -8,10 +8,12 @@
"sdkVersion"
:
"*"
,
"sdkVersion"
:
"*"
,
"dependencies"
:
{
"dependencies"
:
{
"dayjs"
:
"^1.8.28"
,
"dayjs"
:
"^1.8.28"
,
"get-value"
:
"^3.0.1"
,
"lodash"
:
"^4.17.20"
,
"lodash"
:
"^4.17.20"
,
"node-xlsx"
:
"^0.15.0"
,
"node-xlsx"
:
"^0.15.0"
,
"set-value"
:
"^3.0.2"
,
"source-map-support"
:
"^0.5.19"
,
"source-map-support"
:
"^0.5.19"
,
"taobao-mini-sdk"
:
"^0.2.
3
"
"taobao-mini-sdk"
:
"^0.2.
4
"
},
},
"scripts"
:
{
"scripts"
:
{
"start"
:
"tsc"
,
"start"
:
"tsc"
,
...
@@ -30,7 +32,7 @@
...
@@ -30,7 +32,7 @@
"eslint-config-prettier"
:
"^6.11.0"
,
"eslint-config-prettier"
:
"^6.11.0"
,
"eslint-plugin-prettier"
:
"^3.1.4"
,
"eslint-plugin-prettier"
:
"^3.1.4"
,
"prettier"
:
"^2.0.5"
,
"prettier"
:
"^2.0.5"
,
"t
ypescript"
:
"^3.9.7
"
,
"t
s-node"
:
"^9.0.0
"
,
"t
s-node"
:
"^9.0.0
"
"t
ypescript"
:
"^3.9.7
"
}
}
}
}
v2.0/src/controller/task.controller.ts
View file @
66c67294
/** @format */
/** @format */
import
{
CODE_TYPES
}
from
'./../constants'
import
{
checkParams
,
services
,
registeInfos
,
preCheck
}
from
'../decorator/common'
import
{
checkParams
,
services
,
registeInfos
,
preCheck
}
from
'../decorator/common'
import
{
resultsModel
}
from
'../sdk'
import
{
resultsModel
}
from
'../sdk'
import
{
TaskService
,
BaseService
}
from
'../service'
import
{
TaskService
,
BaseService
}
from
'../service'
...
...
v2.0/src/decorator/common/preUpdate.ts
View file @
66c67294
/** @format */
/** @format */
import
{
is
Empty
,
merge
}
from
'lodash'
import
{
is
Array
,
isEmpty
,
isObject
,
merge
}
from
'lodash'
import
{
UserService
}
from
'../../service'
import
{
UserService
}
from
'../../service'
import
{
recordErrorLog
}
from
'../../utils/common/logger'
import
{
recordErrorLog
}
from
'../../utils/common/logger'
import
{
resultsModel
}
from
'../../sdk'
import
{
resultsModel
}
from
'../../sdk'
import
{
CODE_TYPES
}
from
'../../errorCode'
import
{
CODE_TYPES
}
from
'../../errorCode'
import
{
formatUpdatedUserInfo
}
from
'../../utils/common/format'
import
{
formatUpdatedDataByProjection
}
from
'../../utils/common/format'
import
{
userInfo
}
from
'os'
// 检验参数是否存在
// 检验参数是否存在
export
default
function
preUpdate
(
checks
:
IFunction
[])
{
export
default
function
preUpdate
(
checks
:
IFunction
[])
{
...
@@ -31,11 +30,11 @@ export default function preUpdate(checks: IFunction[]) {
...
@@ -31,11 +30,11 @@ export default function preUpdate(checks: IFunction[]) {
otherArgs
=
{
...
otherArgs
}
otherArgs
=
{
...
otherArgs
}
}
}
console
.
log
(
formatUpdatedUserInfo
(
otherArgs
.
userInfo
,
totalUpdateProjection
))
// 更新数据
// 更新数据
try
{
try
{
await
preUpdateUser
(
context
,
otherArgs
.
userInfo
,
totalUpdateProjection
)
await
preUpdateUser
(
context
,
otherArgs
.
userInfo
,
totalUpdateProjection
)
// 避免再次查询
otherArgs
.
userInfo
=
formatUpdatedDataByProjection
(
otherArgs
.
userInfo
,
totalUpdateProjection
)
}
catch
(
error
)
{
}
catch
(
error
)
{
console
.
log
(
error
,
'preUpdateUser-error'
)
console
.
log
(
error
,
'preUpdateUser-error'
)
recordErrorLog
(
context
,
otherArgs
,
error
.
toString
(),
error
.
stack
)
recordErrorLog
(
context
,
otherArgs
,
error
.
toString
(),
error
.
stack
)
...
@@ -47,7 +46,6 @@ export default function preUpdate(checks: IFunction[]) {
...
@@ -47,7 +46,6 @@ export default function preUpdate(checks: IFunction[]) {
}
}
async
function
preUpdateUser
(
context
:
IContext
<
IParams
>
,
userInfo
:
IUserInfo
,
updateProjection
:
IPreUpdateQuery
)
{
async
function
preUpdateUser
(
context
:
IContext
<
IParams
>
,
userInfo
:
IUserInfo
,
updateProjection
:
IPreUpdateQuery
)
{
return
true
// 删除空的操作
// 删除空的操作
if
(
isEmpty
(
updateProjection
.
$inc
))
{
if
(
isEmpty
(
updateProjection
.
$inc
))
{
delete
updateProjection
.
$inc
delete
updateProjection
.
$inc
...
...
v2.0/src/service/base.service.ts
View file @
66c67294
...
@@ -36,7 +36,7 @@ export default class BaseService {
...
@@ -36,7 +36,7 @@ export default class BaseService {
async
getItemListByIds
(
itemIds
:
string
,
session
:
string
):
Promise
<
Array
<
ITaoBaoItems
>>
{
async
getItemListByIds
(
itemIds
:
string
,
session
:
string
):
Promise
<
Array
<
ITaoBaoItems
>>
{
const
GOODSINFO
=
const
GOODSINFO
=
'detail_url,approve_status,num_iid,title,nick,type,cid,pic_url,num,props,valid_thru,list_time,desc,price,has_discount,has_invoice,has_warranty,has_showcase,modified,delist_time,postage_id,seller_cids,outer_id,sold_quantity'
'detail_url,approve_status,num_iid,title,nick,type,cid,pic_url,num,props,valid_thru,list_time,desc,price,has_discount,has_invoice,has_warranty,has_showcase,modified,delist_time,postage_id,seller_cids,outer_id,sold_quantity'
const
result
=
await
TBAPIS
.
getItemListByItemIds
(
this
.
context
,
session
,
itemIds
,
{
fields
:
GOODSINFO
})
const
result
=
await
TBAPIS
.
getItemListByItemIds
(
this
.
context
,
itemIds
,
{
fields
:
GOODSINFO
})
const
items
=
result
?.
items
?.
item
||
[]
const
items
=
result
?.
items
?.
item
||
[]
const
list
=
items
.
map
(
const
list
=
items
.
map
(
(
v
:
{
num_iid
:
string
;
title
:
string
;
price
:
string
;
detail_url
:
string
;
pic_url
:
string
;
desc
:
string
})
=>
{
(
v
:
{
num_iid
:
string
;
title
:
string
;
price
:
string
;
detail_url
:
string
;
pic_url
:
string
;
desc
:
string
})
=>
{
...
...
v2.0/src/typings/resultModel.d.ts
View file @
66c67294
...
@@ -13,7 +13,7 @@ interface ISuccessResult<T> {
...
@@ -13,7 +13,7 @@ interface ISuccessResult<T> {
interface
ICodeType
{
interface
ICodeType
{
code
:
string
code
:
string
defaultMsg
?
:
string
defaultMsg
:
string
}
}
type
IResult
<
T
>
=
T
extends
ICodeType
?
IErrorResult
:
IErrorResult
|
ISuccessResult
<
T
>
type
IResult
<
T
>
=
T
extends
ICodeType
?
IErrorResult
:
IErrorResult
|
ISuccessResult
<
T
>
v2.0/src/utils/common/check/checkExchangeCreditsTask.ts
View file @
66c67294
...
@@ -22,7 +22,7 @@ export default async function checkExchangeCreditsTask(
...
@@ -22,7 +22,7 @@ export default async function checkExchangeCreditsTask(
if
(
myCredits
<
credits
)
return
resultsModel
.
error
(
CODE_TYPES
.
ERROR_NO_CREDITS
)
if
(
myCredits
<
credits
)
return
resultsModel
.
error
(
CODE_TYPES
.
ERROR_NO_CREDITS
)
// 扣积分
// 扣积分
let
result
=
await
TBAPIS
.
changeCredits
(
context
,
session
,
{
let
result
=
await
TBAPIS
.
changeCredits
(
context
,
{
quantity
:
+
credits
,
quantity
:
+
credits
,
change_type
:
2
,
//变更类型:0交易,1:互动活动,2:权益兑换,3:手工调整
change_type
:
2
,
//变更类型:0交易,1:互动活动,2:权益兑换,3:手工调整
opt_type
:
1
,
// 操作类型,'0':增加,1:扣减
opt_type
:
1
,
// 操作类型,'0':增加,1:扣减
...
...
v2.0/src/utils/common/format.ts
View file @
66c67294
/** @format */
/** @format */
import
{
assign
,
isEmpty
,
merge
}
from
'lodash'
import
{
assign
,
isEmpty
,
merge
}
from
'lodash'
import
*
as
set
from
'set-value'
import
*
as
get
from
'get-value'
/**
/**
* updateUser projection 格式化
* updateUser projection 格式化
...
@@ -42,27 +44,28 @@ export function formatUserNick(name: string) {
...
@@ -42,27 +44,28 @@ export function formatUserNick(name: string) {
* @param {IUserInfo} userInfo
* @param {IUserInfo} userInfo
* @param {IDecoratorUpdateQuery} projection
* @param {IDecoratorUpdateQuery} projection
*/
*/
export
function
formatUpdated
UserInfo
(
userInfo
:
IUserInfo
,
projection
:
IPreUpdateQuery
)
{
export
function
formatUpdated
DataByProjection
(
dbData
:
object
,
projection
:
IPreUpdateQuery
)
{
let
updated
UserInfo
=
assign
({},
userInfo
)
let
updated
DbData
=
assign
({},
dbData
)
if
(
!
isEmpty
(
projection
.
$set
))
{
if
(
!
isEmpty
(
projection
.
$set
))
{
updatedUserInfo
=
merge
({},
userInfo
,
projection
.
$set
)
Object
.
keys
(
projection
.
$set
).
forEach
(
key
=>
{
set
(
updatedDbData
,
key
,
projection
.
$set
?.[
key
])
})
}
}
if
(
!
isEmpty
(
projection
.
$inc
))
{
if
(
!
isEmpty
(
projection
.
$inc
))
{
Object
.
keys
(
projection
.
$inc
).
forEach
(
key
=>
{
Object
.
keys
(
projection
.
$inc
).
forEach
(
key
=>
{
// let splitKey
const
originValue
=
get
(
updatedDbData
,
key
)
||
0
set
(
updatedDbData
,
key
,
projection
.
$inc
?.[
key
]
+
originValue
)
})
})
updated
UserInfo
=
merge
({},
userInfo
,
projection
.
$set
)
updated
DbData
=
merge
({},
dbData
,
projection
.
$set
)
}
}
}
function
format$Set
(
userInfo
:
IUserInfo
,
setProjection
:
object
)
{
if
(
!
isEmpty
(
projection
.
$push
))
{
Object
.
keys
(
setProjection
).
forEach
(
setKey
=>
{
Object
.
keys
(
projection
.
$push
).
forEach
(
key
=>
{
const
splitKey
=
setKey
.
split
(
'.'
)
const
originValue
=
get
(
updatedDbData
,
key
)
||
[]
let
result
=
{}
set
(
updatedDbData
,
key
,
[...
originValue
,
projection
.
$push
?.[
key
]])
splitKey
.
forEach
((
key
,
i
)
=>
{
result
[
key
]
=
i
===
splitKey
.
length
-
1
?
setProjection
[
setKey
]
:
{}
})
})
})
}
return
updatedDbData
}
}
v2.0/src/utils/common/sendTBAward.ts
View file @
66c67294
...
@@ -50,7 +50,7 @@ export const sendTBAward = async (
...
@@ -50,7 +50,7 @@ export const sendTBAward = async (
export
const
sendCredits
=
async
(
credits
:
number
,
session
:
string
,
context
:
IContext
<
IParams
>
)
=>
{
export
const
sendCredits
=
async
(
credits
:
number
,
session
:
string
,
context
:
IContext
<
IParams
>
)
=>
{
let
drawStatus
=
0
let
drawStatus
=
0
let
remark
=
''
let
remark
=
''
let
result
=
await
TBAPIS
.
changeCredits
(
context
,
session
,
{
let
result
=
await
TBAPIS
.
changeCredits
(
context
,
{
quantity
:
credits
,
quantity
:
credits
,
change_type
:
2
,
change_type
:
2
,
opt_type
:
'0'
,
opt_type
:
'0'
,
...
...
v2.0/yarn.lock
View file @
66c67294
...
@@ -547,6 +547,13 @@ get-stdin@^6.0.0:
...
@@ -547,6 +547,13 @@ get-stdin@^6.0.0:
resolved "https://registry.npm.taobao.org/get-stdin/download/get-stdin-6.0.0.tgz#9e09bf712b360ab9225e812048f71fde9c89657b"
resolved "https://registry.npm.taobao.org/get-stdin/download/get-stdin-6.0.0.tgz#9e09bf712b360ab9225e812048f71fde9c89657b"
integrity sha1-ngm/cSs2CrkiXoEgSPcf3pyJZXs=
integrity sha1-ngm/cSs2CrkiXoEgSPcf3pyJZXs=
get-value@^3.0.1:
version "3.0.1"
resolved "https://registry.npm.taobao.org/get-value/download/get-value-3.0.1.tgz#5efd2a157f1d6a516d7524e124ac52d0a39ef5a8"
integrity sha1-Xv0qFX8dalFtdSThJKxS0KOe9ag=
dependencies:
isobject "^3.0.1"
glob-parent@^5.0.0:
glob-parent@^5.0.0:
version "5.1.1"
version "5.1.1"
resolved "https://registry.npm.taobao.org/glob-parent/download/glob-parent-5.1.1.tgz?cache=0&sync_timestamp=1584836110944&other_urls=https%3A%2F%2Fregistry.npm.taobao.org%2Fglob-parent%2Fdownload%2Fglob-parent-5.1.1.tgz#b6c1ef417c4e5663ea498f1c45afac6916bbc229"
resolved "https://registry.npm.taobao.org/glob-parent/download/glob-parent-5.1.1.tgz?cache=0&sync_timestamp=1584836110944&other_urls=https%3A%2F%2Fregistry.npm.taobao.org%2Fglob-parent%2Fdownload%2Fglob-parent-5.1.1.tgz#b6c1ef417c4e5663ea498f1c45afac6916bbc229"
...
@@ -631,11 +638,23 @@ is-glob@^4.0.0, is-glob@^4.0.1:
...
@@ -631,11 +638,23 @@ is-glob@^4.0.0, is-glob@^4.0.1:
dependencies:
dependencies:
is-extglob "^2.1.1"
is-extglob "^2.1.1"
is-plain-object@^2.0.4:
version "2.0.4"
resolved "https://registry.npm.taobao.org/is-plain-object/download/is-plain-object-2.0.4.tgz?cache=0&sync_timestamp=1599667338683&other_urls=https%3A%2F%2Fregistry.npm.taobao.org%2Fis-plain-object%2Fdownload%2Fis-plain-object-2.0.4.tgz#2c163b3fafb1b606d9d17928f05c2a1c38e07677"
integrity sha1-LBY7P6+xtgbZ0Xko8FwqHDjgdnc=
dependencies:
isobject "^3.0.1"
isexe@^2.0.0:
isexe@^2.0.0:
version "2.0.0"
version "2.0.0"
resolved "https://registry.npm.taobao.org/isexe/download/isexe-2.0.0.tgz#e8fbf374dc556ff8947a10dcb0572d633f2cfa10"
resolved "https://registry.npm.taobao.org/isexe/download/isexe-2.0.0.tgz#e8fbf374dc556ff8947a10dcb0572d633f2cfa10"
integrity sha1-6PvzdNxVb/iUehDcsFctYz8s+hA=
integrity sha1-6PvzdNxVb/iUehDcsFctYz8s+hA=
isobject@^3.0.1:
version "3.0.1"
resolved "https://registry.npm.taobao.org/isobject/download/isobject-3.0.1.tgz#4e431e92b11a9731636aa1f9c8d1ccbcfdab78df"
integrity sha1-TkMekrEalzFjaqH5yNHMvP2reN8=
js-tokens@^4.0.0:
js-tokens@^4.0.0:
version "4.0.0"
version "4.0.0"
resolved "https://registry.npm.taobao.org/js-tokens/download/js-tokens-4.0.0.tgz#19203fb59991df98e3a287050d4647cdeaf32499"
resolved "https://registry.npm.taobao.org/js-tokens/download/js-tokens-4.0.0.tgz#19203fb59991df98e3a287050d4647cdeaf32499"
...
@@ -804,6 +823,13 @@ semver@^7.2.1, semver@^7.3.2:
...
@@ -804,6 +823,13 @@ semver@^7.2.1, semver@^7.3.2:
resolved "https://registry.npm.taobao.org/semver/download/semver-7.3.2.tgz?cache=0&sync_timestamp=1586886267748&other_urls=https%3A%2F%2Fregistry.npm.taobao.org%2Fsemver%2Fdownload%2Fsemver-7.3.2.tgz#604962b052b81ed0786aae84389ffba70ffd3938"
resolved "https://registry.npm.taobao.org/semver/download/semver-7.3.2.tgz?cache=0&sync_timestamp=1586886267748&other_urls=https%3A%2F%2Fregistry.npm.taobao.org%2Fsemver%2Fdownload%2Fsemver-7.3.2.tgz#604962b052b81ed0786aae84389ffba70ffd3938"
integrity sha1-YElisFK4HtB4aq6EOJ/7pw/9OTg=
integrity sha1-YElisFK4HtB4aq6EOJ/7pw/9OTg=
set-value@^3.0.2:
version "3.0.2"
resolved "https://registry.npm.taobao.org/set-value/download/set-value-3.0.2.tgz#74e8ecd023c33d0f77199d415409a40f21e61b90"
integrity sha1-dOjs0CPDPQ93GZ1BVAmkDyHmG5A=
dependencies:
is-plain-object "^2.0.4"
shebang-command@^2.0.0:
shebang-command@^2.0.0:
version "2.0.0"
version "2.0.0"
resolved "https://registry.npm.taobao.org/shebang-command/download/shebang-command-2.0.0.tgz#ccd0af4f8835fbdc265b82461aaf0c36663f34ea"
resolved "https://registry.npm.taobao.org/shebang-command/download/shebang-command-2.0.0.tgz#ccd0af4f8835fbdc265b82461aaf0c36663f34ea"
...
@@ -902,10 +928,10 @@ table@^5.2.3:
...
@@ -902,10 +928,10 @@ table@^5.2.3:
slice-ansi "^2.1.0"
slice-ansi "^2.1.0"
string-width "^3.0.0"
string-width "^3.0.0"
taobao-mini-sdk@^0.2.
3
:
taobao-mini-sdk@^0.2.
4
:
version "0.2.
3
"
version "0.2.
4
"
resolved "https://registry.npm.taobao.org/taobao-mini-sdk/download/taobao-mini-sdk-0.2.
3.tgz#5b678fa6d538889301a54f7d5f4ca428cdb3ba6e
"
resolved "https://registry.npm.taobao.org/taobao-mini-sdk/download/taobao-mini-sdk-0.2.
4.tgz#5074718bd4135263adbabbf30d8c6b44a0da1d9a
"
integrity sha1-
W2ePptU4iJMBpU99X0ykKM2zum4
=
integrity sha1-
UHRxi9QTUmOturvzDYxrRKDaHZo
=
dependencies:
dependencies:
"@types/mongodb" "^3.5.26"
"@types/mongodb" "^3.5.26"
...
...
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