Auction Expiration process using Php(CodeIgniter) Mysql Jquery - php

I'm developing an auction website. It is like: Auction is consists of X number of cars (let's say 10 cars in an auction). I have tables for auction, bid and product. My cronjob checks if any auction is ready to go live. If there is any then it flag the auction as active and update the bid time in product table.
Every product stays for 1 minute if in that time someone bid on the product time resets. if Minute is over it bring the next car for auction.
I'm wondering, if no user opens the window how i'm gonna expire the auction. All the request go from client. I'm using sockets for biding process.
Thank you

Related

Work log and generate a PDF everys X days

I have created my first php system, it basically is a list of customers which the user can select and log work for which generates a PDF work record.
I want to extend it to generate an invoice every Thursday midnight and send it to the business, eg:
User 1 has worked:
Customer a - 1 hour
Customer c - 2 hours
Customer D - 4 hours
Total 7 hours at (Chargeable rate).
Now in my head it seems pretty straight forward but I want to sense check it with people it possible:
When the PDF is generated I need to store the information in a new table, User ID, Customer name, Hours worked, Time & date. Then each Thursday I need a script to run which will transfer the entries from the database (over the past X days - could I say from ID X which was the last ID to be ran in the previous pdf?) to a PDF, save the pdf to the server and email it to me.
A few questions:
Would It be beneficial to clear this data after X day so the DB doesn't get too big?
What is the best way to ensure that an entry doesn't get missed? I will most likely run the script every thursday at midnight, but I'm guessing theres room for error there if somebody submits an entry at the same time? (slim chance but possible)
I'll be using mPDF for the invoice generation which I already use.

MySQL - automatically update row after x seconds of inactivity (set expiration time)

