Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
T
tl_estate
Project
Project
Details
Activity
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
hujun
tl_estate
Commits
29708ad5
Commit
29708ad5
authored
Mar 13, 2019
by
zhuwei
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
核销优惠券
parent
b0c82b9b
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
69 additions
and
12 deletions
+69
-12
AccountBalanceService.php
application/api/service/AccountBalanceService.php
+28
-1
ConvertCouponService.php
application/api/service/ConvertCouponService.php
+19
-8
CCoupon.php
application/model/CCoupon.php
+10
-0
UAccountBalance.php
application/model/UAccountBalance.php
+11
-2
UpdateCouponTask.php
application/task/controller/UpdateCouponTask.php
+1
-1
No files found.
application/api/service/AccountBalanceService.php
View file @
29708ad5
...
...
@@ -2,6 +2,7 @@
namespace
app\api\service
;
use
app\model\UAccountBalance
;
use
app\model\Users
;
/**
...
...
@@ -19,11 +20,20 @@ class AccountBalanceService{
$this
->
m_account_balance
=
new
UAccountBalance
();
}
public
function
addUserBalance
(
$
user_id
,
$money
){
public
function
addUserBalance
(
$
money
,
$user_id
,
$source_type
,
$source_id
,
$operation_id
){
if
(
!
$user_id
or
!
$money
){
return
false
;
}
$user_info
=
$this
->
getUserInfo
(
$user_id
);
$insert
[
"money"
]
=
$money
;
//金额
$insert
[
"user_id"
]
=
$user_id
;
//用户id
$insert
[
"user_phone"
]
=
$user_info
[
0
][
'user_phone'
];
//用户手机号
$insert
[
"user_name"
]
=
$user_info
[
0
][
'user_name'
];
//用户手机号
$insert
[
"source_type"
]
=
$source_type
;
//来源类型 0:优惠券
$insert
[
"source_id"
]
=
$source_id
;
//来源id,type 0 为优惠券id
$insert
[
"operation_id"
]
=
$operation_id
;
//操作人id
$this
->
m_account_balance
->
addBalance
(
$insert
);
}
//todo 获取用户账户余额
...
...
@@ -41,4 +51,20 @@ class AccountBalanceService{
/**
* 获取客户信息
* @param $user_id
* @return bool|false|\PDOStatement|string|\think\Collection
*/
public
function
getUserInfo
(
$user_id
)
{
$m_user
=
new
Users
();
$field_referrer
=
'id,user_phone,user_name'
;
$referrer_res
=
$m_user
->
getUserByWhere
([
"id"
=>
$user_id
],
$field_referrer
);
if
(
count
(
$referrer_res
)
<=
0
)
return
false
;
return
$referrer_res
;
}
}
\ No newline at end of file
application/api/service/ConvertCouponService.php
View file @
29708ad5
...
...
@@ -18,12 +18,16 @@ class ConvertCouponService
private
$m_coupon
;
private
$m_user
;
private
$m_pay_log
;
private
$s_account_balance
;
function
__construct
()
{
$this
->
m_coupon
=
new
CCoupon
();
$this
->
m_user
=
new
Users
();
$this
->
m_pay_log
=
new
OPayLogModel
();
$this
->
s_account_balance
=
new
AccountBalanceService
();
}
public
function
adddata
()
...
...
@@ -42,12 +46,17 @@ class ConvertCouponService
$res
=
$this
->
m_coupon
->
addCoupon
(
$insert
);
//int(1)
}
/**
/**
* 核销优惠券
* @param $user_id
* @param $report_id
* @param $bargain_id
* @param $order_id
* @return bool
*/
public
function
convertCoupon
(
$user_id
){
if
(
!
$user_id
){
public
function
convertCoupon
(
$user_id
,
$report_id
,
$bargain_id
,
$order_id
){
if
(
!
$user_id
or
!
$report_id
or
!
$bargain_id
or
!
$order_id
){
return
false
;
}
...
...
@@ -76,9 +85,10 @@ class ConvertCouponService
$coupon_list
[]
=
$this
->
getMaxCoupon
(
$coupon_list
);
}
//修改券状态为已使用
$this
->
m_coupon
->
update
Status
(
$coupon_list
[
0
][
'id'
],
2
);
$this
->
m_coupon
->
update
UseStatus
(
$coupon_list
[
0
][
'id'
],
1
,
$report_id
,
$bargain_id
,
$order_id
,
date
(
"Y-m-d H:i:s"
,
time
())
);
//todo 将活动奖励金额写入账户余额 $coupon_list[0]['money']
// 将活动奖励金额写入账户余额
$this
->
s_account_balance
->
addUserBalance
(
$coupon_list
[
0
][
'money'
],
$user_id
,
0
,
$coupon_list
[
0
][
'id'
],
0
);
// 查询当前客户的是否有邀请人
...
...
@@ -102,8 +112,9 @@ class ConvertCouponService
return
false
;
}
elseif
(
$invite_user_coupon_list_count
==
1
){
// 修改券状态为已使用
$this
->
m_coupon
->
updateStatus
(
$invite_user_coupon_list_count
[
0
][
'id'
],
2
);
//todo 将活动奖励金额写入账户余额 $coupon_list[0]['money']
$this
->
m_coupon
->
updateUseStatus
(
$invite_user_coupon_list_count
[
0
][
'id'
],
1
,
$report_id
,
$bargain_id
,
$order_id
,
date
(
"Y-m-d H:i:s"
,
time
()));
// 将活动奖励金额写入账户余额 $coupon_list[0]['money']
$this
->
s_account_balance
->
addUserBalance
(
$invite_user_coupon_list_count
[
0
][
'money'
],
$invite_user
,
0
,
$invite_user_coupon_list_count
[
0
][
'id'
],
0
);
}
return
true
;
...
...
@@ -141,7 +152,7 @@ class ConvertCouponService
#发券日期大于最后使用日期
if
(
$v
[
'create_time'
]
>
date
(
"Y-m-d H:i:s"
,
strtotime
(
"+
{
$v
[
'use_period'
]
}
day"
,
strtotime
(
$v
[
'use_period'
])))){
$this
->
m_coupon
->
updateStatus
(
$v
[
'id'
],
3
);
$this
->
m_coupon
->
updateStatus
(
$v
[
'id'
],
2
);
unset
(
$coupon_list
[
$k
]);
continue
;
}
...
...
application/model/CCoupon.php
View file @
29708ad5
...
...
@@ -148,4 +148,13 @@ class CCoupon extends BaseModel
// big_log($this->getLastSql());
return
$result
;
}
public
function
updateUseStatus
(
$id
,
$status
,
$report_id
,
$bargain_id
,
$order_id
,
$use_time
)
{
$result
=
$this
->
db_
->
where
([
'id'
=>
$id
])
->
update
([
'status'
=>
$status
,
'report_id'
=>
$report_id
,
'bargain_id'
=>
$bargain_id
,
'order_id'
=>
$order_id
,
'use_time'
=>
$use_time
]);
// big_log($this->getLastSql());
return
$result
;
}
}
\ No newline at end of file
application/model/UAccountBalance.php
View file @
29708ad5
...
...
@@ -10,6 +10,15 @@ class UAccountBalance extends Model
// 设置当前模型对应的完整数据表名称
protected
$table
=
'u_account_balance'
;
public
function
addBalance
(
$data
)
{
$time
=
date
(
"Y-m-d H:i:s"
,
time
());
$data
[
'create_time'
]
=
$time
;
$data
[
'update_time'
]
=
$time
;
$data
[
"status"
]
=
0
;
return
$this
->
insert
(
$data
);
}
public
function
getBalanceList
(
$params
)
{
...
...
@@ -39,8 +48,8 @@ class UAccountBalance extends Model
*
FROM
(
( SELECT id, user_id,source_id
, money,
create_time, 1 AS aa FROM `u_account_balance` `a` WHERE `a`.`status` = 0 ) UNION
( SELECT id, user_id,0 as source_id ,money, create_time, 2 AS aa FROM `u_account_check` `a` WHERE `a`.`status` IN ( 0, 1, 2 ) )
( SELECT id, user_id,source_id
, money, user_name,
create_time, 1 AS aa FROM `u_account_balance` `a` WHERE `a`.`status` = 0 ) UNION
( SELECT id, user_id,0 as source_id ,money,
user_name,
create_time, 2 AS aa FROM `u_account_check` `a` WHERE `a`.`status` IN ( 0, 1, 2 ) )
) AS aaa
$where_params
ORDER BY
`create_time` DESC
...
...
application/task/controller/UpdateCouponTask.php
View file @
29708ad5
...
...
@@ -43,7 +43,7 @@ class UpdateCouponTask
#发券日期大于最后使用日期
if
(
$v
[
'create_time'
]
>
date
(
"Y-m-d H:i:s"
,
strtotime
(
"+
{
$v
[
'use_period'
]
}
day"
,
strtotime
(
$v
[
'use_period'
])))){
$this
->
m_coupon
->
updateStatus
(
$v
[
'id'
],
3
);
$this
->
m_coupon
->
updateStatus
(
$v
[
'id'
],
2
);
}
}
exit
;
...
...
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