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
11e531a2
Commit
11e531a2
authored
Mar 11, 2019
by
hujun
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
修改
parent
53e218f4
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
29 additions
and
21 deletions
+29
-21
CouponService.php
application/api/service/CouponService.php
+27
-19
CCoupon.php
application/model/CCoupon.php
+2
-2
No files found.
application/api/service/CouponService.php
View file @
11e531a2
...
...
@@ -26,15 +26,19 @@ class CouponService{
/**
* @param int $user_id
* @param int $type
* @param int $report_id
* @param int $bargain_id
* @param int $order_id
* @return mixed
* @throws \think\Exception
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\ModelNotFoundException
* @throws \think\exception\DbException
*/
public
function
sendCoupon
(
int
$user_id
,
int
$type
)
{
public
function
sendCoupon
(
int
$user_id
,
int
$type
,
$report_id
=
0
,
$bargain_id
=
0
,
$order_id
=
0
)
{
$result
[
'status'
]
=
'successful'
;
$result
[
'msg'
]
=
'发券成功'
;
$result
[
'data'
]
=
[];
$is_exist
=
$this
->
m_user
->
getUserByWhereValue
(
'id'
,
[
'id'
=>
$user_id
]);
if
(
empty
(
$is_exist
))
{
...
...
@@ -43,7 +47,6 @@ class CouponService{
return
$result
;
}
$date
=
date
(
'Y-m-d H:i:s'
);
$activity_data
=
$this
->
checkUserCoupon
(
$user_id
,
$type
);
if
(
empty
(
$activity_data
))
{
$result
[
'status'
]
=
'fail'
;
...
...
@@ -51,15 +54,21 @@ class CouponService{
return
$result
;
}
$save_data
=
[];
$save_data
[
'user_id'
]
=
$user_id
;
if
(
$report_id
)
{
$save_data
[
'report_id'
]
=
$report_id
;
}
if
(
$bargain_id
)
{
$save_data
[
'bargain_id'
]
=
$bargain_id
;
}
if
(
$order_id
)
{
$save_data
[
'order_id'
]
=
$order_id
;
}
$save_data
[
'status'
]
=
0
;
$save_data
[
'create_time'
]
=
date
(
'Y-m-d H:i:s'
);
foreach
(
$activity_data
as
$k
=>
$v
)
{
$save_data
[
'activity_id'
]
=
$v
[
'id'
];
$save_data
[
'rule_no'
]
=
date
(
'YMDHIS'
)
.
mt_rand
(
100
,
100000
);
$save_data
[
'user_id'
]
=
$user_id
;
$save_data
[
'report_id'
]
=
$user_id
;
$save_data
[
'bargain_id'
]
=
$user_id
;
$save_data
[
'order_id'
]
=
$user_id
;
$save_data
[
'status'
]
=
$user_id
;
$save_data
[
'use_time'
]
=
$date
;
$insert_status
=
$this
->
m_coupon
->
insertData
(
$save_data
);
if
(
empty
(
$insert_status
))
{
$this
->
m_activity
->
plusGetNumber
(
$v
[
'id'
]);
//增加用户领取数量
...
...
@@ -78,8 +87,8 @@ class CouponService{
* @throws \think\exception\DbException
*/
public
function
selectActivity
(
int
$return_action
)
{
$field
=
'id,return_type,money,activity_start_time,activity_end_time,use_period,
,
total,available,total'
;
$field
.=
',available,get_number
,status
'
;
$field
=
'id,return_type,money,activity_start_time,activity_end_time,use_period,total,available,total'
;
$field
.=
',available,get_number'
;
//奖励动作 0首次登陆 1邀请登陆 2邀请成交
switch
(
$return_action
)
{
...
...
@@ -98,8 +107,6 @@ class CouponService{
$where
[
'total'
]
=
[
'>'
,
0
];
$where
[
'return_action'
]
=
$return_action
;
$where
[
'status'
]
=
0
;
//0正常 1手动停止 2数量为空 3时间过期 4删除 5未开始
$where
[
'activity_start_time'
]
=
[
'>'
,
$date
];
$where
[
'activity_end_time'
]
=
[
'<'
,
$date
];
$data
=
$this
->
m_activity
->
getActivity
(
$field
,
$where
);
return
$data
;
}
...
...
@@ -117,20 +124,22 @@ class CouponService{
public
function
checkUserCoupon
(
int
$user_id
,
int
$type
)
{
$return_activity
=
[];
$time
=
time
();
$activity_data
=
$this
->
selectActivity
(
$type
);
$count_where
[
'user_id'
]
=
$user_id
;
foreach
(
$activity_data
as
$k
=>
$v
)
{
if
(
$v
[
'total'
]
-
$v
[
'get_number'
]
>
0
)
{
if
(
$v
[
'total'
]
-
$v
[
'get_number'
]
<=
0
)
{
continue
;
}
$count_where
[
'activity_id'
]
=
$v
[
'id'
];
$num
=
$this
->
m_coupon
->
getCount
(
$count_where
);
if
(
$num
<
$v
[
'available'
])
{
$return_activity
[]
=
$v
;
if
(
strtotime
(
$v
[
'activity_start_time'
])
<
$time
&&
strtotime
(
$v
[
'activity_end_time'
])
>
$time
)
{
$count_where
[
'activity_id'
]
=
$v
[
'id'
];
$num
=
$this
->
m_coupon
->
getCount
(
$count_where
);
if
(
$num
<
$v
[
'available'
])
{
$return_activity
[]
=
$v
;
}
}
}
return
$return_activity
;
}
}
\ No newline at end of file
application/model/CCoupon.php
View file @
11e531a2
...
...
@@ -61,10 +61,10 @@ class CCoupon
* @return int|string
*/
public
function
insertData
(
$data
)
{
if
(
is_array
(
$data
))
{
if
(
is_array
(
$data
[
0
]
))
{
$result
=
$this
->
db_
->
insertAll
(
$data
);
}
else
{
$result
=
$this
->
db_
->
insert
();
$result
=
$this
->
db_
->
insert
(
$data
);
}
return
$result
;
}
...
...
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