Forráskód Böngészése

完善关闭赛事即单人退款流程

Memory_LG 5 hónapja
szülő
commit
5424e1d20f

+ 9 - 25
qmjszx-admin/src/main/java/beilv/web/controller/competition/CompetitionController.java

@@ -129,11 +129,18 @@ public class CompetitionController extends BaseController {
        return toAjax(competitionService.publishCompetitionById(id));
     }
 
+    /**
+     * 关闭赛事
+     * @param id
+     * @return
+     */
     @RequiresPermissions("system:competition:publish")
     @GetMapping("/close")
     @ResponseBody
     public AjaxResult close(String id){
-        return toAjax(competitionService.closeCompetitionById(id));
+        int i = competitionService.closeCompetitionById(id);
+        System.out.println("i = " + i);
+        return toAjax(i);
     }
 
     @GetMapping("/getCompetitionList")
@@ -145,31 +152,8 @@ public class CompetitionController extends BaseController {
     @RequiresPermissions("system:competition:view")
     @GetMapping("/openDetails/{id}")
     public String openDetails(@PathVariable("id") Integer id, ModelMap mmap) {
-        mmap.put("id", id);
+        mmap.put("competitionId", id);
         return prefix + "/details";
     }
 
-    /**
-     * 修改赛事发布
-     */
-    @PostMapping("/getTakePartList")
-    @ResponseBody
-    public TableDataInfo getTakePartList(Competition competition) {
-
-        startPage();
-        //通过id获取参赛集合
-        List<Stadium> stadiumList = competitionService.getTakePartList(competition.getId());
-        return getDataTable(stadiumList);
-        /*List<Stadium> takePartList = stadiumList.stream()
-                .filter(stadium -> Objects.equals(stadium.getOrderType(), "1"))
-                .collect(Collectors.toList());
-
-        List<Stadium> watchList = stadiumList.stream()
-                .filter(stadium -> Objects.equals(stadium.getOrderType(), "2"))
-                .collect(Collectors.toList());
-
-        mmap.put("takePartList", takePartList);
-        mmap.put("watchList", watchList);
-        return prefix + "/detail";*/
-    }
 }

+ 27 - 0
qmjszx-admin/src/main/java/beilv/web/controller/stadium/StadiumController.java

@@ -2,15 +2,19 @@ package beilv.web.controller.stadium;
 
 import beilv.common.core.controller.BaseController;
 import beilv.common.core.domain.AjaxResult;
+import beilv.common.core.page.TableDataInfo;
 import beilv.common.utils.uuid.IdUtils;
+import beilv.competition.domain.Competition;
 import beilv.stadium.domain.Stadium;
 import beilv.stadium.domain.StadiumBO;
 import beilv.stadium.service.IStadiumService;
+import org.apache.shiro.authz.annotation.RequiresPermissions;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.web.bind.annotation.*;
 
 import java.text.SimpleDateFormat;
 import java.util.Date;
+import java.util.List;
 
 @RestController
 @RequestMapping("/stadium")
@@ -77,4 +81,27 @@ public class StadiumController extends BaseController {
     public Boolean paymentVerification(@RequestBody Stadium stadium){
         return stadiumService.paymentVerification(stadium);
     }
+
+    /**
+     * 查询购票记录
+     */
+    @PostMapping("/getTakePartList")
+    @ResponseBody
+    public TableDataInfo getTakePartList(Stadium stadium) {
+        startPage();
+        //通过id获取参赛集合
+        List<Stadium> stadiumList = stadiumService.getTakePartList(stadium);
+        return getDataTable(stadiumList);
+    }
+
+    /**
+     * 针对某个购票记录进行退票处理
+     * @param id 购票记录id
+     * @return
+     */
+    @GetMapping("/close")
+    @ResponseBody
+    public AjaxResult closeStadiumById(String id){
+        return toAjax(stadiumService.closeStadiumById(id));
+    }
 }

+ 0 - 14
qmjszx-admin/src/main/resources/templates/competition/competition.html

@@ -153,20 +153,6 @@
         $.table.init(options);
     });
 
-    function closeCompetition(id){
-        $.ajax({
-            url: prefix + "/close",
-            type: "GET",
-            data: {id:id},
-            success: function(res){
-                alert(res)
-            },
-            error: function(err){
-                alert(err)
-            }
-        })
-    }
-
     function getTakePartList(id){
         $.modal.open("参赛人员名单", prefix+"/openDetails/"+id);
     }

+ 82 - 22
qmjszx-admin/src/main/resources/templates/competition/details.html

@@ -5,8 +5,40 @@
 </head>
 <body class="gray-bg">
 <div class="container-div">
-    <input type="hidden" name="id" th:value="${id}"/>
     <div class="row">
