Orders.php
3.97 KB
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
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
<?php
/**
* Created by PhpStorm.
* User: ziy
* Date: 14-8-6
* Time: 下午3:45
*/
class YHMCart_Hook_Orders
{
/**
* 用户uid
* @var int
*/
private $uid;
/**
*
* @var array
*/
private $orderData = array();
/**
* 获取订单数据
* @return array
*/
function getOrder()
{
return $this->orderData;
}
/**
* 存储订单数据
* @param array $orderData
*/
function setOrder(array $orderData)
{
$this->orderData = $orderData;
}
/**
* 设置订单数据项中得数据
* @param $key
* @param $val
* @return $this
*/
function setOrderData($key, $val)
{
$this->orderData[$key] = $val;
return $this;
}
/**
* 获取订单指定值
* @param $key
* @return string
*/
function getOrderData($key)
{
if (empty($this->orderData[$key])) {
return '';
}
return $this->orderData[$key];
}
/**
* 设置订单商品
* @param array $goodsData
* @return $this
*/
function setOrderGoods(array $goodsData)
{
$this->orderData['goods_list'] = $goodsData;
return $this;
}
/**
* 1、正常商品 main_goods
* 2、赠品 gift_goods
* 3、加价购 need_pay_gifts
* 4、outlet outlet_goods
* 5、免单商品 advance_goods
**/
private $goodsType = array(
'main_goods',
'gift_goods',
'need_pay_gifts',
'outlet_goods',
'advance_goods'
);
private $tmpGoods = array();
/**
* 购物车商品列表
* @var array
*/
private $goodsList = array();
/**
* 添加购物车商品
* @param $productSku
* @param $buyNumber
* @param $type
* @return $this
* @throws Exception
*/
function addProduct($uid, $productSku, $buyNumber, $last_price, $type)
{
if (!in_array($type, $this->goodsType)) {
throw new Exception('商品类型不存在.');
}
$this->goodsList[$type] = array(
$productSku => $buyNumber
);
$this->tmpGoods = array(
'product_sku' => $productSku,
'buy_number' => $buyNumber,
'goods_type' => $type,
'uid' => $uid,
'last_price' => $last_price
);
return $this;
}
/**
* 获取购物车商品
* @param $productSku
* @param $type
* @return mixed
* @throws Exception
*/
function getProduct($productSku, $type)
{
if (in_array($type, $this->goodsType)) {
throw new Exception('商品类型不存在.');
}
return $this->goodsList[$type][$productSku];
}
/**
* 获取临时购物车商品
* @return array
*/
function getTmpGoods()
{
return $this->tmpGoods;
}
/**
* 获取UID
* @return int
*/
function getUid()
{
return $this->uid;
}
/**
* 设置用户UID
* @param $uid
* @return $this
*/
function setUid($uid)
{
$this->uid = $uid;
return $this;
}
/**
* 获取订单商品信息
* @param $productSku
* @param $type
* @return mixed
* @throws Exception
*/
function getOrderProduct($sku, $skc)
{
$info=array();
//size
$size = YHMProduct_Models_Stock_Client::getOneBySku($skc, $sku);
//skc基本信息
$goods_info = YHMProduct_Models_Goods_Client::getOneByProductSkc($skc);
$goods_image = YHMProduct_Models_Goodsimages_Client::getDefaultImageBySkc($skc);
if (is_array($goods_image))
{
foreach ($goods_image as $k=>$v)
{
$goods_image=$v;
continue;
}
}
$goods_info['goods_images']=$goods_image;
return array_merge($goods_info,$size);
}
}