diff --git a/app/Http/Controllers/Api/GoodController.php b/app/Http/Controllers/Api/GoodController.php index 81afa8d..2e64e68 100644 --- a/app/Http/Controllers/Api/GoodController.php +++ b/app/Http/Controllers/Api/GoodController.php @@ -190,9 +190,9 @@ public function getIndexGoods(Request $request) 'id' => $datum->id, 'goods_name' => $datum->goods_name, 'is_hot' => $datum->is_hot, - 'dg_price' => floor($dg_price), - 'market_price' => floor($market_price), - 'goods_price' => $mer_id ? floor($dg_price) : floor($market_price), + 'dg_price' => sprintf('%.1f', $dg_price), + 'market_price' => sprintf('%.1f', $market_price), + 'goods_price' => $mer_id ? sprintf('%.1f', $dg_price) : sprintf('%.1f', $market_price), 'tags' => $tags, 'cover_img' => togetherFilePath($datum->cover_img), ]; @@ -263,9 +263,9 @@ public function getDetail(Request $request) $data = [ 'id' => $goods->id, 'goods_img' => $cover, - 'dg_price' => floor($dg_price), - 'goods_price' => $mer_id ? floor($dg_price) : floor($market_price), - 'market_price' => floor($market_price), + 'dg_price' => sprintf('%.2f', $dg_price), + 'goods_price' => $mer_id ? sprintf('%.2f', $dg_price) : sprintf('%.2f', $market_price), + 'market_price' => sprintf('%.2f', $market_price), 'stock' => $stock, 'goods_name' => $goods->goods_name, 'sale' => $goods->sale ?? 0, diff --git a/app/Http/Controllers/Api/OrderController.php b/app/Http/Controllers/Api/OrderController.php index 709984e..f7f8851 100644 --- a/app/Http/Controllers/Api/OrderController.php +++ b/app/Http/Controllers/Api/OrderController.php @@ -298,7 +298,12 @@ public function pay(Request $request) try { $res = ''; $order = OrderInfoModel::find($order_id); - + if ($order->pay_cs > 0) { + $order_record = $order->order_record ?? $order->order_sn; + $order->order_sn = $this->getOrderSn(); + $order->order_record = $order_record . "|" . $order->order_sn; + $order->save(); + } $orderGoodsObj = OrderGoods::where("order_id", $order_id)->first(); $order_title = $orderGoodsObj ? $orderGoodsObj->goods_name : ''; $res = (new Adapay())->pay($order_title, $order->order_sn, $order->order_amount, $openid); @@ -309,7 +314,7 @@ public function pay(Request $request) return $this->JsonResponse($res); } catch (\Exception $exception) { Log::add('拉起微信支付失败', $exception->getMessage()); - return $this->JsonResponse('', '拉起微信支付失败', 201); + return $this->JsonResponse('', $exception->getMessage(), 500); } } diff --git a/app/Models/Adapay.php b/app/Models/Adapay.php index cf414b0..289cb9a 100644 --- a/app/Models/Adapay.php +++ b/app/Models/Adapay.php @@ -34,7 +34,7 @@ public function pay($order_title, $order_sn, $order_amount, $openid) "pay_channel" => "wx_lite", "pay_mode" => "delay", "time_expire" => date('YmdHis', time() + 300), - "pay_amt" => "0.01", + "pay_amt" => $order_amount, "goods_title" => $order_title, "goods_desc" => $order_title, "description" => "", @@ -156,6 +156,8 @@ public function payNotify($params = []) if ($freeze_stat != 'UNFREEZE') { return false; } + $orderObj->freeze_stat = 'UNFREEZE'; + $orderObj->save(); //交易记录 $prObj = PaymentRecord::where('order_sn', $order_no)->first(); # 支付确认参数设置 @@ -184,8 +186,8 @@ public function payNotify($params = []) Log::add('支付确认成功', $payment_confirm->result); $result = $payment_confirm->result; if ($result['status'] == 'succeeded') { - $orderObj->freeze_stat = 'UNFREEZE'; - $orderObj->save(); + DB::table('li_order_info')->where('order_sn', $order_no)->update(['div_status' => 1]); + Log::add('分账成功', ['order_sn' => $order_no]); } } diff --git a/app/Models/OrderDivideRecord.php b/app/Models/OrderDivideRecord.php index de4349b..35d322c 100644 --- a/app/Models/OrderDivideRecord.php +++ b/app/Models/OrderDivideRecord.php @@ -51,14 +51,14 @@ public static function divide($order_id) //直推佣金 if ($spuid && $first_commission >= 1 && $first_commission < 100) { $divide_price = number_format($goods_amount * ($first_commission / 100), 2); - //收益直接到直推账户 $spObj = User::find($spuid); - $spObj->total_revenue += $divide_price; //总余额记录 - //$spObj->balance += $divide_price; //自动分账打款 字段未使用 - $spObj->save(); - self::addRecord($item->id, $order_id, $goods_amount, $divide_price, $first_commission, $spuid, $user_id, 1); //汇付参数 if ($spObj->member_id) { + $spObj->total_revenue += $divide_price; //总余额记录 + //$spObj->balance += $divide_price; //自动分账打款 字段未使用 + $spObj->save(); + self::addRecord($item->id, $order_id, $goods_amount, $divide_price, $first_commission, $spuid, $user_id, 1); + $commissionPreData['first_member_id'] = $spObj->member_id; $commissionPreData['first_amount'] += $divide_price; } @@ -66,14 +66,14 @@ public static function divide($order_id) //间推佣金 if ($second_spuid && $second_commission >= 1 && $second_commission < 100) { $divide_price = number_format($goods_amount * ($second_commission / 100), 2); - //收益直接到直推账户 $spObj = User::find($second_spuid); - $spObj->total_revenue += $divide_price; - //$spObj->balance += $divide_price; - $spObj->save(); - self::addRecord($item->id, $order_id, $goods_amount, $divide_price, $second_commission, $second_spuid, $user_id, 2); //汇付参数 if ($spObj->member_id) { + $spObj->total_revenue += $divide_price; + //$spObj->balance += $divide_price; + $spObj->save(); + self::addRecord($item->id, $order_id, $goods_amount, $divide_price, $second_commission, $second_spuid, $user_id, 2); + $commissionPreData['second_member_id'] = $spObj->member_id; $commissionPreData['second_amount'] += $divide_price; } @@ -83,14 +83,15 @@ public static function divide($order_id) $divide_price = number_format($goods_amount * ($merchant_commission / 100), 2); //收益直接到商户账户 $merObj = Merchant::find($merchant_id); - $merObj->total_revenue += $divide_price; - //$merObj->balance += $divide_price; - $merObj->save(); - //记录 - self::addRecord($item->id, $order_id, $goods_amount, $divide_price, $merchant_commission, $merchant_id, $user_id, 3); //汇付参数 $member_id = HfCompanyMember::where('merchant_id', $merchant_id)->value('member_id'); if ($member_id) { + $merObj->total_revenue += $divide_price; + //$merObj->balance += $divide_price; + $merObj->save(); + //记录 + self::addRecord($item->id, $order_id, $goods_amount, $divide_price, $merchant_commission, $merchant_id, $user_id, 3); + $commissionPreData['merchant_member_id'] = $member_id; $commissionPreData['merchant_amount'] += $divide_price; } @@ -98,17 +99,17 @@ public static function divide($order_id) } //组合分账参数 if ($commissionPreData['first_member_id']) { - array_push($div_members, ['member_id' => $commissionPreData['first_member_id'], 'amount' => $commissionPreData['first_amount'], 'fee_flag' => 'Y']); + array_push($div_members, ['member_id' => $commissionPreData['first_member_id'], 'amount' => sprintf("%.2f", $commissionPreData['first_amount']), 'fee_flag' => 'Y']); } if ($commissionPreData['second_member_id']) { - array_push($div_members, ['member_id' => $commissionPreData['second_member_id'], 'amount' => $commissionPreData['second_amount'], 'fee_flag' => 'Y']); + array_push($div_members, ['member_id' => $commissionPreData['second_member_id'], 'amount' => sprintf("%.2f", $commissionPreData['second_amount']), 'fee_flag' => 'Y']); } if ($commissionPreData['merchant_member_id']) { - array_push($div_members, ['member_id' => $commissionPreData['merchant_member_id'], 'amount' => $commissionPreData['merchant_amount'], 'fee_flag' => 'Y']); + array_push($div_members, ['member_id' => $commissionPreData['merchant_member_id'], 'amount' => sprintf("%.2f", $commissionPreData['merchant_amount']), 'fee_flag' => 'Y']); } //商户本身 $aimeiyuePrice = $total_amount - $commissionPreData['first_amount'] - $commissionPreData['second_amount'] - $commissionPreData['merchant_amount']; - array_push($div_members, ['member_id' => 0, 'amount' => $aimeiyuePrice, 'fee_flag' => 'Y']); + array_push($div_members, ['member_id' => 0, 'amount' => sprintf("%.2f", $aimeiyuePrice), 'fee_flag' => 'Y']); return $div_members; }