Files
WrenchBoradWeb/wrenchboard/src/shared_tool/reco_egine.cc
T
CHIEFSOFT\ameye ddd2bd3859 syntx fix
2023-05-30 13:44:23 -04:00

397 lines
16 KiB
C++

// Twillo management toosl
#include "clog.h"
#include "cgi.h"
#include "input.h"
#include "wrenchboard_api.h"
#include "reco_engine.h" //error in file name
#include "email.h"
#include "safestring.h"
#include <string>
#include "pgsql.h"
#include "pgsql_wrapper.h"
#include <curl/curl.h>
#include "account.h"
#include "cards.h"
#include "twilo.h"
#include "mobile.h"
/*
#define RECOMMEND_COUPON 1000
#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 RecoCheckOffers( int itm_count, CVars in, CVars &out );
long RecoCheckFamilyLogin( int itm_count, CVars in, CVars &out );
long RecoCheckFamilyCount( int itm_count, CVars in, CVars &out );
long RecoCheckCoupons( int itm_count, CVars in, CVars &out );
long RecoCheckTaskDue( int itm_count, CVars in, CVars &out );
long RecoCheckBlog( int itm_count, CVars in, CVars &out );
long recommendation_engine(long action , CVars in, CVars &out) {
try{
switch (action) {
case RECOMMEND_COUPON:
return sendCouponRecommendation( in, out);
break;
case RECOMMEND_BLOG:
return 0;
break;
case RECOMMEND_NEWTASK:
return 0;
break;
case RECOMMEND_TOKEN:
return 0;
break;
case RECOMMEND_OFFERS:
return sendOffersRecommendation( in, out);
break;
}
} catch (bad_parameter) {
logfmt(logINFO, "ERROR CALL long recommendation_engine");
}
return 0;
}
// also used from accounts
long WrenchHomeBanners(CVars in, CVars &out) {
out["status"] = "long WrenchHomeBanners(CVars in, CVars &out)";
CVars offV;
char vname[30];
WrenchReturnJobOffersList(in, offV);
long total_offers = offV["total_record"].Long();
if( total_offers > 0){
for (int i = 0, n = total_offers; i < n; i++) {
snprintf(vname, sizeof (vname), "title_%05d", i);
out[vname] = offV[vname];
snprintf(vname, sizeof (vname), "card_style_%05d", i);
out[vname] = offV[vname];
snprintf(vname, sizeof (vname), "description_%05d", i);
out[vname] = offV[vname];
snprintf(vname, sizeof (vname), "card_type_%05d", i);
out[vname] = "OFFERS";
snprintf(vname, sizeof (vname), "offer_id_%05d", i);
out[vname] = offV[vname];
snprintf(vname, sizeof (vname), "blog_id_%05d", i);
out[vname] = "0";
snprintf(vname, sizeof (vname), "card_icon_%05d", i);
out[vname] = "icon1";
snprintf(vname, sizeof (vname), "contract_%05d", i);
out[vname] = offV[vname];;
}
}
out["total_record"] = total_offers;
return 0;
}
long RecoCheckOffers(int itm_count, CVars in, CVars &out ){
logfmt(logINFO, "RecoCheckOffers()");
long ret = PHP_API_BAD_PARAM;
const PGresult *res;
char vname[30];
try {
// res = pgsql_query("SELECT * FROM members_jobs_offer WHERE expire > now() AND status = 1 AND client_id = %lu ",member_id);
// if (res != NULL && pgsql_num_rows(res) > 0) {
//
// snprintf(vname, sizeof (vname), "title_%05d", ic);
// out[vname] = "This is the offer available text";
//
// snprintf(vname, sizeof (vname), "description_%05d", ic);
// out[vname] = "This is the offer available text DESCRIPTIOON - This is the offer available text";
//
// snprintf(vname, sizeof (vname), "card_type_%05d", ic);
// out[vname] = "OFFERS";
//
// snprintf(vname, sizeof (vname), "offer_id_%05d", ic);
// out[vname] = "0";
//
// snprintf(vname, sizeof (vname), "blog_id_%05d", ic);
// out[vname] = "0";
//
// snprintf(vname, sizeof (vname), "card_icon_%05d", ic);
// out[vname] = "icon1";
//
// snprintf(vname, sizeof (vname), "banner_%05d", i);
// out[vname] ="https://blog.wrenchboard.com/wp-content/uploads/2022/01/wrechboard-sample.jpg";
//
// ret = PHP_API_OK;
// }
long member_id = REQ_LONG(in, "member_id", 1, -1);
int itm_count= 0;
if( RecoCheckOffers( itm_count, in, out ) != PHP_API_BAD_PARAM ) { itm_count++; }
if( RecoCheckFamilyLogin( itm_count, in, out ) != PHP_API_BAD_PARAM ) { itm_count++; }
if( RecoCheckFamilyCount( itm_count, in, out ) != PHP_API_BAD_PARAM ) { itm_count++; }
if( RecoCheckCoupons( itm_count, in, out ) != PHP_API_BAD_PARAM ) { itm_count++; }
//if( RecoCheckTaskDue( itm_count, in, out ) != PHP_API_BAD_PARAM ) { itm_count++; }
if( RecoCheckBlog( itm_count, in, out ) != PHP_API_BAD_PARAM ) { itm_count++; }
} catch (bad_parameter) {
out["status"] = "ERROR";
}
logfmt(logINFO, "/RecoCheckOffers()");
return ret;
}
long RecoCheckFamilyLogin(int itm_count, CVars in, CVars &out ){
//SELECT count(id) AS family_count FROM members_family WHERE member_id =1 AND status = 1 AND last_login IS NULL ;
logfmt(logINFO, "RecoCheckFamilyLogin()");
long ret = PHP_API_BAD_PARAM;
const PGresult *res;
char vname[30];
try {
int ic = itm_count;
long member_id = REQ_LONG(in, "member_id", 1, -1);
res = pgsql_query("SELECT count(id) AS family_count FROM members_family WHERE member_id = %lu AND status = 1 AND last_login IS NULL ",member_id);
if (res != NULL && pgsql_num_rows(res) > 0) {
snprintf(vname, sizeof (vname), "title_%05d", ic);
out[vname] = "This is the family not login text";
snprintf(vname, sizeof (vname), "description_%05d", ic);
out[vname] = "his is the family not login text DESCRIPTIOON - This is the offer available text";
snprintf(vname, sizeof (vname), "card_type_%05d", ic);
out[vname] = "FAMILY_NOLOGIN";
snprintf(vname, sizeof (vname), "offer_id_%05d", ic);
out[vname] = "0";
snprintf(vname, sizeof (vname), "blog_id_%05d", ic);
out[vname] = "0";
snprintf(vname, sizeof (vname), "card_icon_%05d", ic);
out[vname] = "icon1";
snprintf(vname, sizeof (vname), "banner_%05d", i);
out[vname] ="https://blog.wrenchboard.com/wp-content/uploads/2022/01/wrechboard-sample.jpg";
ret = PHP_API_OK;
}
} catch (bad_parameter) {
out["status"] = "ERROR";
}
logfmt(logINFO, "/RecoCheckFamilyLogin()");
return ret;
}
long RecoCheckFamilyCount( int itm_count, CVars in, CVars &out ){
//SELECT count(id) AS family_count FROM members_family WHERE member_id =1 AND status = 1 AND last_login IS NULL ;
logfmt(logINFO, "RecoCheckFamilyCount()");
long ret = PHP_API_BAD_PARAM;
const PGresult *res;
char vname[30];
try {
int ic = itm_count;
long member_id = REQ_LONG(in, "member_id", 1, -1);
res = pgsql_query("SELECT count(id) AS family_count FROM members_family WHERE member_id = %lu AND status = 1 AND last_login IS NULL ",member_id);
if (res != NULL && pgsql_num_rows(res) == 0) {
snprintf(vname, sizeof (vname), "title_%05d", ic);
out[vname] = "You can add your family text";
snprintf(vname, sizeof (vname), "description_%05d", ic);
out[vname] = "do you know his is the family not login text DESCRIPTION - This is the offer available text";
snprintf(vname, sizeof (vname), "card_type_%05d", ic);
out[vname] = "FAMILY_ADD";
snprintf(vname, sizeof (vname), "offer_id_%05d", ic);
out[vname] = "0";
snprintf(vname, sizeof (vname), "blog_id_%05d", ic);
out[vname] = "0";
snprintf(vname, sizeof (vname), "card_icon_%05d", ic);
out[vname] = "icon1";
snprintf(vname, sizeof (vname), "banner_%05d", i);
out[vname] ="https://blog.wrenchboard.com/wp-content/uploads/2022/01/wrechboard-sample.jpg";
ret = PHP_API_OK;
}
} catch (bad_parameter) {
out["status"] = "ERROR";
}
logfmt(logINFO, "/RecoCheckFamilyCount()");
return ret;
}
long RecoCheckCoupons( int itm_count, CVars in, CVars &out ){
//SELECT id AS coupons_count FROM coupons_allocation WHERE member_id =1 AND amount> 0 AND active IS NULL;
logfmt(logINFO, "RecoCheckCoupons()");
long ret = PHP_API_BAD_PARAM;
const PGresult *res;
char vname[30];
try {
int ic = itm_count;
long member_id = REQ_LONG(in, "member_id", 1, -1);
res = pgsql_query("SELECT id AS coupons_count FROM coupons_allocation WHERE member_id = %lu AND amount> 0 AND active IS NULL ",member_id);
if (res != NULL && pgsql_num_rows(res) > 0) {
snprintf(vname, sizeof (vname), "title_%05d", ic);
out[vname] = "Yo man , you have Coupons to play with";
snprintf(vname, sizeof (vname), "description_%05d", ic);
out[vname] = "his is the family not login text DESCRIPTIOON - This is the offer available text";
snprintf(vname, sizeof (vname), "card_type_%05d", ic);
out[vname] = "FAMILY_NOLOGIN";
snprintf(vname, sizeof (vname), "offer_id_%05d", ic);
out[vname] = "0";
snprintf(vname, sizeof (vname), "blog_id_%05d", ic);
out[vname] = "0";
snprintf(vname, sizeof (vname), "card_icon_%05d", ic);
out[vname] = "icon1";
snprintf(vname, sizeof (vname), "banner_%05d", i);
out[vname] ="https://blog.wrenchboard.com/wp-content/uploads/2022/01/wrechboard-sample.jpg";
ret = PHP_API_OK;
}
} catch (bad_parameter) {
out["status"] = "ERROR";
}
logfmt(logINFO, "/RecoCheckCoupons()");
return ret;
}
long RecoCheckTaskDue( int itm_count, CVars in, CVars &out ){
long ret = PHP_API_BAD_PARAM;
return ret;
}
long RecoCheckBlog( int itm_count, CVars in, CVars &out ){
long ret = PHP_API_BAD_PARAM;
logfmt(logINFO, "RecoCheckBlog()");
long ret = PHP_API_BAD_PARAM;
const PGresult *res;
char vname[30];
try {
int ic = itm_count;
long member_id = REQ_LONG(in, "member_id", 1, -1);
snprintf(vname, sizeof (vname), "title_%05d", ic);
out[vname] = "This is the blog title, yes blog title";
snprintf(vname, sizeof (vname), "description_%05d", ic);
out[vname] = "This is the blog title, yes blog title text DESCRIPTIOON - This is the blog title, yes blog title";
snprintf(vname, sizeof (vname), "card_type_%05d", ic);
out[vname] = "BLOG";
snprintf(vname, sizeof (vname), "offer_id_%05d", ic);
out[vname] = "0";
snprintf(vname, sizeof (vname), "blog_id_%05d", ic);
out[vname] = "0";
snprintf(vname, sizeof (vname), "card_icon_%05d", ic);
out[vname] = "icon1";
snprintf(vname, sizeof (vname), "banner_%05d", i);
out[vname] ="https://blog.wrenchboard.com/wp-content/uploads/2022/01/wrechboard-sample.jpg";
ret = PHP_API_OK;
} catch (bad_parameter) {
out["status"] = "ERROR";
}
logfmt(logINFO, "/RecoCheckBlog()");
return ret;
}
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;
xx["member_id"] = in["member_id"]; xx["member_id"].set_valid(true);
xx["code"] = rec["code"]; xx["code"].set_valid(true);
xx["amount"] = rec["amount"]; xx["amount"].set_valid(true);
xx["status"] = COUPON_ACTIVE; xx["status"].set_valid(true);
coupon_id = insert_db_record(DBS_VALID, "coupons_allocation", "coupons_allocation_id_seq", xx);
['title'=>'This is your coupon',
'description'=>'This is the description of the description',
'card_type'=>'COUPON',
'card_style' =>'card1',
'card_icon' =>'icon1',
'assign_id'=> 0,
*/
try{
long member_id = REQ_LONG(in, "member_id", 1, -1);
REQ_LONG(in, "coupon_id", 1, -1);
CVars xx;
CVars xout;
xx["action"] = WRENCHBOARD_CARDS_CREATECARD; xx["action"].set_valid( true );
xx["member_id"] = member_id; xx["member_id"].set_valid( true );
xx["title"] = "This is your coupon"; xx["title"].set_valid( true );
xx["description"] = "Click to redeem your coupon to your account"; xx["description"].set_valid( true );
xx["card_type"] = "COUPON"; xx["card_type"].set_valid( true );
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");
}
return 0;
}