|
@@ -2,8 +2,11 @@
|
|
|
|
|
|
namespace App\Http\Controllers\Api\V1;
|
|
namespace App\Http\Controllers\Api\V1;
|
|
|
|
|
|
|
|
+use Omnipay\Omnipay;
|
|
|
|
+use App\Helper\LogHelper;
|
|
use App\Helper\PayHelper;
|
|
use App\Helper\PayHelper;
|
|
-use App\UserInfoModel;
|
|
|
|
|
|
+use App\Helper\JpushHelper;
|
|
|
|
+use App\Models\UserInfoModel;
|
|
use App\Models\OrderInfoModel;
|
|
use App\Models\OrderInfoModel;
|
|
use App\Models\AccountLog;
|
|
use App\Models\AccountLog;
|
|
use App\Services\Base\ErrorCode;
|
|
use App\Services\Base\ErrorCode;
|
|
@@ -12,8 +15,7 @@ use Config, Auth, DB ,Validator;
|
|
|
|
|
|
class PayController extends Controller
|
|
class PayController extends Controller
|
|
{
|
|
{
|
|
- use PayHelper;
|
|
|
|
-
|
|
|
|
|
|
+ use PayHelper, LogHelper,JpushHelper;
|
|
|
|
|
|
public function alipayNotify() {
|
|
public function alipayNotify() {
|
|
$rawInfo = Request::all();
|
|
$rawInfo = Request::all();
|
|
@@ -93,17 +95,11 @@ class PayController extends Controller
|
|
|
|
|
|
//记日志
|
|
//记日志
|
|
$amount = $rawInfo['total_amount'] * 100;
|
|
$amount = $rawInfo['total_amount'] * 100;
|
|
- if (empty($extInfo)) {
|
|
|
|
- $this->logAccount($tp, $u->id, $u->name,
|
|
|
|
|
|
+
|
|
|
|
+ $this->logAccount($tp, $u->id, $u->name,
|
|
AccountLog::OP_CHARGE, $cType, $master_amount,
|
|
AccountLog::OP_CHARGE, $cType, $master_amount,
|
|
AccountLog::DIRECTION_INC, $cType == AccountLog::TYPE_BALANCE ? $u->balance : $u->credit, AccountLog::CHANNEL_ALIPAY);
|
|
AccountLog::DIRECTION_INC, $cType == AccountLog::TYPE_BALANCE ? $u->balance : $u->credit, AccountLog::CHANNEL_ALIPAY);
|
|
- } else {
|
|
|
|
- //续消费
|
|
|
|
|
|
|
|
- $this->logAccount($tp, $u->id, $u->name,
|
|
|
|
- AccountLog::OP_CC, $cType, $master_amount,
|
|
|
|
- AccountLog::DIRECTION_INC, $cType == AccountLog::TYPE_BALANCE ? $u->balance : $u->credit, AccountLog::CHANNEL_ALIPAY);
|
|
|
|
- }
|
|
|
|
\Log::info('支付完成');
|
|
\Log::info('支付完成');
|
|
|
|
|
|
} else {
|
|
} else {
|
|
@@ -111,7 +107,6 @@ class PayController extends Controller
|
|
\Log::error('保存数据失败');
|
|
\Log::error('保存数据失败');
|
|
}
|
|
}
|
|
|
|
|
|
-
|
|
|
|
DB::commit();
|
|
DB::commit();
|
|
|
|
|
|
return 'success';
|
|
return 'success';
|
|
@@ -151,70 +146,30 @@ class PayController extends Controller
|
|
\Log::info('支付成功');
|
|
\Log::info('支付成功');
|
|
|
|
|
|
$out_trade_no = $rawInfo['out_trade_no'];
|
|
$out_trade_no = $rawInfo['out_trade_no'];
|
|
- $order = Order::where('transaction_id', '=', $out_trade_no)->first();
|
|
|
|
|
|
+ $order = OrderInfoModel::where('transaction_id', '=', $out_trade_no)->first();
|
|
if (!$order) {
|
|
if (!$order) {
|
|
\Log::error('找不到订单' . $out_trade_no);
|
|
\Log::error('找不到订单' . $out_trade_no);
|
|
return 'fail';
|
|
return 'fail';
|
|
}
|
|
}
|
|
- $master_amount = $order->number;
|
|
|
|
- $slave_amount = 0;
|
|
|
|
- if (!empty($order->ext_info)) {
|
|
|
|
- $extInfo = json_decode($order->ext_info, true);
|
|
|
|
- if ($extInfo !== null) {
|
|
|
|
- $cc = $extInfo['cc_bonus'];
|
|
|
|
- $master_amount = round(($cc / 100) * $order->number);
|
|
|
|
- $slave_amount = $order->number - $master_amount;
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- $tp = '';
|
|
|
|
-// $u = null;
|
|
|
|
- if ($order->user_type == Order::USER_TYPE_MERCHANT) {
|
|
|
|
- $tp = 'Merchant';
|
|
|
|
-// $u = Merchant::find($order->user_id);
|
|
|
|
- } elseif ($order->user_type == Order::USER_TYPE_MEMBER) {
|
|
|
|
- $tp = 'Member';
|
|
|
|
- //Not handled here
|
|
|
|
- }
|
|
|
|
$u = UserInfoModel::find($order->user_id);
|
|
$u = UserInfoModel::find($order->user_id);
|
|
if (!$u) {
|
|
if (!$u) {
|
|
- \Log::error('用户不存在' . $order->user_type . ', ' . $order->user_id);
|
|
|
|
|
|
+ \Log::error('用户不存在' . $order->user_id . ', ' . $order->user_id);
|
|
return 'success';
|
|
return 'success';
|
|
}
|
|
}
|
|
|
|
|
|
DB::beginTransaction();
|
|
DB::beginTransaction();
|
|
-
|
|
|
|
- if ($order->goods_type == Order::GOODS_TYPE_BALANCE||$order->goods_type == Order::GOODS_TYPE_COSUME) {
|
|
|
|
- $cType = AccountLog::TYPE_BALANCE;
|
|
|
|
-// $u->account_balance += $order->number;
|
|
|
|
- $u->balance += $master_amount;
|
|
|
|
- } elseif ($order->goods_type == Order::GOODS_TYPE_CREDIT) {
|
|
|
|
- $cType = AccountLog::TYPE_CREDIT;
|
|
|
|
-// $u->credit_balance += $order->number;
|
|
|
|
- $u->credit += $master_amount;
|
|
|
|
- } else {
|
|
|
|
- \Log::error('商品不存在' . $order->goods_type);
|
|
|
|
- return 'success';
|
|
|
|
- }
|
|
|
|
- //测试
|
|
|
|
- \Log::info('支付金额 '.$master_amount);
|
|
|
|
|
|
+ $cType = AccountLog::TYPE_COIN;
|
|
|
|
+ $u->coin += $order->number;
|
|
if ($u->save()) {
|
|
if ($u->save()) {
|
|
|
|
|
|
//更新订单状态
|
|
//更新订单状态
|
|
- $order->status = Order::STATUS_FINISHED;
|
|
|
|
|
|
+ $order->status = OrderInfoModel::STATUS_FINISHED;
|
|
$order->save();
|
|
$order->save();
|
|
|
|
|
|
//记日志
|
|
//记日志
|
|
- $amount = $rawInfo['total_fee'] * 100;
|
|
|
|
- if (empty($extInfo)) {
|
|
|
|
- $this->logAccount($tp, $u->id, $u->name,
|
|
|
|
- AccountLog::OP_CHARGE, $cType, $master_amount,
|
|
|
|
- AccountLog::DIRECTION_INC, $cType == AccountLog::TYPE_BALANCE ? $u->balance : $u->credit, AccountLog::CHANNEL_WECHATPAY);
|
|
|
|
- } else {
|
|
|
|
-
|
|
|
|
- $this->logAccount($tp, $u->id, $u->name,
|
|
|
|
- AccountLog::OP_CC, $cType, $master_amount,
|
|
|
|
- AccountLog::DIRECTION_INC, $cType == AccountLog::TYPE_BALANCE ? $u->balance : $u->credit, AccountLog::CHANNEL_WECHATPAY);
|
|
|
|
- }
|
|
|
|
|
|
+// $this->logAccount($tp, $u->id, $u->name,
|
|
|
|
+// AccountLog::OP_CHARGE, $cType, $master_amount,
|
|
|
|
+// AccountLog::DIRECTION_INC, $cType == AccountLog::TYPE_BALANCE ? $u->balance : $u->credit, AccountLog::CHANNEL_WECHATPAY);
|
|
|
|
|
|
\Log::info('支付完成');
|
|
\Log::info('支付完成');
|
|
|
|
|
|
@@ -311,12 +266,10 @@ class PayController extends Controller
|
|
}
|
|
}
|
|
|
|
|
|
$user = Auth::user();
|
|
$user = Auth::user();
|
|
- $data['goods_id'] = 0;
|
|
|
|
|
|
+ $data['goods_id'] = 1;
|
|
if (!isset($data['goods'])) {//默认充余额
|
|
if (!isset($data['goods'])) {//默认充余额
|
|
$data['goods'] = OrderInfoModel::GOODS_TYPE_COIN;
|
|
$data['goods'] = OrderInfoModel::GOODS_TYPE_COIN;
|
|
}
|
|
}
|
|
-
|
|
|
|
- $data['user_type'] = OrderInfoModel::USER_TYPE_USER;
|
|
|
|
$data['user_id'] = $user->id;
|
|
$data['user_id'] = $user->id;
|
|
if ($data['type'] == OrderInfoModel::PAY_TYPE_ALIPAY) {
|
|
if ($data['type'] == OrderInfoModel::PAY_TYPE_ALIPAY) {
|
|
$result = $this->createAlipayCharge($data);
|
|
$result = $this->createAlipayCharge($data);
|