peter
2025-07-16 076a457c7c7d005075aa8247ee0b214e94418786
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
package com.yami.trading.admin.controller.c2c;
 
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.yami.trading.admin.controller.c2c.model.*;
import com.yami.trading.bean.c2c.C2cOrder;
import com.yami.trading.bean.model.C2cPaymentMethod;
import com.yami.trading.bean.model.User;
import com.yami.trading.common.constants.Constants;
import com.yami.trading.common.domain.Result;
import com.yami.trading.common.exception.YamiShopBindException;
import com.yami.trading.common.util.C2cOrderLock;
import com.yami.trading.common.util.StringUtils;
import com.yami.trading.common.util.ThreadUtils;
import com.yami.trading.security.common.util.SecurityUtils;
import com.yami.trading.service.c2c.C2cAdvertService;
import com.yami.trading.service.c2c.C2cOrderService;
import com.yami.trading.service.chat.otc.OtcOnlineChatMessageService;
import com.yami.trading.service.item.ItemService;
import com.yami.trading.service.rate.ExchangeRateService;
import com.yami.trading.service.user.UserService;
import com.yami.trading.sys.service.SysUserService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
 
import javax.validation.Valid;
import java.util.*;
 
@RestController
@Api(tags = "后台C2C订单")
@RequestMapping("c2cOrder")
public class C2cOrderController {
 
    @Autowired
    protected ExchangeRateService exchangeRateService;
    @Autowired
    protected ItemService itemService;
    @Autowired
    protected C2cOrderService adminC2cOrderService;
    @Autowired
    protected OtcOnlineChatMessageService otcOnlineChatMessageService;
    @Autowired
    protected C2cOrderService c2cOrderService;
    @Autowired
    protected SysUserService sysUserService;
    @Autowired
    protected UserService partyService;
    @Autowired
    protected C2cAdvertService c2cAdvertService;
 
    @Autowired
    UserService userService;
//
//    private final String action = "normal/adminC2cOrderAction!";
//
    /**
     * 获取 C2C订单 列表
     */
    @PostMapping( "list")
    @ApiOperation("获取 C2C订单 列表")
    public Result list(@RequestBody @Valid C2cOrderListModel model) {
         String secUuid = "";
//            String userNameLogin = this.getUsername_login();
//            if (null != userNameLogin) {
//                SecUser sec = this.secUserService.findUserByLoginName(userNameLogin);
//                Set<Role> roles = sec.getRoles();
//                Iterator<Role> it = roles.iterator();
//                while (it.hasNext()) {
//                    Role role = (Role) it.next();
//                    if (role.getRoleName().equals("C2C")) {
//                        secUuid = sec.getId().toString();
//                        break;
//                    }
//                }
//            }
 
        List<String> list = new ArrayList<>();
        if (StringUtils.isNotEmpty(model.getDirection())) {
            list.add(model.getDirection());
        } else {
            list.add("buy");
            list.add("sell");
        }
            Page page = c2cOrderService.pagedQuery(model.getCurrent(), model.getSize(), model.getStatus(),
                    model.getOrder_no(), model.getUser_code(),
                    model.getRolename(), model.getC2c_user_code(),
                    model.getC2c_user_type(), model.getC2c_user_party_code(), list, null);
 
            Map<String, String> pmtMap = this.c2cAdvertService.getC2cSyspara("c2c_payment_method_type");
 
            List<String> nos = new ArrayList<String>();
            for (Map<String, Object> map : (List<Map<String, Object>>) page.getRecords()) {
                nos.add(map.get("order_no").toString());
                String methodType = String.valueOf((Integer) map.get("method_type"));
                map.put("method_type_name", pmtMap.containsKey(methodType) ? pmtMap.get(methodType) : methodType);
            }
            String order_nos = String.join(",", nos);
 
            Map<String, Integer> unreadMsgs = this.otcOnlineChatMessageService.unreadMsgs(nos);
 
            for (Map<String, Object> map : (List<Map<String, Object>>) page.getRecords()) {
                String orderNo = map.get("order_no").toString();
                if(unreadMsgs.containsKey(orderNo)) {
                    map.put("unread_msg", unreadMsgs.get(orderNo));
                }
 
                if (null == map.get("rolename")) {
                    map.put("roleNameDesc", "");
                } else {
                    String roleName = map.get("rolename").toString();
                    map.put("roleNameDesc", Constants.ROLE_MAP.containsKey(roleName) ? Constants.ROLE_MAP.get(roleName) : roleName);
                }
            }
        return Result.succeed(page.getRecords());
    }
 
