935090232@qq.com
2021-07-09 5ebd818a240239e22cb3a587e616991bf208d56b
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
package com.matrix.system.shopXcx.api.action;
 
import com.matrix.component.rabbitmq.RabiitMqTemplate;
import com.matrix.component.redis.RedisUserLoginUtils;
import com.matrix.core.exception.GlobleException;
import com.matrix.core.pojo.AjaxResult;
import com.matrix.core.pojo.VerifyResult;
import com.matrix.core.tools.DateUtil;
import com.matrix.core.tools.StringUtils;
import com.matrix.system.app.mapper.SysProjUseMapper;
import com.matrix.system.app.vo.ServiceProductListVo;
import com.matrix.system.app.vo.ServiceProjVo;
import com.matrix.system.app.vo.ServiceTcVo;
import com.matrix.system.common.bean.BusParameterSettings;
import com.matrix.system.common.bean.SysUsers;
import com.matrix.system.common.dao.BusParameterSettingsDao;
import com.matrix.system.common.dao.SysUsersDao;
import com.matrix.system.common.interceptor.HostInterceptor;
import com.matrix.system.common.tools.LocationUtil;
import com.matrix.system.constance.Dictionary;
import com.matrix.system.hive.bean.*;
import com.matrix.system.hive.dao.*;
import com.matrix.system.hive.plugin.util.CollectionUtils;
import com.matrix.system.hive.service.*;
import com.matrix.system.score.constant.ScoreSettingConstant;
import com.matrix.system.score.entity.ScoreVipDetail;
import com.matrix.system.score.service.ScoreVipDetailService;
import com.matrix.system.shopXcx.api.dto.ErpServiceCommentDto;
import com.matrix.system.shopXcx.api.dto.ErpServiceOrderListDto;
import com.matrix.system.shopXcx.api.vo.ErpServiceOrderListVo;
import com.matrix.system.shopXcx.dao.ShopProductDao;
import com.matrix.system.shopXcx.dao.ShopSkuDao;
import com.matrix.system.shopXcx.dto.YYDayOfWeek;
import com.matrix.system.shopXcx.dto.YYmonth;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiResponse;
import io.swagger.annotations.ApiResponses;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Controller;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
 
import javax.annotation.Resource;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
 
/**
 * @author jiangyouyao
 * @description 预约信息action
 * @date 2019-06-06 10:15
 */
@CrossOrigin(origins = "*", maxAge = 3600)
@Controller
@RequestMapping(value = "wxapi/yuyue")
public class YuyueAction {
 
    @Autowired
    SysShopInfoDao shopInfoDao;
 
    @Autowired
    private SysVipInfoDao vipInfoDao;
 
    @Autowired
    private OnlinebookingDao onlinebookingDao;
    @Autowired
    private SysProjServicesService projServicesService;
 
    @Autowired
    private  SysProjServicesDao projServicesDao;
 
    @Autowired
    private  SysBeauticianStateService sysBeauticianStateService;
 
    @Autowired
    RedisUserLoginUtils redisUserLoginUtils;
 
    @Autowired
    ShopProductDao productDao;
 
    @Autowired
    SysUsersDao staffInfoDao;
 
    @Autowired
    SysVipInfoDao sysVipInfoDao;
 
    @Autowired
    RabiitMqTemplate rabiitMqTemplate;
 
    @Autowired
    SysProjUseDao projUseDao;
 
    @Autowired
    ShopSkuDao skuDao;
 
    @Autowired
    ShoppingGoodsAssembleDao shoppingGoodsAssembleDao;
 
    @Autowired
    ShoppingGoodsDao shoppingGoodsDao;
    @Autowired
    ScoreVipDetailService scoreVipDetailService;
 
    @Autowired
    private BusParameterSettingsDao busParameterSettingsDao;
 
