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
f011efb5
Commit
f011efb5
authored
Sep 02, 2021
by
pengfei
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'colonel' into develop
parents
8d194313
b61d4953
Changes
9
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
9 changed files
with
551 additions
and
438 deletions
+551
-438
GoodsException.php
application/exception/custom/GoodsException.php
+1
-0
Colonelorder.php
application/modules/Cli/controllers/Colonelorder.php
+0
-263
Colonelwallet.php
application/modules/Cli/controllers/Colonelwallet.php
+0
-138
ColonelOrder.php
application/modules/Job/controllers/ColonelOrder.php
+250
-1
ColonelWallet.php
application/modules/Job/controllers/ColonelWallet.php
+125
-1
GoodsService.php
application/services/goods/GoodsService.php
+131
-30
MarketingGoodsService.php
application/services/marketing/MarketingGoodsService.php
+7
-3
MarketingService.php
application/services/marketing/MarketingService.php
+3
-0
Goods.php
daemon/Goods.php
+34
-2
No files found.
application/exception/custom/GoodsException.php
View file @
f011efb5
...
...
@@ -70,5 +70,6 @@ class GoodsException extends BaseException
49
=>
'库存不得小于已售库存'
,
self
::
RULE_LIMIT_ERROR
=>
'单人可买上限填写错误'
,
self
::
NOT_FIND_MARKETING
=>
'找不到活动'
,
52
=>
'过期时间不得小于等于上架开始时间'
,
];
}
\ No newline at end of file
application/modules/Cli/controllers/Colonelorder.php
deleted
100644 → 0
View file @
8d194313
<?php
use
Api\PhpServices\Idgen\Idgen
;
use
Api\PhpUtils\Log\FileLog
;
use
App\Base\Cli
;
use
App\Models\marketing\mysql\ColonelDistributorColonel
;
use
App\Models\marketing\mysql\ColonelDistributorConfig
;
use
App\Models\marketing\mysql\ColonelDistributorInviteOrderNum
;
use
App\Models\marketing\mysql\ColonelDistributorPayInfo
;
use
App\Exception\custom\InterfaceException
;
use
Api\PhpUtils\Http\HttpUtil
;
use
App\Models\user\mysql\UserWechatBind
;
/**
* php public/cli.php colonelorder index
*/
class
ColonelorderController
extends
Cli
{
const
DEFAULT_USER_BATCH_SIZE
=
100
;
public
$today
;
public
$yesterday
;
public
$colonelConfig
;
public
$colonelConfigList
;
public
function
init
()
{
parent
::
init
();
$this
->
today
=
date
(
"Y-m-d"
);
$this
->
yesterday
=
date
(
"Y-m-d"
,
strtotime
(
"-1 day"
));
$this
->
colonelConfig
=
$this
->
getColonelConfig
(
$this
->
yesterday
);
if
(
!
empty
(
$this
->
colonelConfig
))
{
$this
->
colonelConfigList
=
json_decode
(
$this
->
colonelConfig
[
'data'
],
true
);
}
}
public
function
indexAction
()
{
FileLog
::
info
(
"colonel_distributor_order"
,
'团长分销-计算奖励脚本:start'
);
$userIdList
=
$this
->
getColonelUserIds
();
if
(
!
empty
(
$userIdList
))
{
$userIdList
=
array_chunk
(
$userIdList
,
self
::
DEFAULT_USER_BATCH_SIZE
);
$colonelPayInfoData
=
[];
foreach
(
$userIdList
as
$userIds
)
{
// 完成目标单数
if
(
$inviteOrderData
=
$this
->
getInviteOrderData
(
$userIds
))
{
$colonelPayInfoData
=
array_merge
(
$colonelPayInfoData
,
$inviteOrderData
);
}
// 邀请新用户奖励
if
(
$inviteNewUserData
=
$this
->
getInviteNewUserData
(
$userIds
))
{
$colonelPayInfoData
=
array_merge
(
$colonelPayInfoData
,
$inviteNewUserData
);
}
}
$this
->
handleSavePayInfo
(
$colonelPayInfoData
);
}
FileLog
::
info
(
"colonel_distributor_order"
,
'团长分销-计算奖励脚本:end'
);
echo
"success"
;
}
/**
* 保存奖励信息
* @param $yesterday
* @return true
*/
public
function
handleSavePayInfo
(
$colonelPayInfoData
)
{
FileLog
::
info
(
"colonel_distributor_order"
,
'团长分销-计算奖励脚本:colonelPayInfoCount='
.
count
(
$colonelPayInfoData
));
if
(
!
empty
(
$colonelPayInfoData
))
{
$data
=
$this
->
addIdgenId
(
$colonelPayInfoData
);
try
{
ColonelDistributorPayInfo
::
beginTransaction
();
if
(
!
$this
->
addColonelDistributorPayInfo
(
$data
))
{
throw
new
\Exception
(
sprintf
(
"写入错误参数 %s"
,
json_encode
(
$data
)));
}
if
(
!
ColonelDistributorPayInfo
::
commit
())
{
throw
new
\Exception
(
sprintf
(
"事务提交失败 %s"
,
json_encode
(
$data
)));
}
}
catch
(
\Exception
$e
)
{
ColonelDistributorPayInfo
::
rollback
();
FileLog
::
info
(
"add_colonel_distributor_pay_info"
,
$e
->
getMessage
());
}
}
return
true
;
}
/**
* 获取新用户奖励
* @param $yesterday
* @return array
*/
public
function
getInviteNewUserData
(
$userIds
)
{
$inviteNewUserList
=
$this
->
getInviteNewUserList
(
$userIds
,
$this
->
today
);
$inviteOrderData
=
[];
if
(
!
empty
(
$inviteNewUserList
))
{
$userNickList
=
$this
->
getUserList
(
array_column
(
$inviteNewUserList
,
"user_id"
));
foreach
(
$inviteNewUserList
as
$newUser
)
{
$payInfo
=
[
"colonel_user_id"
=>
$newUser
[
"inviter_user_id"
],
"date"
=>
$this
->
yesterday
,
"type"
=>
ColonelDistributorPayInfo
::
TYPE_NEW_USER
,
"reward"
=>
3
*
100
,
"finish_num"
=>
1
,
"invite_user_id"
=>
$newUser
[
"user_id"
],
"invite_user_nick"
=>
empty
(
$userNickList
[
$newUser
[
"user_id"
]][
"user_nick"
])
?
""
:
$userNickList
[
$newUser
[
"user_id"
]][
"user_nick"
],
];
$inviteOrderData
[]
=
$payInfo
;
}
}
return
$inviteOrderData
;
}
/**
* 获取完成目标单数奖励
* @param $yesterday
* @return array
*/
public
function
getInviteOrderData
(
$userIds
)
{
//完成目标单数
$inviteOrderData
=
[];
if
(
empty
(
$this
->
colonelConfigList
))
{
return
$inviteOrderData
;
}
$inviteOrderNumList
=
$this
->
getInviteOrderNum
(
$userIds
,
$this
->
yesterday
,
$this
->
today
);
foreach
(
$inviteOrderNumList
as
$orderNum
)
{
foreach
(
$this
->
colonelConfigList
as
$config
)
{
if
(
!
empty
(
$orderNum
[
"num"
])
&&
$orderNum
[
"num"
]
>=
$config
[
"assess_order_num"
])
{
$payInfo
=
[
"colonel_user_id"
=>
$orderNum
[
"colonel_user_id"
],
"date"
=>
$this
->
yesterday
,
"type"
=>
ColonelDistributorPayInfo
::
TYPE_FINISH_TARGET
,
"reward"
=>
$config
[
"reward_amount"
]
*
100
,
"finish_num"
=>
$config
[
"assess_order_num"
],
"invite_user_id"
=>
0
,
"invite_user_nick"
=>
""
,
];
$inviteOrderData
[]
=
$payInfo
;
}
}
}
return
$inviteOrderData
;
}
/**
* 团长任务配置
* @param $yesterday
* @return \Api\PhpUtils\Mysql\MysqlBase
*/
public
function
getColonelConfig
(
$yesterday
)
{
$type
=
empty
(
$params
[
"type"
])
?
ColonelDistributorConfig
::
TYPE_COLONEL
:
$params
[
"type"
];
$config
=
ColonelDistributorConfig
::
getRecord
([
"date"
=>
$yesterday
,
"type"
=>
$type
]);
if
(
empty
(
$config
))
{
$config
=
ColonelDistributorConfig
::
getRecord
([
"date[<=]"
=>
$yesterday
,
"ORDER"
=>
[
"date"
=>
"DESC"
],
"LIMIT"
=>
1
]);
}
return
$config
;
}
/**
* 团长user_id
* @return array
*/
public
function
getColonelUserIds
()
{
$colonelRes
=
ColonelDistributorColonel
::
select
([
"user_id"
],
[
"LIMIT"
=>
10000000
]);
$userIds
=
[];
if
(
!
empty
(
$colonelRes
))
{
$userIds
=
array_column
(
$colonelRes
,
"user_id"
);
}
return
$userIds
;
}
/**
* 获取order num
* @param $colonelUserIds
* @param $startTime
* @param $endTime
* @return \Api\PhpUtils\Mysql\MysqlBase
*/
public
function
getInviteOrderNum
(
$colonelUserIds
,
$startTime
,
$endTime
)
{
return
ColonelDistributorInviteOrderNum
::
select
(
[
"colonel_user_id"
,
"num"
,
"date"
],
[
"colonel_user_id"
=>
$colonelUserIds
,
"date[>=]"
=>
$startTime
,
"date[<]"
=>
$endTime
,
],
[]
);
}
/**
* 获取有效新用户信息
* @param $userIds
* @param $date
* @return array|mixed
* @throws InterfaceException
*/
public
function
getInviteNewUserList
(
$userIds
,
$date
)
{
$url
=
config
(
'interface'
,
'coupon.background.wx_invite_relation_list_by_user_ids'
);
if
(
empty
(
$url
))
{
throw
new
InterfaceException
([
'cus'
=>
0
]);
}
$res
=
HttpUtil
::
get
(
$url
,
[
"user_ids"
=>
$userIds
,
"date"
=>
$date
]);
if
(
!
empty
(
$res
[
"response"
][
"result"
]))
{
$res
=
array_column
(
$res
[
"response"
][
"result"
],
null
,
"user_id"
);
return
array_values
(
$res
);
}
return
[];
}
/**
* 给数据整理 colonel_distributor_pay_info_id
* @param $data
* @param string $type
* @return mixed
*/
public
function
addIdgenId
(
$data
,
$type
=
"goods"
)
{
$count
=
count
(
$data
);
$res
=
Idgen
::
get
(
appConfig
(
'idgen.partner'
),
appConfig
(
'idgen.key'
),
[],
[[
"type"
=>
$type
,
'number'
=>
00
,
"count"
=>
$count
]]);
$ids
=
$res
[
'id_datetime'
][
$type
]
??
[];
foreach
(
$data
as
$key
=>
$item
)
{
$data
[
$key
][
"colonel_distributor_pay_info_id"
]
=
$ids
[
$key
];
}
return
$data
;
}
/**
* 用户信息,获取昵称
* @param $userIds
* @return \Api\PhpUtils\Mysql\MysqlBase|array
*/
public
function
getUserList
(
$userIds
)
{
$list
=
UserWechatBind
::
select
([
"user_id"
,
"user_nick"
],
[
"user_id"
=>
$userIds
],
[]);
if
(
!
empty
(
$list
))
{
$list
=
array_column
(
$list
,
null
,
"user_id"
);
}
return
$list
;
}
/**
* 写入数据
* @param $data
* @return \Api\PhpUtils\Mysql\MysqlBase
*/
public
function
addColonelDistributorPayInfo
(
$data
)
{
return
ColonelDistributorPayInfo
::
save
(
$data
);
}
}
application/modules/Cli/controllers/Colonelwallet.php
deleted
100644 → 0
View file @
8d194313
<?php
use
Api\PhpUtils\Log\FileLog
;
use
App\Base\Cli
;
use
App\Models\marketing\mysql\ColonelDistributorPayInfo
;
use
App\Exception\custom\InterfaceException
;
use
Api\PhpUtils\Http\HttpUtil
;
/**
* php public/cli.php colonelwallet index
*/
class
ColonelwalletController
extends
Cli
{
public
function
indexAction
()
{
FileLog
::
info
(
"colonel_distributor_wallet"
,
'团长分销-奖励钱包脚本:start'
);
$yesterday
=
date
(
"Y-m-d"
,
strtotime
(
"-1 day"
));
$payInfoList
=
$this
->
getPayInfo
(
$yesterday
);
FileLog
::
info
(
"colonel_distributor_wallet"
,
'团长分销-奖励钱包脚本:payInfoCount='
.
count
(
$payInfoList
));
if
(
!
empty
(
$payInfoList
))
{
if
(
$this
->
deductingInventory
(
$payInfoList
))
{
if
(
$this
->
toWallet
(
$payInfoList
))
{
$this
->
handlePayInfoStatus
(
array_column
(
$payInfoList
,
'pay_info_id'
));
}
}
}
FileLog
::
info
(
"colonel_distributor_wallet"
,
'团长分销-奖励钱包脚本:end'
);
echo
"success"
;
}
/**
* colonel_distributor_pay_info 数据
* @param $date
* @return array
*/
public
function
getPayInfo
(
$date
)
{
$list
=
ColonelDistributorPayInfo
::
select
(
"*"
,
[
"date"
=>
$date
,
'status'
=>
ColonelDistributorPayInfo
::
STATUS_NOT_USE
],
[]);
$data
=
[];
if
(
!
empty
(
$list
))
{
foreach
(
$list
as
$item
)
{
//去重
$key
=
$item
[
"colonel_user_id"
]
.
$item
[
"date"
]
.
$item
[
"type"
]
.
$item
[
"finish_num"
];
$data
[
$key
]
=
$item
;
}
$data
=
array_values
(
$data
);
}
return
$data
;
}
/**
* 写入钱包
*/
public
function
toWallet
(
$payInfoList
)
{
$url
=
config
(
'interface'
,
'wallet.account.transfer'
);
if
(
empty
(
$url
))
{
throw
new
InterfaceException
([
'cus'
=>
0
]);
}
$data
=
[];
foreach
(
$payInfoList
as
$payInfo
)
{
if
(
$payInfo
[
"type"
]
==
ColonelDistributorPayInfo
::
TYPE_NEW_USER
)
{
$desc
=
"邀请新用户("
.
$payInfo
[
"invite_user_nick"
]
.
")完成下单奖励"
;
}
if
(
$payInfo
[
"type"
]
==
ColonelDistributorPayInfo
::
TYPE_FINISH_TARGET
)
{
$desc
=
"完成"
.
$payInfo
[
"finish_num"
]
.
"单用户下单奖励"
;
}
$tmp
=
[];
$tmp
[
"user_id"
]
=
$payInfo
[
"colonel_user_id"
];
$tmp
[
"service_name"
]
=
11
;
//服务名字,10生活圈优惠券,11营销活动
$tmp
[
"source_name"
]
=
1
;
//使用方名,1生活圈,2主端
$tmp
[
"third_order_id"
]
=
$payInfo
[
"colonel_distributor_pay_info_id"
];
$tmp
[
"third_order_id_type"
]
=
$payInfo
[
"type"
];
$tmp
[
"third_order_desc"
]
=
$desc
;
$tmp
[
"amount"
]
=
$payInfo
[
"reward"
];
$tmp
[
"extra"
]
=
$payInfo
;
$data
[]
=
$tmp
;
}
$res
=
HttpUtil
::
post
(
$url
,
[
"list"
=>
$data
]);
if
(
$res
[
'code'
]
==
0
&&
isset
(
$res
[
'response'
][
"result"
]))
{
$date
=
date
(
"Y-m-d H:i:s"
);
FileLog
::
info
(
"colonel_distributor_to_wallet"
,
$date
.
" 写入钱包成功"
);
return
true
;
}
else
{
$msg
=
json_encode
([
"list"
=>
$data
]);
FileLog
::
error
(
"colonel_distributor_to_wallet"
,
$msg
,
null
,
'bp-server@yidian-inc.com'
);
return
false
;
}
}
/**
* 资金池授予用户奖励
*/
public
function
deductingInventory
(
$payInfoList
)
{
$url
=
config
(
'interface'
,
'coupon.capitalpool.grant_user_amount'
);
if
(
empty
(
$url
))
{
throw
new
InterfaceException
([
'cus'
=>
0
]);
}
$data
[
"capital_pool_id"
]
=
2
;
foreach
(
$payInfoList
as
$payInfo
)
{
if
(
$payInfo
[
"type"
]
==
ColonelDistributorPayInfo
::
TYPE_NEW_USER
)
{
$desc
=
"邀请新用户("
.
$payInfo
[
"invite_user_nick"
]
.
")完成下单奖励"
;
}
if
(
$payInfo
[
"type"
]
==
ColonelDistributorPayInfo
::
TYPE_FINISH_TARGET
)
{
$desc
=
"完成"
.
$payInfo
[
"finish_num"
]
.
"单用户下单奖励"
;
}
$tmp
=
[];
$tmp
[
"op"
]
=
200
;
//200:团长奖励
$tmp
[
"user_id"
]
=
$payInfo
[
"colonel_user_id"
];
$tmp
[
"amount"
]
=
$payInfo
[
"reward"
];
$tmp
[
"third_order_id"
]
=
$payInfo
[
"colonel_distributor_pay_info_id"
];
$tmp
[
"third_order_id_type"
]
=
$payInfo
[
"type"
];
$tmp
[
"third_order_desc"
]
=
$desc
;
$data
[
"body"
][]
=
$tmp
;
}
$res
=
HttpUtil
::
post
(
$url
,
$data
,
100000
,
3
);
if
(
$res
[
'code'
]
==
0
&&
isset
(
$res
[
'response'
][
"result"
]))
{
$date
=
date
(
"Y-m-d H:i:s"
);
FileLog
::
info
(
"colonel_distributor_deducting_inventory"
,
$date
.
" 资金池授予用户奖励成功"
);
return
true
;
}
else
{
$msg
=
json_encode
([
"list"
=>
$data
]);
FileLog
::
error
(
"colonel_distributor_deducting_inventory"
,
$msg
,
null
,
'bp-server@yidian-inc.com'
);
return
false
;
}
}
/**
* 修改状态
*/
public
function
handlePayInfoStatus
(
array
$payInfoIds
)
{
return
ColonelDistributorPayInfo
::
updateRecord
([
'status'
=>
ColonelDistributorPayInfo
::
STATUS_USE
],
[
'pay_info_id'
=>
$payInfoIds
]);
}
}
application/modules/Job/controllers/ColonelOrder.php
View file @
f011efb5
...
...
@@ -6,11 +6,260 @@
*/
use
App\Base\Job
;
use
Api\PhpServices\Idgen\Idgen
;
use
Api\PhpUtils\Log\FileLog
;
use
App\Models\marketing\mysql\ColonelDistributorColonel
;
use
App\Models\marketing\mysql\ColonelDistributorConfig
;
use
App\Models\marketing\mysql\ColonelDistributorInviteOrderNum
;
use
App\Models\marketing\mysql\ColonelDistributorPayInfo
;
use
App\Exception\custom\InterfaceException
;
use
Api\PhpUtils\Http\HttpUtil
;
use
App\Models\user\mysql\UserWechatBind
;
class
ColonelOrderController
extends
Job
{
const
DEFAULT_USER_BATCH_SIZE
=
100
;
public
$today
;
public
$yesterday
;
public
$colonelConfig
;
public
$colonelConfigList
;
public
function
init
()
{
parent
::
init
();
$this
->
today
=
date
(
"Y-m-d"
);
$this
->
yesterday
=
date
(
"Y-m-d"
,
strtotime
(
"-1 day"
));
$this
->
colonelConfig
=
$this
->
getColonelConfig
(
$this
->
yesterday
);
if
(
!
empty
(
$this
->
colonelConfig
))
{
$this
->
colonelConfigList
=
json_decode
(
$this
->
colonelConfig
[
'data'
],
true
);
}
}
public
function
indexAction
()
{
\Yaf\Application
::
app
()
->
bootstrap
()
->
getDispatcher
()
->
dispatch
(
new
\Yaf\Request\Simple
(
''
,
'cli'
,
'colonelorder'
,
'index'
,
[]));
FileLog
::
info
(
"colonel_distributor_order"
,
'团长分销-计算奖励脚本:start'
);
$userIdList
=
$this
->
getColonelUserIds
();
if
(
!
empty
(
$userIdList
))
{
$userIdList
=
array_chunk
(
$userIdList
,
self
::
DEFAULT_USER_BATCH_SIZE
);
$colonelPayInfoData
=
[];
foreach
(
$userIdList
as
$userIds
)
{
// 完成目标单数
if
(
$inviteOrderData
=
$this
->
getInviteOrderData
(
$userIds
))
{
$colonelPayInfoData
=
array_merge
(
$colonelPayInfoData
,
$inviteOrderData
);
}
// 邀请新用户奖励
if
(
$inviteNewUserData
=
$this
->
getInviteNewUserData
(
$userIds
))
{
$colonelPayInfoData
=
array_merge
(
$colonelPayInfoData
,
$inviteNewUserData
);
}
}
$this
->
handleSavePayInfo
(
$colonelPayInfoData
);
}
FileLog
::
info
(
"colonel_distributor_order"
,
'团长分销-计算奖励脚本:end'
);
echo
"success"
;
}
/**
* 保存奖励信息
* @param $yesterday
* @return true
*/
public
function
handleSavePayInfo
(
$colonelPayInfoData
)
{
FileLog
::
info
(
"colonel_distributor_order"
,
'团长分销-计算奖励脚本:colonelPayInfoCount='
.
count
(
$colonelPayInfoData
));
if
(
!
empty
(
$colonelPayInfoData
))
{
$data
=
$this
->
addIdgenId
(
$colonelPayInfoData
);
try
{
ColonelDistributorPayInfo
::
beginTransaction
();
if
(
!
$this
->
addColonelDistributorPayInfo
(
$data
))
{
throw
new
\Exception
(
sprintf
(
"写入错误参数 %s"
,
json_encode
(
$data
)));
}
if
(
!
ColonelDistributorPayInfo
::
commit
())
{
throw
new
\Exception
(
sprintf
(
"事务提交失败 %s"
,
json_encode
(
$data
)));
}
}
catch
(
\Exception
$e
)
{
ColonelDistributorPayInfo
::
rollback
();
FileLog
::
info
(
"add_colonel_distributor_pay_info"
,
$e
->
getMessage
());
}
}
return
true
;
}
/**
* 获取新用户奖励
* @param $yesterday
* @return array
*/
public
function
getInviteNewUserData
(
$userIds
)
{
$inviteNewUserList
=
$this
->
getInviteNewUserList
(
$userIds
,
$this
->
today
);
$inviteOrderData
=
[];
if
(
!
empty
(
$inviteNewUserList
))
{
$userNickList
=
$this
->
getUserList
(
array_column
(
$inviteNewUserList
,
"user_id"
));
foreach
(
$inviteNewUserList
as
$newUser
)
{
$payInfo
=
[
"colonel_user_id"
=>
$newUser
[
"inviter_user_id"
],
"date"
=>
$this
->
yesterday
,
"type"
=>
ColonelDistributorPayInfo
::
TYPE_NEW_USER
,
"reward"
=>
3
*
100
,
"finish_num"
=>
1
,
"invite_user_id"
=>
$newUser
[
"user_id"
],
"invite_user_nick"
=>
empty
(
$userNickList
[
$newUser
[
"user_id"
]][
"user_nick"
])
?
""
:
$userNickList
[
$newUser
[
"user_id"
]][
"user_nick"
],
];
$inviteOrderData
[]
=
$payInfo
;
}
}
return
$inviteOrderData
;
}
/**
* 获取完成目标单数奖励
* @param $yesterday
* @return array
*/
public
function
getInviteOrderData
(
$userIds
)
{
//完成目标单数
$inviteOrderData
=
[];
if
(
empty
(
$this
->
colonelConfigList
))
{
return
$inviteOrderData
;
}
$inviteOrderNumList
=
$this
->
getInviteOrderNum
(
$userIds
,
$this
->
yesterday
,
$this
->
today
);
foreach
(
$inviteOrderNumList
as
$orderNum
)
{
foreach
(
$this
->
colonelConfigList
as
$config
)
{
if
(
!
empty
(
$orderNum
[
"num"
])
&&
$orderNum
[
"num"
]
>=
$config
[
"assess_order_num"
])
{
$payInfo
=
[
"colonel_user_id"
=>
$orderNum
[
"colonel_user_id"
],
"date"
=>
$this
->
yesterday
,
"type"
=>
ColonelDistributorPayInfo
::
TYPE_FINISH_TARGET
,
"reward"
=>
$config
[
"reward_amount"
]
*
100
,
"finish_num"
=>
$config
[
"assess_order_num"
],
"invite_user_id"
=>
0
,
"invite_user_nick"
=>
""
,
];
$inviteOrderData
[]
=
$payInfo
;
}
}
}
return
$inviteOrderData
;
}
/**
* 团长任务配置
* @param $yesterday
* @return \Api\PhpUtils\Mysql\MysqlBase
*/
public
function
getColonelConfig
(
$yesterday
)
{
$type
=
empty
(
$params
[
"type"
])
?
ColonelDistributorConfig
::
TYPE_COLONEL
:
$params
[
"type"
];
$config
=
ColonelDistributorConfig
::
getRecord
([
"date"
=>
$yesterday
,
"type"
=>
$type
]);
if
(
empty
(
$config
))
{
$config
=
ColonelDistributorConfig
::
getRecord
([
"date[<=]"
=>
$yesterday
,
"ORDER"
=>
[
"date"
=>
"DESC"
],
"LIMIT"
=>
1
]);
}
return
$config
;
}
/**
* 团长user_id
* @return array
*/
public
function
getColonelUserIds
()
{
$colonelRes
=
ColonelDistributorColonel
::
select
([
"user_id"
],
[
"LIMIT"
=>
10000000
]);
$userIds
=
[];
if
(
!
empty
(
$colonelRes
))
{
$userIds
=
array_column
(
$colonelRes
,
"user_id"
);
}
return
$userIds
;
}
/**
* 获取order num
* @param $colonelUserIds
* @param $startTime
* @param $endTime
* @return \Api\PhpUtils\Mysql\MysqlBase
*/
public
function
getInviteOrderNum
(
$colonelUserIds
,
$startTime
,
$endTime
)
{
return
ColonelDistributorInviteOrderNum
::
select
(
[
"colonel_user_id"
,
"num"
,
"date"
],
[
"colonel_user_id"
=>
$colonelUserIds
,
"date[>=]"
=>
$startTime
,
"date[<]"
=>
$endTime
,
],
[]
);
}
/**
* 获取有效新用户信息
* @param $userIds
* @param $date
* @return array|mixed
* @throws InterfaceException
*/
public
function
getInviteNewUserList
(
$userIds
,
$date
)
{
$url
=
config
(
'interface'
,
'coupon.background.wx_invite_relation_list_by_user_ids'
);
if
(
empty
(
$url
))
{
throw
new
InterfaceException
([
'cus'
=>
0
]);
}
$res
=
HttpUtil
::
get
(
$url
,
[
"user_ids"
=>
$userIds
,
"date"
=>
$date
]);
if
(
!
empty
(
$res
[
"response"
][
"result"
]))
{
$res
=
array_column
(
$res
[
"response"
][
"result"
],
null
,
"user_id"
);
return
array_values
(
$res
);
}
return
[];
}
/**
* 给数据整理 colonel_distributor_pay_info_id
* @param $data
* @param string $type
* @return mixed
*/
public
function
addIdgenId
(
$data
,
$type
=
"goods"
)
{
$count
=
count
(
$data
);
$res
=
Idgen
::
get
(
appConfig
(
'idgen.partner'
),
appConfig
(
'idgen.key'
),
[],
[[
"type"
=>
$type
,
'number'
=>
00
,
"count"
=>
$count
]]);
$ids
=
$res
[
'id_datetime'
][
$type
]
??
[];
foreach
(
$data
as
$key
=>
$item
)
{
$data
[
$key
][
"colonel_distributor_pay_info_id"
]
=
$ids
[
$key
];
}
return
$data
;
}
/**
* 用户信息,获取昵称
* @param $userIds
* @return \Api\PhpUtils\Mysql\MysqlBase|array
*/
public
function
getUserList
(
$userIds
)
{
$list
=
UserWechatBind
::
select
([
"user_id"
,
"user_nick"
],
[
"user_id"
=>
$userIds
],
[]);
if
(
!
empty
(
$list
))
{
$list
=
array_column
(
$list
,
null
,
"user_id"
);
}
return
$list
;
}
/**
* 写入数据
* @param $data
* @return \Api\PhpUtils\Mysql\MysqlBase
*/
public
function
addColonelDistributorPayInfo
(
$data
)
{
return
ColonelDistributorPayInfo
::
save
(
$data
);
}
}
\ No newline at end of file
application/modules/Job/controllers/ColonelWallet.php
View file @
f011efb5
...
...
@@ -6,11 +6,135 @@
*/
use
App\Base\Job
;
use
Api\PhpUtils\Log\FileLog
;
use
App\Models\marketing\mysql\ColonelDistributorPayInfo
;
use
App\Exception\custom\InterfaceException
;
use
Api\PhpUtils\Http\HttpUtil
;
class
ColonelWalletController
extends
Job
{
public
function
indexAction
()
{
\Yaf\Application
::
app
()
->
bootstrap
()
->
getDispatcher
()
->
dispatch
(
new
\Yaf\Request\Simple
(
''
,
'cli'
,
'colonelwallet'
,
'index'
,
[]));
FileLog
::
info
(
"colonel_distributor_wallet"
,
'团长分销-奖励钱包脚本:start'
);
$yesterday
=
date
(
"Y-m-d"
,
strtotime
(
"-1 day"
));
$payInfoList
=
$this
->
getPayInfo
(
$yesterday
);
FileLog
::
info
(
"colonel_distributor_wallet"
,
'团长分销-奖励钱包脚本:payInfoCount='
.
count
(
$payInfoList
));
if
(
!
empty
(
$payInfoList
))
{
if
(
$this
->
deductingInventory
(
$payInfoList
))
{
if
(
$this
->
toWallet
(
$payInfoList
))
{
$this
->
handlePayInfoStatus
(
array_column
(
$payInfoList
,
'pay_info_id'
));
}
}
}
FileLog
::
info
(
"colonel_distributor_wallet"
,
'团长分销-奖励钱包脚本:end'
);
echo
"success"
;
}
/**
* colonel_distributor_pay_info 数据
* @param $date
* @return array
*/
public
function
getPayInfo
(
$date
)
{
$list
=
ColonelDistributorPayInfo
::
select
(
"*"
,
[
"date"
=>
$date
,
'status'
=>
ColonelDistributorPayInfo
::
STATUS_NOT_USE
],
[]);
$data
=
[];
if
(
!
empty
(
$list
))
{
foreach
(
$list
as
$item
)
{
//去重
$key
=
$item
[
"colonel_user_id"
]
.
$item
[
"date"
]
.
$item
[
"type"
]
.
$item
[
"finish_num"
];
$data
[
$key
]
=
$item
;
}
$data
=
array_values
(
$data
);
}
return
$data
;
}
/**
* 写入钱包
*/
public
function
toWallet
(
$payInfoList
)
{
$url
=
config
(
'interface'
,
'wallet.account.transfer'
);
if
(
empty
(
$url
))
{
throw
new
InterfaceException
([
'cus'
=>
0
]);
}
$data
=
[];
foreach
(
$payInfoList
as
$payInfo
)
{
if
(
$payInfo
[
"type"
]
==
ColonelDistributorPayInfo
::
TYPE_NEW_USER
)
{
$desc
=
"邀请新用户("
.
$payInfo
[
"invite_user_nick"
]
.
")完成下单奖励"
;
}
if
(
$payInfo
[
"type"
]
==
ColonelDistributorPayInfo
::
TYPE_FINISH_TARGET
)
{
$desc
=
"完成"
.
$payInfo
[
"finish_num"
]
.
"单用户下单奖励"
;
}
$tmp
=
[];
$tmp
[
"user_id"
]
=
$payInfo
[
"colonel_user_id"
];
$tmp
[
"service_name"
]
=
11
;
//服务名字,10生活圈优惠券,11营销活动
$tmp
[
"source_name"
]
=
1
;
//使用方名,1生活圈,2主端
$tmp
[
"third_order_id"
]
=
$payInfo
[
"colonel_distributor_pay_info_id"
];
$tmp
[
"third_order_id_type"
]
=
$payInfo
[
"type"
];
$tmp
[
"third_order_desc"
]
=
$desc
;
$tmp
[
"amount"
]
=
$payInfo
[
"reward"
];
$tmp
[
"extra"
]
=
$payInfo
;
$data
[]
=
$tmp
;
}
$res
=
HttpUtil
::
post
(
$url
,
[
"list"
=>
$data
]);
if
(
$res
[
'code'
]
==
0
&&
isset
(
$res
[
'response'
][
"result"
]))
{
$date
=
date
(
"Y-m-d H:i:s"
);
FileLog
::
info
(
"colonel_distributor_to_wallet"
,
$date
.
" 写入钱包成功"
);
return
true
;
}
else
{
$msg
=
json_encode
([
"list"
=>
$data
]);
FileLog
::
error
(
"colonel_distributor_to_wallet"
,
$msg
,
null
,
'bp-server@yidian-inc.com'
);
return
false
;
}
}
/**
* 资金池授予用户奖励
*/
public
function
deductingInventory
(
$payInfoList
)
{
$url
=
config
(
'interface'
,
'coupon.capitalpool.grant_user_amount'
);
if
(
empty
(
$url
))
{
throw
new
InterfaceException
([
'cus'
=>
0
]);
}
$data
[
"capital_pool_id"
]
=
2
;
foreach
(
$payInfoList
as
$payInfo
)
{
if
(
$payInfo
[
"type"
]
==
ColonelDistributorPayInfo
::
TYPE_NEW_USER
)
{
$desc
=
"邀请新用户("
.
$payInfo
[
"invite_user_nick"
]
.
")完成下单奖励"
;
}
if
(
$payInfo
[
"type"
]
==
ColonelDistributorPayInfo
::
TYPE_FINISH_TARGET
)
{
$desc
=
"完成"
.
$payInfo
[
"finish_num"
]
.
"单用户下单奖励"
;
}
$tmp
=
[];
$tmp
[
"op"
]
=
200
;
//200:团长奖励
$tmp
[
"user_id"
]
=
$payInfo
[
"colonel_user_id"
];
$tmp
[
"amount"
]
=
$payInfo
[
"reward"
];
$tmp
[
"third_order_id"
]
=
$payInfo
[
"colonel_distributor_pay_info_id"
];
$tmp
[
"third_order_id_type"
]
=
$payInfo
[
"type"
];
$tmp
[
"third_order_desc"
]
=
$desc
;
$data
[
"body"
][]
=
$tmp
;
}
$res
=
HttpUtil
::
post
(
$url
,
$data
,
100000
,
3
);
if
(
$res
[
'code'
]
==
0
&&
isset
(
$res
[
'response'
][
"result"
]))
{
$date
=
date
(
"Y-m-d H:i:s"
);
FileLog
::
info
(
"colonel_distributor_deducting_inventory"
,
$date
.
" 资金池授予用户奖励成功"
);
return
true
;
}
else
{
$msg
=
json_encode
([
"list"
=>
$data
]);
FileLog
::
error
(
"colonel_distributor_deducting_inventory"
,
$msg
,
null
,
'bp-server@yidian-inc.com'
);
return
false
;
}
}
/**
* 修改状态
*/
public
function
handlePayInfoStatus
(
array
$payInfoIds
)
{
return
ColonelDistributorPayInfo
::
updateRecord
([
'status'
=>
ColonelDistributorPayInfo
::
STATUS_USE
],
[
'pay_info_id'
=>
$payInfoIds
]);
}
}
\ No newline at end of file
application/services/goods/GoodsService.php
View file @
f011efb5
This diff is collapsed.
Click to expand it.
application/services/marketing/MarketingGoodsService.php
View file @
f011efb5
...
...
@@ -156,12 +156,12 @@ class MarketingGoodsService
//比例
if
(
!
empty
(
$secondCommission
)
&&
$commissionMode
==
1
)
{
$price
=
!
empty
(
$list
[
$i
][
'price'
])
?
$list
[
$i
][
'price'
]
:
0
;
$list
[
$i
][
'share_price'
]
=
substr
(
sprintf
(
"%.4f"
,
$secondCommission
*
$price
/
100
),
0
,
-
2
);
$list
[
$i
][
'share_price'
]
=
(
float
)
substr
(
sprintf
(
"%.4f"
,
$secondCommission
*
$price
/
100
),
0
,
-
2
);
}
//固定
if
(
!
empty
(
$commissionMode
)
&&
$commissionMode
==
2
)
{
$list
[
$i
][
'share_price'
]
=
substr
(
sprintf
(
"%.4f"
,
$secondCommission
/
100
),
0
,
-
2
);
$list
[
$i
][
'share_price'
]
=
(
float
)
substr
(
sprintf
(
"%.4f"
,
$secondCommission
),
0
,
-
2
);
}
$content
=
$userId
.
'_'
.
$value
[
'marketing_id'
];
...
...
@@ -201,9 +201,13 @@ class MarketingGoodsService
$data
=
[];
foreach
(
$marketingInfoIds
as
$goodsSkuId
=>
$marketingId
)
{
if
(
!
empty
(
$marketingList
[
$marketingId
][
"second_commission_value"
]))
{
if
(
!
empty
(
$marketingList
[
$marketingId
][
"second_commission_value"
])
&&
$marketingList
[
$marketingId
][
"commission_mode"
]
==
1
)
{
$data
[
$goodsSkuId
]
=
substr
(
sprintf
(
"%.4f"
,
$marketingList
[
$marketingId
][
"second_commission_value"
]
/
10000
),
0
,
-
2
);
}
if
(
!
empty
(
$marketingList
[
$marketingId
][
"second_commission_value"
])
&&
$marketingList
[
$marketingId
][
"commission_mode"
]
==
2
)
{
$data
[
$goodsSkuId
]
=
substr
(
sprintf
(
"%.4f"
,
$marketingList
[
$marketingId
][
"second_commission_value"
]
/
100
),
0
,
-
2
);
}
}
return
$data
;
}
...
...
application/services/marketing/MarketingService.php
View file @
f011efb5
...
...
@@ -561,6 +561,9 @@ class MarketingService
$clearPrice
=
!
empty
(
$value
[
"clear_price"
])
?
$value
[
"clear_price"
]
:
0
;
$price
=
!
empty
(
$value
[
"price"
])
?
$value
[
"price"
]
:
0
;
$chargeFee
=
!
empty
(
$price
)
?
(
float
)
bcmul
(
$price
,
self
::
CHARGEFEE
,
2
)
:
0
;
//手续费 (分)
if
(
$chargeFee
<
1
)
{
$chargeFee
=
0
;
}
if
(
!
empty
(
$clearPrice
)
&&
$clearPrice
>
0
)
{
if
(
$commissionMode
==
Marketing
::
COMMISSION_MODE_RATE
)
{
$commissionTotal
=
(
$firstCommissionRate
+
$secondCommissionRate
)
/
10000
*
$price
;
...
...
daemon/Goods.php
View file @
f011efb5
...
...
@@ -29,10 +29,10 @@ class Goods implements DaemonServiceInterface
GoodsSku
::
save
(
$colums
,
$where
);
//更新es
GoodsService
::
updateGoodsInfoToEs
(
$where
[
'goods_sku_id'
]);
}
$this
->
onlineGoods
();
$this
->
onlineOffGoods
();
}
...
...
@@ -65,9 +65,10 @@ class Goods implements DaemonServiceInterface
sleep
(
2
);
$orderData
=
[
'online_type'
=>
2
,
'online_status'
=>
0
,
'online_status'
=>
[
0
,
2
]
,
'audit_status'
=>
1
,
'online_start_time[<]'
=>
date
(
"Y-m-d H:i:s"
,
time
()),
'online_end_time[>]'
=>
date
(
"Y-m-d H:i:s"
,
time
()),
'LIMIT'
=>
100
,
];
$goodsList
=
GoodsSku
::
getRecords
(
$orderData
);
...
...
@@ -84,4 +85,35 @@ class Goods implements DaemonServiceInterface
}
}
/**
*
* 自动下架
*/
public
function
onlineOffGoods
()
{
sleep
(
2
);
$orderData
=
[
'online_type'
=>
2
,
'online_status'
=>
1
,
'audit_status'
=>
1
,
'online_end_time[<]'
=>
date
(
"Y-m-d H:i:s"
,
time
()),
'LIMIT'
=>
100
,
];
$goodsList
=
GoodsSku
::
getRecords
(
$orderData
);
DaemonLog
::
info
(
'DaemonServiceOnlineOff_goods'
,
json_encode
(
$goodsList
));
foreach
(
$goodsList
as
$key
=>
$value
)
{
$where
=
[];
$where
[
'goods_sku_id'
]
=
!
empty
(
$value
[
'goods_sku_id'
])
?
$value
[
'goods_sku_id'
]
:
''
;
$colums
=
[
'online_status'
=>
2
,
];
GoodsSku
::
save
(
$colums
,
$where
);
//更新es
GoodsService
::
updateGoodsInfoToEs
(
$where
[
'goods_sku_id'
]);
}
}
}
\ 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