    /**
     * 手动放行
     */
    @PostMapping(  "orderPass")
    public Result orderPass(@RequestBody @Valid C2cOrderPassModel model) {
        String order_no = model.getOrder_no();
        String safeword = model.getSafeword();
        boolean lock = false;
        try {
 
            if (!C2cOrderLock.add(order_no)) {
                throw new YamiShopBindException("系统繁忙,请稍后重试");
            }
            lock = true;
 
            C2cOrder order = this.c2cOrderService.get(order_no);
            if (null == order) {
                throw new YamiShopBindException("订单不存在");
            }
 
            sysUserService.checkSafeWord(safeword);
            adminC2cOrderService.savePass(order, safeword,SecurityUtils.getSysUser().getUsername());
            ThreadUtils.sleep(100);
 
        } catch (YamiShopBindException e) {
            e.printStackTrace();
        }finally {
            if (lock) {
                C2cOrderLock.remove(order_no);
            }
        }
 
        return Result.succeed();
    }
 
    /**
     * 取消订单
     * <p>
     * remark 取消理由
     */
    @PostMapping("orderCancel")
    @ApiOperation("取消订单")
    public Result orderCancel(@RequestBody @Valid C2cOrderCancelModel model) {
 
        String order_no = model.getOrder_no();
        String remark = model.getRemark();
        C2cOrder order = c2cOrderService.get(order_no);
        if (null == order) {
            throw new YamiShopBindException("订单不存在");
        }
        order.setRemark("订单号:" + order.getOrderNo() + "管理员取消订单:" + remark);
        this.c2cOrderService.saveOrderCancel(order, "manager");
        return Result.succeed();
    }
 
    /**
     * 手动转账
     */
    @PostMapping("orderPay")
    public Result orderPay(@RequestBody @Valid C2cOrderPayModel  model) {
        String order_no = model.getOrder_no();
        String payment_method_id_order_pay = model.getPayment_method_id_order_pay();
        String safeword = model.getSafeword();
        sysUserService.checkSafeWord(safeword);
        adminC2cOrderService.saveOrderPay(order_no, safeword, SecurityUtils.getSysUser().getUsername(), payment_method_id_order_pay);
        return Result.succeed();
    }
 
    /**
     * 获取 订单的支付方式
     */
    @PostMapping( "getOrderPayments")
    @ApiOperation("获取 订单的支付方式")
    public Result getOrderPayments(@RequestBody @Valid GetOrderPaymentsModel model) {
        String order_no =model.getOrder_no();
        Map<String, Object> resultMap = new HashMap<String, Object>();
            List<C2cPaymentMethod> methodList =adminC2cOrderService.getOrderPayments(order_no,true);
 
            resultMap.put("code", 200);
            resultMap.put("payments", methodList);
        return Result.succeed(resultMap);
    }
 
    /**
     * 获取 C2C订单 详情
     */
    @PostMapping( "detail")
    @ApiOperation("获取 C2C订单 详情")
    public Result detail(@RequestBody @Valid GetOrderPaymentsModel request) {
        String order_no =request.getOrder_no();
            C2cOrder order = this.c2cOrderService.get(order_no);
            if (null == order) {
                throw new YamiShopBindException("订单不存在");
            }
            Map<String, Object> detail_map =adminC2cOrderService.detail(order);
            User user = userService.getById(order.getPartyId());
            detail_map.put("username", user.getUserName());
        return Result.succeed(detail_map);
    }
 
}