Compare commits
No commits in common. "626f1252bee283065bf5f334852d8605396bf9e3" and "2dafc82d44cbb760220172d71f9ac5b02682bf3f" have entirely different histories.
626f1252be
...
2dafc82d44
@ -607,165 +607,91 @@ func GetPendingUploadBreakdownBySubNums(subNums []string) ([]*ArtistPendingUploa
|
|||||||
}
|
}
|
||||||
|
|
||||||
nowMonth := time.Now().Format("2006-01")
|
nowMonth := time.Now().Format("2006-01")
|
||||||
|
releasedVideoPackage := fmt.Sprintf("(SELECT COALESCE(SUM(bb2.bundle_video_number + bb2.monthly_bundle_limit_video_number + bb2.monthly_bundle_limit_expired_video_number + bb2.invalid_bundle_video_number + bb2.bundle_limit_video_consumption_number + bb2.bundle_limit_video_expired_consumption_number - bb2.monthly_bundle_limit_expired_video_consumption_number - bb2.monthly_bundle_limit_video_consumption_number), 0) FROM bundle_balance AS bb2 LEFT JOIN bundle_order_records bor2 ON bor2.uuid COLLATE utf8mb4_general_ci = bb2.order_uuid COLLATE utf8mb4_general_ci INNER JOIN (SELECT bb_inner.user_id, bb_inner.order_uuid, MAX(bb_inner.month) AS max_month FROM bundle_balance AS bb_inner LEFT JOIN bundle_order_records bor_inner ON bor_inner.uuid COLLATE utf8mb4_general_ci = bb_inner.order_uuid COLLATE utf8mb4_general_ci WHERE bb_inner.deleted_at IS NULL AND bor_inner.deleted_at IS NULL AND bor_inner.status=2 AND CAST(bb_inner.month AS CHAR) COLLATE utf8mb4_general_ci <= CAST('%s' AS CHAR) COLLATE utf8mb4_general_ci GROUP BY bb_inner.user_id, bb_inner.order_uuid) AS bb_latest ON bb2.user_id = bb_latest.user_id AND bb2.order_uuid COLLATE utf8mb4_general_ci = bb_latest.order_uuid COLLATE utf8mb4_general_ci AND CAST(bb2.month AS CHAR) COLLATE utf8mb4_general_ci = CAST(bb_latest.max_month AS CHAR) COLLATE utf8mb4_general_ci WHERE bb2.deleted_at IS NULL AND bor2.deleted_at IS NULL AND bor2.status=2 AND bb2.user_id = u.id)", nowMonth)
|
||||||
|
increaseVideoBase := fmt.Sprintf("(SELECT COALESCE(SUM(bb2.increase_video_number + bb2.monthly_increase_limit_video_number + bb2.monthly_increase_limit_expired_video_number + bb2.invalid_increase_video_number + bb2.increase_limit_video_consumption_number + bb2.increase_limit_video_expired_consumption_number - bb2.monthly_increase_limit_expired_video_consumption_number - bb2.monthly_increase_limit_video_consumption_number), 0) FROM bundle_balance AS bb2 LEFT JOIN bundle_order_records bor2 ON bor2.uuid COLLATE utf8mb4_general_ci = bb2.order_uuid COLLATE utf8mb4_general_ci INNER JOIN (SELECT bb_inner.user_id, bb_inner.order_uuid, MAX(bb_inner.month) AS max_month FROM bundle_balance AS bb_inner LEFT JOIN bundle_order_records bor_inner ON bor_inner.uuid COLLATE utf8mb4_general_ci = bb_inner.order_uuid COLLATE utf8mb4_general_ci WHERE bb_inner.deleted_at IS NULL AND bor_inner.deleted_at IS NULL AND bor_inner.status=2 AND CAST(bb_inner.month AS CHAR) COLLATE utf8mb4_general_ci <= CAST('%s' AS CHAR) COLLATE utf8mb4_general_ci GROUP BY bb_inner.user_id, bb_inner.order_uuid) AS bb_latest ON bb2.user_id = bb_latest.user_id AND bb2.order_uuid COLLATE utf8mb4_general_ci = bb_latest.order_uuid COLLATE utf8mb4_general_ci AND CAST(bb2.month AS CHAR) COLLATE utf8mb4_general_ci = CAST(bb_latest.max_month AS CHAR) COLLATE utf8mb4_general_ci WHERE bb2.deleted_at IS NULL AND bor2.deleted_at IS NULL AND bor2.status=2 AND bb2.user_id = u.id)", nowMonth)
|
||||||
|
increaseVideoTotal := fmt.Sprintf("((%s) + GREATEST(bb.manual_video_number - bb.manual_video_consumption_number, 0))", increaseVideoBase)
|
||||||
|
releasedVideoTotal := fmt.Sprintf("GREATEST((%s + %s) - (SELECT COUNT(1) FROM cast_work cw WHERE cw.artist_phone COLLATE utf8mb4_general_ci = u.tel_num COLLATE utf8mb4_general_ci AND cw.deleted_at = 0 AND cw.work_category = 2 AND cw.cost = 1), 0)", releasedVideoPackage, increaseVideoTotal)
|
||||||
|
|
||||||
sql := "WITH latest_bundle_balance AS (\n" +
|
releasedImagePackage := fmt.Sprintf("(SELECT COALESCE(SUM(bb2.bundle_image_number + bb2.monthly_bundle_limit_image_number + bb2.monthly_bundle_limit_expired_image_number + bb2.invalid_bundle_image_number + bb2.bundle_limit_image_consumption_number + bb2.bundle_limit_image_expired_consumption_number - bb2.monthly_bundle_limit_expired_image_consumption_number - bb2.monthly_bundle_limit_image_consumption_number), 0) FROM bundle_balance AS bb2 LEFT JOIN bundle_order_records bor2 ON bor2.uuid COLLATE utf8mb4_general_ci = bb2.order_uuid COLLATE utf8mb4_general_ci INNER JOIN (SELECT bb_inner.user_id, bb_inner.order_uuid, MAX(bb_inner.month) AS max_month FROM bundle_balance AS bb_inner LEFT JOIN bundle_order_records bor_inner ON bor_inner.uuid COLLATE utf8mb4_general_ci = bb_inner.order_uuid COLLATE utf8mb4_general_ci WHERE bb_inner.deleted_at IS NULL AND bor_inner.deleted_at IS NULL AND bor_inner.status=2 AND CAST(bb_inner.month AS CHAR) COLLATE utf8mb4_general_ci <= CAST('%s' AS CHAR) COLLATE utf8mb4_general_ci GROUP BY bb_inner.user_id, bb_inner.order_uuid) AS bb_latest ON bb2.user_id = bb_latest.user_id AND bb2.order_uuid COLLATE utf8mb4_general_ci = bb_latest.order_uuid COLLATE utf8mb4_general_ci AND CAST(bb2.month AS CHAR) COLLATE utf8mb4_general_ci = CAST(bb_latest.max_month AS CHAR) COLLATE utf8mb4_general_ci WHERE bb2.deleted_at IS NULL AND bor2.deleted_at IS NULL AND bor2.status=2 AND bb2.user_id = u.id)", nowMonth)
|
||||||
" SELECT\n" +
|
increaseImageBase := fmt.Sprintf("(SELECT COALESCE(SUM(bb2.increase_image_number + bb2.monthly_increase_limit_image_number + bb2.monthly_increase_limit_expired_image_number + bb2.invalid_increase_image_number + bb2.increase_limit_image_consumption_number + bb2.increase_limit_image_expired_consumption_number - bb2.monthly_increase_limit_expired_image_consumption_number - bb2.monthly_increase_limit_image_consumption_number), 0) FROM bundle_balance AS bb2 LEFT JOIN bundle_order_records bor2 ON bor2.uuid COLLATE utf8mb4_general_ci = bb2.order_uuid COLLATE utf8mb4_general_ci INNER JOIN (SELECT bb_inner.user_id, bb_inner.order_uuid, MAX(bb_inner.month) AS max_month FROM bundle_balance AS bb_inner LEFT JOIN bundle_order_records bor_inner ON bor_inner.uuid COLLATE utf8mb4_general_ci = bb_inner.order_uuid COLLATE utf8mb4_general_ci WHERE bb_inner.deleted_at IS NULL AND bor_inner.deleted_at IS NULL AND bor_inner.status=2 AND CAST(bb_inner.month AS CHAR) COLLATE utf8mb4_general_ci <= CAST('%s' AS CHAR) COLLATE utf8mb4_general_ci GROUP BY bb_inner.user_id, bb_inner.order_uuid) AS bb_latest ON bb2.user_id = bb_latest.user_id AND bb2.order_uuid COLLATE utf8mb4_general_ci = bb_latest.order_uuid COLLATE utf8mb4_general_ci AND CAST(bb2.month AS CHAR) COLLATE utf8mb4_general_ci = CAST(bb_latest.max_month AS CHAR) COLLATE utf8mb4_general_ci WHERE bb2.deleted_at IS NULL AND bor2.deleted_at IS NULL AND bor2.status=2 AND bb2.user_id = u.id)", nowMonth)
|
||||||
" bb.user_id,\n" +
|
increaseImageTotal := fmt.Sprintf("((%s) + GREATEST(bb.manual_image_number - bb.manual_image_consumption_number, 0))", increaseImageBase)
|
||||||
" COALESCE(SUM(\n" +
|
|
||||||
" bb.bundle_video_number + bb.monthly_bundle_limit_video_number + bb.monthly_bundle_limit_expired_video_number + bb.invalid_bundle_video_number +\n" +
|
|
||||||
" bb.bundle_limit_video_consumption_number + bb.bundle_limit_video_expired_consumption_number -\n" +
|
|
||||||
" bb.monthly_bundle_limit_expired_video_consumption_number - bb.monthly_bundle_limit_video_consumption_number\n" +
|
|
||||||
" ), 0) AS total_bundle_video,\n" +
|
|
||||||
" COALESCE(SUM(\n" +
|
|
||||||
" bb.increase_video_number + bb.monthly_increase_limit_video_number + bb.monthly_increase_limit_expired_video_number + bb.invalid_increase_video_number +\n" +
|
|
||||||
" bb.increase_limit_video_consumption_number + bb.increase_limit_video_expired_consumption_number -\n" +
|
|
||||||
" bb.monthly_increase_limit_expired_video_consumption_number - bb.monthly_increase_limit_video_consumption_number\n" +
|
|
||||||
" ), 0) AS total_increase_video,\n" +
|
|
||||||
" COALESCE(SUM(\n" +
|
|
||||||
" bb.bundle_image_number + bb.monthly_bundle_limit_image_number + bb.monthly_bundle_limit_expired_image_number + bb.invalid_bundle_image_number +\n" +
|
|
||||||
" bb.bundle_limit_image_consumption_number + bb.bundle_limit_image_expired_consumption_number -\n" +
|
|
||||||
" bb.monthly_bundle_limit_expired_image_consumption_number - bb.monthly_bundle_limit_image_consumption_number\n" +
|
|
||||||
" ), 0) AS total_bundle_image,\n" +
|
|
||||||
" COALESCE(SUM(\n" +
|
|
||||||
" bb.increase_image_number + bb.monthly_increase_limit_image_number + bb.monthly_increase_limit_expired_image_number + bb.invalid_increase_image_number +\n" +
|
|
||||||
" bb.increase_limit_image_consumption_number + bb.increase_limit_image_expired_consumption_number -\n" +
|
|
||||||
" bb.monthly_increase_limit_expired_image_consumption_number - bb.monthly_increase_limit_image_consumption_number\n" +
|
|
||||||
" ), 0) AS total_increase_image,\n" +
|
|
||||||
" COALESCE(SUM(\n" +
|
|
||||||
" bb.bundle_data_analysis_number + bb.monthly_bundle_limit_data_analysis_number + bb.monthly_bundle_limit_expired_data_analysis_number + bb.invalid_bundle_data_analysis_number +\n" +
|
|
||||||
" bb.bundle_limit_data_analysis_consumption_number + bb.bundle_limit_data_analysis_expired_consumption_number -\n" +
|
|
||||||
" bb.monthly_bundle_limit_expired_data_analysis_consumption_number - bb.monthly_bundle_limit_data_analysis_consumption_number\n" +
|
|
||||||
" ), 0) AS total_bundle_data,\n" +
|
|
||||||
" COALESCE(SUM(\n" +
|
|
||||||
" bb.increase_data_analysis_number + bb.monthly_increase_limit_data_analysis_number + bb.monthly_increase_limit_expired_data_analysis_number + bb.invalid_increase_data_analysis_number +\n" +
|
|
||||||
" bb.increase_limit_data_analysis_consumption_number + bb.increase_limit_data_analysis_expired_consumption_number -\n" +
|
|
||||||
" bb.monthly_increase_limit_expired_data_analysis_consumption_number - bb.monthly_increase_limit_data_analysis_consumption_number\n" +
|
|
||||||
" ), 0) AS total_increase_data\n" +
|
|
||||||
" FROM bundle_balance AS bb\n" +
|
|
||||||
" JOIN (\n" +
|
|
||||||
" SELECT bb_inner.user_id, bb_inner.order_uuid, MAX(bb_inner.month) AS max_month\n" +
|
|
||||||
" FROM bundle_balance AS bb_inner\n" +
|
|
||||||
" JOIN bundle_order_records bor_inner ON bor_inner.uuid COLLATE utf8mb4_general_ci = bb_inner.order_uuid COLLATE utf8mb4_general_ci AND bor_inner.deleted_at IS NULL AND bor_inner.status = 2\n" +
|
|
||||||
" WHERE bb_inner.deleted_at IS NULL AND CAST(bb_inner.month AS CHAR) COLLATE utf8mb4_general_ci <= CAST(? AS CHAR) COLLATE utf8mb4_general_ci\n" +
|
|
||||||
" GROUP BY bb_inner.user_id, bb_inner.order_uuid\n" +
|
|
||||||
" ) AS bb_latest ON bb.user_id = bb_latest.user_id AND bb.order_uuid COLLATE utf8mb4_general_ci = bb_latest.order_uuid COLLATE utf8mb4_general_ci AND CAST(bb.month AS CHAR) COLLATE utf8mb4_general_ci = CAST(bb_latest.max_month AS CHAR) COLLATE utf8mb4_general_ci\n" +
|
|
||||||
" JOIN bundle_order_records bor2 ON bor2.uuid COLLATE utf8mb4_general_ci = bb.order_uuid COLLATE utf8mb4_general_ci AND bor2.deleted_at IS NULL AND bor2.status = 2\n" +
|
|
||||||
" WHERE bb.deleted_at IS NULL\n" +
|
|
||||||
" GROUP BY bb.user_id\n" +
|
|
||||||
")\n" +
|
|
||||||
"SELECT\n" +
|
|
||||||
" rn.name AS user_name,\n" +
|
|
||||||
" u.tel_num AS tel_num,\n" +
|
|
||||||
" bor1.customer_num,\n" +
|
|
||||||
" GREATEST(\n" +
|
|
||||||
" COALESCE(lbb.total_bundle_video, 0) -\n" +
|
|
||||||
" COALESCE(wc.video_cost_type_1, 0) -\n" +
|
|
||||||
" GREATEST(COALESCE(wc.total_video_works, 0) - (COALESCE(wc.video_cost_type_1, 0) + COALESCE(wc.video_cost_type_2, 0)), 0),\n" +
|
|
||||||
" 0) AS pending_bundle_video_count,\n" +
|
|
||||||
" GREATEST(\n" +
|
|
||||||
" (COALESCE(lbb.total_increase_video, 0) + GREATEST(bb.manual_video_number - bb.manual_video_consumption_number, 0)) -\n" +
|
|
||||||
" COALESCE(wc.video_cost_type_2, 0) +\n" +
|
|
||||||
" LEAST(\n" +
|
|
||||||
" COALESCE(lbb.total_bundle_video, 0) -\n" +
|
|
||||||
" COALESCE(wc.video_cost_type_1, 0) -\n" +
|
|
||||||
" GREATEST(COALESCE(wc.total_video_works, 0) - (COALESCE(wc.video_cost_type_1, 0) + COALESCE(wc.video_cost_type_2, 0)), 0),\n" +
|
|
||||||
" 0),\n" +
|
|
||||||
" 0) AS pending_increase_video_count,\n" +
|
|
||||||
" GREATEST(\n" +
|
|
||||||
" COALESCE(lbb.total_bundle_image, 0) -\n" +
|
|
||||||
" COALESCE(wc.image_cost_type_1, 0) -\n" +
|
|
||||||
" GREATEST(COALESCE(wc.total_image_works, 0) - (COALESCE(wc.image_cost_type_1, 0) + COALESCE(wc.image_cost_type_2, 0)), 0),\n" +
|
|
||||||
" 0) AS pending_bundle_post_count,\n" +
|
|
||||||
" GREATEST(\n" +
|
|
||||||
" (COALESCE(lbb.total_increase_image, 0) + GREATEST(bb.manual_image_number - bb.manual_image_consumption_number, 0)) -\n" +
|
|
||||||
" COALESCE(wc.image_cost_type_2, 0) +\n" +
|
|
||||||
" LEAST(\n" +
|
|
||||||
" COALESCE(lbb.total_bundle_image, 0) -\n" +
|
|
||||||
" COALESCE(wc.image_cost_type_1, 0) -\n" +
|
|
||||||
" GREATEST(COALESCE(wc.total_image_works, 0) - (COALESCE(wc.image_cost_type_1, 0) + COALESCE(wc.image_cost_type_2, 0)), 0),\n" +
|
|
||||||
" 0),\n" +
|
|
||||||
" 0) AS pending_increase_post_count,\n" +
|
|
||||||
" GREATEST(\n" +
|
|
||||||
" COALESCE(lbb.total_bundle_data, 0) -\n" +
|
|
||||||
" COALESCE(ac.data_cost_type_1, 0) -\n" +
|
|
||||||
" GREATEST(COALESCE(ac.total_data_works, 0) - (COALESCE(ac.data_cost_type_1, 0) + COALESCE(ac.data_cost_type_2, 0)), 0),\n" +
|
|
||||||
" 0) AS pending_bundle_data_count,\n" +
|
|
||||||
" GREATEST(\n" +
|
|
||||||
" (COALESCE(lbb.total_increase_data, 0) + GREATEST(bb.manual_data_analysis_number - bb.manual_data_analysis_consumption_number, 0)) -\n" +
|
|
||||||
" COALESCE(ac.data_cost_type_2, 0) +\n" +
|
|
||||||
" LEAST(\n" +
|
|
||||||
" COALESCE(lbb.total_bundle_data, 0) -\n" +
|
|
||||||
" COALESCE(ac.data_cost_type_1, 0) -\n" +
|
|
||||||
" GREATEST(COALESCE(ac.total_data_works, 0) - (COALESCE(ac.data_cost_type_1, 0) + COALESCE(ac.data_cost_type_2, 0)), 0),\n" +
|
|
||||||
" 0),\n" +
|
|
||||||
" 0) AS pending_increase_data_count,\n" +
|
|
||||||
" GREATEST(\n" +
|
|
||||||
" GREATEST(\n" +
|
|
||||||
" (COALESCE(lbb.total_bundle_video, 0) + COALESCE(lbb.total_increase_video, 0) + GREATEST(bb.manual_video_number - bb.manual_video_consumption_number, 0)) -\n" +
|
|
||||||
" (SELECT COUNT(1) FROM cast_work cw WHERE cw.artist_phone COLLATE utf8mb4_general_ci = u.tel_num COLLATE utf8mb4_general_ci AND cw.deleted_at = 0 AND cw.work_category = 2 AND cw.cost = 1),\n" +
|
|
||||||
" 0) -\n" +
|
|
||||||
" (SELECT COUNT(1) FROM cast_video_script cvs WHERE CAST(u.id AS CHAR) COLLATE utf8mb4_general_ci = cvs.artist_uuid COLLATE utf8mb4_general_ci AND cvs.deleted_at = 0 AND FROM_UNIXTIME(cvs.created_at) >= bb.start_at AND FROM_UNIXTIME(cvs.created_at) <= bb.expired_at),\n" +
|
|
||||||
" 0) AS pending_video_script_count\n" +
|
|
||||||
"FROM\n" +
|
|
||||||
" bundle_order_records AS bor1\n" +
|
|
||||||
"JOIN\n" +
|
|
||||||
" (SELECT customer_id, MAX(created_at) AS max_created_time FROM bundle_order_records WHERE status = 2 AND deleted_at IS NULL GROUP BY customer_id) AS bor2\n" +
|
|
||||||
" ON bor1.customer_id = bor2.customer_id AND bor1.created_at = bor2.max_created_time\n" +
|
|
||||||
"JOIN `micro-account`.user u ON u.id = bor1.customer_id AND u.deleted_at = 0\n" +
|
|
||||||
"JOIN `micro-account`.real_name rn ON rn.id = u.real_name_id\n" +
|
|
||||||
"JOIN bundle_balance bb ON bb.order_uuid COLLATE utf8mb4_general_ci = bor1.uuid COLLATE utf8mb4_general_ci AND bb.user_id = u.id\n" +
|
|
||||||
"JOIN\n" +
|
|
||||||
" (SELECT user_id, MAX(month) AS month FROM bundle_balance WHERE deleted_at IS NULL GROUP BY user_id) AS newest_month\n" +
|
|
||||||
" ON bb.user_id = newest_month.user_id AND CAST(bb.month AS CHAR) COLLATE utf8mb4_general_ci = CAST(newest_month.month AS CHAR) COLLATE utf8mb4_general_ci\n" +
|
|
||||||
"LEFT JOIN latest_bundle_balance lbb ON lbb.user_id = u.id\n" +
|
|
||||||
"LEFT JOIN (\n" +
|
|
||||||
" SELECT\n" +
|
|
||||||
" artist_phone,\n" +
|
|
||||||
" COUNT(CASE WHEN work_category = 2 AND cwe.cost_type = 1 THEN 1 END) AS video_cost_type_1,\n" +
|
|
||||||
" COUNT(CASE WHEN work_category = 2 AND cwe.cost_type = 2 THEN 1 END) AS video_cost_type_2,\n" +
|
|
||||||
" COUNT(CASE WHEN work_category = 2 THEN 1 END) AS total_video_works,\n" +
|
|
||||||
" COUNT(CASE WHEN work_category = 1 AND cwe.cost_type = 1 THEN 1 END) AS image_cost_type_1,\n" +
|
|
||||||
" COUNT(CASE WHEN work_category = 1 AND cwe.cost_type = 2 THEN 1 END) AS image_cost_type_2,\n" +
|
|
||||||
" COUNT(CASE WHEN work_category = 1 THEN 1 END) AS total_image_works\n" +
|
|
||||||
" FROM cast_work cw\n" +
|
|
||||||
" LEFT JOIN cast_work_extra cwe ON cwe.work_uuid = cw.uuid AND cwe.deleted_at = 0\n" +
|
|
||||||
" WHERE cw.deleted_at = 0\n" +
|
|
||||||
" GROUP BY artist_phone\n" +
|
|
||||||
") wc ON wc.artist_phone COLLATE utf8mb4_general_ci = u.tel_num COLLATE utf8mb4_general_ci AND bb.start_at IS NOT NULL AND bb.expired_at IS NOT NULL\n" +
|
|
||||||
"LEFT JOIN (\n" +
|
|
||||||
" SELECT\n" +
|
|
||||||
" artist_phone,\n" +
|
|
||||||
" COUNT(CASE WHEN cwae.cost_type = 1 THEN 1 END) AS data_cost_type_1,\n" +
|
|
||||||
" COUNT(CASE WHEN cwae.cost_type = 2 THEN 1 END) AS data_cost_type_2,\n" +
|
|
||||||
" COUNT(1) AS total_data_works\n" +
|
|
||||||
" FROM cast_work_analysis cwa\n" +
|
|
||||||
" LEFT JOIN cast_work_analysis_extra cwae ON cwae.analysis_uuid = cwa.uuid AND cwae.deleted_at = 0\n" +
|
|
||||||
" WHERE cwa.deleted_at = 0\n" +
|
|
||||||
" GROUP BY artist_phone\n" +
|
|
||||||
") ac ON ac.artist_phone COLLATE utf8mb4_general_ci = u.tel_num COLLATE utf8mb4_general_ci AND bb.start_at IS NOT NULL AND bb.expired_at IS NOT NULL\n" +
|
|
||||||
"WHERE bor1.deleted_at IS NULL AND bor1.status = 2 AND bor1.customer_num IN ?\n" +
|
|
||||||
"GROUP BY u.id\n"
|
|
||||||
|
|
||||||
placeholders := strings.Repeat("?,", len(subNums))
|
releasedDataPackage := fmt.Sprintf("(SELECT COALESCE(SUM(bb2.bundle_data_analysis_number + bb2.monthly_bundle_limit_data_analysis_number + bb2.monthly_bundle_limit_expired_data_analysis_number + bb2.invalid_bundle_data_analysis_number + bb2.bundle_limit_data_analysis_consumption_number + bb2.bundle_limit_data_analysis_expired_consumption_number - bb2.monthly_bundle_limit_expired_data_analysis_consumption_number - bb2.monthly_bundle_limit_data_analysis_consumption_number), 0) FROM bundle_balance AS bb2 LEFT JOIN bundle_order_records bor2 ON bor2.uuid COLLATE utf8mb4_general_ci = bb2.order_uuid COLLATE utf8mb4_general_ci INNER JOIN (SELECT bb_inner.user_id, bb_inner.order_uuid, MAX(bb_inner.month) AS max_month FROM bundle_balance AS bb_inner LEFT JOIN bundle_order_records bor_inner ON bor_inner.uuid COLLATE utf8mb4_general_ci = bb_inner.order_uuid COLLATE utf8mb4_general_ci WHERE bb_inner.deleted_at IS NULL AND bor_inner.deleted_at IS NULL AND bor_inner.status=2 AND CAST(bb_inner.month AS CHAR) COLLATE utf8mb4_general_ci <= CAST('%s' AS CHAR) COLLATE utf8mb4_general_ci GROUP BY bb_inner.user_id, bb_inner.order_uuid) AS bb_latest ON bb2.user_id = bb_latest.user_id AND bb2.order_uuid COLLATE utf8mb4_general_ci = bb_latest.order_uuid COLLATE utf8mb4_general_ci AND CAST(bb2.month AS CHAR) COLLATE utf8mb4_general_ci = CAST(bb_latest.max_month AS CHAR) COLLATE utf8mb4_general_ci WHERE bb2.deleted_at IS NULL AND bor2.deleted_at IS NULL AND bor2.status=2 AND bb2.user_id = u.id)", nowMonth)
|
||||||
placeholders = placeholders[:len(placeholders)-1]
|
increaseDataBase := fmt.Sprintf("(SELECT COALESCE(SUM(bb2.increase_data_analysis_number + bb2.monthly_increase_limit_data_analysis_number + bb2.monthly_increase_limit_expired_data_analysis_number + bb2.invalid_increase_data_analysis_number + bb2.increase_limit_data_analysis_consumption_number + bb2.increase_limit_data_analysis_expired_consumption_number - bb2.monthly_increase_limit_expired_data_analysis_consumption_number - bb2.monthly_increase_limit_data_analysis_consumption_number), 0) FROM bundle_balance AS bb2 LEFT JOIN bundle_order_records bor2 ON bor2.uuid COLLATE utf8mb4_general_ci = bb2.order_uuid COLLATE utf8mb4_general_ci INNER JOIN (SELECT bb_inner.user_id, bb_inner.order_uuid, MAX(bb_inner.month) AS max_month FROM bundle_balance AS bb_inner LEFT JOIN bundle_order_records bor_inner ON bor_inner.uuid COLLATE utf8mb4_general_ci = bb_inner.order_uuid COLLATE utf8mb4_general_ci WHERE bb_inner.deleted_at IS NULL AND bor_inner.deleted_at IS NULL AND bor_inner.status=2 AND CAST(bb_inner.month AS CHAR) COLLATE utf8mb4_general_ci <= CAST('%s' AS CHAR) COLLATE utf8mb4_general_ci GROUP BY bb_inner.user_id, bb_inner.order_uuid) AS bb_latest ON bb2.user_id = bb_latest.user_id AND bb2.order_uuid COLLATE utf8mb4_general_ci = bb_latest.order_uuid COLLATE utf8mb4_general_ci AND CAST(bb2.month AS CHAR) COLLATE utf8mb4_general_ci = CAST(bb_latest.max_month AS CHAR) COLLATE utf8mb4_general_ci WHERE bb2.deleted_at IS NULL AND bor2.deleted_at IS NULL AND bor2.status=2 AND bb2.user_id = u.id)", nowMonth)
|
||||||
sql = strings.Replace(sql, "bor1.customer_num IN ?", "bor1.customer_num IN ("+placeholders+")", 1)
|
increaseDataTotal := fmt.Sprintf("((%s) + GREATEST(bb.manual_data_analysis_number - bb.manual_data_analysis_consumption_number, 0))", increaseDataBase)
|
||||||
|
|
||||||
args := make([]interface{}, 0, 1+len(subNums))
|
scriptCount := "(SELECT COUNT(1) FROM cast_video_script cvs WHERE CAST(bb.user_id AS CHAR) COLLATE utf8mb4_general_ci = cvs.artist_uuid COLLATE utf8mb4_general_ci AND cvs.deleted_at = 0 AND FROM_UNIXTIME(cvs.created_at) >= bb.start_at AND FROM_UNIXTIME(cvs.created_at) <= bb.expired_at)"
|
||||||
args = append(args, nowMonth)
|
|
||||||
for i := range subNums {
|
totalVideoCount := "(SELECT COUNT(1) FROM cast_work cw WHERE cw.artist_phone COLLATE utf8mb4_general_ci = u.tel_num COLLATE utf8mb4_general_ci AND cw.deleted_at = 0 AND cw.work_category = 2 AND cw.submit_time >= bb.start_at AND cw.submit_time <= bb.expired_at)"
|
||||||
args = append(args, subNums[i])
|
knownPkgVideoCount := "(SELECT COUNT(1) FROM cast_work cw INNER JOIN cast_work_extra cwe ON cwe.work_uuid = cw.uuid AND cwe.deleted_at = 0 WHERE cw.artist_phone COLLATE utf8mb4_general_ci = u.tel_num COLLATE utf8mb4_general_ci AND cw.deleted_at = 0 AND cw.work_category = 2 AND cw.submit_time >= bb.start_at AND cw.submit_time <= bb.expired_at AND cwe.cost_type = 1)"
|
||||||
}
|
knownIncVideoCount := "(SELECT COUNT(1) FROM cast_work cw INNER JOIN cast_work_extra cwe ON cwe.work_uuid = cw.uuid AND cwe.deleted_at = 0 WHERE cw.artist_phone COLLATE utf8mb4_general_ci = u.tel_num COLLATE utf8mb4_general_ci AND cw.deleted_at = 0 AND cw.work_category = 2 AND cw.submit_time >= bb.start_at AND cw.submit_time <= bb.expired_at AND cwe.cost_type = 2)"
|
||||||
|
unknownVideoCount := fmt.Sprintf("GREATEST(%s - ((%s) + (%s)), 0)", totalVideoCount, knownPkgVideoCount, knownIncVideoCount)
|
||||||
|
|
||||||
|
totalPostCount := "(SELECT COUNT(1) FROM cast_work cw WHERE cw.artist_phone COLLATE utf8mb4_general_ci = u.tel_num COLLATE utf8mb4_general_ci AND cw.deleted_at = 0 AND cw.work_category = 1 AND cw.submit_time >= bb.start_at AND cw.submit_time <= bb.expired_at)"
|
||||||
|
knownPkgPostCount := "(SELECT COUNT(1) FROM cast_work cw INNER JOIN cast_work_extra cwe ON cwe.work_uuid = cw.uuid AND cwe.deleted_at = 0 WHERE cw.artist_phone COLLATE utf8mb4_general_ci = u.tel_num COLLATE utf8mb4_general_ci AND cw.deleted_at = 0 AND cw.work_category = 1 AND cw.submit_time >= bb.start_at AND cw.submit_time <= bb.expired_at AND cwe.cost_type = 1)"
|
||||||
|
knownIncPostCount := "(SELECT COUNT(1) FROM cast_work cw INNER JOIN cast_work_extra cwe ON cwe.work_uuid = cw.uuid AND cwe.deleted_at = 0 WHERE cw.artist_phone COLLATE utf8mb4_general_ci = u.tel_num COLLATE utf8mb4_general_ci AND cw.deleted_at = 0 AND cw.work_category = 1 AND cw.submit_time >= bb.start_at AND cw.submit_time <= bb.expired_at AND cwe.cost_type = 2)"
|
||||||
|
unknownPostCount := fmt.Sprintf("GREATEST(%s - ((%s) + (%s)), 0)", totalPostCount, knownPkgPostCount, knownIncPostCount)
|
||||||
|
|
||||||
|
totalDataCount := "(SELECT COUNT(1) FROM cast_work_analysis cwa WHERE cwa.artist_phone COLLATE utf8mb4_general_ci = u.tel_num COLLATE utf8mb4_general_ci AND cwa.deleted_at = 0 AND FROM_UNIXTIME(cwa.submit_time) >= bb.start_at AND FROM_UNIXTIME(cwa.submit_time) <= bb.expired_at)"
|
||||||
|
knownPkgDataCount := "(SELECT COUNT(1) FROM cast_work_analysis cwa INNER JOIN cast_work_analysis_extra cwae ON cwae.analysis_uuid = cwa.uuid AND cwae.deleted_at = 0 WHERE cwa.artist_phone COLLATE utf8mb4_general_ci = u.tel_num COLLATE utf8mb4_general_ci AND cwa.deleted_at = 0 AND FROM_UNIXTIME(cwa.submit_time) >= bb.start_at AND FROM_UNIXTIME(cwa.submit_time) <= bb.expired_at AND cwae.cost_type = 1)"
|
||||||
|
knownIncDataCount := "(SELECT COUNT(1) FROM cast_work_analysis cwa INNER JOIN cast_work_analysis_extra cwae ON cwae.analysis_uuid = cwa.uuid AND cwae.deleted_at = 0 WHERE cwa.artist_phone COLLATE utf8mb4_general_ci = u.tel_num COLLATE utf8mb4_general_ci AND cwa.deleted_at = 0 AND FROM_UNIXTIME(cwa.submit_time) >= bb.start_at AND FROM_UNIXTIME(cwa.submit_time) <= bb.expired_at AND cwae.cost_type = 2)"
|
||||||
|
unknownDataCount := fmt.Sprintf("GREATEST(%s - ((%s) + (%s)), 0)", totalDataCount, knownPkgDataCount, knownIncDataCount)
|
||||||
|
|
||||||
|
selectFields := fmt.Sprintf(`
|
||||||
|
rn.name as user_name,
|
||||||
|
u.tel_num as tel_num,
|
||||||
|
bor.customer_num,
|
||||||
|
GREATEST((%s) - (%s), 0) AS pending_video_script_count,
|
||||||
|
GREATEST((%s) - (%s) - (%s), 0) AS pending_bundle_video_count,
|
||||||
|
GREATEST((%s) - (%s) + LEAST((%s) - (%s) - (%s), 0), 0) AS pending_increase_video_count,
|
||||||
|
GREATEST((%s) - (%s) - (%s), 0) AS pending_bundle_post_count,
|
||||||
|
GREATEST((%s) - (%s) + LEAST((%s) - (%s) - (%s), 0), 0) AS pending_increase_post_count,
|
||||||
|
GREATEST((%s) - (%s) - (%s), 0) AS pending_bundle_data_count,
|
||||||
|
GREATEST((%s) - (%s) + LEAST((%s) - (%s) - (%s), 0), 0) AS pending_increase_data_count
|
||||||
|
`,
|
||||||
|
releasedVideoTotal, scriptCount,
|
||||||
|
releasedVideoPackage, knownPkgVideoCount, unknownVideoCount,
|
||||||
|
increaseVideoTotal, knownIncVideoCount, releasedVideoPackage, knownPkgVideoCount, unknownVideoCount,
|
||||||
|
releasedImagePackage, knownPkgPostCount, unknownPostCount,
|
||||||
|
increaseImageTotal, knownIncPostCount, releasedImagePackage, knownPkgPostCount, unknownPostCount,
|
||||||
|
releasedDataPackage, knownPkgDataCount, unknownDataCount,
|
||||||
|
increaseDataTotal, knownIncDataCount, releasedDataPackage, knownPkgDataCount, unknownDataCount,
|
||||||
|
)
|
||||||
|
|
||||||
|
subQuery := app.ModuleClients.BundleDB.Table("bundle_order_records as bor1").
|
||||||
|
Select("bor1.*").
|
||||||
|
Joins(`INNER JOIN (
|
||||||
|
SELECT customer_id, MAX(created_at) AS max_created_time
|
||||||
|
FROM bundle_order_records
|
||||||
|
GROUP BY customer_id
|
||||||
|
) bor2 ON bor1.customer_id = bor2.customer_id AND bor1.created_at = bor2.max_created_time`)
|
||||||
|
|
||||||
|
newestMonthQuery := app.ModuleClients.BundleDB.Table("bundle_balance").
|
||||||
|
Select("max(month) as month, user_id").
|
||||||
|
Where("deleted_at IS NULL").
|
||||||
|
Group("user_id")
|
||||||
|
|
||||||
|
base := app.ModuleClients.BundleDB.Table("`micro-account`.`user` AS u").Unscoped().
|
||||||
|
Select(selectFields).
|
||||||
|
Joins("LEFT JOIN `micro-account`.real_name rn ON u.real_name_id = rn.id").
|
||||||
|
Joins("LEFT JOIN (?) as bor ON bor.customer_id = u.id", subQuery).
|
||||||
|
Joins("LEFT JOIN bundle_balance bb ON u.id = bb.user_id AND bb.order_uuid COLLATE utf8mb4_general_ci = bor.uuid COLLATE utf8mb4_general_ci").
|
||||||
|
Joins("LEFT JOIN (?) as newest_month ON newest_month.user_id = bb.user_id", newestMonthQuery).
|
||||||
|
Where("u.deleted_at = 0").
|
||||||
|
Where("bor.deleted_at IS NULL").
|
||||||
|
Where("CAST(bb.month AS CHAR) COLLATE utf8mb4_general_ci = CAST(newest_month.month AS CHAR) COLLATE utf8mb4_general_ci").
|
||||||
|
Where("bor.customer_num IN ?", subNums)
|
||||||
|
|
||||||
items := make([]ArtistPendingUploadBreakdownItem, 0)
|
items := make([]ArtistPendingUploadBreakdownItem, 0)
|
||||||
if err := app.ModuleClients.BundleDB.Raw(sql, args...).Scan(&items).Error; err != nil {
|
if err := base.Find(&items).Error; err != nil {
|
||||||
return nil, commonErr.ReturnError(err, "查询待发细分数量失败", "查询待发细分数量失败: ")
|
return nil, commonErr.ReturnError(err, "查询待发细分数量失败", "查询待发细分数量失败: ")
|
||||||
}
|
}
|
||||||
|
|
||||||
resp := make([]*ArtistPendingUploadBreakdownItem, 0, len(items))
|
resp2 := make([]*ArtistPendingUploadBreakdownItem, 0, len(items))
|
||||||
for i := range items {
|
for i := range items {
|
||||||
resp = append(resp, &items[i])
|
resp2 = append(resp2, &items[i])
|
||||||
}
|
}
|
||||||
return resp, nil
|
return resp2, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// AssignTask 指派某位员工完成某个艺人的任务
|
// AssignTask 指派某位员工完成某个艺人的任务
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user