+        <div class="col-sm-12 search-collapse">
+            <form id="formId">
+                <div class="select-list">
+                    <ul>
+                        <li>
+                            <input type="hidden" name="competitionId" id="competitionId" th:value="${competitionId}"/>
+                        </li>
+                        <li>
+                            <label>门票类型:</label>
+                            <select name="orderType">
+                                <option value="1" selected>报名门票</option>
+                                <option value="2">观看门票</option>
+                            </select>
+                        </li>
+                        <li>
+                            <a class="btn btn-primary btn-rounded btn-sm" onclick="$.table.search()">
+                                <i class="fa fa-search"></i>&nbsp;
+                                搜索
+                            </a>
+                            <a class="btn btn-warning btn-rounded btn-sm" onclick="$.form.reset()">
+                                <i class="fa fa-refresh"></i>&nbsp;
+                                重置
+                            </a>
+                            <a class="btn btn-warning btn-rounded btn-sm" onclick="closeCompetition()">
+                                <i class="fa fa-search"></i>&nbsp;
+                                关闭赛事
+                            </a>
+                        </li>
+                    </ul>
+                </div>
+            </form>
+        </div>
+
         <div class="col-sm-12 select-table table-striped">
             <table id="bootstrap-table"></table>
         </div>
@@ -15,19 +47,12 @@
 <th:block th:include="include :: footer"/>
 <script th:inline="javascript">
     var paymentStatus = [[${@dict.getType('payment_status')}]];
-    var prefix = ctx + "competition";
+    var prefix = ctx + "stadium";
 
     $(function () {
-        var id = $("input[name='id']").val();
         var options = {
-            id: id,
             url: prefix + "/getTakePartList",
-            modalName: "赛事",
             columns: [{
-                field: 'id',
-                title: 'id',
-                visible: false
-            }, {
                 field: 'contactPerple',
                 title: '联系人'
             }, {
@@ -51,30 +76,65 @@
                 formatter: function (value, row, index) {
                     return $.table.selectDictLabel(paymentStatus, value);
                 }
-            },
-            /*{
+            }, {
                 title: '操作',
                 align: 'center',
                 formatter: function (value, row, index) {
                     var actions = [];
-                    if (row.competitionState === 'competiton_state_1') {
-                        actions.push('<a class="btn btn-success btn-xs ' + publisFlag + '" href="javascript:void(0)" onclick="$.operate.publish(\'' + row.id + '\', \'' + row.competitionTitle + '\')"><i class="fa fa-edit"></i>发布</a> ')
-                        actions.push('<a class="btn btn-success btn-xs ' + editFlag + '" href="javascript:void(0)" onclick="$.operate.editToSet(\'' + row.id + '\')"><i class="fa fa-edit"></i>编辑</a> ');
-                        actions.push('<a class="btn btn-danger btn-xs ' + removeFlag + '" href="javascript:void(0)" onclick="$.operate.remove(\'' + row.id + '\')"><i class="fa fa-remove"></i>删除</a>');
-                    } else if (row.competitionState === 'competiton_state_4') {
-
-                    } else {
-                        actions.push('<a class="btn btn-success btn-xs ' + editFlag + '" href="javascript:void(0)" onclick="getTakePartList(\'' + row.id + '\')"><i class="fa fa-edit"></i>参赛名单</a> ')
-                        // actions.push('<a class="btn btn-success btn-xs ' + publisFlag + '" href="javascript:void(0)" onclick="closeCompetition(\'' + row.id + '\')"><i class="fa fa-close"></i>关闭</a> ')
+                    // if (row.competitionState === 'competiton_state_1')
+                    if(row.paymentStatus === 'payment_status_have_paid'){
+                        actions.push('<a class="btn btn-success btn-xs" href="javascript:void(0)" onclick="closeStadium(\'' + row.id + '\')"><i class="fa fa-close"></i>退款</a> ')
                     }
+
                     return actions.join('');
                 }
-            }*/
-            ]
+            }]
         };
         $.table.init(options);
     });
 
+    function closeStadium(id){
+        $.ajax({
+            url: prefix + "/close",
+            type: "GET",
+            data: {id:id},
+            success: function(res){
+                if(res.code === 0){
+                    $.modal.msgSuccess("操作成功");
+                    $.table.refresh();
+                }else{
+                    $.modal.msgSuccess("未知异常! 请联系管理员处理! ")
+                }
+            },
+            error: function(err){
+                $.modal.msgSuccess("系统发生了错误, 请及时联系管理员进行处理! ")
+            }
+        })
+    }
+
+    function closeCompetition(){
+        var competitionId = $("#competitionId").val();
+        $.ajax({
+            url: ctx + "competition/close",
+            type: "GET",
+            data: {id: competitionId},
+            success: function(res){
+                console.log(res)
+                if(res.code === 0){
+                    var parent = activeWindow();
+                    $.modal.close();
+                    parent.$.modal.msgSuccess(res.msg);
+                    parent.$.table.refresh();
+                }else{
+                    $.modal.alertWarning("还存在未退款的订单! 不可以关闭赛事! ");
+                }
+            },
+            error: function(err){
+                $.modal.msgSuccess("系统发生了错误, 请及时联系管理员进行处理! ")
+            }
+        })
+    }
+
 </script>
 </body>
 </html>

+ 1 - 0
qmjszx-business/src/main/java/beilv/competition/mapper/CompetitionMapper.java

