Backend Service

This commit is contained in:
2019-03-14 09:25:13 +00:00
parent 4522319a38
commit 41a75b9c3c
2 changed files with 357 additions and 376 deletions
+30 -44
View File
@@ -12,86 +12,72 @@
//char confirmation[20] = ""; //char confirmation[20] = "";
//Confirmation(payment_id, confirmation, sizeof (confirmation)); //Confirmation(payment_id, confirmation, sizeof (confirmation));
void GenerateInnerConfirmationSeed(char * number, int sz, int seed) {
void GenerateInnerConfirmationSeed( char * number, int sz, int seed )
{
char chars[] = "WRB01234WRB56789WRB"; char chars[] = "WRB01234WRB56789WRB";
int n = sizeof(chars); int n = sizeof (chars);
int i; int i;
/* /*
time_t t; time_t t;
time( &t ); time( &t );
pid_t pid = getpid(); pid_t pid = getpid();
srand(t+pid); srand(t+pid);
*/ */
srand((unsigned int)time((time_t *)NULL)); srand((unsigned int) time((time_t *) NULL));
for ( i=0; i<10 && i<sz-1; i++ ) for (i = 0; i < 10 && i < sz - 1; i++) {
{ int k = seed % n;
int k = seed%n; if (seed > 1 && k == i) {
if (seed>1 && k==i) { number[i] = chars[n - k];
number[i] = chars[n-k];
} else { } else {
number[i] = chars[ (int) ( (n-1.0)*rand()/(RAND_MAX+1.0)) ]; number[i] = chars[ (int) ((n - 1.0) * rand() / (RAND_MAX + 1.0)) ];
} }
} }
number[i] = 0; number[i] = 0;
} }
void ConfirmationNew(unsigned long payment_id, char * number, int sz) {
void ConfirmationNew( unsigned long payment_id, char * number, int sz )
{
SQLINTEGER rows; SQLINTEGER rows;
char confirmation[11]; char confirmation[11];
// Lock table to prevent generation of two identical confirmation numbers // Lock table to prevent generation of two identical confirmation numbers
pgsql_exec("BEGIN; LOCK TABLE members_payments;" ); pgsql_exec("BEGIN; LOCK TABLE members_payments;");
int i = 0; int i = 0;
do do {
{ GenerateInnerConfirmationSeed(confirmation, sizeof (confirmation), i++);
GenerateInnerConfirmationSeed( confirmation, sizeof(confirmation), i++ );
//st.CloseCursor(); //st.CloseCursor();
rows = 0; rows = 0;
const PGresult *res = pgsql_query("SELECT id FROM members_payments WHERE confirmation='%s'", confirmation ); const PGresult *res = pgsql_query("SELECT id FROM members_payments WHERE confirmation='%s'", confirmation);
if (res!=NULL ) if (res != NULL) {
{
rows = pgsql_num_rows(res); rows = pgsql_num_rows(res);
} }
} while ( rows>0 && i<100 ); } while (rows > 0 && i < 100);
pgsql_exec("UPDATE members_payments SET confirmation='%s', dt_confirmed=now() WHERE id=%lu", confirmation, payment_id ); pgsql_exec("UPDATE members_payments SET confirmation='%s', dt_confirmed=now() WHERE id=%lu", confirmation, payment_id);
pgsql_exec("COMMIT" ); // Unlock table 'data' pgsql_exec("COMMIT"); // Unlock table 'data'
strsafecpy( number, confirmation, sz ); strsafecpy(number, confirmation, sz);
} }
void GetMemberAccountLink(long member_id, unsigned long acc_link, char * number) {
void GetMemberAccountLink( long member_id, unsigned long acc_link, char * number )
{
SQLINTEGER rows; SQLINTEGER rows;
char offer_code[14]; char offer_code[14];
// Lock table to prevent generation of two identical confirmation numbers // Lock table to prevent generation of two identical confirmation numbers
pgsql_exec("BEGIN; LOCK TABLE members_jobs_offer;" ); pgsql_exec("BEGIN; LOCK TABLE members;");
int i = 0; int i = 0;
do do {
{ GenerateInnerConfirmationSeed(offer_code, sizeof (offer_code), i++);
GenerateInnerConfirmationSeed( offer_code, sizeof(offer_code), i++ );
//st.CloseCursor(); //st.CloseCursor();
rows = 0; rows = 0;
const PGresult *res = pgsql_query("SELECT id FROM members WHERE offer_code='%s'", offer_code ); const PGresult *res = pgsql_query("SELECT id FROM members WHERE acc_link='%s'", offer_code);
if (res!=NULL ) if (res != NULL) {
{
rows = pgsql_num_rows(res); rows = pgsql_num_rows(res);
} }
} while ( rows>0 && i<100 ); } while (rows > 0 && i < 100);
pgsql_exec("UPDATE members_jobs_offer SET acc_link='%s' WHERE id=%lu", offer_code, member_id ); pgsql_exec("UPDATE members SET acc_link='%s' WHERE id=%lu", offer_code, member_id);
pgsql_exec("COMMIT" ); // Unlock table 'data' pgsql_exec("COMMIT"); // Unlock table 'data'
// strsafecpy( acc_link, offer_code, sz ); // strsafecpy( acc_link, offer_code, sz );
} }
+37 -42
View File
@@ -20,7 +20,7 @@
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <assert.h> #include <assert.h>
*/ */
/* -- */ /* -- */
#include "function_members.h" #include "function_members.h"
@@ -137,7 +137,6 @@ long MemberSessionCheck(long uid, const char *sessionid, int create) {
return 0L; // No route return 0L; // No route
} }
long CreateMember(CVars in, CVars &out) { long CreateMember(CVars in, CVars &out) {
long ret = PHP_API_BAD_PARAM; long ret = PHP_API_BAD_PARAM;
logfmt(logINFO, "CreateMember()"); logfmt(logINFO, "CreateMember()");
@@ -241,17 +240,18 @@ long CreateMember(CVars in, CVars &out) {
} }
} }
}catch (bad_parameter) { } catch (bad_parameter) {
logfmt(logINFO, "ERROR CALL CreateMember"); logfmt(logINFO, "ERROR CALL CreateMember");
} }
logfmt(logINFO, "/CreateMember()"); logfmt(logINFO, "/CreateMember()");
return ret; return ret;
} }
long getMemberProfile(CVars in, CVars &out); long getMemberProfile(CVars in, CVars &out);
long MemberProfile(CVars in, CVars &out){
long MemberProfile(CVars in, CVars &out) {
try{ try {
long task_mode = REQ_LONG(in, "task_mode", 0, -1); long task_mode = REQ_LONG(in, "task_mode", 0, -1);
REQ_LONG(in, "member_id", 0, -1); REQ_LONG(in, "member_id", 0, -1);
switch (task_mode) { switch (task_mode) {
@@ -263,14 +263,13 @@ long MemberProfile(CVars in, CVars &out){
return getMemberProfile(in, out); return getMemberProfile(in, out);
break; break;
} }
}catch (bad_parameter) { } catch (bad_parameter) {
logfmt(logINFO, "ERROR CALL CreateMember"); logfmt(logINFO, "ERROR CALL CreateMember");
} }
logfmt(logINFO, "/MemberReminders()"); logfmt(logINFO, "/MemberReminders()");
return 0; return 0;
} }
long getMemberProfile(CVars in, CVars &out) { long getMemberProfile(CVars in, CVars &out) {
@@ -367,9 +366,9 @@ long medTrUpdateProfile(CVars in, CVars &out) {
long setMemberReminders(CVars in, CVars &out); long setMemberReminders(CVars in, CVars &out);
long getMemberReminders(CVars in, CVars &out); long getMemberReminders(CVars in, CVars &out);
long MemberReminders(CVars in, CVars &out)
{ long MemberReminders(CVars in, CVars &out) {
try{ try {
long task_mode = REQ_LONG(in, "task_mode", 0, -1); long task_mode = REQ_LONG(in, "task_mode", 0, -1);
switch (task_mode) { switch (task_mode) {
case USER_CREATETASK: case USER_CREATETASK:
@@ -380,14 +379,13 @@ long MemberReminders(CVars in, CVars &out)
return getMemberReminders(in, out); return getMemberReminders(in, out);
break; break;
} }
}catch (bad_parameter) { } catch (bad_parameter) {
logfmt(logINFO, "ERROR CALL CreateMember"); logfmt(logINFO, "ERROR CALL CreateMember");
} }
logfmt(logINFO, "/MemberReminders()"); logfmt(logINFO, "/MemberReminders()");
return 0; return 0;
} }
long setMemberReminders(CVars in, CVars &out) { long setMemberReminders(CVars in, CVars &out) {
long ret = PHP_API_BAD_PARAM; long ret = PHP_API_BAD_PARAM;
logfmt(logINFO, "CreateMember()"); logfmt(logINFO, "CreateMember()");
@@ -437,7 +435,7 @@ long setMemberReminders(CVars in, CVars &out) {
} }
} }
}catch (bad_parameter) { } catch (bad_parameter) {
logfmt(logINFO, "ERROR CALL CreateMember"); logfmt(logINFO, "ERROR CALL CreateMember");
} }
logfmt(logINFO, "/CreateMember()"); logfmt(logINFO, "/CreateMember()");
@@ -458,16 +456,16 @@ members_reminders
status = 1 status = 1
*/ */
long getMemberReminders(CVars in, CVars &out) { long getMemberReminders(CVars in, CVars &out) {
long ret = PHP_API_BAD_PARAM; long ret = PHP_API_BAD_PARAM;
char vname[20]; char vname[20];
try { try {
// REQ_LONG(in, "status", 0, -1); // REQ_LONG(in, "status", 0, -1);
REQ_LONG( in, "member_id", 0, -1); REQ_LONG(in, "member_id", 0, -1);
out["total_record"] = "0"; out["total_record"] = "0";
const PGresult *res = pgsql_query("SELECT *,start_date::date AS start_date_formatted,end_date::date AS end_date_formatted FROM members_reminders WHERE member_id = %lu AND status = 1 ORDER BY start_date ASC",in["member_id"].Long()); const PGresult *res = pgsql_query("SELECT *,start_date::date AS start_date_formatted,end_date::date AS end_date_formatted FROM members_reminders WHERE member_id = %lu AND status = 1 ORDER BY start_date ASC", in["member_id"].Long());
if (res != NULL && pgsql_num_rows(res) > 0) { if (res != NULL && pgsql_num_rows(res) > 0) {
out["total_record"] = pgsql_num_rows(res); out["total_record"] = pgsql_num_rows(res);
@@ -519,7 +517,7 @@ long medTrMemberTransportById(CVars in, CVars &out) {
long ret = PHP_API_BAD_PARAM; long ret = PHP_API_BAD_PARAM;
ret = load_db_record(out, "SELECT * FROM members_service_request WHERE id = %lu ", in["transport_id"].Long()); ret = load_db_record(out, "SELECT * FROM members_service_request WHERE id = %lu ", in["transport_id"].Long());
if (ret > 0) { if (ret > 0) {
ret = PHP_API_OK; ret = PHP_API_OK;
} }
return ret; return ret;
} }
@@ -542,7 +540,6 @@ long DeletAallCards(CVars in, CVars &out) {
return ret; return ret;
} }
long medTrMemberServiceById(CVars in, CVars &out) { long medTrMemberServiceById(CVars in, CVars &out) {
long ret = PHP_API_BAD_PARAM; long ret = PHP_API_BAD_PARAM;
@@ -561,7 +558,7 @@ long medTrMemberServiceById(CVars in, CVars &out) {
if (ret > 0) { if (ret > 0) {
// out["estimated_cost"] ="34.00"; // out["estimated_cost"] ="34.00";
getServiceDetail( out["service_id"].Long(), out); getServiceDetail(out["service_id"].Long(), out);
// snprintf(vname, sizeof (vname), "service_list_detail_%05d", i); // snprintf(vname, sizeof (vname), "service_list_detail_%05d", i);
// out[vname] = out["service_list"]; // out[vname] = out["service_list"];
@@ -577,13 +574,12 @@ long medTrMemberServiceById(CVars in, CVars &out) {
return ret; return ret;
} }
long medTrLanguageList(CVars in, CVars &out) { long medTrLanguageList(CVars in, CVars &out) {
long ret = PHP_API_BAD_PARAM; long ret = PHP_API_BAD_PARAM;
char vname[20]; char vname[20];
try { try {
// REQ_LONG(in, "status", 0, -1); // REQ_LONG(in, "status", 0, -1);
REQ_LONG( in, "member_id", 0, -1); REQ_LONG(in, "member_id", 0, -1);
out["total_record"] = "0"; out["total_record"] = "0";
@@ -621,6 +617,7 @@ long medTrLanguageList(CVars in, CVars &out) {
} }
return ret; return ret;
} }
/* /*
* street | city | zipcode * street | city | zipcode
kleen=> SELECT t.*,a.agent_name,TO_CHAR(t.service_date :: TIMESTAMP, 'Day Mon dd, yyyy HH:MM AM') AS long_date FROM members_service_request t LEFT JOIN agents a ON a.id=t.agent_id; kleen=> SELECT t.*,a.agent_name,TO_CHAR(t.service_date :: TIMESTAMP, 'Day Mon dd, yyyy HH:MM AM') AS long_date FROM members_service_request t LEFT JOIN agents a ON a.id=t.agent_id;
@@ -693,7 +690,7 @@ long medTrMemberTransportList(CVars in, CVars &out) {
snprintf(vname, sizeof (vname), "stype_desc_%05d", i); snprintf(vname, sizeof (vname), "stype_desc_%05d", i);
out[vname] = rec["service_type_description"]; out[vname] = rec["service_type_description"];
getServiceDetail( service_id, out); getServiceDetail(service_id, out);
snprintf(vname, sizeof (vname), "service_list_detail_%05d", i); snprintf(vname, sizeof (vname), "service_list_detail_%05d", i);
out[vname] = out["service_list"]; out[vname] = out["service_list"];
@@ -719,7 +716,7 @@ long getServiceDetail(long service_id, CVars &out) {
out["service_list"] = ""; out["service_list"] = "";
char vname[300]; char vname[300];
long ret = 0; long ret = 0;
int icc=0; int icc = 0;
ret = load_db_record(out, "SELECT * FROM members_service_request WHERE id = %lu ", service_id); ret = load_db_record(out, "SELECT * FROM members_service_request WHERE id = %lu ", service_id);
if (ret > 0) { if (ret > 0) {
@@ -727,7 +724,7 @@ long getServiceDetail(long service_id, CVars &out) {
case 1: case 1:
snprintf(vname, sizeof (vname), "%lu Bag(s)", out["quantity"].Long()); snprintf(vname, sizeof (vname), "%lu Bag(s)", out["quantity"].Long());
out["service_list"] = vname; out["service_list"] = vname;
out["total_detail_record"] ="1"; out["total_detail_record"] = "1";
break; break;
case 2: case 2:
@@ -763,18 +760,11 @@ long getServiceDetail(long service_id, CVars &out) {
return 0; return 0;
} }
vector<string> split_string(const char *str, char c = ' ') {
vector<string> split_string(const char *str, char c = ' ')
{
vector<string> result; vector<string> result;
do { do {
const char *begin = str; const char *begin = str;
while(*str != c && *str) while (*str != c && *str)
str++; str++;
result.push_back(string(begin, str)); result.push_back(string(begin, str));
} while (0 != *str++); } while (0 != *str++);
@@ -782,36 +772,42 @@ vector<string> split_string(const char *str, char c = ' ')
} }
// trim from start (in place) // trim from start (in place)
static inline void ltrim(std::string &s) { static inline void ltrim(std::string &s) {
s.erase(s.begin(), std::find_if(s.begin(), s.end(), s.erase(s.begin(), std::find_if(s.begin(), s.end(),
std::not1(std::ptr_fun<int, int>(std::isspace)))); std::not1(std::ptr_fun<int, int>(std::isspace))));
} }
// trim from end (in place) // trim from end (in place)
static inline void rtrim(std::string &s) { static inline void rtrim(std::string &s) {
s.erase(std::find_if(s.rbegin(), s.rend(), s.erase(std::find_if(s.rbegin(), s.rend(),
std::not1(std::ptr_fun<int, int>(std::isspace))).base(), s.end()); std::not1(std::ptr_fun<int, int>(std::isspace))).base(), s.end());
} }
// trim from both ends (in place) // trim from both ends (in place)
static inline void trim(std::string &s) { static inline void trim(std::string &s) {
ltrim(s); ltrim(s);
rtrim(s); rtrim(s);
} }
// trim from start (copying) // trim from start (copying)
static inline std::string ltrim_copy(std::string s) { static inline std::string ltrim_copy(std::string s) {
ltrim(s); ltrim(s);
return s; return s;
} }
// trim from end (copying) // trim from end (copying)
static inline std::string rtrim_copy(std::string s) { static inline std::string rtrim_copy(std::string s) {
rtrim(s); rtrim(s);
return s; return s;
} }
// trim from both ends (copying) // trim from both ends (copying)
static inline std::string trim_copy(std::string s) { static inline std::string trim_copy(std::string s) {
trim(s); trim(s);
return s; return s;
@@ -905,8 +901,7 @@ long kleenNewLundryPickUp(CVars in, CVars &out) {
out["service_id"] = insert_db_record(DBS_VALID, "members_service_request", "members_service_request_id_seq", x); out["service_id"] = insert_db_record(DBS_VALID, "members_service_request", "members_service_request_id_seq", x);
if (out["service_id"].Long() > 0) { if (out["service_id"].Long() > 0) {
if (in["instruction"].length() > 0) if (in["instruction"].length() > 0) {
{
// let us save instruction to another table // let us save instruction to another table
} }
@@ -926,7 +921,7 @@ long kleenNewLundryPickUp(CVars in, CVars &out) {
logfmt(FLOG_MAX, "key=%s, val=%s", key, val); logfmt(FLOG_MAX, "key=%s, val=%s", key, val);
CVars v; CVars v;
if ( load_db_record(v, "SELECT * FROM dryclean_service WHERE code='%s' ", key) > 0 ) { if (load_db_record(v, "SELECT * FROM dryclean_service WHERE code='%s' ", key) > 0) {
CVars m; CVars m;
m["member_id"] = in["member_id"]; m["member_id"] = in["member_id"];
m["member_id"].set_valid(true); m["member_id"].set_valid(true);
@@ -946,9 +941,9 @@ long kleenNewLundryPickUp(CVars in, CVars &out) {
service_total = m["total"].Long() + service_total; service_total = m["total"].Long() + service_total;
/* /*
id | code | description | price | added id | code | description | price | added
----+------+-------------------+-------+---------------------------- ----+------+-------------------+-------+----------------------------
1 | S01 | Shirt (Laundry) | 160 | 2018-07-19 09:43:21.379297 1 | S01 | Shirt (Laundry) | 160 | 2018-07-19 09:43:21.379297
2 | S02 | Shirt (Dry Clean) | 400 | 2018-07-19 09:43:21.383512 2 | S02 | Shirt (Dry Clean) | 400 | 2018-07-19 09:43:21.383512
3 | S03 | Shirt (Ladies) | 400 | 2018-07-19 09:43:21.386951 3 | S03 | Shirt (Ladies) | 400 | 2018-07-19 09:43:21.386951
@@ -968,16 +963,16 @@ long kleenNewLundryPickUp(CVars in, CVars &out) {
if (in["service_type"].Long() == 2) { if (in["service_type"].Long() == 2) {
if (discount_rate < 100) { if (discount_rate < 100) {
service_total = service_total * (100 - discount_rate)/100; service_total = service_total * (100 - discount_rate) / 100;
} }
t["est_cost"] = service_total; t["est_cost"] = service_total;
} else { } else {
t["est_cost"] = serviceCost(out["service_id"].Long(), discount_rate); t["est_cost"] = serviceCost(out["service_id"].Long(), discount_rate);
} }
pgsql_query("UPDATE members_service_request SET est_cost = %lu, discount_rate = %lu WHERE id = %lu", t["est_cost"].Long(),discount_rate, out["service_id"].Long()); pgsql_query("UPDATE members_service_request SET est_cost = %lu, discount_rate = %lu WHERE id = %lu", t["est_cost"].Long(), discount_rate, out["service_id"].Long());
serviceCost( out["service_id"].Long(),discount_rate ); serviceCost(out["service_id"].Long(), discount_rate);
load_db_record(out, "SELECT * FROM members_service_request WHERE id=%lu ", out["service_id"].Long()); load_db_record(out, "SELECT * FROM members_service_request WHERE id=%lu ", out["service_id"].Long());
// Now Send Email // Now Send Email
member_email_calls(in["action"].Long(), out, out); member_email_calls(in["action"].Long(), out, out);
@@ -1013,7 +1008,7 @@ long serviceCost(long service_id, long discount_rate) {
} }
if (discount_rate < 100) { if (discount_rate < 100) {
service_cost = service_cost * (100 - discount_rate)/100; service_cost = service_cost * (100 - discount_rate) / 100;
} }
return service_cost; return service_cost;
} }