    @Value("${evn}")
    private String evn;
    /**
     * 获取门店列表
     *
     * @return
     */
    @RequestMapping(value = "/getShopList/{locX}/{locY}")
    public @ResponseBody
    AjaxResult getShopList(@PathVariable("locX") String locX, @PathVariable("locY") String locY) {
        SysShopInfo sysShopInfo=new SysShopInfo();
        sysShopInfo.setIsOpenNet(SysShopInfo.OPEN_NET);
        sysShopInfo.setCompanyId(HostInterceptor.getCompanyId());
        List<SysShopInfo> shopList = shopInfoDao.selectByModel(sysShopInfo);
 
        if ("X".equals(locX) || "Y".equals(locY)) {
            return new AjaxResult(AjaxResult.STATUS_SUCCESS, shopList);
        }
 
        Double distance = null;
        SysShopInfo nearestShop = null;
 
        AjaxResult ajaxResult = new AjaxResult("200", shopList);
        if (CollectionUtils.isNotEmpty(shopList)) {
            for (SysShopInfo shopInfo : shopList) {
                Double shopX = Double.parseDouble(shopInfo.getLongitude());
                Double shopY = Double.parseDouble(shopInfo.getLatitude());
                Double disResult = LocationUtil.getDistance(Double.parseDouble(locX), Double.parseDouble(locY), shopX, shopY);
                shopInfo.setDistance(new BigDecimal(disResult).setScale(1, BigDecimal.ROUND_HALF_UP));
                if (distance == null || distance > disResult) {
                    distance = disResult;
                    nearestShop = shopInfo;
                }
            }
        }
        ajaxResult.putInMap("shopInfo", nearestShop);
        return ajaxResult;
 
    }
 
    @RequestMapping(value = "/findShopInfoById/{id}")
    @ResponseBody
    public AjaxResult findShopInfoById(@PathVariable Long id) {
        SysShopInfo shopInfo = shopInfoDao.selectById(id);
        AjaxResult ajaxResult = new AjaxResult(AjaxResult.STATUS_SUCCESS,"获取成功");
        ajaxResult.putInMap("shopInfo", shopInfo);
        return ajaxResult;
    }
 
 
    /**
     * 获取预约时间表
     *
     * @return
     */
    @RequestMapping(value = "/getTimeList")
    public @ResponseBody
    AjaxResult getTimeList() {
        return new AjaxResult("200", YYmonth.buildMonth(3));
 
    }
 
 
    /**
     * 获取预约日期
     *
     * @return
     */
    @RequestMapping(value = "/getYYDayAndWeek")
    public @ResponseBody
    AjaxResult getYYDayAndWeek(String time) {
        Date date = DateUtil.stringToDate(time, DateUtil.DATE_FORMAT_DD);
        List<YYDayOfWeek> yyDayOfWeeks = YYDayOfWeek.build(date, 4);
        return new AjaxResult("200", yyDayOfWeeks);
    }
 
 
    @Resource
    private SysWorkBeatuistaffService sysWorkBeatuistaffService;
    @Resource
    private com.matrix.system.common.service.SysUsersService SysUsersService;
    @Autowired
    private SysWorktimeService sysWorkTimeService;
 
    /**
     * 查询空闲美疗师
     */
    @RequestMapping(value = "/getPaiBanBeauticianList")
    public @ResponseBody
    AjaxResult showPaiBanBeauticianList(@RequestBody SysBeauticianState sysBeauticianState) {
        if(StringUtils.isNotBlank(sysBeauticianState.getBbeginTime())&&
        StringUtils.isNotBlank(sysBeauticianState.getEendTime())){
            sysBeauticianState.setBeginTime(DateUtil.stringToDate(sysBeauticianState.getBbeginTime(), DateUtil.DATE_FORMAT_MM));
            sysBeauticianState.setEndTime(DateUtil.stringToDate(sysBeauticianState.getEendTime(), DateUtil.DATE_FORMAT_MM));
            String codes = DateUtil.dateToString(sysBeauticianState.getBeginTime(),DateUtil.DATE_FORMAT_NO_SPLITE_DD);
            List<SysUsers> staffs = SysUsersService.findByCodeBeaStateShop(sysBeauticianState.getShopId(),
                    sysBeauticianState, codes);
            return new AjaxResult(AjaxResult.STATUS_SUCCESS, staffs);
        }else{
            return  AjaxResult.buildSuccessInstance("");
        }
 
 
    }
 
    @Resource
    private SysProjUseService projUseService;
 
