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'); $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, '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); $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($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, 'method' => 3)); 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(); $coupon = Dever::db('shop/coupon')->select(array('coupon_id' => $v['coupon_id'], 'city' => $v['city'])); foreach ($coupon as $k1 => $v1) { $shop = Dever::db('shop/info')->getOne(array('id' => $v1['shop_id'], 'city' => $v['city'], 'coupon_city' => 1)); if ($shop) { $this->data[$k]['shop'][] = $shop; } } $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 (count($this->data[$k]['shop']) > 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 = true; 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, ); echo $cash; $this->data['price'] -= $cash; echo $this->data['price'];die; $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; } # 销量统计 }