|
@@ -0,0 +1,194 @@
|
|
|
+<?php
|
|
|
+
|
|
|
+namespace Mshop\Lib;
|
|
|
+
|
|
|
+use Dever;
|
|
|
+
|
|
|
+class Out
|
|
|
+{
|
|
|
+
|
|
|
+ public function getList($type, $id)
|
|
|
+ {
|
|
|
+ $where['use_type'] = $type;
|
|
|
+ $where['use_id'] = $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');
|
|
|
+ }
|
|
|
+
|
|
|
+ $order_num = Dever::input('order_num');
|
|
|
+ if ($order_num) {
|
|
|
+ $where['order_num'] = $name;
|
|
|
+ }
|
|
|
+
|
|
|
+ $status = Dever::input('status');
|
|
|
+ if ($status) {
|
|
|
+ $where['status'] = $status;
|
|
|
+ }
|
|
|
+
|
|
|
+ $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($type, $id)
|
|
|
+ {
|
|
|
+ $where['use_type'] = $type;
|
|
|
+ $where['use_id'] = $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 confirm()
|
|
|
+ {
|
|
|
+ $this->goods();
|
|
|
+
|
|
|
+ return $this->data;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ private function goods()
|
|
|
+ {
|
|
|
+ $goods_id = Dever::input('goods_id');
|
|
|
+ if (!$goods_id) {
|
|
|
+ Dever::alert('请传入商品');
|
|
|
+ }
|
|
|
+ $goods_id = explode(',', $goods_id);
|
|
|
+
|
|
|
+ $sku_id = Dever::input('price_id');
|
|
|
+ if ($sku_id) {
|
|
|
+ $sku_id = explode(',', $sku_id);
|
|
|
+ }
|
|
|
+
|
|
|
+ $num = Dever::input('num');
|
|
|
+ if (!$num) {
|
|
|
+ Dever::alert('请传入商品数量');
|
|
|
+ }
|
|
|
+ $num = explode(',', $num);
|
|
|
+
|
|
|
+ $this->data['price'] = 0;
|
|
|
+ $this->data['num'] = 0;
|
|
|
+ $this->data['name'] = array();
|
|
|
+
|
|
|
+ foreach ($goods_id as $k => $v) {
|
|
|
+ $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;
|
|
|
+
|
|
|
+
|
|
|
+ $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_commit()
|
|
|
+ {
|
|
|
+ $info = Dever::input('info');
|
|
|
+ $type = Dever::input('type', 1);
|
|
|
+
|
|
|
+ $this->goods();
|
|
|
+
|
|
|
+ $order_data['use_type'] = 1;
|
|
|
+ $order_data['use_id'] = $this->shop['id'];
|
|
|
+ $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;
|
|
|
+
|
|
|
+ $order_data['order_num'] = $this->getOrderId();
|
|
|
+ $id = Dever::db('shop/out_order')->insert($order_data);
|
|
|
+
|
|
|
+ if (!$id) {
|
|
|
+ Dever::alert('出库失败');
|
|
|
+ }
|
|
|
+
|
|
|
+ foreach($this->data['list'] as $k => $v) {
|
|
|
+ if ($v['ku_state'] == 1) {
|
|
|
+ $data['order_id'] = $id;
|
|
|
+ $data['goods_id'] = $v['id'];
|
|
|
+ $data['sku_id'] = $v['sku_id'];
|
|
|
+ $data['price'] = $v['price'] * $v['buy_num'];
|
|
|
+ $data['d_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($order_data, 2, 1, array($data));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ return array('order_id' => $id);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ public function getOrderId()
|
|
|
+ {
|
|
|
+ $where['order_num'] = Dever::order('OUT');
|
|
|
+ $state = Dever::db('shop/out_order')->one($where);
|
|
|
+ if (!$state) {
|
|
|
+ return $where['order_num'];
|
|
|
+ } else {
|
|
|
+ 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['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;
|
|
|
+ }
|
|
|
+}
|