Dao.php
6.86 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
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
<?php
/**
* Created by JetBrains PhpStorm.
* User: elkan
* Date: 14-8-20
* Time: 下午6:04
* To change this template use File | Settings | File Templates.
*/
use YHMOrders\SqlMap\Orders;
use YHMOrders\SqlMap\Shopping;
class YHMOrders_Models_Shopping_Dao extends YHMOrders_Dao
{
private $orderDefaultParameters = array(
'want_invoice' => 'N', #是否开发票
'payment_type' => 1,
'bank_code' => '',
'is_payed' => 'N',
'order_status' => 100,
'is_show' => 'Y',
'order_remark' => ''
);
private $orderParameters = array(
'order_code',
'buyer_uid',
'seller_uid',
'store_id',
'order_amount',
'last_order_amount',
'shipping_fee',
'last_shipping_fee',
'buying_way',
'payment_id'
);
private $ordersGoodsParameters = array(
'order_code', 'product_skc',
'product_sku', 'buy_number',
'goods_type', 'quality_level',
'sale_price', 'last_price',
'store_id', 'color_id', 'brand_id'
);
private $ordersGoodsInfo = array(
'goods_images', 'color_name',
'goods_name', 'small_category_id',
'size_name', 'max_category_id',
'middle_category_id','gender','shipping_fee'
);
public function __construct()
{
$this->router = 'order.yhm_orders';
$this->daoObject = $this->dao();
}
function create(array $orderData)
{
$this->addOrders($orderData);
foreach ($orderData['goods_list'] as $goodsKey => $goods) {
$goods['order_code'] = $orderData['order_code'];
$this->addOrdersGoods($goods);
$this->addOrdersStatus($goods['order_code'], 100, $orderData['buyer_uid']);
}
}
/**
* 添加商品
* @param array $orderData
* @return int
*/
public function addOrders(array $orderData)
{
$_orderData = array();
foreach ($this->orderParameters as $key) {
if (!isset($orderData[$key])) {
throw new Exception('缺少' . $key . '字段.');
}
$_orderData[$key] = $orderData[$key];
}
foreach ($this->orderDefaultParameters as $key => $val) {
if (!isset($orderData[$key]) || empty($orderData[$key])) {
$_orderData[$key] = $val;
} else {
$_orderData[$key] = $orderData[$key];
}
}
return $this->daoObject->insert(Orders\Shopping::INSERT_ORDERS, $_orderData)->lastInsertId();
}
/**
* 添加订单商品
* @param array $ordersGoods
* @return int
* @throws Exception
*/
public function addOrdersGoods(array $ordersGoods)
{
$_ordersGoods = array();
foreach ($this->ordersGoodsParameters as $goodsKey) {
if (!isset($ordersGoods[$goodsKey])) {
throw new Exception('缺少订单商品字段' . $goodsKey);
}
$_ordersGoods[$goodsKey] = $ordersGoods[$goodsKey];
}
return $this->daoObject->insert(Orders\Shopping::INSERT_ORDERS_GOODS, $_ordersGoods)->lastInsertId();
}
/**
* 插入订单状态
* @param $orderCode
* @param $orderStatus
* @param $triggerUser
* @return int
*/
public function addOrdersStatus($orderCode, $orderStatus, $triggerUser)
{
$parameter = array(
'order_code' => $orderCode,
'order_status' => $orderStatus,
'trigger_user' => $triggerUser
);
return $this->daoObject->insert(Orders\Shopping::INSERT_ORDERS_STATUS, $parameter)->lastInsertId();
}
/**
* 修改价格
* @param array $package
* @return int
* @throws Exception
*/
public function addShoppingChangePrice(array $package)
{
$changeParameters = array(
'agreement_key', 'buyer_uid', 'store_id', 'seller_uid', 'product_skc', 'sale_price', 'agreement_price', 'buy_number', 'goods_type'
);
$parameter = array();
foreach ($changeParameters as $key) {
if (empty($package[$key])) {
throw new Exception('改价异常,缺少字段:' . $key);
}
$parameter[$key] = $package[$key];
}
return $this->daoObject->insert(Shopping::INSERT_CHANGE_PRICE, $parameter)->lastInsertId();
}
/**
* 修改订单价格
*
* @param array $package
* @return int
*/
public function addShoppingOrderChangePrice(array $package)
{
$changeParameters = array(
'agreement_key', 'buyer_uid', 'store_id', 'seller_uid', 'product_skc', 'sale_price', 'agreement_price', 'buy_number', 'goods_type',
'agreement_shipping_fee','order_shipping_fee','order_amount','order_code','order_last_shipping_fee'
);
$parameter = array();
foreach ($changeParameters as $key) {
if (!isset($package[$key])) {
throw new Exception('改价异常,缺少字段:' . $key);
}
$parameter[$key] = $package[$key];
}
return $this->daoObject->insert(Shopping::INSERT_SHIPPING_ORDER_CHANGE_PRICE, $parameter)->lastInsertId();
}
/**
* 获取购物改价
*
* @param $agreementKey
* @param $buyerUid
* @return Array
*/
public function getShoppingChangePrice($agreementKey, $buyerUid)
{
$parameter = array(
'agreement_key' => $agreementKey,
'buyer_uid' => $buyerUid
);
return $this->daoObject->cache(false)->fetchRow(Shopping::SELECT_CHANGE_PRICE_BY_KEY, $parameter);
}
/**
* @param $agreementKey
* @param $orderCode
* @param $isBuyer
* @return int
*/
public function updateShoppingChange($agreementKey, $orderCode, $isBuyer = 'Y')
{
$parameter = array(
'agreement_key' => $agreementKey,
'order_code' => $orderCode,
'is_buyer' => $isBuyer
);
return $this->daoObject->update(Shopping::UPDATE_AGREEMENT_STATUS, $parameter)->rowCount();
}
/**
* 获取指定小于状态的购买数量
* @param $productSku
* @param $orderStatus
* @return Array
*/
public function getBuyGoodsNumber($productSku, $orderStatus = 900)
{
$parameter = array(
'product_sku' => $productSku,
'order_status' => $orderStatus
);
return $this->daoObject->cache(false)->fetchOne(Shopping::SELECT_BUY_GOODS_NUMBER, $parameter);
}
/**
* 插入订单镜像表
* @param $storeID
* @return mixed
*/
public function setBuyGoodsInfo($data)
{
$filer = array_merge($this->ordersGoodsParameters,$this->ordersGoodsInfo);
foreach ($filer as $k=>$v)
{
$parameter[$v]= $data[$v];
}
return $this->daoObject->insert(Orders\Shopping::INSERT_ORDERS_GOODS_INFO, $parameter)->lastInsertId();
}
}