Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
P
pay
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
pay
Commits
d54c4db2
Commit
d54c4db2
authored
Sep 24, 2021
by
songxiaohang
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add:营销账户相关
parent
5dd1c7f3
Changes
6
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
260 additions
and
1 deletion
+260
-1
AccountException.php
application/exception/custom/AccountException.php
+35
-0
MarketingAccount.php
application/models/marketing/mysql/MarketingAccount.php
+13
-0
MarketingAccountLog.php
application/models/marketing/mysql/MarketingAccountLog.php
+28
-0
MarketingAccountMap.php
application/models/marketing/mysql/MarketingAccountMap.php
+13
-0
Marketing.php
application/modules/Pay/controllers/Marketing.php
+158
-0
AccountService.php
application/services/marketing/AccountService.php
+13
-1
No files found.
application/exception/custom/AccountException.php
0 → 100644
View file @
d54c4db2
<?php
/*
* @Author: your name
* @Date: 2021-09-24 10:59:20
* @LastEditTime: 2021-09-24 15:05:12
* @LastEditors: Please set LastEditors
* @Description: In User Settings Edit
* @FilePath: /robot/pay/application/exception/custom/AccountException.php
*/
namespace
App\Exception\custom
;
use
App\Exception\BaseException
;
class
AccountException
extends
BaseException
{
protected
$base_code
=
Code
::
ACCOUNT
;
protected
$cus
=
[
0
=>
'生成账户ID失败,请重试'
,
1
=>
'缺少账户ID参数'
,
2
=>
'账户不存在'
,
3
=>
'充值金额不能小于0'
,
4
=>
'充值失败,请重试'
,
5
=>
'创建营销活动失败,请重试'
,
6
=>
'创建营销账号失败,请重试'
,
7
=>
'创建消费记录失败,请重试'
,
8
=>
'冻结失败,请重试'
,
9
=>
'解冻失败,请重试'
,
10
=>
'营销账户出款失败,请重试'
,
11
=>
'营销账户退款失败,请重试'
,
];
}
application/models/marketing/mysql/MarketingAccount.php
0 → 100644
View file @
d54c4db2
<?php
namespace
App\Models\order\mysql
;
use
Api\PhpUtils\Mysql\MysqlBase
;
use
App\Exception\custom\PayException
;
class
MarketingAccount
extends
MysqlBase
{
const
TABLE_NAME
=
'marketing_account'
;
const
CONFIG_INDEX
=
'pay'
;
}
application/models/marketing/mysql/MarketingAccountLog.php
0 → 100644
View file @
d54c4db2
<?php
/*
* @Author: your name
* @Date: 2021-09-24 10:59:20
* @LastEditTime: 2021-09-24 15:08:52
* @LastEditors: your name
* @Description: In User Settings Edit
* @FilePath: /robot/pay/application/models/marketing/mysql/MarketingAccountLog.php
*/
/*
* @Author: your name
* @Date: 2021-09-24 10:59:20
* @LastEditTime: 2021-09-24 15:08:39
* @LastEditors: Please set LastEditors
* @Description: In User Settings Edit
* @FilePath: /robot/pay/application/models/marketing/mysql/MarketingAccountLog.php
*/
namespace
App\Models\order\mysql
;
use
Api\PhpUtils\Mysql\MysqlBase
;
class
MarketingAccountLog
extends
MysqlBase
{
const
TABLE_NAME
=
'marketing_account_log'
;
const
CONFIG_INDEX
=
'pay'
;
}
application/models/marketing/mysql/MarketingAccountMap.php
0 → 100644
View file @
d54c4db2
<?php
namespace
App\Models\order\mysql
;
use
Api\PhpUtils\Mysql\MysqlBase
;
use
App\Exception\custom\PayException
;
class
MarketingAccountMap
extends
MysqlBase
{
const
TABLE_NAME
=
'marketing_account_map'
;
const
CONFIG_INDEX
=
'pay'
;
}
application/modules/Pay/controllers/Marketing.php
0 → 100644
View file @
d54c4db2
<?php
use
App\Base\Base
;
use
App\Models\order\mysql\MarketingAccount
;
use
App\Models\order\mysql\MarketingAccountMap
;
use
App\Models\order\mysql\MarketingAccountLog
;
use
App\Services\marketing\AccountService
;
use
App\Exception\custom\AccountException
;
class
MarketingController
extends
Base
{
/**
* 创建营销账户
* @params source_name 1:生活圈; 2:主端
* @params service_name 1:生活圈优惠券
*/
public
function
create_accountAction
(){
$params
=
$this
->
params
;
$data
=
array
(
'marketing_account_id'
=>
AccountService
::
get_idgen_id
(),
'title'
=>
$params
[
'title'
],
'desc'
=>
$params
[
'desc'
],
'source_name'
=>
$params
[
'source_name'
]
??
10
,
'service_name'
=>
$params
[
'service_name'
]
??
1
);
$i_ret
=
MarketingAccount
::
insert
(
$data
);
if
(
$i_ret
==
false
){
throw
new
AccountException
([
'cus'
=>
6
]);
}
$this
->
success
();
}
/**
* 创建营销活动&绑定营销账户
* @params source_name 1:生活圈; 2:主端
* @params service_name 1:生活圈优惠券
*/
public
function
create_account_mapAction
(){
$params
=
$this
->
params
;
if
(
!
$params
[
'marketing_account_id'
]){
throw
new
AccountException
([
'cus'
=>
0
]);
}
$data
=
array
(
'marketing_account_id'
=>
$params
[
'marketing_account_id'
],
'marketing_id'
=>
AccountService
::
get_idgen_id
(),
'source_name'
=>
$params
[
'source_name'
]
??
1
,
'service_name'
=>
$params
[
'service_name'
]
??
1
);
$i_ret
=
MarketingAccountMap
::
insert
(
$data
);
if
(
$i_ret
==
false
){
throw
new
AccountException
([
'cus'
=>
5
]);
}
$this
->
success
();
}
/**
* 营销账户充值
* @params marketing_account_id 账户ID
* @params third_id 三方ID
* @params trade_id 业务ID
* @params amount 充值金额
*/
public
function
recharge_accountAction
(){
$params
=
$this
->
params
;
if
(
!
$params
[
'marketing_account_id'
]){
throw
new
AccountException
([
'cus'
=>
0
]);
}
if
(
$params
[
'amount'
]
<=
0
){
throw
new
AccountException
([
'cus'
=>
3
]);
}
$recharge_data
=
array
(
'amount'
=>
$params
[
'amount'
],
'trade_id'
=>
$params
[
'trade_id'
],
'third_id'
=>
$params
[
'third_id'
]
);
$ret
=
AccountService
::
recharge
(
$recharge_data
,
$params
[
'marketing_account_id'
]);
if
(
!
$ret
){
throw
new
AccountException
([
'cus'
=>
4
]);
}
$this
->
success
();
}
/**
* 营销账户冻结资金
* @params capital_pool_id 优惠券资金池id
* @params share_coupon_amount 优惠券分摊金额 单位:分
* @params trade_id 业务ID
* @params type 1:冻结| 2:解冻
*/
public
function
freeze_accountAction
(){
$params
=
$this
->
params
;
if
(
!
$params
[
'trade_id'
]){
throw
new
AccountException
([
'cus'
=>
0
]);
}
$frozen_data
=
array
(
'capital_pool_id'
=>
$params
[
'capital_pool_id'
],
'share_coupon_amount'
=>
$params
[
'share_coupon_amount'
],
);
if
(
$params
[
'type'
]
==
1
){
$ret
=
AccountService
::
frozen
(
$frozen_data
,
$params
[
'trade_id'
]);
if
(
!
$ret
){
throw
new
AccountException
([
'cus'
=>
8
]);
}
}
elseif
(
$params
[
'type'
]
==
2
){
$ret
=
AccountService
::
cancel
(
$frozen_data
,
$params
[
'trade_id'
]);
if
(
!
$ret
){
throw
new
AccountException
([
'cus'
=>
9
]);
}
}
$this
->
success
();
}
/**
* 营销账户出款
* @params capital_pool_id 优惠券资金池id
* @params share_coupon_amount 优惠券分摊金额 单位:分
* @params trade_id 业务ID
* @params trade_id 业务ID
*/
public
function
deduct_accountAction
(){
$params
=
$this
->
params
;
if
(
!
$params
[
'trade_id'
]){
throw
new
AccountException
([
'cus'
=>
0
]);
}
$deduct_data
=
array
(
'capital_pool_id'
=>
$params
[
'capital_pool_id'
],
'share_coupon_amount'
=>
$params
[
'share_coupon_amount'
],
);
$ret
=
AccountService
::
pay
(
$deduct_data
,
$params
[
'trade_id'
]);
if
(
!
$ret
){
throw
new
AccountException
([
'cus'
=>
10
]);
}
$this
->
success
();
}
/**
* 营销账户退款
* @params capital_pool_id 优惠券资金池id
* @params share_coupon_amount 优惠券分摊金额 单位:分
* @params trade_id 业务ID
*/
public
function
refund_accountAction
(){
$params
=
$this
->
params
;
if
(
!
$params
[
'trade_id'
]){
throw
new
AccountException
([
'cus'
=>
0
]);
}
$deduct_data
=
array
(
'capital_pool_id'
=>
$params
[
'capital_pool_id'
],
'share_coupon_amount'
=>
$params
[
'share_coupon_amount'
],
);
$ret
=
AccountService
::
refund
(
$deduct_data
,
$params
[
'trade_id'
]);
if
(
!
$ret
){
throw
new
AccountException
([
'cus'
=>
11
]);
}
$this
->
success
();
}
}
application/services/marketing/AccountService.php
View file @
d54c4db2
...
...
@@ -7,7 +7,8 @@ namespace App\Services\marketing;
use
App\Models\order\mysql\MarketingAccount
;
use
App\Models\order\mysql\MarketingAccountLog
;
use
App\Models\order\mysql\MarketingAccountMap
;
use
Api\PhpServices\Idgen\Idgen
;
use
App\Exception\custom\AccountException
;
class
AccountService
{
...
...
@@ -115,6 +116,7 @@ class AccountService
foreach
(
$coupon
as
$id
=>
$amount
)
{
$marketing_account_id
=
self
::
map
(
$id
);
$cnt
=
$cnt
&&
MarketingAccount
::
update
([
'frozen_amount[-]'
=>
$amount
,
'receivable_amount[+]'
=>
$amount
,
],
[
'marketing_account_id'
=>
$marketing_account_id
]);
...
...
@@ -197,4 +199,14 @@ class AccountService
return
$coupon
;
}
public
static
function
get_idgen_id
(
$count
=
1
){
$res
=
Idgen
::
get
(
appConfig
(
'idgen.partner'
),
appConfig
(
'idgen.key'
),
[[
"type"
=>
"pay_marketing_account_id"
,
"count"
=>
$count
]]);
if
(
!
$res
[
'id_snow'
][
'pay_marketing_account_id'
]){
throw
new
AccountException
([
'cus'
=>
0
]);
}
return
$res
[
'id_snow'
][
'pay_marketing_account_id'
][
0
];
}
}
\ 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