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
84a58217
Commit
84a58217
authored
Mar 12, 2019
by
zhuwei
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
核销优惠券
parent
635f333d
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
208 additions
and
10 deletions
+208
-10
ConvertCouponService.php
application/api/service/ConvertCouponService.php
+164
-0
ImageDepot.php
application/index/controller/ImageDepot.php
+22
-10
CCoupon.php
application/model/CCoupon.php
+22
-0
No files found.
application/api/service/ConvertCouponService.php
0 → 100644
View file @
84a58217
<?php
namespace
app\api\service
;
use
app\model\CCoupon
;
use
app\model\Users
;
/**
* 核销优惠券
* Created by PhpStorm.
* User: zhuwei
* Date: 2019/3/12
* Time: 2:39 PM
*/
class
ConvertCouponService
{
private
$m_coupon
;
private
$m_user
;
function
__construct
()
{
$this
->
m_coupon
=
new
CCoupon
();
$this
->
m_user
=
new
Users
();
}
/**
* 核销优惠券
* @return bool
*/
public
function
convertCoupon
(
$user_id
){
if
(
!
$user_id
){
return
false
;
}
// 根据$user_id 取出 当前客户的 0首次登陆 1邀请登陆 券
$coupon_list
=
$this
->
getCoupon
(
$user_id
,
''
);
if
(
!
$coupon_list
){
return
false
;
}
//去除已经过期的优惠券
$coupon_list
=
$this
->
filterExpireData
(
$coupon_list
);
// 存在未过期 券数等于1直接核销
$coupon_list_count
=
count
(
$coupon_list
);
if
(
$coupon_list_count
==
0
){
return
false
;
}
elseif
(
$coupon_list_count
>
1
){
// 券数大于1 选取金额最大的核销
$coupon_list
=
[];
$coupon_list
=
$this
->
getMaxCoupon
(
$coupon_list
);
}
//修改券状态为已使用
$this
->
m_coupon
->
updateStatus
(
$coupon_list
[
0
][
'id'
],
2
);
//todo 将活动奖励金额写入账户余额 $coupon_list[0]['money']
// 查询当前客户的是否有邀请人
$invite_user
=
$this
->
getUserInviter
(
$user_id
);
if
(
!
$invite_user
){
return
false
;
}
//是客户 根据邀请人user_id 和被邀请人user_id 取出 2邀请成交 券
$invite_user_coupon_list
=
$this
->
getCoupon
(
$user_id
,
$invite_user
);
if
(
!
$invite_user_coupon_list
){
return
false
;
}
//去除已经过期的优惠券
$invite_user_coupon_list
=
$this
->
filterExpireData
(
$invite_user_coupon_list
);
// 存在未过期
$invite_user_coupon_list_count
=
count
(
$invite_user_coupon_list
);
if
(
$invite_user_coupon_list_count
==
0
){
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']
}
return
true
;
}
/**
* 获取最大优惠券
* @return mixed
*/
public
function
getMaxCoupon
(
$coupon_list
){
$field
=
'money'
;
$temp
=
[];
foreach
(
$coupon_list
as
$k
=>
$v
){
$temp
[]
=
$v
[
$field
];
}
$max_money
=
max
(
$temp
);
foreach
(
$coupon_list
as
$k
=>
$v
){
if
(
$v
[
$field
]
==
$max_money
){
return
$coupon_list
[
$k
];
}
}
}
/**
* 去除已经过期的优惠券,并修改状态为已过期
* @param $coupon_list
* @return mixed
*/
public
function
filterExpireData
(
$coupon_list
){
// 循环查看是否过期
foreach
(
$coupon_list
as
$k
=>
$v
)
{
if
(
$v
[
'use_period'
]
<
0
){
continue
;
}
#发券日期大于最后使用日期
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'
],
2
);
unset
(
$coupon_list
[
$k
]);
continue
;
}
}
return
$coupon_list
;
}
/**
* 获取优惠券
* @param $user_id
* @param $referrer_id
* @return false|\PDOStatement|string|\think\Collection
*/
public
function
getCoupon
(
$user_id
,
$referrer_id
){
$field
=
'a.id,a.activity_id,a.create_time,b.money,b.use_period'
;
$params
[
'a.user_id'
]
=
$user_id
;
if
(
$referrer_id
){
$params
[
'a.referrer_id'
]
=
$referrer_id
;
$params
[
'b.return_action'
]
=
2
;
}
else
{
$params
[
'b.return_action'
]
=
array
(
"in"
,
"0,1"
);
}
$params
[
'a.status'
]
=
0
;
return
$this
->
m_coupon
->
getCouponJoinActivity
(
$field
,
$params
);
}
/**
* 获取客户邀请人[必须是客户]
* @param $user_id
* @return bool
*/
public
function
getUserInviter
(
$user_id
)
{
//查找邀请人的信息
$field_referrer
=
'id,referrer_id,referrer_source'
;
$referrer_res
=
$this
->
m_user
->
getUserByWhere
([
"id"
=>
$user_id
],
$field_referrer
);
if
(
count
(
$referrer_res
)
<=
0
)
return
false
;
// 存在邀请人则判断是否是客户
if
(
$referrer_res
[
0
][
'referrer_source'
]
==
20
)
return
false
;
return
$referrer_res
[
0
][
'referrer_id'
];
}
}
\ No newline at end of file
application/index/controller/ImageDepot.php
View file @
84a58217
...
...
@@ -181,24 +181,36 @@ class ImageDepot extends Basic
public
function
ceshi
()
{
$messageUntil
=
new
MessageUntils
();
$data
=
'朱伟2'
;
$result
=
$messageUntil
->
sendSMSForUser
(
'18112347151'
,
$data
,
'415209'
);
if
(
$result
==
'true'
)
{
return
$this
->
response
(
"200"
,
"短信发送成功"
,
$result
);
}
else
{
return
$this
->
response
(
"101"
,
$result
);
$arr
=
[[
'id'
=>
1
,
'money'
=>
400
,
'sd'
=>
1
],[
'id'
=>
2
,
'money'
=>
200
,
'sd'
=>
1
],[
'id'
=>
3
,
'money'
=>
300
,
'sd'
=>
1
],[
'id'
=>
4
,
'money'
=>
400
,
'sd'
=>
1
]];
$field
=
'money'
;
$temp
=
[];
foreach
(
$arr
as
$k
=>
$v
){
$temp
[]
=
$v
[
$field
];
}
$max_money
=
max
(
$temp
);
foreach
(
$arr
as
$k
=>
$v
){
if
(
$v
[
$field
]
==
$max_money
){
// return $arr[$k];
dump
(
$arr
[
$k
]);
exit
;
}
}
}
//
// function getArrayMax($arr,$field)
// {
// foreach ($arr as $k=>$v){
// $temp[]=$v[$field];
// }
// return max($temp);
}
}
application/model/CCoupon.php
View file @
84a58217
...
...
@@ -46,6 +46,18 @@ class CCoupon extends BaseModel
return
$result
;
}
public
function
getCouponJoinActivity
(
$field
,
$params
)
{
$result
=
$this
->
db_
->
field
(
$field
)
->
alias
(
"a"
)
->
join
(
"c_activity b"
,
"a.activity_id = b.id"
,
"left"
)
->
where
(
$params
)
->
select
();
//dump($this->getLastSql());
return
$result
;
}
/**
* @param $field
* @param $params
...
...
@@ -118,4 +130,13 @@ class CCoupon extends BaseModel
public
function
commitTrans
()
{
$this
->
db_
->
commit
();
}
public
function
updateStatus
(
$id
,
$status
)
{
$result
=
$this
->
db_
->
where
([
'id'
=>
$id
])
->
update
([
'status'
=>
$status
]);
// big_log($this->getLastSql());
return
$result
;
}
}
\ 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