|
package io.renren.modules.app.controller;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;
import java.util.Map;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestAttribute;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.bind.annotation.PathVariable;
import io.renren.common.utils.R;
import io.renren.modules.admin.entity.AttendersEntity;
import io.renren.modules.admin.entity.PaymentEntity;
import io.renren.modules.admin.service.AttendersService;
import io.renren.modules.admin.service.PaymentService;
import io.renren.modules.app.annotation.Login;
import io.renren.modules.app.annotation.LoginUser;
import io.renren.modules.app.entity.UserEntity;
import io.renren.modules.app.form.PaymentForm;
import io.renren.modules.admin.entity.TypesOfFeeEntity;
import io.renren.modules.admin.service.TypesOfFeeService;
import io.renren.modules.admin.entity.MoneyAccountEntity;
import io.renren.modules.admin.service.MoneyAccountService;
/**
* @author chenshun
* @email sunlightcs@gmail.com
* @date 2020-02-21 15:10:27
*/
@RestController
@RequestMapping("app/order")
public class AppOrderController {
@Autowired
private AttendersService attendersService;
@Autowired
private PaymentService paymentService;
@Autowired
private TypesOfFeeService typesOfFeeService;
@Autowired
private MoneyAccountService moneyAccountService;
/**
* 订单列表
*/
@Login
@GetMapping("/list")
public R list(@RequestAttribute("userId") Integer userId){
Long memberId = Long.valueOf(userId);
List<Map<String, Object>> orderList = paymentService.queryOrderListByMemberId(memberId);
return R.ok().put("orderList", orderList);
}
/**
* 获取注册类型列表
*/
@GetMapping("/feelist/{mid}")
public R feeList(@PathVariable("mid") Long mid){
List<TypesOfFeeEntity> feeList = typesOfFeeService.list(
new QueryWrapper<TypesOfFeeEntity>().eq("meeting_id", mid));
return R.ok().put("feeList", feeList);
}
/**
* 根据meetingId信息获取对公账号
* @param mid
* @return
*/
@GetMapping("/accountinfo/{mid}")
public R accountInfoByMid(@PathVariable("mid") Long mid){
MoneyAccountEntity moneyAccount = moneyAccountService.getOneByMeetingId(mid);
return R.ok().put("moneyAccount", moneyAccount);
}
/**
* 保存
*/
@Login
@PostMapping("/save")
public R save(@RequestBody Map<String, Object> params, @LoginUser UserEntity user){
Long meetingId = 0L;
if (params.containsKey("meetingId")) {
meetingId = Long.valueOf(params.get("meetingId").toString());
} else {
return R.error("会议id 不可为空");
}
AttendersEntity attendersEntity = new AttendersEntity();
attendersEntity.setMeetingId(meetingId);
attendersEntity.setMemberId(user.getUserId());
attendersEntity.setName(user.getTruename());
attendersEntity.setPhone(user.getPhone());
attendersEntity.setOrganization(user.getOrganization());
attendersEntity.setEmail(user.getEmail());
Integer room = params.containsKey("room") ? Integer.valueOf(params.get("room").toString()) : 0 ;
attendersEntity.setRoom(room);
Integer transfer = params.containsKey("transfer") ? Integer.valueOf(params.get("transfer").toString()) : 0 ;
attendersEntity.setTransfer(transfer);
attendersEntity.setCreateTime(new Date());
boolean res = attendersService.save(attendersEntity);
if (!res) {
return R.error("未知错误");
}
// System.out.println(attendersEntity.getId());
// 付款信息
PaymentEntity paymentEntity = new PaymentEntity();
SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMddhhmmss");
String nowtime = sdf.format(new Date());
// System.out.println(time);
Integer fourRandom = Integer.valueOf((int)((Math.random()*9+1)*1000));
paymentEntity.setOrderId("FY" + nowtime + fourRandom);
paymentEntity.setMeetingId(meetingId);
paymentEntity.setAttendersId(attendersEntity.getId());
Long feeId = params.containsKey("feeId") ? Long.valueOf(params.get("feeId").toString()) : 0L ;
paymentEntity.setFeeId(feeId);
paymentEntity.setPayType(1);
Integer taxType = params.containsKey("taxType") ? Integer.valueOf(params.get("taxType").toString()) : 0;
paymentEntity.setTaxType(taxType);
String taxTitle = params.containsKey("taxTitle") ? params.get("taxTitle").toString() : "";
paymentEntity.setTaxTitle(taxTitle);
String taxNumber = params.containsKey("taxNumber") ? params.get("taxNumber").toString() : "";
paymentEntity.setTaxNumber(taxNumber);
String addPhone = params.containsKey("addPhone") ? params.get("addPhone").toString() : "";
paymentEntity.setAddrPhone(addPhone);
String bankAddrAccount = params.containsKey("bankAddrAccount") ? params.get("bankAddrAccount").toString() : "";
paymentEntity.setBankAddrAccount(bankAddrAccount);
String taxAddress = params.containsKey("taxAddress") ? params.get("taxAddress").toString() : "";
paymentEntity.setTaxAddress(taxAddress);
paymentEntity.setCreateTime(new Date());
try {
paymentService.save(paymentEntity);
} catch (Exception e) {
attendersService.removeById(attendersEntity.getId());
e.printStackTrace();
return R.error("订单生成出错");
}
return R.ok();
}
/**
* 根据订单编号获取订单信息
* @param orderId
* @return
*/
@GetMapping("/infobyorderid/{orderId}")
public R infoByOrderId(@PathVariable("orderId") String orderId){
Map<String, Object> orderInfo = paymentService.queryOrderInfoByOrderId(orderId);
return R.ok().put("orderInfo", orderInfo);
}
/**
* 根据订单id获取缴费信息
* @param id
* @return
*/
@Login
@GetMapping("/payinfo/{id}")
public R payInfo(@PathVariable("id") Long id){
PaymentEntity payInfo = paymentService.getById(id);
return R.ok().put("payInfo", payInfo);
}
/**
* 修改开票信息
* @param payment
* @return
*/
@Login
@PostMapping("/updatetax")
public R updateTaxInfo(@RequestBody PaymentForm payment){
PaymentEntity paymentEntity = new PaymentEntity();
paymentEntity.setId(payment.getId());
paymentEntity.setTaxType(payment.getTaxType());
paymentEntity.setTaxTitle(payment.getTaxTitle());
paymentEntity.setTaxNumber(payment.getTaxNumber());
paymentEntity.setAddrPhone(payment.getAddrPhone());
paymentEntity.setBankAddrAccount(payment.getBankAddrAccount());
paymentEntity.setTaxAddress(payment.getTaxAddress());
paymentService.updateById(paymentEntity);
return R.ok();
}
// /**
// * 删除
// */
// @Login
// @PostMapping("/delete")
// public R delete(@RequestBody Long[] ids){
// attendersService.removeByIds(Arrays.asList(ids));
// return R.ok();
// }
}
|