|
@@ -10,22 +10,59 @@ class Out extends Core
|
|
|
|
|
|
public function getGoods()
|
|
|
{
|
|
|
- $where = array();
|
|
|
+ $this->data['data'] = Dever::load('shop/lib/info')->getGoods($this->shop_id);
|
|
|
|
|
|
- $name = Dever::input('name');
|
|
|
- if ($name) {
|
|
|
- $where['name'] = $name;
|
|
|
+ return $this->data;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ public function getList()
|
|
|
+ {
|
|
|
+ $where['shop_id'] = $this->shop_id;
|
|
|
+
|
|
|
+ $this->data['search_value'] = $where;
|
|
|
+ $this->data['search_value']['day'] = $day = Dever::input('day');
|
|
|
+ if ($day) {
|
|
|
+ $where['start'] = Dever::maketime($day . ' 00:00:00');
|
|
|
+ $where['end'] = Dever::maketime($day . ' 23:59:59');
|
|
|
}
|
|
|
- $this->data['data'] = Dever::db('goods/info')->getPageAll($where);
|
|
|
- if ($this->data['data']) {
|
|
|
- foreach ($this->data['data'] as $k => $v) {
|
|
|
- $this->data['data'][$k] = Dever::load('shop/lib/info')->getGoodsInfo($this->shop_id, $v);
|
|
|
+
|
|
|
+ $this->data['order'] = Dever::db('shop/out_order')->getAll($where);
|
|
|
+
|
|
|
+ if ($this->data['order']) {
|
|
|
+ foreach ($this->data['order'] as $k => $v) {
|
|
|
+ $this->data['order'][$k] = $this->getInfo($v);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
return $this->data;
|
|
|
}
|
|
|
|
|
|
+
|
|
|
+ public function view()
|
|
|
+ {
|
|
|
+ $where['shop_id'] = $this->shop_id;
|
|
|
+ $where['id'] = Dever::input('order_id');
|
|
|
+
|
|
|
+ $this->data = Dever::db('shop/out_order')->find($where);
|
|
|
+
|
|
|
+ if (!$this->data) {
|
|
|
+ Dever::alert('订单不存在');
|
|
|
+ }
|
|
|
+
|
|
|
+ $this->data = $this->getInfo($this->data, true);
|
|
|
+
|
|
|
+ return $this->data;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ public function info()
|
|
|
+ {
|
|
|
+ $this->data['user'] = $this->user;
|
|
|
+ $this->data['type'] = Dever::db('shop/out_order')->config['type'];
|
|
|
+ return $this->data;
|
|
|
+ }
|
|
|
+
|
|
|
|
|
|
public function confirm()
|
|
|
{
|
|
@@ -63,30 +100,44 @@ class Out extends Core
|
|
|
$s = isset($sku_id[$k]) ? $sku_id[$k] : -1;
|
|
|
$n = isset($num[$k]) ? $num[$k] : 1;
|
|
|
$this->data['list'][$k] = Dever::load('goods/lib/info')->getPayInfo($v, $s, $n);
|
|
|
+ $this->data['list'][$k]['num'] = $n;
|
|
|
+
|
|
|
+
|
|
|
+ $this->data['list'][$k]['ku_state'] = 1;
|
|
|
|
|
|
- $this->data['list'][$k]['buy_num'] = $n;
|
|
|
- $this->data['num'] += $n;
|
|
|
- $this->data['price'] += $this->data['list'][$k]['price'] * $n;
|
|
|
- $this->data['name'][] = $this->data['list'][$k]['name'];
|
|
|
+
|
|
|
+ $total = Dever::load('shop/lib/info')->checkTotal($n, $v, $this->shop_id, $s);
|
|
|
+
|
|
|
+ if ($total <= 0) {
|
|
|
+ $this->data['list'][$k]['ku_state'] = 2;
|
|
|
+ $this->data['list'][$k]['buy_num'] = 0;
|
|
|
+ }
|
|
|
+
|
|
|
+ if ($this->data['list'][$k]['ku_state'] == 1) {
|
|
|
+ $this->data['list'][$k]['buy_num'] = $n;
|
|
|
+ $this->data['num'] += $n;
|
|
|
+ $this->data['price'] += $this->data['list'][$k]['price'] * $n;
|
|
|
+ $this->data['name'][] = $this->data['list'][$k]['name'];
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
$this->data['name'] = implode(',', $this->data['name']);
|
|
|
}
|
|
|
|
|
|
|
|
|
- public function action()
|
|
|
+ public function action_commit()
|
|
|
{
|
|
|
$info = Dever::input('info');
|
|
|
+ $type = Dever::input('type', 1);
|
|
|
|
|
|
$this->goods();
|
|
|
-
|
|
|
- $pay = Dever::load('mshop/lib/buy')->action($this->shop, $this->data['name'], $this->data['num'], $this->data['list'], $this->data['price'], $info, $refer);
|
|
|
|
|
|
$order_data['shop_id'] = $this->shop['id'];
|
|
|
$order_data['mobile'] = $this->shop['mobile'];
|
|
|
$order_data['name'] = $this->data['name'];
|
|
|
$order_data['num'] = $this->data['num'];
|
|
|
$order_data['info'] = $info;
|
|
|
+ $order_data['type'] = $type;
|
|
|
$order_data['price'] = $this->data['price'];
|
|
|
$order_data['member_id'] = $this->uid;
|
|
|
|
|
@@ -104,17 +155,20 @@ class Out extends Core
|
|
|
}
|
|
|
|
|
|
foreach($this->data['list'] as $k => $v) {
|
|
|
- $data['shop_id'] = $shop['id'];
|
|
|
- $data['order_id'] = $id;
|
|
|
- $data['goods_id'] = $v['id'];
|
|
|
- $data['sku_id'] = $v['sku_id'];
|
|
|
- $data['price'] = $v['price'];
|
|
|
- $data['num'] = $v['buy_num'];
|
|
|
-
|
|
|
- $state = Dever::db('shop/out_order_goods')->insert($data);
|
|
|
- if ($state) {
|
|
|
-
|
|
|
- }
|
|
|
+ if ($v['ku_state'] == 1) {
|
|
|
+ $data['shop_id'] = $this->shop['id'];
|
|
|
+ $data['order_id'] = $id;
|
|
|
+ $data['goods_id'] = $v['id'];
|
|
|
+ $data['sku_id'] = $v['sku_id'];
|
|
|
+ $data['price'] = $v['price'];
|
|
|
+ $data['num'] = $v['buy_num'];
|
|
|
+
|
|
|
+ $state = Dever::db('shop/out_order_goods')->insert($data);
|
|
|
+ if ($state) {
|
|
|
+
|
|
|
+ Dever::load('shop/lib/goods')->oper(2, 1, array($data));
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
return 'ok';
|
|
@@ -131,4 +185,22 @@ class Out extends Core
|
|
|
return $this->getOrderId();
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
+
|
|
|
+ private function getInfo($info, $view = false)
|
|
|
+ {
|
|
|
+ $info['goods'] = Dever::db('shop/out_order_goods')->select(array('order_id' => $info['id']));
|
|
|
+ $info['cdate'] = date('Y-m-d H:i', $info['cdate']);
|
|
|
+
|
|
|
+ $type = Dever::db('shop/out_order')->config['type'];
|
|
|
+ $info['type_name'] = $type[$info['type']];
|
|
|
+ if ($view) {
|
|
|
+ foreach ($info['goods'] as $k => $v) {
|
|
|
+ $info['goods'][$k]['info'] = Dever::load('goods/lib/info')->getPayInfo($v['goods_id'], $v['sku_id']);
|
|
|
+ }
|
|
|
+
|
|
|
+ $info['member'] = Dever::db('shop/member')->find($info['member_id']);
|
|
|
+ }
|
|
|
+ return $info;
|
|
|
+ }
|
|
|
}
|