orderMapper.xml 99 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235
  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.OrderMapper">
  6. <resultMap type="Order" id="OrderResult">
  7. <result property="id" column="id" />
  8. <result property="outTradeNo" column="out_trade_no" />
  9. <result property="productId" column="product_id" />
  10. <result property="productName" column="product_name" />
  11. <result property="weight" column="weight" />
  12. <result property="takeDate" column="take_date" />
  13. <result property="takeTime" column="take_time" />
  14. <result property="takeRemark" column="take_remark" />
  15. <result property="paymentType" column="payment_type" />
  16. <result property="totalAmount" column="total_amount" />
  17. <result property="couponAmount" column="coupon_amount" />
  18. <result property="payAmount" column="pay_amount" />
  19. <result property="couponId" column="coupon_id" />
  20. <result property="sendAddressId" column="send_address_id" />
  21. <result property="sendProvinceName" column="send_province_name" />
  22. <result property="sendCityName" column="send_city_name" />
  23. <result property="sendDistrictName" column="send_district_name" />
  24. <result property="sendAddress" column="send_address" />
  25. <result property="sendContactName" column="send_contact_name" />
  26. <result property="sendPhone" column="send_phone" />
  27. <result property="receiptAddressId" column="receipt_address_id" />
  28. <result property="receiptProvinceName" column="receipt_province_name" />
  29. <result property="receiptCityName" column="receipt_city_name" />
  30. <result property="receiptDistrictName" column="receipt_district_name" />
  31. <result property="receiptAddress" column="receipt_address" />
  32. <result property="receiptContactName" column="receipt_contact_name" />
  33. <result property="receiptPhone" column="receipt_phone" />
  34. <result property="deliveryType" column="delivery_type" />
  35. <result property="preDeliveryIds" column="pre_delivery_ids" />
  36. <result property="actualDeliveryId" column="actual_delivery_id" />
  37. <result property="useTip" column="use_tip" />
  38. <result property="tipAmount" column="tip_amount" />
  39. <result property="status" column="status" />
  40. </resultMap>
  41. <select id="queryPage" resultType="com.ydd.module.domain.Order">
  42. SELECT * FROM lb_order WHERE 1 = 1
  43. <if test="params.memberId != null and params.memberId != ''">
  44. AND member_id = #{params.memberId}
  45. </if>
  46. <if test="params.outTradeNo != null and params.outTradeNo != ''">
  47. AND out_trade_no like concat('%', #{params.outTradeNo}, '%')
  48. </if>
  49. <if test="params.productName != null and params.productName != ''">
  50. AND product_name like concat('%', #{params.productName}, '%')
  51. </if>
  52. <if test="params.paymentType != null and params.paymentType != ''">
  53. AND payment_type = #{params.paymentType}
  54. </if>
  55. <if test="params.couponId != null and params.couponId != ''">
  56. AND coupon_id = #{params.couponId}
  57. </if>
  58. <if test="params.sendContactName != null and params.sendContactName != ''">
  59. AND send_contact_name like concat('%', #{params.sendContactName}, '%')
  60. </if>
  61. <if test="params.sendPhone != null and params.sendPhone != ''">
  62. AND send_phone like concat('%', #{params.sendPhone}, '%')
  63. </if>
  64. <if test="params.receiptContactName != null and params.receiptContactName != ''">
  65. AND receipt_contact_name like concat('%', #{params.receiptContactName}, '%')
  66. </if>
  67. <if test="params.receiptPhone != null and params.receiptPhone != ''">
  68. AND receipt_phone like concat('%', #{params.receiptPhone}, '%')
  69. </if>
  70. <if test="params.status != null">
  71. AND status = #{params.status}
  72. </if>
  73. <if test="memberIds != null">
  74. AND member_id IN
  75. <foreach collection="memberIds" index="index" item="item" open="(" separator="," close=")">
  76. #{item}
  77. </foreach>
  78. </if>
  79. ORDER BY lb_order.create_time DESC
  80. </select>
  81. <select id="queryPageList" resultType="com.ydd.module.dto.SystemOrderDto">
  82. SELECT
  83. o.id,
  84. o.waimai_order_id,
  85. o.merchant_id,
  86. o.take_type,
  87. o.order_sn,
  88. o.take_time,
  89. o.create_time,
  90. o.delivery_status,
  91. o.`status`,
  92. o.send_contact_name,
  93. o.send_phone,
  94. o.send_province_name,
  95. o.send_city_name,
  96. o.send_district_name,
  97. o.send_address,
  98. o.send_extension,
  99. o.receipt_contact_name,
  100. o.receipt_phone,
  101. o.receipt_province_name,
  102. o.receipt_city_name,
  103. o.receipt_district_name,
  104. o.receipt_address,
  105. o.receipt_extension,
  106. o.pay_amount,
  107. o.payment_type,
  108. o.product_name,
  109. o.weight,
  110. o.take_remark,
  111. o.out_trade_no,
  112. o.delivery_name,
  113. o.delivery_id,
  114. o.shipper_name,
  115. o.shipper_phone,
  116. o.cancel_reason,
  117. o.agent_Id,
  118. o.commission,
  119. o.total_amount,
  120. o.coupon_amount,
  121. o.tip_amount,
  122. o.first_coupon,
  123. o.product_amount,
  124. o.bind_fee,
  125. o.deleted,
  126. o.refund_money,
  127. o.dada_dsp_type,
  128. o.dada_dsp_id,
  129. wo.`status` AS wmstatus,
  130. wo.total_price AS puductMoney,
  131. wo.caution AS wmCaution,
  132. wo.delivery_time AS waimaiDeliveryTime,
  133. wo.order_type,
  134. wo.order_time,
  135. wo.day_seq,
  136. m.merchant_name AS merchantName,
  137. b.nickname AS memberName,
  138. b.mobile AS memberMobile,
  139. p.`name` AS personnelName,
  140. (select `name` from lb_shop as s where s.id = o.shop_id and s.deleted = 0 limit 1) AS shopName
  141. FROM lb_order o
  142. left join lb_merchant m ON o.merchant_id = m.id
  143. left join lb_member b ON o.member_id = b.id
  144. LEFT JOIN lb_waimai_order AS wo ON o.waimai_order_id = wo.id
  145. left join lb_personnel p on o.personnel_id = p.id
  146. <if test="(params.completeStartTime != null and params.completeStartTime != '') or (params.completeEndTime != null and params.completeEndTime != '')">
  147. LEFT JOIN lb_order_log AS ol ON o.id = ol.order_id
  148. </if>
  149. WHERE 1 = 1
  150. <if test="params.personnelName != null and params.personnelName != ''">
  151. AND p.`name` like concat('%', #{params.personnelName}, '%')
  152. </if>
  153. <if test="params.personnelId != null">
  154. and o.personnel_id = #{params.personnelId}
  155. </if>
  156. <if test="params.deliveryStatus != 6">
  157. AND o.deleted = 0
  158. </if>
  159. <if test="params.deliveryStatus == 6">
  160. AND o.deleted = 1
  161. </if>
  162. AND
  163. (
  164. not(
  165. o.delivery_status = 0
  166. AND o.`status` = 0
  167. AND wo.`status` != 0
  168. AND ( wo.`status` != 4 OR wo.`status` IS NULL )
  169. )
  170. or o.waimai_order_id in (select waimai_order_id from lb_order where deleted=1)
  171. or o.save_flag = 1
  172. )
  173. <if test="params.memberId != null and params.memberId != ''">
  174. AND o.member_id = #{params.memberId}
  175. </if>
  176. <if test="params.merchantId != null and params.merchantId != ''">
  177. AND o.merchant_id = #{params.merchantId}
  178. </if>
  179. <if test="params.merchantName != null and params.merchantName != ''">
  180. AND m.merchant_name like concat('%', #{params.merchantName}, '%')
  181. </if>
  182. <if test="params.deliveryId != null and params.deliveryId != '' and params.deliveryId != 100">
  183. AND o.delivery_id = #{params.deliveryId}
  184. </if>
  185. <if test="params.deliveryId != null and params.deliveryId != '' and params.deliveryId == 100">
  186. AND (wo.status = 4 and o.delivery_status != 4 and o.delivery_id is null )
  187. </if>
  188. <if test="params.createStartTime != null and params.createStartTime != ''">
  189. AND o.create_time >= #{params.createStartTime}
  190. </if>
  191. <if test="params.createEndTime != null and params.createEndTime != ''">
  192. AND #{params.createEndTime} >= o.create_time
  193. </if>
  194. <!-- <if test="params.completeStartTime != null and params.completeStartTime != ''">-->
  195. <!-- AND o.update_time >= #{params.completeStartTime} AND o.delivery_status = 4-->
  196. <!-- </if>-->
  197. <!-- <if test="params.completeEndTime != null and params.completeEndTime != ''">-->
  198. <!-- AND o.update_time &lt;= #{params.completeEndTime} AND o.delivery_status = 4-->
  199. <!-- </if>-->
  200. <if test="params.completeStartTime != null and params.completeStartTime != ''">
  201. AND ol.create_time >= #{params.completeStartTime} AND ol.order_status = 4
  202. </if>
  203. <if test="params.completeEndTime != null and params.completeEndTime != ''">
  204. AND ol.create_time &lt;= #{params.completeEndTime} AND ol.order_status = 4
  205. </if>
  206. <if test="params.deliveryStartTime != null and params.deliveryStartTime != ''">
  207. AND o.delivery_time >= #{params.deliveryStartTime}
  208. </if>
  209. <if test="params.deliveryEndTime != null and params.deliveryEndTime != ''">
  210. AND #{params.deliveryEndTime} >= o.delivery_time
  211. </if>
  212. <!-- <if test="params.outTradeNo != null and params.outTradeNo != ''">-->
  213. <!-- AND o.out_trade_no like concat('%', #{params.outTradeNo}, '%')-->
  214. <!-- </if>-->
  215. <!-- <if test="params.orderSn != null and params.orderSn != ''">-->
  216. <!-- AND o.order_sn like concat('%', #{params.orderSn}, '%')-->
  217. <!-- </if>-->
  218. <if test="params.orderSn != null and params.orderSn != ''">
  219. AND (o.order_sn like concat('%', #{params.orderSn}, '%') or o.out_trade_no like concat('%', #{params.orderSn}, '%'))
  220. </if>
  221. <if test="params.productName != null and params.productName != ''">
  222. AND o.product_name like concat('%', #{params.productName}, '%')
  223. </if>
  224. <if test="params.paymentType != null and params.paymentType != ''">
  225. AND o.payment_type = #{params.paymentType}
  226. </if>
  227. <if test="params.couponId != null and params.couponId != ''">
  228. AND o.coupon_id = #{params.couponId}
  229. </if>
  230. <if test="params.memberName != null and params.memberName != ''">
  231. AND b.nickname like concat('%', #{params.memberName}, '%')
  232. </if>
  233. <if test="params.memberMobile != null and params.memberMobile != ''">
  234. AND b.mobile like concat('%', #{params.memberMobile}, '%')
  235. </if>
  236. <if test="params.sendContactName != null and params.sendContactName != ''">
  237. AND o.send_contact_name like concat('%', #{params.sendContactName}, '%')
  238. </if>
  239. <if test="params.sendPhone != null and params.sendPhone != ''">
  240. AND o.send_phone like concat('%', #{params.sendPhone}, '%')
  241. </if>
  242. <if test="params.receiptContactName != null and params.receiptContactName != ''">
  243. AND o.receipt_contact_name like concat('%', #{params.receiptContactName}, '%')
  244. </if>
  245. <if test="params.receiptPhone != null and params.receiptPhone != ''">
  246. AND o.receipt_phone like concat('%', #{params.receiptPhone}, '%')
  247. </if>
  248. <if test="params.status != null">
  249. AND o.status = #{params.status}
  250. </if>
  251. <if test="params.deliveryStatus != null and params.deliveryStatus != 4 and params.deliveryStatus != 100 and params.deliveryStatus != 6">
  252. AND (o.delivery_status = #{params.deliveryStatus} and (wo.`status`!=4 or wo.`status` is null))
  253. </if>
  254. <!-- <if test="params.deliveryStatus != null and params.deliveryStatus == 0">-->
  255. <!-- AND ((wo.status is null or wo.status != 4) and o.delivery_status=0 and o.waimai_order_id is not null)-->
  256. <!-- </if>-->
  257. <if test="params.deliveryStatus != null and params.deliveryStatus == 4">
  258. AND o.delivery_status=4
  259. </if>
  260. <!-- <if test="params.deliveryStatus != null and params.deliveryStatus == 4">-->
  261. <!-- AND ((wo.`status` is null and o.delivery_status=4) or (wo.`status` =4 and o.delivery_status=4))-->
  262. <!-- </if>-->
  263. <!-- <if test="params.deliveryStatus != null and params.deliveryStatus == -1">-->
  264. <!-- AND (o.delivery_status = #{params.deliveryStatus} and wo.`status` != 4)-->
  265. <!-- </if>-->
  266. <!-- <if test="params.deliveryStatus != null and params.deliveryStatus == 1">-->
  267. <!-- AND (o.delivery_status = #{params.deliveryStatus} and wo.`status` != 4)-->
  268. <!-- </if>-->
  269. <if test="params.deliveryStatus != null and params.deliveryStatus == 100">
  270. AND (wo.status = 4 and o.delivery_status != 4)
  271. </if>
  272. <if test="params.agentId != null">
  273. AND
  274. o.agent_Id in
  275. <if test="agentIds.size > 0 and agentIds != null">
  276. <foreach collection="agentIds" index="index" item="item" open="(" separator="," close=")">
  277. #{item}
  278. </foreach>
  279. </if>
  280. </if>
  281. <if test="params.aId != null">
  282. AND
  283. o.agent_Id in
  284. <if test="aIds.size > 0 and aIds != null">
  285. <foreach collection="aIds" index="index" item="aid" open="(" separator="," close=")">
  286. #{aid}
  287. </foreach>
  288. </if>
  289. </if>
  290. <if test="params.receiptProvinceName != null and params.receiptProvinceName != ''">
  291. AND o.receipt_province_name like concat('%', #{params.receiptProvinceName}, '%')
  292. </if>
  293. <if test="params.receiptCityName != null and params.receiptCityName != ''">
  294. AND o.receipt_city_name like concat('%', #{params.receiptCityName}, '%')
  295. </if>
  296. <if test="params.receiptDistrictName != null and params.receiptDistrictName != ''">
  297. AND o.receipt_district_name like concat('%', #{params.receiptDistrictName}, '%')
  298. </if>
  299. <if test="params.sendProvinceName != null and params.sendProvinceName != ''">
  300. AND o.send_province_name like concat('%', #{params.sendProvinceName}, '%')
  301. </if>
  302. <if test="params.sendCityName != null and params.sendCityName != ''">
  303. AND o.send_city_name like concat('%', #{params.sendCityName}, '%')
  304. </if>
  305. <if test="params.sendDistrictName != null and params.sendDistrictName != ''">
  306. AND o.send_district_name like concat('%', #{params.sendDistrictName}, '%')
  307. </if>
  308. <if test="params.waimaiOrderType != null and params.waimaiOrderType != 4">
  309. AND wo.order_type = #{params.waimaiOrderType}
  310. </if>
  311. <if test="params.waimaiOrderType != null and params.waimaiOrderType == 4">
  312. AND o.waimai_order_id is null
  313. </if>
  314. <if test="params.paymentType != null">
  315. AND (o.payment_type = #{params.paymentType} and o.status != 0)
  316. </if>
  317. ORDER BY o.create_time DESC
  318. </select>
  319. <select id="queryPageListNew" resultType="com.ydd.module.dto.SystemOrderDto">
  320. SELECT
  321. o.id,
  322. o.waimai_order_id,
  323. o.merchant_id,
  324. o.shop_id,
  325. o.take_type,
  326. o.order_sn,
  327. o.take_time,
  328. o.create_time,
  329. o.delivery_status,
  330. o.status,
  331. o.send_contact_name,
  332. o.send_phone,
  333. o.send_province_name,
  334. o.send_city_name,
  335. o.send_district_name,
  336. o.send_address,
  337. o.send_extension,
  338. o.send_street,
  339. o.receipt_contact_name,
  340. o.receipt_phone,
  341. o.receipt_province_name,
  342. o.receipt_city_name,
  343. o.receipt_district_name,
  344. o.receipt_address,
  345. o.receipt_extension,
  346. o.receipt_street,
  347. o.pay_amount,
  348. o.payment_type,
  349. o.product_name,
  350. o.weight,
  351. o.take_remark,
  352. o.out_trade_no,
  353. o.delivery_name,
  354. o.delivery_id,
  355. o.shipper_name,
  356. o.shipper_phone,
  357. o.cancel_reason,
  358. o.agent_Id,
  359. o.commission,
  360. o.total_amount,
  361. o.coupon_amount,
  362. o.tip_amount,
  363. o.first_coupon,
  364. o.product_amount,
  365. o.bind_fee,
  366. o.deleted,
  367. o.refund_money,
  368. o.dada_dsp_type,
  369. o.dada_dsp_id,
  370. o.member_id,
  371. o.platform_type,
  372. wo.status AS wmstatus,
  373. wo.total_price AS puductMoney,
  374. wo.caution AS wmCaution,
  375. wo.delivery_time AS waimaiDeliveryTime,
  376. wo.order_type,
  377. wo.order_time,
  378. case when wo.day_seq is not null then wo.day_seq
  379. else o.lb_day_seq
  380. end as day_seq
  381. FROM lb_order o
  382. LEFT JOIN lb_waimai_order AS wo ON o.waimai_order_id = wo.id
  383. <if test="(params.completeStartTime != null and params.completeStartTime != '') or (params.completeEndTime != null and params.completeEndTime != '')">
  384. LEFT JOIN lb_order_log AS ol ON o.id = ol.order_id
  385. </if>
  386. WHERE 1 = 1
  387. <if test="params.createStartTime != null and params.createStartTime != ''">
  388. AND o.create_time >= #{params.createStartTime}
  389. </if>
  390. <if test="params.createEndTime != null and params.createEndTime != ''">
  391. AND #{params.createEndTime} >= o.create_time
  392. </if>
  393. <if test="params.completeStartTime != null and params.completeStartTime != ''">
  394. AND ol.create_time >= #{params.completeStartTime} AND ol.order_status = 4
  395. </if>
  396. <if test="params.completeEndTime != null and params.completeEndTime != ''">
  397. AND ol.create_time &lt;= #{params.completeEndTime} AND ol.order_status = 4
  398. </if>
  399. <!-- <if test="params.completeStartTime != null and params.completeStartTime != ''">-->
  400. <!-- AND-->
  401. <!-- (-->
  402. <!-- (o.waimai_order_id is not null AND o.update_time >= #{params.completeStartTime} AND o.delivery_status = 4)-->
  403. <!-- OR-->
  404. <!-- (o.waimai_order_id is null AND wo.update_time >= #{params.completeStartTime} AND wo.status = 4)-->
  405. <!-- )-->
  406. <!-- </if>-->
  407. <!-- <if test="params.completeEndTime != null and params.completeEndTime != ''">-->
  408. <!-- AND-->
  409. <!-- (-->
  410. <!-- (o.waimai_order_id is not null AND o.update_time &lt;= #{params.completeEndTime} AND o.delivery_status = 4)-->
  411. <!-- OR-->
  412. <!-- (o.waimai_order_id is null AND wo.update_time &lt;= #{params.completeEndTime} AND wo.status = 4)-->
  413. <!-- )-->
  414. <!-- </if>-->
  415. <if test="params.agentIds != null and params.agentIds.size > 0">
  416. AND
  417. o.agent_Id in
  418. <foreach collection="params.agentIds" index="index" item="item" open="(" separator="," close=")">
  419. #{item}
  420. </foreach>
  421. </if>
  422. <if test="params.merchantIds != null and params.merchantIds.size > 0">
  423. AND
  424. o.merchant_id in
  425. <foreach collection="params.merchantIds" index="index" item="item" open="(" separator="," close=")">
  426. #{item}
  427. </foreach>
  428. </if>
  429. <if test="params.memberIds != null and params.memberIds.size > 0">
  430. AND
  431. o.member_id in
  432. <foreach collection="params.memberIds" index="index" item="item" open="(" separator="," close=")">
  433. #{item}
  434. </foreach>
  435. </if>
  436. <if test="params.personnelIds != null and params.personnelIds.size > 0">
  437. AND
  438. o.personnel_id in
  439. <foreach collection="params.personnelIds" index="index" item="item" open="(" separator="," close=")">
  440. #{item}
  441. </foreach>
  442. </if>
  443. <if test="params.personnelId != null">
  444. and o.personnel_id = #{params.personnelId}
  445. </if>
  446. <if test="params.deliveryStatus != 6">
  447. AND o.deleted = 0
  448. </if>
  449. <if test="params.deliveryStatus == 6">
  450. AND o.deleted = 1
  451. </if>
  452. AND
  453. (
  454. not(
  455. o.delivery_status = 0
  456. AND o.status = 0
  457. AND wo.status != 0
  458. AND ( wo.status != 4 OR wo.status IS NULL )
  459. )
  460. or o.waimai_order_id in (select waimai_order_id from lb_order where deleted=1)
  461. or o.save_flag = 1
  462. )
  463. <if test="params.memberId != null and params.memberId != ''">
  464. AND o.member_id = #{params.memberId}
  465. </if>
  466. <if test="params.merchantId != null and params.merchantId != ''">
  467. AND o.merchant_id = #{params.merchantId}
  468. </if>
  469. <if test="params.deliveryId != null and params.deliveryId != '' and params.deliveryId != 100">
  470. AND o.delivery_id = #{params.deliveryId}
  471. </if>
  472. <if test="params.deliveryId != null and params.deliveryId != '' and params.deliveryId == 100">
  473. AND (wo.status = 4 and o.delivery_status != 4 and o.delivery_id is null )
  474. </if>
  475. <if test="params.deliveryStartTime != null and params.deliveryStartTime != ''">
  476. AND o.delivery_time >= #{params.deliveryStartTime}
  477. </if>
  478. <if test="params.deliveryEndTime != null and params.deliveryEndTime != ''">
  479. AND #{params.deliveryEndTime} >= o.delivery_time
  480. </if>
  481. <if test="params.orderSn != null and params.orderSn != ''">
  482. AND (o.order_sn like concat('%', #{params.orderSn}, '%') or o.out_trade_no like concat('%', #{params.orderSn}, '%'))
  483. </if>
  484. <if test="params.productName != null and params.productName != ''">
  485. AND o.product_name like concat('%', #{params.productName}, '%')
  486. </if>
  487. <if test="params.paymentType != null and params.paymentType != ''">
  488. AND o.payment_type = #{params.paymentType}
  489. </if>
  490. <if test="params.couponId != null and params.couponId != ''">
  491. AND o.coupon_id = #{params.couponId}
  492. </if>
  493. <if test="params.sendContactName != null and params.sendContactName != ''">
  494. AND o.send_contact_name like concat('%', #{params.sendContactName}, '%')
  495. </if>
  496. <if test="params.sendPhone != null and params.sendPhone != ''">
  497. AND o.send_phone like concat('%', #{params.sendPhone}, '%')
  498. </if>
  499. <if test="params.receiptContactName != null and params.receiptContactName != ''">
  500. AND o.receipt_contact_name like concat('%', #{params.receiptContactName}, '%')
  501. </if>
  502. <if test="params.receiptPhone != null and params.receiptPhone != ''">
  503. AND o.receipt_phone like concat('%', #{params.receiptPhone}, '%')
  504. </if>
  505. <if test="params.status != null">
  506. AND o.status = #{params.status}
  507. </if>
  508. <if test="params.deliveryStatus != null and params.deliveryStatus != 4 and params.deliveryStatus != 100 and params.deliveryStatus != 6">
  509. AND (o.delivery_status = #{params.deliveryStatus} and (wo.`status`!=4 or wo.`status` is null))
  510. </if>
  511. <if test="params.deliveryStatus != null and params.deliveryStatus == 4">
  512. AND o.delivery_status=4
  513. </if>
  514. <if test="params.deliveryStatus != null and params.deliveryStatus == 100">
  515. AND (wo.status = 4 and o.delivery_status != 4)
  516. </if>
  517. <if test="params.receiptProvinceName != null and params.receiptProvinceName != ''">
  518. AND o.receipt_province_name like concat('%', #{params.receiptProvinceName}, '%')
  519. </if>
  520. <if test="params.receiptCityName != null and params.receiptCityName != ''">
  521. AND o.receipt_city_name like concat('%', #{params.receiptCityName}, '%')
  522. </if>
  523. <if test="params.receiptDistrictName != null and params.receiptDistrictName != ''">
  524. AND o.receipt_district_name like concat('%', #{params.receiptDistrictName}, '%')
  525. </if>
  526. <if test="params.sendProvinceName != null and params.sendProvinceName != ''">
  527. AND o.send_province_name like concat('%', #{params.sendProvinceName}, '%')
  528. </if>
  529. <if test="params.sendCityName != null and params.sendCityName != ''">
  530. AND o.send_city_name like concat('%', #{params.sendCityName}, '%')
  531. </if>
  532. <if test="params.sendDistrictName != null and params.sendDistrictName != ''">
  533. AND o.send_district_name like concat('%', #{params.sendDistrictName}, '%')
  534. </if>
  535. <if test="params.waimaiOrderType != null and params.waimaiOrderType != 4">
  536. AND wo.order_type = #{params.waimaiOrderType}
  537. </if>
  538. <if test="params.waimaiOrderType != null and params.waimaiOrderType == 4">
  539. AND o.waimai_order_id is null
  540. </if>
  541. <if test="params.paymentType != null">
  542. AND (o.payment_type = #{params.paymentType} and o.status != 0)
  543. </if>
  544. <if test="params.shopIds != null and params.shopIds.size > 0">
  545. AND
  546. o.shop_id in
  547. <foreach collection="params.shopIds" index="index" item="item" open="(" separator="," close=")">
  548. #{item}
  549. </foreach>
  550. </if>
  551. ORDER BY o.create_time DESC
  552. </select>
  553. <select id="findOneKeyList" resultType="com.ydd.module.dto.OrderDetailDto">
  554. SELECT
  555. o.id,
  556. o.member_id,
  557. o.waimai_order_id,
  558. o.order_sn,
  559. o.out_trade_no,
  560. o.product_id,
  561. o.product_name,
  562. o.weight,
  563. o.take_type,
  564. o.take_date,
  565. o.take_time,
  566. o.payment_type,
  567. o.total_amount,
  568. o.pay_amount,
  569. o.coupon_id,
  570. o.receipt_address_id,
  571. o.receipt_province_name,
  572. o.receipt_city_name,
  573. o.receipt_district_name,
  574. o.receipt_address,
  575. o.receipt_contact_name,
  576. o.receipt_phone,
  577. o.receipt_extension,
  578. o.receipt_city_code,
  579. o.receipt_lng,
  580. o.receipt_lat,
  581. o.receipt_street,
  582. o.send_address_id,
  583. o.send_province_name,
  584. o.send_city_name,
  585. o.send_district_name,
  586. o.send_address,
  587. o.send_contact_name,
  588. o.send_phone,
  589. o.send_extension,
  590. o.send_city_code,
  591. o.send_lng,
  592. o.send_lat,
  593. o.send_street,
  594. o.shop_id,
  595. o.shop_name,
  596. o.order_distance,
  597. o.delivery_status,
  598. o.delivery_id,
  599. o.delivery_logo,
  600. o.delivery_name,
  601. o.use_tip,
  602. o.tip_amount,
  603. o.take_remark,
  604. o.delivery_time,
  605. o.cancel_type,
  606. o.cancel_reason,
  607. o.merchant_id,
  608. o.shipper_name,
  609. o.shipper_phone,
  610. o.delivery_logo,
  611. o.delivery_name,
  612. o.agent_id,
  613. o.update_time,
  614. case when o.waimai_order_id is not null then wo.total_price
  615. else o.product_amount
  616. end as productAmount,
  617. wo.out_order_id,
  618. wo.caution,
  619. wo.waimai_id,
  620. wo.order_type,
  621. wo.status as wmstatus,
  622. wo.delivery_time exceptTime,
  623. wo.order_time orderTime,
  624. d.delay_time,
  625. case when wo.day_seq is not null then wo.day_seq
  626. else o.lb_day_seq
  627. end as day_seq
  628. FROM lb_order as o FORCE INDEX(idx_order_shop_id)
  629. left join lb_waimai_order as wo on o.waimai_order_id = wo.id
  630. LEFT JOIN lb_order_delay d on o.id = d.order_id and d.deleted = 0
  631. WHERE o.waimai_order_id is not null and o.deleted = 0
  632. <!-- <if test="memberId != null and memberId != ''">
  633. AND (o.member_id = #{memberId}
  634. <if test="spId != null and memberId != ''">
  635. OR o.shop_id = #{spId}
  636. </if>)
  637. </if>-->
  638. <if test="shopIds != null">
  639. AND o.shop_id IN
  640. <foreach collection="shopIds" index="index" item="item" open="(" separator="," close=")">
  641. #{item}
  642. </foreach>
  643. </if>
  644. <if test="oldStatus == 0">
  645. <if test="status != null and status != '' and status !=0 and status !=4 and status!=10">
  646. AND (o.delivery_status = #{status} and wo.status !=4)
  647. </if>
  648. </if>
  649. <if test="oldStatus == 1">
  650. AND (o.delivery_status in (-1,-2) and wo.status !=4)
  651. </if>
  652. <!-- <if test="status != null and status != '' and status !=0 and status !=4 and status!=10">-->
  653. <!-- AND (o.delivery_status = #{status} and wo.status !=4)-->
  654. <!-- </if>-->
  655. <if test="status != null and status != '' and status==4">
  656. AND (o.delivery_status = #{status} or wo.status = 4)
  657. </if>
  658. <if test="status == 0">
  659. AND (o.delivery_status = 0 and wo.status !=4 and wo.delivery_time=0)
  660. </if>
  661. <if test="status == 10">
  662. AND ( wo.delivery_time> 0 and wo.status !=4 and o.delivery_status = 0 )
  663. </if>
  664. <if test="searchKey != null and searchKey != ''">
  665. AND (o.receipt_address like concat('%', #{searchKey}, '%') or wo.out_order_id like concat('%', #{searchKey}, '%'))
  666. </if>
  667. <if test="shopId != null and shopId != ''">
  668. AND o.shop_id = #{shopId}
  669. </if>
  670. <if test="startDate != null and startDate!=''">
  671. AND DATE_FORMAT(o.create_time,'%Y-%m-%d') >= DATE_FORMAT(#{startDate},'%Y-%m-%d')
  672. </if>
  673. <if test="endDate != null and endDate!=''">
  674. AND DATE_FORMAT(o.create_time,'%Y-%m-%d') &lt;= DATE_FORMAT(#{endDate},'%Y-%m-%d')
  675. </if>
  676. <if test="waimaiId != null and waimaiId != ''">
  677. AND wo.waimai_id = #{waimaiId}
  678. </if>
  679. <if test="status == 10">
  680. ORDER BY wo.delivery_time asc
  681. </if>
  682. <if test="status != 10 and status !=-2">
  683. ORDER BY o.create_time DESC
  684. </if>
  685. <!-- <if test="status == -2">-->
  686. <!-- ORDER BY o.id DESC-->
  687. <!-- </if>-->
  688. </select>
  689. <select id="findList" resultType="com.ydd.module.domain.Order">
  690. select * from lb_order
  691. where member_id IN
  692. <foreach collection="memberId" index="index" item="memberId" open="(" separator="," close=")">
  693. #{memberId}
  694. </foreach>
  695. and waimai_order_id is null and deleted = 0
  696. <if test="status != null and status != ''">
  697. AND delivery_status = #{status}
  698. </if>
  699. <if test="status == 0">
  700. AND delivery_status = 0
  701. </if>
  702. <if test="searchKey != null and searchKey != ''">
  703. AND (receipt_address like concat('%', #{searchKey}, '%') or order_sn like concat('%', #{searchKey}, '%'))
  704. </if>
  705. <if test="shopId != null ">
  706. AND shop_id = #{shopId}
  707. </if>
  708. <if test="startDate != null and startDate!=''">
  709. AND DATE_FORMAT(create_time,'%Y-%m-%d') >= DATE_FORMAT(#{startDate},'%Y-%m-%d')
  710. </if>
  711. <if test="endDate != null and endDate!=''">
  712. AND DATE_FORMAT(create_time,'%Y-%m-%d') &lt;= DATE_FORMAT(#{endDate},'%Y-%m-%d')
  713. </if>
  714. ORDER BY create_time DESC
  715. </select>
  716. <select id="getDetail" resultType="com.ydd.module.domain.Order">
  717. select * from lb_order
  718. where member_id IN
  719. <foreach collection="memberId" index="index" item="memberId" open="(" separator="," close=")">
  720. #{memberId}
  721. </foreach>
  722. and id = #{orderId}
  723. </select>
  724. <select id="getDetailByShopId" resultType="com.ydd.module.domain.Order">
  725. select * from lb_order
  726. where shop_id IN
  727. <foreach collection="shopIds" index="index" item="shopIds" open="(" separator="," close=")">
  728. #{shopIds}
  729. </foreach>
  730. and id = #{orderId}
  731. </select>
  732. <select id="getOrderNum" resultType="java.lang.Integer">
  733. SELECT count(id) FROM lb_order WHERE delivery_status = 4
  734. <if test="shopIds != null and shopIds.size > 0">
  735. AND shop_id IN
  736. <foreach collection="shopIds" index="index" item="shopId" open="(" separator="," close=")">
  737. #{shopId}
  738. </foreach>
  739. </if>
  740. <if test="startDate != null and startDate != ''">
  741. AND create_time >= #{startDate}
  742. </if>
  743. </select>
  744. <select id="getOrderAmount" resultType="java.math.BigDecimal">
  745. SELECT COALESCE(SUM(pay_amount),0) FROM lb_order WHERE delivery_status = 4
  746. <if test="shopIds != null and shopIds.size > 0">
  747. AND shop_id IN
  748. <foreach collection="shopIds" index="index" item="shopId" open="(" separator="," close=")">
  749. #{shopId}
  750. </foreach>
  751. </if>
  752. <if test="startDate != null and startDate != ''">
  753. AND create_time >= #{startDate}
  754. </if>
  755. </select>
  756. <select id="queryTimeOutOrder" resultType="com.ydd.module.domain.Order">
  757. SELECT * FROM lb_order WHERE delivery_status = 1 and deleted=0 and dada_dsp_id is null and create_time &lt;= date_sub(now(), interval #{time} minute)
  758. </select>
  759. <select id="sumOrder" resultType="com.ydd.module.domain.Order">
  760. <!-- SELECT-->
  761. <!-- COALESCE(count(id), 0) AS deliveryNum,-->
  762. <!-- COALESCE(sum(total_amount), 0) AS expenses,-->
  763. <!-- COALESCE(sum(pay_amount), 0) AS payMoney-->
  764. <!-- FROM lb_order-->
  765. <!-- WHERE deleted = 0 AND delivery_status = #{status}-->
  766. SELECT DISTINCT o.*
  767. FROM lb_order o join lb_payment p on o.order_sn = p.order_sn and p.pay_status=1
  768. WHERE o.deleted = 0
  769. <!-- <if test="shopId != null and shopId!=0">-->
  770. <!-- AND o.shop_id = #{shopId}-->
  771. <!-- </if>-->
  772. <if test="shopIds != null">
  773. AND o.shop_id IN
  774. <foreach collection="shopIds" index="index" item="item" open="(" separator="," close=")">
  775. #{item}
  776. </foreach>
  777. </if>
  778. <if test="startTime != null and startTime != ''">
  779. AND to_days(o.create_time) >= to_days(#{startTime})
  780. </if>
  781. <if test="endTime != null and endTime != ''">
  782. AND to_days(#{endTime}) >= to_days(o.create_time)
  783. </if>
  784. <if test="timeType != null and timeType == 1 and (startTime == null or startTime == '') and (endTime == null or endTime == '')">
  785. AND to_days(o.create_time) = to_days(NOW())
  786. </if>
  787. <if test="timeType != null and timeType == 2 and (startTime == null or startTime == '') and (endTime == null or endTime == '')">
  788. AND to_days(NOW()) - to_days( o.create_time) = 1
  789. </if>
  790. <if test="timeType != null and timeType == 3 and (startTime == null or startTime == '') and (endTime == null or endTime == '')">
  791. AND DATE_FORMAT( o.create_time, '%Y%m' ) = DATE_FORMAT( CURDATE( ) , '%Y%m' )
  792. </if>
  793. <if test="deliveryId != null">
  794. AND o.delivery_id = #{deliveryId}
  795. </if>
  796. <!-- <if test="loginId != null">-->
  797. <!-- AND o.member_id = #{loginId}-->
  798. <!-- </if>-->
  799. </select>
  800. <select id="sumOrder1" resultType="com.ydd.module.dto.OrderSumDto">
  801. SELECT
  802. COALESCE(sum(total_amount), 0) AS refund
  803. FROM lb_order
  804. WHERE deleted = 0 AND delivery_status = #{status}
  805. <if test="shopId != null and shopId!=0">
  806. AND shop_id = #{shopId}
  807. </if>
  808. <if test="startTime != null and startTime != ''">
  809. AND to_days(create_time) >= to_days(#{startTime})
  810. </if>
  811. <if test="endTime != null and endTime != ''">
  812. AND to_days(#{endTime}) >= to_days(create_time)
  813. </if>
  814. <if test="timeType != null and timeType == 1 and (startTime == null or startTime == '') and (endTime == null or endTime == '')">
  815. AND to_days(create_time) = to_days(NOW())
  816. </if>
  817. <if test="timeType != null and timeType == 2 and (startTime == null or startTime == '') and (endTime == null or endTime == '')">
  818. AND to_days(NOW()) - to_days( create_time) = 1
  819. </if>
  820. <if test="timeType != null and timeType == 3 and (startTime == null or startTime == '') and (endTime == null or endTime == '')">
  821. AND DATE_FORMAT( create_time, '%Y%m' ) = DATE_FORMAT( CURDATE( ) , '%Y%m' )
  822. </if>
  823. <if test="loginId != null">
  824. AND member_id = #{loginId}
  825. </if>
  826. </select>
  827. <select id="getByStatus" resultType="com.ydd.module.domain.Order">
  828. select * from lb_order WHERE delivery_status = 4 and deleted = 0 and create_time &lt;= '2021-06-28 21:00:00'
  829. </select>
  830. <select id="selectCountByStatusNew" resultType="com.ydd.module.dto.SystemOrderDto">
  831. SELECT
  832. o.id,
  833. wo.status AS wmStatus,
  834. o.delivery_status
  835. FROM lb_order AS o
  836. LEFT JOIN lb_waimai_order AS wo ON o.waimai_order_id = wo.id
  837. <if test="(params.completeStartTime != null and params.completeStartTime != '') or (params.completeEndTime != null and params.completeEndTime != '')">
  838. LEFT JOIN lb_order_log AS ol ON o.id = ol.order_id
  839. </if>
  840. WHERE 1 = 1
  841. <if test="params.createStartTime != null and params.createStartTime != ''">
  842. AND o.create_time >= #{params.createStartTime}
  843. </if>
  844. <if test="params.createEndTime != null and params.createEndTime != ''">
  845. AND #{params.createEndTime} >= o.create_time
  846. </if>
  847. <if test="params.completeStartTime != null and params.completeStartTime != ''">
  848. AND ol.create_time >= #{params.completeStartTime} AND ol.order_status = 4
  849. </if>
  850. <if test="params.completeEndTime != null and params.completeEndTime != ''">
  851. AND ol.create_time &lt;= #{params.completeEndTime} AND ol.order_status = 4
  852. </if>
  853. <!-- <if test="params.completeStartTime != null and params.completeStartTime != ''">-->
  854. <!-- AND-->
  855. <!-- (-->
  856. <!-- (o.waimai_order_id is not null AND o.update_time >= #{params.completeStartTime} AND o.delivery_status = 4)-->
  857. <!-- OR-->
  858. <!-- (o.waimai_order_id is null AND wo.update_time >= #{params.completeStartTime} AND wo.status = 4)-->
  859. <!-- )-->
  860. <!-- </if>-->
  861. <!-- <if test="params.completeEndTime != null and params.completeEndTime != ''">-->
  862. <!-- AND-->
  863. <!-- (-->
  864. <!-- (o.waimai_order_id is not null AND o.update_time &lt;= #{params.completeEndTime} AND o.delivery_status = 4)-->
  865. <!-- OR-->
  866. <!-- (o.waimai_order_id is null AND wo.update_time &lt;= #{params.completeEndTime} AND wo.status = 4)-->
  867. <!-- )-->
  868. <!-- </if>-->
  869. AND
  870. (
  871. not(
  872. o.delivery_status = 0
  873. AND o.`status` = 0
  874. AND wo.`status` != 0
  875. AND ( wo.`status` != 4 OR wo.`status` IS NULL )
  876. )
  877. or o.waimai_order_id in (select waimai_order_id from lb_order where deleted=1)
  878. or o.save_flag = 1
  879. )
  880. <if test="params.agentIds != null and params.agentIds.size > 0">
  881. AND
  882. o.agent_Id in
  883. <foreach collection="params.agentIds" index="index" item="item" open="(" separator="," close=")">
  884. #{item}
  885. </foreach>
  886. </if>
  887. <if test="params.merchantIds != null and params.merchantIds.size > 0">
  888. AND
  889. o.merchant_id in
  890. <foreach collection="params.merchantIds" index="index" item="item" open="(" separator="," close=")">
  891. #{item}
  892. </foreach>
  893. </if>
  894. <if test="params.memberIds != null and params.memberIds.size > 0">
  895. AND
  896. o.member_id in
  897. <foreach collection="params.memberIds" index="index" item="item" open="(" separator="," close=")">
  898. #{item}
  899. </foreach>
  900. </if>
  901. <if test="params.personnelIds != null and params.personnelIds.size > 0">
  902. AND
  903. o.personnel_id in
  904. <foreach collection="params.personnelIds" index="index" item="item" open="(" separator="," close=")">
  905. #{item}
  906. </foreach>
  907. </if>
  908. <if test="params.personnelId != null">
  909. and o.personnel_id = #{params.personnelId}
  910. </if>
  911. <if test="params.deliveryStatus != 6">
  912. AND o.deleted = 0
  913. </if>
  914. <if test="params.deliveryStatus == 6">
  915. AND o.deleted = 1
  916. </if>
  917. <if test="params.memberId != null and params.memberId != ''">
  918. AND o.member_id = #{params.memberId}
  919. </if>
  920. <if test="params.merchantId != null and params.merchantId != ''">
  921. AND o.merchant_id = #{params.merchantId}
  922. </if>
  923. <if test="params.deliveryId != null and params.deliveryId != '' and params.deliveryId != 100">
  924. AND o.delivery_id = #{params.deliveryId}
  925. </if>
  926. <if test="params.deliveryId != null and params.deliveryId != '' and params.deliveryId == 100">
  927. AND (wo.status = 4 and o.delivery_status != 4 and o.delivery_id is null )
  928. </if>
  929. <if test="params.deliveryStartTime != null and params.deliveryStartTime != ''">
  930. AND o.delivery_time >= #{params.deliveryStartTime}
  931. </if>
  932. <if test="params.deliveryEndTime != null and params.deliveryEndTime != ''">
  933. AND #{params.deliveryEndTime} >= o.delivery_time
  934. </if>
  935. <if test="params.orderSn != null and params.orderSn != ''">
  936. AND (o.order_sn like concat('%', #{params.orderSn}, '%') or o.out_trade_no like concat('%', #{params.orderSn}, '%'))
  937. </if>
  938. <if test="params.productName != null and params.productName != ''">
  939. AND o.product_name like concat('%', #{params.productName}, '%')
  940. </if>
  941. <if test="params.paymentType != null and params.paymentType != ''">
  942. AND o.payment_type = #{params.paymentType}
  943. </if>
  944. <if test="params.couponId != null and params.couponId != ''">
  945. AND o.coupon_id = #{params.couponId}
  946. </if>
  947. <if test="params.sendContactName != null and params.sendContactName != ''">
  948. AND o.send_contact_name like concat('%', #{params.sendContactName}, '%')
  949. </if>
  950. <if test="params.sendPhone != null and params.sendPhone != ''">
  951. AND o.send_phone like concat('%', #{params.sendPhone}, '%')
  952. </if>
  953. <if test="params.receiptContactName != null and params.receiptContactName != ''">
  954. AND o.receipt_contact_name like concat('%', #{params.receiptContactName}, '%')
  955. </if>
  956. <if test="params.receiptPhone != null and params.receiptPhone != ''">
  957. AND o.receipt_phone like concat('%', #{params.receiptPhone}, '%')
  958. </if>
  959. <if test="params.status != null">
  960. AND o.status = #{params.status}
  961. </if>
  962. <if test="params.receiptProvinceName != null and params.receiptProvinceName != ''">
  963. AND o.receipt_province_name like concat('%', #{params.receiptProvinceName}, '%')
  964. </if>
  965. <if test="params.receiptCityName != null and params.receiptCityName != ''">
  966. AND o.receipt_city_name like concat('%', #{params.receiptCityName}, '%')
  967. </if>
  968. <if test="params.receiptDistrictName != null and params.receiptDistrictName != ''">
  969. AND o.receipt_district_name like concat('%', #{params.receiptDistrictName}, '%')
  970. </if>
  971. <if test="params.sendProvinceName != null and params.sendProvinceName != ''">
  972. AND o.send_province_name like concat('%', #{params.sendProvinceName}, '%')
  973. </if>
  974. <if test="params.sendCityName != null and params.sendCityName != ''">
  975. AND o.send_city_name like concat('%', #{params.sendCityName}, '%')
  976. </if>
  977. <if test="params.sendDistrictName != null and params.sendDistrictName != ''">
  978. AND o.send_district_name like concat('%', #{params.sendDistrictName}, '%')
  979. </if>
  980. <if test="params.waimaiOrderType != null and params.waimaiOrderType != 4">
  981. AND wo.order_type = #{params.waimaiOrderType}
  982. </if>
  983. <if test="params.waimaiOrderType != null and params.waimaiOrderType == 4">
  984. AND o.waimai_order_id is null
  985. </if>
  986. <if test="params.paymentType != null">
  987. AND (o.payment_type = #{params.paymentType} and o.status != 0)
  988. </if>
  989. <if test="params.shopIds != null and params.shopIds.size > 0">
  990. AND
  991. o.shop_id in
  992. <foreach collection="params.shopIds" index="index" item="item" open="(" separator="," close=")">
  993. #{item}
  994. </foreach>
  995. </if>
  996. </select>
  997. <select id="selectExportOrder" resultType="com.ydd.module.dto.OrderExportDto">
  998. SELECT
  999. o.id,
  1000. o.order_sn,
  1001. o.pay_amount,
  1002. o.payment_type,
  1003. COALESCE(o.coupon_amount+o.first_coupon,0) AS discountAmount,
  1004. o.tip_amount,
  1005. b.nickname AS memberName,
  1006. b.mobile AS memberMobile,
  1007. o.send_contact_name,
  1008. o.send_phone,
  1009. o.send_extension,
  1010. o.receipt_contact_name,
  1011. o.receipt_phone,
  1012. o.receipt_extension,
  1013. o.delivery_name,
  1014. m.merchant_name AS merchantName,
  1015. o.`status`,
  1016. o.delivery_status,
  1017. o.deleted,
  1018. wo.status AS wmstatus,
  1019. wo.order_time,
  1020. o.create_time,
  1021. o.waimai_order_id,
  1022. (select create_time from lb_order_log as lol where lol.order_id = o.id and lol.order_status = 4 limit 1) AS finishTime
  1023. FROM lb_order o
  1024. left join lb_merchant m ON o.merchant_id = m.id
  1025. left join lb_member b ON o.member_id = b.id
  1026. LEFT JOIN lb_waimai_order AS wo ON o.waimai_order_id = wo.id
  1027. left join lb_personnel p on o.personnel_id = p.id
  1028. <if test="(params.completeStartTime != null and params.completeStartTime != '') or (params.completeEndTime != null and params.completeEndTime != '')">
  1029. LEFT JOIN lb_order_log AS ol ON o.id = ol.order_id
  1030. </if>
  1031. WHERE 1 = 1 AND o.create_time BETWEEN date_sub( now( ), INTERVAL 2 MONTH ) AND now( )
  1032. AND
  1033. (
  1034. not(
  1035. o.delivery_status = 0
  1036. AND o.`status` = 0
  1037. AND wo.`status` != 0
  1038. AND ( wo.`status` != 4 OR wo.`status` IS NULL )
  1039. )
  1040. or o.waimai_order_id in (select waimai_order_id from lb_order where deleted=1)
  1041. or o.save_flag = 1
  1042. )
  1043. <if test="params.personnelName != null and params.personnelName != ''">
  1044. AND p.`name` like concat('%', #{params.personnelName}, '%')
  1045. </if>
  1046. <if test="params.personnelId != null">
  1047. and o.personnel_id = #{params.personnelId}
  1048. </if>
  1049. <if test="params.deliveryStatus != 6">
  1050. AND o.deleted = 0
  1051. </if>
  1052. <if test="params.deliveryStatus == 6">
  1053. AND o.deleted = 1
  1054. </if>
  1055. <if test="params.memberId != null and params.memberId != ''">
  1056. AND o.member_id = #{params.memberId}
  1057. </if>
  1058. <if test="params.merchantId != null and params.merchantId != ''">
  1059. AND o.merchant_id = #{params.merchantId}
  1060. </if>
  1061. <if test="params.merchantName != null and params.merchantName != ''">
  1062. AND m.merchant_name like concat('%', #{params.merchantName}, '%')
  1063. </if>
  1064. <if test="params.deliveryId != null and params.deliveryId != '' and params.deliveryId != 100">
  1065. AND o.delivery_id = #{params.deliveryId}
  1066. </if>
  1067. <if test="params.deliveryId != null and params.deliveryId != '' and params.deliveryId == 100">
  1068. AND (wo.status = 4 and o.delivery_status != 4 and o.delivery_id is null )
  1069. </if>
  1070. <if test="params.createStartTime != null and params.createStartTime != ''">
  1071. AND o.create_time >= #{params.createStartTime}
  1072. </if>
  1073. <if test="params.createEndTime != null and params.createEndTime != ''">
  1074. AND #{params.createEndTime} >= o.create_time
  1075. </if>
  1076. <if test="params.completeStartTime != null and params.completeStartTime != ''">
  1077. AND ol.create_time >= #{params.completeStartTime} AND ol.order_status = 4
  1078. </if>
  1079. <if test="params.completeEndTime != null and params.completeEndTime != ''">
  1080. AND ol.create_time &lt;= #{params.completeEndTime} AND ol.order_status = 4
  1081. </if>
  1082. <if test="params.deliveryStartTime != null and params.deliveryStartTime != ''">
  1083. AND o.delivery_time >= #{params.deliveryStartTime}
  1084. </if>
  1085. <if test="params.deliveryEndTime != null and params.deliveryEndTime != ''">
  1086. AND #{params.deliveryEndTime} >= o.delivery_time
  1087. </if>
  1088. <if test="params.orderSn != null and params.orderSn != ''">
  1089. AND (o.order_sn like concat('%', #{params.orderSn}, '%') or o.out_trade_no like concat('%', #{params.orderSn}, '%'))
  1090. </if>
  1091. <if test="params.productName != null and params.productName != ''">
  1092. AND o.product_name like concat('%', #{params.productName}, '%')
  1093. </if>
  1094. <if test="params.paymentType != null and params.paymentType != ''">
  1095. AND o.payment_type = #{params.paymentType}
  1096. </if>
  1097. <if test="params.couponId != null and params.couponId != ''">
  1098. AND o.coupon_id = #{params.couponId}
  1099. </if>
  1100. <if test="params.memberName != null and params.memberName != ''">
  1101. AND b.nickname like concat('%', #{params.memberName}, '%')
  1102. </if>
  1103. <if test="params.memberMobile != null and params.memberMobile != ''">
  1104. AND b.mobile like concat('%', #{params.memberMobile}, '%')
  1105. </if>
  1106. <if test="params.sendContactName != null and params.sendContactName != ''">
  1107. AND o.send_contact_name like concat('%', #{params.sendContactName}, '%')
  1108. </if>
  1109. <if test="params.sendPhone != null and params.sendPhone != ''">
  1110. AND o.send_phone like concat('%', #{params.sendPhone}, '%')
  1111. </if>
  1112. <if test="params.receiptContactName != null and params.receiptContactName != ''">
  1113. AND o.receipt_contact_name like concat('%', #{params.receiptContactName}, '%')
  1114. </if>
  1115. <if test="params.receiptPhone != null and params.receiptPhone != ''">
  1116. AND o.receipt_phone like concat('%', #{params.receiptPhone}, '%')
  1117. </if>
  1118. <if test="params.status != null">
  1119. AND o.status = #{params.status}
  1120. </if>
  1121. <if test="params.deliveryStatus != null and params.deliveryStatus != 4 and params.deliveryStatus != 100 and params.deliveryStatus != 6">
  1122. AND (o.delivery_status = #{params.deliveryStatus} and (wo.`status`!=4 or wo.`status` is null))
  1123. </if>
  1124. <!-- <if test="params.deliveryStatus != null and params.deliveryStatus == 0">-->
  1125. <!-- AND ((wo.status is null or wo.status != 4) and o.delivery_status=0 and o.waimai_order_id is not null)-->
  1126. <!-- </if>-->
  1127. <if test="params.deliveryStatus != null and params.deliveryStatus == 4">
  1128. AND o.delivery_status=4
  1129. </if>
  1130. <if test="params.deliveryStatus != null and params.deliveryStatus == 100">
  1131. AND (wo.status = 4 and o.delivery_status != 4)
  1132. </if>
  1133. <if test="agentIds != null and agentIds.size > 0">
  1134. AND o.agent_Id in
  1135. <foreach collection="agentIds" index="index" item="item" open="(" separator="," close=")">
  1136. #{item}
  1137. </foreach>
  1138. </if>
  1139. <if test="params.aId != null">
  1140. AND
  1141. o.agent_Id in
  1142. <if test="aIds.size > 0 and aIds != null">
  1143. <foreach collection="aIds" index="index" item="aid" open="(" separator="," close=")">
  1144. #{aid}
  1145. </foreach>
  1146. </if>
  1147. </if>
  1148. <if test="params.receiptProvinceName != null and params.receiptProvinceName != ''">
  1149. AND o.receipt_province_name like concat('%', #{params.receiptProvinceName}, '%')
  1150. </if>
  1151. <if test="params.receiptCityName != null and params.receiptCityName != ''">
  1152. AND o.receipt_city_name like concat('%', #{params.receiptCityName}, '%')
  1153. </if>
  1154. <if test="params.receiptDistrictName != null and params.receiptDistrictName != ''">
  1155. AND o.receipt_district_name like concat('%', #{params.receiptDistrictName}, '%')
  1156. </if>
  1157. <if test="params.sendProvinceName != null and params.sendProvinceName != ''">
  1158. AND o.send_province_name like concat('%', #{params.sendProvinceName}, '%')
  1159. </if>
  1160. <if test="params.sendCityName != null and params.sendCityName != ''">
  1161. AND o.send_city_name like concat('%', #{params.sendCityName}, '%')
  1162. </if>
  1163. <if test="params.sendDistrictName != null and params.sendDistrictName != ''">
  1164. AND o.send_district_name like concat('%', #{params.sendDistrictName}, '%')
  1165. </if>
  1166. <if test="params.waimaiOrderType != null and params.waimaiOrderType != 4">
  1167. AND wo.order_type = #{params.waimaiOrderType}
  1168. </if>
  1169. <if test="params.waimaiOrderType != null and params.waimaiOrderType == 4">
  1170. AND o.waimai_order_id is null
  1171. </if>
  1172. <if test="params.paymentType != null">
  1173. AND (o.payment_type = #{params.paymentType} and o.status != 0)
  1174. </if>
  1175. <if test="params.shopIds != null and params.shopIds.size > 0">
  1176. AND
  1177. o.shop_id in
  1178. <foreach collection="params.shopIds" index="index" item="item" open="(" separator="," close=")">
  1179. #{item}
  1180. </foreach>
  1181. </if>
  1182. ORDER BY o.create_time DESC
  1183. </select>
  1184. <select id="totalConsume" resultType="java.math.BigDecimal">
  1185. SELECT COALESCE(SUM(pay_amount) + SUM(breach_fee),0) FROM lb_order WHERE
  1186. delivery_status = 4 and deleted = 0
  1187. <if test="shopIds != null and shopIds.size > 0">
  1188. AND shop_id IN
  1189. <foreach collection="shopIds" index="index" item="shopId" open="(" separator="," close=")">
  1190. #{shopId}
  1191. </foreach>
  1192. </if>
  1193. <if test="params.balanceStartTime != null and params.balanceStartTime != ''">
  1194. AND create_time >= #{params.balanceStartTime}
  1195. </if>
  1196. <if test="params.balanceEndTime != null and params.balanceEndTime != ''">
  1197. AND #{params.balanceEndTime} > create_time
  1198. </if>
  1199. </select>
  1200. <select id="totalConsumeByMemberId" resultType="java.math.BigDecimal">
  1201. SELECT COALESCE(SUM(pay_amount) + SUM(breach_fee),0) FROM lb_order WHERE
  1202. delivery_status = 4 and deleted = 0
  1203. <if test="memberId != null and memberId != ''">
  1204. AND member_id = #{memberId}
  1205. </if>
  1206. </select>
  1207. <select id="selectOriginalOrderSn1" resultType="java.lang.String">
  1208. select order_sn from lb_order
  1209. where id = (
  1210. select max(id) from lb_order where deleted = 0 and waimai_order_id = #{waimaiOrderId}
  1211. )
  1212. </select>
  1213. <!-- <update id="autofinish">-->
  1214. <!-- update lb_waimai_order set `status`=4 where id in(-->
  1215. <!-- select id from (-->
  1216. <!-- SELECT-->
  1217. <!-- w.id-->
  1218. <!-- FROM-->
  1219. <!-- lb_order o join lb_waimai_order w on o.waimai_order_id = w.id-->
  1220. <!-- WHERE-->
  1221. <!-- delivery_status in(0,-2)-->
  1222. <!-- AND take_type = 0-->
  1223. <!-- AND w.create_time &lt;= DATE_SUB(NOW(),INTERVAL 6 HOUR)-->
  1224. <!-- and w.`status` not in(-1,4)-->
  1225. <!-- union all-->
  1226. <!-- SELECT-->
  1227. <!-- w.id-->
  1228. <!-- FROM-->
  1229. <!-- lb_order o join lb_waimai_order w on o.waimai_order_id = w.id-->
  1230. <!-- WHERE-->
  1231. <!-- delivery_status in(0,-2)-->
  1232. <!-- AND take_type in (1,2)-->
  1233. <!-- AND o.take_time &lt;DATE_SUB(NOW(),INTERVAL 6 HOUR)-->
  1234. <!-- and w.`status` not in(-1,4)) t)-->
  1235. <!--</update>-->
  1236. <update id="autofinish">
  1237. update lb_waimai_order set `status`=4 where id in(
  1238. select id from (
  1239. SELECT
  1240. w.id
  1241. FROM
  1242. lb_waimai_order w straight_join lb_order o on o.waimai_order_id = w.id
  1243. WHERE
  1244. delivery_status in(0,-2)
  1245. AND take_type = 0
  1246. AND w.create_time &lt;= DATE_SUB(NOW(),INTERVAL 6 HOUR)
  1247. and w.`status` not in(-1,4)
  1248. union all
  1249. SELECT
  1250. w.id
  1251. FROM
  1252. lb_waimai_order w straight_join lb_order o on o.waimai_order_id = w.id
  1253. WHERE
  1254. delivery_status in(0,-2)
  1255. AND take_type in (1,2)
  1256. AND o.take_time &lt;DATE_SUB(NOW(),INTERVAL 6 HOUR)
  1257. and w.`status` not in(-1,4))t)
  1258. </update>
  1259. <select id="getOrderList" resultType="com.ydd.module.dto.OrderListDto">
  1260. SELECT
  1261. o.id,
  1262. o.waimai_order_id,
  1263. o.order_sn,
  1264. o.take_type,
  1265. o.shop_id,
  1266. o.shop_name,
  1267. o.order_distance,
  1268. o.receipt_address_id,
  1269. o.receipt_province_name,
  1270. o.receipt_city_name,
  1271. o.receipt_district_name,
  1272. o.receipt_address,
  1273. o.receipt_contact_name,
  1274. o.receipt_phone,
  1275. o.receipt_extension,
  1276. o.receipt_city_code,
  1277. o.receipt_lng,
  1278. o.receipt_lat,
  1279. o.send_address_id,
  1280. o.send_province_name,
  1281. o.send_city_name,
  1282. o.send_district_name,
  1283. o.send_address,
  1284. o.send_contact_name,
  1285. o.send_phone,
  1286. o.send_extension,
  1287. o.send_city_code,
  1288. o.send_lng,
  1289. o.send_lat,
  1290. o.delivery_status,
  1291. o.delivery_id,
  1292. o.take_time,
  1293. o.take_remark,
  1294. o.delivery_time,
  1295. o.cancel_type,
  1296. o.product_id,
  1297. o.weight,
  1298. o.product_name,
  1299. o.pay_amount,
  1300. o.shipper_name,
  1301. o.shipper_phone,
  1302. o.delivery_logo,
  1303. o.delivery_name,
  1304. o.platform_type,
  1305. o.auto_delivery_minutes,
  1306. o.send_street,
  1307. o.receipt_street,
  1308. case when o.waimai_order_id is not null then wo.total_price
  1309. else o.product_amount end as productAmount,
  1310. wo.out_order_id,
  1311. wo.caution,
  1312. wo.waimai_id,
  1313. wo.order_type,
  1314. case when wo.day_seq is not null then wo.day_seq
  1315. else o.lb_day_seq
  1316. end as day_seq,
  1317. wo.status AS wmstatus,
  1318. wo.delivery_time AS wmDeliveryTime,
  1319. wo.order_time AS orderTime,
  1320. (SELECT delay_time FROM lb_order_delay WHERE order_id = o.id AND deleted = 0) AS delay_time,
  1321. case when o.take_type != 0 and o.waimai_order_id is null then UNIX_TIMESTAMP(o.delivery_time)
  1322. else wo.delivery_time
  1323. end as sortedTime
  1324. FROM lb_order AS o
  1325. <if test="params.memberType != null and params.memberType > 1">
  1326. FORCE INDEX(idx_order_shop_id)
  1327. </if>
  1328. LEFT JOIN lb_waimai_order AS wo ON o.waimai_order_id = wo.id
  1329. WHERE o.deleted = 0
  1330. <if test="params.memberType != null and params.memberType == 1">
  1331. AND o.member_id = #{params.memberId}
  1332. </if>
  1333. <if test="params.memberType != null and params.memberType > 1">
  1334. <if test="params.shopIds != null and params.shopIds.size != 0 ">
  1335. AND (o.shop_id IN
  1336. <foreach collection="params.shopIds" index="index" item="item" open="(" separator="," close=")">
  1337. #{item}
  1338. </foreach>
  1339. <if test="params.isHasPersonalOrder">
  1340. OR (o.member_id = #{params.memberId} AND o.shop_id is null)
  1341. </if>
  1342. )
  1343. </if>
  1344. </if>
  1345. <if test="params.searchType != null and params.searchType == 0">
  1346. <if test="params.status != null">
  1347. <if test="params.status != -1 and params.status != 0 and params.status != 4 and params.status != 10 and params.status != 94 and params.status != 93">
  1348. AND (
  1349. (o.waimai_order_id IS NULL AND o.delivery_status = #{params.status})
  1350. OR (o.waimai_order_id IS NOT NULL AND o.delivery_status = #{params.status} AND wo.status != 4)
  1351. )
  1352. </if>
  1353. <if test="params.status == -1">
  1354. AND
  1355. (
  1356. (o.waimai_order_id IS NULL AND o.delivery_status = -1 AND o.update_time >= #{params.cancelTime})
  1357. OR (o.waimai_order_id IS NOT NULL AND o.delivery_status = -1 AND wo.status != 4 AND wo.update_time >= #{params.cancelTime})
  1358. )
  1359. </if>
  1360. <if test="params.status == 0 ">
  1361. AND (o.waimai_order_id IS NOT NULL AND o.delivery_status = 0 AND o.take_type = 0 AND wo.status != 4)
  1362. </if>
  1363. <if test="params.status == 4">
  1364. AND
  1365. (
  1366. (o.waimai_order_id IS NULL AND o.delivery_status = 4)
  1367. OR (o.waimai_order_id IS NOT NULL AND wo.status = 4)
  1368. )
  1369. </if>
  1370. <if test="params.status == 10">
  1371. AND
  1372. (
  1373. (o.waimai_order_id IS NULL AND o.delivery_status = 0 AND o.take_type != 0 AND o.save_flag = 1)
  1374. OR (o.waimai_order_id IS NOT NULL AND o.delivery_status = 0 AND o.take_type != 0 AND wo.status != 4)
  1375. )
  1376. </if>
  1377. <if test="params.status == 94">
  1378. AND o.create_time >= #{params.lastDayTime}
  1379. </if>
  1380. <if test="params.status == 93">
  1381. AND
  1382. (
  1383. (o.waimai_order_id IS NULL AND o.delivery_status = 4 AND o.update_time >= #{params.lastDayTime})
  1384. OR (o.waimai_order_id IS NOT NULL AND wo.status = 4 AND wo.update_time >= #{params.lastDayTime})
  1385. OR (o.waimai_order_id IS NULL AND o.delivery_status = -1 AND o.update_time >= #{params.lastDayTime})
  1386. OR (o.waimai_order_id IS NOT NULL AND o.delivery_status = -1 AND wo.status != 4 AND wo.update_time >= #{params.lastDayTime})
  1387. )
  1388. </if>
  1389. </if>
  1390. </if>
  1391. <if test="params.searchType != null and params.searchType == 1">
  1392. <if test="params.status != null">
  1393. <if test="params.status == -1">
  1394. AND (
  1395. (o.waimai_order_id IS NULL AND o.delivery_status = -1)
  1396. OR (o.waimai_order_id IS NOT NULL AND o.delivery_status = -1 AND wo.status != 4)
  1397. )
  1398. </if>
  1399. <if test="params.status == 95">
  1400. AND
  1401. (
  1402. (o.waimai_order_id IS NULL AND o.delivery_status = 0 AND o.save_flag = 1)
  1403. OR (o.waimai_order_id IS NOT NULL AND o.delivery_status = 0 AND wo.status = 0)
  1404. )
  1405. </if>
  1406. <if test="params.status == 96">
  1407. AND (
  1408. (o.waimai_order_id IS NULL AND o.delivery_status IN (-2,1,2,3))
  1409. OR (o.waimai_order_id IS NOT NULL AND o.delivery_status IN (-2,1,2,3) AND wo.status != 4 AND wo.status != -1)
  1410. )
  1411. </if>
  1412. <if test="params.status == 97">
  1413. AND (o.delivery_status = 4)
  1414. </if>
  1415. <if test="params.status == 98">
  1416. AND (o.delivery_status != 4 AND o.waimai_order_id IS NOT NULL AND wo.status = 4)
  1417. </if>
  1418. <if test="params.status == 99">
  1419. AND (
  1420. NOT(
  1421. o.delivery_status = 0
  1422. AND o.status = 0
  1423. AND wo.status != 0
  1424. AND (wo.status != 4 OR wo.status IS NULL)
  1425. )
  1426. OR o.waimai_order_id IN (SELECT waimai_order_id FROM lb_order WHERE deleted=1)
  1427. OR o.save_flag = 1
  1428. )
  1429. </if>
  1430. </if>
  1431. </if>
  1432. <if test="params.searchType != null and params.searchType == 2">
  1433. <if test="params.searchStatusItem != null">
  1434. <!-- 新订单 -->
  1435. <if test="params.searchStatusItem.newOrder">
  1436. AND (
  1437. (o.waimai_order_id IS NOT NULL AND o.delivery_status = 0 AND o.take_type = 0 AND wo.status != 4)
  1438. </if>
  1439. <!-- 预约单 -->
  1440. <if test="params.searchStatusItem.bookingOrder">
  1441. <if test="!params.searchStatusItem.newOrder">
  1442. AND (
  1443. </if>
  1444. <if test="params.searchStatusItem.newOrder">
  1445. OR
  1446. </if>
  1447. (
  1448. (o.waimai_order_id IS NULL AND o.delivery_status = 0 AND o.take_type != 0 AND o.save_flag = 1)
  1449. OR (o.waimai_order_id IS NOT NULL AND o.delivery_status = 0 AND o.take_type != 0 AND wo.status != 4)
  1450. )
  1451. </if>
  1452. <!-- 待接单 -->
  1453. <if test="params.searchStatusItem.toBeReceivedOrder">
  1454. <if test="!params.searchStatusItem.newOrder and !params.searchStatusItem.bookingOrder">
  1455. AND (
  1456. </if>
  1457. <if test="params.searchStatusItem.newOrder || params.searchStatusItem.bookingOrder">
  1458. OR
  1459. </if>
  1460. (
  1461. (o.waimai_order_id IS NULL AND o.delivery_status = 1)
  1462. OR (o.waimai_order_id IS NOT NULL AND o.delivery_status = 1 AND wo.status != 4 AND wo.status != -1)
  1463. )
  1464. </if>
  1465. <!-- 取货中 -->
  1466. <if test="params.searchStatusItem.toBeDeliveredOrder">
  1467. <if test="!params.searchStatusItem.newOrder and !params.searchStatusItem.bookingOrder
  1468. and !params.searchStatusItem.toBeReceivedOrder">
  1469. AND (
  1470. </if>
  1471. <if test="params.searchStatusItem.newOrder || params.searchStatusItem.bookingOrder
  1472. || params.searchStatusItem.toBeReceivedOrder">
  1473. OR
  1474. </if>
  1475. (
  1476. (o.waimai_order_id IS NULL AND o.delivery_status = 2)
  1477. OR (o.waimai_order_id IS NOT NULL AND o.delivery_status = 2 AND wo.status != 4 AND wo.status != -1)
  1478. )
  1479. </if>
  1480. <!-- 配送中 -->
  1481. <if test="params.searchStatusItem.inDeliveryOrder">
  1482. <if test="!params.searchStatusItem.newOrder and !params.searchStatusItem.bookingOrder
  1483. and !params.searchStatusItem.toBeReceivedOrder and !params.searchStatusItem.toBeDeliveredOrder">
  1484. AND (
  1485. </if>
  1486. <if test="params.searchStatusItem.newOrder || params.searchStatusItem.bookingOrder
  1487. || params.searchStatusItem.toBeReceivedOrder || params.searchStatusItem.toBeDeliveredOrder">
  1488. OR
  1489. </if>
  1490. (
  1491. (o.waimai_order_id IS NULL AND o.delivery_status = 3)
  1492. OR (o.waimai_order_id IS NOT NULL AND o.delivery_status = 3 AND wo.status != 4 AND wo.status != -1)
  1493. )
  1494. </if>
  1495. <!-- 异常单 -->
  1496. <if test="params.searchStatusItem.abnormalOrder">
  1497. <if test="!params.searchStatusItem.newOrder and !params.searchStatusItem.bookingOrder
  1498. and !params.searchStatusItem.toBeReceivedOrder and !params.searchStatusItem.toBeDeliveredOrder
  1499. and !params.searchStatusItem.inDeliveryOrder">
  1500. AND (
  1501. </if>
  1502. <if test="params.searchStatusItem.newOrder || params.searchStatusItem.bookingOrder
  1503. || params.searchStatusItem.toBeReceivedOrder || params.searchStatusItem.toBeDeliveredOrder
  1504. || params.searchStatusItem.inDeliveryOrder">
  1505. OR
  1506. </if>
  1507. (
  1508. (o.waimai_order_id IS NULL AND o.delivery_status = -2)
  1509. OR (o.waimai_order_id IS NOT NULL AND o.delivery_status = -2 AND wo.status != 4 AND wo.status != -1)
  1510. )
  1511. </if>
  1512. <!-- 完成 -->
  1513. <if test="params.searchStatusItem.finishOrder">
  1514. <if test="!params.searchStatusItem.newOrder and !params.searchStatusItem.bookingOrder
  1515. and !params.searchStatusItem.toBeReceivedOrder and !params.searchStatusItem.toBeDeliveredOrder
  1516. and !params.searchStatusItem.inDeliveryOrder and !params.searchStatusItem.abnormalOrder">
  1517. AND (
  1518. </if>
  1519. <if test="params.searchStatusItem.newOrder || params.searchStatusItem.bookingOrder
  1520. || params.searchStatusItem.toBeReceivedOrder || params.searchStatusItem.toBeDeliveredOrder
  1521. || params.searchStatusItem.inDeliveryOrder || params.searchStatusItem.abnormalOrder">
  1522. OR
  1523. </if>
  1524. (
  1525. (o.waimai_order_id IS NULL AND o.delivery_status = 4)
  1526. OR (o.waimai_order_id IS NOT NULL AND wo.status = 4)
  1527. )
  1528. </if>
  1529. <!-- 取消 -->
  1530. <if test="params.searchStatusItem.cancelOrder">
  1531. <if test="!params.searchStatusItem.newOrder and !params.searchStatusItem.bookingOrder
  1532. and !params.searchStatusItem.toBeReceivedOrder and !params.searchStatusItem.toBeDeliveredOrder
  1533. and !params.searchStatusItem.inDeliveryOrder and !params.searchStatusItem.abnormalOrder
  1534. and !params.searchStatusItem.finishOrder">
  1535. AND (
  1536. </if>
  1537. <if test="params.searchStatusItem.newOrder || params.searchStatusItem.bookingOrder
  1538. || params.searchStatusItem.toBeReceivedOrder || params.searchStatusItem.toBeDeliveredOrder
  1539. || params.searchStatusItem.inDeliveryOrder || params.searchStatusItem.abnormalOrder
  1540. || params.searchStatusItem.finishOrder">
  1541. OR
  1542. </if>
  1543. (
  1544. (o.waimai_order_id IS NULL AND o.delivery_status = -1)
  1545. OR (o.waimai_order_id IS NOT NULL AND o.delivery_status = -1 AND wo.status != 4)
  1546. )
  1547. </if>
  1548. <if test="params.searchStatusItem.newOrder || params.searchStatusItem.bookingOrder
  1549. || params.searchStatusItem.toBeReceivedOrder || params.searchStatusItem.toBeDeliveredOrder
  1550. || params.searchStatusItem.inDeliveryOrder || params.searchStatusItem.abnormalOrder
  1551. || params.searchStatusItem.finishOrder || params.searchStatusItem.cancelOrder">
  1552. )
  1553. </if>
  1554. </if>
  1555. </if>
  1556. <if test="params.searchKeyType != null and params.searchKeyType != 0 and params.searchKey != null and params.searchKey != ''">
  1557. AND
  1558. <if test="params.searchKeyType == 1">
  1559. (wo.day_seq = #{params.searchKey}
  1560. OR
  1561. o.lb_day_seq = #{params.searchKey}
  1562. )
  1563. </if>
  1564. <if test="params.searchKeyType == 2">
  1565. o.receipt_phone LIKE concat('%', #{params.searchKey}, '%')
  1566. </if>
  1567. <if test="params.searchKeyType == 3">
  1568. o.receipt_contact_name like concat('%', #{params.searchKey}, '%')
  1569. </if>
  1570. <if test="params.searchKeyType == 4">
  1571. o.receipt_address LIKE concat('%', #{params.searchKey}, '%')
  1572. </if>
  1573. <if test="params.searchKeyType == 5">
  1574. o.order_sn LIKE concat('%', #{params.searchKey}, '%')
  1575. </if>
  1576. <if test="params.searchKeyType == 6">
  1577. wo.out_order_id LIKE concat('%', #{params.searchKey}, '%')
  1578. </if>
  1579. </if>
  1580. <if test="params.searchType != null and params.searchType == 1 and params.orderType != null">
  1581. <if test="params.orderType != 0 and params.orderType != 99">
  1582. AND o.waimai_order_id IS NOT NULL AND wo.order_type = #{params.orderType}
  1583. </if>
  1584. <if test="params.orderType == 99">
  1585. AND o.waimai_order_id IS NULL
  1586. </if>
  1587. </if>
  1588. <if test="params.shopId != null and params.shopId != 0">
  1589. AND o.shop_id = #{params.shopId}
  1590. </if>
  1591. <if test="params.startDate != null and params.startDate!=''">
  1592. AND o.create_time >= #{params.startDate}
  1593. </if>
  1594. <if test="params.endDate != null and params.endDate!=''">
  1595. AND o.create_time &lt; #{params.endDate}
  1596. </if>
  1597. <if test="params.status == 10">
  1598. ORDER BY sortedTime ASC, o.id DESC
  1599. </if>
  1600. <if test="params.status == -2">
  1601. ORDER BY o.id DESC
  1602. </if>
  1603. <if test="params.status != 10 and params.status != -2">
  1604. ORDER BY o.create_time DESC
  1605. </if>
  1606. </select>
  1607. <select id="getOrderListByShopIdsAndMemberIds" resultType="com.ydd.module.dto.OrderListDto">
  1608. SELECT
  1609. o.id,
  1610. o.delivery_status,
  1611. o.take_type,
  1612. o.waimai_order_id,
  1613. o.save_flag,
  1614. wo.status AS wmstatus,
  1615. o.update_time,
  1616. wo.update_time AS wmUpdateTime,
  1617. wo.delivery_time AS wmDeliveryTime
  1618. FROM lb_order AS o
  1619. <if test="memberType != null and memberType > 1">
  1620. FORCE INDEX(idx_order_shop_id)
  1621. </if>
  1622. LEFT JOIN lb_waimai_order AS wo ON o.waimai_order_id = wo.id
  1623. WHERE o.deleted = 0
  1624. <if test="memberType != null and memberType == 1">
  1625. AND o.member_id = #{memberId}
  1626. </if>
  1627. <if test="memberType != null and memberType > 1">
  1628. <if test="shopIds != null and shopIds.size != 0 ">
  1629. AND (o.shop_id IN
  1630. <foreach collection="shopIds" index="index" item="item" open="(" separator="," close=")">
  1631. #{item}
  1632. </foreach>
  1633. <if test="hasPersonalOrder">
  1634. OR (o.member_id = #{memberId} AND o.shop_id is null)
  1635. </if>
  1636. )
  1637. </if>
  1638. </if>
  1639. </select>
  1640. <select id="selectOrderData" resultType="com.ydd.module.dto.ProfitsSystemOrderDto">
  1641. SELECT
  1642. DATE_FORMAT( o.create_time, "%Y-%m-%d" ) AS date,
  1643. o.id AS orderId,
  1644. o.pay_amount,
  1645. o.delivery_status,
  1646. wo.`status` AS wmStatus,
  1647. o.delivery_id,
  1648. o.agent_Id,
  1649. o.merchant_id,
  1650. (select sum(commission) from lb_profits_detail as pd where o.id = pd.order_id and agent_id IS NOT NULL and deleted = 0 and is_source = 0) AS agentCommission,
  1651. (select sum(commission) from lb_profits_detail as pd where o.id = pd.order_id and dsp_id IS NOT NULL and deleted = 0 and is_source = 0) AS dspCommission,
  1652. m.merchant_name,
  1653. a.`name` AS agentName
  1654. FROM
  1655. lb_order o
  1656. LEFT JOIN lb_waimai_order wo ON o.waimai_order_id = wo.id
  1657. LEFT JOIN lb_merchant m ON o.merchant_id = m.id
  1658. LEFT JOIN lb_agent a ON o.agent_Id = a.id
  1659. WHERE o.id = #{orderId}
  1660. </select>
  1661. <select id="getByOrderSn" resultType="com.ydd.module.domain.Order">
  1662. select id,order_sn,delivery_status from lb_order where order_sn = #{orderSn} and deleted = 0
  1663. </select>
  1664. <select id="getAllOrderByOrderSn" resultType="com.ydd.module.domain.Order">
  1665. select id,order_sn,delivery_status from lb_order where order_sn like concat('%', #{orderSn}, '%')
  1666. </select>
  1667. <select id="getAllOrderByOrderId" resultType="com.ydd.module.domain.Order">
  1668. select id,order_sn,delivery_status from lb_order where id = #{orderId}
  1669. </select>
  1670. <select id="queryDadaPageList" resultType="com.ydd.module.dto.DadaOrderListDto">
  1671. SELECT
  1672. o.id,
  1673. o.waimai_order_id,
  1674. o.merchant_id,
  1675. o.take_type,
  1676. o.order_sn,
  1677. o.take_time,
  1678. o.create_time,
  1679. o.delivery_status,
  1680. o.status,
  1681. o.send_contact_name,
  1682. o.send_phone,
  1683. o.send_province_name,
  1684. o.send_city_name,
  1685. o.send_district_name,
  1686. o.send_address,
  1687. o.send_extension,
  1688. o.send_street,
  1689. o.receipt_contact_name,
  1690. o.receipt_phone,
  1691. o.receipt_province_name,
  1692. o.receipt_city_name,
  1693. o.receipt_district_name,
  1694. o.receipt_address,
  1695. o.receipt_extension,
  1696. o.receipt_street,
  1697. o.pay_amount,
  1698. o.payment_type,
  1699. o.product_name,
  1700. o.weight,
  1701. o.take_remark,
  1702. o.out_trade_no,
  1703. o.delivery_name,
  1704. o.delivery_id,
  1705. o.shipper_name,
  1706. o.shipper_phone,
  1707. o.cancel_reason,
  1708. o.agent_Id,
  1709. o.commission,
  1710. o.total_amount,
  1711. o.coupon_amount,
  1712. o.tip_amount,
  1713. o.first_coupon,
  1714. o.bind_fee,
  1715. o.deleted,
  1716. o.refund_money,
  1717. o.dada_dsp_id,
  1718. o.dada_dsp_type,
  1719. o.shop_id,
  1720. o.member_id,
  1721. o.platform_type,
  1722. wo.status AS wmstatus,
  1723. case when o.waimai_order_id is not null then wo.total_price
  1724. else o.product_amount end as productAmount,
  1725. wo.caution AS wmCaution,
  1726. wo.delivery_time AS waimaiDeliveryTime,
  1727. wo.order_type,
  1728. wo.order_time,
  1729. case when wo.day_seq is not null then wo.day_seq
  1730. else o.lb_day_seq
  1731. end as day_seq,
  1732. (select name from lb_dsp_waimai where parent_id is not null and type = wo.order_type) AS dspWaimaiName
  1733. FROM lb_order o
  1734. LEFT JOIN lb_waimai_order AS wo ON o.waimai_order_id = wo.id
  1735. <if test="(params.completeStartTime != null and params.completeStartTime != '') or (params.completeEndTime != null and params.completeEndTime != '')">
  1736. LEFT JOIN lb_order_log AS ol ON o.id = ol.order_id
  1737. </if>
  1738. WHERE 1 = 1 AND o.dada_dsp_id is not null
  1739. <if test="params.deliveryStatus != 6">
  1740. AND o.deleted = 0
  1741. </if>
  1742. <if test="params.deliveryStatus == 6">
  1743. AND o.deleted = 1
  1744. </if>
  1745. AND
  1746. (
  1747. not(
  1748. o.delivery_status = 0
  1749. AND o.status = 0
  1750. AND wo.status != 0
  1751. AND ( wo.status != 4 OR wo.status IS NULL )
  1752. )
  1753. or o.waimai_order_id in (select waimai_order_id from lb_order where deleted=1)
  1754. or o.save_flag = 1
  1755. )
  1756. <if test="params.dadaDspId != null and params.dadaDspId != ''">
  1757. AND o.dada_dsp_id = #{params.dadaDspId}
  1758. </if>
  1759. <if test="params.createStartTime != null and params.createStartTime != ''">
  1760. AND o.create_time >= #{params.createStartTime}
  1761. </if>
  1762. <if test="params.createEndTime != null and params.createEndTime != ''">
  1763. AND #{params.createEndTime} >= o.create_time
  1764. </if>
  1765. <if test="params.merchantIds != null and params.merchantIds.size > 0 ">
  1766. AND o.merchant_id IN
  1767. <foreach collection="params.merchantIds" index="index" item="item" open="(" separator="," close=")">
  1768. #{item}
  1769. </foreach>
  1770. </if>
  1771. <if test="params.shopIds != null and params.shopIds.size > 0 ">
  1772. AND o.shop_id IN
  1773. <foreach collection="params.shopIds" index="index" item="item" open="(" separator="," close=")">
  1774. #{item}
  1775. </foreach>
  1776. </if>
  1777. <if test="params.completeStartTime != null and params.completeStartTime != ''">
  1778. AND ol.create_time >= #{params.completeStartTime} AND ol.order_status = 4
  1779. </if>
  1780. <if test="params.completeEndTime != null and params.completeEndTime != ''">
  1781. AND ol.create_time &lt;= #{params.completeEndTime} AND ol.order_status = 4
  1782. </if>
  1783. <if test="params.orderSn != null and params.orderSn != ''">
  1784. AND (o.order_sn like concat('%', #{params.orderSn}, '%') or o.out_trade_no like concat('%', #{params.orderSn}, '%'))
  1785. </if>
  1786. <if test="params.sendContactName != null and params.sendContactName != ''">
  1787. AND o.send_contact_name like concat('%', #{params.sendContactName}, '%')
  1788. </if>
  1789. <if test="params.sendPhone != null and params.sendPhone != ''">
  1790. AND o.send_phone like concat('%', #{params.sendPhone}, '%')
  1791. </if>
  1792. <if test="params.receiptContactName != null and params.receiptContactName != ''">
  1793. AND o.receipt_contact_name like concat('%', #{params.receiptContactName}, '%')
  1794. </if>
  1795. <if test="params.receiptPhone != null and params.receiptPhone != ''">
  1796. AND o.receipt_phone like concat('%', #{params.receiptPhone}, '%')
  1797. </if>
  1798. <if test="params.deliveryStatus != null and params.deliveryStatus != 4 and params.deliveryStatus != 100 and params.deliveryStatus != 6">
  1799. AND (o.delivery_status = #{params.deliveryStatus} and (wo.`status`!=4 or wo.`status` is null))
  1800. </if>
  1801. <if test="params.deliveryStatus != null and params.deliveryStatus == 4">
  1802. AND o.delivery_status=4
  1803. </if>
  1804. <if test="params.deliveryStatus != null and params.deliveryStatus == 100">
  1805. AND (wo.status = 4 and o.delivery_status != 4)
  1806. </if>
  1807. <if test="params.sendProvinceName != null and params.sendProvinceName != ''">
  1808. AND o.send_province_name like concat('%', #{params.sendProvinceName}, '%')
  1809. </if>
  1810. <if test="params.sendCityName != null and params.sendCityName != ''">
  1811. AND o.send_city_name like concat('%', #{params.sendCityName}, '%')
  1812. </if>
  1813. <if test="params.sendDistrictName != null and params.sendDistrictName != ''">
  1814. AND o.send_district_name like concat('%', #{params.sendDistrictName}, '%')
  1815. </if>
  1816. <if test="params.waimaiOrderType != null and params.waimaiOrderType != 4">
  1817. AND wo.order_type = #{params.waimaiOrderType}
  1818. </if>
  1819. <if test="params.waimaiOrderType != null and params.waimaiOrderType == 4">
  1820. AND o.waimai_order_id is null
  1821. </if>
  1822. ORDER BY o.create_time DESC
  1823. </select>
  1824. <select id="selectDadaCountByStatus" resultType="com.ydd.module.dto.SystemOrderDto">
  1825. SELECT
  1826. o.delivery_status,
  1827. wo.status AS wmStatus,
  1828. o.waimai_order_id,
  1829. o.order_sn,
  1830. o.payment_type
  1831. FROM lb_order AS o
  1832. LEFT JOIN lb_waimai_order AS wo ON o.waimai_order_id = wo.id
  1833. <if test="(params.completeStartTime != null and params.completeStartTime != '') or (params.completeEndTime != null and params.completeEndTime != '')">
  1834. LEFT JOIN lb_order_log AS ol ON o.id = ol.order_id
  1835. </if>
  1836. WHERE 1 = 1 AND o.dada_dsp_id is not null
  1837. AND
  1838. (
  1839. not(
  1840. o.delivery_status = 0
  1841. AND o.status = 0
  1842. AND wo.status != 0
  1843. AND (wo.status != 4 OR wo.status IS NULL)
  1844. )
  1845. or o.waimai_order_id in (select waimai_order_id from lb_order where deleted=1)
  1846. or o.save_flag = 1
  1847. )
  1848. <if test="params.dadaDspId != null and params.dadaDspId != ''">
  1849. AND o.dada_dsp_id = #{params.dadaDspId}
  1850. </if>
  1851. <if test="params.createStartTime != null and params.createStartTime != ''">
  1852. AND o.create_time >= #{params.createStartTime}
  1853. </if>
  1854. <if test="params.createEndTime != null and params.createEndTime != ''">
  1855. AND #{params.createEndTime} >= o.create_time
  1856. </if>
  1857. <if test="params.merchantIds != null and params.merchantIds.size > 0 ">
  1858. AND o.merchant_id IN
  1859. <foreach collection="params.merchantIds" index="index" item="item" open="(" separator="," close=")">
  1860. #{item}
  1861. </foreach>
  1862. </if>
  1863. <if test="params.shopIds != null and params.shopIds.size > 0 ">
  1864. AND o.shop_id IN
  1865. <foreach collection="params.shopIds" index="index" item="item" open="(" separator="," close=")">
  1866. #{item}
  1867. </foreach>
  1868. </if>
  1869. <if test="params.completeStartTime != null and params.completeStartTime != ''">
  1870. AND ol.create_time >= #{params.completeStartTime} AND ol.order_status = 4
  1871. </if>
  1872. <if test="params.completeEndTime != null and params.completeEndTime != ''">
  1873. AND ol.create_time &lt;= #{params.completeEndTime} AND ol.order_status = 4
  1874. </if>
  1875. <if test="params.orderSn != null and params.orderSn != ''">
  1876. AND (o.order_sn like concat('%', #{params.orderSn}, '%') or o.out_trade_no like concat('%', #{params.orderSn}, '%'))
  1877. </if>
  1878. <if test="params.sendContactName != null and params.sendContactName != ''">
  1879. AND o.send_contact_name like concat('%', #{params.sendContactName}, '%')
  1880. </if>
  1881. <if test="params.sendPhone != null and params.sendPhone != ''">
  1882. AND o.send_phone like concat('%', #{params.sendPhone}, '%')
  1883. </if>
  1884. <if test="params.receiptContactName != null and params.receiptContactName != ''">
  1885. AND o.receipt_contact_name like concat('%', #{params.receiptContactName}, '%')
  1886. </if>
  1887. <if test="params.receiptPhone != null and params.receiptPhone != ''">
  1888. AND o.receipt_phone like concat('%', #{params.receiptPhone}, '%')
  1889. </if>
  1890. <if test="params.sendProvinceName != null and params.sendProvinceName != ''">
  1891. AND o.send_province_name like concat('%', #{params.sendProvinceName}, '%')
  1892. </if>
  1893. <if test="params.sendCityName != null and params.sendCityName != ''">
  1894. AND o.send_city_name like concat('%', #{params.sendCityName}, '%')
  1895. </if>
  1896. <if test="params.sendDistrictName != null and params.sendDistrictName != ''">
  1897. AND o.send_district_name like concat('%', #{params.sendDistrictName}, '%')
  1898. </if>
  1899. <if test="params.waimaiOrderType != null and params.waimaiOrderType != 4">
  1900. AND wo.order_type = #{params.waimaiOrderType}
  1901. </if>
  1902. <if test="params.waimaiOrderType != null and params.waimaiOrderType == 4">
  1903. AND o.waimai_order_id is null
  1904. </if>
  1905. </select>
  1906. <select id="selectCountByStatus" resultType="com.ydd.module.dto.SystemOrderDto">
  1907. SELECT
  1908. o.delivery_status,
  1909. wo.`status` AS wmStatus,
  1910. o.waimai_order_id,
  1911. o.order_sn,
  1912. o.payment_type
  1913. FROM lb_order AS o
  1914. left join lb_merchant m ON o.merchant_id = m.id
  1915. left join lb_member b ON o.member_id = b.id
  1916. LEFT JOIN lb_waimai_order AS wo ON o.waimai_order_id = wo.id
  1917. left join lb_personnel p on o.personnel_id = p.id
  1918. <if test="(params.completeStartTime != null and params.completeStartTime != '') or (params.completeEndTime != null and params.completeEndTime != '')">
  1919. LEFT JOIN lb_order_log AS ol ON o.id = ol.order_id
  1920. </if>
  1921. WHERE 1 = 1
  1922. AND
  1923. (
  1924. not(
  1925. o.delivery_status = 0
  1926. AND o.`status` = 0
  1927. AND wo.`status` != 0
  1928. AND ( wo.`status` != 4 OR wo.`status` IS NULL )
  1929. )
  1930. or o.waimai_order_id in (select waimai_order_id from lb_order where deleted=1)
  1931. or o.save_flag = 1
  1932. )
  1933. <if test="params.personnelName != null and params.personnelName != ''">
  1934. AND p.`name` like concat('%', #{params.personnelName}, '%')
  1935. </if>
  1936. <if test="params.personnelId != null">
  1937. and o.personnel_id = #{params.personnelId}
  1938. </if>
  1939. <if test="params.deliveryStatus != 6">
  1940. AND o.deleted = 0
  1941. </if>
  1942. <if test="params.deliveryStatus == 6">
  1943. AND o.deleted = 1
  1944. </if>
  1945. <if test="params.memberId != null and params.memberId != ''">
  1946. AND o.member_id = #{params.memberId}
  1947. </if>
  1948. <if test="params.merchantId != null and params.merchantId != ''">
  1949. AND o.merchant_id = #{params.merchantId}
  1950. </if>
  1951. <if test="params.merchantName != null and params.merchantName != ''">
  1952. AND m.merchant_name like concat('%', #{params.merchantName}, '%')
  1953. </if>
  1954. <if test="params.deliveryId != null and params.deliveryId != '' and params.deliveryId != 100">
  1955. AND o.delivery_id = #{params.deliveryId}
  1956. </if>
  1957. <if test="params.deliveryId != null and params.deliveryId != '' and params.deliveryId == 100">
  1958. AND (wo.status = 4 and o.delivery_status != 4 and o.delivery_id is null )
  1959. </if>
  1960. <if test="params.createStartTime != null and params.createStartTime != ''">
  1961. AND o.create_time >= #{params.createStartTime}
  1962. </if>
  1963. <if test="params.createEndTime != null and params.createEndTime != ''">
  1964. AND #{params.createEndTime} >= o.create_time
  1965. </if>
  1966. <!-- <if test="params.completeStartTime != null and params.completeStartTime != ''">-->
  1967. <!-- AND o.update_time >= #{params.completeStartTime} AND o.delivery_status = 4-->
  1968. <!-- </if>-->
  1969. <!-- <if test="params.completeEndTime != null and params.completeEndTime != ''">-->
  1970. <!-- AND o.update_time &lt;= #{params.completeEndTime} AND o.delivery_status = 4-->
  1971. <!-- </if>-->
  1972. <if test="params.completeStartTime != null and params.completeStartTime != ''">
  1973. AND ol.create_time >= #{params.completeStartTime} AND ol.order_status = 4
  1974. </if>
  1975. <if test="params.completeEndTime != null and params.completeEndTime != ''">
  1976. AND ol.create_time &lt;= #{params.completeEndTime} AND ol.order_status = 4
  1977. </if>
  1978. <if test="params.deliveryStartTime != null and params.deliveryStartTime != ''">
  1979. AND o.delivery_time >= #{params.deliveryStartTime}
  1980. </if>
  1981. <if test="params.deliveryEndTime != null and params.deliveryEndTime != ''">
  1982. AND #{params.deliveryEndTime} >= o.delivery_time
  1983. </if>
  1984. <!-- <if test="params.outTradeNo != null and params.outTradeNo != ''">-->
  1985. <!-- AND o.out_trade_no like concat('%', #{params.outTradeNo}, '%')-->
  1986. <!-- </if>-->
  1987. <!-- <if test="params.orderSn != null and params.orderSn != ''">-->
  1988. <!-- AND o.order_sn like concat('%', #{params.orderSn}, '%')-->
  1989. <!-- </if>-->
  1990. <if test="params.orderSn != null and params.orderSn != ''">
  1991. AND (o.order_sn like concat('%', #{params.orderSn}, '%') or o.out_trade_no like concat('%', #{params.orderSn}, '%'))
  1992. </if>
  1993. <if test="params.productName != null and params.productName != ''">
  1994. AND o.product_name like concat('%', #{params.productName}, '%')
  1995. </if>
  1996. <if test="params.paymentType != null and params.paymentType != ''">
  1997. AND o.payment_type = #{params.paymentType}
  1998. </if>
  1999. <if test="params.couponId != null and params.couponId != ''">
  2000. AND o.coupon_id = #{params.couponId}
  2001. </if>
  2002. <if test="params.memberName != null and params.memberName != ''">
  2003. AND b.nickname like concat('%', #{params.memberName}, '%')
  2004. </if>
  2005. <if test="params.memberMobile != null and params.memberMobile != ''">
  2006. AND b.mobile like concat('%', #{params.memberMobile}, '%')
  2007. </if>
  2008. <if test="params.sendContactName != null and params.sendContactName != ''">
  2009. AND o.send_contact_name like concat('%', #{params.sendContactName}, '%')
  2010. </if>
  2011. <if test="params.sendPhone != null and params.sendPhone != ''">
  2012. AND o.send_phone like concat('%', #{params.sendPhone}, '%')
  2013. </if>
  2014. <if test="params.receiptContactName != null and params.receiptContactName != ''">
  2015. AND o.receipt_contact_name like concat('%', #{params.receiptContactName}, '%')
  2016. </if>
  2017. <if test="params.receiptPhone != null and params.receiptPhone != ''">
  2018. AND o.receipt_phone like concat('%', #{params.receiptPhone}, '%')
  2019. </if>
  2020. <if test="params.status != null">
  2021. AND o.status = #{params.status}
  2022. </if>
  2023. <!-- <if test="params.deliveryStatus != null and params.deliveryStatus != 0 and params.deliveryStatus != 4 and params.deliveryStatus != 100 and params.deliveryStatus != 6">-->
  2024. <!-- AND (o.delivery_status = #{params.deliveryStatus} and (wo.`status`!=4 or wo.`status` is null))-->
  2025. <!-- </if>-->
  2026. <!-- <if test="params.deliveryStatus != null and params.deliveryStatus == 0">-->
  2027. <!-- AND ((wo.status is null or wo.status != 4) and o.delivery_status=0 and o.waimai_order_id is not null)-->
  2028. <!-- </if>-->
  2029. <!-- <if test="params.deliveryStatus != null and params.deliveryStatus == 4">-->
  2030. <!-- AND o.delivery_status=4-->
  2031. <!-- </if>-->
  2032. <!-- <if test="params.deliveryStatus != null and params.deliveryStatus == 100">-->
  2033. <!-- AND (wo.status = 4 and o.delivery_status != 4)-->
  2034. <!-- </if>-->
  2035. <if test="params.agentId != null">
  2036. AND
  2037. o.agent_Id in
  2038. <if test="agentIds.size > 0 and agentIds != null">
  2039. <foreach collection="agentIds" index="index" item="item" open="(" separator="," close=")">
  2040. #{item}
  2041. </foreach>
  2042. </if>
  2043. </if>
  2044. <if test="params.aId != null">
  2045. AND
  2046. o.agent_Id in
  2047. <if test="aIds.size > 0 and aIds != null">
  2048. <foreach collection="aIds" index="index" item="aid" open="(" separator="," close=")">
  2049. #{aid}
  2050. </foreach>
  2051. </if>
  2052. </if>
  2053. <if test="params.receiptProvinceName != null and params.receiptProvinceName != ''">
  2054. AND o.receipt_province_name like concat('%', #{params.receiptProvinceName}, '%')
  2055. </if>
  2056. <if test="params.receiptCityName != null and params.receiptCityName != ''">
  2057. AND o.receipt_city_name like concat('%', #{params.receiptCityName}, '%')
  2058. </if>
  2059. <if test="params.receiptDistrictName != null and params.receiptDistrictName != ''">
  2060. AND o.receipt_district_name like concat('%', #{params.receiptDistrictName}, '%')
  2061. </if>
  2062. <if test="params.sendProvinceName != null and params.sendProvinceName != ''">
  2063. AND o.send_province_name like concat('%', #{params.sendProvinceName}, '%')
  2064. </if>
  2065. <if test="params.sendCityName != null and params.sendCityName != ''">
  2066. AND o.send_city_name like concat('%', #{params.sendCityName}, '%')
  2067. </if>
  2068. <if test="params.sendDistrictName != null and params.sendDistrictName != ''">
  2069. AND o.send_district_name like concat('%', #{params.sendDistrictName}, '%')
  2070. </if>
  2071. <if test="params.waimaiOrderType != null and params.waimaiOrderType != 4">
  2072. AND wo.order_type = #{params.waimaiOrderType}
  2073. </if>
  2074. <if test="params.waimaiOrderType != null and params.waimaiOrderType == 4">
  2075. AND o.waimai_order_id is null
  2076. </if>
  2077. <if test="params.paymentType != null">
  2078. AND (o.payment_type = #{params.paymentType} and o.status != 0)
  2079. </if>
  2080. </select>
  2081. <select id="getOrderInfoByOrderId" resultType="com.ydd.module.dto.OrderInfoDto">
  2082. SELECT
  2083. o.id as orderId,
  2084. o.waimai_order_id,
  2085. o.order_sn,
  2086. o.take_type,
  2087. o.member_id,
  2088. o.shop_id,
  2089. o.shop_name,
  2090. o.order_distance,
  2091. o.receipt_address_id,
  2092. o.receipt_province_name,
  2093. o.receipt_city_name,
  2094. o.receipt_district_name,
  2095. o.receipt_address,
  2096. o.receipt_contact_name,
  2097. o.receipt_phone,
  2098. o.receipt_extension,
  2099. o.receipt_city_code,
  2100. o.receipt_lng,
  2101. o.receipt_lat,
  2102. o.send_address_id,
  2103. o.send_province_name,
  2104. o.send_city_name,
  2105. o.send_district_name,
  2106. o.send_address,
  2107. o.send_contact_name,
  2108. o.send_phone,
  2109. o.send_extension,
  2110. o.send_city_code,
  2111. o.send_lng,
  2112. o.send_lat,
  2113. o.delivery_status,
  2114. o.delivery_id,
  2115. o.take_time,
  2116. o.take_remark,
  2117. o.delivery_time,
  2118. o.cancel_type,
  2119. o.product_id,
  2120. o.weight,
  2121. o.product_name,
  2122. o.pay_amount,
  2123. o.payment_type,
  2124. o.shipper_name,
  2125. o.shipper_phone,
  2126. o.delivery_logo,
  2127. o.delivery_name,
  2128. o.refund_money,
  2129. o.out_trade_no,
  2130. o.order_distance,
  2131. o.total_amount,
  2132. o.tip_amount,
  2133. o.coupon_amount,
  2134. o.first_coupon,
  2135. o.auto_delivery_minutes,
  2136. o.send_street,
  2137. o.receipt_street,
  2138. o.platform_type,
  2139. case when o.waimai_order_id is not null then wo.total_price
  2140. else o.product_amount end as productAmount,
  2141. wo.out_order_id,
  2142. case when wo.day_seq is not null then wo.day_seq
  2143. else o.lb_day_seq
  2144. end as day_seq,
  2145. wo.caution,
  2146. wo.waimai_id,
  2147. wo.order_type,
  2148. wo.status AS wmstatus,
  2149. wo.delivery_time AS wmDeliveryTime,
  2150. wo.order_time AS orderTime
  2151. FROM lb_order AS o
  2152. LEFT JOIN lb_waimai_order AS wo ON o.waimai_order_id = wo.id
  2153. WHERE o.id = #{orderId} and o.deleted = 0
  2154. </select>
  2155. <select id="getSubsidyList" resultType="com.ydd.module.dto.SubsidyStatisticsDto">
  2156. SELECT
  2157. sum(original) as originalAmount,
  2158. sum(reala) as realAmount,
  2159. sum(coup) as couponAmount,
  2160. (sum(original) - sum(reala)) as subsidyAmount,
  2161. delivery_name as deliveryName,
  2162. tim as date,
  2163. sum(commission) as commission,
  2164. if(sum(original) - sum(reala) &gt;0,-(sum(original) - sum(reala)+sum(commission)),abs(sum(original) - sum(reala))-sum(commission)) as profit
  2165. FROM
  2166. (
  2167. SELECT
  2168. o.max_amount original,
  2169. o.pay_amount - o.tip_amount reala,
  2170. o.pay_amount realb,
  2171. (select SUM(if(agent_id is not null,commission,0)) from lb_profits_detail d where d.order_id= o.id)commission,
  2172. o.coupon_amount coup,
  2173. o.delivery_name,
  2174. DATE_FORMAT(o.create_time, '%Y-%m-%d') tim
  2175. FROM
  2176. lb_order o
  2177. WHERE
  2178. o.id in(select DISTINCT order_id from lb_profits_detail d where d.create_time &gt;= #{params.startTime}
  2179. AND d.create_time &lt; #{params.endTime} and origin_source=0)
  2180. and o.delivery_status = 4
  2181. and o.payment_type!=5
  2182. and o.dada_dsp_id is null
  2183. ) t
  2184. GROUP BY deliveryName,date
  2185. ORDER BY date DESC
  2186. </select>
  2187. <select id="countPersonalOrder" resultType="java.lang.Integer">
  2188. SELECT
  2189. count(id)
  2190. FROM
  2191. lb_order
  2192. WHERE
  2193. member_id = #{memberId}
  2194. AND shop_id is null
  2195. AND delivery_status IN (0, 1, 2, 3, -1, -2)
  2196. AND create_time >= #{lastDayTime};
  2197. </select>
  2198. </mapper>