@@ -17,28 +17,45 @@ public function index()
17
17
public function CreateOrder () {
18
18
$ response = array ('status ' =>'0 ' ,'msg ' =>'failed ' ,'data ' =>'' );
19
19
$ this ->load ->model ('Orders_model ' );
20
-
20
+ $ this -> load -> model ( ' Product_model ' );
21
21
if (isset ($ _COOKIE ['auth ' ])){
22
22
$ decodeToken = $ this ->objOfJwt ->DecodeToken ($ _COOKIE ['auth ' ]);
23
23
$ user = $ decodeToken ;
24
24
$ 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 ]);
25
57
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 );
35
59
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
- }
42
60
}
43
61
}
44
-
0 commit comments