Esempio n. 1
0
 public function edit($goods_id)
 {
     //检查登录
     $this->_login();
     if (!$goods_id) {
         $url = url('admin', 'admingoods::detail');
         header('Location:' . $url);
         throw new Exception('exit');
     }
     $where = array();
     $data = array();
     $goods_id = $goods_id + 0;
     $where['goods_id'] = $goods_id;
     $data = $this->_getPost();
     AdminGoodsM::update($data, $where);
     $url = url('admin', 'admingoods::detail', $goods_id);
     header('Location:' . $url);
     throw new Exception('exit');
 }
Esempio n. 2
0
 public static function plusStock($uid = null, $order_id = null)
 {
     if (!$order_id || !$uid) {
         return false;
     }
     $order_id = (int) $order_id;
     //获取商品信息
     if ($uid) {
         $goods_list_info = OrderGoodsInfo::getUserOrderGoodsInfoByOrderId($uid, $order_id);
     } else {
         $goods_list_info = OrderGoodsInfo::getOrderGoodsInfoByOrderId($uid, $order_id);
     }
     foreach ($goods_list_info as $key => $value) {
         $goods_id = $value['goods_id'];
         $goods_num = $value['goods_num'];
         //获取库存
         $goods_info = AdminGoodsM::getGoodsInfoByGoodsId($goods_id);
         if ($goods_info['goods_num'] !== false) {
             $data['goods_num'] = $goods_info['goods_num'] + $goods_num;
             $where['goods_id'] = $goods_id;
             AdminGoodsM::update($data, $where);
         }
     }
     return true;
 }
Esempio n. 3
0
 public function goods()
 {
     for ($i = 1; $i < 10; $i++) {
         $data['goods_sn'] = 'test' . $i;
         $data['goods_name'] = '测试' . $i;
         $data['goods_price'] = 69;
         $data['goods_num'] = $i;
         AdminGoodsM::add($data);
     }
     echo 'ok';
 }
Esempio n. 4
0
 public static function addOrder($uid = 0, $username = '', $pay_name = '货到付款', $default_address_id = 0)
 {
     if ($uid) {
         //从购物车里获取到商品列表
         $cart_goods_list = Cart::select($uid);
         if ($cart_goods_list) {
             //计算订单总金额
             $order_total_data = self::getOrderTotal($cart_goods_list);
             $total = $order_total_data['total'];
             //运费
             $shipping_fee = self::getOrderShippingFee($total);
             //优惠
             $bonus = 0;
             //使用优惠券...
             //收货地址
             $address_info = UserAddress::getAddrByAddressId($uid, $default_address_id);
             if (!$address_info) {
                 $address_info = UserAddress::getDefaultAddress($uid);
             }
             $data['sn'] = self::createOrderSn();
             //订单号
             $data['uid'] = $uid;
             //用户id
             $data['username'] = $username;
             //用户名
             $data['order_status'] = 'yes';
             //订单有效
             $data['consignee'] = $address_info['consignee'];
             //联系人
             $data['province'] = $address_info['province'];
             //省
             $data['city'] = $address_info['city'];
             //市
             $data['district'] = $address_info['district'];
             //区
             $data['address'] = $address_info['address'];
             //详细地址
             $data['mobile'] = $address_info['mobile'];
             //手机或电话
             $data['shipping_fee'] = $shipping_fee;
             //运费
             $data['bonus'] = $bonus;
             //优惠
             $data['order_money'] = $total;
             //货物总金额
             $data['money_paid'] = $total + $shipping_fee + $bonus;
             //应付款金额
             $data['pay_name'] = $pay_name;
             //付款方式
             //非货到付款操作
             if ($pay_name !== '货到付款') {
                 $data['pay_time'] = time();
                 //支付时间
                 $data['confirm_status'] = 'yes';
                 //确认订单状态(非货到付款自动确认)
                 $data['confirm_time'] = time();
                 //确认订单时间
             }
             $rs = OrderInfo::addOrder($data);
             if ($rs) {
                 //下单成功,减少库存
                 AdminGoodsM::minusStock($cart_goods_list);
                 //添加到订单商品表
                 OrderGoodsInfo::addGoods($rs, $cart_goods_list);
                 //删除购物车里面的商品信息
                 $where = self::_where($uid);
                 Cart::delete($where);
             }
             //下单成功
             return $rs;
         }
     }
     //下单失败
     return false;
 }
Esempio n. 5
0
 public function editcartnum()
 {
     $cart_ids = $_POST['goods_number'];
     $uid = LuS::get('uid');
     if ($cart_ids) {
         //处理数据
         $cart_id = 0;
         foreach ($cart_ids as $key => $value) {
             $cart_id = $key;
             $goods_num = $value;
             //检查库存
             $goods_id = Cart::getGoodsIdByCartId($cart_id);
             if ($goods_id) {
                 //获取库存
                 $goods_info = AdminGoodsM::getGoodsInfoByGoodsId($goods_id);
                 if ($goods_info['goods_num'] >= $goods_num) {
                     $data['goods_num'] = $goods_num;
                     $where['cart_id'] = $cart_id;
                     Cart::update($data, $where);
                 } else {
                     $data['goods_num'] = $goods_info['goods_num'];
                     $where['cart_id'] = $cart_id;
                     Cart::update($data, $where);
                 }
             }
         }
         $return = array();
         //取出新数据
         $cart_goods_list = Cart::select($uid);
         $data = Cart::getOrderTotal($cart_goods_list);
         $total = $data['total'];
         $all_num = $data['num'];
         $shipping_fee = Cart::getOrderShippingFee($total);
         $money_paid = $total + $shipping_fee;
         foreach ($cart_goods_list as $k => $v) {
             if ($v['cart_id'] == $cart_id) {
                 $return[] = array($v['cart_id'], $v['goods_num'], $v['goods_price'], $total, $money_paid, $shipping_fee, $all_num);
                 break;
             }
         }
         echo json_encode($return);
     }
     throw new Exception('exit');
 }