<?php namespace Store\Lib; use Dever; class Order { # 单个商品下单 public function pay($shop_order_id, $shop, $store_id, $price, $num, $goods_id, $sku_id) { # 先更新库存 $state = $this->updateSell($store_id, $goods_id, $sku_id, $num); if (!$state) { return false; } $where['order_num'] = $shop_order_id; $where['shop_id'] = $shop['id']; $where['type'] = 1; $where['type_id'] = $store_id; $info = Dever::db('shop/buy_order')->find($where); if (!$info) { $data = $where; $data['name'] = $shop_order_id; $data['mobile'] = $shop['mobile']; $data['area'] = $shop['area']; $data['province'] = $shop['province']; $data['city'] = $shop['city']; $data['county'] = $shop['county']; $data['town'] = $shop['town']; $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['shop_id'] = $shop['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($store_id, $goods_id, $sku_id, $num) { $data['store_id'] = $store_id; $data['goods_id'] = $goods_id; $data['sku_id'] = $sku_id; $data['num'] = $num; return Dever::load('store/lib/goods')->oper(1, 2, array($data)); } }