placeInfoMapper.xml 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859
  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. <!-- 命名,每一个映射对象不一样
  4. namespace:必须与对应的接口全类名一致
  5. -->
  6. <mapper namespace="com.iamberry.wechat.service.mapper.PlaceInfoMapper">
  7. <!-- palceInfo活动所有字段映射 -->
  8. <sql id="palceInfoAllField">
  9. PLACE_ID id,
  10. PLACE_SUPPER_ID supperId,
  11. PLACE_NAME name,
  12. PLACE_ADDR addr,
  13. PLACE_USERNAME userName,
  14. PLACE_TEL tel,
  15. PLACE_AMOUNT amount,
  16. PLACE_CREATE_DATE createDate,
  17. PLACE_STATUS status,
  18. PLACE_OPENID openid,
  19. PLACE_ROLE_ID roleId,
  20. PLACE_PID placePid ,
  21. PLACE_PIDS placeIds ,
  22. PLACE_AREA areaName,
  23. PLACE_INIT_CODE initCode,
  24. PLACE_REMARK remark
  25. </sql>
  26. <!-- 商户申请修改信息页面 -->
  27. <sql id="applyLogsAllField">
  28. APPLY_ID applyID, APPLY_OPENID applyOpenID, APPLY_TO_PLACEID applyToPlaceID,
  29. APPLY_NAME applyName, APPLY_USERNAME applyUserName, APPLY_TEL applyTel,
  30. APPLY_AREA applyArea, APPLY_DATE applyDate, APPLY_STATUS applyStatus, APPLY_ADDR applyAddr
  31. </sql>
  32. <select id="getOnePlaceInfo" parameterType="integer" resultType="PlaceInfo">
  33. SELECT
  34. <include refid="palceInfoAllField"/>,
  35. PLACE_PIDS placeIds ,
  36. PLACE_HAS_QRCODE hasQrcode,
  37. PLACE_TEMPLATE_ID templateId,
  38. (select role_name from tb_iamberry_place_role where role_id=roleId ) as roleName,
  39. (select template_name from tb_iamberry_template where template_id=templateId) templateName
  40. FROM tb_iamberry_place_info WHERE place_id = #{placeId} and PLACE_STATUS=1
  41. </select>
  42. <select id="getOnePlaceInfo2" parameterType="string" resultType="PlaceInfo">
  43. SELECT
  44. <include refid="palceInfoAllField"/>,
  45. PLACE_PIDS placeIds ,
  46. PLACE_HAS_QRCODE hasQrcode,
  47. PLACE_TEMPLATE_ID templateId,
  48. PLACE_INFO_STATUS placeInfoStus,
  49. ROLE_NAME roleName
  50. FROM TB_IAMBERRY_PLACE_INFO
  51. JOIN TB_IAMBERRY_PLACE_ROLE ON ROLE_ID = PLACE_ROLE_ID
  52. WHERE PLACE_OPENID=#{openid} AND PLACE_STATUS=1
  53. </select>
  54. <select id="getOnePlaceInfoByInitcode" resultType="PlaceInfo">
  55. SELECT
  56. <include refid="palceInfoAllField"/>,
  57. PLACE_PIDS placeIds ,
  58. PLACE_HAS_QRCODE hasQrcode,
  59. PLACE_TEMPLATE_ID templateId
  60. FROM tb_iamberry_place_info
  61. WHERE
  62. PLACE_STATUS=1
  63. <if test="initCode!=null and initCode!=''">
  64. and PLACE_INIT_CODE=#{initCode}
  65. </if>
  66. <if test="id!=null and id!=''">
  67. and PLACE_ID=${id}
  68. </if>
  69. <if test="name!=null and name!=''">
  70. and PLACE_Name=#{name}
  71. </if>
  72. </select>
  73. <select id="getPlaceInfosForDownLoad" resultType="PlaceInfo">
  74. select
  75. PLACE_ID id,
  76. PLACE_NAME name,
  77. PLACE_ADDR addr,
  78. PLACE_USERNAME userName,
  79. PLACE_TEL tel,
  80. PLACE_ROLE_ID roleId,
  81. PLACE_PID placePid ,
  82. PLACE_AREA areaName,
  83. PLACE_HAS_QRCODE hasQrcode,
  84. PLACE_INIT_CODE initCode,
  85. PLACE_REMARK remark
  86. FROM tb_iamberry_place_info
  87. WHERE
  88. PLACE_STATUS=1
  89. <if test="beginNum!=null and beginNum!=''">
  90. <![CDATA[ and PLACE_ID >= #{beginNum} ]]>
  91. </if>
  92. <if test="num!=null and num!=''">
  93. limit #{num}
  94. </if>
  95. </select>
  96. <select id="getUnderling" parameterType="PlaceInfo" resultType="string">
  97. select t.PLACE_OPENID openid
  98. from tb_iamberry_place_info t
  99. <where>
  100. t.PLACE_PID=(select PLACE_ID from tb_iamberry_place_info where PLACE_OPENID=#{openid})
  101. <if test="roleId>0" >
  102. and t.PLACE_ROLE_ID=${roleId}
  103. </if>
  104. and t.PLACE_OPENID is not null
  105. </where>
  106. </select>
  107. <select id="selectAll" resultType="PlaceInfo" parameterType="PlaceInfo">
  108. select
  109. <include refid="palceInfoAllField"/>,
  110. (select role_name from tb_iamberry_place_role where role_id=roleId ) as roleName,
  111. (SELECT Q.QRCODE_URL FROM TB_IAMBERRY_USER_QRCODE Q WHERE (Q.QRCODE_REPLACE_OPENID = id OR Q.QRCODE_REPLACE_OPENID = openid) AND Q.QRCODE_STATUS = 1 limit 1) qrcodeUrl
  112. from tb_iamberry_place_info
  113. <where>
  114. PLACE_STATUS=1
  115. <if test="name!=null and name!=''">
  116. and PLACE_NAME like CONCAT('%',#{name},'%')
  117. </if>
  118. <if test="userName!=null and userName!=''" >
  119. and PLACE_USERNAME like CONCAT('%',#{userName},'%')
  120. </if>
  121. <if test="roleId!=null and roleId!=''" >
  122. and PLACE_ROLE_ID=#{roleId}
  123. </if>
  124. <if test="tel!=null and tel!=''">
  125. AND PLACE_TEL LIKE CONCAT('%',#{tel},'%')
  126. </if>
  127. <if test="userNickname != null and userNickname != ''">
  128. AND PLACE_OPENID IN (SELECT T.USER_OPENID FROM TB_IAMBERRY_USER_USERINFO T WHERE T.USER_NICKNAME LIKE CONCAT('%',#{userNickname},'%'))
  129. </if>
  130. <if test="placePid!=null and placePid!=''" >
  131. and PLACE_PID=#{placePid}
  132. </if>
  133. <if test="supperId>0" >
  134. and PLACE_SUPPER_ID =#{supperId}
  135. </if>
  136. <if test="parentName!=null and parentName!=''" >
  137. and PLACE_PID in
  138. (select PLACE_ID from tb_iamberry_place_info where
  139. PLACE_NAME like CONCAT('%',#{parentName},'%')
  140. )
  141. </if>
  142. <if test="initCode!=null and initCode!=''" >
  143. and UPPER(PLACE_INIT_CODE) like CONCAT('%',UPPER(#{initCode}),'%')
  144. </if>
  145. </where>
  146. order by place_create_date desc
  147. <if test="page!=null and page.recordBegin>0 and page.pageSize>0 ">
  148. limit ${page.recordBegin},${page.pageSize}
  149. </if>
  150. <if test="page!=null and page.recordBegin==0 and page.pageSize>0 ">
  151. limit ${page.pageSize}
  152. </if>
  153. </select>
  154. <!-- 公司分销下线用户 - 个人代理个数 -->
  155. <select id="getDistributorNumber" resultType="integer" parameterType="PlaceInfo">
  156. SELECT count(*)
  157. FROM tb_iamberry_place_info TIPI
  158. <where>
  159. PLACE_STATUS=1
  160. <if test="name!=null and name!=''">
  161. and PLACE_NAME like CONCAT('%',#{name},'%')
  162. </if>
  163. <if test="userName!=null and userName!=''" >
  164. and PLACE_USERNAME like CONCAT('%',#{userName},'%')
  165. </if>
  166. <if test="roleId!=null and roleId!=''" >
  167. and PLACE_ROLE_ID=#{roleId}
  168. </if>
  169. <if test="tel!=null and tel!=''">
  170. AND PLACE_TEL LIKE CONCAT('%',#{tel},'%')
  171. </if>
  172. <if test="userNickname != null and userNickname != ''">
  173. AND PLACE_OPENID IN (SELECT T.USER_OPENID FROM TB_IAMBERRY_USER_USERINFO T WHERE T.USER_NICKNAME LIKE CONCAT('%',#{userNickname},'%'))
  174. </if>
  175. <if test="placePid!=null and placePid!=''" >
  176. and PLACE_PID=#{placePid}
  177. </if>
  178. <if test="supperId>0" >
  179. and PLACE_SUPPER_ID =#{supperId}
  180. </if>
  181. <if test="initCode!=null and initCode!=''" >
  182. and UPPER(PLACE_INIT_CODE) like CONCAT('%',UPPER(#{initCode}),'%')
  183. </if>
  184. <if test="openid==1" >
  185. AND IFNULL(PLACE_OPENID,"") != ""
  186. </if>
  187. <if test="openid==2" >
  188. AND IFNULL(PLACE_OPENID,"") = ""
  189. </if>
  190. </where>
  191. </select>
  192. <!-- 公司分销下线用户 - 个人代理 -->
  193. <select id="getDistributor" resultType="PlaceInfo" parameterType="PlaceInfo">
  194. select
  195. <include refid="palceInfoAllField"/>,
  196. TIUU.user_head AS userHead,TIUU.user_nickname AS userNickname
  197. from tb_iamberry_place_info
  198. LEFT JOIN tb_iamberry_user_userinfo TIUU ON tb_iamberry_place_info.place_openid = TIUU.user_openid
  199. <where>
  200. PLACE_STATUS=1
  201. <if test="name!=null and name!=''">
  202. and PLACE_NAME like CONCAT('%',#{name},'%')
  203. </if>
  204. <if test="userName!=null and userName!=''" >
  205. and PLACE_USERNAME like CONCAT('%',#{userName},'%')
  206. </if>
  207. <if test="roleId!=null and roleId!=''" >
  208. and PLACE_ROLE_ID=#{roleId}
  209. </if>
  210. <if test="tel!=null and tel!=''">
  211. AND PLACE_TEL LIKE CONCAT('%',#{tel},'%')
  212. </if>
  213. <if test="userNickname != null and userNickname != ''">
  214. AND PLACE_OPENID IN (SELECT T.USER_OPENID FROM TB_IAMBERRY_USER_USERINFO T WHERE T.USER_NICKNAME LIKE CONCAT('%',#{userNickname},'%'))
  215. </if>
  216. <if test="placePid!=null and placePid!=''" >
  217. and PLACE_PID=#{placePid}
  218. </if>
  219. <if test="supperId>0" >
  220. and PLACE_SUPPER_ID =#{supperId}
  221. </if>
  222. <if test="initCode!=null and initCode!=''" >
  223. and UPPER(PLACE_INIT_CODE) like CONCAT('%',UPPER(#{initCode}),'%')
  224. </if>
  225. <if test="initCode==1" >
  226. and UPPER(PLACE_INIT_CODE) like CONCAT('%',UPPER(#{initCode}),'%')
  227. </if>
  228. <if test="openid==1" >
  229. and PLACE_OPENID is not null
  230. </if>
  231. <if test="openid==2" >
  232. and PLACE_OPENID is null
  233. </if>
  234. </where>
  235. order by place_create_date desc
  236. <if test="page!=null and page.recordBegin>0 and page.pageSize>0 ">
  237. limit ${page.recordBegin},${page.pageSize}
  238. </if>
  239. <if test="page!=null and page.recordBegin==0 and page.pageSize>0 ">
  240. limit ${page.pageSize}
  241. </if>
  242. </select>
  243. <select id="selectAllByParent" resultType="PlaceInfo" parameterType="PlaceInfo">
  244. select
  245. <include refid="palceInfoAllField"/>,
  246. (select role_name from tb_iamberry_place_role where role_id=roleId ) as roleName,
  247. (SELECT Q.QRCODE_URL FROM TB_IAMBERRY_USER_QRCODE Q WHERE (Q.QRCODE_REPLACE_OPENID = id OR Q.QRCODE_REPLACE_OPENID = openid) AND Q.QRCODE_STATUS = 1 limit 1) qrcodeUrl
  248. from tb_iamberry_place_info
  249. <where>
  250. PLACE_STATUS=1
  251. <if test="name!=null and name!=''">
  252. and PLACE_NAME like CONCAT('%',#{name},'%')
  253. </if>
  254. <if test="roleId!=null and templateId == 23 and roleId == 49" >
  255. and PLACE_ROLE_ID= 51
  256. </if>
  257. <if test="roleId!=null and templateId == 22 and roleId == 49" >
  258. and PLACE_ROLE_ID= 48
  259. </if>
  260. <if test="roleId!=null and templateId == 21 and roleId == 49" >
  261. and PLACE_ROLE_ID= 48
  262. </if>
  263. <if test="roleId!=null and templateId == 23 and roleId == 51" >
  264. and PLACE_ROLE_ID= 48
  265. </if>
  266. <if test="roleId!=null and roleId == 48" >
  267. and PLACE_ROLE_ID= 47
  268. </if>
  269. <if test="roleId!=null and roleId == 52" >
  270. and PLACE_ROLE_ID= 53
  271. </if>
  272. </where>
  273. order by place_create_date desc
  274. <if test="page!=null and page.recordBegin>0 and page.pageSize>0 ">
  275. limit ${page.recordBegin},${page.pageSize}
  276. </if>
  277. <if test="page!=null and page.recordBegin==0 and page.pageSize>0 ">
  278. limit ${page.pageSize}
  279. </if>
  280. </select>
  281. <select id="getAllByParentCount" parameterType="PlaceInfo" resultType="integer">
  282. select count(PLACE_ID) from tb_iamberry_place_info
  283. <where>
  284. PLACE_STATUS=1
  285. <if test="name!=null and name!=''">
  286. and PLACE_NAME like CONCAT('%',#{name},'%')
  287. </if>
  288. <if test="roleId!=null and templateId == 23 and roleId == 49" >
  289. and PLACE_ROLE_ID= 51
  290. </if>
  291. <if test="roleId!=null and templateId == 22 and roleId == 49" >
  292. and PLACE_ROLE_ID= 48
  293. </if>
  294. <if test="roleId!=null and templateId == 21 and roleId == 49" >
  295. and PLACE_ROLE_ID= 48
  296. </if>
  297. <if test="roleId!=null and templateId == 23 and roleId == 51" >
  298. and PLACE_ROLE_ID= 48
  299. </if>
  300. <if test="roleId!=null and roleId == 48" >
  301. and PLACE_ROLE_ID= 47
  302. </if>
  303. <if test="roleId!=null and roleId == 52" >
  304. and PLACE_ROLE_ID= 53
  305. </if>
  306. </where>
  307. </select>
  308. <!-- 根据条件获取placeId -->
  309. <select id="getPlaceId" resultType="PlaceInfo" parameterType="PlaceInfo">
  310. SELECT
  311. PLACE_ID id,
  312. PLACE_OPENID openid,
  313. (SELECT Q.QRCODE_URL FROM TB_IAMBERRY_USER_QRCODE Q WHERE (Q.QRCODE_REPLACE_OPENID = id OR Q.QRCODE_REPLACE_OPENID = openid) AND Q.QRCODE_STATUS = 1 limit 1) qrcodeUrl
  314. FROM
  315. TB_IAMBERRY_PLACE_INFO
  316. <where>
  317. PLACE_STATUS=1
  318. <if test="name!=null and name!=''">
  319. and PLACE_NAME like CONCAT('%',#{name},'%')
  320. </if>
  321. <if test="userName!=null and userName!=''" >
  322. and PLACE_USERNAME like CONCAT('%',#{userName},'%')
  323. </if>
  324. <if test="roleId!=null and roleId!=''" >
  325. and PLACE_ROLE_ID=#{roleId}
  326. </if>
  327. <if test="placePid!=null and placePid!=''" >
  328. and PLACE_PID=#{placePid}
  329. </if>
  330. <if test="supperId>0" >
  331. and PLACE_SUPPER_ID =#{supperId}
  332. </if>
  333. <if test="parentName!=null and parentName!=''" >
  334. and PLACE_PID in
  335. (select PLACE_ID from tb_iamberry_place_info where
  336. PLACE_NAME like CONCAT('%',#{parentName},'%')
  337. )
  338. </if>
  339. </where>
  340. order by place_create_date desc
  341. </select>
  342. <select id="getAllCount" resultType="integer">
  343. select count(PLACE_ID) from tb_iamberry_place_info
  344. <where>
  345. PLACE_STATUS=1
  346. <if test="name!=null and name!=''">
  347. and PLACE_NAME like CONCAT('%',#{name},'%')
  348. </if>
  349. <if test="userName!=null and userName!=''" >
  350. and PLACE_USERNAME like CONCAT('%',#{userName},'%')
  351. </if>
  352. <if test="supperId!=null and supperId!=''" >
  353. and PLACE_SUPPER_ID =${supperId}
  354. </if>
  355. <if test="roleId!=null and roleId!=''" >
  356. and PLACE_ROLE_Id=#{roleId}
  357. </if>
  358. <if test="placePid!=null and placePid!=''" >
  359. and PLACE_PID=#{placePid}
  360. </if>
  361. <if test="parentName!=null and parentName!=''" >
  362. and PLACE_PID in
  363. (select PLACE_ID from tb_iamberry_place_info where
  364. PLACE_NAME like CONCAT('%',#{parentName},'%')
  365. )
  366. </if>
  367. </where>
  368. </select>
  369. <select id="testNameExist" resultType="Integer">
  370. select count(PLACE_ID) from tb_iamberry_place_info
  371. where
  372. PLACE_NAME= #{name}
  373. and PLACE_STATUS=1
  374. </select>
  375. <insert id="insert" >
  376. insert into
  377. tb_iamberry_place_info(
  378. PLACE_SUPPER_ID ,
  379. PLACE_NAME ,
  380. PLACE_ADDR ,
  381. PLACE_USERNAME ,
  382. PLACE_TEL ,
  383. PLACE_AMOUNT ,
  384. PLACE_CREATE_DATE ,
  385. PLACE_STATUS ,
  386. PLACE_OPENID ,
  387. PLACE_ROLE_ID ,
  388. PLACE_PID ,
  389. PLACE_HAS_QRCODE ,
  390. PLACE_TEMPLATE_ID ,
  391. PLACE_AREA ,
  392. PLACE_INIT_CODE,
  393. PLACE_REMARK)
  394. values(#{supperId},#{name},#{addr},#{userName},#{tel},#{amount},
  395. #{createDate},#{status},#{openid},${roleId},${placePid},#{hasQrcode},#{templateId},#{areaName},
  396. #{initCode},#{remark})
  397. </insert>
  398. <!-- 插入对象,并返回带有主键的对象 -->
  399. <insert id="insertObj" useGeneratedKeys="true" keyProperty="id" >
  400. <selectKey keyProperty="id" resultType="int">
  401. select LAST_INSERT_ID()
  402. </selectKey>
  403. insert into
  404. tb_iamberry_place_info(
  405. PLACE_SUPPER_ID ,
  406. PLACE_NAME ,
  407. PLACE_ADDR ,
  408. PLACE_USERNAME ,
  409. PLACE_TEL ,
  410. PLACE_AMOUNT ,
  411. PLACE_CREATE_DATE ,
  412. PLACE_STATUS ,
  413. PLACE_OPENID ,
  414. PLACE_ROLE_ID ,
  415. PLACE_PID ,
  416. PLACE_HAS_QRCODE ,
  417. PLACE_TEMPLATE_ID ,
  418. PLACE_AREA ,
  419. PLACE_INIT_CODE,
  420. PLACE_REMARK,
  421. PLACE_INFO_STATUS)
  422. values(#{supperId},#{name},#{addr},#{userName},#{tel},#{amount},
  423. #{createDate},#{status},#{openid},${roleId},${placePid},#{hasQrcode},#{templateId},#{areaName},
  424. #{initCode},#{remark},#{placeInfoStus})
  425. </insert>
  426. <update id="update" >
  427. update tb_iamberry_place_info
  428. <set>
  429. <if test="templateId!=null and templateId!=''">
  430. PLACE_TEMPLATE_ID =#{templateId},
  431. </if>
  432. <if test="name!=null and name!=''">
  433. PLACE_NAME =#{name},
  434. </if>
  435. <if test="addr!=null and addr!=''">
  436. PLACE_ADDR =#{addr},
  437. </if>
  438. <if test="userName!=null and userName!=''">
  439. PLACE_USERNAME =#{userName},
  440. </if>
  441. <if test="tel!=null and tel!=''">
  442. PLACE_TEL =#{tel},
  443. </if>
  444. <if test="amount!=null and amount!=''">
  445. PLACE_AMOUNT =#{amount},
  446. </if>
  447. <if test="status!=null and status!=''">
  448. PLACE_STATUS =#{status},
  449. </if>
  450. <if test="openid!=null and openid!=''">
  451. PLACE_OPENID =#{openid},
  452. </if>
  453. <if test="roleId!=null and roleId!=''">
  454. PLACE_ROLE_ID =#{roleId},
  455. </if>
  456. <if test="placePid!=null and placePid!=''">
  457. PLACE_PID =#{placePid},
  458. </if>
  459. <if test="placeIds!=null and placeIds!=''">
  460. PLACE_PIDS =#{placeIds},
  461. </if>
  462. <if test="areaName!=null and areaName!=''">
  463. PLACE_AREA =#{areaName},
  464. </if>
  465. <if test="hasQrcode!=null and hasQrcode!=''">
  466. PLACE_HAS_QRCODE =#{hasQrcode},
  467. </if>
  468. <if test="remark!=null and remark!=''">
  469. PLACE_REMARK =#{remark}
  470. </if>
  471. </set>
  472. where PLACE_ID = #{id}
  473. </update>
  474. <update id="batchUpdate" parameterType="java.util.List">
  475. <foreach collection="list" item="item" index="index" separator=";" open="" close="">
  476. update tb_iamberry_place_info
  477. <set>
  478. <if test="item.name!=null and item.name!=''">
  479. PLACE_NAME =#{item.name,jdbcType=VARCHAR},
  480. </if>
  481. <if test="item.addr!=null and item.addr!=''">
  482. PLACE_ADDR =#{item.addr,jdbcType=VARCHAR},
  483. </if>
  484. <if test="item.userName!=null and item.userName!=''">
  485. PLACE_USERNAME =#{item.userName,jdbcType=VARCHAR},
  486. </if>
  487. <if test="item.tel!=null and item.tel!=''">
  488. PLACE_TEL =#{item.tel,jdbcType=VARCHAR},
  489. </if>
  490. <if test="item.areaName!=null and item.areaName!=''">
  491. PLACE_AREA =#{item.areaName,jdbcType=VARCHAR},
  492. </if>
  493. <if test="item.hasQrcode!=null and item.hasQrcode!=''">
  494. PLACE_HAS_QRCODE =#{item.hasQrcode,jdbcType=INTEGER},
  495. </if>
  496. <if test="item.remark!=null and item.remark!=''">
  497. PLACE_REMARK =#{item.remark,jdbcType=VARCHAR}
  498. </if>
  499. </set>
  500. where PLACE_ID = #{item.id,jdbcType=INTEGER}
  501. </foreach>
  502. </update>
  503. <delete id="delete" parameterType="string">
  504. delete from tb_iamberry_place_info
  505. where PLACE_ID = #{appid}
  506. </delete>
  507. <!-- 根据code获取代理商信息 -->
  508. <select id="selectOnePlaceInfoByCode" parameterType="String" resultType="PlaceInfo">
  509. SELECT
  510. PLACE_ID id, PLACE_OPENID openid,
  511. (select r.role_name from tb_iamberry_place_role r where r.role_id=place_role_id ) as roleName
  512. FROM
  513. TB_IAMBERRY_PLACE_INFO
  514. WHERE
  515. PLACE_INIT_CODE = #{code}
  516. </select>
  517. <!-- 更新微代理的微信openid -->
  518. <update id="updateOpenidById" parameterType="PlaceInfo">
  519. UPDATE
  520. TB_IAMBERRY_PLACE_INFO
  521. SET
  522. PLACE_OPENID = #{openid}
  523. WHERE
  524. PLACE_ID = #{id}
  525. </update>
  526. <!-- 根据ID,获取顶级代理商ID -->
  527. <select id="selectPlaceInfobyId" parameterType="Integer" resultType="PlaceInfo">
  528. SELECT
  529. PLACE_ID id, PLACE_PIDS placeIds,PLACE_TEMPLATE_ID templateId,
  530. PLACE_OPENID openid, PLACE_ROLE_ID roleId,PLACE_HAS_QRCODE hasQrcode
  531. FROM
  532. TB_IAMBERRY_PLACE_INFO
  533. WHERE
  534. PLACE_ID = #{id}
  535. </select>
  536. <!-- 根据用户openid,获取对应的代理商ID -->
  537. <select id="selectPlaceIdByOpenId" parameterType="String" resultType="Integer">
  538. SELECT
  539. PLACE_ID id
  540. FROM
  541. TB_IAMBERRY_PLACE_INFO
  542. WHERE
  543. PLACE_OPENID = #{openid}
  544. </select>
  545. <!-- 根据代理商ID,获取完善信息的状态 -->
  546. <select id="selectPlaceInfoStatusByPlaceId" parameterType="Integer" resultType="Integer">
  547. SELECT
  548. PLACE_INFO_STATUS
  549. FROM
  550. TB_IAMBERRY_PLACE_INFO
  551. WHERE
  552. PLACE_ID = #{id}
  553. </select>
  554. <!-- 获取某一页的商户申请记录 -->
  555. <select id="selectApplyPlaceLogs" parameterType="PaperBean" resultType="ApplyPlaceLogs">
  556. SELECT
  557. <include refid="applyLogsAllField"/>
  558. FROM
  559. TB_IAMBERRY_PLACE_APPLY_LOGS
  560. ORDER BY
  561. APPLY_ID
  562. LIMIT
  563. #{minNum}, #{maxNum}
  564. </select>
  565. <!-- 获取待处理的总记录条数 -->
  566. <select id="getCount" resultType="int">
  567. SELECT
  568. COUNT(APPLY_ID)
  569. FROM
  570. TB_IAMBERRY_PLACE_APPLY_LOGS
  571. </select>
  572. <!-- 修改状态 -->
  573. <update id="updateApplyStatus" parameterType="ApplyPlaceLogs">
  574. UPDATE
  575. TB_IAMBERRY_PLACE_APPLY_LOGS
  576. SET
  577. APPLY_STATUS = #{applyStatus}
  578. WHERE
  579. APPLY_ID = #{applyID}
  580. </update>
  581. <!-- 获取某一个商户最近的申请记录 -->
  582. <select id="selectApplyLogsByPlaceID" parameterType="int" resultType="ApplyPlaceLogs">
  583. SELECT
  584. <include refid="applyLogsAllField"/>
  585. FROM
  586. TB_IAMBERRY_PLACE_APPLY_LOGS
  587. WHERE
  588. APPLY_TO_PLACEID = #{applyToPlaceID}
  589. ORDER BY
  590. APPLY_ID DESC
  591. LIMIT
  592. 0, 1
  593. </select>
  594. <!-- 获取某一个商户最近的申请记录 -->
  595. <select id="selectApplyLogsByOpenID" parameterType="String" resultType="ApplyPlaceLogs">
  596. SELECT
  597. <include refid="applyLogsAllField"/>
  598. FROM
  599. TB_IAMBERRY_PLACE_APPLY_LOGS
  600. WHERE
  601. APPLY_OPENID = #{applyOpenID}
  602. ORDER BY
  603. APPLY_ID DESC
  604. LIMIT
  605. 0, 1
  606. </select>
  607. <!-- 根据apply_id获取申请记录 -->
  608. <select id="selectApplyLogsByID" parameterType="int" resultType="ApplyPlaceLogs">
  609. SELECT
  610. <include refid="applyLogsAllField"/>
  611. FROM
  612. TB_IAMBERRY_PLACE_APPLY_LOGS
  613. WHERE
  614. APPLY_ID = #{applyID}
  615. </select>
  616. <!-- 修改代理商信息 -->
  617. <update id="updatePlaceInfo" parameterType="PlaceInfo">
  618. UPDATE
  619. TB_IAMBERRY_PLACE_INFO
  620. SET
  621. PLACE_NAME = #{name},
  622. PLACE_AREA = #{areaName},
  623. PLACE_USERNAME = #{userName},
  624. PLACE_TEL = #{tel},
  625. PLACE_INFO_STATUS = 2,
  626. PLACE_ADDR = #{addr}
  627. WHERE
  628. PLACE_ID = #{id}
  629. </update>
  630. <!-- 保存申请记录信息 -->
  631. <insert id="insertApplyLogs" parameterType="ApplyPlaceLogs"
  632. useGeneratedKeys="true" keyProperty="applyID">
  633. INSERT INTO
  634. TB_IAMBERRY_PLACE_APPLY_LOGS
  635. (
  636. APPLY_OPENID , APPLY_TO_PLACEID ,
  637. APPLY_NAME , APPLY_USERNAME , APPLY_TEL ,
  638. APPLY_AREA , APPLY_DATE, APPLY_STATUS, APPLY_ADDR
  639. )
  640. VALUES
  641. (
  642. #{applyOpenID}, #{applyToPlaceID}, #{applyName},
  643. #{applyUserName}, #{applyTel}, #{applyArea}, NOW(),
  644. 1, #{applyAddr}
  645. )
  646. </insert>
  647. <!-- 获取商户详情 -->
  648. <select id="selectPlaceInfoDetailByOpenId" resultType="PlaceInfo" parameterType="String">
  649. SELECT
  650. p.PLACE_ID id,
  651. u.USER_HEAD userHead,
  652. u.USER_NICKNAME userNickname,
  653. (select role_name from tb_iamberry_place_role where role_id=Place_role_id ) as roleName,
  654. p.PLACE_USERNAME userName,
  655. p.PLACE_TEL tel,
  656. p.PLACE_NAME name,
  657. p.PLACE_AREA areaName,
  658. p.PLACE_ADDR addr,
  659. p.PLACE_INFO_STATUS placeInfoStus
  660. FROM TB_IAMBERRY_PLACE_INFO p JOIN tb_iamberry_user_userinfo u ON p.place_openid=u.user_openid
  661. WHERE p.PLACE_OPENID = #{openid} and p.PLACE_STATUS=1
  662. </select>
  663. <!-- 我要代理申请信息页面 -->
  664. <sql id="applyAgentAllField">
  665. user_id userId,
  666. user_name userName,
  667. user_tel userTel,
  668. user_mail userMail,
  669. user_city userCity,
  670. user_tc userTc,
  671. user_date userDate
  672. </sql>
  673. <insert id="addApplyAgent" parameterType="ApplyUserInfo">
  674. insert into user_info
  675. (
  676. user_name,
  677. user_tel,
  678. user_mail,
  679. user_city,
  680. user_tc,
  681. user_date
  682. ) value (
  683. #{userName},
  684. #{userTel},
  685. #{userMail},
  686. #{userCity},
  687. #{userTc},
  688. #{userDate}
  689. )
  690. </insert>
  691. <select id="selectApplyAgentByTel" parameterType="String" resultType="Integer">
  692. SELECT count(*) from user_info where user_tel = #{userTel}
  693. </select>
  694. <!-- 分页查询代理申请记录信息表数据 -->
  695. <select id="getApplyAgentList" parameterType="ApplyUserInfo" resultType="ApplyUserInfo">
  696. SELECT
  697. <include refid="applyAgentAllField"/>
  698. FROM
  699. user_info
  700. <where>
  701. <if test="userName != null and userName != ''">
  702. user_name like CONCAT('%',#{userName},'%')
  703. or
  704. user_tel like CONCAT('%',#{userName},'%')
  705. </if>
  706. </where>
  707. LIMIT ${page.recordBegin},${page.pageSize}
  708. </select>
  709. <!-- 分页查询代理申请记录信息表数据条数 -->
  710. <select id="getApplyAgentCount" parameterType="ApplyUserInfo" resultType="Integer">
  711. SELECT
  712. COUNT(user_id) Num
  713. FROM
  714. user_info
  715. <where>
  716. <if test="userName != null and userName != ''">
  717. user_name like CONCAT('%',#{userName},'%')
  718. or
  719. user_tel like CONCAT('%',#{userName},'%')
  720. </if>
  721. </where>
  722. </select>
  723. <!-- 通过placepids查询商户信息 -->
  724. <select id="selectPlaceByPlacePids" resultType="PlaceInfo" parameterType="Integer">
  725. SELECT
  726. <include refid="palceInfoAllField" />
  727. FROM
  728. TB_IAMBERRY_PLACE_INFO
  729. WHERE
  730. PLACE_PIDS = #{placeIds}
  731. AND
  732. PLACE_STATUS = 1
  733. </select>
  734. <!-- 查询分销员商户购买商品的下线人数 -->
  735. <select id="getPlaceSalesUser" parameterType="PlaceInfo" resultType="Integer">
  736. SELECT
  737. COUNT(DISTINCT U.USER_ID)
  738. FROM
  739. TB_IAMBERRY_USER_USERINFO U
  740. LEFT JOIN
  741. TB_IAMBERRY_SHOP_SALES_ORDER O ON U.USER_OPENID = O.SALES_OPENID
  742. WHERE
  743. O.SALES_STATUS IN (2,5,12)
  744. <!-- 查询个人分销员 -->
  745. <if test="roleId == 55">
  746. AND U.USER_DEALERS = #{placeIds}
  747. </if>
  748. <!-- 查询公司分销员 -->
  749. <if test="roleId == 54">
  750. AND U.USER_DEALERS IN (SELECT
  751. P.PLACE_PIDS
  752. FROM
  753. TB_IAMBERRY_PLACE_INFO P
  754. WHERE
  755. P.PLACE_PID = #{id})
  756. </if>
  757. </select>
  758. <!-- 查询分销员下线总人数 -->
  759. <select id="getPlaceUser" parameterType="PlaceInfo" resultType="Integer">
  760. SELECT
  761. COUNT(DISTINCT U.USER_ID)
  762. FROM
  763. TB_IAMBERRY_USER_USERINFO U
  764. <where>
  765. <!-- 查询个人分销员 -->
  766. <if test="roleId == 55">
  767. U.USER_DEALERS = #{placeIds}
  768. </if>
  769. <!-- 查询公司分销员 -->
  770. <if test="roleId == 54">
  771. U.USER_DEALERS IN (SELECT
  772. P.PLACE_PIDS
  773. FROM
  774. TB_IAMBERRY_PLACE_INFO P
  775. WHERE
  776. P.PLACE_PID = #{id})
  777. </if>
  778. </where>
  779. </select>
  780. <!-- 查询商户的待返和已返金额 -->
  781. <!-- 添加 左链接 tb_iamberry_shop_sales_order 是为了过滤订单不为2,5,12的返利 -->
  782. <select id="listPlaceReback" parameterType="PlaceInfo" resultType="RebackInfo">
  783. SELECT
  784. REBACK_ID id,
  785. REBACK_TO_OPENID toOpenid,
  786. REBACK_FROM_OPENID fromOpenid,
  787. REBACK_ORDERID orderId,
  788. REBACK_USER_TYPE userType,
  789. REBACK_MONEY money,
  790. REBACK_CREATE_DATE createDate,
  791. REBACK_UPDATE_DATE updateDate,
  792. REBACK_FINISH_DATE finishDate,
  793. REBACK_STATUS status
  794. FROM
  795. TB_IAMBERRY_REBACK
  796. LEFT JOIN tb_iamberry_shop_sales_order TISSO ON TB_IAMBERRY_REBACK.REBACK_ORDERID = TISSO.sales_orderid
  797. WHERE
  798. REBACK_STATUS IN (1,2)
  799. AND TISSO.sales_status in (2,5,12)
  800. AND
  801. REBACK_USER_ID = #{id}
  802. ORDER BY REBACK_CREATE_DATE DESC
  803. <if test="page!=null and page.pageSize>0 ">
  804. LIMIT ${page.recordBegin},${page.pageSize}
  805. </if>
  806. </select>
  807. <!-- 查询商户已激活下线信息 -->
  808. <select id="listActivatePlace" parameterType="PlaceInfo" resultType="PlaceInfo">
  809. select <include refid="palceInfoAllField" />
  810. from tb_iamberry_place_info t
  811. <where>
  812. t.PLACE_PID = #{placePid}
  813. and t.PLACE_OPENID is not null
  814. </where>
  815. </select>
  816. <select id="getIsQrCode" parameterType="String" resultType="Integer">
  817. SELECT COUNT(*) from tb_iamberry_user_qrcode where qrcode_openid = #{id}
  818. </select>
  819. </mapper>