#Coupon
##System Requirements
- PHP 5.3 or later
- MySql
- Internet (for google chart)
##Software Architecture Used
- Dependency injection (DI)
- Inversion of control (IOC)
- Database Layer (Repositories)
- Single responsibility (One class one responsibility)
- Design Pattern
##Folder Structure |- app | |- config | | |- database.php | |- controllers | |- database | | |- migrations | |- domains | | |- Base | | |- Shop | | | |- Coupon | | | | |- Stat | |- lang | | |- en | | | | validation.php | |- views | | | graph.php | | routes.php |- public | |- js | | | graph.js | db.sql
app/config/database.php
- database config e.g, username, password, database nameapp/controller/
- after route is matched then the function in controller will be calledapp/database/migrations/
- Create/Drop database schemas codeapp/domains/
- All business logics are here (modular structure) includeing entities, repositories and valdation rulesapp/lang/en/validation.php
- Validation messagesapp/views/graph.php
- html for graph pagepublic/js/graph.js
- create google chart
##Installation
- use
git clone git@github.com:witooh/coupon.git
or download here - import database schema with
db.sql
- change database config in
app/config/database.php
'mysql' => array(
'driver' => 'mysql',
'host' => '127.0.0.1',
'database' => 'coupon',
'username' => 'root',
'password' => '',
'charset' => 'utf8',
'collation' => 'utf8_unicode_ci',
'prefix' => '',
),
- open command line and run command
php artisan migrate:install
for create migration database table
$ php artisan migrate:install
- and then
php artisan migrate
for create shop, coupon and use_coupon database table. Migration database schemas are created inapp/database/migrations/
$ php artisan migrate
- you can remove all data in database by run this command
php artisan migrate:refresh
$ php artisan migrate:refresh
##Using Services
###Create Shop
- method
GET
- url
<domain>/shop/create
- parameters:
shop_name
string
name of shopowner_username
string
username of shop ownerowner_password
string
password of shop owner
- example
http://<domain>/shop/create?shop_name=test&owner_username=user&owner_password=pass
- Output
{
"shop_name": "test",
"owner_username": "user",
"owner_password": "ff41f462a484668de7784448623d3d0c",
"id": 1
}
###Create Coupon
- method
GET
- url
<domain>/coupon/create
- parameters:
shop_id
number
ID of shopcoupon_name
string
name of couponactive_date
string
coupon will be actived in formatYYYY-MM-DD
expire_date
string
coupon will be expired in formatYYYY-MM-DD
- example
http://<domain>/coupon/create?shop_id=1&coupon_name=Buy1Get1&active_date=2013-09-01&expire_date=2013-09-31
- Output
{
"shop_id": "1",
"coupon_name": "Buy1Get1",
"active_date": "2013-09-01",
"expire_date": "2013-09-30",
"id": 1,
"action": {
"coupon_id": 31,
"action": "active",
"action_time": "2013-09-08T18:46:52+07:00",
"id": 57
}
}
###Use Coupon
- method
GET
- url
<domain>/coupon/use
- parameters:
coupin_id
number
ID of couponaction
string
use coupon forcollected
orredeemed
- example collected
http://<domain>/coupon/use?coupon_id=1&action=collected
- Output
{
"coupon_id": "1",
"action": "collected",
"action_time": "2013-09-08T18:54:37+07:00",
"id": 1
}
- example collected
http://<domain>/coupon/use?coupon_id=1&action=redeemed
- Output
{
"coupon_id": "1",
"action": "redeemed",
"action_time": "2013-09-08T18:55:31+07:00",
"id": 2
}
##Statistic Page
You can go to the statistic page by http://<domain>/graph