-
Notifications
You must be signed in to change notification settings - Fork 1
/
market.php
158 lines (147 loc) · 5.32 KB
/
market.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
<?php
function check_friend($uid, $fuid) {
global $db;
$row = $db->fetch_first("SELECT COUNT(*) as totalnum FROM game_friends WHERE uid = '{$uid}' AND fuid = '{$fuid}'");
return intval($row['totalnum']) > 0;
}
require_once './include/api.php';
require_once './include/warehouse.php';
$module = gp('module');
$action = gp('action');
$ajax = gp('ajax', 0);
switch($action){
case 'product':
json_result(['products' => get_warehouses($uid)]);
break;
case 'sell':
$products = [];
$query = $db->query("SELECT m.*, p.productname FROM game_markets m LEFT JOIN game_products p ON p.pid = m.pid WHERE m.uid = '{$uid}'");
while($row = $db->fetch_array($query)){
$products[] = $row;
}
json_result(['products' => $products]);
break;
}
switch($module){
case 'sell':
// $products = get_warehouses($uid);
// $smarty->assign('product_list', $products);
$smarty->display('market_sell.html');
break;
case 'move':
$query = $db->query("SELECT m.*, p.productname FROM game_markets m
LEFT JOIN game_products p ON m.pid = p.pid
WHERE m.uid = '$uid'");
$prudcts = array();
while($row = $db->fetch_array($query)) {
$products[] = $row;
}
$smarty->assign('products', $products);
$smarty->display('market_move.html');
break;
case 'detail':
$productid = isset($_GET['productid']) ? intval($_GET['productid']) : 0;
if($productid){
$product = $db->fetch_first("SELECT * FROM hap_product WHERE id = '{$productid}'");
$material = null;
if(!empty($product['material'])){
$arr = json_decode($product['material'], true);
$result = $db->query("SELECT * FROM hap_product WHERE id IN (".implode(',', array_keys($arr)).")");
while($row = mysql_fetch_assoc($result)){
$row['quantity'] = $arr[$row['id']];
$material[] = $row;
}
}
$product['material'] = $material;
echo json_encode(array('product' => $product));
}
break;
case 'buylog':
$marketlog = $db->query("SELECT m.*,p.productname,u.username FROM game_marketlog m ".
"LEFT JOIN game_products p ON m.pid=p.pid ".
"LEFT JOIN game_users u ON m.suid=u.uid ".
"WHERE m.buid=$uid ORDER BY dateline DESC");
while($row = $db->fetch_array($marketlog))
{
$log_list[] = array(
'productname' => $row['productname'],
'price' => $row['price'],
'count' => $row['count'],
'seller' => $row['username'],
'date' => $row['dateline']
);
}
$smarty->assign('log_list', $log_list);
$smarty->display('market_buy_log.html');
break;
case 'selllog':
$marketlog = $db->query("SELECT m.*,p.productname,u.username FROM game_marketlog m ".
"LEFT JOIN game_products p ON m.pid=p.pid ".
"LEFT JOIN game_users u ON m.suid=u.uid ".
"WHERE m.suid=$uid ORDER BY m.dateline DESC");
while($row = $db->fetch_array($marketlog))
{
$log_list[] = array(
'productname' => $row['productname'],
'price' => $row['price'],
'count' => $row['count'],
'buyer' => $row['username'],
'date' => $row['dateline']
);
}
if($ajax){
foreach($log_list as $key => &$val){
$val['date'] = date('Y-m-d H:i', $val['date']);
}
die(json_encode(array('list'=>$log_list)));
}
$smarty->assign('log_list', $log_list);
$smarty->display('market_sell_log.html');
break;
default:
$cate_id = intval(gp('cateid', 0));
$ajax = intval(gp('ajax', 0));
if($ajax){
$sqladd = '';
if($cate_id>0){
$sqladd .= " AND p.cateid = '{$cate_id}'";
}
$query = $db->query("SELECT m.*, p.productname FROM game_markets m LEFT JOIN game_products p ON p.pid = m.pid WHERE m.uid != '{$uid}'{$sqladd}");
$products = [];
while($row = $db->fetch_array($query)){
$row['is_friend'] = check_friend($uid, $row['uid']) ? 1 : 0;
$products[] = $row;
}
json_result(['products' => $products]);
}
// $categoryId = $_REQUEST['cateid'];
// $categoryId = isset($_GET['cateid']) ? intval($_GET['cateid']) : 0;
// $sqladd = empty($categoryId) ? "" : "AND cateid = $categoryId";
// $result = $db->query("SELECT id,category FROM game_productcategory");
// while($category = $db->fetch_array($result)) {
// $categoryList[] = array('id'=>$category['id'], 'category'=>$category['category']);
// }
// $smarty->assign('categoryList', $categoryList);
// $data = $db->query("SELECT m.*,p.productname FROM game_markets m ".
// "LEFT JOIN game_products p ON m.pid = p.pid ".
// "WHERE m.uid <> $uid $sqladd");
// while($market = $db->fetch_array($data)) {
// $friend = $db->fetch_first("SELECT uid,fuid FROM game_friends WHERE uid = $uid AND fuid = ". $market['uid']);
// $friendstatus = ($friend == FALSE) ? 0 : 1;
// $market_list[] = array(
// 'marketid' => $market['id'],
// 'pid' => $market['pid'],
// 'productname' => $market['productname'],
// 'uid' => $market['uid'],
// 'seller' => $market['username'],
// 'count' => $market['count'],
// 'price' => $market['price'],
// 'friendstatus' => $friendstatus,
// );
// }
// if($ajax){
// die(json_encode(array('list'=>$market_list)));
// }
// $smarty->assign('market_list', $market_list);
$smarty->display('market.html');
}