Browse Source

Merge branch 'develop' of ssh://8.134.10.79:222/Leadfyy.co/hainan into develop

develop
lemon 4 years ago
parent
commit
6ee009fb65
  1. 24
      app/AdminAgent/Extensions/Grid/AuditRefund.php
  2. 12
      app/Http/Controllers/Api/OrderController.php
  3. 48
      app/Http/Controllers/Api/SharePayController.php
  4. 4
      app/Http/Controllers/Api/WxpayController.php

24
app/AdminAgent/Extensions/Grid/AuditRefund.php

@ -51,6 +51,7 @@ class AuditRefund extends RowAction
if (!$order) { if (!$order) {
return $this->response()->error("退款订单不存在或已处理过了")->refresh(); return $this->response()->error("退款订单不存在或已处理过了")->refresh();
} }
$order->verify_code = ''; //清空核销码
$order->status = OrderStatus::REFUNDED; $order->status = OrderStatus::REFUNDED;
$order->save(); $order->save();
@ -78,13 +79,28 @@ class AuditRefund extends RowAction
// 参数分别为:微信订单号、商户退款单号、订单金额、退款金额、其他参数 // 参数分别为:微信订单号、商户退款单号、订单金额、退款金额、其他参数
foreach ($log as $k=>$v) { foreach ($log as $k=>$v) {
$refund_no = $order->refund_info['refund_no'] . '-' . $v['id']; $refund_no = $order->refund_info['refund_no'] . '-' . $v['id'];
$app->refund->byTransactionId($v->transaction_id, $refund_no, $v->money, $v->money, $config);
}
$money = intval(0 - $v->money * 100);
$result = $app->refund->byTransactionId($v->transaction_id, $refund_no, $money, $money);
//退款回调之后再存入UserMoneyLog
//存入UserMoneyLog
if (isset($result['return_code'], $result['result_code']) && $result['return_code'] == 'SUCCESS' && $result['result_code'] == 'SUCCESS') {
UserMoneyLog::query()->insert([
'user_id' => $order->user_id,
'agent_id' => $order->agent_id,
'money' => $result['refund_fee'] / 100,
'order_id' => $order->id,
'type' => 2,
'desc' => DB::raw("LEFT('退款:{$order->title}', 250)"),
'transaction_id' => $result['transaction_id'],
'created_at' => now(), //模型没有updated_at,无法自动写入时间
]);
} else {
return $this->response()->error("操作失败,失败原因:" . ($result['return_msg']??'未知'))->refresh();
}
}
DB::commit(); DB::commit();
return $this->response()->success("操作成功,已向微信申请退款,款项将原路退还")->refresh();
return $this->response()->success("操作成功,款项将原路退还")->refresh();
} catch (\Exception $e) { } catch (\Exception $e) {
DB::rollBack(); DB::rollBack();
return $this->response()->error($e->getMessage()); return $this->response()->error($e->getMessage());

12
app/Http/Controllers/Api/OrderController.php

@ -366,7 +366,7 @@ class OrderController extends Controller
$result = $app->order->unify([ $result = $app->order->unify([
'body' => $order->title, 'body' => $order->title,
'out_trade_no' => $order->order_no . '-' . $order->status, //后面加status,主要是为了方便微信支付回调时区分定金(首付款)和尾款支付 'out_trade_no' => $order->order_no . '-' . $order->status, //后面加status,主要是为了方便微信支付回调时区分定金(首付款)和尾款支付
'total_fee' => 1, //TODO 测试暂时注释 round($price * 100), //支付金额单位为分
'total_fee' => round($price * 100), //支付金额单位为分
'notify_url' => route('wxpay_notify', ['agent_id' => $this->agent_id]), // 支付结果通知网址,如果不设置则会使用配置里的默认地址 'notify_url' => route('wxpay_notify', ['agent_id' => $this->agent_id]), // 支付结果通知网址,如果不设置则会使用配置里的默认地址
'trade_type' => 'JSAPI', 'trade_type' => 'JSAPI',
'openid' => $openid, 'openid' => $openid,
@ -432,19 +432,19 @@ class OrderController extends Controller
* 计算最终价格(扣除优惠券之后的价格) * 计算最终价格(扣除优惠券之后的价格)
* $price:原价;$coupon:优惠券;$num:产品数量;$pay_type:支付方式 * $price:原价;$coupon:优惠券;$num:产品数量;$pay_type:支付方式
* @param float $price * @param float $price
* @param int $num
* @param float $num
* @param int $pay_type * @param int $pay_type
* @param Model $agent_product
* @param AgentProduct $agent_product
* @return float * @return float
*/ */
private function calc($price, $num, $pay_type, $agent_product)
private function calc(float $price, float $num, int $pay_type, AgentProduct $agent_product): float
{ {
/** 修改需要同步修改sharePay里面的 */
//根据支付方式计算价格 //根据支付方式计算价格
if (in_array($pay_type, [PayType::DEPOSIT_PAY, PayType::EARNEST_PAY, PayType::DOWN_PAYMENT])) { if (in_array($pay_type, [PayType::DEPOSIT_PAY, PayType::EARNEST_PAY, PayType::DOWN_PAYMENT])) {
if ($pay_type == PayType::DEPOSIT_PAY && $agent_product->deposit && $agent_product->deposit_timeout) { if ($pay_type == PayType::DEPOSIT_PAY && $agent_product->deposit && $agent_product->deposit_timeout) {
return $agent_product->deposit; return $agent_product->deposit;
}
if ($pay_type == PayType::EARNEST_PAY && $agent_product->earnest && $agent_product->earnest_timeout) {
} else if ($pay_type == PayType::EARNEST_PAY && $agent_product->earnest && $agent_product->earnest_timeout) {
return $agent_product->earnest; return $agent_product->earnest;
} }
} }

48
app/Http/Controllers/Api/SharePayController.php

@ -2,8 +2,10 @@
namespace App\Http\Controllers\Api; namespace App\Http\Controllers\Api;
use App\Common\OrderStatus as Status; use App\Common\OrderStatus as Status;
use App\Common\PayType;
use App\Http\Controllers\Controller; use App\Http\Controllers\Controller;
use App\Models\Agent; use App\Models\Agent;
use App\Models\AgentProduct;
use App\Models\Order; use App\Models\Order;
use App\Models\User; use App\Models\User;
use EasyWeChat\Factory; use EasyWeChat\Factory;
@ -36,14 +38,24 @@ class SharePayController extends Controller
$openid = $user_info['openid']; $openid = $user_info['openid'];
$this->agent_id = $user_info['agent_id']; $this->agent_id = $user_info['agent_id'];
$order = Order::query()->whereIn('status', [Status::UNPAID, Status::PAY_EARNEST])->find($order_id);
$order = Order::with(['agentProduct'])
->whereRaw('`timeout` >= NOW()')
->whereIn('status', [Status::UNPAID, Status::PAY_EARNEST])
->find($order_id);
if (!$order) { if (!$order) {
return $this->error('订单不存在或已支付');
return $this->error('订单已支付或已超时');
} }
$order->pay_user_id = $this->user_id; $order->pay_user_id = $this->user_id;
$order->save(); $order->save();
//如果已经付定金或首付款,则仅支付尾款
if ($order->status == Status::PAY_EARNEST) {
$price = $order->price - $order->paid_money;
} else {
$price = $this->calc($order->price, $order->num, $order->pay_type, $order->agent_product);
}
$config = config('wechat.payment.default'); $config = config('wechat.payment.default');
$config = array_merge($config, [ $config = array_merge($config, [
'app_id' => 'wxb35ef055a4dd8ad4', 'app_id' => 'wxb35ef055a4dd8ad4',
@ -56,7 +68,7 @@ class SharePayController extends Controller
$result = $app->order->unify([ $result = $app->order->unify([
'body' => $order->title, 'body' => $order->title,
'out_trade_no' => $order->order_no . '-' . $order->status, //后面加status,主要是为了方便微信支付回调时区分定金(首付款)和尾款支付 'out_trade_no' => $order->order_no . '-' . $order->status, //后面加status,主要是为了方便微信支付回调时区分定金(首付款)和尾款支付
'total_fee' => 1, //TODO 测试暂时注释 round($price * 100), //支付金额单位为分
'total_fee' => round($price * 100), //支付金额单位为分
'notify_url' => route('wxpay_notify', ['agent_id' => $this->agent_id]), // 支付结果通知网址,如果不设置则会使用配置里的默认地址 'notify_url' => route('wxpay_notify', ['agent_id' => $this->agent_id]), // 支付结果通知网址,如果不设置则会使用配置里的默认地址
'trade_type' => 'JSAPI', 'trade_type' => 'JSAPI',
'openid' => $openid, 'openid' => $openid,
@ -71,10 +83,36 @@ class SharePayController extends Controller
return $result; return $result;
} }
$jump_appid = Agent::where('id', $order->agent_id)->value('appid');
$jssdk = $app->jssdk; $jssdk = $app->jssdk;
$goback_appid = Agent::where('id', $order->agent_id)->value('appid');
$payConfig = $jssdk->bridgeConfig($result['prepay_id'], false) + $payConfig = $jssdk->bridgeConfig($result['prepay_id'], false) +
['id' => $order->id, 'order_no' => $order->order_no, 'jump_appid' => $goback_appid]; // 返回数组
['id' => $order->id, 'order_no' => $order->order_no, 'jump_appid' => $jump_appid]; // 返回数组
return $this->success($payConfig); return $this->success($payConfig);
} }
/**
* 计算最终价格
* @param float $price 订单价格
* @param float $num 购买数量
* @param int $pay_type 支付方式
* @param AgentProduct $agent_product 代理商产品
* @return float
*/
private function calc(float $price, float $num, int $pay_type, AgentProduct $agent_product): float
{
/** 修改需要同步修改Order里面的 */
//根据支付方式计算价格
if (in_array($pay_type, [PayType::DEPOSIT_PAY, PayType::EARNEST_PAY, PayType::DOWN_PAYMENT])) {
if ($pay_type == PayType::DEPOSIT_PAY && $agent_product->deposit && $agent_product->deposit_timeout) {
return $agent_product->deposit;
} else if ($pay_type == PayType::EARNEST_PAY && $agent_product->earnest && $agent_product->earnest_timeout) {
return $agent_product->earnest;
}
}
$total_price = $price * $num;
return round($total_price, 2);
}
} }

4
app/Http/Controllers/Api/WxpayController.php

@ -38,7 +38,7 @@ class WxpayController
// 请求成功 // 请求成功
if ($message['return_code'] === 'SUCCESS') { if ($message['return_code'] === 'SUCCESS') {
//主要是为了区分定金支付和尾款支付,订单号带有-status后缀,分割后前面才是真正的订单号 //主要是为了区分定金支付和尾款支付,订单号带有-status后缀,分割后前面才是真正的订单号
list($order_no, $status) = explode('-', $message['out_trade_no']);
$order_no = explode('-', $message['out_trade_no'])[0];
$order = Order::query() $order = Order::query()
->where(['order_no' => $order_no]) ->where(['order_no' => $order_no])
->first(); ->first();
@ -164,7 +164,7 @@ class WxpayController
// 请求成功 // 请求成功
if ($message['return_code'] === 'SUCCESS') { if ($message['return_code'] === 'SUCCESS') {
//主要是为了区分定金支付和尾款支付,订单号带有-status后缀,分割后前面才是真正的订单号 //主要是为了区分定金支付和尾款支付,订单号带有-status后缀,分割后前面才是真正的订单号
list($order_no, $status) = explode('-', $message['out_trade_no']);
$order_no = explode('-', $reqInfo['out_trade_no'])[0];
$order = Order::query() $order = Order::query()
->where(['order_no' => $order_no]) ->where(['order_no' => $order_no])
->first(); ->first();

Loading…
Cancel
Save