    /**
     * 获取用户已购项目列表
     *
     * @return
     */
    @RequestMapping(value = "/getUserPro/{phone}")
    @ResponseBody
    public
    AjaxResult getUserPro(@PathVariable String phone) {
        SysVipInfo vipInfo = vipInfoDao.selectByPhone(phone,HostInterceptor.getCompanyId());
 
        if (vipInfo == null) {
            throw new GlobleException("会员不存在");
        }
        ServiceProductListVo productListVo = new ServiceProductListVo();
        productListVo.setName(vipInfo.getVipName());
        productListVo.setVipId(vipInfo.getId());
 
        SysProjUse queryUse = new SysProjUse();
        queryUse.setVipId(vipInfo.getId());
        queryUse.setType(Dictionary.SHOPPING_GOODS_TYPE_XM);
        queryUse.setTaocanId(-1L);
        queryUse.setStatus(Dictionary.TAOCAN_STATUS_YX);
        List<SysProjUse> projList = projUseService.findInPage(queryUse, null);
        List<ServiceProjVo> serviceProjVos = SysProjUseMapper.INSTANCE.entityListToProjVoList(projList);
 
        queryUse.setTaocanId(null);
        queryUse.setType(Dictionary.SHOPPING_GOODS_TYPE_TC);
        List<SysProjUse> taoCanList = projUseService.findInPage(queryUse, null);
        List<ServiceTcVo> serviceTcVos = SysProjUseMapper.INSTANCE.entityListToTcVoList(taoCanList);
 
        if (CollectionUtils.isNotEmpty(serviceTcVos)) {
            serviceTcVos.forEach(item -> {
                List<SysProjUse> sysProjUses = projUseService.selectTaocanProjUse(item.getId(), queryUse.getStatus());
                List<ServiceProjVo> taocanProj = SysProjUseMapper.INSTANCE.entityListToProjVoList(sysProjUses);
                item.setProj(taocanProj);
            });
        }
 
        productListVo.setProj(serviceProjVos);
        productListVo.setComposeProj(serviceTcVos);
        AjaxResult ajaxResult = AjaxResult.buildSuccessInstance("获取成功");
        ajaxResult.putInMap("proj", productListVo);
        return ajaxResult;
    }
 
 
    @Autowired
    private CodeService codeService;
 
    /**
     * 创建预约订单
     *
     * @param onlinebooking
     * @return
     */
    @RequestMapping(value = "/createServiceOrder")
    public @ResponseBody
    AjaxResult createServiceOrder(@RequestBody Onlinebooking onlinebooking) {
        SysVipInfo sysVipInfo = redisUserLoginUtils.getLoginUser(SysVipInfo.class);
        SysVipInfo vipInfo = vipInfoDao.selectByPhone(sysVipInfo.getPhone(),HostInterceptor.getCompanyId());
        SysProjUse sysProjUse = projUseDao.selectById(Long.parseLong(onlinebooking.getProductId() + ""));
        Date yyTime = DateUtil.stringToDate(onlinebooking.getTimeStr(), DateUtil.DATE_FORMAT_MM);
        SysProjServices sysProjServices = new SysProjServices();
        sysProjServices.setCompanyId(vipInfo.getCompanyId());
        sysProjServices.setShopId(onlinebooking.getShopId());
        sysProjServices.setVipId(vipInfo.getId());
        sysProjServices.setYyTime(yyTime);
        sysProjServices.setRemark(onlinebooking.getRemark());
 
        List<SysBeauticianState> sysBeauticianStates = new ArrayList<>();
 
        SysBeauticianState sysBeauticianState = new SysBeauticianState();
        sysBeauticianState.setPuseId(sysProjUse.getId());
        sysBeauticianState.setProjUse(sysProjUse);
        sysBeauticianState.setCount(1);
        sysBeauticianState.setBeginTime(yyTime);
        int timeLength=30;
        if(sysProjUse.getTimeLength()!=null){
            timeLength=sysProjUse.getTimeLength();
        }
        sysBeauticianState.setEndTime(DateUtil.getDateAfterMinute(yyTime, timeLength));
        if(onlinebooking.getStaffId()!=null){
            sysBeauticianState.setStaffId(Long.parseLong(onlinebooking.getStaffId()+""));
        }
 
        sysBeauticianStates.add(sysBeauticianState);
        sysProjServices.setServiceItems(sysBeauticianStates);
 
        //检测欠款
        VerifyResult arrearsVerifyResult = projServicesService.checkArrears(sysProjServices);
        if (arrearsVerifyResult.isError()) {
            return new AjaxResult(AjaxResult.STATUS_FAIL, arrearsVerifyResult.getMsg());
        }
        //检测余次
        VerifyResult balanceverifyResult = projServicesService.checkBalance(sysProjServices);
        if (balanceverifyResult.isError()) {
            return new AjaxResult(AjaxResult.STATUS_FAIL, balanceverifyResult.getMsg());
        }
        sysProjServices.setState(Dictionary.SERVICE_STATU_DQR);
        SysProjServices newSysProjServices = projServicesService.addSysProjServices(sysProjServices);
        if (newSysProjServices != null) {
 
            //添加用户积分
            BusParameterSettings parameterSetting = busParameterSettingsDao.selectCompanyParamByCode(ScoreSettingConstant.RESERVATION_SERVICE_SHOP, sysVipInfo.getCompanyId());
            scoreVipDetailService.addScoreByParamSetting(sysVipInfo.getId(), null,null, newSysProjServices.getId(),
                    ScoreVipDetail.SCORE_VIP_TYPE_JOIN_ACTIVE,"预约送积分", parameterSetting);
 
 
            return AjaxResult.buildSuccessInstance("下单成功");
        } else {
            return new AjaxResult(AjaxResult.STATUS_FAIL, "下单失败!");
        }
    }
 
 
    /**
     * 根据id查询预约订单的详情
     *
     * @param id
     * @return
     */
    @ApiOperation(value = " 根据id查询预约订单的详情", notes = " 根据id查询预约订单的详情")
    @ApiResponses({
            @ApiResponse(code = 200, message = "ok", response = ErpServiceOrderListVo.class)
    })
    @RequestMapping(value = "/getServiceOrderById/{id}")
    public @ResponseBody
    AjaxResult getServiceOrderById(@PathVariable("id") Long id) {
        SysProjServices projServices = projServicesService.findById(id);
        if (projServices == null) {
            return AjaxResult.buildFailInstance("服务单不存在");
        }
        ErpServiceOrderListVo serviceOrder = projServicesDao.findWxServiceOrderById(id);
        AjaxResult ajaxResult = AjaxResult.buildSuccessInstance("获取成功");
        ajaxResult.putInMap("detail", serviceOrder);
        return ajaxResult;
    }
 
 
 
