|
@@ -4,6 +4,7 @@ import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
4
|
4
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
5
|
5
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
6
|
6
|
import com.huiju.estateagents.base.ResponseBean;
|
|
7
|
+import com.huiju.estateagents.common.CommConstant;
|
7
|
8
|
import com.huiju.estateagents.entity.TaPerson;
|
8
|
9
|
import com.huiju.estateagents.entity.TaShareActivity;
|
9
|
10
|
import com.huiju.estateagents.entity.TaShareChildRecord;
|
|
@@ -16,6 +17,7 @@ import com.huiju.estateagents.service.ITaShareChildRecordService;
|
16
|
17
|
import org.springframework.beans.factory.annotation.Autowired;
|
17
|
18
|
import org.springframework.stereotype.Service;
|
18
|
19
|
|
|
20
|
+import java.time.LocalDateTime;
|
19
|
21
|
import java.util.List;
|
20
|
22
|
|
21
|
23
|
/**
|
|
@@ -84,4 +86,86 @@ public class TaShareChildRecordServiceImpl extends ServiceImpl<TaShareChildRecor
|
84
|
86
|
|
85
|
87
|
return responseBean;
|
86
|
88
|
}
|
|
89
|
+
|
|
90
|
+ /**
|
|
91
|
+ * 微信端成为团员
|
|
92
|
+ *
|
|
93
|
+ * @param taShareChildRecord
|
|
94
|
+ * @param orgId
|
|
95
|
+ * @param person
|
|
96
|
+ * @return
|
|
97
|
+ */
|
|
98
|
+ @Override
|
|
99
|
+ public ResponseBean addChildRecord(TaShareChildRecord taShareChildRecord, Integer orgId, TaPerson person) {
|
|
100
|
+ //查看是否拼团成功
|
|
101
|
+ TaShareRecord taShareRecord = tashareRecordmapper.selectById(taShareChildRecord.getRecordId());
|
|
102
|
+ if (taShareRecord.getStatus().equals(CommConstant.STATUS_UNACCALIMED)){
|
|
103
|
+ return ResponseBean.error("已经拼团成功", ResponseBean.ERROR_UNAVAILABLE);
|
|
104
|
+ }
|
|
105
|
+
|
|
106
|
+ //查看是否拼团成功
|
|
107
|
+ TaShareActivity taShareActivity = activityMapper.selectById(taShareChildRecord.getGroupActivityId());
|
|
108
|
+ if (taShareActivity.getJoinPeople() >= taShareActivity.getGroupBuyPeople()){
|
|
109
|
+ return ResponseBean.error("已经拼团成功", ResponseBean.ERROR_UNAVAILABLE);
|
|
110
|
+ }
|
|
111
|
+ if (taShareActivity.getEndTime().isBefore(LocalDateTime.now())){
|
|
112
|
+ return ResponseBean.error("活动已超时", ResponseBean.ERROR_UNAVAILABLE);
|
|
113
|
+ }
|
|
114
|
+
|
|
115
|
+ //查看这个人是否是团员
|
|
116
|
+ QueryWrapper<TaShareChildRecord> taShareChildRecordQueryWrapper = new QueryWrapper<>();
|
|
117
|
+ taShareChildRecordQueryWrapper.eq("org_id",orgId);
|
|
118
|
+ taShareChildRecordQueryWrapper.eq("group_activity_id",taShareChildRecord.getGroupActivityId());
|
|
119
|
+ taShareChildRecordQueryWrapper.eq("person_id",person.getPersonId());
|
|
120
|
+ taShareChildRecordQueryWrapper.eq("record_id",taShareChildRecord.getRecordId());
|
|
121
|
+ List<TaShareChildRecord> shareChildRecordList = taShareChildRecordMapper.selectList(taShareChildRecordQueryWrapper);
|
|
122
|
+ if (shareChildRecordList.size() > 0){
|
|
123
|
+ return ResponseBean.error("您已经是团员,无需重复拼团", ResponseBean.ERROR_UNAVAILABLE);
|
|
124
|
+ }
|
|
125
|
+
|
|
126
|
+ //检查这个团员积分够不够
|
|
127
|
+ if (person.getPoints() == null || person.getPoints() < taShareActivity.getIntegral()){
|
|
128
|
+ return ResponseBean.error("积分不足",ResponseBean.ERROR_UNAVAILABLE);
|
|
129
|
+ }
|
|
130
|
+
|
|
131
|
+ //反更新人数
|
|
132
|
+ taShareActivity.setJoinPeople(taShareActivity.getJoinPeople()+1);
|
|
133
|
+ activityMapper.updateById(taShareActivity);
|
|
134
|
+
|
|
135
|
+ //成为团员
|
|
136
|
+ taShareChildRecord.setOrgId(orgId);
|
|
137
|
+ taShareChildRecord.setStatus(CommConstant.STATUS_NORMAL);
|
|
138
|
+ taShareChildRecord.setPersonId(person.getPersonId());
|
|
139
|
+ taShareChildRecordMapper.insert(taShareChildRecord);
|
|
140
|
+ if (taShareActivity.getJoinPeople().equals(taShareActivity.getGroupBuyPeople())){
|
|
141
|
+ //发送微信模板消息所有人都发送--todo
|
|
142
|
+
|
|
143
|
+ //生成团员核销码和改状态拼团成功
|
|
144
|
+ changeChildRecord(taShareChildRecord.getRecordId(),orgId,taShareChildRecord.getGroupActivityId());
|
|
145
|
+ //生成团长核销码和拼团成功
|
|
146
|
+ taShareRecord.setVerificationCode(String.valueOf(taShareRecord.getRecordId()+System.currentTimeMillis()));
|
|
147
|
+ taShareRecord.setVerificationStatus(CommConstant.STATUS_UNACCALIMED);
|
|
148
|
+ }
|
|
149
|
+ tashareRecordmapper.updateById(taShareRecord);
|
|
150
|
+ return ResponseBean.success(taShareRecord);
|
|
151
|
+ }
|
|
152
|
+
|
|
153
|
+ /**
|
|
154
|
+ * 更改团员状态和生成核销码
|
|
155
|
+ * @param recordId
|
|
156
|
+ * @param orgId
|
|
157
|
+ * @param groupActivityId
|
|
158
|
+ */
|
|
159
|
+ private void changeChildRecord(Integer recordId, Integer orgId, Integer groupActivityId) {
|
|
160
|
+ QueryWrapper<TaShareChildRecord> taShareChildRecordQueryWrapper = new QueryWrapper<>();
|
|
161
|
+ taShareChildRecordQueryWrapper.eq("record_id",recordId);
|
|
162
|
+ taShareChildRecordQueryWrapper.eq("org_id",orgId);
|
|
163
|
+ taShareChildRecordQueryWrapper.eq("group_activity_id",groupActivityId);
|
|
164
|
+ List<TaShareChildRecord> shareChildRecordList = taShareChildRecordMapper.selectList(taShareChildRecordQueryWrapper);
|
|
165
|
+ shareChildRecordList.forEach(e -> {
|
|
166
|
+ e.setVerificationCode(String.valueOf(e.getChildRecordId()+System.currentTimeMillis()));
|
|
167
|
+ e.setVerificationStatus(CommConstant.STATUS_UNACCALIMED);
|
|
168
|
+ });
|
|
169
|
+ this.updateBatchById(shareChildRecordList);
|
|
170
|
+ }
|
87
|
171
|
}
|