Showing
1 changed file
with
239 additions
and
0 deletions
业务分享/商品模块SQL和业务逻辑.md
0 → 100644
1 | +>#product项目# | ||
2 | +> | ||
3 | +>文档中只涉及数据库的相关查询逻辑,并未包含缓存的相关内容,具体请查询业务代码。 | ||
4 | +> | ||
5 | +>##CommentController 评论## | ||
6 | +>###查询商品的最新评论 | ||
7 | +>1、**yh\_comment** <br> | ||
8 | +> `select * from comments where element_id=? and comment_type=1 and status=1 order by create_time desc limit 1` | ||
9 | +> | ||
10 | +>###分页查询商品评论 | ||
11 | +>1、**yh\_comment** <br> | ||
12 | +>`select * from comments where element_id=? comment_type=1 and status=1 order by create_time desc limit ?,?` <br> | ||
13 | +>2、**yoho\_passport** 查询用户昵称<br> | ||
14 | +>`select * from user_base where uid = #{uid} limit 1` | ||
15 | +> | ||
16 | +> | ||
17 | +>##ConsultController 咨询 | ||
18 | +>###查询咨询总数 | ||
19 | +>1、**yh_passport** | ||
20 | +> | ||
21 | +>`select count(1) from consult where product_id =? and answer_user_id > 0` | ||
22 | +> | ||
23 | +>###查询商品最新咨询 | ||
24 | +>1、**yh_passport**<br> | ||
25 | +>` select * from consult where product_id =? and answer_user_id > 0 order by id DESC limit 1` | ||
26 | +> | ||
27 | +>###分页查询咨询 | ||
28 | +>1、**yh_passport**<br> | ||
29 | +>`select * from consult where product_id =? and answer_user_id > 0 order by id DESC limit ?,?` | ||
30 | +> | ||
31 | +>###查询是咨询列表否点赞喜欢、有用 | ||
32 | +>1、数据存储在redis中 | ||
33 | +><table> | ||
34 | +> <tr> | ||
35 | +> <td>"yh:like:id:" + consultId</td> | ||
36 | +> <td>咨询被喜欢次数</td> | ||
37 | +> </tr> | ||
38 | +> <tr> | ||
39 | +> <td>"yh:useful:id:" + consultId</td> | ||
40 | +> <td>咨询被用户点有用次数</td> | ||
41 | +> </tr> | ||
42 | +> <tr> | ||
43 | +> <td>"yh:like:id:" + consultId+":"+uid</td> | ||
44 | +> <td>该用户是否喜该咨询</td> | ||
45 | +> </tr> | ||
46 | +> <tr> | ||
47 | +> <td>"yh:useful:id:" + consultId+":"+uid</td> | ||
48 | +> <td>该用户是否对该咨询点有用</td> | ||
49 | +> </tr> | ||
50 | +></table> | ||
51 | +> | ||
52 | +>###新增咨询 | ||
53 | +>1、**yh\_shops** 查询product是否存在根据商品id。<br> | ||
54 | +>`select * from product where id=?` | ||
55 | +>不存在直接抛异常,中断执行。 | ||
56 | +> | ||
57 | +>2、**yh\_passport** 插入咨询表 <br> | ||
58 | +> `insert into consult values()` | ||
59 | +> | ||
60 | +>###咨询点赞接口 | ||
61 | +>1、判断是否已经点赞 <br> | ||
62 | +> 从redis中取:"yh:like:id:" + consultId+":"+uid 判断用户是否已经点赞,已经点赞直接返回。<br> | ||
63 | +>2、增加redis中key为:"yh:like:id:" + consultId。 咨询的点赞的总数。<br> | ||
64 | +>3、增加redis中key为:"yh:like:id:" + consultId+":"+uid的值为1,标示已点赞<br> | ||
65 | +>4、**yh\_consult** 异步记录点赞表<br> | ||
66 | +> a:`select count(1) from consult_praise_$(consultId%100) where where consult_id=? and uid=?` 判断是否已经点赞,已经点赞,直接返回 <br> | ||
67 | +> b:`insert into consult_praise_$(consultId%100) (consult_id,uid,create_time) values(?,?,?)` | ||
68 | +> | ||
69 | +> | ||
70 | +>###咨询有用接口 | ||
71 | +>1、判断用户是否已经点击有用<br> | ||
72 | +> 从redis中取:"yh:useful:id:" + consultId+":"+uid 判断用户是否已经点击有用,已经点击则直接返回。<br> | ||
73 | +>2、增加redis中key为:"yh:useful:id:" + consultId。咨询的有用总数。<br> | ||
74 | +>3、增加redis中key为:"yh:useful:id:" + consultId+":"+uid;的值为1,标示该用户已经点击有用。<br> | ||
75 | +>4、**yh\_consult** 异步记录点有用<br> | ||
76 | +> a:`select count(1) from consult_useful_$(consultId%100) where consult_id=? and uid=?` 判断用户是否已经点击有用,已经点有用,直接返回<br> | ||
77 | +> b:` insert into consult_useful_$(consultId%100) (consult_id,uid,create_time) values(?,?,?)` 插入用户点击有用表。 | ||
78 | +> | ||
79 | +>##CouponsController | ||
80 | +>###根据品牌Id查询品牌及优惠券相关信息 | ||
81 | +>1、缓存中查询品牌相关信息,品牌不存在直接返回。 | ||
82 | +>2、**yhb\_promotion** <br> | ||
83 | +> `select coupons_id from brand_coupons where status=2 and brand_id =? order by update_time desc,create_time desc` | ||
84 | +>3、**yhb\_promotion** <br> | ||
85 | +> ` select * from coupons where id in ()` | ||
86 | +> | ||
87 | +>##KeywordsController | ||
88 | +>###搜索关键词及平台记录接口 | ||
89 | +>1、异步插入表 `yh_shops.search_keywords` 表,平台编号 | ||
90 | +> <table> | ||
91 | +> <tr><td>pc</td><td>1</td></tr> | ||
92 | +> <tr><td>mobile</td><td>2</td></tr> | ||
93 | +> <tr><td>h5</td><td>3</td></tr> | ||
94 | +> <tr><td>ipad</td><td>4</td></tr> | ||
95 | +> </table> | ||
96 | + | ||
97 | +> | ||
98 | +> | ||
99 | +>##LimitProductController 限量商品Controller ## | ||
100 | +>###查询已经发布的限量商品 ### | ||
101 | +>1. 查询限量销售商品 | ||
102 | +>`select * from yh_shops.limit_product where 1=1 and status=1 and sale_time < UNIX_TIMESTAMP()order by sale_time DESC` | ||
103 | +>2. 查询限量销售商品关联商品 | ||
104 | +>`select * from yh_shops.limit_product_attach where product_id in()` | ||
105 | +>3. 封装关联关系并缓存 | ||
106 | +>4. 根据商品skn(erp_product_id)查询商品ID | ||
107 | +> `select * from yh_shops.product where erp_product_id in()` <br> | ||
108 | +>5. 根据商品id查询商品价格 | ||
109 | +> `select * from yh_shops.product_price where product_id in()` | ||
110 | +>6. 封装并返回结果 | ||
111 | +> | ||
112 | +>### 查询热门发售的限量商品 ### | ||
113 | +>1. 查询限量热门商品 | ||
114 | +> ` select * from yh_shops.limit_product where 1=1 and hotFlag=1 and status=1 order by order_by DESC` | ||
115 | +> (备注:区别于已经发布的是限量商品查询条件) | ||
116 | +>2. 查询限量销售商品关联商品 | ||
117 | +> `select * from yh_shops.limit_product_attach where product_id in()` | ||
118 | +>(备注:limit_product_attach表中的product_id实际是limit_product表中的id,而不是商品表中的Id) | ||
119 | +>3. 封装限量销售商品和附件的关联关系并缓存。 | ||
120 | +>4. 根据商品skn(erp_product_id)查询商品ID | ||
121 | +> `select * from yh_shops.product where erp_product_id in()` <br> | ||
122 | +>5. 根据商品id查询商品价格 | ||
123 | +> `select * from yh_shops.product_price where product_id in()` | ||
124 | +> | ||
125 | +>###查询即将发售的限量商品### | ||
126 | +>1. 查询即将发售的限量商品 | ||
127 | +> `select * from yh_shops.limit_product where 1=1 and status=1 and showFlag=1 and sale_time > UNIX_TIMESTAMP() order by order_by DESC,sale_time ASC;` | ||
128 | +>2. 查询限量销售商品关联商品 | ||
129 | +> `select * from yh_shops.limit_product_attach where product_id in()` | ||
130 | +>(备注:limit_product_attach表中的product_id实际是limit_product表中的id,而不是商品表中的Id) | ||
131 | +>3. 封装限量销售商品和附件的关联关系并缓存。 | ||
132 | +>4. 根据商品skn(erp_product_id)查询商品ID | ||
133 | +> `select * from yh_shops.product where erp_product_id in()` <br> | ||
134 | +>5. 根据商品id查询商品价格 | ||
135 | +> `select * from yh_shops.product_price where product_id in()` | ||
136 | +> | ||
137 | +>###根据限量商品code获取限量商品详情### | ||
138 | +>1. 根据商品code查询限量商品 | ||
139 | +> `select * from yh_shops.limit_product where code =? and status=1` | ||
140 | +> | ||
141 | +>2. 查询限量销售商品关联商品 | ||
142 | +> `select * from yh_shops.limit_product_attach where product_id in()` | ||
143 | +>(备注:limit_product_attach表中的product_id实际是limit_product表中的id,而不是商品表中的Id) | ||
144 | +> | ||
145 | +>3. 封装限量销售商品和附件的关联关系并缓存。 | ||
146 | +>4. 根据商品skn(erp_product_id)查询商品ID | ||
147 | +> `select * from yh_shops.product where erp_product_id in()` <br> | ||
148 | +>5. 根据商品id查询商品价格 | ||
149 | +> `select * from yh_shops.product_price where product_id in()` | ||
150 | +> | ||
151 | +>###根据活动ID查询限量商品### | ||
152 | +>1.根据活动ID查询限量商品 | ||
153 | +>`select * form yh_shops.limit_product where activityId=? and status=1` | ||
154 | +>2. 查询限量销售商品关联商品 | ||
155 | +> `select * from yh_shops.limit_product_attach where product_id in()` | ||
156 | +>(备注:limit_product_attach表中的product_id实际是limit_product表中的id,而不是商品表中的Id) | ||
157 | +> | ||
158 | +> | ||
159 | +>###批量根据限量商品code获取限量商品详情### | ||
160 | +>1. 根据商品code列表查询商品详情 | ||
161 | +> | ||
162 | +> select * from yh_shops.limit_product where code in () | ||
163 | +> | ||
164 | +>2. 查询限量商品关联的商品 | ||
165 | +> `select * from yh_shops.limit_product_attach where product_id in()` | ||
166 | +>3. 封装限量销售商品和附件的关联关系并缓存。 | ||
167 | +>4. 根据商品skn(erp_product_id)查询商品ID | ||
168 | +> `select * from yh_shops.product where erp_product_id in()` <br> | ||
169 | +>5. 根据商品id查询商品价格 | ||
170 | +> `select * from yh_shops.product_price where product_id in()` | ||
171 | +>###已经发售的商品总数### | ||
172 | +>1. 查询已经发售的商品总数 | ||
173 | +>`select count(1) from yh_shops.limit_product where sale_time<UNIX_TIMESTAMP() and status=1` | ||
174 | +> | ||
175 | +> | ||
176 | +>###热门发售商品的发售总数### | ||
177 | +>1. 查询热门发售商品的发售总数 | ||
178 | +> `select count(1) from yh_shops.limit_product where hotFlag=1 and status=1` | ||
179 | +> | ||
180 | +>###即将发售的商品总数## | ||
181 | +>1.查询即将发售的商品总数 | ||
182 | +>> `select count(1) from yh_shops.limit_product where sale_time>UNIX_TIMESTAMP() and status=1 and showFlag=1` | ||
183 | +> | ||
184 | +>###给后台提供的新增限量商品### | ||
185 | +> | ||
186 | +> 1. 校验限量商品是否存在 | ||
187 | +> `select * from yh_shops.limit_product where code=?` | ||
188 | +> 2. 插入限量商品 | ||
189 | +> `insert into yh_shops.limit_product values();` | ||
190 | +> 3. | ||
191 | +> | ||
192 | + | ||
193 | + | ||
194 | + | ||
195 | + | ||
196 | + | ||
197 | + | ||
198 | + | ||
199 | + | ||
200 | + | ||
201 | + | ||
202 | + | ||
203 | + | ||
204 | + | ||
205 | + | ||
206 | + | ||
207 | +#promotion模块 | ||
208 | + | ||
209 | +##CouponController | ||
210 | +###发送优惠券 flag=1支持重复发送### | ||
211 | +1. 检查用户是否已经领取过优惠券 | ||
212 | +> select count(1) from yhb_promotion.coupons_logs where uid=8038725 and coupon_id=11759; | ||
213 | + | ||
214 | +2. 检查券是否存在 | ||
215 | +> select * from yhb_promotion.coupons where id= 11759; | ||
216 | + | ||
217 | +3. 查询券类型是否存在 | ||
218 | + | ||
219 | +> select * from yhb_promotion.coupon_type ; | ||
220 | + | ||
221 | +4. 判断yhb_promotion.coupons.custom_type 是否存在,存在需要校验用户的会员级别等信息 | ||
222 | + | ||
223 | +5. 查询一个可用的优惠券 | ||
224 | +> select * from yhb_promotion.coupons_sn where is_use="N" limit 1; | ||
225 | +> select * from yhb_promotion.a_coupons_sn where is_use="N" limit 1; | ||
226 | +> select * from yhb_promotion.b_coupons_sn where is_use="N" limit 1; | ||
227 | + | ||
228 | +6. 增加券的领用记录(包括用户id,是否重复领用标记,券号等) | ||
229 | + | ||
230 | +> insert into yhb_promotion.coupons_logs value(); | ||
231 | +7. 缓存中增加券的领用数量,并设置用户的领券状态 | ||
232 | + | ||
233 | +8. 记录用户领券同步表(用户id,券号等) | ||
234 | + | ||
235 | +>insert into yhb_promotion.user_coupon_logs_sync value(); | ||
236 | + | ||
237 | + | ||
238 | + | ||
239 | + |
-
Please register or login to post a comment