fix
This commit is contained in:
@@ -3,7 +3,10 @@
|
||||
|
||||
#include "vars.h"
|
||||
|
||||
long card_calls(CVars in, CVars &out);
|
||||
|
||||
long card_calls(CVars in, CVars &out);
|
||||
long getMembercards(CVars in, CVars &out);
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
@@ -3,6 +3,6 @@
|
||||
|
||||
#include "vars.h"
|
||||
|
||||
|
||||
long recommendation_engine(long action , CVars in, CVars &out);
|
||||
|
||||
#endif
|
||||
@@ -99,7 +99,11 @@ enum { PARTNER_STRIPE };
|
||||
#define ACCOUNT_AGREE_REFER 200
|
||||
|
||||
//========================
|
||||
|
||||
#define RECOMMEND_COUPON 1000
|
||||
#define RECOMMEND_BLOG 1005
|
||||
#define RECOMMEND_NEWTASK 1010
|
||||
#define RECOMMEND_TOKEN 1015
|
||||
//========================
|
||||
|
||||
#define WRENCHBOARD_SESSION_CHECK 299
|
||||
#define WRENCHBOARD_USER_LOGIN 300
|
||||
@@ -238,9 +242,16 @@ enum { PARTNER_STRIPE };
|
||||
#define WRENCHBOARD_SMONEY_BKOPROC 33030
|
||||
|
||||
#define WRENCHBOARD_SMONEY_END 33999
|
||||
|
||||
//**************************************************************
|
||||
#define WRENCHBOARD_CARDS_START 40000
|
||||
|
||||
#define WRENCHBOARD_CARDS_GETCARDLIST 40010
|
||||
#define WRENCHBOARD_CARDS_UPDATECARD 40015
|
||||
#define WRENCHBOARD_CARDS_CREATECARD 40020
|
||||
|
||||
#define WRENCHBOARD_CARDS_END 49999
|
||||
//**************************************************************
|
||||
|
||||
#define WRENCHBOARD_LOGIN_SHOP 50501
|
||||
#define WRENCHBOARD_LOGIN_ADMIN 50502
|
||||
|
||||
@@ -11,21 +11,167 @@
|
||||
#include "pgsql_wrapper.h"
|
||||
#include <curl/curl.h>
|
||||
#include "account.h"
|
||||
#include "reco_engine.h"
|
||||
|
||||
#include "twilo.h"
|
||||
|
||||
long createMembercard(CVars in, CVars &out);
|
||||
long card_calls(CVars in, CVars &out) {
|
||||
logfmt(logINFO, "card_calls()");
|
||||
out["result"] = "YES I GET TO BACK END";
|
||||
long action = REQ_LONG(in, "action", 0, -1);
|
||||
CVars x;
|
||||
long ret = 0;
|
||||
const char * loc = getenv("REMOTE_ADDR");
|
||||
const PGresult *res;
|
||||
logfmt(logINFO, "action = %ld", action);
|
||||
//test();
|
||||
|
||||
long dummyCards(CVars in, CVars &out)
|
||||
{
|
||||
long ret = 0;
|
||||
logfmt( logINFO, "dummyReco()09-09-********~************");
|
||||
// REQ_STRING( in, "batch_name", 1, 50, "(.*)");
|
||||
// REQ_LONG( in, "customer_id", 1, -1 );
|
||||
CVars cust;
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
return ret;
|
||||
switch (action) {
|
||||
case WRENCHBOARD_CARDS_GETCARDLIST:
|
||||
return getMembercards(in, out);
|
||||
break;
|
||||
case WRENCHBOARD_CARDS_CREATECARD:
|
||||
return createMembercard(in, out);
|
||||
break;
|
||||
case WRENCHBOARD_CARDS_UPDATECARD:
|
||||
return 0; //CompleteMobileAccountCreation(in, out);
|
||||
break;
|
||||
}
|
||||
logfmt(logINFO, "/card_calls()");
|
||||
return ret;
|
||||
}
|
||||
/*
|
||||
CREATE TABLE members_cards (
|
||||
id SERIAL,
|
||||
card_type VARCHAR(15) REFERENCES card_type( code ) NOT NULL,
|
||||
card_style VARCHAR(15) REFERENCES card_style( style ) NOT NULL,
|
||||
card_icon VARCHAR(15) REFERENCES card_icon( icon ) NOT NULL,
|
||||
member_id INT REFERENCES members(id) NOT NULL,
|
||||
title VARCHAR(35) NOT NULL,
|
||||
description VARCHAR(55) NOT NULL,
|
||||
blog_id INT DEFAULT 0,
|
||||
added timestamp without time zone DEFAULT now(),
|
||||
expire timestamp without time zone DEFAULT now(),
|
||||
active timestamp DEFAULT NULL,
|
||||
loc INET,
|
||||
status INT DEFAULT 0
|
||||
);
|
||||
*/
|
||||
long createMembercard(CVars in, CVars &out){
|
||||
CVars y;
|
||||
long card_id = PHP_API_BAD_PARAM;
|
||||
try {
|
||||
long member_id = REQ_LONG(in, "member_id", 1, -1);
|
||||
REQ_STRING(in, "card_type", 5, 14, "(.*)");
|
||||
REQ_STRING(in, "card_style", 2, 14, "(.*)");
|
||||
REQ_STRING(in, "card_icon", 2, 14, "(.*)");
|
||||
REQ_STRING(in, "title", 5, 34, "(.*)");
|
||||
REQ_STRING(in, "description", 5, 54, "(.*)");
|
||||
OPTIONAL(in, "blog_id") REQ_LONG(in, "blog_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);
|
||||
}
|
||||
else
|
||||
{
|
||||
continue_insert= true;
|
||||
}
|
||||
|
||||
if(continue_insert){
|
||||
CVars x;
|
||||
x["member_id"] = member_id;
|
||||
x["member_id"].set_valid(true);
|
||||
x["card_type"] = in["card_type"];
|
||||
x["card_type"].set_valid(true);
|
||||
x["card_style"] = in["card_style"];
|
||||
x["card_style"].set_valid(true);
|
||||
x["card_icon"] = in["card_icon"];
|
||||
x["card_icon"].set_valid(true);
|
||||
x["title"] = in["title"];
|
||||
x["title"].set_valid(true);
|
||||
x["description"] = in["description"];
|
||||
x["description"].set_valid(true);
|
||||
x["blog_id"] = in["blog_id"];
|
||||
x["blog_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);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
} catch (bad_parameter) {
|
||||
logfmt(logINFO, "ERROR CALL long createMembercard");
|
||||
}
|
||||
logfmt(logINFO, "/createMembercard()");
|
||||
return card_id;
|
||||
}
|
||||
long getMembercards(CVars in, CVars &out){
|
||||
char vname[30];
|
||||
long ret = PHP_API_BAD_PARAM;
|
||||
|
||||
try {
|
||||
REQ_LONG(in, "member_id", 1, -1);
|
||||
out["total_record"] = "0";
|
||||
const PGresult *res;
|
||||
res = pgsql_query("SELECT * FROM members_cards WHERE member_id =%lu AND expire > now() AND status = 1 ORDER BY added DESC", in["member_id"].Long());
|
||||
|
||||
if (res != NULL && pgsql_num_rows(res) > 0) {
|
||||
out["total_record"] = pgsql_num_rows(res);
|
||||
|
||||
for (int i = 0, n = pgsql_num_rows(res); i < n; i++) {
|
||||
map<const char*, const char*>f = pgsql_fetch_assoc(res, i);
|
||||
if (f.empty()) continue;
|
||||
CVars rec;
|
||||
map_to_cvars(f, rec);
|
||||
|
||||
snprintf(vname, sizeof (vname), "assign_id_%05d", i);
|
||||
out[vname] = rec["id"];
|
||||
|
||||
snprintf(vname, sizeof (vname), "title_%05d", i);
|
||||
out[vname] = rec["title"];
|
||||
|
||||
// amount | id | code | description | symbol | action_type | lorder | current_balance
|
||||
snprintf(vname, sizeof (vname), "description_%05d", i);
|
||||
out[vname] = rec["description"];
|
||||
|
||||
snprintf(vname, sizeof (vname), "card_type_%05d", i);
|
||||
out[vname] = rec["card_type"];
|
||||
|
||||
snprintf(vname, sizeof (vname), "card_style_%05d", i);
|
||||
out[vname] = rec["card_style"];
|
||||
|
||||
snprintf(vname, sizeof (vname), "card_icon_%05d", i);
|
||||
out[vname] = rec["card_icon"];
|
||||
|
||||
}
|
||||
}
|
||||
ret = PHP_API_OK;
|
||||
out["status"] = "OK";
|
||||
} catch (bad_parameter) {
|
||||
logfmt(logINFO, "ERROR CALL long getMembercards(CVars in, CVars &out)");
|
||||
}
|
||||
logfmt(logINFO, "/getMembercards()");
|
||||
return ret;
|
||||
}
|
||||
|
||||
/*
|
||||
['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,
|
||||
'Nigeria'],
|
||||
['title'=>'A Recommended S
|
||||
*/
|
||||
|
||||
@@ -15,6 +15,7 @@
|
||||
#include "account_mngt.h"
|
||||
#include "creditcards.h"
|
||||
#include "payments.h"
|
||||
#include "reco_engine.h"
|
||||
|
||||
/*
|
||||
#define WRENCHBOARD_COUPON_START 85000
|
||||
@@ -151,7 +152,7 @@ CREATE TABLE coupons_allocation (
|
||||
pgsql_exec("UPDATE coupons SET active=now(), status=%lu WHERE code='%s' AND status=0",COUPON_ALLOC_STARTED,in["code"].c_str());
|
||||
// send allocation email
|
||||
coupon_email(WRENCHBOARD_COUPON_ACTIVATE, inx, out);
|
||||
|
||||
recommendation_engine(RECOMMEND_COUPON , inx, out); // trigger the card interaction in apps
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -11,21 +11,78 @@
|
||||
#include "pgsql_wrapper.h"
|
||||
#include <curl/curl.h>
|
||||
#include "account.h"
|
||||
|
||||
#include "cards.h"
|
||||
#include "twilo.h"
|
||||
|
||||
/*
|
||||
#define RECOMMEND_COUPON 1000
|
||||
#define RECOMMEND_BLOG 1005
|
||||
#define RECOMMEND_NEWTASK 1010
|
||||
#define RECOMMEND_TOKEN 1015
|
||||
//========================
|
||||
*/
|
||||
long sendCouponRecommendation( CVars in, CVars &out);
|
||||
long recommendation_engine(long action , CVars in, CVars &out) {
|
||||
try{
|
||||
|
||||
long dummyReco(CVars in, CVars &out)
|
||||
{
|
||||
long ret = 0;
|
||||
logfmt( logINFO, "dummyReco()09-09-********~************");
|
||||
// REQ_STRING( in, "batch_name", 1, 50, "(.*)");
|
||||
// REQ_LONG( in, "customer_id", 1, -1 );
|
||||
CVars cust;
|
||||
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;
|
||||
}
|
||||
|
||||
|
||||
return ret;
|
||||
} catch (bad_parameter) {
|
||||
logfmt(logINFO, "ERROR CALL long recommendation_engine");
|
||||
}
|
||||
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["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 );
|
||||
card_calls(xx, xout);
|
||||
} catch (bad_parameter) {
|
||||
logfmt(logINFO, "ERROR CALL long sendCouponRecommendation");
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
@@ -20,6 +20,7 @@
|
||||
#include "stripe_charge.h"
|
||||
#include "account_mngt.h"
|
||||
#include "coupons.h"
|
||||
#include "cards.h"
|
||||
|
||||
#include "twilo.h"
|
||||
//extern CSQL *sql;
|
||||
@@ -57,6 +58,11 @@ long wrenchboard_api_main(CVars in, CVars &out) {
|
||||
return sitecrons_calls(in, out);
|
||||
}
|
||||
|
||||
if (action >= WRENCHBOARD_CARDS_START && action <= WRENCHBOARD_CARDS_END) {
|
||||
logfmt(logINFO, "card_calls");
|
||||
return card_calls(in, out);
|
||||
}
|
||||
|
||||
if (action >= WRENCHBOARD_COUPON_START && action <= WRENCHBOARD_COUPON_END) {
|
||||
logfmt(logINFO, "coupons_calls");
|
||||
return coupons_calls(in, out);
|
||||
|
||||
Reference in New Issue
Block a user