SELECT
t0.ID as id,
t0.`NAME` as name,
t0.PHONE as phone,
t0.`CITY_CODE` as cityCode,
t0.SHOOTING_TIME as shootingTime,
t0.REMARK as remark,
t0.SOURCE_FROM as sourceFrom,-- 平臺來源
t0.REFER as refer,
t0.UPDATE_TIME as updateTime,
CONCAT(IFNULL(t0.SHOOTING_NAME,''),t1.SHOOTING_NAME) as shootingName,
t0.SHOOTING_ADDRESS as shootingAddress,
t0.CREATE_TIME as createTime,
CASE t0.OP_RESULT
WHEN 1 THEN '確認需求'
WHEN 2 THEN '無效需求'
WHEN 3 THEN '詢價需求'
WHEN 4 THEN '其餘需求'
ELSE ''
END as opResultStr,
t0.OP_EXPLAIN as opExplain,
t1.ORDER_ID as orderCode,
t2.name as sysName,-- 處理人
t0.STATUS as status,
t0.OP_TIME AS opTime,
t3.COUPONS_ID AS couponsId,
t5.DESCRIPTION AS couponsDescription,
t4.`CODE` AS couponsCode,
t5.EXPIRY_DATE AS couponsExpiryDate,
t3.STATE AS couponsState,
ao.ORDER_ID AS reqOrderCode,
ao.SHOOTING_NAME AS reqShootingName,
ci.CITY_NAME as cityName
FROM
V_TBL_REQUIREMENT AS t0
-- 問題出處
left join V_TBL_USER_ORDER t1 ON t1.REQUIREMENT_ID IS NOT NULL AND t0.ID = t1.REQUIREMENT_ID
left join t_user t2 ON t0.OP_CUSTOMMANAGER_ID = t2.id
LEFT JOIN V_TBL_COUPONS_USER t3 ON t0.ID = t3.REQUIREMENT_ID
LEFT JOIN V_TBL_COUPONS t4 ON t3.COUPONS_ID = t4.ID
LEFT JOIN V_TBL_COUPONS_TEMPLATE t5 ON t4.COUPON_TEMPLATE_ID = t5.ID
LEFT JOIN V_TBL_PHOTO_ALBUM a ON a.wechatMd5 = t0.WECHAT_MD5
LEFT JOIN V_TBL_USER_ORDER ao ON ao.ID = a.orderId
LEFT JOIN V_TBL_CITY ci on ci.CITY_CODE =t0.CITY_CODE
FROM V_TBL_REQUIREMENT AS t0 left join V_TBL_USER_ORDER t1 ON t1.REQUIREMENT_ID IS NOT NULL AND t0.ID = t1.REQUIREMENT_ID