前端 + 后端:支付界面~
							parent
							
								
									3a27ae5d96
								
							
						
					
					
						commit
						0b35a92b01
					
				| 
						 | 
					@ -0,0 +1,24 @@
 | 
				
			||||||
 | 
					import request from "../config/request";
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					export function getTransaction(appId, orderId) {
 | 
				
			||||||
 | 
					  return request({
 | 
				
			||||||
 | 
					    url: '/pay-api/users/transaction/get',
 | 
				
			||||||
 | 
					    method: 'get',
 | 
				
			||||||
 | 
					    params: {
 | 
				
			||||||
 | 
					      appId,
 | 
				
			||||||
 | 
					      orderId
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					  });
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					export function submitTransaction(appId, orderId, payChannel) {
 | 
				
			||||||
 | 
					  return request({
 | 
				
			||||||
 | 
					    url: '/pay-api/users/transaction/submit',
 | 
				
			||||||
 | 
					    method: 'post',
 | 
				
			||||||
 | 
					    params: {
 | 
				
			||||||
 | 
					      appId,
 | 
				
			||||||
 | 
					      orderId,
 | 
				
			||||||
 | 
					      payChannel
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					  });
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
| 
						 | 
					@ -21,11 +21,11 @@ const serviceRouter = function(requestUrl) {
 | 
				
			||||||
      },
 | 
					      },
 | 
				
			||||||
      '/promotion-api': {
 | 
					      '/promotion-api': {
 | 
				
			||||||
        prefix: '/promotion-api',
 | 
					        prefix: '/promotion-api',
 | 
				
			||||||
        target: 'http://127.0.0.1:18085//promotion-api',
 | 
					        target: 'http://127.0.0.1:18085/promotion-api',
 | 
				
			||||||
      },
 | 
					      },
 | 
				
			||||||
      '/pay-api': {
 | 
					      '/pay-api': {
 | 
				
			||||||
        prefix: '/pay-api',
 | 
					        prefix: '/pay-api',
 | 
				
			||||||
        target: 'http://127.0.0.1:18084//promotion-api',
 | 
					        target: 'http://127.0.0.1:18084/pay-api',
 | 
				
			||||||
      },
 | 
					      },
 | 
				
			||||||
    };
 | 
					    };
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -48,7 +48,7 @@ const serviceRouter = function(requestUrl) {
 | 
				
			||||||
      },
 | 
					      },
 | 
				
			||||||
      '/pay-api': {
 | 
					      '/pay-api': {
 | 
				
			||||||
        prefix: '/pay-api',
 | 
					        prefix: '/pay-api',
 | 
				
			||||||
        target: 'http://api.shop.iocoder.cn:18099/promotion-api',
 | 
					        target: 'http://api.shop.iocoder.cn:18099/pay-api',
 | 
				
			||||||
      },
 | 
					      },
 | 
				
			||||||
    };
 | 
					    };
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -203,6 +203,13 @@ const routes = [
 | 
				
			||||||
    meta: {
 | 
					    meta: {
 | 
				
			||||||
      title: '优惠劵领取'
 | 
					      title: '优惠劵领取'
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					  },
 | 
				
			||||||
 | 
					  {
 | 
				
			||||||
 | 
					    path: '/pay',
 | 
				
			||||||
 | 
					    component: () => import('../page/pay/index'),
 | 
				
			||||||
 | 
					    meta: {
 | 
				
			||||||
 | 
					      title: '收银台'
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
];
 | 
					];
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -1,50 +1,46 @@
 | 
				
			||||||
<template>
 | 
					<template>
 | 
				
			||||||
    <div>
 | 
					    <div>
 | 
				
			||||||
 | 
					        <headerNav title="收银台"/>
 | 
				
			||||||
        <van-cell-group>
 | 
					        <van-cell-group>
 | 
				
			||||||
            <van-cell title="优惠劵编号" :value="couponTemplate.id" />
 | 
					            <van-cell title="订单商品名" :value="transaction.orderSubject" />
 | 
				
			||||||
            <van-cell title="优惠劵名" :value="couponTemplate.title"/>
 | 
					            <van-cell title="价格" :value="transaction.price / 100.0" />
 | 
				
			||||||
        </van-cell-group>
 | 
					        </van-cell-group>
 | 
				
			||||||
        <van-button slot="button" size="small" type="primary" @click="onFetchClick">领取优惠劵</van-button>
 | 
					        <van-button slot="button" size="small" type="primary" @click="submit(9999)">模拟支付</van-button>
 | 
				
			||||||
    </div>
 | 
					    </div>
 | 
				
			||||||
</template>
 | 
					</template>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
<script>
 | 
					<script>
 | 
				
			||||||
  import { getCouponTemplate, doAddCouponCard } from '../../api/promotion';
 | 
					  import { getTransaction, submitTransaction } from '../../api/pay';
 | 
				
			||||||
 | 
					  import pingpp from 'pingpp-js';
 | 
				
			||||||
  import { Dialog } from 'vant';
 | 
					  import { Dialog } from 'vant';
 | 
				
			||||||
  import { setLoginToken } from '../../utils/cache';
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
  export default {
 | 
					  export default {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    data() {
 | 
					    data() {
 | 
				
			||||||
      return {
 | 
					      return {
 | 
				
			||||||
        couponTemplate: {
 | 
					        appId: this.$route.query.appId,
 | 
				
			||||||
        }
 | 
					        orderId: this.$route.query.orderId,
 | 
				
			||||||
 | 
					        transaction: {},
 | 
				
			||||||
      }
 | 
					      }
 | 
				
			||||||
    },
 | 
					    },
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    mounted() {
 | 
					    mounted() {
 | 
				
			||||||
      let id = this.$route.query.id;
 | 
					      let response = getTransaction(this.appId, this.orderId);
 | 
				
			||||||
      let response = getCouponTemplate(id);
 | 
					 | 
				
			||||||
      response.then(data => {
 | 
					      response.then(data => {
 | 
				
			||||||
        this.couponTemplate = data;
 | 
					        this.transaction = data;
 | 
				
			||||||
      });
 | 
					      });
 | 
				
			||||||
    },
 | 
					    },
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    methods: {
 | 
					    methods: {
 | 
				
			||||||
      onFetchClick: function () {
 | 
					      submit(payChannel) {
 | 
				
			||||||
        let that = this;
 | 
					        let that = this;
 | 
				
			||||||
        let id = this.$route.query.id;
 | 
					        debugger;
 | 
				
			||||||
        let response = doAddCouponCard(id);
 | 
					        submitTransaction(this.appId, this.orderId, payChannel).then(data => {
 | 
				
			||||||
        response.then(data => {
 | 
					          pingpp.createPayment(data.invokeResponse, function(result, err) {
 | 
				
			||||||
          Dialog.alert({
 | 
					            debugger;
 | 
				
			||||||
            title: '系统提示',
 | 
					            console.log(result);
 | 
				
			||||||
            message: '领取成功',
 | 
					            console.log(err.msg);
 | 
				
			||||||
            beforeClose: function (action, done) {
 | 
					            console.log(err.extra);
 | 
				
			||||||
              // 关闭弹窗
 | 
					 | 
				
			||||||
              done();
 | 
					 | 
				
			||||||
              // 跳转到我的优惠劵
 | 
					 | 
				
			||||||
              that.$router.push('/user/coupon');
 | 
					 | 
				
			||||||
            }
 | 
					 | 
				
			||||||
          });
 | 
					          });
 | 
				
			||||||
        });
 | 
					        });
 | 
				
			||||||
      }
 | 
					      }
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -38,7 +38,9 @@
 | 
				
			||||||
              <van-button v-if="[3,4,5].indexOf(item.status) != -1" size="small">查看物流</van-button>
 | 
					              <van-button v-if="[3,4,5].indexOf(item.status) != -1" size="small">查看物流</van-button>
 | 
				
			||||||
            </router-link>
 | 
					            </router-link>
 | 
				
			||||||
            <van-button v-if="item.status === 3 " size="small" v-on:click="clickConfirmReceiving(item)">确认收货</van-button>
 | 
					            <van-button v-if="item.status === 3 " size="small" v-on:click="clickConfirmReceiving(item)">确认收货</van-button>
 | 
				
			||||||
            <van-button v-if="item.status === 1 " size="small" type="danger">支付</van-button>
 | 
					            <van-button v-if="item.status === 1 " size="small" type="danger" @click="goPay(item.orderid)">
 | 
				
			||||||
 | 
					                    支付
 | 
				
			||||||
 | 
					            </van-button>
 | 
				
			||||||
          </div>
 | 
					          </div>
 | 
				
			||||||
        </van-panel>
 | 
					        </van-panel>
 | 
				
			||||||
      </van-cell-group>
 | 
					      </van-cell-group>
 | 
				
			||||||
| 
						 | 
					@ -60,6 +62,10 @@
 | 
				
			||||||
      }
 | 
					      }
 | 
				
			||||||
    },
 | 
					    },
 | 
				
			||||||
    methods: {
 | 
					    methods: {
 | 
				
			||||||
 | 
					      goPay(itemId) {
 | 
				
			||||||
 | 
					        this.$router.push('/pay?appId=POd4RC6a&orderId=' + itemId);
 | 
				
			||||||
 | 
					      },
 | 
				
			||||||
 | 
					
 | 
				
			||||||
      onTabChange(index) {
 | 
					      onTabChange(index) {
 | 
				
			||||||
        // status 和 tab index 对应的关系
 | 
					        // status 和 tab index 对应的关系
 | 
				
			||||||
        const statusArray = [null, 1, 3, 4, 5];
 | 
					        const statusArray = [null, 1, 3, 4, 5];
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -27,6 +27,11 @@
 | 
				
			||||||
            <artifactId>admin-sdk</artifactId>
 | 
					            <artifactId>admin-sdk</artifactId>
 | 
				
			||||||
            <version>1.0-SNAPSHOT</version>
 | 
					            <version>1.0-SNAPSHOT</version>
 | 
				
			||||||
        </dependency>
 | 
					        </dependency>
 | 
				
			||||||
 | 
					        <dependency>
 | 
				
			||||||
 | 
					            <groupId>cn.iocoder.mall</groupId>
 | 
				
			||||||
 | 
					            <artifactId>user-sdk</artifactId>
 | 
				
			||||||
 | 
					            <version>1.0-SNAPSHOT</version>
 | 
				
			||||||
 | 
					        </dependency>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        <dependency>
 | 
					        <dependency>
 | 
				
			||||||
            <groupId>org.springframework.boot</groupId>
 | 
					            <groupId>org.springframework.boot</groupId>
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -3,15 +3,14 @@ package cn.iocoder.mall.pay.application.controller.users;
 | 
				
			||||||
import cn.iocoder.common.framework.util.HttpUtil;
 | 
					import cn.iocoder.common.framework.util.HttpUtil;
 | 
				
			||||||
import cn.iocoder.common.framework.vo.CommonResult;
 | 
					import cn.iocoder.common.framework.vo.CommonResult;
 | 
				
			||||||
import cn.iocoder.mall.pay.api.PayTransactionService;
 | 
					import cn.iocoder.mall.pay.api.PayTransactionService;
 | 
				
			||||||
 | 
					import cn.iocoder.mall.pay.api.bo.PayTransactionBO;
 | 
				
			||||||
import cn.iocoder.mall.pay.api.bo.PayTransactionSubmitBO;
 | 
					import cn.iocoder.mall.pay.api.bo.PayTransactionSubmitBO;
 | 
				
			||||||
import cn.iocoder.mall.pay.api.constant.PayChannelEnum;
 | 
					import cn.iocoder.mall.pay.api.constant.PayChannelEnum;
 | 
				
			||||||
import cn.iocoder.mall.pay.api.dto.PayTransactionSubmitDTO;
 | 
					import cn.iocoder.mall.pay.api.dto.PayTransactionSubmitDTO;
 | 
				
			||||||
 | 
					import cn.iocoder.mall.user.sdk.context.UserSecurityContextHolder;
 | 
				
			||||||
import com.alibaba.dubbo.config.annotation.Reference;
 | 
					import com.alibaba.dubbo.config.annotation.Reference;
 | 
				
			||||||
import org.springframework.http.MediaType;
 | 
					import org.springframework.http.MediaType;
 | 
				
			||||||
import org.springframework.web.bind.annotation.PostMapping;
 | 
					import org.springframework.web.bind.annotation.*;
 | 
				
			||||||
import org.springframework.web.bind.annotation.RequestMapping;
 | 
					 | 
				
			||||||
import org.springframework.web.bind.annotation.RequestParam;
 | 
					 | 
				
			||||||
import org.springframework.web.bind.annotation.RestController;
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
import javax.servlet.http.HttpServletRequest;
 | 
					import javax.servlet.http.HttpServletRequest;
 | 
				
			||||||
import java.io.BufferedReader;
 | 
					import java.io.BufferedReader;
 | 
				
			||||||
| 
						 | 
					@ -24,6 +23,12 @@ public class PayTransactionController {
 | 
				
			||||||
    @Reference(validation = "true")
 | 
					    @Reference(validation = "true")
 | 
				
			||||||
    private PayTransactionService payService;
 | 
					    private PayTransactionService payService;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    @GetMapping("/get")
 | 
				
			||||||
 | 
					    public CommonResult<PayTransactionBO> get(@RequestParam("appId") String appId,
 | 
				
			||||||
 | 
					                                              @RequestParam("orderId") String orderId) {
 | 
				
			||||||
 | 
					        return payService.getTransaction(UserSecurityContextHolder.getContext().getUserId(), appId, orderId);
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    @PostMapping("/submit") // TODO api 注释
 | 
					    @PostMapping("/submit") // TODO api 注释
 | 
				
			||||||
    // TODO result 后面改下
 | 
					    // TODO result 后面改下
 | 
				
			||||||
    public CommonResult<PayTransactionSubmitBO> submit(HttpServletRequest request,
 | 
					    public CommonResult<PayTransactionSubmitBO> submit(HttpServletRequest request,
 | 
				
			||||||
| 
						 | 
					@ -56,4 +61,4 @@ public class PayTransactionController {
 | 
				
			||||||
        return result.isSuccess() ? "success" : "failure";
 | 
					        return result.isSuccess() ? "success" : "failure";
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -8,6 +8,8 @@ import cn.iocoder.mall.pay.api.dto.PayTransactionSubmitDTO;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
public interface PayTransactionService {
 | 
					public interface PayTransactionService {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    CommonResult<PayTransactionBO> getTransaction(Integer userId, String appId, String orderId);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    CommonResult<PayTransactionBO> createTransaction(PayTransactionCreateDTO payTransactionCreateDTO);
 | 
					    CommonResult<PayTransactionBO> createTransaction(PayTransactionCreateDTO payTransactionCreateDTO);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    CommonResult<PayTransactionSubmitBO> submitTransaction(PayTransactionSubmitDTO payTransactionSubmitDTO);
 | 
					    CommonResult<PayTransactionSubmitBO> submitTransaction(PayTransactionSubmitDTO payTransactionSubmitDTO);
 | 
				
			||||||
| 
						 | 
					@ -26,4 +28,4 @@ public interface PayTransactionService {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    CommonResult cancelTransaction(); // TODO 1. params 2. result
 | 
					    CommonResult cancelTransaction(); // TODO 1. params 2. result
 | 
				
			||||||
 | 
					
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -14,9 +14,9 @@ public enum PayErrorCodeEnum {
 | 
				
			||||||
    // ========== TRANSACTION 模块 ==========
 | 
					    // ========== TRANSACTION 模块 ==========
 | 
				
			||||||
    PAY_TRANSACTION_NOT_FOUND(100401000, "支付交易单不存在"),
 | 
					    PAY_TRANSACTION_NOT_FOUND(100401000, "支付交易单不存在"),
 | 
				
			||||||
    PAY_TRANSACTION_STATUS_IS_NOT_WAITING(100401001, "支付交易单不处于待支付"),
 | 
					    PAY_TRANSACTION_STATUS_IS_NOT_WAITING(100401001, "支付交易单不处于待支付"),
 | 
				
			||||||
 | 
					 | 
				
			||||||
    PAY_TRANSACTION_EXTENSION_NOT_FOUND(100401002, "支付交易拓展单不存在"),
 | 
					    PAY_TRANSACTION_EXTENSION_NOT_FOUND(100401002, "支付交易拓展单不存在"),
 | 
				
			||||||
    PAY_TRANSACTION_EXTENSION_STATUS_IS_NOT_WAITING(100401003, "支付交易拓展单不处于待支付"),
 | 
					    PAY_TRANSACTION_EXTENSION_STATUS_IS_NOT_WAITING(100401003, "支付交易拓展单不处于待支付"),
 | 
				
			||||||
 | 
					    PAY_TRANSACTION_ERROR_USER(100401004, "支付交易单用户不正确"),
 | 
				
			||||||
    ;
 | 
					    ;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    private final int code;
 | 
					    private final int code;
 | 
				
			||||||
| 
						 | 
					@ -35,4 +35,4 @@ public enum PayErrorCodeEnum {
 | 
				
			||||||
        return message;
 | 
					        return message;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -53,6 +53,16 @@ public class PayServiceImpl implements PayTransactionService {
 | 
				
			||||||
    @Resource
 | 
					    @Resource
 | 
				
			||||||
    private RocketMQTemplate rocketMQTemplate;
 | 
					    private RocketMQTemplate rocketMQTemplate;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    @Override
 | 
				
			||||||
 | 
					    public CommonResult<PayTransactionBO> getTransaction(Integer userId, String appId, String orderId) {
 | 
				
			||||||
 | 
					        PayTransactionDO payTransaction = payTransactionMapper.selectByAppIdAndOrderId(appId, orderId);
 | 
				
			||||||
 | 
					        if (payTransaction == null) {
 | 
				
			||||||
 | 
					            return ServiceExceptionUtil.error(PayErrorCodeEnum.PAY_TRANSACTION_NOT_FOUND.getCode());
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					        // TODO 芋艿 userId 的校验
 | 
				
			||||||
 | 
					        return CommonResult.success(PayTransactionConvert.INSTANCE.convert(payTransaction));
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    @Override
 | 
					    @Override
 | 
				
			||||||
    @SuppressWarnings("Duplicates")
 | 
					    @SuppressWarnings("Duplicates")
 | 
				
			||||||
    public CommonResult<PayTransactionBO> createTransaction(PayTransactionCreateDTO payTransactionCreateDTO) {
 | 
					    public CommonResult<PayTransactionBO> createTransaction(PayTransactionCreateDTO payTransactionCreateDTO) {
 | 
				
			||||||
| 
						 | 
					@ -205,4 +215,4 @@ public class PayServiceImpl implements PayTransactionService {
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
		Reference in New Issue