Skip to content

Commit

Permalink
个人总结
Browse files Browse the repository at this point in the history
  • Loading branch information
equinox2333 committed Jan 3, 2021
1 parent 8980280 commit 249667d
Show file tree
Hide file tree
Showing 28 changed files with 612 additions and 126 deletions.
Binary file added document/个人总结_王世麟_2018010798.pdf
Binary file not shown.
Binary file added document/需求分析.docx
Binary file not shown.
2 changes: 1 addition & 1 deletion ts-backend/ts-config.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public static function init()
'host' => 'localhost', // including port
'user' => 'root',
'pwd' => '',
'charset' => 'utf8mb4',
'charset' => 'utf8',
'db_name' => 'test',
),
'user' => array(
Expand Down
4 changes: 3 additions & 1 deletion ts-backend/ts-libs/ts/db.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,9 @@ public function exec($sql) {
return $this->__conn->query($sql);
}
public function fetch1($sql) {
return $this->__conn->query($sql)->fetch_assoc();
$res = $this->__conn->query($sql);
if (!$res) return NULL;
else return $res->fetch_assoc();
}
public function escape($str) {
return $this->__conn->real_escape_string($str);
Expand Down
1 change: 1 addition & 0 deletions ts-backend/ts-mods.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
*/

ts_load('user/user');
ts_load('order/order');
ts_load('yyj/merchant_handler');

/* End of /ts-mods.php */
157 changes: 83 additions & 74 deletions ts-backend/ts-mods/order/order.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<?php
<?php if (!defined('TS_DEV')) { header('HTTP/1.1 403 Forbidden'); die(); }

/**
* Order Module
Expand All @@ -11,39 +11,37 @@ class OrderHandler {
/**
* get new order
*/
public static function new_order($args){
public static function new_order($args) {
global $ts_db;
$u_id = $args['u-id'];
$u_token = $args['u-token'];
$s_id = $args['s-id'];
$o_p_ids = $args['o-p-ids'];
$o_p_n = $args['o-p-n'];

$sql = "SELECT * FROM users WHERE u_id=$u_id";
$result = $ts_db->query($sql);
$row = $result->fetch_assoc();
if($row['u_authent']==0)
{
echo json_encode("Unauthenticated");
}
else
{
$o_id = (string)$u_id."".(string)time();
//查询订单原价
$length=count($o_p_ids);
$o_raw_price = 0;
for($x=0;$x<$length;$x++)
$o_id = (string)$u_id."".(string)time();
//查询订单原价
$length=count($o_p_ids);
$o_raw_price = 0;
echo json_encode(array('msg' => 'ok'));
return;
for($x=0;$x<$length;$x++)
{
$sql = "SELECT p_price FROM ts_products WHERE p_id=\'" . $ts_db->escape($o_p_ids[$x]) . "\' AND p_s_id=\'" . $ts_db->escape($s_id) . "\'";
$result = $ts_db->exec($sql);
while($result)
{
$sql = "SELECT p_price FROM commodities WHERE p_id=$o_p_ids[$x] AND p_s_id=$s_id";
$result = $ts_db->query($sql);
while($row = $result->fetch_assoc())
{
$o_raw_price += $row['p_price'] * $o_p_n[$x];
}
$row = $result->fetch_assoc();
if (!$row) break;
$o_raw_price += $row['p_price'] * $o_p_n[$x];
}
//查询店家名称
$sql = "SELECT * FROM stores WHERE s_id=$s_id";
$result = $ts_db->query($sql);
$row = $result->fetch_assoc();
}
//查询店家名称
$sql = "SELECT * FROM ts_stores WHERE s_id=\'" . $ts_db->escape($s_id) . "\'";
$row = $ts_db->fetch1($sql);
if (!$row) {
echo json_encode(array('msg' => 'no such store'));
} else {
$s_name = $row['s_name'];
$discount = unserialize($row['discount']);
$o_p_ids = json_encode($o_p_ids);
Expand All @@ -64,11 +62,11 @@ public static function new_order($args){
$o_price = $o_raw_price - $discount[$index];
}
$sql = "INSERT INTO
orders (o_id,o_u_id,o_s_id,o_s_name,o_p_ids,o_p_n,o_price,o_raw_price,o_confirm,o_paid)
VALUES ($o_id,$u_id,$s_id,$s_name,'$o_p_ids','$o_p_n',$o_price,$o_raw_price,0,0)";
$ts_db->query($sql);
echo json_encode($o_id);
}
ts_orders (o_id,o_u_id,o_s_id,o_s_name,o_p_ids,o_p_n,o_price,o_raw_price,o_confirm,o_paid)
VALUES (\'" . $ts_db->escape($o_id) . "\',\'" . $ts_db->escape($u_id) . "\',\'" . $ts_db->escape($s_id) . "\',\'" . $ts_db->escape($s_name) . "\',\'" . $ts_db->escape($o_p_ids) . "\',\'" . $ts_db->escape($o_p_n) . "\',\'" . $ts_db->escape($o_price) . "\',\'" . $ts_db->escape($o_raw_price) . "\',0,0)";
$ts_db->exec($sql);
echo json_encode(array('msg' => $o_id ? 'ok' : 'failed'));
}
}

/**
Expand All @@ -82,7 +80,7 @@ public static function get_cb($args){

$S = GetRandStr(40);
//查询该订单是否已创建拼单
$sql = "SELECT * FROM orders WHERE o_id=$o_id";
$sql = "SELECT * FROM ts_orders WHERE o_id=$o_id";
$result = $ts_db->query($sql);
$row = $result->fetch_assoc();
$s_id = $row['o_s_id'];
Expand All @@ -93,7 +91,7 @@ public static function get_cb($args){
{
$o_price = $row['o_price'];
$cb_id = $row['o_cb_id'];
$sql = "SELECT * FROM cbs WHERE cb_id=$cb_id";
$sql = "SELECT * FROM ts_cbs WHERE cb_id=$cb_id";
$result = $ts_db->query($sql);
$row = $result->fetch_assoc();
$cb_start_time = $row['cb_start_time'];
Expand Down Expand Up @@ -125,7 +123,7 @@ public static function get_cb($args){
{
if(time()-$cb_start_time>600)
{
$sql = "UPDATE cbs SET cb_status=2 WHERE cb_id=$cb_id";
$sql = "UPDATE ts_cbs SET cb_status=2 WHERE cb_id=$cb_id";
$ts_db->query($sql);
echo $S."\n";
echo json_encode('Timeout')."\n";
Expand All @@ -142,7 +140,7 @@ public static function get_cb($args){
else //未创建拼单
{
//查询用户点云位置
$sql = "SELECT * FROM users WHERE u_id=$u_id";
$sql = "SELECT * FROM ts_users WHERE u_id=$u_id";
$result = $ts_db->query($sql);
$row = $result->fetch_assoc();
$u_coord_x = $row['u_coord_x'];
Expand Down Expand Up @@ -251,10 +249,17 @@ public static function confirm_o_pay($args){
$u_token = $args['u-token'];
$o_id = $args['o-id'];

$sql = "SELECT * FROM orders WHERE o_id=$o_id";
$result = $ts_db->query($sql);
$row = $result->fetch_assoc();
echo json_encode($row['o_paid']);
global $ts_db;
$sql = "SELECT * FROM ts_orders WHERE o_id=\'" . $ts_db->escape($o_id) . "\' LIMIT 1";
$row = $ts_db->fetch1($sql);
$arr = array('msg' => '', 'paid' => false);
if (!$row) {
$arr['msg'] = 'no such order';
} else {
$arr['msg'] = 'found';
$arr['paid'] = (bool) $row['o_paid'];
}
echo json_encode($arr);
}

/**
Expand All @@ -265,17 +270,16 @@ public static function get_cb_deliv($args){
$u_token = $args['u-token'];
$cb_id = $args['cb-id'];

$sql = "SELECT * FROM cbs WHERE cb_id=$cb_id";
$result = $ts_db->query($sql);
$row = $result->fetch_assoc();
$sql = "SELECT * FROM ts_cbs WHERE cb_id=\'" . $ts_db->escape($cb_id) . "\' LIMIT 1";
$row = $ts_db->fetch1($sql);
$cb_done_time = $row['cb_done_time'];
$cb_done = $row['cb_done'];
$cb_g_id = $row['cb_g_id'];

$result = array(
'cb_done_time' => $cb_done_time,
'cb_done' => $cb_done,
'cb_g_id' => $cb_g_id
'cb_done_time' => $cb_done_time,
'cb_done' => $cb_done,
'cb_g_id' => $cb_g_id
);

echo json_encode($result);
Expand All @@ -287,12 +291,12 @@ public static function get_cb_deliv($args){
public static function get_cb_history($args){
$u_id = $args['u-id'];
$u_token = $args['u-token'];
$from = $args['from'];
$to = $args['to'];
$from = (int) $args['from'];
$to = (int) $args['to'];

$S = GetRandStr(40);
$to = $to - $from + 1;
$sql = "SELECT * FROM orders WHERE o_u_id=$u_id LIMIT $from,$to";
$sql = "SELECT * FROM orders WHERE o_u_id=\'" . $ts_db->escape($u_id) . "\' LIMIT $from,$to";
$result = $ts_db->query($sql);
$cb_history = array();
while($row = $result->fetch_assoc())
Expand All @@ -306,19 +310,19 @@ public static function get_cb_history($args){
$cb = array();
$commodity_list = array();
$length = count($o_p_ids);
$pics=array();
$pic_num=0;
//$pics=array();
//$pic_num=0;
for($x=0;$x<$length;$x++)
{
$p_id = $o_p_ids[$x];
$sql = "SELECT * FROM commodities WHERE p_s_id=$s_id and p_id=$p_id";
$sql = "SELECT * FROM commodities WHERE p_s_id=\'" . $ts_db->escape($s_id) . "\' and p_id=\'" . $ts_db->escape($p_id) . "\'";
$result2 = $ts_db->query($sql);
$row2 = $result2->fetch_assoc();
$p_name = $row2['p_name'];
$p_price = $row2['p_price'];
$p_pic = $row2['p_pic'];
array_push($pics,$p_pic);
$pic_num += 1;
//$p_pic = $row2['p_pic'];
//array_push($pics,$p_pic);
//$pic_num += 1;
$p_n = $o_p_n[$x];
$commodity = array();
$commodity['p_id'] = $p_id;
Expand All @@ -334,14 +338,14 @@ public static function get_cb_history($args){
$cb['ps'] = $commodity_list;
array_push($cb_history, $cb);
}
$cb_history['pic_num'] = $pic_num;
echo $S."\n";
echo json_encode($cb_history)."\n";
for($x=0;$x<$pic_num;$x++){
echo $S."\n";
echo $pics[$x]."\n";
}
echo $S."\n";
//$cb_history['pic_num'] = $pic_num;
//echo $S."\n";
echo json_encode($cb_history);//echo "\n";
//for($x=0;$x<$pic_num;$x++){
// echo $S."\n";
// echo $pics[$x]."\n";
//}
//echo $S."\n";
}
};

Expand All @@ -358,49 +362,54 @@ function GetRandStr($length){
return $randstr;
}

TsRoute::hook('order/new_order',
TsRoute::hook('new-o',
array(
'u-id' => TS_ROUTE_KEY_POST,
'u-token' => TS_ROUTE_KEY_POST,
's-id' => TS_ROUTE_KEY_POST,
'o-p-ids' => TS_ROUTE_KEY_POST,
'o-p-n' => TS_ROUTE_KEY_POST,
),
array('UserHandler','check_token'),
array('OrderHandler', 'new_order'),
);
TsRoute::hook('order/get_cb',
TsRoute::hook('get-cb',
array(
'u-id' => TS_ROUTE_KEY_POST,
'u-token' => TS_ROUTE_KEY_POST,
'o-id' => TS_ROUTE_KEY_POST,
),
array('UserHandler','check_token'),
array('OrderHandler', 'get_cb'),
);
TsRoute::hook('order/confirm_o_pay',
array(
'u-id' => TS_ROUTE_KEY_POST,
'u-token' => TS_ROUTE_KEY_POST,
'o-id' => TS_ROUTE_KEY_POST,
),
array('OrderHandler', 'confirm_o_pay'),
TsRoute::hook('confirm-o-pay',
array(
'u-id' => TS_ROUTE_KEY_POST,
'u-token' => TS_ROUTE_KEY_POST,
'o-id' => TS_ROUTE_KEY_POST,
),
array('UserHandler','check_token'),
array('OrderHandler', 'confirm_o_pay'),
);
TsRoute::hook('order/get_cb_deliv',
TsRoute::hook('get-cb-deliv',
array(
'u-id' => TS_ROUTE_KEY_POST,
'u-token' => TS_ROUTE_KEY_POST,
'cb-id' => TS_ROUTE_KEY_POST,
),
array('UserHandler','check_token'),
array('OrderHandler', 'get_cb_deliv'),
);
TsRoute::hook('order/get_cb_history',
TsRoute::hook('get-cb-history',
array(
'u-id' => TS_ROUTE_KEY_POST,
'u-token' => TS_ROUTE_KEY_POST,
'from' => TS_ROUTE_KEY_POST,
'to' => TS_ROUTE_KEY_POST,
),
array('UserHandler','check_token'),
array('OrderHandler', 'get_cb_history'),
);


/** End of /ts-mods/order/order.php */
/** End of /ts-mods/order/order.php */
53 changes: 53 additions & 0 deletions ts-backend/ts-mods/order/setup.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
<?php if (!defined('TS_DEV')) { header('HTTP/1.1 403 Forbidden'); die(); }

$TABLE_ORDERS = 'ts_orders';
$TABLE_CBS = 'ts_cbs';

if (TS_DEV) {
$ts_db->exec('DROP TABLE IF EXISTS ' . $TABLE_ORDERS);
}
if (!$ts_db->exec('CREATE TABLE ' . $TABLE_ORDERS . 'CREATE TABLE orders (
o_id INT AUTO_INCREMENT,
o_u_id VARCHAR(31),
o_s_id VARCHAR(30),
o_s_name VARCHAR(30),
o_p_ids VARCHAR(1023),
o_p_n VARCHAR(80),
o_cb_id VARCHAR(30),
o_cb_n INT(6),
o_price FLOAT(24),
o_raw_price FLOAT(24),
o_confirm bit(1),
o_paid bit(1),
) ENGINE=InnoDB DEFAULT CHARSET=' . TsConfig::get('db', 'charset'))) {
echo 'could not create table ' . $TABLE_ORDERS;
exit(-1);
}
if (!$ts_db->exec('CREATE TABLE ' . $TABLE_CBS . ' (
cb_id VARCHAR(30),
cb_s_id VARCHAR(30),
cb_s_name VARCHAR(30),
cb_o_ids VARCHAR(80),
cb_n INT(6),
cb_status INT(2),
cb_from INT(6),
cb_to INT(6),
cb_pay VARBINARY(200),
cb_done_time INT(30),
cb_done bit(1),
cb_g_id INT(6),
cb_start_time INT(20),
cb_raw_price INT(20),
cb_price INT(20)
)')) {
echo 'could not create table ' . $TABLE_CBS;
exit(-1);
}
if (TS_DEV) {
/*if (!$ts_db->exec('INSERT INTO ' . $TABLE_ORDERS . ' (o_id, o_u_id, o_s_id, o_s_name, o_p_ids, o_p_n, o_cb_id, o_cb_n, o_price, o_raw_price, o_confirm, o_paid) VALUES
()
')) {
echo 'could not insert into ' . $TABLE_ORDERS;
exit(-1);
}*/
}
6 changes: 6 additions & 0 deletions ts-backend/ts-mods/user/setup.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,9 @@
echo 'could not create table ' . $TABLE_USERS;
exit(-1);
}
if (TS_DEV) {
if (!$ts_db->exec('INSERT INTO ' . $TABLE_USERS . ' (uid, hashed_pwd, token) VALUES (\'admin\', \'$2y$10$T1SqgEKTpmL5/ksngWkVCuzZYTK.XKG6zFgyZB.rNB9de1.mNe0ju\', \'test_token\')')) { // pwd = 1234
echo 'could not insert into ' . $TABLE_USERS;
exit(-1);
}
}
Loading

0 comments on commit 249667d

Please sign in to comment.