|
@@ -2,6 +2,7 @@
|
|
|
|
|
|
namespace App\Http\Controllers\Wap\Pay;
|
|
namespace App\Http\Controllers\Wap\Pay;
|
|
|
|
|
|
|
|
+use App\Modules\Book\Services\ChapterService;
|
|
use App\Modules\Subscribe\Services\SubstituteOrderService;
|
|
use App\Modules\Subscribe\Services\SubstituteOrderService;
|
|
use App\Modules\User\Services\ReadRecordService;
|
|
use App\Modules\User\Services\ReadRecordService;
|
|
use Illuminate\Routing\Controller;
|
|
use Illuminate\Routing\Controller;
|
|
@@ -24,7 +25,7 @@ use EasyWeChat\Support\XML;
|
|
use App\Modules\OfficialAccount\Services\ForceSubscribeService;
|
|
use App\Modules\OfficialAccount\Services\ForceSubscribeService;
|
|
use App\Jobs\SendTexts;
|
|
use App\Jobs\SendTexts;
|
|
use App\Jobs\SendStatisticsList;
|
|
use App\Jobs\SendStatisticsList;
|
|
-use App\Libs\SMS;
|
|
|
|
|
|
+use App\Libs\AliSMS;
|
|
use App\Modules\Activity\Services\ActivityService;
|
|
use App\Modules\Activity\Services\ActivityService;
|
|
use App\Modules\SendOrder\Services\SendOrderService;
|
|
use App\Modules\SendOrder\Services\SendOrderService;
|
|
use GuzzleHttp\Client;
|
|
use GuzzleHttp\Client;
|
|
@@ -131,8 +132,11 @@ class OrdersController extends Controller
|
|
return response()->error('WAP_PARAM_ERROR');
|
|
return response()->error('WAP_PARAM_ERROR');
|
|
}
|
|
}
|
|
//获取支付类型
|
|
//获取支付类型
|
|
- $pay_merchant = DB::table('pay_merchants')->select('appid', 'source', 'config_info')->where('id', $channel->pay_merchant_id)->where('is_enabled', 1)->first();
|
|
|
|
|
|
+ $pay_merchant = DB::table('pay_merchants')->select('id','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 || !$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++;
|
|
$n++;
|
|
if ($n >= 5) {
|
|
if ($n >= 5) {
|
|
@@ -353,6 +357,187 @@ class OrdersController extends Controller
|
|
return view('pay.order.index', compact('pay_info', 'referer', 'jsSdkSign', 'pay_order'));
|
|
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) {
|
|
|
|
+ if (isset($url_info['path']) && str_contains($url_info['path'], 'reader') && isset($path['cid']) && !empty($path['cid'])) {
|
|
|
|
+ $chapter_info = ChapterService::getChapterNameByIdNoCheck($path['cid']);
|
|
|
|
+ $path['cid'] = $chapter_info->prev_cid;
|
|
|
|
+ $url = sprintf('%s://%s/reader?%s', $url_info['scheme'], $url_info['host'], http_build_query($path));
|
|
|
|
+ }
|
|
|
|
+ return redirect($url);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ return view('pay.order.wait', compact('order', 'url'));
|
|
|
|
+ }
|
|
|
|
+
|
|
private function isNewUserSecondCharge($charge_type,$product_id,$uid){
|
|
private function isNewUserSecondCharge($charge_type,$product_id,$uid){
|
|
//Log::info('新用户只能冲一次:' .$charge_type);
|
|
//Log::info('新用户只能冲一次:' .$charge_type);
|
|
if($charge_type == 'NEW_USER'){
|
|
if($charge_type == 'NEW_USER'){
|
|
@@ -1160,7 +1345,7 @@ class OrdersController extends Controller
|
|
protected function successPayPushMsg($uid, $product_info, $order_id)
|
|
protected function successPayPushMsg($uid, $product_info, $order_id)
|
|
{
|
|
{
|
|
try {
|
|
try {
|
|
- $force_sub_info = $this->getSubscribe($uid);
|
|
|
|
|
|
+ $force_sub_info = $this->getSubscribeV2($uid);
|
|
$data = UserService::getById($uid);
|
|
$data = UserService::getById($uid);
|
|
if (!in_array($data->distribution_channel_id, [5, 123])) {
|
|
if (!in_array($data->distribution_channel_id, [5, 123])) {
|
|
//return false;
|
|
//return false;
|
|
@@ -1186,22 +1371,25 @@ class OrdersController extends Controller
|
|
$delay = 0;
|
|
$delay = 0;
|
|
$url = env('PROTOCOL') . '://site' . encodeDistributionChannelId($data->distribution_channel_id) . '.' . env('CUSTOM_HOST') . '.com/continue';;
|
|
$url = env('PROTOCOL') . '://site' . encodeDistributionChannelId($data->distribution_channel_id) . '.' . env('CUSTOM_HOST') . '.com/continue';;
|
|
$content = sprintf($content_format, $data->nickname ? $data->nickname : '匿名', $uid, $money_text, $url);
|
|
$content = sprintf($content_format, $data->nickname ? $data->nickname : '匿名', $uid, $money_text, $url);
|
|
- $res['openid'] = $force_sub_info->openid;
|
|
|
|
- $res['appid'] = $force_sub_info->appid;
|
|
|
|
- $res['content'] = $content;
|
|
|
|
- $res['type'] = 'one_task';
|
|
|
|
- $res['send_time'] = date("Y-m-d H:i:s");
|
|
|
|
- $res['task_id'] = md5('pay_success_push');
|
|
|
|
- $send_data = array(
|
|
|
|
- 'send_time' => date("Y-m-d H:i:s"),
|
|
|
|
- 'data' => $res
|
|
|
|
- );
|
|
|
|
- dispatch((new SendTexts($send_data))->onConnection('rabbitmq')->delay($delay)->onQueue('send_texts_list'));
|
|
|
|
|
|
+ foreach ($force_sub_info as $item){
|
|
|
|
+ $res['openid'] = $item->openid;
|
|
|
|
+ $res['appid'] = $item->appid;
|
|
|
|
+ $res['content'] = $content;
|
|
|
|
+ $res['type'] = 'one_task';
|
|
|
|
+ $res['send_time'] = date("Y-m-d H:i:s");
|
|
|
|
+ $res['task_id'] = md5('pay_success_push');
|
|
|
|
+ $send_data = array(
|
|
|
|
+ 'send_time' => date("Y-m-d H:i:s"),
|
|
|
|
+ 'data' => $res
|
|
|
|
+ );
|
|
|
|
+
|
|
|
|
+ dispatch((new SendTexts($send_data))->onConnection('rabbitmq')->delay($delay)->onQueue('send_texts_list'));
|
|
|
|
+ }
|
|
}
|
|
}
|
|
} catch (\Exception $e) {
|
|
} catch (\Exception $e) {
|
|
-
|
|
|
|
|
|
+ Log::info('pay_success_push error');
|
|
|
|
+ Log::info($e);
|
|
}
|
|
}
|
|
-
|
|
|
|
return true;
|
|
return true;
|
|
}
|
|
}
|
|
|
|
|
|
@@ -1248,6 +1436,11 @@ class OrdersController extends Controller
|
|
return ForceSubscribeService::forceSubscribeUsersByUid(['uid' => $uid]);
|
|
return ForceSubscribeService::forceSubscribeUsersByUid(['uid' => $uid]);
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ private function getSubscribeV2($uid)
|
|
|
|
+ {
|
|
|
|
+ return DB::table('force_subscribe_users')->where('uid',$uid)->where('is_subscribed', 1)->get();
|
|
|
|
+ }
|
|
|
|
+
|
|
public function getSubscribeOfficialName($uid)
|
|
public function getSubscribeOfficialName($uid)
|
|
{
|
|
{
|
|
$subscribe = $this->getSubscribe($uid);
|
|
$subscribe = $this->getSubscribe($uid);
|
|
@@ -1267,7 +1460,7 @@ class OrdersController extends Controller
|
|
//$change_pay_id = 12;
|
|
//$change_pay_id = 12;
|
|
}
|
|
}
|
|
try {
|
|
try {
|
|
- $time = (int)date('H');
|
|
|
|
|
|
+ $time = (int)date('G');
|
|
$change = false;
|
|
$change = false;
|
|
if ($time <= 8 || $time >= 23) {
|
|
if ($time <= 8 || $time >= 23) {
|
|
if (!$pay_info && $pay_merchant_id != $change_pay_id) {
|
|
if (!$pay_info && $pay_merchant_id != $change_pay_id) {
|
|
@@ -1275,20 +1468,26 @@ class OrdersController extends Controller
|
|
$change = true;
|
|
$change = true;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
+ //$number,$template_type,$param=array()
|
|
$phone_arr = ['15868100210', '18072713392', '15088790066', '13858057394', '18668029091', '18668420256'];
|
|
$phone_arr = ['15868100210', '18072713392', '15088790066', '13858057394', '18668029091', '18668420256'];
|
|
//$phone_arr = ['18668029091'];
|
|
//$phone_arr = ['18668029091'];
|
|
|
|
+
|
|
|
|
+ $param = ['pay_id'=>$pay_merchant_id];
|
|
if ($n) {
|
|
if ($n) {
|
|
- $content = '支付通道:' . $pay_merchant_id . ',获取授权信息失败';
|
|
|
|
|
|
+ $template_type = 'pay_channel_remind';
|
|
|
|
+ //$content = '支付通道:' . $pay_merchant_id . ',获取授权信息失败';
|
|
} else {
|
|
} else {
|
|
- $content = '支付通道:' . $pay_merchant_id . ',订单号为' . $trade_no . '支付异常,异常信息:' . json_encode($pay_info);
|
|
|
|
|
|
+ $template_type = 'pay_channel_remind';
|
|
|
|
+ //$content = '支付通道:' . $pay_merchant_id . ',订单号为' . $trade_no . '支付异常,异常信息:' . json_encode($pay_info);
|
|
}
|
|
}
|
|
if ($change) {
|
|
if ($change) {
|
|
- $content .= ',已经切换到支付通道:' . $change_pay_id;
|
|
|
|
|
|
+ $template_type = 'pay_channel_change';
|
|
|
|
+ $param = ['pay_id'=>$pay_merchant_id,'new_pay_id'=>$change_pay_id];
|
|
}
|
|
}
|
|
foreach ($phone_arr as $phone) {
|
|
foreach ($phone_arr as $phone) {
|
|
- SMS::send($phone, $content);
|
|
|
|
|
|
+ AliSMS::send($phone, $template_type,$param);
|
|
}
|
|
}
|
|
- file_put_contents(date('Y-m-d') . '.txt', json_encode($pay_info), FILE_APPEND);
|
|
|
|
|
|
+
|
|
} catch (\Exception $e) {
|
|
} catch (\Exception $e) {
|
|
|
|
|
|
}
|
|
}
|