    /**
     * 查询服务单
     * @param orderListDto
     * @return
     */
    @ApiOperation(value = "查询服务单列表", notes = "查询服务单列表")
    @ApiResponses({
            @ApiResponse(code = 200, message = "ok", response = ErpServiceOrderListVo.class)
    })
    @PostMapping(value = "/getServiceOrderList")
    @ResponseBody
    public AjaxResult findServiceOrderList(@RequestBody @Validated ErpServiceOrderListDto orderListDto) {
        SysVipInfo sysVipInfo = redisUserLoginUtils.getLoginUser(SysVipInfo.class);
        orderListDto.setVipId(sysVipInfo.getId());
        List<ErpServiceOrderListVo> apiServiceOrderListInPage = projServicesDao.findWxServiceOrderList(orderListDto);
        return AjaxResult.buildSuccessInstance(apiServiceOrderListInPage,"查询成功");
    }
 
    /**
     * 取消预约订单
     *
     * @param
     * @return
     */
    @ApiOperation(value = "取消预约", notes = "取消预约")
    @GetMapping(value = "/cancelOrderById/{id}")
    public @ResponseBody
    AjaxResult cancelOrderById(@PathVariable Long id) {
        SysProjServices services = new SysProjServices();
        services.setId(id);
        int i = projServicesService.modifyCancelProjServices(services);
        if (i > 0) {
            return new AjaxResult(AjaxResult.STATUS_SUCCESS, "取消预约成功");
        } else {
            return new AjaxResult(AjaxResult.STATUS_FAIL, "取消预约失败");
        }
    }
 
 
    @ApiOperation(value = "服务单评论", notes = "服务单评论")
    @PostMapping(value = "/commentService")
    public @ResponseBody
    AjaxResult commentService(@RequestBody @Validated ErpServiceCommentDto commentDto) {
        SysProjServices services = new SysProjServices();
        services.setId(commentDto.getId());
        services.setComment(commentDto.getComment());
        int i = projServicesDao.update(services);
        if (i > 0) {
            return new AjaxResult(AjaxResult.STATUS_SUCCESS, "评论成功");
        } else {
            return new AjaxResult(AjaxResult.STATUS_FAIL, "评论失败");
        }
    }
 
 
 
 
 
}