ShopMapper.xml 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384
  1. <?xml version="1.0" encoding="UTF-8" ?>
  2. <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
  3. <mapper namespace="com.caimei.mapper.cmMapper.ShopMapper">
  4. <insert id="insertStatementFile" keyColumn="id" keyProperty="id" useGeneratedKeys="true" parameterType="com.caimei.model.po.CmBrandAuthFilePo">
  5. insert into cm_brand_auth_file (`authUserId`, `brandId`, `name`, `ossName`, `md5Hex`, `uploadTime`)
  6. values (#{authUserId}, #{brandId}, #{name}, #{ossName}, #{md5Hex}, #{uploadTime})
  7. </insert>
  8. <insert id="insertShop" keyColumn="authUserId" keyProperty="authUserId" useGeneratedKeys="true" parameterType="com.caimei.model.po.UserPo">
  9. insert into cm_brand_auth_user (`name`, `mobile`, `password`, `linkMan`, `userIdentity`, `shopType`, `logo`, `qrCodeImage`, `wxAccountType`, `appId`, `appSecret`, `createTime`,
  10. `createBy`,`status`)
  11. values (#{name}, #{mobile}, #{password}, #{linkMan}, #{userIdentity}, #{shopType}, #{logo}, #{qrCodeImage}, #{wxAccountType}, #{appId}, #{appSecret}, #{createTime}, #{createBy}, #{status});
  12. </insert>
  13. <insert id="insertShopInfo">
  14. insert into cm_brand_auth_shop_info
  15. <trim prefix="(" suffix=")" suffixOverrides=",">
  16. authUserId,brandId,countryId,securityLink,
  17. <if test="statementType != null">
  18. statementType,
  19. </if>
  20. <if test="statementContent != null and statementContent != ''">
  21. statementContent,
  22. </if>
  23. <if test="statementLink != null and statementLink != ''">
  24. statementLink,
  25. </if>
  26. <if test="statementImage != null and statementImage != ''">
  27. statementImage,
  28. </if>
  29. </trim>
  30. <trim prefix="values (" suffix=")" suffixOverrides=",">
  31. #{authUserId},#{brandId},#{countryId},#{securityLink},
  32. <if test="statementType != null">
  33. #{statementType},
  34. </if>
  35. <if test="statementContent != null and statementContent != ''">
  36. #{statementContent},
  37. </if>
  38. <if test="statementLink != null and statementLink != ''">
  39. #{statementLink},
  40. </if>
  41. <if test="statementImage != null and statementImage != ''">
  42. #{statementImage},
  43. </if>
  44. </trim>
  45. </insert>
  46. <update id="updateShopStatusByUserId">
  47. update cm_brand_auth_user
  48. set status = #{status}
  49. where authUserId = #{authUserId};
  50. </update>
  51. <update id="updateBrandAuthLogo">
  52. update cm_brand
  53. set authLogo = #{brandAuthLogo}
  54. where id = #{brandId}
  55. </update>
  56. <update id="updateFileUserId">
  57. update cm_brand_auth_file
  58. set authUserId =#{authUserId}
  59. where id = #{statementFileId};
  60. </update>
  61. <update id="updateShopByUserId">
  62. update cm_brand_auth_user
  63. set `mobile` = #{mobile},
  64. `linkMan` = #{linkMan},
  65. `status` = #{status},
  66. `logo` = #{logo},
  67. `qrCodeImage` = #{qrCodeImage},
  68. `wxAccountType` = #{wxAccountType},
  69. `appId` = #{appId},
  70. `appSecret` = #{appSecret}
  71. where authUserId = #{authUserId}
  72. </update>
  73. <update id="updateShopInfo">
  74. update cm_brand_auth_shop_info
  75. <set>
  76. countryId=#{countryId},securityLink = #{securityLink},
  77. <if test="statementType != null">
  78. statementType = #{statementType},
  79. </if>
  80. <if test="statementContent != null and statementContent != ''">
  81. statementContent = #{statementContent},
  82. </if>
  83. <if test="statementLink != null and statementLink != ''">
  84. statementLink = #{statementLink},
  85. </if>
  86. <if test="statementImage != null and statementImage != ''">
  87. statementImage = #{statementImage},
  88. </if>
  89. </set>
  90. where authUserId = #{authUserId} and brandId = #{brandId}
  91. </update>
  92. <update id="handleFeedback">
  93. update cm_brand_club_feedback
  94. set handleResult = #{handleResult},
  95. handleStatus = 1,
  96. handleTime = NOW()
  97. where id = #{feedbackId}
  98. </update>
  99. <update id="updateShopMobile">
  100. update cm_brand_auth_user
  101. set mobile = #{newMobile}
  102. where authUserId = #{authUserId}
  103. </update>
  104. <update id="bindLoginAccount">
  105. update cm_brand_auth_user
  106. set loginAccount = #{loginAccount}
  107. where authUserId = #{authUserId}
  108. </update>
  109. <delete id="deleteStatementFile">
  110. delete from cm_brand_auth_file where id = #{id}
  111. </delete>
  112. <delete id="deleteShopInfoById">
  113. delete from cm_brand_auth_shop_info where id = #{infoId}
  114. </delete>
  115. <select id="getShopList" resultType="com.caimei.model.vo.ShopListVo">
  116. select u.authUserId,u.name,u.loginAccount,u.shopType,group_concat(cb.name) as brandName,group_concat(cb.id) as brandId,
  117. u.mobile,u.linkMan,u.status as shopStatus,u.createTime,
  118. (select au.name from cm_brand_auth_user au where au.authUserId = u.createBy) as createBy,
  119. (ifnull(aw.authWaitNum,0)+ifnull(pw.productWaitNum,0)) as waitAuditNum,
  120. ifnull(arw.articleWaitNum,0) as articleWaitNum,
  121. ifnull(iw.imageWaitNum,0) as imageWaitNum,
  122. ifnull(vw.videoWaitNum,0) as videoWaitNum,
  123. ifnull(fw.fileWaitNum,0) as fileWaitNum,
  124. ifnull(zw.zipWaitNum,0) as zipWaitNum,
  125. ifnull(dw.doctorWaitNum,0) as doctorWaitNum,
  126. ifnull(tw.productTypeWaitNum,0) as productTypeWaitNum
  127. from cm_brand_auth_user u
  128. left join cm_brand_auth_shop_info s on u.authUserId = s.authUserId
  129. left join cm_brand cb on cb.id = s.brandId
  130. left join (select authUserId, count(*) as authWaitNum from cm_brand_auth where auditStatus = 2 and shopAuditStatus = 1 group by authUserId) aw on u.authUserId = aw.authUserId
  131. left join (select a.authUserId, count(*) as productWaitNum from cm_brand_auth_product p left join cm_brand_auth a on p.authId = a.id
  132. where p.auditStatus = 2 and p.shopAuditStatus = 1 group by a.authUserId) pw on u.authUserId = pw.authUserId
  133. left join (select authUserId, count(*) as articleWaitNum from cm_brand_article where auditStatus = 2 group by authUserId) arw on u.authUserId = arw.authUserId
  134. left join (select authUserId, count(*) as imageWaitNum from cm_brand_image where auditStatus = 2 group by authUserId) iw on u.authUserId = iw.authUserId
  135. left join (select authUserId, count(*) as videoWaitNum from cm_brand_video where auditStatus = 2 group by authUserId) vw on u.authUserId = vw.authUserId
  136. left join (select authUserId, count(*) as fileWaitNum from cm_brand_file where auditStatus = 2 and fileType = 1 group by authUserId) fw on u.authUserId = fw.authUserId
  137. left join (select authUserId, count(*) as zipWaitNum from cm_brand_file where auditStatus = 2 and fileType = 2 group by authUserId) zw on u.authUserId = zw.authUserId
  138. left join (select authUserId, count(*) as doctorWaitNum from cm_brand_doctor where auditStatus = 2 group by authUserId) dw on u.authUserId = dw.authUserId
  139. left join (select authUserId, count(*) as productTypeWaitNum from cm_brand_product_type where auditStatus = 2 group by authUserId) tw on u.authUserId = tw.authUserId
  140. left join (select authUserId, count(*) as waitSendNum from cm_brand_auth where auditStatus = 2 and sendStatus = 0 group by authUserId) sw on u.authUserId = sw.authUserId
  141. where u.userIdentity = 2
  142. <if test="shopName != null and shopName !=''">
  143. AND u.name like CONCAT('%',#{shopName},'%')
  144. </if>
  145. <if test="listType == 5">
  146. AND u.status = 1
  147. </if>
  148. <if test="loginAccount != null and loginAccount != ''">
  149. AND u.loginAccount like CONCAT('%',#{loginAccount},'%')
  150. </if>
  151. <if test="shopType != null ">
  152. AND u.shopType = #{shopType}
  153. </if>
  154. <if test="brandId != null">
  155. AND s.brandId = #{brandId}
  156. </if>
  157. <if test="mobile != null and mobile !=''">
  158. AND u.mobile like CONCAT('%',#{mobile},'%')
  159. </if>
  160. <if test="linkMan != null and linkMan !=''">
  161. AND u.linkMan like CONCAT('%',#{linkMan},'%')
  162. </if>
  163. <if test="sendStatus != null">
  164. <if test="0 == sendStatus">
  165. and ifnull(sw.waitSendNum,0) > 0
  166. </if>
  167. <if test="1 == sendStatus">
  168. and ifnull(sw.waitSendNum,0) = 0
  169. </if>
  170. </if>
  171. <if test="lowerAuditStatus != null">
  172. <if test="0 == lowerAuditStatus">
  173. <if test="listType == 2">
  174. and (ifnull(aw.authWaitNum,0)+ifnull(pw.productWaitNum,0)) > 0
  175. </if>
  176. <if test="listType == 3">
  177. and (ifnull(articleWaitNum,0) + ifnull(imageWaitNum,0) + ifnull(videoWaitNum,0) + ifnull(fileWaitNum,0) + ifnull(zipWaitNum,0)) > 0
  178. </if>
  179. <if test="listType == 4">
  180. and ifnull(dw.doctorWaitNum,0) > 0
  181. </if>
  182. <if test="listType == 6">
  183. and ifnull(tw.productTypeWaitNum,0) > 0
  184. </if>
  185. </if>
  186. <if test="1 == lowerAuditStatus">
  187. <if test="listType == 2">
  188. and (ifnull(aw.authWaitNum,0)+ifnull(pw.productWaitNum,0)) = 0
  189. </if>
  190. <if test="listType == 3">
  191. and (ifnull(articleWaitNum,0) + ifnull(imageWaitNum,0) + ifnull(videoWaitNum,0) + ifnull(fileWaitNum,0) + ifnull(zipWaitNum,0)) = 0
  192. </if>
  193. <if test="listType == 4">
  194. and ifnull(dw.doctorWaitNum,0) = 0
  195. </if>
  196. <if test="listType == 6">
  197. and ifnull(tw.productTypeWaitNum,0) = 0
  198. </if>
  199. </if>
  200. </if>
  201. group by u.authUserId,u.createTime
  202. <choose>
  203. <when test="listType == 2">
  204. ORDER BY waitAuditNum desc, u.createTime DESC
  205. </when>
  206. <when test="listType == 3">
  207. ORDER BY (ifnull(articleWaitNum,0) + ifnull(imageWaitNum,0) + ifnull(videoWaitNum,0) + ifnull(fileWaitNum,0) + ifnull(zipWaitNum,0)) desc, u.createTime DESC
  208. </when>
  209. <when test="listType == 4">
  210. ORDER BY ifnull(dw.doctorWaitNum,0) desc, u.createTime DESC
  211. </when>
  212. <when test="listType == 6">
  213. ORDER BY ifnull(tw.productTypeWaitNum,0) desc, u.createTime DESC
  214. </when>
  215. <otherwise>
  216. ORDER BY u.createTime DESC
  217. </otherwise>
  218. </choose>
  219. </select>
  220. <select id="getShopMobileByUserId" resultType="java.lang.String">
  221. select mobile from cm_brand_auth_user where authUserId = #{authUserId}
  222. </select>
  223. <select id="getStatementFile" resultType="com.caimei.model.po.CmBrandAuthFilePo">
  224. select id, authUserId, name, ossName, md5Hex, uploadTime
  225. from cm_brand_auth_file
  226. <where>
  227. <if test="id != null">
  228. and id = #{id}
  229. </if>
  230. <if test="authUserId != null">
  231. and authUserId = #{authUserId}
  232. </if>
  233. <if test="brandId != null">
  234. and brandId = #{brandId}
  235. </if>
  236. <if test="md5Hex != null and md5Hex != ''">
  237. and md5Hex = #{md5Hex}
  238. </if>
  239. </where>
  240. limit 1
  241. </select>
  242. <select id="getFileNumByMd5Hex" resultType="java.lang.Integer">
  243. select count(*) from cm_brand_auth_file where md5Hex = #{md5Hex}
  244. </select>
  245. <select id="getShopByUserId" resultType="com.caimei.model.vo.ShopFormVo">
  246. select u.authUserId, u.name as shopName, u.loginAccount, u.mobile, u.linkMan, u.status as shopStatus, u.shopType as shopType,
  247. u.wxAccountType, u.logo, u.qrCodeImage, u.appId, u.appSecret,
  248. if(avu.id is null, 3, (if(NOW() <![CDATA[<]]> avu.endTime, 1, 0))) as vipStatus
  249. from cm_brand_auth_user u
  250. left join auth_vip_user avu on u.authUserId = avu.authUserId
  251. where u.authUserId = #{authUserId};
  252. </select>
  253. <select id="getBrandList" resultType="com.caimei.model.vo.BrandVo">
  254. select id,name,authLogo from cm_brand
  255. <where>
  256. <if test="type == 1">
  257. id not in (select brandId
  258. from cm_brand_auth_shop_info i
  259. left join cm_brand_auth_user u on i.authUserId= u.authUserId
  260. where u.shopType = 1 and i.brandId is not null);
  261. </if>
  262. <if test="type == 3">
  263. id in (select brandId
  264. from cm_brand_auth_shop_info
  265. where authUserId = #{authUserId})
  266. </if>
  267. </where>
  268. </select>
  269. <select id="getCountryList" resultType="com.caimei.model.vo.CountryVo">
  270. select countryId, name as countryName
  271. from country
  272. where validFlag = 1
  273. </select>
  274. <select id="getUserIdByMobile" resultType="java.lang.Integer">
  275. select authUserId from cm_brand_auth_user where mobile = #{mobile} and userIdentity = 2 limit 1
  276. </select>
  277. <select id="getDbInfoBrandList" resultType="com.caimei.model.vo.ShopBrandVo">
  278. select id, brandId
  279. from cm_brand_auth_shop_info
  280. where authUserId = #{authUserId}
  281. </select>
  282. <select id="getShopInfoByUserId" resultType="com.caimei.model.vo.ShopInfoVo">
  283. select i.brandId,
  284. i.countryId,
  285. i.securityLink,
  286. i.statementType,
  287. i.statementContent,
  288. i.statementLink,
  289. i.statementImage,
  290. f.id as statementFileId,
  291. f.name as statementFileName,
  292. b.name as brandName,
  293. b.authLogo as brandAuthLogo
  294. from cm_brand_auth_shop_info i
  295. left join cm_brand b on i.brandId = b.id
  296. left join cm_brand_auth_file f on i.authUserId = f.authUserId and i.brandId = f.brandId
  297. where i.authUserId = #{authUserId}
  298. </select>
  299. <select id="getUserIdByShopName" resultType="java.lang.Integer">
  300. select authUserId from cm_brand_auth_user where name = #{shopName} and userIdentity = 2 limit 1
  301. </select>
  302. <select id="getAuthWaitAuditNum" resultType="java.lang.Integer">
  303. select count(*)
  304. from cm_brand_auth
  305. where authUserId = #{authUserId}
  306. and auditStatus = 2
  307. </select>
  308. <select id="getProductWaitAuditNum" resultType="java.lang.Integer">
  309. select count(*)
  310. from cm_brand_auth_product p
  311. left join cm_brand_auth a on p.authId = a.id
  312. where a.authUserId = #{authUserId}
  313. and p.auditStatus = 2
  314. </select>
  315. <select id="getProductCount" resultType="java.lang.Integer">
  316. select count(*)
  317. from cm_brand_auth a
  318. left join cm_brand_auth_product p on p.authId = a.id
  319. where a.authUserId = #{authUserId} and p.brandId = #{brandId}
  320. </select>
  321. <select id="getFeedbackList" resultType="com.caimei.model.vo.FeedbackVo">
  322. select cf.id as feedbackId, a.authParty as clubName, cu.mobile, content, commitTime, handleStatus, handleResult,
  323. handleTime
  324. from cm_brand_club_feedback cf
  325. join cm_brand_club_user cu on cf.clubUserId = cu.id
  326. join cm_brand_auth a on cu.authId = a.id
  327. where a.authUserId = #{authUserId}
  328. <if test="clubName != null and clubName != ''">
  329. and a.authParty like concat('%',#{clubName},'%')
  330. </if>
  331. <if test="mobile != null and mobile != ''">
  332. and cu.mobile like concat('%',#{mobile},'%')
  333. </if>
  334. <if test="handleStatus != null">
  335. and cf.handleStatus = #{handleStatus}
  336. </if>
  337. </select>
  338. <select id="getFeedback" resultType="com.caimei.model.vo.FeedbackVo">
  339. select cf.id as feedbackId, a.authParty as clubName, cu.mobile, content, commitTime, handleStatus, handleResult, handleTime
  340. from cm_brand_club_feedback cf
  341. join cm_brand_club_user cu on cf.clubUserId = cu.id
  342. join cm_brand_auth a on cu.authId = a.id
  343. where cf.id = #{feedbackId}
  344. </select>
  345. <select id="getShopStatus" resultType="java.lang.Integer">
  346. select status
  347. from cm_brand_auth_user
  348. where authUserId = #{authUserId}
  349. </select>
  350. <select id="getUserIdByAppId" resultType="java.lang.Integer">
  351. select authUserId from cm_brand_auth_user where appId = #{appId} and userIdentity = 2 and appId is not null limit 1
  352. </select>
  353. <select id="getAppSecretByAppId" resultType="java.lang.String">
  354. select appSecret from cm_brand_auth_user where appId = #{appId} and status = 1
  355. </select>
  356. <select id="getAppId" resultType="java.lang.String">
  357. select appId from cm_brand_auth_user where authUserId = #{authUserId} and status = 1
  358. </select>
  359. <select id="getShopNameByAppId" resultType="java.lang.String">
  360. select name from cm_brand_auth_user where appId = #{appId} and status = 1
  361. </select>
  362. <select id="getShopBrands" resultType="java.lang.String">
  363. select b.name
  364. from cm_brand_auth_shop_info i
  365. left join cm_brand b on i.brandId = b.id
  366. where i.authUserId = #{authUserId}
  367. </select>
  368. <select id="getWxShopInfo" resultType="com.caimei.model.vo.WxShopVo">
  369. select au.authUserId, au.appId, au.name as shopName, if(au.shopType = 1, cb.authLogo, au.logo) as logo
  370. from cm_brand_auth_user au
  371. left join cm_brand_auth_shop_info si on au.authUserId = si.authUserId
  372. left join cm_brand cb on si.brandId = cb.id
  373. where au.authUserId = #{authUserId}
  374. and au.status = 1
  375. limit 1
  376. </select>
  377. <select id="getWxAccountTypeByAppId" resultType="java.lang.Integer">
  378. select wxAccountType from cm_brand_auth_user where appId = #{appId} and status = 1
  379. </select>
  380. <select id="getLoginAccount" resultType="java.lang.String">
  381. select loginAccount from cm_brand_auth_user where authUserId = #{authUserId}
  382. </select>
  383. </mapper>