|
@@ -23,7 +23,9 @@ use App\Modules\Product\Services\ProductService;
|
|
use App\Modules\Book\Services\BookConfigService;
|
|
use App\Modules\Book\Services\BookConfigService;
|
|
use App\Modules\Book\Services\BookService;
|
|
use App\Modules\Book\Services\BookService;
|
|
use App\Modules\Channel\Services\PayTemplateService;
|
|
use App\Modules\Channel\Services\PayTemplateService;
|
|
|
|
+use App\Modules\Trade\Pay\OrderArousePayFactory;
|
|
use App\Modules\Trade\Pay\OrderPaySuccess;
|
|
use App\Modules\Trade\Pay\OrderPaySuccess;
|
|
|
|
+use Exception;
|
|
use Log;
|
|
use Log;
|
|
|
|
|
|
class OrdersController extends BaseController
|
|
class OrdersController extends BaseController
|
|
@@ -332,7 +334,6 @@ class OrdersController extends BaseController
|
|
return response()->pagination(new ChapterOrderTransformer(), $chapter_order);
|
|
return response()->pagination(new ChapterOrderTransformer(), $chapter_order);
|
|
}
|
|
}
|
|
|
|
|
|
-
|
|
|
|
/**
|
|
/**
|
|
* @apiVersion 1.0.0
|
|
* @apiVersion 1.0.0
|
|
* @apiDescription 充值记录
|
|
* @apiDescription 充值记录
|
|
@@ -395,6 +396,50 @@ class OrdersController extends BaseController
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
+ private function getPayParams(Request $request)
|
|
|
|
+ {
|
|
|
|
+ $product_id = $request->get('product_id', 0);
|
|
|
|
+ $send_order_id = $request->get('send_order_id', 0);
|
|
|
|
+ if (!$product_id) {
|
|
|
|
+ return false;
|
|
|
|
+ }
|
|
|
|
+ $bid = $request->get('bid', 0);
|
|
|
|
+ if ($bid) {
|
|
|
|
+ $from_bid = BookService::decodeBidStatic($bid);
|
|
|
|
+ }
|
|
|
|
+ $trade_no = date("YmdHis") . hexdec(uniqid());
|
|
|
|
+ $product_info = ProductService::getProductSingle($product_id);
|
|
|
|
+ $uid = $this->uid;
|
|
|
|
+ $distribution_channel_id = $this->distribution_channel_id;
|
|
|
|
+ $price = $product_info->price * 100;
|
|
|
|
+ if (in_array($uid, explode(',', env('TEST_UID')))) {
|
|
|
|
+ $price = 1;
|
|
|
|
+ }
|
|
|
|
+ $from_type = 'QuickApp';
|
|
|
|
+ if ($product_info->type == 'YEAR_ORDER') {
|
|
|
|
+ $order_type = 'YEAR';
|
|
|
|
+ } elseif ($product_info->type == 'BOOK_ORDER') {
|
|
|
|
+ $order_type = 'BOOK';
|
|
|
|
+ } elseif ($product_info->type == 'TICKET_RECHARGE') {
|
|
|
|
+ $order_type = 'RECHARGE';
|
|
|
|
+ } else {
|
|
|
|
+ $order_type = '';
|
|
|
|
+ }
|
|
|
|
+ $create_ip = _getIp();
|
|
|
|
+ return compact(
|
|
|
|
+ 'distribution_channel_id',
|
|
|
|
+ 'uid',
|
|
|
|
+ 'product_id',
|
|
|
|
+ 'price',
|
|
|
|
+ 'trade_no',
|
|
|
|
+ 'create_ip',
|
|
|
|
+ 'send_order_id',
|
|
|
|
+ 'from_bid',
|
|
|
|
+ 'from_type',
|
|
|
|
+ 'order_type'
|
|
|
|
+ );
|
|
|
|
+ }
|
|
|
|
+
|
|
/**
|
|
/**
|
|
* @apiVersion 1.0.0
|
|
* @apiVersion 1.0.0
|
|
* @apiDescription 支付
|
|
* @apiDescription 支付
|
|
@@ -425,78 +470,42 @@ class OrdersController extends BaseController
|
|
*/
|
|
*/
|
|
function wxindex(Request $request)
|
|
function wxindex(Request $request)
|
|
{
|
|
{
|
|
- $product_id = $request->get('product_id', 0);
|
|
|
|
- $send_order_id = $request->get('send_order_id', 0);
|
|
|
|
- if (!$product_id) {
|
|
|
|
|
|
+ if ($params = $this->getPayParams($request)) {
|
|
|
|
+ $params['pay_merchant_source'] = 'QuickAppWxPay';
|
|
|
|
+ } else {
|
|
return response()->error('QAPP_PARAM_ERROR');
|
|
return response()->error('QAPP_PARAM_ERROR');
|
|
}
|
|
}
|
|
- $bid = $request->get('bid', 0);
|
|
|
|
- if ($bid) {
|
|
|
|
- $bid = BookService::decodeBidStatic($bid);
|
|
|
|
- }
|
|
|
|
- $trade_no = date("YmdHis") . hexdec(uniqid());
|
|
|
|
- $product_info = ProductService::getProductSingle($product_id);
|
|
|
|
- $uid = $this->uid;
|
|
|
|
- $distribution_channel_id = $this->distribution_channel_id;
|
|
|
|
- $price = $product_info->price * 100;
|
|
|
|
- if (in_array($uid, explode(',', env('TEST_UID')))) {
|
|
|
|
- $price = 1;
|
|
|
|
- }
|
|
|
|
- if ($product_info->type == 'YEAR_ORDER') {
|
|
|
|
- $order_type = 'YEAR';
|
|
|
|
- } elseif ($product_info->type == 'BOOK_ORDER') {
|
|
|
|
- $order_type = 'BOOK';
|
|
|
|
- } elseif ($product_info->type == 'TICKET_RECHARGE') {
|
|
|
|
- $order_type = 'RECHARGE';
|
|
|
|
|
|
+ $app = OrderArousePayFactory::wxApp($this->uid);
|
|
|
|
+ $result = $app->handle($params);
|
|
|
|
+ if ($result) {
|
|
|
|
+ return response()->success($result);
|
|
} else {
|
|
} else {
|
|
- $order_type = '';
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- $this->createUnPayOrder([
|
|
|
|
- 'distribution_channel_id' => $distribution_channel_id,
|
|
|
|
- 'uid' => $uid,
|
|
|
|
- 'product_id' => $product_id,
|
|
|
|
- 'price' => $price / 100,
|
|
|
|
- 'pay_type' => 1,
|
|
|
|
- 'trade_no' => $trade_no,
|
|
|
|
- 'pay_merchant_source' => 'QuickApp',
|
|
|
|
- 'pay_merchant_id' => 0,
|
|
|
|
- 'create_ip' => $request->getClientIp(),
|
|
|
|
- 'send_order_id' => $send_order_id,
|
|
|
|
- 'order_type' => $order_type,
|
|
|
|
- 'from_bid' => $bid,
|
|
|
|
- 'from_type' => 'QuickApp',
|
|
|
|
- 'activity_id' => 0
|
|
|
|
- ]);
|
|
|
|
- $config = [
|
|
|
|
- // 微信支付参数
|
|
|
|
- 'appid' => 'wxf065f7364b078a73', // 应用ID
|
|
|
|
- 'merchant_id' => '1500977641', // 微信支付商户号
|
|
|
|
- 'key' => '0e7SfPt3EOS0HC1GxVa4fqmCUINcN71E', // 微信支付密钥
|
|
|
|
- 'trade_type' => 'APP',
|
|
|
|
- ];
|
|
|
|
- $pay = WechatPay::Official('OFFICIALPAY', $config);
|
|
|
|
- try {
|
|
|
|
- $payOrder = [
|
|
|
|
- 'trade_no' => $trade_no, // 订单号
|
|
|
|
- 'price' => $price, // 订单金额,**单位:分**
|
|
|
|
- 'body' => '快应用 小说', // 订单描述
|
|
|
|
- 'create_ip' => _getIp(), // 支付人的 IP
|
|
|
|
- 'remark' => 'QuickApp'
|
|
|
|
- ];
|
|
|
|
- $result = $pay->send($payOrder);
|
|
|
|
- if ($result) {
|
|
|
|
- return response()->success($result);
|
|
|
|
- } else {
|
|
|
|
- Log::error("创建微信订单失败," . json_encode($result));
|
|
|
|
- return response()->error('APP_CREATE_WECHAT_ORDER_FAIL');
|
|
|
|
- }
|
|
|
|
- } catch (Exception $e) {
|
|
|
|
- Log::error("创建微信订单失败," . $e->getMessage());
|
|
|
|
return response()->error('APP_CREATE_WECHAT_ORDER_FAIL');
|
|
return response()->error('APP_CREATE_WECHAT_ORDER_FAIL');
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ /**
|
|
|
|
+ * @apiVersion 1.0.0
|
|
|
|
+ * @apiDescription 支付宝支付
|
|
|
|
+ * @api {get} ali/goToPay 支付宝支付
|
|
|
|
+ * @apiGroup pay
|
|
|
|
+ * @apiName aliIndex
|
|
|
|
+ * @apiParam {Int} product_id product_id
|
|
|
|
+ * @apiParam {Int} send_order_id send_order_id
|
|
|
|
+ * @apiParam {String} bid bid
|
|
|
|
+ * @apiHeader {String} [Authorization] token
|
|
|
|
+ *
|
|
|
|
+ */
|
|
|
|
+ public function aliIndex(Request $request)
|
|
|
|
+ {
|
|
|
|
+ if ($params = $this->getPayParams($request)) {
|
|
|
|
+ $params['pay_merchant_source'] = 'QuickAppALiPay';
|
|
|
|
+ } else {
|
|
|
|
+ return response()->error('QAPP_PARAM_ERROR');
|
|
|
|
+ }
|
|
|
|
+ $app = OrderArousePayFactory::ali($this->uid);
|
|
|
|
+ return $app->handle($params);
|
|
|
|
+ }
|
|
|
|
|
|
/**
|
|
/**
|
|
* @apiVersion 1.0.0
|
|
* @apiVersion 1.0.0
|
|
@@ -596,6 +605,7 @@ class OrdersController extends BaseController
|
|
*/
|
|
*/
|
|
private function createUnPayOrder($data)
|
|
private function createUnPayOrder($data)
|
|
{
|
|
{
|
|
|
|
+ $data['price'] = $data['price'] / 100;
|
|
$data['status'] = 'UNPAID';
|
|
$data['status'] = 'UNPAID';
|
|
$data['transaction_id'] = '';
|
|
$data['transaction_id'] = '';
|
|
$data['pay_end_at'] = '0000-00-00 00:00:00';
|
|
$data['pay_end_at'] = '0000-00-00 00:00:00';
|