For an art project I am trying to set up an order site.
The concept allows users to book a max. of two time slots with each artist. There are 12 slots per artist, but each slot with a specific definition (so each is unique). The slots are only available for a very limited time and hopefully booked fast. So there will be a lot of requests in a short period of time. I have to make sure each article/slot is only offered to a single user at a time and cannot be double booked.
My idea was, to check for the next unbooked slot(s) (status="free) and on that request update the status of the corresponding row in the table to status="locked". If the user proceeds to actually book the slot, the status is updated to "booked".
If a user clicks "cancel" I can release the article by updating the row to status="free".
However, it is not unlikely that users just abandon the site and I don't see a way to check for that. The slot would remain "locked". I was thinking, there might be a way to automatically reset the status e.g. 120 seconds after is was "locked" and show a countdown to the users. This could even enhance the excitement factor.
I don't think a cron job would work as I need the anchor to be the last update of the row and not a specific datetime.
I looked into MySQL events but understood that I cannot manipulate the data of the table it is attached to.
I would greatly appreciate any ideas.
Thanks,
Sam
In your db your status table add a datetime field.
When someone lock a slot you also save the current time using NOW()
When someone consult the slots you perform and update and free the inactive slots
Update slots
SET locked = false
WHERE `datetime`> NOW() - INTERVAL 15 MINUTE;
SELECT *
FROM slots
WHERE locked = false;

Programming logic - update the database only one time after specific time interval

I am developing ecommerce store in php and I have some problem in creating a logic. The problem is I have a store page where I am showing some products. all the products have some time interval,after interval passes the products will no longer be display there.
For example
Product: jeans
time left: 10 days.
after 10 days jeans product will no longer be there. in database I have a set a field with the name active_status which accepts Y or N..
I know that I can simply run the update query and set the status to "N" after time passes. here in this example after 10 days
BUT the question is WHEN DO I RUN THIS UPDATE QUERY ?
should I always check time and run again and again update query and set STATUS TO 'N'??? IS that is the only solution ?
I mean usually we do like for example if customer logins we set some status or any other event but here we are setting the status against checking the time. Hopefully you have understand my question
In the db I am saving the start time and number of days which user puts through the admin panel
My first shot would be cron, php script and properties table (if needed, because for simple uses you could just store expiration date inside business entity).
Cron runs php script periodically (e.g. once a day),
scripts checks if there is anything to delete, based on properties table, or entity properties.
If there is anything to delete, script performs deletion of selected content.
That's all and it is in fact very popular scenario.
More on cron: http://www.pantz.org/software/cron/croninfo.html
Here is my logic i hope it will helps i think
While Publishing the product we have to maintain the time interval of that product for example if you want to display the product for 10 days give 10 days and date of publish product.
By comparing with that date and number of days given for time interval with the present date i.e today's date
Can you check with this

how to restrict user for 10minutes for payment on paypal

I am working on booking website. When any user come to site, select any date & time for booking and go to paypal for payment. Before going to paypal, I am adding this entry to booking, so any other user can not go for booking on that specific time for that date.
Now if user does not make payment on paypal and stay idle. In this case that time gets blocked.
I want user should have 10 minutes to make a payment on paypal. If time exceeds user should redirect to my website with any flag, so I can remove that booking and that time - date will be available for booking to users.
I can use cron job which can remove bookings which are in pending status in database for more than 10 mins.
Major problem I am facing is
1) When I go to paypal for payment and stay idle, paypal automatically redirect after 5 min (giving error of session time out)
2) But when I go to paypal and log in with sandbox account and then stay idle, if after 5 min, I try to do any activity, it gives error of time out, and redirect to login screen of paypal. So it allow me to login again and proceed for payment.
By this way user can even pay after 1 hour. If I delete booking entry using cron, it will create conflict because payment is completed and there is no entry in database.
I want way to explicitly redirect user from paypal to my site after 10 mins.
<?php
// Create and start timer firing after 10 minute
$w1 = new EvTimer(600, 0, function () {
echo "10 minute elapsed\n";
//Your Condition
});
?>
use Timer and Write your condition in the Timer and check the user payment status
What you could do is store the booking in a table in your database, then have a cron job that runs every minute or so and deletes any entries older than 10 minutes:
mysql myDatabase < 'DELETE FROM bookings WHERE (now() - time_the_booking_was_made) > (120*60)'
Bookings in the database should not be displayed to other users as those bookings would be in the 10 minute reserved state. If you need the booking to become instantaneously available to other users after the 10 minute time period, you could save it to the table and run a timer like in the answer above that would remove the booking after the specified time.
Hope this may give you some idea :
1> After selecting date&time, you are adding entry to booking. Now before adding entry check whether the same 'date&time' is already present in database (because many may be booking simultaneously). If present 'display' message to users that it is already booked (redirect to booking page). If it is not present then add entry to database.
2> Create column 'status' in database entry table, While adding 'booking entry' to database , set 'status' as 'pending or 0'. At this time other users cant able to book this entry(same date&time).
3> After successful payment set 'status' as 'confirmed or 1'. If unsuccessful set 'status' as 'denied' or '-1'
4> I guess paypal has default time limit.
5> So, when the status is 'pending' and 'confirmed'. Others cant book on that.
6> If the status is 'denied' or 'empty' then others can book on that.

Countdown Timer interact with php mysql

I want to construct a countdown timer so the customer gets discount on price if he buys the product before countdown ends.
I've search internet and found a lot about countdown timer using Jquery, Javascript...
But how can i say in PHP that if the countdown is running then the product has 50% discount
Else if countdown ends(00:00:00) delete discount, return product's price to normal.
The price is stored in the database.
No need for timer. Jut store discount date time in database with product.
and if purchase time is within that time apply 50% discount else no discount. You can do this by any means either apply if/ else condition using PHP or handle if/else and datetime comperisions in mysql query.
You just need to store in database the end time of countdown with something like this
INSERT INTO user_offers SET countdown_end = DATE_ADD(NOW(),INTERVAL 5 MINUTE), user = ...
This will insert row with current time + 5 minutes. Assuming that you have logged in user, you will insert item id and user id, otherwise you need to develop your own way to recognize user (cookie for example), so that refreshing page would not refresh countdown.
Then you will need some jQuery (I like jQuery, but you can use whatever you want) magic for countdown, like this plugin http://keith-wood.name/countdown.html
When user clicks on ORDER NOW button (or smthing like that) you just check user_offers table like this
SELECT countdown_end FROM user_offers WHERE countdown_end > NOW() AND user = ...
If it returns something than you know, that he clicked in limit :)

Categories