|
@@ -8,7 +8,7 @@ use Dever;
|
|
|
|
|
|
class Buy
|
|
|
{
|
|
|
-
|
|
|
+
|
|
|
public $type = 1;
|
|
|
|
|
|
public $view = 1;
|
|
@@ -36,7 +36,15 @@ class Buy
|
|
|
public function where($id)
|
|
|
{
|
|
|
$where = array();
|
|
|
- $where['shop_id'] = $id;
|
|
|
+ if ($this->type > 10) {
|
|
|
+ $type = $this->type - 10;
|
|
|
+ $where['source_type'] = $type;
|
|
|
+ $where['source_type_id'] = $id;
|
|
|
+ } else {
|
|
|
+ $where['type'] = $this->type;
|
|
|
+ $where['type_id'] = $id;
|
|
|
+ }
|
|
|
+
|
|
|
if (!$where) {
|
|
|
Dever::alert('参数错误');
|
|
|
}
|
|
@@ -49,10 +57,6 @@ class Buy
|
|
|
{
|
|
|
$result = array();
|
|
|
$where = $this->where($id);
|
|
|
- $mobile = Dever::input('mobile');
|
|
|
- if ($mobile) {
|
|
|
- $where['mobile'] = $mobile;
|
|
|
- }
|
|
|
$status = Dever::input('status');
|
|
|
if ($status) {
|
|
|
$where['status'] = $status;
|
|
@@ -138,12 +142,29 @@ class Buy
|
|
|
$info['status_name'] = $this->config['status'][$info['status']];
|
|
|
|
|
|
$info['goods'] = Dever::db('shop/buy_order_goods')->select(array('order_id' => $info['id']));
|
|
|
- $info['shop'] = Dever::db('shop/info')->getOne($info['shop_id']);
|
|
|
- $info['cdate'] = date('Y-m-d H:i', $info['cdate']);
|
|
|
+ if ($info['type'] == 1) {
|
|
|
+ $info['type_info'] = Dever::db('shop/info')->getOne($info['type_id']);
|
|
|
+ } elseif ($info['type'] == 2) {
|
|
|
+ $info['type_info'] = Dever::db('store/info')->find($info['type_id']);
|
|
|
+ } elseif ($info['type'] == 3) {
|
|
|
+ $info['type_info'] = Dever::db('factory/info')->find($info['type_id']);
|
|
|
+ }
|
|
|
|
|
|
+ if ($info['source_type'] == 1) {
|
|
|
+ $info['source_info'] = Dever::db('shop/info')->getOne($info['source_id']);
|
|
|
+ } elseif ($info['source_type'] == 2) {
|
|
|
+ $info['source_info'] = Dever::db('store/info')->find($info['source_id']);
|
|
|
+ } elseif ($info['source_type'] == 3) {
|
|
|
+ $info['source_info'] = Dever::db('factory/info')->find($info['source_id']);
|
|
|
+ }
|
|
|
+
|
|
|
+ $info['cdate'] = date('Y-m-d H:i', $info['cdate']);
|
|
|
+ if ($info['operdate']) {
|
|
|
+ $info['operdate'] = date('Y-m-d H:i', $info['operdate']);
|
|
|
+ }
|
|
|
$goods_status = Dever::db('shop/buy_order_goods')->config['status'];
|
|
|
$goods_process = Dever::db('shop/buy_order_refund')->config['process'];
|
|
|
- if ($view) {
|
|
|
+ if ($view || $this->view == 2) {
|
|
|
foreach ($info['goods'] as $k => $v) {
|
|
|
$info['goods'][$k]['info'] = Dever::load('goods/lib/info')->getPayInfo($v['goods_id'], $v['sku_id']);
|
|
|
$info['goods'][$k]['status_name'] = $goods_status[$v['status']];
|
|
@@ -162,42 +183,36 @@ class Buy
|
|
|
$info['refund_cash'] = 0;
|
|
|
}
|
|
|
|
|
|
- if ($info['fdate']) {
|
|
|
- $info['fdate'] = date('Y-m-d H:i', $info['fdate']);
|
|
|
- }
|
|
|
- if ($info['qfdate']) {
|
|
|
- $info['qfdate'] = date('Y-m-d H:i', $info['qfdate']);
|
|
|
- }
|
|
|
- if ($info['operdate']) {
|
|
|
- $info['operdate'] = date('Y-m-d H:i', $info['operdate']);
|
|
|
- }
|
|
|
- if ($info['shdate']) {
|
|
|
- $info['shdate'] = date('Y-m-d H:i', $info['shdate']);
|
|
|
+
|
|
|
+ $info['ps_info'] = Dever::db('shop/buy_order_ps')->find(array('order_id' => $info['id']));
|
|
|
+ if ($info['ps_info']) {
|
|
|
+ $info['ps_info']['service_name'] = '商家自送';
|
|
|
+ $info['ps_info']['cdate'] = date('Y-m-d H:i', $info['ps_info']['cdate']);
|
|
|
+ if ($info['ps_info']['ydate']) {
|
|
|
+ $info['ps_info']['ydate'] = date('Y-m-d H:i', $info['ps_info']['ydate']);
|
|
|
+ }
|
|
|
+
|
|
|
+ $status = Dever::db('shop/buy_order_ps')->config['status'];
|
|
|
+ $info['ps_info']['status_name'] = $status[$info['ps_info']['status']];
|
|
|
+
|
|
|
+ if ($info['ps_info']['service_id'] > 0) {
|
|
|
+
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
return $info;
|
|
|
}
|
|
|
|
|
|
|
|
|
- public function action($shop, $name, $num, $goods, $price, $info, $refer = '')
|
|
|
+ public function action($type, $type_id, $name, $num, $goods, $price, $info, $refer = '')
|
|
|
{
|
|
|
- if (!$shop) {
|
|
|
- Dever::alert('错误的门店信息');
|
|
|
- }
|
|
|
-
|
|
|
- $order_data['shop_id'] = $shop['id'];
|
|
|
- $order_data['mobile'] = $shop['mobile'];
|
|
|
+ $order_data['type'] = $type;
|
|
|
+ $order_data['type_id'] = $type_id;
|
|
|
$order_data['name'] = $name;
|
|
|
$order_data['num'] = $num;
|
|
|
$order_data['info'] = $info;
|
|
|
$order_data['price'] = $price;
|
|
|
|
|
|
- $order_data['area'] = $shop['area'];
|
|
|
- $order_data['province'] = $shop['province'];
|
|
|
- $order_data['city'] = $shop['city'];
|
|
|
- $order_data['county'] = $shop['county'];
|
|
|
- $order_data['town'] = $shop['town'];
|
|
|
-
|
|
|
$order_data['order_num'] = $this->getOrderId();
|
|
|
$id = Dever::db('shop/buy_order')->insert($order_data);
|
|
|
|
|
@@ -206,7 +221,6 @@ class Buy
|
|
|
}
|
|
|
|
|
|
foreach($goods as $k => $v) {
|
|
|
- $data['shop_id'] = $shop['id'];
|
|
|
$data['order_id'] = $id;
|
|
|
$data['goods_id'] = $v['id'];
|
|
|
$data['sku_id'] = $v['sku_id'];
|
|
@@ -352,6 +366,20 @@ class Buy
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+
|
|
|
+ public function updatePs($order, $status = 1)
|
|
|
+ {
|
|
|
+ $where['order_id'] = $order['id'];
|
|
|
+ $data = Dever::db('shop/buy_order_ps')->find($where);
|
|
|
+
|
|
|
+ if ($data) {
|
|
|
+ $update['where_id'] = $data['id'];
|
|
|
+ $update['status'] = $status;
|
|
|
+ $update['ydate'] = time();
|
|
|
+ Dever::db('shop/buy_order_ps')->update($update);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
|
|
|
public function finish($id, $order_id)
|
|
|
{
|
|
@@ -362,14 +390,15 @@ class Buy
|
|
|
} else {
|
|
|
$status = 5;
|
|
|
}
|
|
|
- $state = Dever::db('shop/buy_order')->update(array('where_id' => $data['id'], 'status' => $status, 'qsdate' => time()));
|
|
|
+ $state = Dever::db('shop/buy_order')->update(array('where_id' => $data['id'], 'status' => $status));
|
|
|
if ($state) {
|
|
|
+ $this->updatePs($data, 3);
|
|
|
|
|
|
$where['order_id'] = $data['id'];
|
|
|
$where['status'] = 1;
|
|
|
- $data = Dever::db('shop/buy_order_goods')->select($where);
|
|
|
- if ($data) {
|
|
|
- Dever::load('shop/lib/goods')->oper(1, 1, $data);
|
|
|
+ $goods = Dever::db('shop/buy_order_goods')->select($where);
|
|
|
+ if ($goods) {
|
|
|
+ Dever::load('shop/lib/goods')->oper($data, 1, 1, $goods);
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -423,8 +452,6 @@ class Buy
|
|
|
|
|
|
$info = Dever::db('shop/buy_order')->one($id);
|
|
|
|
|
|
- $shop = Dever::db('shop/info')->find($info['shop_id']);
|
|
|
-
|
|
|
$tk_status = Dever::db('shop/buy_order_refund')->config['status'];
|
|
|
$tk_process = Dever::db('shop/buy_order_refund')->config['process'];
|
|
|
|
|
@@ -440,25 +467,43 @@ class Buy
|
|
|
|
|
|
</tr>';
|
|
|
|
|
|
- $html .= '<tr>
|
|
|
- <td>门店信息</td>
|
|
|
- <td>'.$this->table(false, array(array('门店名称:' . $shop['name'], '联系人:' . $shop['truename'], '联系电话:' . $shop['mobile']))).'</td>
|
|
|
+ if ($info['type'] == 1) {
|
|
|
+ $type_info = Dever::db('shop/info')->find($info['type_id']);
|
|
|
+ $html .= '<tr>
|
|
|
+ <td>门店信息</td>
|
|
|
+ <td>'.$this->table(false, array(array('门店名称:' . $type_info['name'], '联系人:' . $type_info['truename'], '联系电话:' . $type_info['mobile']))).'</td>
|
|
|
|
|
|
- </tr>';
|
|
|
+ </tr>';
|
|
|
+ } elseif ($info['type'] == 2) {
|
|
|
+ $type_info = Dever::db('store/info')->find($info['type_id']);
|
|
|
+ $html .= '<tr>
|
|
|
+ <td>仓库信息</td>
|
|
|
+ <td>'.$this->table(false, array(array('仓库名称:' . $type_info['name'], '联系人:' . $type_info['truename'], '联系电话:' . $type_info['mobile']))).'</td>
|
|
|
+
|
|
|
+ </tr>';
|
|
|
+ } elseif ($info['type'] == 3) {
|
|
|
+ $type_info = Dever::db('store/info')->find($info['type_id']);
|
|
|
+ $html .= '<tr>
|
|
|
+ <td>工厂信息</td>
|
|
|
+ <td>'.$this->table(false, array(array('工厂名称:' . $type_info['name'], '联系人:' . $type_info['truename'], '联系电话:' . $type_info['mobile']))).'</td>
|
|
|
+
|
|
|
+ </tr>';
|
|
|
+ }
|
|
|
+
|
|
|
|
|
|
- if ($info['type_id'] > 0) {
|
|
|
- if ($info['type'] == 1) {
|
|
|
+ if ($info['source_id'] > 0) {
|
|
|
+ if ($info['source_type'] == 2) {
|
|
|
|
|
|
- $store = Dever::db('store/info')->find($info['type_id']);
|
|
|
+ $store = Dever::db('store/info')->find($info['source_id']);
|
|
|
|
|
|
$html .= '<tr>
|
|
|
<td>供应商信息</td>
|
|
|
<td>'.$this->table(false, array(array('仓库名称:' . $store['name'], '联系人:' . $store['truename'], '联系电话:' . $store['mobile']))).'</td>
|
|
|
|
|
|
</tr>';
|
|
|
- } elseif ($info['type'] == 2) {
|
|
|
+ } elseif ($info['source_type'] == 3) {
|
|
|
|
|
|
- $factory = Dever::db('factory/info')->find($info['type_id']);
|
|
|
+ $factory = Dever::db('factory/info')->find($info['source_id']);
|
|
|
|
|
|
$html .= '<tr>
|
|
|
<td>供应商信息</td>
|
|
@@ -467,32 +512,56 @@ class Buy
|
|
|
</tr>';
|
|
|
}
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
+ if ($info['info']) {
|
|
|
+ $html .= '<tr>
|
|
|
+ <td>订单备注</td>
|
|
|
+ <td>'.$this->table(false, array(array($info['info']))).'</td>
|
|
|
+
|
|
|
+ </tr>';
|
|
|
+ }
|
|
|
|
|
|
$url = Dever::url('lib/buy.refund', 'mshop');
|
|
|
+ if (!$info['refund_cash']) {
|
|
|
+ $info['refund_cash'] = 0;
|
|
|
+ }
|
|
|
|
|
|
- if ($tk && $tk['process'] == 1) {
|
|
|
- $status = '申请' . $tk_status[$tk['status']];
|
|
|
- $process = $tk_process[$tk['process']];
|
|
|
- $process = '';
|
|
|
+ if ($info['refund_cash'] > 0) {
|
|
|
+
|
|
|
+ if ($tk) {
|
|
|
+ $process = $tk_process[$tk['process']];
|
|
|
+ $process = '';
|
|
|
+
|
|
|
+ if ($tk['process'] == 1) {
|
|
|
+ $status = '申请' . $tk_status[$tk['status']];
|
|
|
+ $process .= ' <a href="javascript:;" onclick="audit('.$tk['id'].', 2, \''.$url.'\')" class="layui-btn">通过</a><a href="javascript:;" onclick="audit('.$tk['id'].', 3, \''.$url.'\')" class="layui-btn layui-btn-danger">驳回</a>';
|
|
|
|
|
|
- if ($tk['process'] == 1) {
|
|
|
- $process .= ' <a href="javascript:;" onclick="audit('.$tk['id'].', 2, \''.$url.'\')" class="layui-btn">通过</a><a href="javascript:;" onclick="audit('.$tk['id'].', 3, \''.$url.'\')" class="layui-btn layui-btn-danger">驳回</a>';
|
|
|
+ }
|
|
|
+ $desc = array();
|
|
|
+ $desc['原因'] = $tk['desc'];
|
|
|
+ if ($tk['pic']) {
|
|
|
+ $desc['图片'] = '';
|
|
|
+ $pic = explode(',', $tk['pic']);
|
|
|
+ foreach ($pic as $k => $v) {
|
|
|
+ $desc['图片'] .= '<a href="'.$v.'" target="_blank"><img src="'.$v.'" width="100"/></a>';
|
|
|
+ }
|
|
|
+ }
|
|
|
+ $tk['desc'] = '<a href="javascript:layer.alert($(\'#desc_content\').html());">查看</a><span id="desc_content" style="display:none">'.Dever::table($desc).'</span>';
|
|
|
}
|
|
|
+
|
|
|
$html .= '<tr>
|
|
|
<td>订单信息</td>
|
|
|
- <td>'.$this->table(array('金额', '退款金额', '数量', '订单状态', '审核状态'), array(array($info['price'], $info['refund_cash'], $info['num'], $status, $process))).'</td>
|
|
|
+ <td>'.$this->table(array('金额', '数量', '订单状态', '退款金额', '退款原因', '退款审核'), array(array($info['price'], $info['num'], $status, $info['refund_cash'], $tk['desc'], $process))).'</td>
|
|
|
</tr>';
|
|
|
+
|
|
|
} else {
|
|
|
$html .= '<tr>
|
|
|
<td>订单信息</td>
|
|
|
- <td>'.$this->table(array('金额', '退款金额', '数量', '订单状态'), array(array($info['price'], $info['refund_cash'], $info['num'], $status))).'</td>
|
|
|
+ <td>'.$this->table(array('金额', '数量', '订单状态'), array(array($info['price'], $info['num'], $status))).'</td>
|
|
|
</tr>';
|
|
|
}
|
|
|
|
|
|
|
|
|
-
|
|
|
-
|
|
|
$html .= '</tbody></table>';
|
|
|
|
|
|
$html .= '[商品清单]:';
|
|
@@ -508,16 +577,32 @@ class Buy
|
|
|
$tk = Dever::db('shop/buy_order_refund')->find(array('order_id' => $info['id'], 'order_goods_id' => $v['id'], 'type' => 2));
|
|
|
if ($tk && $tk['process'] == 1) {
|
|
|
$status = '申请' . $tk_status[$tk['status']];
|
|
|
-
|
|
|
+
|
|
|
+ $desc = array();
|
|
|
+ $desc['原因'] = $tk['desc'];
|
|
|
+ if ($tk['pic']) {
|
|
|
+ $desc['图片'] = '';
|
|
|
+ $pic = explode(',', $tk['pic']);
|
|
|
+ foreach ($pic as $k => $v) {
|
|
|
+ $desc['图片'] .= '<a href="'.$v.'" target="_blank"><img src="'.$v.'" width="100"/></a>';
|
|
|
+ }
|
|
|
+ }
|
|
|
+ $status .= ' <a href="javascript:layer.alert($(\'#desc_content\').html());">查看原因</a><span id="desc_content" style="display:none">'.Dever::table($desc).'</span>';
|
|
|
|
|
|
if ($tk['process'] == 1) {
|
|
|
$status .= ' <a href="javascript:;" onclick="audit('.$tk['id'].', 2, \''.$url.'\')" class="layui-btn">通过</a><a href="javascript:;" onclick="audit('.$tk['id'].', 3, \''.$url.'\')" class="layui-btn layui-btn-danger">驳回</a>';
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
+ if (isset($goods_info['sku'])) {
|
|
|
+ $sku = $goods_info['sku']['string'];
|
|
|
+ } else {
|
|
|
+ $sku = '无';
|
|
|
+ }
|
|
|
$body[$k] = array
|
|
|
(
|
|
|
$goods_info['name'],
|
|
|
- $v['price'],
|
|
|
+ $sku,
|
|
|
$v['price'],
|
|
|
$v['num'],
|
|
|
$status,
|
|
@@ -565,6 +650,7 @@ class Buy
|
|
|
}
|
|
|
|
|
|
|
|
|
+
|
|
|
public function send_commit()
|
|
|
{
|
|
|
$order_id = Dever::input('order_id');
|
|
@@ -574,10 +660,14 @@ class Buy
|
|
|
Dever::alert('当前订单状态无法发货');
|
|
|
}
|
|
|
|
|
|
- $state = Dever::db('shop/buy_order')->update(array('where_id' => $order['id'], 'status' => 4, 'fdate' => time()));
|
|
|
+ $state = Dever::db('shop/buy_order')->update(array('where_id' => $order['id'], 'status' => 4));
|
|
|
+
|
|
|
+ if ($state) {
|
|
|
+ $this->updatePs($order, 1);
|
|
|
+ }
|
|
|
|
|
|
return 'reload';
|
|
|
- }
|
|
|
+ }*/
|
|
|
|
|
|
|
|
|
public function audit_commit()
|
|
@@ -589,9 +679,13 @@ class Buy
|
|
|
Dever::alert('当前订单状态无法拆单');
|
|
|
}
|
|
|
|
|
|
+ if ($order['type'] != 1) {
|
|
|
+ Dever::alert('这不是门店的订单');
|
|
|
+ }
|
|
|
+
|
|
|
$goods = Dever::db('shop/buy_order_goods')->select(array('order_id' => $order_id));
|
|
|
|
|
|
- $shop = Dever::db('shop/info')->find($order['shop_id']);
|
|
|
+ $shop = Dever::db('shop/info')->find($order['type_id']);
|
|
|
|
|
|
|
|
|
$shop_store = Dever::db('shop/store')->select(array('shop_id' => $shop['id']));
|
|
@@ -624,25 +718,21 @@ class Buy
|
|
|
|
|
|
array_multisort($distance, SORT_ASC, SORT_NUMERIC, $factory);
|
|
|
|
|
|
- $num = 0;
|
|
|
+ $this->order_num = 0;
|
|
|
foreach ($goods as $k => $v) {
|
|
|
|
|
|
- $find = $this->store($order['order_num'] . '_' . $num, $shop, $store, $v);
|
|
|
+ $find = $this->store($order['id'], $order['order_num'] . '_' . $this->order_num, $shop, $store, $v);
|
|
|
if (!$find[1]) {
|
|
|
|
|
|
if ($factory) {
|
|
|
- $find = $this->factory($order['order_num'] . '_' . $num, $shop, $factory, $v);
|
|
|
+ $find = $this->factory($order['id'], $order['order_num'] . '_' . $this->order_num, $shop, $factory, $v);
|
|
|
}
|
|
|
}
|
|
|
-
|
|
|
- if ($find[1]) {
|
|
|
- $num++;
|
|
|
- }
|
|
|
}
|
|
|
|
|
|
- if ($num > 0) {
|
|
|
- if ($num == 1 && count($find[1]) == 1) {
|
|
|
- Dever::db('shop/buy_order')->update(array('where_id' => $order['id'], 'status' => 3, 'type' => $find[0], 'type_id' => implode('', $find[1])));
|
|
|
+ if ($this->order_num > 0) {
|
|
|
+ if ($this->order_num == 1) {
|
|
|
+ Dever::db('shop/buy_order')->update(array('where_id' => $order['id'], 'status' => 3, 'source_type' => $find[0], 'source_id' => implode('', $find[1])));
|
|
|
|
|
|
Dever::db('shop/buy_order')->delete($find[2][0]);
|
|
|
Dever::db('shop/buy_order_goods')->delete(array('order_id' => $find[2][0]));
|
|
@@ -659,13 +749,13 @@ class Buy
|
|
|
return 'ok';
|
|
|
}
|
|
|
|
|
|
- private function store($order_id, $shop, $store, $goods, $state = 2)
|
|
|
+ private function store($order_id, $order_num, $shop, $store, $goods, $state = 2)
|
|
|
{
|
|
|
$find = array();
|
|
|
$type_id = array();
|
|
|
$id = array();
|
|
|
if (!$store) {
|
|
|
- return array(1, $type_id, $id);
|
|
|
+ return array(2, $type_id, $id);
|
|
|
}
|
|
|
foreach ($store as $k => $v) {
|
|
|
$where['store_id'] = $v['id'];
|
|
@@ -676,7 +766,7 @@ class Buy
|
|
|
if ($sku) {
|
|
|
if ($goods['num'] <= $sku['total']) {
|
|
|
|
|
|
- $state = Dever::load('store/lib/order')->pay($order_id, $shop, $where['store_id'], $goods['price'], $goods['num'], $where['goods_id'], $where['sku_id']);
|
|
|
+ $state = $this->createOrder($order_id, $order_num, 1, $shop['id'], 2, $where['store_id'], $goods['price'], $goods['num'], $where['goods_id'], $where['sku_id']);
|
|
|
if ($state) {
|
|
|
$type_id[] = $where['store_id'];
|
|
|
$id[] = $state;
|
|
@@ -686,7 +776,7 @@ class Buy
|
|
|
|
|
|
$goods['num'] = $goods['num'] - $sku['total'];
|
|
|
|
|
|
- $state = Dever::load('store/lib/order')->pay($order_id, $shop, $where['store_id'], $goods['price'], $sku['total'], $where['goods_id'], $where['sku_id']);
|
|
|
+ $state = $this->createOrder($order_id, $order_num, 1, $shop['id'], 2, $where['store_id'], $goods['price'], $sku['total'], $where['goods_id'], $where['sku_id']);
|
|
|
if (!$state) {
|
|
|
$goods['num'] = $goods['num'] + $sku['total'];
|
|
|
} else {
|
|
@@ -702,16 +792,16 @@ class Buy
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- return array(1, $type_id, $id);
|
|
|
+ return array(2, $type_id, $id);
|
|
|
}
|
|
|
|
|
|
- private function factory($order_id, $shop, $factory, $goods)
|
|
|
+ private function factory($order_id, $order_num, $shop, $factory, $goods)
|
|
|
{
|
|
|
$find = array();
|
|
|
$type_id = array();
|
|
|
$id = array();
|
|
|
if (!$factory) {
|
|
|
- return array(1, $type_id, $id);
|
|
|
+ return array(3, $type_id, $id);
|
|
|
}
|
|
|
|
|
|
foreach ($factory as $k => $v) {
|
|
@@ -721,7 +811,7 @@ class Buy
|
|
|
$sku = Dever::db('factory/goods_sku')->select($where);
|
|
|
|
|
|
if ($sku) {
|
|
|
- $state = Dever::load('factory/lib/order')->pay($order_id, $shop, $where['factory_id'], $goods['price'], $goods['num'], $where['goods_id'], $where['sku_id']);
|
|
|
+ $state = $this->createOrder($order_id, $order_num, 1, $shop['id'], 3, $where['factory_id'], $goods['price'], $goods['num'], $where['goods_id'], $where['sku_id']);
|
|
|
if ($state) {
|
|
|
$type_id[] = $where['factory_id'];
|
|
|
$id[] = $state;
|
|
@@ -732,6 +822,86 @@ class Buy
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- return array(2, $type_id, $id);
|
|
|
+ return array(3, $type_id, $id);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ private function createOrder($order_id, $order_num, $type, $type_id, $source_type, $source_id, $price, $num, $goods_id, $sku_id)
|
|
|
+ {
|
|
|
+ $where['parent_order_id'] = $order_id;
|
|
|
+ $where['type'] = $type;
|
|
|
+ $where['type_id'] = $type_id;
|
|
|
+ $where['source_type'] = $source_type;
|
|
|
+ $where['source_id'] = $source_id;
|
|
|
+ $where['r'] = $goods_id;
|
|
|
+ $info = Dever::db('shop/buy_order')->find($where);
|
|
|
+
|
|
|
+ if (!$info) {
|
|
|
+ $this->order_num++;
|
|
|
+ $data = $where;
|
|
|
+ $data['name'] = $order_id;
|
|
|
+ $data['order_num'] = $order_num;
|
|
|
+ $data['operdate'] = time();
|
|
|
+ $data['status'] = 3;
|
|
|
+ $data['price'] = $price;
|
|
|
+ $data['num'] = $num;
|
|
|
+ $id = $state = Dever::db('shop/buy_order')->insert($data);
|
|
|
+ } else {
|
|
|
+ $id = $info['id'];
|
|
|
+
|
|
|
+ $data['where_id'] = $id;
|
|
|
+ $data['price'] = $info['price'] + $price;
|
|
|
+ $data['num'] = $info['num'] + $num;
|
|
|
+ $state = Dever::db('shop/buy_order')->update($data);
|
|
|
+ }
|
|
|
+
|
|
|
+ if ($state && $id > 0) {
|
|
|
+ $goods_info = Dever::db('shop/buy_order_goods')->find(array('order_id' => $id));
|
|
|
+ if (!$goods_info) {
|
|
|
+ $goods['order_id'] = $id;
|
|
|
+ $goods['goods_id'] = $goods_id;
|
|
|
+ $goods['sku_id'] = $sku_id;
|
|
|
+ $goods['price'] = $price;
|
|
|
+ $goods['num'] = $num;
|
|
|
+ Dever::db('shop/buy_order_goods')->insert($goods);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ return $id;
|
|
|
+ }
|
|
|
+
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ public function updateSell($source_type, $source_id, $goods_id, $sku_id, $num)
|
|
|
+ {
|
|
|
+ if ($source_type == 2) {
|
|
|
+ $data['store_id'] = $source_id;
|
|
|
+ $data['goods_id'] = $goods_id;
|
|
|
+ $data['sku_id'] = $sku_id;
|
|
|
+ $data['num'] = $num;
|
|
|
+ return Dever::load('store/lib/goods')->oper($source_id, 1, 2, array($data));
|
|
|
+ } else {
|
|
|
+ $up = array();
|
|
|
+ $up['where_factory_id'] = $source_id;
|
|
|
+ $up['where_goods_id'] = $goods_id;
|
|
|
+ $up['sell_num'] = $num;
|
|
|
+ $state = Dever::db('factory/goods')->incSell($up);
|
|
|
+
|
|
|
+ if ($state) {
|
|
|
+ if ($sku_id > 0) {
|
|
|
+
|
|
|
+ } else {
|
|
|
+ $sku_id = -1;
|
|
|
+ }
|
|
|
+ $upSku = $up;
|
|
|
+ $upSku['where_sku_id'] = $sku_id;
|
|
|
+ $state = Dever::db('factory/goods_sku')->incSell($upSku);
|
|
|
+ }
|
|
|
+
|
|
|
+ return $state;
|
|
|
+ }
|
|
|
}
|
|
|
}
|