(SELECT org.org_name FROM t_behavior_qrcode_record record INNER JOIN t_shop_wxqrcode shop ON record.ticket = shop.ticket INNER JOIN t_orgunit org ON org.id = shop.bind_id WHERE record.openid = ord.openid AND org.del_flag = 0 AND record.del_flag = 0 AND shop.del_flag = 0 AND shop.type = 4 ORDER BY record.create_time DESC LIMIT 1) hospital,
(SELECT qyuser.name FROM t_behavior_qrcode_record record INNER JOIN t_shop_wxqrcode shop ON record.ticket = shop.ticket INNER JOIN t_orgunit org ON org.id = shop.bind_id INNER JOIN t_qyuser qyuser ON qyuser.org_id = shop.bind_id WHERE record.openid = ord.openid AND org.del_flag = 0 AND record.del_flag = 0 AND shop.del_flag = 0 AND shop.type = 4 AND qyuser.user_type = '5' AND qyuser.del_flag = 0 ORDER BY record.create_time DESC LIMIT 1) salesRepresent,
org.org_name department,
consult.allergy cfHospital,
consult.past_records cfDoctor,
consult.consult_id consultNumber,
ord.number orderNumber,
CONVERT ( AES_DECRYPT( consult.user_name, 'aideakey' ) USING UTF8 ) userName,
CONVERT ( AES_DECRYPT( consult.phone, 'aideakey' ) USING UTF8 ) phone,
CASE WHEN memb.status = '1' THEN '三期' ELSE '' END isThree,
product.common_name productName,
detail.drugs_num drugsNum,
ord.pay_time fkTime,
waybill.send_express_date fhTime,
waybill.accept_express_date sjTime
FROM
t_order ord
LEFT JOIN t_order_details detail ON ord.id = detail.order_id
LEFT JOIN t_aidea_product product ON product.id = detail.drugs_id AND product.del_flag = 0
LEFT JOIN t_aidea_consult_sheet consult ON ord.id = consult.order_id
LEFT JOIN wx_mp_member memb ON memb.open_id = consult.open_id AND memb.del_flag = 0
LEFT JOIN t_aidea_waybill waybill ON waybill.order_id = ord.id
LEFT JOIN t_aidea_report report ON report.order_number = ord.number
LEFT JOIN t_orgunit org ON org.id = memb.storeid AND org.del_flag = 0
<includerefid="sqlWhere"/>
<iftest="sort!=null">ORDER BY ${sort.param} ${sort.type}</if>