@@ -64,4 +64,5 @@ public interface CompetitionMapper {
 
     List<Competition> getCompetitionList();
 
+    boolean selectStadumIsOpenById(String id);
 }

+ 0 - 1
qmjszx-business/src/main/java/beilv/competition/service/ICompetitionService.java

@@ -67,5 +67,4 @@ public interface ICompetitionService {
 
     List<Competition> getCompetitionList();
 
-    List<Stadium> getTakePartList(Integer id);
 }

+ 13 - 10
qmjszx-business/src/main/java/beilv/competition/service/impl/CompetitionServiceImpl.java

@@ -118,20 +118,23 @@ public class CompetitionServiceImpl implements ICompetitionService {
 
     @Override
     public int closeCompetitionById(String id) {
-        //修改赛事状态
-        Competition competition = new Competition();
-        competition.setId(Integer.valueOf(id));
-        competition.setCompetitionState(YI_GUAN_BI);
-        return competitionMapper.publishCompetition(competition);
+
+        //查询是否存在为退款的订单
+        if(competitionMapper.selectStadumIsOpenById(id)){
+            //修改赛事状态
+            Competition competition = new Competition();
+            competition.setId(Integer.valueOf(id));
+            competition.setCompetitionState(YI_GUAN_BI);
+            return competitionMapper.publishCompetition(competition);
+        }else{
+            return 0;
+        }
+
+
     }
 
     @Override
     public List<Competition> getCompetitionList() {
         return competitionMapper.getCompetitionList();
     }
-
-    @Override
-    public List<Stadium> getTakePartList(Integer id) {
-        return stadiumMapper.getTakePartList(id);
-    }
 }

+ 3 - 1
qmjszx-business/src/main/java/beilv/stadium/mapper/StadiumMapper.java

@@ -18,5 +18,7 @@ public interface StadiumMapper {
 
     boolean paymentVerification(Stadium stadium);
 
-    List<Stadium> getTakePartList(@Param("competitionId")Integer id);
+    List<Stadium> getTakePartList(Stadium stadium);
+
+    int closeStadiumById(Stadium stadium);
 }

+ 4 - 0
qmjszx-business/src/main/java/beilv/stadium/service/IStadiumService.java

@@ -18,4 +18,8 @@ public interface IStadiumService {
     int havePaidStadium(Stadium stadium);
 
     Boolean paymentVerification(Stadium stadium);
+
+    List<Stadium> getTakePartList(Stadium stadium);
+
+    int closeStadiumById(String id);
 }

+ 19 - 0
qmjszx-business/src/main/java/beilv/stadium/service/impl/StadiumServiceImpl.java

@@ -83,4 +83,23 @@ public class StadiumServiceImpl implements IStadiumService {
         System.out.println("flag = " + flag);
         return flag;
     }
+
+    @Override
+    public List<Stadium> getTakePartList(Stadium stadium) {
+        return stadiumMapper.getTakePartList(stadium);
+    }
+
+    @Override
+    public int closeStadiumById(String id) {
+        //发起退票
+
+        //修改购票状态
+        Stadium stadium = new Stadium();
+        stadium.setId(Long.parseLong(id));
+        //设置订单状态
+        stadium.setPaymentStatus("payment_status_refunded");
+        //设置退款时间
+        stadium.setRefundTime(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date()));
+        return stadiumMapper.closeStadiumById(stadium);
+    }
 }

+ 13 - 0
qmjszx-business/src/main/resources/mapper/competition/CompetitionMapper.xml

@@ -159,4 +159,17 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
         select * from beilv_competition where competition_state = 'competiton_state_2'
     </select>
 
+    <select id="selectStadumIsOpenById" parameterType="string" resultType="boolean">
+        SELECT
+            CASE
+                WHEN COUNT(1) > 0 THEN false
+                ELSE true
+                END AS result
+        FROM
+            beilv_book_a_race
+        WHERE
+            payment_status = 'payment_status_have_paid'
+          AND competition_id = #{id}
+    </select>
+
 </mapper>

+ 14 - 2
qmjszx-business/src/main/resources/mapper/stadium/StadiumMapper.xml

@@ -90,10 +90,22 @@
                 (SELECT COUNT(id) AS isPay FROM beilv_book_a_race WHERE competition_id = #{competitionId} AND (payment_status = 'payment_status_have_paid' OR payment_status = 'payment_status_to_be_paid	')  and order_type = '1') b;
     </select>
 
-    <select id="getTakePartList" parameterType="integer" resultMap="StadiumResult">
+    <select id="getTakePartList" parameterType="stadium" resultMap="StadiumResult">
         select * from beilv_book_a_race
-        where competition_id = #{competitionId}
+        <where>
+            <if test="competitionId != null and competitionId != ''">
+                and competition_id = #{competitionId}
+            </if>
+            <if test="orderType != null and orderType != ''">
+                and order_type = #{orderType}
+            </if>
+        </where>
         order by registration_time desc
     </select>
 
+    <update id="closeStadiumById" parameterType="Stadium">
+        update beilv_book_a_race set payment_status = #{paymentStatus}, refund_time = #{refundTime}
+        where id = #{id}
+    </update>
+
 </mapper>