Skip to content
切换导航面板
项目
群组
代码片段
帮助
zhangtai
/
zzhnc
当前项目
正在载入...
登录
切换导航面板
转到一个项目
项目
版本库
问题
0
合并请求
0
流水线
维基
设置
活动
图像
图表
创建新的问题
作业
提交
问题看板
文件
提交
分支
标签
贡献者
图像
比较
图表
Commit 2e6cbf3d
由
zxt@theyeasy.com
编写于
Jan 03, 2018
浏览文件
选项
浏览文件
标签
下载
电子邮件补丁
差异文件
添加粉丝配置数量
1 个父辈
980ac755
全部展开
隐藏空白字符变更
内嵌
并排
正在显示
7 个修改的文件
包含
90 行增加
和
27 行删除
src/com/w1hd/zzhnc/controller/wx/WxMiniController.java
src/com/w1hd/zzhnc/model/Activity.java
src/com/w1hd/zzhnc/model/Fans.java
src/com/w1hd/zzhnc/service/FansService.java
src/com/w1hd/zzhnc/service/PrizeService.java
src/org/theyeasy/weixin/service/impl/WxMiniServiceImpl.java
src/org/theyeasy/weixin/util/ActivitySettingUtils.java
src/com/w1hd/zzhnc/controller/wx/WxMiniController.java
查看文件 @
2e6cbf3
...
...
@@ -100,14 +100,16 @@ public class WxMiniController extends BaseController {
@RequestMapping
(
value
=
"/login"
,
method
=
RequestMethod
.
GET
)
// 购房助手登录 double lng,double lat
public
@ResponseBody
Vo_msg
login
(
@RequestParam
(
value
=
"code"
)
String
code
,
@RequestParam
(
value
=
"shareId"
)
Integer
shareId
,
@RequestParam
(
value
=
"nickname"
)
String
nickname
,
@RequestParam
(
value
=
"shareId"
)
Integer
shareId
,
@RequestParam
(
value
=
"fansId"
)
Integer
fansId
,
@RequestParam
(
value
=
"nickname"
)
String
nickname
,
@RequestParam
(
value
=
"logo"
)
String
logo
,
@RequestParam
(
value
=
"lng"
)
double
lng
,
@RequestParam
(
value
=
"lat"
)
double
lat
)
{
logger
.
info
(
"小程序登录:code="
+
code
);
// 取openid
WxMiniSessionInfo
sessionInfo
=
WxMiniUtil
.
jscode2session
(
code
);
// 添加粉丝记录
Fans
fans
=
fansService
.
addFans
(
sessionInfo
,
shareId
,
nickname
,
logo
,
lng
,
lat
);
Fans
fans
=
fansService
.
addFans
(
sessionInfo
,
shareId
,
nickname
,
logo
,
lng
,
lat
,
fansId
);
if
(
fans
!=
null
)
{
Map
<
String
,
Object
>
map
=
new
HashMap
<>();
map
.
put
(
"miniOpenId"
,
sessionInfo
.
getOpenid
());
...
...
@@ -316,12 +318,12 @@ public class WxMiniController extends BaseController {
@ResponseBody
public
Object
prizesKill
(
@RequestParam
(
value
=
"openId"
)
String
openId
)
{
Fans
fans
=
fansService
.
getFansByMiniOpenid
(
openId
);
Integer
logId
=
prizeService
.
randomKill
(
fans
.
getId
());
if
(
logId
==
0
)
{
return
new
Vo_msg
(-
1
,
null
,
"不好意思你没中奖"
);
Integer
logId
=
prizeService
.
randomKill
(
fans
.
getId
()
,
0
);
if
(
logId
==
0
)
{
return
new
Vo_msg
(-
1
,
null
,
"不好意思你没中奖"
);
}
if
(
logId
==
-
1
)
{
return
new
Vo_msg
(-
1
,
null
,
"你已经中过奖了"
);
if
(
logId
==
-
1
)
{
return
new
Vo_msg
(-
1
,
null
,
"你已经中过奖了"
);
}
Lotterylog
log
=
prizeService
.
getLog
(
logId
);
return
new
Vo_msg
(
0
,
log
);
...
...
@@ -351,4 +353,17 @@ public class WxMiniController extends BaseController {
return
new
Vo_msg
(
0
,
seacrh
);
}
@RequestMapping
(
value
=
"/goods/share/{id}"
,
method
=
RequestMethod
.
GET
)
@ResponseBody
public
Object
goodsShare
(
@RequestParam
(
value
=
"openId"
)
String
openId
,
@PathVariable
(
value
=
"id"
)
Integer
id
)
{
PageResults
<
Goods
>
seacrh
=
goodsService
.
seacrh
(
id
,
null
,
null
,
null
,
null
);
Goods
goods
=
seacrh
.
getRows
().
get
(
0
);
goods
.
setShareCount
(
goods
.
getShareCount
()
+
1
);
goodsService
.
update
(
goods
);
Fans
fans
=
fansService
.
getFansByMiniOpenid
(
openId
);
fans
.
setShareCount
(
fans
.
getShareCount
()
+
1
);
fansService
.
updateFans
(
fans
);
return
new
Vo_msg
(
0
,
seacrh
);
}
}
src/com/w1hd/zzhnc/model/Activity.java
查看文件 @
2e6cbf3
...
...
@@ -25,7 +25,7 @@ public class Activity implements Serializable {
@DateTimeFormat
(
pattern
=
"yyyy-MM-dd HH:mm:ss"
)
@JsonFormat
(
pattern
=
"yyyy-MM-dd HH:mm:ss"
,
timezone
=
"GMT+8"
)
private
Date
endTime
;
// 活动结束时间
private
int
shareCount
;
// 下属粉丝达到一定数量可以再次抽奖
private
int
status
;
// 活动状态
private
BigDecimal
planMny
;
// 发放红包预算
private
BigDecimal
currentMny
;
...
...
@@ -295,5 +295,12 @@ public class Activity implements Serializable {
this
.
p8
=
p8
;
}
public
int
getShareCount
()
{
return
shareCount
;
}
public
void
setShareCount
(
int
shareCount
)
{
this
.
shareCount
=
shareCount
;
}
}
\ No newline at end of file
src/com/w1hd/zzhnc/model/Fans.java
查看文件 @
2e6cbf3
package
com
.
w1hd
.
zzhnc
.
model
;
import
java.io.Serializable
;
import
java.util.Date
;
import
javax.persistence.Id
;
import
org.joda.time.DateTime
;
public
class
Fans
{
public
class
Fans
implements
Serializable
{
/**
*
*/
private
static
final
long
serialVersionUID
=
-
418002994563516320L
;
@Id
private
Integer
id
;
...
...
@@ -44,6 +50,8 @@ public class Fans {
private
boolean
readed
=
false
;
private
String
remarkName
;
private
Integer
shareCount
;
public
Integer
getId
()
{
return
id
;
}
...
...
@@ -213,9 +221,12 @@ public class Fans {
this
.
remarkName
=
remarkName
;
}
public
Integer
getShareCount
()
{
return
shareCount
;
}
public
void
setShareCount
(
Integer
shareCount
)
{
this
.
shareCount
=
shareCount
;
}
}
\ No newline at end of file
src/com/w1hd/zzhnc/service/FansService.java
查看文件 @
2e6cbf3
...
...
@@ -4,6 +4,7 @@ import java.util.List;
import
org.apache.ibatis.session.RowBounds
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.data.redis.core.RedisTemplate
;
import
org.springframework.stereotype.Service
;
import
org.theyeasy.weixin.model.WxMiniSessionInfo
;
import
org.theyeasy.weixin.util.CusAccessObjectUtil2
;
...
...
@@ -14,6 +15,7 @@ import com.w1hd.zzhnc.dao.FansDao;
import
com.w1hd.zzhnc.model.Fans
;
import
com.w1hd.zzhnc.util.CommonUtil
;
import
com.w1hd.zzhnc.util.PageResults
;
import
com.w1hd.zzhnc.util.RedisUtil
;
import
jodd.util.URLDecoder
;
import
tk.mybatis.mapper.entity.Example
;
...
...
@@ -29,14 +31,15 @@ import tk.mybatis.mapper.entity.Example.Criteria;
@Service
public
class
FansService
{
public
static
final
String
FANS_KEY_OPENID
=
RedisUtil
.
PROJECTNAME
.
concat
(
"_"
).
concat
(
"FANS_KEY_OPENID_"
);
@Autowired
FansDao
fansDao
;
public
PageResults
<
Fans
>
getFansList
(
Integer
page
,
String
keyword
)
{
Example
ex
=
new
Example
(
Fans
.
class
);
Criteria
criteria
=
ex
.
createCriteria
();
if
(!
Strings
.
isNullOrEmpty
(
keyword
))
{
criteria
.
andCondition
(
" ( nickname like \"%"
+
keyword
+
"%\")"
);
if
(!
Strings
.
isNullOrEmpty
(
keyword
))
{
criteria
.
andCondition
(
" ( nickname like \"%"
+
keyword
+
"%\")"
);
}
RowBounds
row
=
new
RowBounds
((
page
-
1
)
*
10
,
10
);
List
<
Fans
>
list
=
fansDao
.
selectByExampleAndRowBounds
(
ex
,
row
);
...
...
@@ -49,14 +52,24 @@ public class FansService {
return
pageresult
;
}
@Autowired
RedisTemplate
redisTemplate
;
@SuppressWarnings
(
"unchecked"
)
public
Fans
getFansByMiniOpenid
(
String
miniOpenid
)
{
Example
example
=
new
Example
(
Fans
.
class
);
example
.
createCriteria
().
andEqualTo
(
"miniopenid"
,
miniOpenid
);
List
<
Fans
>
list
=
fansDao
.
selectByExample
(
example
);
if
(
list
!=
null
&&
list
.
size
()
>
0
)
{
return
list
.
get
(
0
);
Fans
fans
=
(
Fans
)
redisTemplate
.
opsForValue
().
get
(
FANS_KEY_OPENID
+
miniOpenid
);
if
(
fans
==
null
)
{
Example
example
=
new
Example
(
Fans
.
class
);
example
.
createCriteria
().
andEqualTo
(
"miniopenid"
,
miniOpenid
);
List
<
Fans
>
list
=
fansDao
.
selectByExample
(
example
);
if
(
list
!=
null
&&
list
.
size
()
>
0
)
{
fans
=
list
.
get
(
0
);
redisTemplate
.
opsForValue
().
set
(
FANS_KEY_OPENID
+
miniOpenid
,
fans
);
return
fans
;
}
}
return
null
;
return
fans
;
}
public
Fans
getFansById
(
Integer
id
)
{
...
...
@@ -77,13 +90,14 @@ public class FansService {
fans
.
setLogo
(
""
);
fans
.
setNickname
(
""
);
fans
.
setParentfansid
(
0
);
fans
.
setShareCount
(
0
);
int
flag
=
fansDao
.
insertSelective
(
fans
);
return
fans
;
// 插入成功后会返回新的id;
}
public
Fans
addFans
(
WxMiniSessionInfo
info
,
Integer
shareFansId
,
String
nickname
,
String
logo
,
double
lng
,
double
lat
)
{
double
lat
,
Integer
fansId
)
{
if
(
info
==
null
)
return
null
;
...
...
@@ -108,6 +122,7 @@ public class FansService {
fans
.
setFanstype
(
1
);
fans
.
setLng
(
lng
);
fans
.
setLat
(
lat
);
fans
.
setParentfansid
(
fansId
);
JSONObject
locationResult
=
CusAccessObjectUtil2
.
locationResult
(
lng
,
lat
);
if
(
null
!=
locationResult
)
{
fans
.
setProvince
(
CusAccessObjectUtil2
.
getProvince
(
locationResult
));
...
...
@@ -133,16 +148,28 @@ public class FansService {
fansDao
.
updateByPrimaryKeySelective
(
fans
);
}
}
catch
(
Exception
e
)
{
// TODO Auto-generated catch block
e
.
printStackTrace
();
System
.
out
.
println
(
"新增粉丝失败:"
+
e
.
getMessage
());
return
null
;
}
return
fans
;
}
@SuppressWarnings
(
"unchecked"
)
public
void
updateFans
(
Fans
fans
)
{
redisTemplate
.
delete
(
FANS_KEY_OPENID
+
fans
.
getMiniopenid
());
fansDao
.
updateByPrimaryKeySelective
(
fans
);
}
public
Integer
getCountParentFansId
(
Integer
id
)
{
try
{
Example
ex
=
new
Example
(
Fans
.
class
);
ex
.
createCriteria
().
andEqualTo
(
"parentfansid"
,
id
).
andNotEqualTo
(
"parentfansid"
,
0
);
return
fansDao
.
selectCountByExample
(
ex
);
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
}
return
0
;
}
}
src/com/w1hd/zzhnc/service/PrizeService.java
查看文件 @
2e6cbf3
...
...
@@ -125,6 +125,7 @@ public class PrizeService {
default
:
break
;
}
setting
.
setCurrentMny
(
setting
.
getCurrentMny
().
add
(
mny
));
activityService
.
updateActivity
(
setting
);
Lotterylog
lotterylog
=
new
Lotterylog
();
lotterylog
.
setCreatedtime
(
new
Date
());
...
...
@@ -169,7 +170,9 @@ public class PrizeService {
RedisTemplate
redisTemplate
;
@SuppressWarnings
(
"unchecked"
)
public
Integer
randomKill
(
Integer
fansId
)
{
public
Integer
randomKill
(
Integer
fansId
,
Integer
count
)
{
if
(
count
==
8
)
return
0
;
Integer
lotteryLog
=
(
Integer
)
redisTemplate
.
opsForValue
().
get
(
PRIZE_KILL_FANSID
+
fansId
);
if
(
lotteryLog
==
null
)
{
Activity
activity
=
activityService
.
getActivitySetting
();
...
...
@@ -258,7 +261,7 @@ public class PrizeService {
logId
=
insert
(
fansId
,
8
,
new
BigDecimal
(
mny
*
0.01
).
setScale
(
2
,
RoundingMode
.
HALF_UP
));
}
else
{
if
(
sumNum
>
0
)
{
return
randomKill
(
fansId
);
return
randomKill
(
fansId
,
count
++
);
}
}
}
...
...
src/org/theyeasy/weixin/service/impl/WxMiniServiceImpl.java
查看文件 @
2e6cbf3
此文件的差异被折叠,
点击展开。
src/org/theyeasy/weixin/util/ActivitySettingUtils.java
查看文件 @
2e6cbf3
...
...
@@ -23,8 +23,8 @@ public class ActivitySettingUtils {
public
static
ActivitySettingUtils
getInstance
(
Activity
act
)
{
if
(
instance
==
null
)
{
instance
=
new
ActivitySettingUtils
();
ActivitySettingUtils
.
act
=
act
;
}
ActivitySettingUtils
.
act
=
act
;
return
instance
;
}
...
...
编写
预览
Markdown
格式
附加文件
你添加了
0
人
到此讨论。请谨慎行事。
请先完成此消息的编辑!
取消
请
注册
或
登录
后发表评论