diff --git a/wrenchboard/src/include/wrenchboard_api.h b/wrenchboard/src/include/wrenchboard_api.h index 16578032..ab97ef29 100644 --- a/wrenchboard/src/include/wrenchboard_api.h +++ b/wrenchboard/src/include/wrenchboard_api.h @@ -103,6 +103,7 @@ enum { PARTNER_STRIPE }; #define RECOMMEND_BLOG 1005 #define RECOMMEND_NEWTASK 1010 #define RECOMMEND_TOKEN 1015 +#define RECOMMEND_OFFERS 1020 //======================== #define WRENCHBOARD_SESSION_CHECK 299 diff --git a/wrenchboard/src/shared_tool/cards.cc b/wrenchboard/src/shared_tool/cards.cc index cb625d46..99dfc4d2 100644 --- a/wrenchboard/src/shared_tool/cards.cc +++ b/wrenchboard/src/shared_tool/cards.cc @@ -69,13 +69,14 @@ long createMembercard(CVars in, CVars &out){ REQ_STRING(in, "title", 5, 34, "(.*)"); REQ_STRING(in, "description", 5, 54, "(.*)"); OPTIONAL(in, "blog_id") REQ_LONG(in, "blog_id", 1, -1); + OPTIONAL(in, "offer_id") REQ_LONG(in, "offer_id", 1, -1); const char * loc = getenv("REMOTE_ADDR"); bool continue_insert = false; //const PGresult *res = pgsql_query("SELECT id FROM members_cards WHERE member_id=%lu AND card_type = '%s'", in["member_id"].Long(), in["card_type"].c_str()); if (load_db_record(y, "SELECT * FROM members_cards WHERE member_id=%lu AND card_type = '%s' LIMIT 1", in["member_id"].Long(), in["card_type"].c_str()) > 0) { card_id = y["id"].Long(); - pgsql_exec("UPDATE members_cards SET active=NOW(),status =1 WHERE member_id=%lu AND card_type = '%s' AND id = %lu", member_id,in["card_type"].c_str(),card_id); + pgsql_exec("UPDATE members_cards SET active=NOW(),status =1,expire = now()+'2 days' WHERE member_id=%lu AND card_type = '%s' AND id = %lu", member_id,in["card_type"].c_str(),card_id); } else { @@ -98,13 +99,16 @@ long createMembercard(CVars in, CVars &out){ x["description"].set_valid(true); x["blog_id"] = in["blog_id"]; x["blog_id"].set_valid(true); + x["offer_id"] = in["offer_id"]; + x["offer_id"].set_valid(true); x["loc"] = loc; x["loc"].set_valid(true); - x["status"] = "1"; x["status"].set_valid(true); card_id = insert_db_record(DBS_VALID, "members_cards", "members_cards_id_seq", x); + pgsql_exec("UPDATE members_cards SET active = now(),expire = now()+'2 days' WHERE id = %lu",card_id); + // pgsql_exec("UPDATE members_cards SET expire = now()+'2 days' WHERE id = %lu",card_id); } diff --git a/wrenchboard/src/shared_tool/jobs.cc b/wrenchboard/src/shared_tool/jobs.cc index fb8f28cf..90c1ce39 100644 --- a/wrenchboard/src/shared_tool/jobs.cc +++ b/wrenchboard/src/shared_tool/jobs.cc @@ -14,6 +14,7 @@ #include "cfg.h" #include #include "common_tool.h" +#include "reco_engine.h" long WrenchJobsQuestion(CVars in, CVars &out); long WrenchMarketInterestQuestion(CVars in, CVars &out); @@ -666,6 +667,7 @@ long WrenchSendJobsOfferIndividual(CVars in, CVars &out) { job_email(JOBS_INDIVIDUAL_OFFER_MAIL, x, out); load_db_record(out, "SELECT *,id AS offer_id FROM members_jobs_offer WHERE id = %lu ", offer_id); out["status"] = "Offer sent to recipient"; + recommendation_engine(RECOMMEND_OFFERS , y, out); // trigger the card interaction in apps } else { out["status"] = "Unable to create this offer"; diff --git a/wrenchboard/src/shared_tool/reco_egine.cc b/wrenchboard/src/shared_tool/reco_egine.cc index b028df3b..cb591f20 100644 --- a/wrenchboard/src/shared_tool/reco_egine.cc +++ b/wrenchboard/src/shared_tool/reco_egine.cc @@ -19,8 +19,10 @@ #define RECOMMEND_BLOG 1005 #define RECOMMEND_NEWTASK 1010 #define RECOMMEND_TOKEN 1015 +#define RECOMMEND_OFFERS 1020 //======================== */ +long sendOffersRecommendation( CVars in, CVars &out); long sendCouponRecommendation( CVars in, CVars &out); long recommendation_engine(long action , CVars in, CVars &out) { try{ @@ -41,6 +43,10 @@ long recommendation_engine(long action , CVars in, CVars &out) { case RECOMMEND_TOKEN: return 0; break; + + case RECOMMEND_OFFERS: + return sendOffersRecommendation( in, out); + break; } } catch (bad_parameter) { @@ -49,6 +55,33 @@ long recommendation_engine(long action , CVars in, CVars &out) { return 0; } + +long sendOffersRecommendation( CVars in, CVars &out){ + + try{ + long member_id = REQ_LONG(in, "member_id", 1, -1); + REQ_LONG(in, "offer_id", 1, -1); + + if ( load_db_record(out, "SELECT client_id FROM members_jobs_offer WHERE id=%lu", in["offer_id"].Long())> 0){ + CVars xx; + CVars xout; + xx["action"] = WRENCHBOARD_CARDS_CREATECARD; xx["action"].set_valid( true ); + xx["member_id"] = out["client_id"]; xx["member_id"].set_valid( true ); // the card is going to job recipient + xx["title"] = "New job offer"; xx["title"].set_valid( true ); + xx["description"] = "You have received a new Task/Job offer"; xx["description"].set_valid( true ); + xx["card_type"] = "OFFERS"; xx["card_type"].set_valid( true ); + xx["card_style"] = "card2"; xx["card_style"].set_valid( true ); + xx["card_icon"] = "icon1"; xx["card_icon"].set_valid( true ); + xx["offer_id"] = in["offer_id"]; xx["offer_id"].set_valid( true ); + xx["blog_id"] = "0"; xx["blog_id"].set_valid( true ); + card_calls(xx, xout); + } + } catch (bad_parameter) { + logfmt(logINFO, "ERROR CALL long sendCouponRecommendation"); + } +return 0; +} + long sendCouponRecommendation( CVars in, CVars &out){ /* CVars xx; @@ -80,6 +113,7 @@ long sendCouponRecommendation( CVars in, CVars &out){ xx["card_style"] = "card1"; xx["card_style"].set_valid( true ); xx["card_icon"] = "icon1"; xx["card_icon"].set_valid( true ); xx["blog_id"] = "0"; xx["blog_id"].set_valid( true ); + xx["offer_id"] = "0"; xx["offer_id"].set_valid( true ); card_calls(xx, xout); } catch (bad_parameter) { logfmt(logINFO, "ERROR CALL long sendCouponRecommendation");