Commit c7eb7e2a authored by wuxiaoli's avatar wuxiaoli

聚物通支付api接口

parent c0685f23
......@@ -248,6 +248,9 @@ class OrderService {
$item->amount = $item->goods->price * $item->num;
$item->integral = $item->goods->integral * $item->num;
}
//使用聚物通资金不可用积分
$item->goods->integral = $item->integral = $request->input('pay_way')=="integral" ? $item->integral:0;
$orderGoods[] = new OrderItem([
'member_id' => auth('api')->user()['uid'],
'store_id' => $item->store_id,
......@@ -271,8 +274,17 @@ class OrderService {
$order->pay_type = $request->input('pay_type') ?? 'wechat';
$order->amount = $carts->sum('amount');
$order->integral = $carts->sum('integral');
$order->pay_way =$request->input('pay_way');
$order->status = 0;
if($request->input('pay_way') == "polymer_money"){
if(auth('api')->user()['polymer_money'] >= $order->amount){
$order->polymer_money = $order->amount;//聚物通
}else{
$order->polymer_money = auth('api')->user()['polymer_money'];
}
}
if($order->integral > auth('api')->user()['score']){
throw new \Exception("积分不足!", 0);
}
......@@ -299,6 +311,9 @@ class OrderService {
], [
'goods_id.required' => '请选择商品',
]);
$pay_way=$request->input('pay_way') ?? 'wechat';//付款方式
$order = new Order();
$goods = Goods::where('id', '=', $request->input('goods_id'))->first();
......@@ -333,6 +348,9 @@ class OrderService {
if(!$sku){
throw new \Exception("商品规格不存在!", 0);
}
//使用聚物通资金不可用积分
$sku->integral = $pay_way == "integral"?$sku->integral:0;
$orderGoods = new OrderItem([
'member_id' => auth('api')->user()['uid'],
'store_id' => $goods->store_id,
......@@ -350,6 +368,9 @@ class OrderService {
$amount = $sku->price;
$integral = $sku->integral;
}else{
//使用聚物通资金不可用积分
$goods->integral = $pay_way == "integral"?$goods->integral:0;
$orderGoods = new OrderItem([
'member_id' => auth('api')->user()['uid'],
'store_id' => $goods->store_id,
......@@ -374,9 +395,18 @@ class OrderService {
$order->pay_type = $request->input('pay_type') ?? 'wechat';
$order->delivery_type = $request->input('delivery_type') ?? 1;
$order->amount = $amount;
$order->integral = $integral;
$order->integral = $integral;//积分
$order->pay_way =$pay_way;
$order->status = 0;
if($pay_way == "polymer_money"){
if(auth('api')->user()['polymer_money'] >= $amount){
$order->polymer_money = $amount;//聚物通
}else{
$order->polymer_money = auth('api')->user()['polymer_money'];
}
}
if($order->integral > auth('api')->user()['score']){
throw new \Exception("积分不足!", 0);
}
......@@ -520,11 +550,15 @@ class OrderService {
$itemCount = $order->detail()->count();
// 订单详情商品处理
$order->detail()->with(['goods', 'sku'])->get()->each(function($item) use ($order, $itemCount) {
$order->detail()->with(['goods', 'sku'])->get()->each(function($item,$key) use ($order, $itemCount) {
// 积分商品积分扣除
if($item->total_integral > 0){
app(\Modules\Member\Services\ScoreService::class)->createScore(store_id: $item->store_id, order_id: $item->id, member_id: $order->member['uid'], type: 'pay', account_type: 'order', amount: $item->total_integral, remark: '订单支付');
}
// 聚物通扣除
if( $key== 0 && $order->polymer_money > 0){
app(\Modules\Member\Services\PolymerService::class)->createPolymer(store_id: $item->store_id, order_id: $item->id, member_id: $order->member['uid'], type: 'pay', account_type: 'order', amount: $order->polymer_money, remark: '订单支付');
}
if($item->goods->goods_type == 0){
$item->status = 3;
$item->save();
......
......@@ -42,7 +42,7 @@ class Payment extends BaseController {
'amount.required' => '请输入金额',
'integral.required' => '请输入积分',
]);
$this->data['data'] = $service->create(store_id: $request->input('store_id'), amount: $request->input('amount'), integral: $request->input('integral'), remark: $request->input('remark'));
$this->data['data'] = $service->create(store_id: $request->input('store_id'), amount: $request->input('amount'), integral: $request->input('integral'), polymer_money: $request->input('polymer_money'),pay_way: $request->input('pay_way'),remark: $request->input('remark'));
} catch (\Throwable $e) {
$this->data['code'] = 0;
$this->data['message'] = $e->getMessage();
......
......@@ -47,7 +47,7 @@ class PaymentService {
return $data;
}
public function create($store_id, $amount, $integral, $remark){
public function create($store_id, $amount, $integral, $polymer_money,$pay_way,$remark){
$payment = new Payment();
......@@ -56,16 +56,30 @@ class PaymentService {
$payment->member_id = auth('api')->user()->uid;
$payment->amount = $amount;
$payment->integral = $integral;
$payment->polymer_money = $polymer_money;
$payment->pay_way = $pay_way;
$payment->payment_remark = $remark ? $remark : '店铺收款';
$payment->payment_status = 0;
if(($amount + $integral +$polymer_money ) <=0){
throw new \Exception("请输入支付金额!", 0);
}
//判断积分是否满足
$member = auth('api')->user();
if($member['score'] < $integral){
if($pay_way == "integral" && $member['score'] < $integral){
throw new \Exception("积分不足!", 0);
}
if($pay_way == "polymer_money" && $member['polymer_money'] < $polymer_money){
throw new \Exception("聚物通不足!", 0);
}
$payment->save();
if($pay_way == "polymer_money" && $payment->amount == 0){//聚物通支付完成
app(PaymentService::class)->paySuccess($payment->order_no, null);
}
return $payment;
}
......@@ -98,6 +112,15 @@ class PaymentService {
$payment = Payment::where('order_no', $order_no)->first();
if($payment && $payment->status == 0){
if($payment->integral > 0){//扣除积分
app(\Modules\Member\Services\ScoreService::class)->createScore(store_id: $item->store_id, order_id: $item->id, member_id: $order->member['uid'], type: 'pay', account_type: 'order', amount: $item->total_integral, remark: '订单支付');
}
if($payment->polymer_money > 0){//扣除聚物通资金
app(\Modules\Member\Services\PolymerService::class)->createPolymer(store_id: $payment->store_id, order_id: $payment->id, member_id: $payment->member['uid'], type: 'pay', account_type: 'order', amount: $payment->polymer_money, remark: '店铺支付');
}
$res = app(\Modules\Wechat\Services\PayService::class)->orderQuery($order_no);
if(isset($res['trade_state']) && $res['trade_state'] == 'SUCCESS'){
$payment->payment_status = 1;
......
......@@ -30,7 +30,7 @@ class PayService {
case 'order':
$data = app('Modules\Order\Services\OrderService')->getjsPayData($request, $from);
$description = "订单支付";
$data->amount = $data->amount-$data->integral;
$data->amount = $data->amount - $data->integral - $data->polymer_money;
break;
case 'payment':
$data = app('Modules\Store\Services\PaymentService')->getjsPayData($request, $from);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment