1 | const Response = require('../../util/response') |
||
2 | const ModelCustomer = require('../../model/catering/customer') |
||
3 | const ModelSeller = require('../../model/catering/seller') |
||
4 | const ModelStore = require('../../model/catering/store') |
||
5 | const ApiError = require('../../util/api_error') |
||
6 | const _ = require('underscore') |
||
7 | |||
8 | module.exports = { |
||
9 | |||
10 | /** |
||
11 | * @api {post} /api/catering/v1/audits/:uid/sellers/:sellerId 审核商家 |
||
12 | * @apiVersion 1.0.0 |
||
13 | * @apiGroup audit |
||
14 | * @apiPermission audit |
||
15 | * |
||
16 | * @apiDescription 分销人员审核商家,默认给商家开一个店铺 |
||
17 | * |
||
18 | * |
||
19 | * @apiSuccess {String} data response data |
||
20 | * |
||
21 | * @apiSuccessExample {json} Visual Preview: |
||
22 | { |
||
23 | "success": true, |
||
24 | "code": 200, |
||
25 | "data": { |
||
26 | "seller_id": "1", |
||
27 | "name": "新视觉烧烤", |
||
28 | "thumb": "https://wx.qlogo.cn/mmopen/vi_32/DYAIOgq83eo13vc2RhqKyJI8f5qaGCcj2ZeRfic696O0a2PDZvJ2JrGL8ia8EJHA6KjR37ia2neD11IBcNJ4HianZg/132", |
||
29 | "tel": "234", |
||
30 | "address": "12", |
||
31 | "id": 1 |
||
32 | }, |
||
33 | "message": "请求成功" |
||
34 | } |
||
35 | * @apiSampleRequest https://garylv.com/api/catering/v1/audits/:uid/sellers/:sellerId |
||
36 | */ |
||
37 | seller: async function (ctx) { |
||
38 | |||
39 | let sellerInfo = await ModelSeller.first(ctx.params.sellerId) |
||
40 | if (_.isEmpty(sellerInfo)) { |
||
41 | throw new ApiError('common.notExist', '商家') |
||
42 | } |
||
43 | if (sellerInfo.approve_status == 1) throw new ApiError('audit.hadPass') |
||
0 ignored issues
–
show
|
|||
44 | |||
45 | let storeData = { |
||
46 | seller_id: ctx.params.sellerId, |
||
47 | name: sellerInfo.company, |
||
48 | thumb: sellerInfo.avatar, |
||
49 | tel: sellerInfo.tel, |
||
50 | address: sellerInfo.address, |
||
51 | } |
||
52 | |||
53 | let updateSeller = { |
||
54 | approve_status: 1 |
||
55 | } |
||
56 | |||
57 | let [data, u1] = await Promise.all([ |
||
58 | ModelStore.add(storeData), |
||
59 | ModelSeller.edit(updateSeller, { seller_id: ctx.params.sellerId }), |
||
60 | ]) |
||
61 | storeData.id = data.insertId |
||
62 | |||
63 | let updateCustomer = { |
||
64 | default_store: storeData.id |
||
65 | } |
||
66 | await ModelCustomer.edit(updateCustomer, { id: ctx.params.sellerId }) |
||
67 | |||
68 | return Response.output(ctx, storeData) |
||
69 | |||
70 | }, |
||
71 | |||
72 | } |
Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.
Consider:
If you or someone else later decides to put another statement in, only the first statement will be executed.
In this case the statement
b = 42
will always be executed, while the logging statement will be executed conditionally.ensures that the proper code will be executed conditionally no matter how many statements are added or removed.