...
|
...
|
@@ -87,6 +87,7 @@ class Order extends Api |
|
|
if (empty($provinceId)) $this->error('缺少参数 province_id!');
|
|
|
if (empty($cityId)) $this->error('缺少参数 city_id!');
|
|
|
if (empty($countyId)) $this->error('缺少参数 county_id!');
|
|
|
if (empty($postageType)) $this->error('缺少参数 postage_type!');
|
|
|
//判断优惠券和优惠码不能同时使用
|
|
|
if (!empty($ticketCode) && !empty($ticketId)) $this->error('优惠券与优惠码不能同时使用!');
|
|
|
//获取普通商品id
|
...
|
...
|
@@ -267,7 +268,7 @@ class Order extends Api |
|
|
if (!$validate->check($param)) {
|
|
|
$this->error($validate->getError());
|
|
|
}
|
|
|
|
|
|
if ($param['pay_type'] == 3 || $param['pay_type'] == 4) $this->error('员工或代理不能使用余额支付!');
|
|
|
//判断优惠券和优惠码不能同时使用
|
|
|
if (!empty($param['ticket_code']) && !empty($param['ticket_user_id'])) $this->error('优惠券与优惠码不能同时使用!');
|
|
|
//获取普通商品id
|
...
|
...
|
@@ -382,6 +383,7 @@ class Order extends Api |
|
|
'pay_total' => $data['price'],
|
|
|
'discount_price' => $data['discount_price'],
|
|
|
'score' => $data['integral'],
|
|
|
'present_id' => !empty($data['present_id']) ? $data['present_id'] : '',
|
|
|
'postage_total' => $postage,
|
|
|
'postage_type' => $param['postage_type'],
|
|
|
'postage_date' => $param['postage_date'],
|
...
|
...
|
@@ -429,15 +431,13 @@ class Order extends Api |
|
|
'createtime' => time(),
|
|
|
'updatetime' => time(),
|
|
|
];
|
|
|
$res3 = $this->orderAddressInvoiceModel->insertData($orderAddress);
|
|
|
$res3 = $this->orderAddressInvoiceModel->insertData($orderAddressInvoice);
|
|
|
}
|
|
|
$where = ['order_address_id' => $res2, 'id' => $res1];
|
|
|
if (!empty($res3)) $where['order_address_invoice_id'] = $res3;
|
|
|
|
|
|
$this->orderModel->update($where);
|
|
|
|
|
|
//获取商品详情列表
|
|
|
$list = $this->carModel->getCarMoney(['id' => ['in', $param['car_id']]]);
|
|
|
$orderInfoData = [];
|
|
|
$integral_total = 0;
|
|
|
foreach ($list as $k => $goodsItem) {
|
|
|
$goodsItem['user_type'] = $this->user['type'];
|
|
|
$orderInfoData[$k] = [
|
...
|
...
|
@@ -450,25 +450,17 @@ class Order extends Api |
|
|
'goods_image' => $goodsItem['image'],
|
|
|
'number' => $goodsItem['number'],
|
|
|
'type' => $goodsItem['type'],
|
|
|
'score' => !empty($goodsItem['integral']) ? $goodsItem['integral'] : '',
|
|
|
'score' => !empty($goodsItem['integral']) ? $goodsItem['integral'] : 0,
|
|
|
'goods_total' => get_price($goodsItem),
|
|
|
'pay_total' => $data['price'],
|
|
|
'postage_total' => $postage,
|
|
|
'status' => 1,
|
|
|
];
|
|
|
|
|
|
$integral_total += $orderInfoData[$k]['score'];
|
|
|
|
|
|
}
|
|
|
$res4 = $this->orderInfoModel->saveAll($orderInfoData);
|
|
|
|
|
|
//有积分商品减积分
|
|
|
if (!empty($goodsItem['integral'])) {
|
|
|
$userScoreLogModel = new UserScoreLog();
|
|
|
$res5 = $userScoreLogModel->setDecScore($userId, $goodsItem['integral']);
|
|
|
}
|
|
|
//减库存
|
|
|
|
|
|
if ($res1 && $res2 && $res4 && (empty($res3) || $res3) && (empty($res5) || $res5)) {
|
|
|
if ($res1 && $res2 && $res4 && (empty($res3) || $res3)) {
|
|
|
Db::commit();
|
|
|
return true;
|
|
|
} else {
|
...
|
...
|
@@ -480,6 +472,107 @@ class Order extends Api |
|
|
}
|
|
|
}
|
|
|
|
|
|
|
|
|
/**
|
|
|
* @ApiTitle (确认订单(团购商品))
|
|
|
* @ApiSummary (确认订单(团购商品))
|
|
|
* @ApiMethod (POST)
|
|
|
* @ApiHeaders (name=token, type=string, required=true description="请求的Token")
|
|
|
* @ApiParams (name=goods_id, type=string, required=true, description="商品id")
|
|
|
* @ApiParams (name=number, type=string, required=true, description="商品数量")
|
|
|
* @ApiParams (name=province_id, type=string, required=true, description="省id")
|
|
|
* @ApiParams (name=city_id, type=string, required=true, description="市")
|
|
|
* @ApiParams (name=county_id, type=string, required=true, description="县")
|
|
|
* @ApiParams (name=postage_type, type=string, required=true, description="配送类型:1=普通配送,2=闪送")
|
|
|
* @ApiRoute (/api/order/orderTeam)
|
|
|
* @ApiReturn({
|
|
|
"code": 1,
|
|
|
"msg": "success",
|
|
|
"time": "1587691008",
|
|
|
"data": {
|
|
|
"price": 263.7, 总价
|
|
|
"discount_price": 12.3, 折扣价
|
|
|
"original_price": 246, 原价
|
|
|
"integral": 0, 积分
|
|
|
"postage": "30.00" 运费
|
|
|
"is_lack_stock": "1" 收货地址没货
|
|
|
}
|
|
|
},
|
|
|
})
|
|
|
*/
|
|
|
public function orderTeam()
|
|
|
{
|
|
|
$goodsModel = new \app\api\model\Goods();
|
|
|
$userId = $this->getUserId();
|
|
|
$number = $this->request->param('number');
|
|
|
$goodsId = $this->request->param('goods_id');
|
|
|
$provinceId = $this->request->param('province_id');
|
|
|
$cityId = $this->request->param('city_id');
|
|
|
$countyId = $this->request->param('county_id');
|
|
|
$postageType = $this->request->param('postage_type');
|
|
|
if (empty($goodsId)) $this->error('缺少参数 goods_id!');
|
|
|
if (empty($number)) $this->error('缺少参数 number!');
|
|
|
if (empty($provinceId)) $this->error('缺少参数 province_id!');
|
|
|
if (empty($cityId)) $this->error('缺少参数 city_id!');
|
|
|
if (empty($countyId)) $this->error('缺少参数 county_id!');
|
|
|
if (empty($postageType)) $this->error('缺少参数 postage_type!');
|
|
|
|
|
|
$goodsInfo = $goodsModel->where(['id' => $goodsId])->field('id,status,stock_num')->find();
|
|
|
//判断商品是否有库存和状态
|
|
|
if ($goodsInfo['status'] == 2) $this->error('商品已下架');
|
|
|
if ($goodsInfo['stock_num'] == 0) $this->error('商品库存不足');
|
|
|
//判断用户收货区域是否有库存
|
|
|
$areaStock = $goodsModel->getAreaStockNum(['g.id' => $goodsId, 'd.area_id' => $provinceId]);
|
|
|
if (!$areaStock) $data['is_lack_stock'] = 1;
|
|
|
|
|
|
//获取原价,现价,折扣
|
|
|
$priceArr = $this->carModel->getCarMoney(['id' => ['in', $carId]]);
|
|
|
$data['price'] = 0; //折扣后价格
|
|
|
$data['discount_price'] = 0; //折扣金额
|
|
|
$data['original_price'] = 0; //原价
|
|
|
$data['integral'] = 0; //积分
|
|
|
foreach ($priceArr as $k => $v) {
|
|
|
$priceArr[$k]['user_type'] = $this->user['type'];
|
|
|
$data['price'] += round(get_price($v), 2);
|
|
|
$data['discount_price'] += round(get_discount_price($v), 2);
|
|
|
$data['original_price'] += $v['goods_price'];
|
|
|
if (!empty($v['integral'])) $data['integral'] += $v['integral'];
|
|
|
|
|
|
}
|
|
|
//获取运费
|
|
|
$is_special = $this->areaExtendModel->where(['province_id' => $provinceId])->value('is_special');
|
|
|
//特殊地区满200免运费
|
|
|
if ($is_special == 1 && $data['price'] >= 200) {
|
|
|
$postage = 0;
|
|
|
//其他地区满300免运费
|
|
|
} elseif ($data['price'] >= 300) {
|
|
|
$postage = 0;
|
|
|
} else {
|
|
|
//都不满足获取对应的运费
|
|
|
$postageWhere = ['province_id' => $provinceId, 'city_id' => $cityId, 'county_id' => $countyId];
|
|
|
if ($postageType == 2) {
|
|
|
//配送为闪送
|
|
|
$postage = $this->areaExtendModel->where($postageWhere)->value('postage2');
|
|
|
if (!$postage) {
|
|
|
$postage = $this->areaExtendModel->where(['province_id' => $provinceId])->value('postage2');
|
|
|
}
|
|
|
} else {
|
|
|
//配送为普通配送
|
|
|
$postage = $this->areaExtendModel->where($postageWhere)->value('postage1');
|
|
|
if (!$postage) {
|
|
|
$postage = $this->areaExtendModel->where(['province_id' => $provinceId])->value('postage1');
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
$data['postage'] = $postage;
|
|
|
$data['price'] += $postage;
|
|
|
|
|
|
|
|
|
$this->success('success', $data);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
/**
|
|
|
* @ApiTitle (订单付款)
|
|
|
* @ApiSummary (订单付款)
|
...
|
...
|
@@ -492,6 +585,7 @@ class Order extends Api |
|
|
*/
|
|
|
public function orderPay()
|
|
|
{
|
|
|
$userId = $this->getUserId();
|
|
|
$param = $this->request->param();
|
|
|
$rule = [
|
|
|
'order_id' => 'require',
|
...
|
...
|
@@ -506,15 +600,32 @@ class Order extends Api |
|
|
if (!$result) {
|
|
|
$this->error(__($validate->getError()));
|
|
|
}
|
|
|
|
|
|
$order = $this->orderModel->where(['id' => $param['order_id']])->find();
|
|
|
if ($order['status'] == 2) $this->error('订单已支付');
|
|
|
if ($order['status'] == -1) $this->error('订单已取消');
|
|
|
//判断积分
|
|
|
if ($order['score'] > $this->user['score']) $this->error('积分不足');
|
|
|
//获取订单商品id,库存
|
|
|
$goodsList = $this->orderInfoModel->where('order_id', $order['id'])->field('goods_id,number,ch_goods_name,type,score')->select();
|
|
|
foreach ($goodsList as $k => $v) {
|
|
|
if ($v['type'] == 2) {
|
|
|
//判断积分商品是否有库存
|
|
|
$is_stock = $this->integralGoodsModel->checkStockNum($v['goods_id'], $v['number']);
|
|
|
if (!$is_stock) $this->error($v['ch_goods_name'] . ' 库存不足');
|
|
|
} else {
|
|
|
//判断商品是否有库存
|
|
|
$is_stock = $this->goodsModel->checkStockNum($v['goods_id'], $v['number']);
|
|
|
if (!$is_stock) $this->error($v['ch_goods_name'] . ' 库存不足');
|
|
|
}
|
|
|
}
|
|
|
$amount = $order['pay_total'];
|
|
|
$payType = $order['pay_type'];
|
|
|
if ($payType == 2) {
|
|
|
//余额支付
|
|
|
if ($this->user['money'] >= $amount) {
|
|
|
$res = $this->orderModel->balancePay($param['order_id'], $this->auth->id, $amount);
|
|
|
if ($res) $this->success('支付成功');
|
|
|
$res = $this->orderModel->balancePay($param['order_id'], $userId, $amount, $goodsList);
|
|
|
if ($res && empty($res['code'])) $this->success('支付成功');
|
|
|
elseif (!empty($res['code'])) $this->error($res['msg']);
|
|
|
else $this->error('支付失败');
|
|
|
} else {
|
|
|
$this->error('余额不足');
|
...
|
...
|
|