|
@@ -133,6 +133,9 @@ class OrdersController extends Controller
|
|
|
//获取支付类型
|
|
|
$pay_merchant = DB::table('pay_merchants')->select('appid', 'source', 'config_info')->where('id', $channel->pay_merchant_id)->where('is_enabled', 1)->first();
|
|
|
if (!$pay_merchant || !$pay_merchant->appid || !$pay_merchant->source) return response()->error('WAP_PARAM_ERROR');
|
|
|
+ if($pay_merchant->source == 'PALMPAYV2'){
|
|
|
+ return redirect()->to($this->paympay($request,$pay_merchant));
|
|
|
+ }
|
|
|
//重定向 获取用户信息的次数
|
|
|
$n++;
|
|
|
if ($n >= 5) {
|
|
@@ -353,6 +356,182 @@ class OrdersController extends Controller
|
|
|
return view('pay.order.index', compact('pay_info', 'referer', 'jsSdkSign', 'pay_order'));
|
|
|
}
|
|
|
|
|
|
+
|
|
|
+ private function paympay(Request $request,$pay_merchant){
|
|
|
+ $product_id = $request->get('product_id');
|
|
|
+ $uid = $request->get('uid');
|
|
|
+ $distribution_channel_id = $request->get('distribution_channel_id');
|
|
|
+ $pay_redirect_url = $request->get('pay_redirect_url');
|
|
|
+ $send_order_id = $request->get('send_order_id',0) ;
|
|
|
+ $activity_id = $request->get('activity_id',0) ;
|
|
|
+ $suid= $request->get('suid',0);
|
|
|
+ $bid = $request->has('bid') ? $request->get('bid') : 0;
|
|
|
+ $hash_bid = $bid;
|
|
|
+ $fromtype = $request->has('fromtype') ? $request->get('fromtype') : $request->get('from','main');
|
|
|
+
|
|
|
+ //根据分校id获取支付配置id
|
|
|
+ Log::info($request->all());
|
|
|
+
|
|
|
+ $trade_no =$trade_no = date("YmdHis") . hexdec(uniqid());;
|
|
|
+ $order_info = OrderService::getByTradeNo($trade_no);
|
|
|
+ if ($order_info) return response()->error('WAP_SYS_ERROR');
|
|
|
+
|
|
|
+ $cid = $request->has('cid') ? $request->get('cid') : '';
|
|
|
+ $product_info = ProductService::getProductSingle($product_id,false);
|
|
|
+ //新用户只能冲一次
|
|
|
+ //Log::info('新用户只能冲一次:' .$product_info->type);
|
|
|
+ if($this->isNewUserSecondCharge($product_info->type,$product_id,$uid)){
|
|
|
+ $url = env('PROTOCOL', 'https') . '://site' . encodeDistributionChannelId($distribution_channel_id) . '.' . env('CUSTOM_HOST', 'leyuee') . '.com/pay';
|
|
|
+ return redirect()->to($url);
|
|
|
+ }
|
|
|
+ $price = $product_info->price * 100;
|
|
|
+ if ($uid < 32) {
|
|
|
+ $price = 1;
|
|
|
+ }
|
|
|
+ if (!$send_order_id) {
|
|
|
+ try {
|
|
|
+ $send_order_id = (int)Redis::hget('book_read:' . $uid, 'send_order_id');
|
|
|
+ } catch (\Exception $e) {}
|
|
|
+ }
|
|
|
+ $this->updateUserSendOrderId($uid,$send_order_id);
|
|
|
+ if (in_array($uid, explode(',', env('TEST_UID')))) {
|
|
|
+ $price = 1;
|
|
|
+ }
|
|
|
+
|
|
|
+ try {
|
|
|
+ $key = 'leyuee:to_send_not_pay_uid:distribution_channel_id:' . $distribution_channel_id;
|
|
|
+ Redis::hset($key, $uid, time());
|
|
|
+ $date = date('Y-m-d');
|
|
|
+ Redis::hincrby('order_stat:' . $distribution_channel_id, 'order_num_' . $date, 1);
|
|
|
+ if ($send_order_id) {
|
|
|
+ Redis::hincrby('order_promotion_stat:' . $send_order_id, 'order_num_' . $date, 1);
|
|
|
+ Redis::hincrby('order_promotion_stat:' . $send_order_id, 'total', 1);
|
|
|
+ }
|
|
|
+ } catch (\Exception $e) {
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ $data = [];
|
|
|
+
|
|
|
+ $data['price'] = $price;
|
|
|
+ $data['create_ip'] = $request->getClientIp();
|
|
|
+ $data['body'] = 'novel read';
|
|
|
+ $official_name = $this->getSubscribeOfficialName($uid);
|
|
|
+ if ($official_name) {
|
|
|
+ $data['body'] = '搜索公众号' . $official_name . ',请继续阅读';
|
|
|
+ }
|
|
|
+ $data['detail'] = 'novel read';
|
|
|
+ $data['trade_no'] = $trade_no;
|
|
|
+
|
|
|
+ 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';
|
|
|
+ } elseif($product_info->type == 'NEW_USER'){
|
|
|
+ $order_type = 'RECHARGE';
|
|
|
+ }else{
|
|
|
+ $order_type = 'UNKNOWN';
|
|
|
+ }
|
|
|
+
|
|
|
+ $send_order_name = '';
|
|
|
+ if ($send_order_id) {
|
|
|
+ $send_order_info = SendOrderService::getById($send_order_id);
|
|
|
+ if ($send_order_info && isset($send_order_info->name) && !empty($send_order_info->name)) {
|
|
|
+ $send_order_name = $send_order_info->name;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if($suid){
|
|
|
+ $user_info = UserService::getById($uid);
|
|
|
+ $distribution_channel_id = $user_info->distribution_channel_id;
|
|
|
+ }
|
|
|
+ $from_bid = ReadRecordService::getSimpleFirstReadRecord($uid);
|
|
|
+ $inner_send_order_id = ReadRecordService::getInnerSendOrderId($uid);
|
|
|
+ $init_order = [
|
|
|
+ 'distribution_channel_id' => $distribution_channel_id,
|
|
|
+ 'uid' => $uid,
|
|
|
+ 'product_id' => $product_id,
|
|
|
+ 'price' => $price / 100,
|
|
|
+ 'pay_type' => 1,
|
|
|
+ 'trade_no' => $data['trade_no'],
|
|
|
+ 'pay_merchant_source' => 'PALMPAY',
|
|
|
+ 'pay_merchant_id' => $pay_merchant->id,
|
|
|
+ 'create_ip' => $request->getClientIp(),
|
|
|
+ 'send_order_id' => $send_order_id,
|
|
|
+ 'send_order_name' => $send_order_name,
|
|
|
+ 'order_type' => $order_type,
|
|
|
+ 'from_bid' => $from_bid,
|
|
|
+ 'from_type' => $fromtype,
|
|
|
+ 'activity_id' => $activity_id,
|
|
|
+ 'inner_send_order_id'=>$inner_send_order_id
|
|
|
+ ];
|
|
|
+ $result = $this->createUnPayOrder($init_order);
|
|
|
+
|
|
|
+ //订单创建成功后增加统计
|
|
|
+ if($result)
|
|
|
+ {
|
|
|
+ $this->orderCreated($init_order);
|
|
|
+ }
|
|
|
+ if ($suid) {
|
|
|
+ $this->createSubstituteOrder($result->id, $uid, $suid);
|
|
|
+ }
|
|
|
+
|
|
|
+ if ($suid) {
|
|
|
+ $prize_fee = (int)(($product_info->price*100)*0.1);
|
|
|
+ //$help_pay_page_channel_id = env('HELP_PAY_PAGE_CHANNEL_ID', 123);
|
|
|
+ $help_pay_page_channel_id = $distribution_channel_id;
|
|
|
+ $url_format = '%s://site%s.%s.com/helppay?back=%s&su=%s';
|
|
|
+ $pay_redirect_url = sprintf(
|
|
|
+ $url_format,
|
|
|
+ env('PROTOCOL'),
|
|
|
+ encodeDistributionChannelId($help_pay_page_channel_id),
|
|
|
+ env('CUSTOM_HOST'),
|
|
|
+ $prize_fee,
|
|
|
+ $uid
|
|
|
+ );
|
|
|
+ }
|
|
|
+ $de_pay_redirect_url = urldecode($pay_redirect_url);
|
|
|
+ /*if ($request->has('cid')) {
|
|
|
+ $de_pay_redirect_url = $de_pay_redirect_url . '&cid=' . $request->get('cid');
|
|
|
+ }*/
|
|
|
+
|
|
|
+ $pay_url_info = parse_url($de_pay_redirect_url);
|
|
|
+ $data['pay_wait_url'] = $pay_url_info['scheme'] . '://' . $pay_url_info['host'] . '/pay/waitv2?order=' . $data['trade_no'] . '&redirect=' . urlencode($de_pay_redirect_url);
|
|
|
+ Log::info($data);
|
|
|
+
|
|
|
+ $config = [];
|
|
|
+ if ($pay_merchant->config_info) {
|
|
|
+ $config = json_decode($pay_merchant->config_info, true);
|
|
|
+ }
|
|
|
+ $wechatPay = WechatPay::instance($pay_merchant->source, $config);
|
|
|
+ \Log::info('$wechatPay is');
|
|
|
+ //\Log::info($wechatPay);
|
|
|
+ if (!$wechatPay) return response()->error('WAP_PARAM_ERROR');
|
|
|
+ \Log::info('$wechatPay ok-------------------');
|
|
|
+ $pay_info = $wechatPay->send($data);
|
|
|
+ \Log::info('send ok-------------------');
|
|
|
+ return $pay_info;
|
|
|
+ }
|
|
|
+
|
|
|
+ public function waitPageV2(Request $request)
|
|
|
+ {
|
|
|
+ $order = $request->get('order');
|
|
|
+ $order = (string)$order;
|
|
|
+ $url = urldecode($request->get('redirect'));
|
|
|
+ if(substr_count($url,'?') >1){
|
|
|
+ $url = str_replace_last('?','&',$url);
|
|
|
+ }
|
|
|
+ $url_info = parse_url($url);
|
|
|
+ if(isset($url_info['query']) && !empty($url_info['query']) ){
|
|
|
+ parse_str($url_info['query'],$path);
|
|
|
+ if(isset($path['success']) && $path['success'] == 0){
|
|
|
+ return redirect($url);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return view('pay.order.wait', compact('order', 'url'));
|
|
|
+ }
|
|
|
+
|
|
|
private function isNewUserSecondCharge($charge_type,$product_id,$uid){
|
|
|
//Log::info('新用户只能冲一次:' .$charge_type);
|
|
|
if($charge_type == 'NEW_USER'){
|