merchantMapper.xml 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367
  1. <?xml version="1.0" encoding="UTF-8" ?>
  2. <!DOCTYPE mapper
  3. PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
  4. "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
  5. <mapper namespace="com.ydd.module.mapper.MerchantMapper">
  6. <resultMap type="Merchant" id="MerchantResult">
  7. <result property="id" column="id"/>
  8. <result property="merchantName" column="merchant_name"/>
  9. <result property="agentId" column="agent_id"/>
  10. <result property="provinceId" column="province_id"/>
  11. <result property="cityId" column="city_id"/>
  12. <result property="districtId" column="district_id"/>
  13. <result property="merchantType" column="merchant_type"/>
  14. <result property="licenseType" column="license_type"/>
  15. <result property="categoryId" column="category_id"/>
  16. <result property="logo" column="logo"/>
  17. <result property="contactName" column="contact_name"/>
  18. <result property="mobile" column="mobile"/>
  19. <result property="intro" column="intro"/>
  20. <result property="photoAlbum" column="photo_album"/>
  21. <result property="bizLicense" column="biz_license"/>
  22. <result property="bizLicenseNo" column="biz_license_no"/>
  23. <result property="legalPerson" column="legal_person"/>
  24. <result property="idcardNo" column="idcard_no"/>
  25. <result property="idcardFront" column="idcard_front"/>
  26. <result property="idcardBack" column="idcard_back"/>
  27. <result property="lng" column="lng"/>
  28. <result property="lat" column="lat"/>
  29. <result property="address" column="address"/>
  30. <result property="errorMsg" column="error_msg"/>
  31. <result property="status" column="status"/>
  32. </resultMap>
  33. <update id="updatePersonnelId">
  34. update lb_merchant set personnel_id = null where id = #{id}
  35. </update>
  36. <select id="findIdsByAgentId" resultType="java.lang.Integer">
  37. SELECT id
  38. FROM lb_merchant
  39. WHERE agent_id = #{agentId}
  40. </select>
  41. <select id="findIdsByAgentIds" resultType="java.lang.Integer">
  42. SELECT id FROM lb_merchant WHERE 1 = 1
  43. AND agent_id IN
  44. <foreach collection="agentIds" index="index" item="agentId" open="(" separator="," close=")">
  45. #{agentId}
  46. </foreach>
  47. </select>
  48. <select id="findIdsByAgentIdLists" resultType="java.lang.Integer">
  49. SELECT id FROM lb_merchant WHERE 1 = 1
  50. AND agent_id IN
  51. <foreach collection="agentIds" index="index" item="agentId" open="(" separator="," close=")">
  52. #{agentId}
  53. </foreach>
  54. </select>
  55. <select id="listMerchan" resultType="com.ydd.module.domain.Merchant" >
  56. SELECT *
  57. FROM lb_merchant
  58. WHERE agent_Id IN
  59. (SELECT id FROM lb_agent WHERE pid in (SELECT id FROM lb_agent WHERE id = #{id}) OR id = #{id})
  60. </select>
  61. <select id="getMerchantNum" resultType="java.lang.Integer">
  62. SELECT count(id) FROM lb_merchant WHERE deleted = 0
  63. <if test="agentIds != null and agentIds.size() > 0">
  64. AND agent_id in
  65. <foreach collection="agentIds" index="index" item="agentId" open="(" separator="," close=")">
  66. #{agentId}
  67. </foreach>
  68. </if>
  69. <if test="startDate != null and startDate != ''">
  70. AND create_time >= #{startDate}
  71. </if>
  72. </select>
  73. <select id="findByMobile" resultType="com.ydd.module.domain.Merchant">
  74. select *
  75. from lb_merchant
  76. where mobile = #{mobile} and deleted = 0
  77. </select>
  78. <select id="selectExportList" resultType="com.ydd.module.dto.MerchantExportDto">
  79. select
  80. mc.logo,
  81. mc.merchant_name,
  82. mc.agent_id,
  83. mc.province_name,
  84. mc.city_name,
  85. mc.district_name,
  86. mc.merchant_type,
  87. mc.license_type,
  88. mc.category_id,
  89. mc.contact_name,
  90. mc.mobile,
  91. mc.legal_person,
  92. mc.idcard_no,
  93. mc.create_time,
  94. mc.status,
  95. mb.nickname as memberName,
  96. mb.mobile as memberMobile
  97. from lb_merchant mc
  98. left join lb_member mb on mc.id = mb.merchant_id
  99. left join lb_personnel p on mc.personnel_id = p.id
  100. where mc.deleted = 0 and mb.member_type = 2
  101. <if test="agentIds != null and agentIds.size > 0">
  102. and mc.agent_id in
  103. <foreach collection="agentIds" index="index" item="item" open="(" separator="," close=")">
  104. #{item}
  105. </foreach>
  106. </if>
  107. <if test="params.personnelId != null">
  108. and mc.personnel_id = #{params.personnelId}
  109. </if>
  110. <if test="params.merchantName != null and params.merchantName != ''">
  111. and mc.merchant_name like concat('%', #{params.merchantName} ,'%')
  112. </if>
  113. <if test="params.merchantType != null">
  114. and mc.merchant_type = #{params.merchantType}
  115. </if>
  116. <if test="params.licenseType != null">
  117. and mc.license_type = #{params.licenseType}
  118. </if>
  119. <if test="params.contactName != null and params.contactName != ''">
  120. and mc.contact_name like concat('%', #{params.contactName}, '%')
  121. </if>
  122. <if test="params.mobile != null and params.mobile != ''">
  123. and mc.mobile like concat('%', #{params.mobile}, '%')
  124. </if>
  125. <if test="params.startTime != null">
  126. AND mc.create_time >= #{params.startTime}
  127. </if>
  128. <if test="params.endTime != null">
  129. AND #{params.endTime} >= mc.create_time
  130. </if>
  131. <if test="params.memberName != null and params.memberName != ''">
  132. and mb.nickname like concat('%', #{params.memberName}, '%')
  133. </if>
  134. <if test="params.memberMobile != null and params.memberMobile != ''">
  135. and mb.mobile like concat('%', #{params.memberMobile}, '%')
  136. </if>
  137. <if test="params.personnelName != null and params.personnelName != ''">
  138. AND p.`name` like concat('%', #{params.personnelName}, '%')
  139. </if>
  140. order by create_time desc
  141. </select>
  142. <select id="selectMerchantList" resultType="com.ydd.module.domain.Merchant">
  143. select
  144. mc.*,
  145. mb.nickname as memberName,
  146. mb.mobile as memberMobile
  147. from lb_merchant mc
  148. left join lb_member mb on mc.id = mb.merchant_id
  149. left join lb_personnel p on mc.personnel_id = p.id
  150. where mb.member_type = 2
  151. <if test="params.merchantName != null and params.merchantName != ''">
  152. and mc.merchant_name like concat('%', #{params.merchantName}, '%')
  153. </if>
  154. <if test="agentIds != null and agentIds.size > 0">
  155. and mc.agent_id in
  156. <foreach collection="agentIds" index="index" item="agentId" open="(" separator="," close=")">
  157. #{agentId}
  158. </foreach>
  159. </if>
  160. <if test="params.packageDiscountId != null">
  161. and mc.agent_id in
  162. <foreach collection="agentList" index="index" item="agentId" open="(" separator="," close=")">
  163. #{agentId}
  164. </foreach>
  165. </if>
  166. <if test="params.personnelId != null">
  167. and mc.personnel_id = #{params.personnelId}
  168. </if>
  169. <if test="params.merchantType != null">
  170. and mc.merchant_type = #{params.merchantType}
  171. </if>
  172. <if test="params.licenseType != null">
  173. and mc.license_type = #{params.licenseType}
  174. </if>
  175. <if test="params.contactName != null and params.contactName != ''">
  176. and mc.contact_name like concat('%', #{params.contactName}, '%')
  177. </if>
  178. <if test="params.mobile != null and params.mobile != ''">
  179. and mc.mobile like concat('%', #{params.mobile}, '%')
  180. </if>
  181. <if test="params.provinceName != null and params.provinceName != ''">
  182. and mc.province_name like concat('%', #{params.provinceName}, '%')
  183. </if>
  184. <if test="params.cityName != null and params.cityName != ''">
  185. and mc.city_name like concat('%', #{params.cityName}, '%')
  186. </if>
  187. <if test="params.districtName != null and params.districtName != ''">
  188. and mc.district_name like concat('%', #{params.districtName}, '%')
  189. </if>
  190. <if test="params.startTime != null">
  191. AND mc.create_time >= #{params.startTime}
  192. </if>
  193. <if test="params.endTime != null">
  194. AND #{params.endTime} >= mc.create_time
  195. </if>
  196. <if test="params.memberName != null and params.memberName != ''">
  197. and mb.nickname like concat('%', #{params.memberName}, '%')
  198. </if>
  199. <if test="params.memberMobile != null and params.memberMobile != ''">
  200. and mb.mobile like concat('%', #{params.memberMobile}, '%')
  201. </if>
  202. <!-- <if test="params.aId != null">-->
  203. <!-- ANd mc.agent_id = #{params.aId}-->
  204. <!-- </if>-->
  205. <if test="params.personnelName != null and params.personnelName != ''">
  206. AND p.`name` like concat('%', #{params.personnelName}, '%')
  207. </if>
  208. order by create_time desc
  209. </select>
  210. <select id="listMerchantIds" resultType="java.lang.Long">
  211. SELECT id FROM lb_merchant WHERE 1 = 1
  212. AND agent_id IN
  213. <foreach collection="agentIds" index="index" item="agentId" open="(" separator="," close=")">
  214. #{agentId}
  215. </foreach>
  216. </select>
  217. <select id="getIdListByFreightPackageId" resultType="java.lang.Long">
  218. SELECT id FROM lb_merchant
  219. WHERE freight_package_id = #{freightPackageId} AND deleted = 0
  220. </select>
  221. <select id="queryListByDadaDspId" resultType="com.ydd.module.dto.DadaDspMerchantInfoDto">
  222. select
  223. mc.id,
  224. mc.merchant_name,
  225. mc.contact_name,
  226. mc.mobile as contactMobile,
  227. mc.create_time,
  228. mc.merchant_type,
  229. mc.freight_package_id,
  230. mc.open_qr_code,
  231. dd.name as dspName,
  232. lm.amount as accountAmount,
  233. pf.name as freightPackageName
  234. from lb_merchant mc
  235. left join lb_dada_dsp dd on mc.dada_dsp_id = dd.id
  236. left join lb_member lm on lm.merchant_id = mc.id and lm.member_type = 2
  237. left join lb_package_freight pf on mc.freight_package_id = pf.id
  238. where mc.dada_dsp_id is not null
  239. <if test="params.dadaDspId != null and params.dadaDspId != ''">
  240. and mc.dada_dsp_id = #{params.dadaDspId}
  241. </if>
  242. <if test="params.merchantName != null and params.merchantName != ''">
  243. and mc.merchant_name like concat('%', #{params.merchantName}, '%')
  244. </if>
  245. <if test="params.contactName != null and params.contactName != ''">
  246. and mc.contact_name l ike concat('%', #{params.contactName}, '%')
  247. </if>
  248. <if test="params.mobile != null and params.mobile != ''">
  249. and mc.mobile like concat('%', #{params.mobile}, '%')
  250. </if>
  251. <if test="params.startTime != null and params.startTime != ''">
  252. AND mc.create_time >= #{params.startTime}
  253. </if>
  254. <if test="params.endTime != null and params.startTime != ''">
  255. AND #{params.endTime} >= mc.create_time
  256. </if>
  257. <if test="params.merchantType != null and params.merchantType != ''">
  258. AND mc.merchant_type = #{params.merchantType}
  259. </if>
  260. <if test="params.amountStart != null and params.amountStart != ''">
  261. AND lm.amount >= #{params.amountStart}
  262. </if>
  263. <if test="params.amountEnd != null and params.amountEnd != ''">
  264. AND #{params.amountEnd} >= lm.amount
  265. </if>
  266. <if test="params.freightPackageId != null and params.freightPackageId != ''">
  267. <if test="params.dimension != null">
  268. <if test="params.dimension == 0">
  269. AND mc.freight_package_id is null
  270. </if>
  271. <if test="params.dimension == 1">
  272. AND mc.freight_package_id = #{params.freightPackageId}
  273. </if>
  274. </if>
  275. </if>
  276. order by mc.id desc
  277. </select>
  278. <select id="queryDadaMerchantInfo" resultType="com.ydd.module.dto.DadaDspMerchantInfoDto">
  279. select
  280. mc.id,
  281. mc.merchant_name,
  282. mc.province_id,
  283. mc.city_id,
  284. mc.district_id,
  285. mc.province_name,
  286. mc.city_name,
  287. mc.district_name,
  288. mc.address,
  289. mc.street,
  290. mc.contact_name,
  291. mc.mobile as contactMobile,
  292. mc.dada_dsp_id,
  293. mc.freight_package_id,
  294. mc.category_id,
  295. mc.merchant_type,
  296. mc.license_type,
  297. mc.legal_person,
  298. mc.idcard_no
  299. from lb_merchant mc
  300. where mc.id = #{merchantId}
  301. </select>
  302. <select id="selectIdByName" resultType="java.lang.Long">
  303. SELECT id FROM lb_merchant WHERE deleted = 0 AND merchant_name like concat('%', #{merchantName}, '%')
  304. </select>
  305. <select id="findMerchantIdByAgentId" resultType="java.lang.Long">
  306. SELECT id FROM lb_merchant WHERE 1 = 1
  307. <if test="agentIds != null and agentIds.size > 0">
  308. AND agent_id IN
  309. <foreach collection="agentIds" index="index" item="agentId" open="(" separator="," close=")">
  310. #{agentId}
  311. </foreach>
  312. </if>
  313. </select>
  314. <select id="selectListByDadaDspId" resultType="com.ydd.module.domain.Merchant">
  315. SELECT
  316. id,
  317. code,
  318. merchant_name,
  319. create_time,
  320. dada_dsp_id
  321. FROM lb_merchant
  322. WHERE deleted = 0
  323. AND dada_dsp_id = #{dadaDspId}
  324. </select>
  325. <select id="selectCustomerList" resultType="com.ydd.module.dto.OpenCustomerDto">
  326. SELECT
  327. ai.create_time,
  328. m.city_name,
  329. m.merchant_name AS businessName,
  330. m.contact_name,
  331. m.mobile AS contactMobile,
  332. ai.end_time,
  333. ai.earnest_money,
  334. m.status
  335. FROM lb_merchant m
  336. LEFT JOIN lb_app_info ai ON m.app_id = ai.id
  337. WHERE m.deleted = 0
  338. <if test="cityName != null and cityName != ''">
  339. AND m.city_name = #{cityName}
  340. </if>
  341. <if test="businessName != null and businessName != ''">
  342. AND m.merchant_name = #{businessName}
  343. </if>
  344. <if test="contactName != null and contactName != ''">
  345. AND m.contact_name = #{contactName}
  346. </if>
  347. </select>
  348. </mapper>