Skip to content

Commit dfde47b

Browse files
committed
客户购买
1 parent 5e4679e commit dfde47b

File tree

4 files changed

+43
-25
lines changed

4 files changed

+43
-25
lines changed

application/controllers/Orders.php

Lines changed: 34 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -17,28 +17,45 @@ public function index()
1717
public function CreateOrder() {
1818
$response = array('status'=>'0','msg'=>'failed','data'=>'');
1919
$this->load->model('Orders_model');
20-
20+
$this->load->model('Product_model');
2121
if(isset($_COOKIE['auth'])){
2222
$decodeToken = $this->objOfJwt->DecodeToken($_COOKIE['auth']);
2323
$user = $decodeToken;
2424
$userid = $user['userid'];
25+
}
26+
else {
27+
$userid = 'guest-internal';
28+
}
29+
30+
$post = $this->input->post(NULL, TRUE);
31+
// Consult the database in order to get the instant price of the product
32+
// and insert to order.
33+
34+
$pids = explode('-', $post['pid']);
35+
$prices = [];
36+
foreach ($pids as $prod_id) {
37+
$product = $this->Product_model->get_product_detail($prod_id);
38+
//echo $prod_id;
39+
//echo var_dump($product);
40+
$product_price = $product[0]->price;
41+
array_push($prices, $product_price);
42+
}
43+
$order_price = join('-', $prices);
44+
//echo "======price_get: " . $order_price;
45+
$data = array(
46+
'pid' => $post['pid'],
47+
'qty' => $post['qty'],
48+
'price' => $order_price,
49+
'userid' => $userid,
50+
'hash' => md5($post['pid'] . ':' . $post['qty'] . ':' . time()),//
51+
'status' => 0
52+
);
53+
$res = $this->Orders_model->create_orders($data);
54+
//echo "----------1------------";
55+
56+
$response = array('status'=>'2','msg'=>'success','data'=>$res[0]);
2557

26-
$post = $this->input->post(NULL, TRUE);
27-
$data = array(
28-
'pid' => $post['pid'],
29-
'qty' => $post['qty'],
30-
'userid' => $userid,
31-
'hash' => md5($post['pid'] . ':' . $post['qty'] . ':' . time()),//
32-
'status' => 0
33-
);
34-
$res = $this->Orders_model->create_orders($data);
58+
echo json_encode($response);
3559

36-
$response = array('status'=>'2','msg'=>'success','data'=>$res[0]);
37-
echo json_encode($response);
38-
}else {
39-
$response = array('status'=>'0','msg'=>'failed','data'=>'登录过期了,请重新登录');
40-
echo json_encode($response);
41-
}
4260
}
4361
}
44-

application/database/data.db

5 KB
Binary file not shown.

application/database/data.sq3

0 Bytes
Binary file not shown.

application/views/header.php

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -41,17 +41,17 @@
4141
<div class="shopping-car"></div>
4242
<!-- end -->
4343
<?php
44-
if($data){
44+
// if($data){
4545
echo
4646
'
4747
<button class="btn-info checkout col-sm-6">Checkout</button>
4848
';
49-
} else {
50-
echo
51-
'
52-
<button class="btn-info signIn-checkout col-sm-6">Checkout</button>
53-
';
54-
}
49+
// } else {
50+
// echo
51+
// '
52+
// <button class="btn-info signIn-checkout col-sm-6">Checkout</button>
53+
// ';
54+
// }
5555
?>
5656
<p class="col-sm-2">total:$<span class="total-product">0</span></p>
5757
</div>
@@ -180,6 +180,7 @@ function findProd(prod) {
180180
$('.pay-loading').show();
181181
// console.log(123123)
182182
},
183+
183184
success: function(data) {
184185
if(data.status == 2){
185186
$('.paypal-form').html(
@@ -205,7 +206,7 @@ function findProd(prod) {
205206

206207
},
207208
error: function() {
208-
alert("ajax error");
209+
alert("ajax error!!!!!!!!!!!!!!");
209210
}
210211
});
211212
})

0 commit comments

Comments
 (0)