123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456 |
- <?php
- namespace Mshop\Src;
- use Dever;
- use Mshop\Lib\Core;
- class Data extends Core
- {
- public function home()
- {
- $day = Dever::input('day');
- if (!$day) {
- $day = date('Y-m-d');
- }
- $where['start'] = Dever::maketime($day . ' 00:00:00');
- $where['end'] = Dever::maketime($day . ' 23:59:59');
- $where['shop_id'] = $this->shop_id;
- $where['status'] = '1,2,3,4';
- $this->data['num_order'] = round(Dever::db('shop/sell_order')->getOrderNum($where), 2);
- $cash = Dever::db('shop/sell_order')->getCashNum($where);
- if ($cash) {
- $this->data['num_cash'] = $cash['total'];
- }
- if (!$this->data['num_cash']) {
- $this->data['num_cash'] = 0;
- }
- $goods = Dever::db('shop/sell_order')->getGoodsNum($where);
- if ($goods) {
- $this->data['num_goods'] = $goods['total'];
- }
- if (!$this->data['num_goods']) {
- $this->data['num_goods'] = 0;
- }
- $this->data['num_cash'] = round($this->data['num_cash'], 2);
- $this->data['num_goods'] = round($this->data['num_goods'], 2);
- return $this->data;
- }
- # 销售订单列表
- public function sell_order()
- {
- return Dever::load('shop/lib/sell')->set(2, 1)->getList($this->shop_id);
- }
- # 查看订单详情
- public function order_view()
- {
- $order_id = Dever::input('order_id');
- return Dever::load('shop/lib/sell')->set(2, 2)->getView($this->shop_id, $order_id);
- }
- # 通知用户取件或者配送
- public function notice()
- {
- $order_id = Dever::input('order_id');
- $info = Dever::db('shop/sell_order')->find(array('id' => $order_id));
- if ($info && $info['shop_id'] == $this->shop_id && $info['status'] < 3) {
- $state = Dever::db('shop/sell_order')->update(array('where_id' => $info['id'], 'status' => 3, 'operdate' => time()));
- # 给用户发消息
- if ($info['uid'] && $info['uid'] > 0) {
- $shop = Dever::db('shop/info')->one($info['shop_id']);
- $msg_param['type'] = 1;//消息类型1是订单消息
- $msg_param['id'] = $info['id'];
- $msg_param['name'] = $shop['name'];
- $msg_param = Dever::json_encode($msg_param);
- if ($info['method'] == 1) {
- $msg = '您有一件自提商品已完成配货,请尽快到指定门店使用取件码取货,取件码:' . $info['code'];
- $name = '取货通知';
- } else {
- $msg = '您有一件外送商品已开始配送,收货时请将取件码提供给配送员核实货品信息,取件码::' . $info['code'];
- $name = '配送通知';
- }
-
- Dever::load('message/lib/data')->push(-1, $info['uid'], $name, $msg, 1, 1, false, $msg_param);
- }
- if ($info['method'] == 2) {
- Dever::load('shop/lib/sell')->updatePs($info, 2);
- }
-
- return 'ok';
- } else {
- Dever::alert('您没有权限');
- }
- }
- # 核销取件码,完成
- public function finish_commit()
- {
- $code = Dever::input('code');
- if (!$code) {
- Dever::alert('请输入自提码');
- }
- $order_id = Dever::input('order_id');
- $info = Dever::db('shop/sell_order')->find(array('code' => $code, 'id' => $order_id));
- if ($info && $info['shop_id'] == $this->shop_id && $info['status'] <= 4) {
- if ($info['refund_cash'] > 0) {
- $status = 6;
- } else {
- $status = 5;
- }
- $state = Dever::db('shop/sell_order')->update(array('where_id' => $info['id'], 'status' => $status, 'fdate' => time()));
- # 给用户发消息
- if ($info['uid'] && $info['uid'] > 0) {
- $shop = Dever::db('shop/info')->one($info['shop_id']);
- $msg_param['type'] = 1;//消息类型1是订单消息
- $msg_param['id'] = $info['id'];
- $msg_param['name'] = $shop['name'];
- $msg_param = Dever::json_encode($msg_param);
- $msg = '您有一笔订单已签收,祝您用餐愉快~';
- Dever::load('message/lib/data')->push(-1, $info['uid'], '订单完成通知', $msg, 1, 1, false, $msg_param);
- }
- if ($info['method'] == 2) {
- Dever::load('shop/lib/sell')->updatePs($info, 3);
- }
- return 'ok';
- } else {
- Dever::alert('您没有权限核销');
- }
- }
- # 获取订单退款记录
- public function order_tui_log()
- {
- $order_id = Dever::input('order_id');
- return Dever::load('shop/lib/refund')->set('sell')->getList(2, $this->shop_id, $order_id);
- }
- # 门店全部退款
- public function order_tui_commit()
- {
- $order_id = Dever::input('order_id');
- $status = Dever::input('status');
- $desc = Dever::input('desc');
- return Dever::load('shop/lib/refund')->set('sell')->apply(2, $this->shop_id, $order_id, false, $status, 0, $desc);
- }
- # 门店部分退款信息
- public function order_tui_one_info()
- {
- $order_id = Dever::input('order_id');
- $order_goods_id = Dever::input('order_goods_id');
- return Dever::load('shop/lib/refund')->set('sell')->getInfo(2, $this->shop_id, $order_id, $order_goods_id);
- }
- # 门店部分退款
- public function order_tui_one_commit()
- {
- $order_id = Dever::input('order_id');
- $order_goods_id = Dever::input('order_goods_id');
- $num = Dever::input('num');
- $status = Dever::input('status');
- $desc = Dever::input('desc');
- return Dever::load('shop/lib/refund')->set('sell')->apply(2, $this->shop_id, $order_id, $order_goods_id, $status, $num, $desc);
- }
- # 根据店铺获取商品列表
- public function getGoods()
- {
- return Dever::load('shop/lib/goods')->getList();
- }
- # 获取店铺的优惠券
- public function getCoupon()
- {
- $this->data = Dever::db('shop/coupon')->getAllPage(array('shop_id' => $this->shop_id));
- if ($this->data) {
- $time = time();
- foreach ($this->data as $k => $v) {
- $this->data[$k]['info'] = Dever::db('goods/coupon')->find($v['coupon_id']);
- $this->data[$k]['shop'] = array();
- $shop_num = Dever::db('shop/coupon')->total(array('coupon_id' => $v['coupon_id'], 'city' => $v['city']));
- $shop = Dever::db('shop/info')->getOne($v['shop_id']);
- if ($this->data[$k]['info']['method'] == 1) {
- $this->data[$k]['shop_name'] = '平台通用';
- } elseif ($this->data[$k]['info']['method'] == 2) {
- $this->data[$k]['shop_name'] = $shop['name'];
- if ($shop_num > 1) {
- $this->data[$k]['shop_name'] .= '多店通用';
- }
- } elseif ($this->data[$k]['info']['method'] == 3) {
- $this->data[$k]['shop_name'] = $shop['name'];
- }
- }
- }
- return $this->data;
- }
- # 赠送优惠券
- public function giveCoupon()
- {
- $coupon_id = Dever::input('coupon_id');
- $coupon = explode(',', $coupon_id);
- $num = Dever::input('num');
- $coupon_num = explode(',', $num);
- $order_id = Dever::input('order_id');
- $info = Dever::db('shop/sell_order')->find(array('shop_id' => $this->shop_id, 'id' => $order_id));
- if ($info['uid'] && $info['uid'] > 0) {
- foreach ($coupon as $k => $v) {
- $num = isset($coupon_num[$k]) ? $coupon_num[$k] : 1;
- Dever::load('shop/lib/coupon')->getOne($info['uid'], $this->shop, $v, 1, $num, false);
- }
- }
- return 'ok';
- }
- # 获取购物车的数据
- public function getCart()
- {
- $where['shop_id'] = $this->shop_id;
- $this->data['cart'] = Dever::db('shop/shop_cart')->select($where);
- if ($this->data['cart']) {
- foreach ($this->data['cart'] as $k => $v) {
- $this->data['cart'][$k]['goods'] = Dever::load('goods/lib/info')->getPayInfo($v['goods_id'], $v['sku_id']);
- if (isset($this->data['cart'][$k]['goods']['sku_id'])) {
- $this->data['cart'][$k]['price_id'] = $this->data['cart'][$k]['goods']['sku_id'];
- }
- }
- }
- return $this->data['cart'];
- }
- # 加入到购物车
- public function addCart()
- {
- $where['shop_id'] = $this->shop_id;
- $where['goods_id'] = Dever::input('goods_id');
- $where['sku_id'] = Dever::input('price_id');
- if (!$where['goods_id']) {
- Dever::alert('错误的商品');
- }
- $info = Dever::db('shop/shop_cart')->find($where);
- $where['num'] = Dever::input('num');
- if (!$info) {
- # 验证库存
- Dever::load('shop/lib/info')->checkTotal($where['num'], $where['goods_id'], $this->shop_id, $where['sku_id'], 2);
- $state = Dever::db('shop/shop_cart')->insert($where);
- } else {
- $where['num'] += $info['num'];
- # 验证库存
- Dever::load('shop/lib/info')->checkTotal($where['num'], $where['goods_id'], $this->shop_id, $where['sku_id'], 2);
- $where['where_id'] = $info['id'];
- $state = Dever::db('shop/shop_cart')->update($where);
- }
- return $this->getCart();
- }
- # 清空购物车
- public function dropCart()
- {
- $where['shop_id'] = $this->shop_id;
- $state = Dever::db('shop/shop_cart')->delete($where);
- return $this->alert($state);
- }
- # 更新购物车数量
- public function upCart()
- {
- $where['shop_id'] = $this->shop_id;
- $where['id'] = Dever::input('cart_id');
- $status = Dever::input('status', 1);
- $type = Dever::input('type', 1);
- $num = Dever::input('num');
- $info = Dever::db('shop/shop_cart')->find($where);
- $state = false;
- if ($info) {
- if ($type == 1) {
- $num = $info['num'] + $num;
- } else {
- $num = $info['num'] - $num;
- }
- $where = array();
- $where['where_id'] = $info['id'];
- if ($num <= 0) {
- $state = Dever::db('shop/shop_cart')->delete($info['id']);
- } else {
- $where['status'] = $status;
- $where['num'] = $num;
-
- # 验证库存
- $total = Dever::load('shop/lib/info')->checkTotal($num, $info['goods_id'], $this->shop_id, $info['sku_id']);
- if ($where['num'] > $total) {
- # 库存不足
- $where['num'] = $total;
- $state = Dever::db('shop/shop_cart')->update($where);
- return array('cart' => 2, 'data' => $total);
- }
- $state = Dever::db('shop/shop_cart')->update($where);
- }
- }
- return array('cart' => 1, 'data' => $this->getCart());
- }
- # 确认订单页面
- public function confirm()
- {
- $this->data['shop'] = $this->shop;
- Dever::load('shop/lib/sell')->goods($this->data);
- Dever::load('shop/lib/sell')->coupon($this->data);
- return $this->data;
- }
- # 开始下单
- public function pay()
- {
- $refer = Dever::input('refer');
- $cart = Dever::input('cart', 2);
- $address_id = Dever::input('address_id');
- $invoice_id = Dever::input('invoice_id');
- $pay_type = Dever::input('pay_type', 1);
- $mobile = Dever::input('mobile');
- $cash = Dever::input('cash', 0);
- Dever::setInput('pay_method', 2);
- if (!$mobile) {
- Dever::alert('手机号不能为空');
- }
-
- $info = Dever::input('info');
- $this->data['shop'] = $this->shop;
- Dever::load('shop/lib/sell')->goods($this->data);
- Dever::load('shop/lib/sell')->coupon($this->data, 3);
- if ($this->data['pay_method'] > 1) {
- $cart = false;
- }
- $cart = 2;
- if (!$this->data['coupon_id'] && $this->data['price'] <= 0) {
- Dever::alert('已售空');
- }
- if ($this->data['method'] == 2 && !$address_id) {
- Dever::alert('收货地址不能为空');
- }
- if (!isset($this->data['card'])) {
- $this->data['card'] = false;
- }
- $this->user = array
- (
- 'id' => -1,
- 'mobile' => $mobile,
- );
- $this->data['price'] -= $cash;
- $pay = Dever::load('shop/lib/sell')->pay($this->data['method'], $this->data['pay_method'], $pay_type, $this->user, $this->shop, $this->data['name'], $this->data['num'], $this->data['list'], $this->data['price'], $cash, $address_id, $invoice_id, $info, $this->data['card'], $this->data['coupon_id'], $this->data['user_coupon_id'], $this->data['coupon_cash'], $cart, 4, $refer);
- return $pay;
- }
- # 再次付款
- public function r_pay()
- {
- $refer = Dever::input('refer');
- $order_id = Dever::input('order_id');
- $pay = Dever::load('shop/lib/sell')->rpay($order_id, 4, $refer);
- return $pay;
- }
- # 销量统计
- public function stat()
- {
- $where['shop_id'] = $this->shop_id;
- $where['end'] = time();
- $where['start'] = $where['end'] - 86400*30;
- $this->data['total'] = array();
- $this->data['total']['cash'] = 0;
- $this->data['total']['order'] = 0;
- $this->data['total']['goods'] = 0;
- $this->data['data'] = Dever::db('shop/sell_stat')->getAll($where);
- $this->data['day'] = $this->data['cash'] = $this->data['order'] = $this->data['goods'] = array();
- if ($this->data['data']) {
- foreach ($this->data['data'] as $k => $v) {
- if (!$v['cash']) {
- $this->data['data'][$k]['cash'] = 0;
- }
- if (!$v['order']) {
- $this->data['data'][$k]['order'] = 0;
- }
- if (!$v['goods']) {
- $this->data['data'][$k]['goods'] = 0;
- }
- $this->data['data'][$k]['cash'] = floatval($this->data['data'][$k]['cash']);
- $this->data['data'][$k]['order'] = floatval($this->data['data'][$k]['order']);
- $this->data['data'][$k]['goods'] = floatval($this->data['data'][$k]['goods']);
- $this->data['data'][$k]['day'] = date('m-d', $v['day']);
- $this->data['total']['cash'] += $this->data['data'][$k]['cash'];
- $this->data['total']['order'] += $this->data['data'][$k]['order'];
- $this->data['total']['goods'] += $this->data['data'][$k]['goods'];
- $this->data['day'][] = $this->data['data'][$k]['day'];
- $this->data['cash'][] = $this->data['data'][$k]['cash'];
- $this->data['order'][] = $this->data['data'][$k]['order'];
- $this->data['goods'][] = $this->data['data'][$k]['goods'];
- }
- }
- return $this->data;
- }
- }
|