|
@@ -2,53 +2,18 @@
|
|
|
|
|
|
namespace App\Http\Controllers\Api\V1;
|
|
namespace App\Http\Controllers\Api\V1;
|
|
|
|
|
|
-use App\Http\HelperTraits\LogHelper;
|
|
|
|
-use App\Http\HelperTraits\PayHelper;
|
|
|
|
-use App\Http\HelperTraits\JpushHelper;
|
|
|
|
-use Omnipay\Omnipay;
|
|
|
|
-use App\User;
|
|
|
|
-use App\Models\MerchantMemberService;
|
|
|
|
-use App\Models\Order;
|
|
|
|
|
|
+use App\Helper\PayHelper;
|
|
|
|
+use App\UserInfoModel;
|
|
|
|
+use App\Models\OrderInfoModel;
|
|
use App\Models\AccountLog;
|
|
use App\Models\AccountLog;
|
|
-use Request, Config, DB;
|
|
|
|
|
|
+use App\Services\Base\ErrorCode;
|
|
|
|
+use Illuminate\Http\Request;
|
|
|
|
+use Config, Auth, DB ,Validator;
|
|
|
|
|
|
class PayController extends Controller
|
|
class PayController extends Controller
|
|
{
|
|
{
|
|
- use PayHelper, LogHelper,JpushHelper;
|
|
|
|
|
|
+ use PayHelper;
|
|
|
|
|
|
- /**
|
|
|
|
- * p++ webhooks通知
|
|
|
|
- */
|
|
|
|
-// public function pppNotify() {
|
|
|
|
-// $sig = Request::header('x-pingplusplus-signature');
|
|
|
|
-// $request = Request::instance();
|
|
|
|
-// $data = $request->getContent();
|
|
|
|
-//
|
|
|
|
-// if (!$this->checkPppSignature($data, $sig)) {//验签失败
|
|
|
|
-// header($_SERVER['SERVER_PROTOCOL'] . ' 400 Bad Request');
|
|
|
|
-// exit("fail");
|
|
|
|
-// }
|
|
|
|
-//
|
|
|
|
-// $event = json_decode($data);
|
|
|
|
-// if (!isset($event->type)) {
|
|
|
|
-//// return Response::make('fail', 400);
|
|
|
|
-// header($_SERVER['SERVER_PROTOCOL'] . ' 400 Bad Request');
|
|
|
|
-// exit("fail");
|
|
|
|
-// }
|
|
|
|
-// switch ($event->type) {
|
|
|
|
-// case "charge.succeeded":
|
|
|
|
-// // 开发者在此处加入对支付异步通知的处理代码
|
|
|
|
-// header($_SERVER['SERVER_PROTOCOL'] . ' 200 OK');
|
|
|
|
-// break;
|
|
|
|
-// case "refund.succeeded":
|
|
|
|
-// // 开发者在此处加入对退款异步通知的处理代码
|
|
|
|
-// header($_SERVER['SERVER_PROTOCOL'] . ' 200 OK');
|
|
|
|
-// break;
|
|
|
|
-// default:
|
|
|
|
-// header($_SERVER['SERVER_PROTOCOL'] . ' 400 Bad Request');
|
|
|
|
-// break;
|
|
|
|
-// }
|
|
|
|
-// }
|
|
|
|
|
|
|
|
public function alipayNotify() {
|
|
public function alipayNotify() {
|
|
$rawInfo = Request::all();
|
|
$rawInfo = Request::all();
|
|
@@ -99,7 +64,7 @@ class PayController extends Controller
|
|
$tp = 'Member';
|
|
$tp = 'Member';
|
|
//Not handled here
|
|
//Not handled here
|
|
}
|
|
}
|
|
- $u = User::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_type . ', ' . $order->user_id);
|
|
return 'success';
|
|
return 'success';
|
|
@@ -134,7 +99,6 @@ class PayController extends Controller
|
|
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 {
|
|
} else {
|
|
//续消费
|
|
//续消费
|
|
- $this->continue_consume($order);
|
|
|
|
|
|
|
|
$this->logAccount($tp, $u->id, $u->name,
|
|
$this->logAccount($tp, $u->id, $u->name,
|
|
AccountLog::OP_CC, $cType, $master_amount,
|
|
AccountLog::OP_CC, $cType, $master_amount,
|
|
@@ -211,7 +175,7 @@ class PayController extends Controller
|
|
$tp = 'Member';
|
|
$tp = 'Member';
|
|
//Not handled here
|
|
//Not handled here
|
|
}
|
|
}
|
|
- $u = User::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_type . ', ' . $order->user_id);
|
|
return 'success';
|
|
return 'success';
|
|
@@ -276,12 +240,6 @@ class PayController extends Controller
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
- function continue_consume($order){
|
|
|
|
-
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
-
|
|
|
|
-
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
* @api {post} /api/pay/charge 充值
|
|
* @api {post} /api/pay/charge 充值
|
|
@@ -289,7 +247,7 @@ class PayController extends Controller
|
|
* @apiGroup Merchant
|
|
* @apiGroup Merchant
|
|
* @apiPermission Passport
|
|
* @apiPermission Passport
|
|
* @apiVersion 0.1.0
|
|
* @apiVersion 0.1.0
|
|
- * @apiParam {int} [goods=1] 充值商品(1:余额,2:卡金)
|
|
|
|
|
|
+ * @apiParam {int} [goods=1] 充值商品(1:梦想币)
|
|
* @apiParam {int} number 充值数量,人民币,以分表示
|
|
* @apiParam {int} number 充值数量,人民币,以分表示
|
|
* @apiParam {int} type 支付类型(1:支付宝,2:微信支付)
|
|
* @apiParam {int} type 支付类型(1:支付宝,2:微信支付)
|
|
* @apiSuccessExample {json} Success-Response:
|
|
* @apiSuccessExample {json} Success-Response:
|
|
@@ -325,24 +283,23 @@ class PayController extends Controller
|
|
* }
|
|
* }
|
|
* 可能出现的错误代码:
|
|
* 可能出现的错误代码:
|
|
* 1000 CLIENT_WRONG_PARAMS 传入参数不正确
|
|
* 1000 CLIENT_WRONG_PARAMS 传入参数不正确
|
|
- * 1300 MERCHANT_NOT_EXIST 商户不存在
|
|
|
|
*/
|
|
*/
|
|
public function charge(Request $request)
|
|
public function charge(Request $request)
|
|
{
|
|
{
|
|
- $goodsTypes = Order::getAllGoodsTypes();
|
|
|
|
|
|
+ $goodsTypes = OrderInfoModel::getAllGoodsTypes();
|
|
$gTypes = array_keys($goodsTypes);
|
|
$gTypes = array_keys($goodsTypes);
|
|
- $payTypes = Order::getAllPayTypes();
|
|
|
|
|
|
+ $payTypes = OrderInfoModel::getAllPayTypes();
|
|
$pTypes = array_keys($payTypes);
|
|
$pTypes = array_keys($payTypes);
|
|
- $validator = Validator::make($data = $request->input(),
|
|
|
|
|
|
+ $validator = Validator::make($data = $request->all(),
|
|
[
|
|
[
|
|
'number' => 'required|integer|min:1',
|
|
'number' => 'required|integer|min:1',
|
|
'type' => 'required|in:' . join(',', $pTypes),
|
|
'type' => 'required|in:' . join(',', $pTypes),
|
|
'goods' => 'in:' . join(',', $gTypes),
|
|
'goods' => 'in:' . join(',', $gTypes),
|
|
],
|
|
],
|
|
[
|
|
[
|
|
- 'number.required' => '充值金额必填',
|
|
|
|
- 'number.integer' => '金额必须为整数',
|
|
|
|
- 'number.min' => '充值金额至少为1',
|
|
|
|
|
|
+ 'number.required' => '请输入梦想币数量',
|
|
|
|
+ 'number.integer' => '梦想币数量必须为整数',
|
|
|
|
+ 'number.min' => '充值梦想币数量至少为1',
|
|
'type.required' => '支付类型必填',
|
|
'type.required' => '支付类型必填',
|
|
'type.in' => '支付类型非法',
|
|
'type.in' => '支付类型非法',
|
|
'goods.in' => '充值商品非法',
|
|
'goods.in' => '充值商品非法',
|
|
@@ -354,19 +311,14 @@ class PayController extends Controller
|
|
}
|
|
}
|
|
|
|
|
|
$user = Auth::user();
|
|
$user = Auth::user();
|
|
- $merchant = Merchant::where('user_id', '=', $user->id)->first();//模型支持单用户多商户,业务只设计单商户
|
|
|
|
- if (!$merchant) {
|
|
|
|
- return $this->error(ErrorCode::MERCHANT_NOT_EXIST);
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
$data['goods_id'] = 0;
|
|
$data['goods_id'] = 0;
|
|
if (!isset($data['goods'])) {//默认充余额
|
|
if (!isset($data['goods'])) {//默认充余额
|
|
- $data['goods'] = Order::GOODS_TYPE_BALANCE;
|
|
|
|
|
|
+ $data['goods'] = OrderInfoModel::GOODS_TYPE_COIN;
|
|
}
|
|
}
|
|
|
|
|
|
- $data['user_type'] = Order::USER_TYPE_MERCHANT;
|
|
|
|
- $data['user_id'] = $user->id;//$merchant->id;
|
|
|
|
- if ($data['type'] == Order::PAY_TYPE_ALIPAY) {
|
|
|
|
|
|
+ $data['user_type'] = OrderInfoModel::USER_TYPE_USER;
|
|
|
|
+ $data['user_id'] = $user->id;
|
|
|
|
+ if ($data['type'] == OrderInfoModel::PAY_TYPE_ALIPAY) {
|
|
$result = $this->createAlipayCharge($data);
|
|
$result = $this->createAlipayCharge($data);
|
|
} else {
|
|
} else {
|
|
$result = $this->createWechatpayCharge($data);
|
|
$result = $this->createWechatpayCharge($data);
|