123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538 |
- <?php
- namespace App\Http\Controllers\Wap\Pay;
- use App\Modules\Trade\Pay\BookOrderPaySuccess;
- use App\Modules\Trade\Pay\ForeverOrderPaySuccess;
- use App\Modules\Trade\Pay\RechargeOrderPaySuccess;
- use App\Modules\Trade\Pay\YearOrderPaySuccess;
- use App\Modules\Book\Services\BookGiftsService;
- use App\Modules\Book\Services\ChapterService;
- use App\Modules\OfficialAccount\Services\OfficialAccountService;
- use App\Modules\Subscribe\Services\OrderParamService;
- use App\Modules\Subscribe\Services\OrderParamWsoService;
- use App\Modules\Subscribe\Services\SubstituteOrderService;
- use App\Modules\User\Services\ReadRecordService;
- use App\Modules\User\Services\UserBindPhoneService;
- use App\Modules\User\Services\UserDivisionCpcPropertyService;
- use App\Modules\User\Services\UserGiftService;
- use Illuminate\Routing\Controller;
- use App\Libs\Pay\WechatPay;
- use Illuminate\Http\Request;
- use App\Modules\Subscribe\Services\YearOrderService;
- use App\Modules\Subscribe\Services\BookOrderService;
- use App\Modules\Subscribe\Services\OrderService;
- use App\Modules\Product\Services\ProductService;
- use App\Modules\Book\Services\BookConfigService;
- use App\Modules\User\Services\UserService;
- use App\Modules\Channel\Services\ChannelService;
- use Log;
- use DB;
- use Cookie;
- use Redis;
- use Hashids;
- use EasyWeChat\Foundation\Application;
- use EasyWeChat\Support\XML;
- use App\Modules\OfficialAccount\Services\ForceSubscribeService;
- use App\Jobs\SendTexts;
- use App\Jobs\SendStatisticsList;
- use App\Libs\AliSMS;
- use App\Libs\Pay\Merchants\UnionPay;
- use App\Modules\Activity\Services\ActivityService;
- use App\Modules\SendOrder\Services\SendOrderService;
- use App\Modules\Subscribe\Models\Order;
- use App\Modules\Trade\Models\PayMerchant;
- use GuzzleHttp\Client;
- class OrdersController extends Controller
- {
- /**
- * @apiDefine pay 支付
- */
- /**
- * 支付唤起入口
- * 功能:授权、请求支付参数、并跳转微信支付
- * TODO 暂时不创建订单
- * tail -f /var/www/ydy_wap_backend/storage/logs/laravel-2017-12-01.log
- * zwap/goToPay?distribution_channel_id=3&price=1&uid=3
- * @apiVersion 1.0.0
- * @apiDescription 支付
- * @api {get} http://pay.aizhuishu.com/goToPay 支付
- * @apiGroup pay
- * @apiName wxindex
- * @apiParam {Int} product_id product_id
- * @apiParam {Int} uid uid
- * @apiParam {Int} distribution_channel_id distribution_channel_id
- * @apiParam {String} pay_redirect_url pay_redirect_url
- * @apiSuccess {int} code 状态码
- * @apiSuccessExample {json} Success-Response:
- * HTTP/1.1 200 OK
- * {
- * code: 0,
- * msg: "",
- * data: {
- * }
- */
- function wxindex(Request $request)
- {
- $product_id = $request->has('product_id') ? $request->get('product_id') : '';
- $uid = $request->has('uid') ? $request->get('uid') : '';
- $distribution_channel_id = $request->has('distribution_channel_id') ? $request->get('distribution_channel_id') : '';
- $p_channel_id = $request->has('p_channel_id') ? $request->get('p_channel_id') : 0;
- $pay_redirect_url = $request->has('pay_redirect_url') ? $request->get('pay_redirect_url') : '';
- $send_order_id = $request->has('send_order_id') ? $request->get('send_order_id') : 0;
- $activity_id = $request->has('activity_id') ? $request->get('activity_id') : 0;
- $ip = $request->has('ip') ? $request->get('ip') : '';
- $n = $request->has('n') ? $request->get('n') : 0;
- $crm = $request->has('crm') ? $request->get('crm') : 0;
- if ($send_order_id && strlen($send_order_id) > 50) {
- try {
- $send_order_id = decrypt($send_order_id);
- } catch (\Exception $e) {
- $send_order_id = 0;
- }
- }
- if ($send_order_id && strlen($send_order_id) > 50) {
- $send_order_id = 0;
- }
- //活动判断
- if ($activity_id) {
- $limit = $request->get('limit', 0);
- if ($limit && $limit == 1) {
- $order = OrderService::userIsParticipateActivity($uid, $activity_id);
- if ($order) {
- $activity = ActivityService::getById($activity_id);
- if ($activity) {
- $url = env('PROTOCOL', 'https') . '://site' . encodeDistributionChannelId($distribution_channel_id) . '.' . env('CUSTOM_HOST', 'leyuee') . '.com' . $activity->activity_page;
- return redirect()->to($url);
- }
- return '';
- }
- }
- }
- $suid = $request->get('suid', 0);
- if ($suid) {
- $user_info = UserService::getById($uid);
- $distribution_channel_id = $user_info->distribution_channel_id;
- $pay_redirect_url = 1;
- }
- if (empty($product_id) || empty($uid) || empty($distribution_channel_id) || empty($pay_redirect_url)) {
- return response()->error('WAP_PARAM_ERROR');
- }
- if ($suid && $suid == $uid) {
- return back();
- }
- $openid = $request->has('openid') ? $request->get('openid') : '';
- $bid = $request->has('bid') ? $request->get('bid') : 0;
- $hash_bid = $bid;
- $fromtype = $request->has('fromtype') ? $request->get('fromtype') : $request->get('from');
- if ($fromtype && strlen($fromtype) > 50) {
- try {
- $fromtype = decrypt($fromtype);
- } catch (\Exception $e) {
- $fromtype = 'main';
- }
- }
- if ($fromtype && strlen($fromtype) > 50) {
- $fromtype = 'main';
- }
- if (!$openid && !$p_channel_id && !$suid) {
- $transfer_channel_id = $this->transfer($distribution_channel_id);
- if ($transfer_channel_id) {
- $p_channel_id = $distribution_channel_id;
- $distribution_channel_id = $transfer_channel_id;
- }
- }
- //根据分校id获取支付配置id
- Log::info($request->all());
- $channel = ChannelService::getById($distribution_channel_id);
- if (!$channel || !$channel->pay_merchant_id) {
- return response()->error('WAP_PARAM_ERROR');
- }
- //获取支付类型
- $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->source == 'PALMPAYV2') {
- return redirect()->to($this->paympay($request, $pay_merchant));
- } else if ($pay_merchant->source === 'UNIONPAY') {
- return redirect()->to($this->unionpay($request, $pay_merchant));
- }
- //重定向 获取用户信息的次数
- $n++;
- if ($n >= 5) {
- //重定向次数过多,则授权公众号出问题
- $this->payAlert($channel->pay_merchant_id, '', '', $n);
- $back_url = env('PROTOCOL') . '://site' . encodeDistributionChannelId($distribution_channel_id) . '.' . env('CUSTOM_HOST') . '.com' . '/pay';
- return redirect()->to($back_url);
- }
- if (empty($openid)) {
- $trade_no = date("YmdHis") . str_shuffle(hexdec(uniqid()));
- if (isset($_SERVER['HTTP_X_FORWARDED_FOR']) && $_SERVER['HTTP_X_FORWARDED_FOR']) {
- $ip = $_SERVER['HTTP_X_FORWARDED_FOR'];
- } else {
- $ip = get_client_ip();
- }
- $params = compact('uid', 'product_id', 'distribution_channel_id', 'send_order_id', 'bid', 'trade_no', 'pay_redirect_url', 'fromtype', 'activity_id', 'n', 'suid', 'ip', 'p_channel_id', 'crm');
- $redirect_url = env('CREATE_PAY_URL') . '?' . http_build_query($params);
- //$redirect_url = env('CREATE_PAY_URL').'?uid='.$uid.'&product_id='.$product_id.'&distribution_channel_id='
- // .$distribution_channel_id.'&send_order_id='.$send_order_id.'&bid='.$bid.'&pay_redirect_url='.urlencode($pay_redirect_url)
- $auth_url = env('AUTH_URL') . '?gzh_app_id=' . $pay_merchant->appid . '&redirect_url=' . urlencode($redirect_url);
- Log::info('redirect_auth_url:' . $auth_url);
- header("Location:" . $auth_url);
- exit();
- }
- $trade_no = $request->input('trade_no');
- $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;
- }
- 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;
- }
- if ($bid) {
- try {
- $bid = Hashids::decode($bid)[0];
- } catch (\Exception $e) {
- $bid = 0;
- }
- }
- 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'] = $ip;
- $data['openid'] = $openid; //
- $data['body'] = 'novel read';
- $official_name = $this->getSubscribeOfficialName($uid, $distribution_channel_id);
- if ($official_name) {
- $data['body'] = '搜索公众号' . $official_name . ',请继续阅读';
- }
- $data['detail'] = 'novel read';
- $data['trade_no'] = $trade_no;
- $data['remark'] = json_encode(
- [
- 'uid' => $uid,
- 'dcd' => $distribution_channel_id,
- 'bid' => $bid,
- 'cp' => $ip,
- 'pms' => $pay_merchant->source,
- 'pmi' => $channel->pay_merchant_id,
- 'pd' => $product_id,
- 'soi' => $send_order_id,
- ]
- );
- 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';
- }
- /*
- $this->createOrderTotal([
- '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'=>$pay_merchant->source,
- 'pay_merchant_id'=>$channel->pay_merchant_id,
- 'create_ip'=>$request->getClientIp(),
- 'send_order_id'=>$send_order_id,
- 'order_type'=>$order_type,
- 'from_bid'=>$bid
- ]);*/
- $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 (redisEnv('MIWAN_TRANSFER_TO_CHANNEL_ID', 0) == $distribution_channel_id) {
- $send_order_id = -$send_order_id;
- }
- }
- 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' => $pay_merchant->source,
- 'pay_merchant_id' => $channel->pay_merchant_id,
- 'create_ip' => $ip,
- '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);
- $this->recordOtherParam($result->id, $uid);
- if ($p_channel_id) {
- //miwa 转换
- OrderParamService::createByParam([
- 'order_id' => $result->id, 'gxhp' => 'mw_transfer', 'appid' => '', 'bid' => $bid, 'data_hour_key' => '', 'times' => '', 'distribution_channel_id' => $p_channel_id
- ]);
- }
- if ($crm) {
- OrderParamService::createByParam([
- 'order_id' => $result->id, 'gxhp' => 'crm', 'appid' => '', 'bid' => $bid, 'data_hour_key' => $crm, 'times' => '', 'distribution_channel_id' => $distribution_channel_id
- ]);
- }
- $this->orderParamWso($uid, $result->id);
- }
- if ($request->get('suid')) {
- $this->createSubstituteOrder($result->id, $uid, $request->get('suid'));
- }
- Log::info($data);
- $config = [];
- if ($pay_merchant->config_info) {
- $config = json_decode($pay_merchant->config_info, true);
- }
- $wechatPay = WechatPay::instance($pay_merchant->source, $config);
- if (!$wechatPay) return response()->error('WAP_PARAM_ERROR');
- $pay_info = $wechatPay->send($data);
- if (!$pay_info) {
- $pay_info = $wechatPay->send($data);
- }
- if (!isset($pay_info['appId']) || !isset($pay_info['package'])) {
- //支付异常
- myLog('order')->info('pay error start---------------------------------');
- myLog('order')->info($pay_info);
- myLog('order')->info($request->all());
- myLog('order')->info('order info is');
- myLog('order')->info($init_order);
- myLog('order')->info('pay error end-----------------------------------');
- $this->payAlert($channel->pay_merchant_id, $trade_no, $pay_info);
- }
- $pay_info['pay_redirect_url'] = urldecode($pay_redirect_url);
- if ($request->has('cid')) {
- $pay_info['pay_redirect_url'] = $pay_info['pay_redirect_url'] . '&cid=' . $request->input('cid');
- }
- // if ($hash_bid) {
- // $pay_info['pay_redirect_url'] = $pay_info['pay_redirect_url'] . '&bid=' . $hash_bid;
- // }
- 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_info['pay_redirect_url'] = $pay_redirect_url = sprintf(
- $url_format,
- env('PROTOCOL'),
- encodeDistributionChannelId($help_pay_page_channel_id),
- env('CUSTOM_HOST'),
- $prize_fee,
- $uid
- );
- }
- $pay_url_info = parse_url($pay_redirect_url);
- $pay_info['pay_wait_url'] = $pay_url_info['scheme'] . '://' . $pay_url_info['host'] . '/pay/wait?order=' . $data['trade_no'] . '&redirect=' . urlencode($pay_info['pay_redirect_url']);
- //$h5_scheme = env('H5_SCHEME','https');
- //$jsSdkSign = $this->jsSdkSign($pay_info,str_replace('http',$h5_scheme,url()->current()));
- Log::info('$pay_info is');
- $jsSdkSign = 0;
- Log::info($pay_info);
- Log::info('jsSdkSign---- :' . $jsSdkSign);
- $pay_order = $trade_no;
- // 注册动作-》创建订单
- $action_type = 'CreateOrder';
- $param = [
- 'openid' => isset($openid) ? $openid : '0',
- 'uid' => isset($uid) ? $uid : '0',
- 'order_sn' => isset($trade_no) ? $trade_no : '0',
- 'amount' => isset($price) ? $price : '0',
- ];
- UserService::PushUserActionToQueue($action_type, $distribution_channel_id, $param);
- 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;
- $crm = $request->has('crm') ? $request->get('crm') : '';
- $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") . str_shuffle(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) { }
- if (isset($_SERVER['HTTP_X_FORWARDED_FOR']) && $_SERVER['HTTP_X_FORWARDED_FOR']) {
- $ip = $_SERVER['HTTP_X_FORWARDED_FOR'];
- } else {
- $ip = get_client_ip();
- }
- $data = [];
- $data['price'] = $price;
- $data['create_ip'] = $ip;
- $data['body'] = 'novel read';
- $official_name = $this->getSubscribeOfficialName($uid, $distribution_channel_id);
- 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' => $ip,
- '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);
- $this->recordOtherParam($result->id, $uid);
- if ($crm) {
- OrderParamService::createByParam([
- 'order_id' => $result->id, 'gxhp' => 'crm', 'appid' => '', 'bid' => $bid, 'data_hour_key' => $crm, 'times' => '', 'distribution_channel_id' => $distribution_channel_id
- ]);
- }
- $this->orderParamWso($uid, $result->id);
- }
- 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-------------------');
- // 注册动作-》创建订单
- $action_type = 'CreateOrder';
- $param = [
- 'openid' => isset($openid) ? $openid : '0',
- 'uid' => isset($uid) ? $uid : '0',
- 'order_sn' => isset($trade_no) ? $trade_no : '0',
- 'amount' => isset($price) ? $price : '0',
- ];
- \Log::info('FUCK_PALMPAYV2');
- UserService::PushUserActionToQueue($action_type, $distribution_channel_id, $param);
- return $pay_info;
- }
- /**
- * shit code
- */
- private function unionpay(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;
- $crm = $request->has('crm') ? $request->get('crm') : '';
- $hash_bid = $bid;
- $fromtype = $request->has('fromtype') ? $request->get('fromtype') : $request->get('from', 'main');
- //根据分校id获取支付配置id
- Log::info($request->all());
- $config = [];
- if ($pay_merchant->config_info) {
- $config = json_decode($pay_merchant->config_info, true);
- }
- $wechatPay = WechatPay::Union($pay_merchant->source, $config);
- if (!$wechatPay) return response()->error('WAP_PARAM_ERROR');
- $trade_no = $wechatPay->generateTradeNo();
- $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) { }
- if (isset($_SERVER['HTTP_X_FORWARDED_FOR']) && $_SERVER['HTTP_X_FORWARDED_FOR']) {
- $ip = $_SERVER['HTTP_X_FORWARDED_FOR'];
- } else {
- $ip = get_client_ip();
- }
- $data = [];
- $data['price'] = $price;
- $data['create_ip'] = $ip;
- $data['body'] = 'novel read';
- $official_name = $this->getSubscribeOfficialName($uid, $distribution_channel_id);
- 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' => $pay_merchant->source,
- 'pay_merchant_id' => $pay_merchant->id,
- 'create_ip' => $ip,
- '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);
- $this->recordOtherParam($result->id, $uid);
- if ($crm) {
- OrderParamService::createByParam([
- 'order_id' => $result->id, 'gxhp' => 'crm', 'appid' => '', 'bid' => $bid, 'data_hour_key' => $crm, 'times' => '', 'distribution_channel_id' => $distribution_channel_id
- ]);
- }
- $this->orderParamWso($uid, $result->id);
- }
- 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);
- $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);
- $pay_info = $wechatPay->send($data);
- // 注册动作-》创建订单
- $action_type = 'CreateOrder';
- $param = [
- 'openid' => isset($openid) ? $openid : '0',
- 'uid' => isset($uid) ? $uid : '0',
- 'order_sn' => isset($trade_no) ? $trade_no : '0',
- 'amount' => isset($price) ? $price : '0',
- ];
- \Log::info($pay_info);
- UserService::PushUserActionToQueue($action_type, $distribution_channel_id, $param);
- 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);
- }
- $from = 'pay';
- $order_info = OrderService::getByTradeNo($order);
- $uid = $order_info->uid;
- //$bind_info = UserBindPhoneService::bindInfo($uid);
- $bind_info = true;
- $page = 'pay.order.wait';
- if (!$bind_info) {
- //$page = 'pay.order.bindPhone';
- }
- $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));
- }
- if (!$bind_info) {
- return view('pay.order.bindPhone', compact('order', 'url', 'from'));
- } else {
- return redirect($url);
- }
- }
- }
- if (isset($url_info['path']) && str_contains($url_info['path'], 'pay')) {
- $url = sprintf('%s://%s/recent', $url_info['scheme'], $url_info['host']);
- //return redirect($url);
- if (!$bind_info) {
- return view('pay.order.bindPhone', compact('order', 'url', 'from'));
- } else {
- return redirect($url);
- }
- }
- return view($page, compact('order', 'url', 'from'));
- }
- private function isNewUserSecondCharge($charge_type, $product_id, $uid)
- {
- //Log::info('新用户只能冲一次:' .$charge_type);
- if ($charge_type == 'NEW_USER') {
- $result = OrderService::getUserOrderByProductId($uid, $product_id);
- //Log::info('isNewUserSecondCharge-------------------------');
- //Log::info($result);
- if ($result) {
- return true;
- }
- }
- return false;
- }
- //订单创建后统计
- private function orderCreated($init_order)
- {
- try {
- if (isset($init_order['pay_merchant_id'])) {
- $key = 'pay_merchant:' . $init_order['pay_merchant_id'];
- Redis::hincrby($key, 'unpaid_num', 1);
- Redis::hset($key, 'last_create_time', time());
- }
- } catch (\Exception $e) { }
- }
- //订单回调后统计
- private function orderPaid($init_order)
- {
- try {
- if (isset($init_order['pay_merchant_id'])) {
- $key = 'pay_merchant:' . $init_order['pay_merchant_id'];
- Redis::hset($key, 'unpaid_num', 0);
- }
- } catch (\Exception $e) { }
- }
- public function reportError(Request $request)
- {
- $data = $request->post('data');
- DB::table('pay_page_error')->insert([
- 'msg' => $data,
- 'created_at' => date('Y-m-d H:i:s'),
- 'updated_at' => date('Y-m-d H:i:s')
- ]);
- return response()->success();
- }
- private function jsSdkSign($pay_info, $url)
- {
- if (!isset($pay_info['appId']) || !isset($pay_info['package'])) {
- return 0;
- }
- $appid = $pay_info['appId'];
- $jsapi_ticket = Redis::hget($appid, 'jsapi_ticket');
- //如果能获取到jsapi_ticket 则直接签名
- if ($jsapi_ticket) {
- $sign_arr = [
- 'noncestr' => $pay_info['nonceStr'],
- 'jsapi_ticket' => $jsapi_ticket,
- 'timestamp' => $pay_info['timeStamp'],
- 'url' => $url
- ];
- return sha1($this->arr_to_url($sign_arr));
- }
- //获取不到jsapi_ticket
- $app_secret_info = DB::table('official_setting')->select('secret')->first();
- if ($app_secret_info && !empty($app_secret_info->secret)) {
- $client = new Client(['timeout' => 5]);
- try {
- //获取access_token
- $url = 'https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=' . $appid . '&secret=' . $app_secret_info->secret;
- $res = $client->request('get', $url)->getBody()->getContents();
- if (!$res) {
- return 0;
- }
- $res = json_decode($res, 1);
- if (!isset($res['access_token']) || empty($res['access_token'])) {
- return 0;
- }
- Redis::hset($appid, 'access_token', $res['access_token']);
- //获取jsapi_ticket
- $res = null;
- $url = 'https://api.weixin.qq.com/cgi-bin/ticket/getticket?access_token=' . $res['access_token'] . '&type=jsapi';
- $res = $client->request('get', $url)->getBody()->getContents();
- if (!$res) {
- return 0;
- }
- $res = json_decode($res, 1);
- if (!isset($res['ticket']) || empty($res['ticket'])) {
- return 0;
- }
- Redis::hset($appid, 'jsapi_ticket', $res['ticket']);
- Redis::EXPIRE($appid, 7000);
- $sign_arr = [
- 'noncestr' => $pay_info['nonceStr'],
- 'jsapi_ticket' => $res['ticket'],
- 'timestamp' => $pay_info['timeStamp'],
- 'url' => $url
- ];
- return sha1($this->arr_to_url($sign_arr));
- } catch (\Exception $e) {
- return 0;
- }
- }
- return 0;
- }
- public function waitPage(Request $request)
- {
- $order = $request->input('order');
- $from = 'pay';
- //$order = "201712081711401585932843356442";
- $order = (string) $order;
- $order_info = OrderService::getByTradeNo($order);
- $uid = $order_info->uid;
- $bind_info = UserBindPhoneService::bindInfo($uid);
- //$bind_info = false;
- $page = 'pay.order.wait';
- if (!$bind_info) {
- $page = 'pay.order.bindPhone';
- }
- $url = urldecode($request->input('redirect'));
- return view($page, compact('order', 'url', 'from'));
- //return view('pay.order.wait');
- }
- public function waitPageUnion(Request $request)
- {
- $order = $request->input('merOrderId');
- if ($order) {
- $from = 'pay';
- $order = (string) $order;
- $order_info = OrderService::getByTradeNo($order);
- $uid = $order_info->uid;
- $bind_info = UserBindPhoneService::bindInfo($uid);
- $page = 'pay.order.wait';
- if (!$bind_info) {
- $page = 'pay.order.bindPhone';
- }
- $url = urldecode($request->input('redirect'));
- return view($page, compact('order', 'url', 'from'));
- }
- }
- /**
- * 官方微信回调
- * @param Request $request
- * @return \Symfony\Component\HttpFoundation\Response
- */
- function wcback_official(Request $request)
- {
- libxml_disable_entity_loader(true);
- $xml = XML::parse(strval($request->getContent()));
- Log::info('xml is');
- Log::info($xml);
- if (!$xml || !is_array($xml)) return 'fail';
- $remarks = json_decode($xml['attach'], true);
- $pay_merchant_id = $remarks['pmi'];
- $pay_merchant = DB::table('pay_merchants')->select('appid', 'source', 'config_info')->where('id', $pay_merchant_id)->where('is_enabled', 1)->first();
- $application = WechatPay::Official($pay_merchant->source, json_decode($pay_merchant->config_info, true));
- //$app = new Application($options);
- $app = $application->app;
- $response = $app->payment->handleNotify(function ($notify, $successful) {
- if (!$successful) return 'fail';
- $trade_no = $notify->out_trade_no;
- $order = OrderService::getByTradeNo($trade_no);
- if (isset($order->status) && $order->status == 'PAID') {
- Log::info('has_pay:' . $trade_no);
- return true;
- }
- DB::beginTransaction();
- try {
- $transaction_id = $notify->transaction_id;
- $remarks = json_decode($notify->attach, true);
- $uid = $remarks['uid'];
- $distribution_channel_id = $remarks['dcd'];
- $product_id = $remarks['pd'];
- $product = ProductService::getProductSingle($product_id);
- $pay_merchant_source = $remarks['pms'];
- $pay_merchant_id = $remarks['pmi'];
- $send_order_id = $remarks['soi'];
- $create_ip = $remarks['cp'];
- $price = $product->price;
- $bid = $remarks['bid'];
- //$this->updateOrderTotal($trade_no,$transaction_id);
- $prize_fee = (int) (($product->price * 100) * 0.1);
- $this->substituteOrderPrice($order->id, $prize_fee);
- $this->smartPushTestBookPaidUv($order->from_bid, $order->uid, $order->price);
- //获取用户充值次数
- $order->pay_type = $this->getChargeTimes($order->uid);
- // 更新其他定制Order表
- if ($product->type == 'YEAR_ORDER') {
- Log::info('YEAR_ORDERYEAR_ORDERYEAR_ORDERYEAR_ORDERYEAR_ORDERYEAR_ORDERYEAR_ORDERYEAR_ORDER');
- $order_type = 'YEAR';
- $this->yearOrder($uid, $distribution_channel_id, $price, $send_order_id);
- $order->order_type = $order_type;
- $order->status = 'PAID';
- $order->pay_end_at = date('Y-m-d H:i:s');
- $order->transaction_id = $transaction_id;
- $order->save();
- //$price = $price/100;
- /*
- $this->createOrder(
- compact(
- 'uid','distribution_channel_id','product_id','price','trade_no','send_order_id','order_type','pay_merchant_source',
- 'pay_merchant_id','create_ip','bid','transaction_id'
- )
- );*/
- } elseif ($product->type == 'BOOK_ORDER') {
- Log::info('BOOK_ORDERBOOK_ORDERBOOK_ORDERBOOK_ORDERBOOK_ORDERBOOK_ORDERBOOK_ORDERBOOK_ORDER');
- $order_type = 'BOOK';
- $this->bookOrder($product_id, $uid, $send_order_id, $price, $distribution_channel_id);
- $order->order_type = $order_type;
- $order->status = 'PAID';
- $order->pay_end_at = date('Y-m-d H:i:s');
- $order->transaction_id = $transaction_id;
- $order->save();
- //$price = $price/100;
- /*
- $this->createOrder(
- compact(
- 'uid','distribution_channel_id','product_id','price','trade_no','send_order_id','order_type','pay_merchant_source',
- 'pay_merchant_id','create_ip','bid','transaction_id'
- )
- );*/
- } elseif ($product->type == 'TICKET_RECHARGE') {
- Log::info('TICKET_RECHARGETICKET_RECHARGETICKET_RECHARGETICKET_RECHARGETICKET_RECHARGE');
- $order_type = 'RECHARGE';
- $this->userCharge($product, $uid);
- $order->order_type = $order_type;
- $order->status = 'PAID';
- $order->pay_end_at = date('Y-m-d H:i:s');
- $order->transaction_id = $transaction_id;
- $order->save();
- //$price = $price/100;
- /*
- $this->createOrder(
- compact(
- 'uid','distribution_channel_id','product_id','price','trade_no','send_order_id','order_type','pay_merchant_source',
- 'pay_merchant_id','create_ip','bid','transaction_id'
- ));*/
- } elseif ($product->type == 'FOREVER') {
- Log::info('FOREVER------------------------FOREVER');
- $order_type = 'FOREVER';
- $this->foreverFreeOrder($uid, $distribution_channel_id, $price, $send_order_id);
- $order->order_type = $order_type;
- $order->status = 'PAID';
- $order->pay_end_at = date('Y-m-d H:i:s');
- $order->transaction_id = $transaction_id;
- $order->save();
- } else {
- DB::rollback();
- return 'Order not exist.';
- }
- $this->successPayPushMsg($uid, $product, $order->id);
- $this->orderStatistical($order);
- $key = 'leyuee:to_send_not_pay_uid:distribution_channel_id:' . $distribution_channel_id;
- Redis::hdel($key, $uid);
- DB::commit();
- //$this->huaweiActivity($order->activity_id,$uid,$product_id);
- // 注册动作-》回调订单
- $action_type = 'CallBackOrder';
- $param = [
- 'order_sn' => isset($trade_no) ? $trade_no : '0',
- 'openid' => isset($uid) ? $uid : '0', // 没有openid,用uid写log
- ];
- UserService::PushUserActionToQueue($action_type, $distribution_channel_id, $param);
- //用户属性
- $this->userProperty($uid, $price, $product->type, $order->activity_id);
- //交换订单时间
- $this->exchangeUpdateAndCreated($order->id);
- return true;
- } catch (\Exception $e) {
- DB::rollback();
- return 'fail';
- }
- });
- return $response;
- }
- /**
- * 银联支付回调
- */
- function wcback_union(Request $request)
- {
- $data = $request->all();
- \Log::info('union_pay.notify: ');
- \Log::info($data);
- if (isset($data['merOrderId'])) {
- $trade_no = $data['merOrderId'];
- if ($trade_no) {
- $order = OrderService::getByTradeNo($trade_no);
- $transaction_id = $data['targetOrderId'];
- if ($order) {
- if (isset($order->status) && $order->status == 'PAID') {
- Log::info('has_pay:' . $order->trade_no);
- return 'SUCCESS';
- }
- $pay_merchant = DB::table('pay_merchants')->select('appid', 'source', 'config_info')
- ->where('id', $order->pay_merchant_id)->where('is_enabled', 1)->first();
- $instance = WechatPay::Union(json_decode($pay_merchant->config, true));
- if ($instance->notify($data)) {
- // 修改表比较多,开启事务
- DB::beginTransaction();
- $uid = $order->uid;
- $distribution_channel_id = $order->distribution_channel_id;
- $product_id = $order->product_id;
- $product = ProductService::getProductSingle($product_id);
- $send_order_id = $order->send_order_id;
- $price = $product->price;
- Log::info('save_order_end');
- Log::info($product);
- Log::info('product_type:' . $product->type);
- $prize_fee = (int) (($product->price * 100) * 0.1);
- $this->substituteOrderPrice($order->id, $prize_fee);
- $this->smartPushTestBookPaidUv($order->from_bid, $order->uid, $order->price);
- //获取用户充值次数
- $order->pay_type = $this->getChargeTimes($order->uid);
- // 更新其他定制Order表
- if ($product->type == 'YEAR_ORDER') {
- Log::info('YEAR_ORDERYEAR_ORDERYEAR_ORDERYEAR_ORDERYEAR_ORDERYEAR_ORDERYEAR_ORDERYEAR_ORDER');
- $order_type = 'YEAR';
- $this->yearOrder($uid, $distribution_channel_id, $price, $send_order_id);
- $order->order_type = $order_type;
- $order->status = 'PAID';
- $order->pay_end_at = date('Y-m-d H:i:s');
- $order->transaction_id = $transaction_id;
- $order->save();
- } elseif ($product->type == 'BOOK_ORDER') {
- Log::info('BOOK_ORDERBOOK_ORDERBOOK_ORDERBOOK_ORDERBOOK_ORDERBOOK_ORDERBOOK_ORDERBOOK_ORDER');
- $order_type = 'BOOK';
- $this->bookOrder($product_id, $uid, $send_order_id, $price, $distribution_channel_id);
- $order->order_type = $order_type;
- $order->status = 'PAID';
- $order->pay_end_at = date('Y-m-d H:i:s');
- $order->transaction_id = $transaction_id;
- $order->save();
- } elseif ($product->type == 'TICKET_RECHARGE' || $product->type == 'NEW_USER') {
- Log::info('TICKET_RECHARGETICKET_RECHARGETICKET_RECHARGETICKET_RECHARGETICKET_RECHARGE');
- $order_type = 'RECHARGE';
- $this->userCharge($product, $uid);
- $order->order_type = $order_type;
- $order->status = 'PAID';
- $order->pay_end_at = date('Y-m-d H:i:s');
- $order->transaction_id = $transaction_id;
- $order->save();
- } elseif ($product->type == 'FOREVER') {
- Log::info('FOREVER------------------------FOREVER');
- $order_type = 'FOREVER';
- $this->foreverFreeOrder($uid, $distribution_channel_id, $price, $send_order_id);
- $order->order_type = $order_type;
- $order->status = 'PAID';
- $order->pay_end_at = date('Y-m-d H:i:s');
- $order->transaction_id = $transaction_id;
- $order->save();
- }
- $this->successPayPushMsg($uid, $product, $order->id);
- $this->orderStatistical($order);
- DB::commit();
- //redis 删除未支付的uid
- try {
- $key = 'leyuee:to_send_not_pay_uid:distribution_channel_id:' . $distribution_channel_id;
- Redis::hdel($key, $uid);
- } catch (\Exception $e) {
- Log::info('redis remote error-----------------------');
- Log::info($e);
- }
- // 注册动作-》回调订单
- $action_type = 'CallBackOrder';
- $param = [
- 'order_sn' => isset($trade_no) ? $trade_no : '0',
- 'openid' => isset($uid) ? $uid : '0', // 没有openid,用uid写log
- ];
- UserService::PushUserActionToQueue($action_type, $distribution_channel_id, $param);
- $this->userProperty($uid, $price, $product->type, $order->activity_id);
- //$this->huaweiActivity($order->activity_id,$uid,$product_id);
- //交换订单时间
- $this->exchangeUpdateAndCreated($order->id);
- }
- }
- }
- }
- }
- /**
- * 通联支付回调
- * @param Request $request
- */
- function wcback_allinpay(Request $request)
- {
- Log::info('wcback_allinpay_request');
- try {
- $data = $request->all();
- Log::info($request->all());
- if (!$data['trxreserved']) return 'fail';
- $pay_merchant_id = json_decode($data['trxreserved'], true)['pmi'];
- $pay_merchant = DB::table('pay_merchants')->select('appid', 'source', 'config_info')->where('id', $pay_merchant_id)->where('is_enabled', 1)->first();
- unset($data['_url']);
- if (!$pay_merchant->config_info) return 'fail';
- $wechatPay = WechatPay::instance('ALLINPAY', json_decode($pay_merchant->config_info, true));
- if ($wechatPay->NotifyValidSign($data, $wechatPay->appkey)) {
- Log::info('allinpay_notify_sign_success');
- /**
- * 只有0000表示交易成功或下单成功,其他为失败
- * 0000:交易成功
- * 3045,3088:交易超时
- * 3008:余额不足
- * 3999:交易失败
- * 2008:交易处理中
- * 3050:交易已撤销
- */
- if ($data['trxstatus'] == '0000') {
- // 修改表比较多,开启事务
- DB::beginTransaction();
- $trade_no = $data['cusorderid'];
- $transaction_id = $data['chnltrxid'];
- //$openid = $data['acct'];
- $remarks = $data['trxreserved'];
- // $remarks = '{"openid":"oEteU1VNvYozhXuu8TXhByPBtSl4","distribution_channel_id":2,"product_id":1,"uid":1,"price":"1","trade_no":"201711301937151585490779316114","create_ip":"::1","servicer":"AllinPay"}';
- $remarks = json_decode($remarks, true);
- Log::info('$remarks');
- Log::info($remarks);
- // 更新Order
- $order = OrderService::getByTradeNo($trade_no);
- // 防止重复推送
- if (isset($order->status) && $order->status == 'PAID') {
- Log::info('has_pay:' . $trade_no);
- echo 'success';
- exit();
- }
- $uid = $remarks['uid'];
- $distribution_channel_id = $remarks['dcd'];
- $product_id = $remarks['pd'];
- $product = ProductService::getProductSingle($product_id);
- $pay_merchant_source = $remarks['pms'];
- $pay_merchant_id = $remarks['pmi'];
- $send_order_id = $remarks['soi'];
- $create_ip = $remarks['cp'];
- $price = $product->price;
- $bid = $remarks['bid'];
- Log::info('save_order_end');
- //$this->updateOrderTotal($trade_no,$transaction_id);
- Log::info($product);
- Log::info('product_type:' . $product->type);
- $prize_fee = (int) (($product->price * 100) * 0.1);
- $this->substituteOrderPrice($order->id, $prize_fee);
- $this->smartPushTestBookPaidUv($order->from_bid, $order->uid, $order->price);
- //获取用户充值次数
- $order->pay_type = $this->getChargeTimes($order->uid);
- // 更新其他定制Order表
- if ($product->type == 'YEAR_ORDER') {
- Log::info('YEAR_ORDERYEAR_ORDERYEAR_ORDERYEAR_ORDERYEAR_ORDERYEAR_ORDERYEAR_ORDERYEAR_ORDER');
- $order_type = 'YEAR';
- $this->yearOrder($uid, $distribution_channel_id, $price, $send_order_id);
- $order->order_type = $order_type;
- $order->status = 'PAID';
- $order->pay_end_at = date('Y-m-d H:i:s');
- $order->transaction_id = $transaction_id;
- $order->save();
- //$price = $price/100;
- /*
- $this->createOrder(
- compact(
- 'uid','distribution_channel_id','product_id','price','trade_no','send_order_id','order_type','pay_merchant_source',
- 'pay_merchant_id','create_ip','bid','transaction_id'
- )
- );*/
- } elseif ($product->type == 'BOOK_ORDER') {
- Log::info('BOOK_ORDERBOOK_ORDERBOOK_ORDERBOOK_ORDERBOOK_ORDERBOOK_ORDERBOOK_ORDERBOOK_ORDER');
- $order_type = 'BOOK';
- $this->bookOrder($product_id, $uid, $send_order_id, $price, $distribution_channel_id);
- $order->order_type = $order_type;
- $order->status = 'PAID';
- $order->pay_end_at = date('Y-m-d H:i:s');
- $order->transaction_id = $transaction_id;
- $order->save();
- //$price = $price/100;
- /*
- $this->createOrder(
- compact(
- 'uid','distribution_channel_id','product_id','price','trade_no','send_order_id','order_type','pay_merchant_source',
- 'pay_merchant_id','create_ip','bid','transaction_id'
- )
- );*/
- } elseif ($product->type == 'TICKET_RECHARGE' || $product->type == 'NEW_USER') {
- Log::info('TICKET_RECHARGETICKET_RECHARGETICKET_RECHARGETICKET_RECHARGETICKET_RECHARGE');
- $order_type = 'RECHARGE';
- $this->userCharge($product, $uid);
- $order->order_type = $order_type;
- $order->status = 'PAID';
- $order->pay_end_at = date('Y-m-d H:i:s');
- $order->transaction_id = $transaction_id;
- $order->save();
- //$price = $price/100;
- /*
- $this->createOrder(
- compact(
- 'uid','distribution_channel_id','product_id','price','trade_no','send_order_id','order_type','pay_merchant_source',
- 'pay_merchant_id','create_ip','bid','transaction_id'
- ));*/
- } elseif ($product->type == 'FOREVER') {
- Log::info('FOREVER------------------------FOREVER');
- $order_type = 'FOREVER';
- $this->foreverFreeOrder($uid, $distribution_channel_id, $price, $send_order_id);
- $order->order_type = $order_type;
- $order->status = 'PAID';
- $order->pay_end_at = date('Y-m-d H:i:s');
- $order->transaction_id = $transaction_id;
- $order->save();
- }
- $this->successPayPushMsg($uid, $product, $order->id);
- $this->orderStatistical($order);
- DB::commit();
- $this->userProperty($uid, $price, $product->type, $order->activity_id);
- //$this->huaweiActivity($order->activity_id,$uid,$product_id);
- //交换订单时间
- $this->exchangeUpdateAndCreated($order->id);
- //redis 删除未支付的uid
- try {
- $key = 'leyuee:to_send_not_pay_uid:distribution_channel_id:' . $distribution_channel_id;
- Redis::hdel($key, $uid);
- //Redis::srem($key,$uid);
- } catch (\Exception $e) {
- Log::info('redis remote error-----------------------');
- Log::info($e);
- }
- }
- } else {
- Log::info('allinpay_notify_sign_fail');
- }
- } catch (\Exception $e) {
- DB::rollBack();
- Log::info('receive_allinpay_ept:' . $e->getMessage());
- Log::info('pay_callback_end fail');
- echo 'fail';
- return;
- }
- Log::info('pay_callback_end');
- echo "success";
- }
- public function wcback_lianlianpay(Request $request)
- {
- $data = $request->getContent();
- Log::info('wcback_lianlianpay call back enter');
- Log::info($request->getContent());
- $data = json_decode($data, true);
- if ($data['result_pay'] == 'SUCCESS') {
- $trade_no = $data['no_order'];
- $order = OrderService::getByTradeNo($trade_no);
- if (!$order) return response()->json(['ret_code' => '-1']);
- $pay_merchant_id = $order->pay_merchant_id;
- $pay_merchant = DB::table('pay_merchants')->select('appid', 'source', 'config_info')->where('id', $pay_merchant_id)->where('is_enabled', 1)->first();
- unset($data['_url']);
- if (!$pay_merchant->config_info) response()->json(['ret_code' => '-1']);
- $wechatPay = WechatPay::instance('LIANLIANPAY', json_decode($pay_merchant->config_info, true));
- $uid = $order->uid;
- $distribution_channel_id = $order->distribution_channel_id;
- $price = $order->price;
- $send_order_id = $order->send_order_id;
- $product_id = $order->product_id;
- if (!$wechatPay->rsaCheck($data)) {
- Log::info('sign check error');
- //return response()->json(['ret_code'=>'-1']);
- }
- // 防止重复推送
- if (isset($order->status) && $order->status == 'PAID') {
- Log::info('has_pay:' . $trade_no);
- return response()->json(['ret_code' => '0000', 'ret_msg' => '交易成功']);
- }
- DB::beginTransaction();
- try {
- $product = ProductService::getProductSingle($order->product_id);
- $transaction_id = $data['oid_paybill'];
- $prize_fee = (int) (($product->price * 100));
- $this->substituteOrderPrice($order->id, $prize_fee);
- $this->smartPushTestBookPaidUv($order->from_bid, $order->uid, $order->price);
- //获取用户充值次数
- $order->pay_type = $this->getChargeTimes($order->uid);
- // 更新其他定制Order表
- if ($product->type == 'YEAR_ORDER') {
- Log::info('YEAR_ORDERYEAR_ORDERYEAR_ORDERYEAR_ORDERYEAR_ORDERYEAR_ORDERYEAR_ORDERYEAR_ORDER');
- $order_type = 'YEAR';
- $this->yearOrder($uid, $distribution_channel_id, $price, $send_order_id);
- $order->order_type = $order_type;
- $order->status = 'PAID';
- $order->pay_end_at = date('Y-m-d H:i:s');
- $order->transaction_id = $transaction_id;
- $order->save();
- } elseif ($product->type == 'BOOK_ORDER') {
- Log::info('BOOK_ORDERBOOK_ORDERBOOK_ORDERBOOK_ORDERBOOK_ORDERBOOK_ORDERBOOK_ORDERBOOK_ORDER');
- $order_type = 'BOOK';
- $this->bookOrder($product_id, $uid, $send_order_id, $price, $distribution_channel_id);
- $order->order_type = $order_type;
- $order->status = 'PAID';
- $order->pay_end_at = date('Y-m-d H:i:s');
- $order->transaction_id = $transaction_id;
- $order->save();
- } elseif ($product->type == 'TICKET_RECHARGE' || $product->type == 'NEW_USER') {
- Log::info('TICKET_RECHARGETICKET_RECHARGETICKET_RECHARGETICKET_RECHARGETICKET_RECHARGE');
- $order_type = 'RECHARGE';
- $this->userCharge($product, $uid);
- $order->order_type = $order_type;
- $order->status = 'PAID';
- $order->pay_end_at = date('Y-m-d H:i:s');
- $order->transaction_id = $transaction_id;
- $order->save();
- } elseif ($product->type == 'FOREVER') {
- Log::info('FOREVER------------------------FOREVER');
- $order_type = 'FOREVER';
- $this->foreverFreeOrder($uid, $distribution_channel_id, $price, $send_order_id);
- $order->order_type = $order_type;
- $order->status = 'PAID';
- $order->pay_end_at = date('Y-m-d H:i:s');
- $order->transaction_id = $transaction_id;
- $order->save();
- }
- $this->successPayPushMsg($uid, $product, $order->id);
- $this->orderStatistical($order);
- DB::commit();
- $this->userProperty($uid, $price, $product->type, $order->activity_id);
- //$this->huaweiActivity($order->activity_id,$uid,$product_id);
- //redis 删除未支付的uid
- $key = 'leyuee:to_send_not_pay_uid:distribution_channel_id' . $distribution_channel_id;
- Redis::hdel($key, $uid);
- //交换订单时间
- $this->exchangeUpdateAndCreated($order->id);
- return response()->json(['ret_code' => '0000', 'ret_msg' => '交易成功']);
- } catch (\Exception $e) {
- DB::rollBack();
- Log::info('lianlian:' . $e->getMessage());
- echo 'fail';
- return;
- }
- }
- echo 'success';
- }
- /**
- * 微众支付回调
- * @param Request $request
- */
- function wcback_palmpay(Request $request)
- {
- Log::info('wcback_palmpay_request');
- try {
- $data = $request->except('_url');
- Log::info($request->all());
- //订单
- $trade_no = $data['outTradeNo'];
- $order = OrderService::getByTradeNo($trade_no);
- if (!$order) die('failed');
- // 防止重复推送
- if (isset($order->status) && $order->status == 'PAID') {
- if ($data['chorderid'] != $order->transaction_id) {
- Log::info('palmpay order repeat');
- $this->palmpaySpecial($data['chorderid'], $trade_no);
- }
- Log::info('has_pay:' . $trade_no);
- echo 'success';
- exit();
- }
- $pay_merchant = DB::table('pay_merchants')->select('appid', 'source', 'config_info')->where('id', $order->pay_merchant_id)->where('is_enabled', 1)->first();
- //校验签名
- $sign = _sign($data, json_decode($pay_merchant->config_info, 1)['appKey']);
- if ($sign != $data['sign']) die('failed');
- $transaction_id = $data['chorderid'];
- if ($data['status'] == 'success') {
- Log::info('wcback_palmpay_notify_sign_success');
- if ($data['status'] == 'success') {
- // 修改表比较多,开启事务
- DB::beginTransaction();
- // 更新Order
- $order = OrderService::getByTradeNo($trade_no);
- $uid = $order->uid;
- $distribution_channel_id = $order->distribution_channel_id;
- $product_id = $order->product_id;
- $product = ProductService::getProductSingle($product_id);
- $send_order_id = $order->send_order_id;
- $price = $product->price;
- Log::info('save_order_end');
- Log::info($product);
- Log::info('product_type:' . $product->type);
- $prize_fee = (int) (($product->price * 100) * 0.1);
- $this->substituteOrderPrice($order->id, $prize_fee);
- $this->smartPushTestBookPaidUv($order->from_bid, $order->uid, $order->price);
- //获取用户充值次数
- $order->pay_type = $this->getChargeTimes($order->uid);
- // 更新其他定制Order表
- if ($product->type == 'YEAR_ORDER') {
- Log::info('YEAR_ORDERYEAR_ORDERYEAR_ORDERYEAR_ORDERYEAR_ORDERYEAR_ORDERYEAR_ORDERYEAR_ORDER');
- $order_type = 'YEAR';
- $this->yearOrder($uid, $distribution_channel_id, $price, $send_order_id);
- $order->order_type = $order_type;
- $order->status = 'PAID';
- $order->pay_end_at = date('Y-m-d H:i:s');
- $order->transaction_id = $transaction_id;
- $order->save();
- } elseif ($product->type == 'BOOK_ORDER') {
- Log::info('BOOK_ORDERBOOK_ORDERBOOK_ORDERBOOK_ORDERBOOK_ORDERBOOK_ORDERBOOK_ORDERBOOK_ORDER');
- $order_type = 'BOOK';
- $this->bookOrder($product_id, $uid, $send_order_id, $price, $distribution_channel_id);
- $order->order_type = $order_type;
- $order->status = 'PAID';
- $order->pay_end_at = date('Y-m-d H:i:s');
- $order->transaction_id = $transaction_id;
- $order->save();
- } elseif ($product->type == 'TICKET_RECHARGE' || $product->type == 'NEW_USER') {
- Log::info('TICKET_RECHARGETICKET_RECHARGETICKET_RECHARGETICKET_RECHARGETICKET_RECHARGE');
- $order_type = 'RECHARGE';
- $this->userCharge($product, $uid);
- $order->order_type = $order_type;
- $order->status = 'PAID';
- $order->pay_end_at = date('Y-m-d H:i:s');
- $order->transaction_id = $transaction_id;
- $order->save();
- } elseif ($product->type == 'FOREVER') {
- Log::info('FOREVER------------------------FOREVER');
- $order_type = 'FOREVER';
- $this->foreverFreeOrder($uid, $distribution_channel_id, $price, $send_order_id);
- $order->order_type = $order_type;
- $order->status = 'PAID';
- $order->pay_end_at = date('Y-m-d H:i:s');
- $order->transaction_id = $transaction_id;
- $order->save();
- }
- $this->successPayPushMsg($uid, $product, $order->id);
- $this->orderStatistical($order);
- DB::commit();
- //redis 删除未支付的uid
- try {
- $key = 'leyuee:to_send_not_pay_uid:distribution_channel_id:' . $distribution_channel_id;
- Redis::hdel($key, $uid);
- } catch (\Exception $e) {
- Log::info('redis remote error-----------------------');
- Log::info($e);
- }
- // 注册动作-》回调订单
- $action_type = 'CallBackOrder';
- $param = [
- 'order_sn' => isset($trade_no) ? $trade_no : '0',
- 'openid' => isset($uid) ? $uid : '0', // 没有openid,用uid写log
- ];
- UserService::PushUserActionToQueue($action_type, $distribution_channel_id, $param);
- $this->userProperty($uid, $price, $product->type, $order->activity_id);
- //$this->huaweiActivity($order->activity_id,$uid,$product_id);
- //交换订单时间
- $this->exchangeUpdateAndCreated($order->id);
- }
- } else {
- Log::info('wcback_palmpay_notify_sign_fail');
- }
- } catch (\Exception $e) {
- var_dump($e->getMessage());
- DB::rollBack();
- Log::info('receive_wcback_palmpay_ept:' . $e->getMessage());
- echo 'fail';
- Log::info('pay_callback_end error');
- return;
- }
- Log::info('pay_callback_end');
- echo "success";
- }
- //平安银行支付回调
- function wcback_originbank(Request $request)
- {
- Log::info($request->all());
- Log::info('wcback_palmpay_request');
- try {
- $data = $request->except('_url');
- unset($data['sign']);
- //订单
- $trade_no = $data['out_no'];
- $order = OrderService::getByTradeNo($trade_no);
- if (!$order) die('failed');
- $pay_merchant = DB::table('pay_merchants')->select('appid', 'source', 'config_info')->where('id', $order->pay_merchant_id)->first();
- // 防止重复推送
- if (isset($order->status) && $order->status == 'PAID') {
- Log::info('has_pay:' . $trade_no);
- echo 'success';
- exit();
- }
- //校验签名
- // $sign = _sign($data, json_decode($pay_merchant->config_info, 1)['appKey']);
- // if ($sign != $data['sign']) die('failed');
- $trade_result = json_decode($data['trade_result'], true);
- $transaction_id = $trade_result['transaction_id'];
- if ($trade_result['return_code'] == 'SUCCESS') {
- Log::info('wcback_palmpay_notify_sign_success');
- // 修改表比较多,开启事务
- DB::beginTransaction();
- $uid = $order->uid;
- $distribution_channel_id = $order->distribution_channel_id;
- $product_id = $order->product_id;
- $product = ProductService::getProductSingle($product_id);
- $send_order_id = $order->send_order_id;
- $price = $product->price;
- Log::info('save_order_end');
- Log::info($product);
- Log::info('product_type:' . $product->type);
- $prize_fee = (int) (($product->price * 100) * 0.1);
- $this->substituteOrderPrice($order->id, $prize_fee);
- $this->smartPushTestBookPaidUv($order->from_bid, $order->uid, $order->price);
- //获取用户充值次数
- $order->pay_type = $this->getChargeTimes($order->uid);
- // 更新其他定制Order表
- if ($product->type == 'YEAR_ORDER') {
- Log::info('YEAR_ORDERYEAR_ORDERYEAR_ORDERYEAR_ORDERYEAR_ORDERYEAR_ORDERYEAR_ORDERYEAR_ORDER');
- $order_type = 'YEAR';
- $this->yearOrder($uid, $distribution_channel_id, $price, $send_order_id);
- $order->order_type = $order_type;
- $order->status = 'PAID';
- $order->pay_end_at = date('Y-m-d H:i:s');
- $order->transaction_id = $transaction_id;
- $order->save();
- } elseif ($product->type == 'BOOK_ORDER') {
- Log::info('BOOK_ORDERBOOK_ORDERBOOK_ORDERBOOK_ORDERBOOK_ORDERBOOK_ORDERBOOK_ORDERBOOK_ORDER');
- $order_type = 'BOOK';
- $this->bookOrder($product_id, $uid, $send_order_id, $price, $distribution_channel_id);
- $order->order_type = $order_type;
- $order->status = 'PAID';
- $order->pay_end_at = date('Y-m-d H:i:s');
- $order->transaction_id = $transaction_id;
- $order->save();
- } elseif ($product->type == 'TICKET_RECHARGE' || $product->type == 'NEW_USER') {
- Log::info('TICKET_RECHARGETICKET_RECHARGETICKET_RECHARGETICKET_RECHARGETICKET_RECHARGE');
- $order_type = 'RECHARGE';
- $this->userCharge($product, $uid);
- $order->order_type = $order_type;
- $order->status = 'PAID';
- $order->pay_end_at = date('Y-m-d H:i:s');
- $order->transaction_id = $transaction_id;
- $order->save();
- } elseif ($product->type == 'FOREVER') {
- Log::info('FOREVER------------------------FOREVER');
- $order_type = 'FOREVER';
- $this->foreverFreeOrder($uid, $distribution_channel_id, $price, $send_order_id);
- $order->order_type = $order_type;
- $order->status = 'PAID';
- $order->pay_end_at = date('Y-m-d H:i:s');
- $order->transaction_id = $transaction_id;
- $order->save();
- }
- $this->successPayPushMsg($uid, $product, $order->id);
- $this->orderStatistical($order);
- DB::commit();
- //redis 删除未支付的uid
- try {
- $key = 'leyuee:to_send_not_pay_uid:distribution_channel_id:' . $distribution_channel_id;
- Redis::hdel($key, $uid);
- } catch (\Exception $e) {
- Log::info('redis remote error-----------------------');
- Log::info($e);
- }
- // 注册动作-》回调订单
- $action_type = 'CallBackOrder';
- $param = [
- 'order_sn' => isset($trade_no) ? $trade_no : '0',
- 'openid' => isset($uid) ? $uid : '0', // 没有openid,用uid写log
- ];
- UserService::PushUserActionToQueue($action_type, $distribution_channel_id, $param);
- $this->userProperty($uid, $price, $product->type, $order->activity_id);
- //$this->huaweiActivity($order->activity_id,$uid,$product_id);
- //交换订单时间
- $this->exchangeUpdateAndCreated($order->id);
- } else {
- Log::info('wcback_palmpay_notify_sign_fail');
- }
- } catch (\Exception $e) {
- var_dump($e->getMessage());
- DB::rollBack();
- Log::info('receive_wcback_palmpay_ept:' . $e->getMessage());
- echo 'fail';
- Log::info('pay_callback_end error');
- return;
- }
- Log::info('pay_callback_end');
- echo "success";
- }
- //市民卡支付回调
- function wcback_smkpay(Request $request)
- {
- Log::info('wcback_smkpay start:');
- $res_data = [];
- try {
- $data = $request->except('_url');
- $source_sign = $data['sign'];
- unset($data['sign']);
- //订单
- $trade_no = $data['orderNo'];
- $order = OrderService::getByTradeNo($trade_no);
- if (!$order) die('failed');
- $pay_merchant = DB::table('pay_merchants')->select('appid', 'source', 'config_info')->where('id', $order->pay_merchant_id)->first();
- $pay_config_info = json_decode($pay_merchant->config_info, 1);
- // 防止重复推送
- if (isset($order->status) && $order->status == 'PAID') {
- Log::info('has_pay:' . $trade_no);
- $res_data['respCode'] = '00';
- $res_data['respDesc'] = '成功';
- $res_data['merCode'] = $pay_config_info['merCode'];
- $res_data['reqSeq'] = $data['reqSeq'];
- return response()->json($res_data);
- }
- //校验签名
- $wechatPay = WechatPay::instance($pay_merchant->source, $pay_config_info);
- if (!$wechatPay->checkSign($data, $source_sign)) {
- Log::info('sign check error:');
- Log::info($request->all());
- die('failed');
- }
- $trade_code = $data['respCode'];
- $trade_status = $data['status'];
- $transaction_id = $data['serialNo'];
- if ($trade_code == '00' && $trade_status == '01') {
- Log::info('wcback_wcback_smkpay_notify_sign_success');
- // 修改表比较多,开启事务
- DB::beginTransaction();
- $uid = $order->uid;
- $distribution_channel_id = $order->distribution_channel_id;
- $product_id = $order->product_id;
- $product = ProductService::getProductSingle($product_id);
- $send_order_id = $order->send_order_id;
- $price = $product->price;
- Log::info('save_order_end');
- Log::info($product);
- Log::info('product_type:' . $product->type);
- $prize_fee = (int) (($product->price * 100) * 0.1);
- $this->substituteOrderPrice($order->id, $prize_fee);
- $this->smartPushTestBookPaidUv($order->from_bid, $order->uid, $order->price);
- //获取用户充值次数
- $order->pay_type = $this->getChargeTimes($order->uid);
- // 更新其他定制Order表
- if ($product->type == 'YEAR_ORDER') {
- Log::info('YEAR_ORDERYEAR_ORDERYEAR_ORDERYEAR_ORDERYEAR_ORDERYEAR_ORDERYEAR_ORDERYEAR_ORDER');
- $order_type = 'YEAR';
- $this->yearOrder($uid, $distribution_channel_id, $price, $send_order_id);
- $order->order_type = $order_type;
- $order->status = 'PAID';
- $order->pay_end_at = date('Y-m-d H:i:s');
- $order->transaction_id = $transaction_id;
- $order->save();
- } elseif ($product->type == 'BOOK_ORDER') {
- Log::info('BOOK_ORDERBOOK_ORDERBOOK_ORDERBOOK_ORDERBOOK_ORDERBOOK_ORDERBOOK_ORDERBOOK_ORDER');
- $order_type = 'BOOK';
- $this->bookOrder($product_id, $uid, $send_order_id, $price, $distribution_channel_id);
- $order->order_type = $order_type;
- $order->status = 'PAID';
- $order->pay_end_at = date('Y-m-d H:i:s');
- $order->transaction_id = $transaction_id;
- $order->save();
- } elseif ($product->type == 'TICKET_RECHARGE' || $product->type == 'NEW_USER') {
- Log::info('TICKET_RECHARGETICKET_RECHARGETICKET_RECHARGETICKET_RECHARGETICKET_RECHARGE');
- $order_type = 'RECHARGE';
- $this->userCharge($product, $uid);
- $order->order_type = $order_type;
- $order->status = 'PAID';
- $order->pay_end_at = date('Y-m-d H:i:s');
- $order->transaction_id = $transaction_id;
- $order->save();
- } elseif ($product->type == 'FOREVER') {
- Log::info('FOREVER------------------------FOREVER');
- $order_type = 'FOREVER';
- $this->foreverFreeOrder($uid, $distribution_channel_id, $price, $send_order_id);
- $order->order_type = $order_type;
- $order->status = 'PAID';
- $order->pay_end_at = date('Y-m-d H:i:s');
- $order->transaction_id = $transaction_id;
- $order->save();
- }
- $this->successPayPushMsg($uid, $product, $order->id);
- $this->orderStatistical($order);
- DB::commit();
- //redis 删除未支付的uid
- try {
- $key = 'leyuee:to_send_not_pay_uid:distribution_channel_id:' . $distribution_channel_id;
- Redis::hdel($key, $uid);
- } catch (\Exception $e) {
- Log::info('redis remote error-----------------------');
- Log::info($e);
- }
- // 注册动作-》回调订单
- $action_type = 'CallBackOrder';
- $param = [
- 'order_sn' => isset($trade_no) ? $trade_no : '0',
- 'openid' => isset($uid) ? $uid : '0', // 没有openid,用uid写log
- ];
- UserService::PushUserActionToQueue($action_type, $distribution_channel_id, $param);
- $this->userProperty($uid, $price, $product->type, $order->activity_id);
- } else {
- Log::info('wcback_smkpay_notify_sign_fail');
- }
- $res_data['respCode'] = '00';
- $res_data['respDesc'] = '成功';
- $res_data['merCode'] = $pay_config_info['merCode'];
- $res_data['reqSeq'] = $order->transaction_id;
- return response()->json($res_data);
- Log::info('pay_callback_end');
- } catch (\Exception $e) {
- DB::rollBack();
- Log::info('receive_smkpay_palmpay_ept:' . $e->getMessage());
- echo 'fail';
- Log::info('pay_callback_end error');
- return;
- }
- }
- /**
- * 公众号签名@华灯初上
- * @param $params
- * @return string
- */
- protected function getSign($params, $key)
- {
- $url = $this->arr_to_url($params, false);
- $url = $url . '&key=' . $key;
- $sign = md5($url);
- return $sign;
- }
- /**
- * 公众号签名@华灯初上
- * @param $array
- * @param bool $has_sign
- * @return string
- */
- protected function arr_to_url($array, $has_sign = false)
- {
- ksort($array);
- reset($array);
- $arg = "";
- while (list($name, $val) = each($array)) {
- if ($name == 'sign' && !$has_sign) continue;
- if (strpos($name, "_") === 0)
- continue;
- if (is_array($val))
- $val = join(',', $val);
- if ($val === "")
- continue;
- $arg .= $name . "=" . $val . "&";
- }
- $arg = substr($arg, 0, count($arg) - 2);
- return $arg;
- }
- /**
- * 单本充值会掉
- * @param $product_id
- * @param $uid
- * @param $send_order_id
- * @param $fee
- */
- protected function bookOrder($product_id, $uid, $send_order_id, $fee, $distribution_channel_id)
- {
- $book_conf = BookConfigService::getBookByProduct($product_id);
- $insert_data['bid'] = isset($book_conf->bid) ? $book_conf->bid : '';
- $insert_data['book_name'] = isset($book_conf->book_name) ? $book_conf->book_name : '';
- $insert_data['uid'] = $uid;
- $insert_data['distribution_channel_id'] = $distribution_channel_id;
- $insert_data['fee'] = $fee;
- $insert_data['send_order_id'] = $send_order_id;
- $insert_data['charge_balance'] = 0;
- $insert_data['reward_balance'] = 0;
- Log::info('start_save_book_order');
- Log::info($insert_data);
- return BookOrderService::save_book_order($insert_data);
- }
- /**
- * 包年
- * @param $uid
- * @param $distribution_channel_id
- * @param $fee
- * @param $send_order_id
- * @return mixed
- */
- protected function yearOrder($uid, $distribution_channel_id, $fee, $send_order_id)
- {
- Log::info('start_save_year_order');
- $insert_data['uid'] = $uid;
- $insert_data['distribution_channel_id'] = $distribution_channel_id;
- $insert_data['fee'] = $fee;
- $insert_data['send_order_id'] = $send_order_id;
- Log::info($insert_data);
- return YearOrderService::save_year_order($insert_data);
- }
- private function foreverFreeOrder($uid, $distribution_channel_id, $fee, $send_order_id)
- {
- Log::info('start_save_year_order');
- ('start_forever_Free_Order');
- $insert_data['uid'] = $uid;
- $insert_data['distribution_channel_id'] = $distribution_channel_id;
- $insert_data['fee'] = $fee;
- $insert_data['send_order_id'] = $send_order_id;
- Log::info($insert_data);
- return YearOrderService::foreverFree($insert_data);
- }
- /**
- * 用户充值
- * @param $product
- * @param $uid\
- */
- protected function userCharge($product, $uid)
- {
- $total = $product->price * 100 + $product->given;
- UserService::addBalance($uid, $total, $product->price * 100, $product->given);
- Log::info('update_user_balance_end:' . $uid . ' balance_add:' . $total);
- }
- /**
- * 添加订单
- * @param array $data
- * @return mixed
- */
- protected function createOrder(array $data)
- {
- $insert_data = array();
- $insert_data['uid'] = $data['uid'];
- $insert_data['distribution_channel_id'] = $data['distribution_channel_id'];
- $insert_data['product_id'] = $data['product_id'];
- $insert_data['price'] = $data['price'];
- $insert_data['status'] = 'PAID';
- $insert_data['pay_type'] = 1;
- $insert_data['trade_no'] = $data['trade_no'];
- $insert_data['send_order_id'] = $data['send_order_id'];
- $insert_data['order_type'] = $data['order_type'];
- $insert_data['pay_merchant_source'] = $data['pay_merchant_source'];
- $insert_data['pay_merchant_id'] = $data['pay_merchant_id'];
- $insert_data['transaction_id'] = $data['transaction_id'];
- $insert_data['pay_end_at'] = date('Y-m-d H:i:s');
- $insert_data['create_ip'] = $data['create_ip'];
- $insert_data['from_bid'] = $data['bid'];
- Log::info('createOrder');
- Log::info($insert_data);
- return OrderService::save_order($insert_data);
- }
- /**
- * 添加位置付订单
- * @param $data
- * @return mixed
- */
- protected function createUnPayOrder($data)
- {
- $data['status'] = 'UNPAID';
- $data['transaction_id'] = '';
- $data['pay_end_at'] = '0000-00-00 00:00:00';
- return OrderService::save_order($data);
- }
- /**
- * order total
- * @param $data
- *
- */
- protected function createOrderTaotal($data)
- {
- $data['status'] = 'UNPAID';
- $data['created_at'] = date('Y-m-d H:i:s');
- $data['updated_at'] = date('Y-m-d H:i:s');
- DB::table('orders_total')->insert($data);
- }
- protected function updateOrderTotal($trade_no, $transaction_id)
- {
- $data['status'] = 'PAID';
- $data['transaction_id'] = $transaction_id;
- $data['pay_end_at'] = date('Y-m-d H:i:s');
- //DB::table('orders_total')->where('trade_no',$trade_no)->update($data);
- }
- protected function successPayPushMsg($uid, $product_info, $order_id)
- {
- $force_sub_info = $this->getSubscribeV2($uid);
- $data = UserService::getById($uid);
- try {
- if (!in_array($data->distribution_channel_id, [5, 123])) {
- //return false;
- }
- if ($force_sub_info) {
- //$content_format = "您好,你已经成功充值\r\n\r\n会员:%s\r\n会员ID:%s\r\n充值金额:%s\r\n充值状态:充值成功\r\n如有疑问,请点击用户中心-联系客服\r\n\r\n><a href='%s'>点击继续阅读上次阅读</a>";
- if (SubstituteOrderService::getByOrderId($order_id)) {
- $content_format = "代充值客服消息:\r\n\r\n你好,您的好友为你代付成功\r\n会员:%s\r\n会员ID:%s\r\n代付金额:%s\r\n充值状态:充值成功\r\n赠送的礼物道具在阅读页-送礼物\r\n\r\n><a href='%s'>点击继续上次阅读</a>";
- } else {
- $content_format = "您好,你已经成功充值\r\n\r\n会员:%s\r\n会员ID:%s\r\n充值金额:%s\r\n充值状态:充值成功\r\n赠送的礼物道具在阅读页-送礼物\r\n\r\n><a href='%s'>点击继续上次阅读</a>";
- }
- if ($product_info->type == 'YEAR_ORDER') {
- $money_text = $product_info->price . '元(尊贵的年费VIP会员)';
- } elseif ($product_info->type == 'TICKET_RECHARGE') {
- if ($product_info->given) {
- $money_text = $product_info->price . '元(' . ($product_info->price * 100) . '书币+赠送' . $product_info->given . '书币)';
- } else {
- $money_text = $product_info->price . '元(' . ($product_info->price * 100) . '书币)';
- }
- } else {
- $money_text = '未知';
- }
- $delay = 0;
- $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);
- foreach ($force_sub_info as $item) {
- $appid = $item->appid;
- $gzh = OfficialAccountService::officialAccountByAppid(compact('appid'));
- $top_url = OfficialAccountService::getTopUrl($gzh->service_type_info);
- if ($gzh->service_type_info == 1) {
- $top_content = "\r\n\r\n为方便阅读,请<a href='{$top_url}'>设为星标</a>";
- } else {
- $top_content = "\r\n\r\n为方便阅读,请<a href='{$top_url}'>置顶公众号</a>";
- }
- $content .= $top_content . $top_content . $top_content;
- $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) {
- Log::info('pay_success_push error');
- Log::info($e);
- }
- $this->notifyXiyue($uid, $product_info->price, $data->distribution_channel_id, $data->openid);
- return true;
- }
- private function orderStatistical($order)
- {
- try {
- $send_data = array(
- 'type' => 'order_info',
- 'data' => $order->toArray()
- );
- $send = new SendStatisticsList($send_data);
- $job = ($send)->onConnection('rabbitmq')->delay(0)->onQueue('send_statistics_list');
- dispatch($job);
- } catch (\Exception $e) {
- Log::info($e);
- }
- //灵界的推送统计\App\Modules\Statistic\Services\WapVisitStatService::customerAllStats
- try {
- if ($order->from_type) {
- $pv = Redis::hget('push:distribution_channel_id:allpv', $order->from_type);
- if ($pv) {
- Redis::sadd('push:all:paidnum:from:' . $order->from_type, $order->uid);
- $old = Redis::hget('push:all:paidamount', $order->from_type);
- if ($old) {
- Redis::hset('push:all:paidamount', $order->from_type, $old + $order->price);
- } else {
- Redis::hset('push:all:paidamount', $order->from_type, $order->price);
- }
- }
- }
- if (isset($order->pay_merchant_id) && $order->pay_merchant_id) //临时统计队列清0 用于报警
- {
- $key = 'pay_merchant:' . $order->pay_merchant_id;
- Redis::hset($key, 'unpaid_num', 0);
- }
- } catch (\Exception $e) { }
- }
- private function getSubscribe($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, $distribution_channel_id)
- {
- $subscribe = $this->getSubscribe($uid);
- if ($subscribe && isset($subscribe->appid)) {
- $official = DB::table('official_accounts')->where('appid', $subscribe->appid)->select('nickname')->first();
- if ($official && isset($official->nickname)) {
- return $official->nickname;
- }
- }
- $res = OfficialAccountService::canUseOfficialAccountByChannelId(compact('distribution_channel_id'));
- if (isset($res->nickname) && !empty($res->nickname)) {
- return $res->nickname;
- }
- try {
- $official = DB::table('official_accounts')
- ->where('distribution_channel_id', $distribution_channel_id)
- ->where('is_auth', 1)
- ->orderBy('id', 'desc')
- ->select('nickname')->first();
- if ($official && isset($official->nickname)) {
- return $official->nickname;
- }
- } catch (\Exception $e) { }
- return '';
- }
- private function payAlert($pay_merchant_id, $trade_no = '', $pay_info = '', $n = 0)
- {
- $change_pay_id = 96;
- if ($pay_merchant_id == 96) {
- $change_pay_id = 9;
- }
- try {
- $time = (int) date('G');
- $change = false;
- if ($time <= 8 || $time >= 23) {
- if (!$pay_info && $pay_merchant_id != $change_pay_id) {
- DB::table('distribution_channels')->where('pay_merchant_id', $pay_merchant_id)->update(['pay_merchant_id' => $change_pay_id]);
- $change = true;
- }
- }
- //$number,$template_type,$param=array()
- $phone_arr = ['15868100210', '15088790066', '13858057394', '18668029091', '18668420256'];
- //$phone_arr = ['18668029091'];
- $param = ['pay_id' => $pay_merchant_id];
- if ($n) {
- $template_type = 'pay_channel_remind';
- //$content = '支付通道:' . $pay_merchant_id . ',获取授权信息失败';
- } else {
- $template_type = 'pay_channel_remind';
- //$content = '支付通道:' . $pay_merchant_id . ',订单号为' . $trade_no . '支付异常,异常信息:' . json_encode($pay_info);
- }
- if ($change) {
- $template_type = 'pay_channel_change';
- $param = ['pay_id' => $pay_merchant_id, 'new_pay_id' => $change_pay_id];
- }
- $last_alert_time = Redis::hget('autopayalert', $pay_merchant_id);
- if ($last_alert_time && (time() - $last_alert_time) <= 3600) {
- return;
- }
- Redis::hset('autopayalert', $pay_merchant_id, time());
- foreach ($phone_arr as $phone) {
- AliSMS::send($phone, $template_type, $param);
- }
- } catch (\Exception $e) { }
- }
- private function createSubstituteOrder($order_id, $uid, $pay_uid)
- {
- SubstituteOrderService::createOrder($order_id, $uid, $pay_uid);
- }
- private function recordOtherParam($order_id, $uid)
- {
- $gxhp = ReadRecordService::getByField($uid, 'gxhp');
- if ($gxhp) {
- OrderParamService::create($order_id, $gxhp);
- }
- }
- private function substituteOrderPrice($order_id, $prize_fee = 500)
- {
- SubstituteOrderService::SubstituteOrderPrize($order_id, $prize_fee);
- }
- private function updateUserSendOrderId(int $uid, $send_order_id)
- {
- if ($send_order_id && $uid) {
- $user = UserService::getById($uid);
- if ($user && !$user->send_order_id) {
- UserService::updateInfo($uid, compact('send_order_id'));
- }
- }
- }
- /**
- * 测书智能推送统计 付费用户数、充值金额
- * @param $bid
- * @param $uid
- * @param $price
- */
- private function smartPushTestBookPaidUv($bid, $uid, $price)
- {
- $smart_bid = ReadRecordService::getSmartPush($uid);
- if ($smart_bid && in_array($bid, $smart_bid)) {
- try {
- //$key = 'smartPushTestBookPaidUv:bid:%s';
- //Redis::sadd(sprintf($key, $bid), $uid);
- $now_amount = Redis::hget('smartPushTestBookPaidAmount', $bid);
- if (!$now_amount) {
- $now_amount = 0;
- }
- Redis::hset('smartPushTestBookPaidAmount', $bid, $now_amount + $price);
- } catch (\Exception $e) { }
- }
- }
- /**
- * 获取用户第几次充值
- * @param $uid
- * @return int
- */
- private function getChargeTimes($uid)
- {
- $count = OrderService::getUserChargeTimes($uid);
- return $count + 1;
- }
- //米玩 订单转移
- private function transfer($distribution_channel_id)
- {
- if (in_array($distribution_channel_id, explode(',', redisEnv('MIWAN_TRANSFER_CHANNEL_ID', 1)))) {
- $random = random_int(1, 100);
- $miwan_transfer_probability = redisEnv('MIWAN_TRANSFER_PROBABILITY', 0);
- $miwan_transfer_to_channel_id = redisEnv('MIWAN_TRANSFER_TO_CHANNEL_ID', 0);
- if ($miwan_transfer_to_channel_id && $random <= $miwan_transfer_probability) {
- return $miwan_transfer_to_channel_id;
- }
- }
- return 0;
- }
- private function userProperty($uid, $price, $charge_type, $activity_id)
- {
- /*try{
- $old_property = UserDivisionCpcPropertyService::getUserProperty($uid);
- if(!$activity_id){
- $this->chargeGiveGift($uid,$old_property,$price,$charge_type);
- }
- $userproperty = UserDivisionCpcPropertyService::getUserSubscribeAndChargeInfoByUid($uid);
- if(!$userproperty) {
- return ;
- }
- UserDivisionCpcPropertyService::createorUpdate($userproperty);
- }catch (\Exception $e){}*/
- try {
- $old_property = UserDivisionCpcPropertyService::getUserPropertyV2($uid);
- if (!$activity_id) {
- $this->chargeGiveGift($uid, $old_property, $price, $charge_type);
- }
- $userproperty = UserDivisionCpcPropertyService::calculateUserPropertyV2($uid);
- if (!$userproperty) {
- return;
- }
- UserDivisionCpcPropertyService::createorUpdateV2($userproperty);
- } catch (\Exception $e) {
- Log::error('pay userProperty error');
- Log::error($e);
- }
- }
- private function huaweiActivity($activity_id, $uid, $product_id)
- {
- return;
- /*$huawei_activity_id = redisEnv('HUAWEI_ACTIVITY_ID');
- if($huawei_activity_id && $activity_id && $activity_id == $huawei_activity_id){
- $product_id_relate_lottery_count = ['6117'=>1,'6118'=>2,'6119'=>4,'6120'=>8];
- if(isset($product_id_relate_lottery_count[$product_id])){
- $info = DB::table('huaweilottery_user_counts')->where('uid',$uid)->select('count')->first();
- if($info){
- DB::table('huaweilottery_user_counts')->where('uid',$uid)->update([
- 'uid'=>$uid,
- 'count'=>$info->count+$product_id_relate_lottery_count[$product_id],
- 'updated_at'=>date('Y-m-d H:i:s')
- ]);
- }else{
- DB::table('huaweilottery_user_counts')->insert([
- 'uid'=>$uid,
- 'count'=>$product_id_relate_lottery_count[$product_id],
- 'updated_at'=>date('Y-m-d H:i:s'),
- 'created_at'=>date('Y-m-d H:i:s')
- ]);
- }
- }
- }*/
- }
- private function palmpaySpecial($transaction_id, $trade_no)
- {
- try {
- $order = OrderService::getByTradeNo($trade_no);
- $product_id = $order->product_id;
- $product = ProductService::getProductSingle($product_id);
- $init_order = [
- 'distribution_channel_id' => $order->distribution_channel_id,
- 'uid' => $order->uid,
- 'product_id' => $product_id,
- 'price' => $order->price,
- 'pay_type' => 1,
- 'trade_no' => $order->uid . '-' . $order->id,
- 'pay_merchant_source' => $order->pay_merchant_source,
- 'pay_merchant_id' => $order->pay_merchant_id,
- 'create_ip' => $order->create_ip,
- 'send_order_id' => $order->send_order_id,
- 'send_order_name' => $order->send_order_name,
- 'order_type' => $order->order_type,
- 'from_bid' => $order->from_bid,
- 'from_type' => $order->from_type,
- 'activity_id' => $order->activity_id,
- 'inner_send_order_id' => $order->inner_send_order_id,
- 'status' => 'PAID',
- 'transaction_id' => $transaction_id,
- 'pay_end_at' => date('Y-m-d H:i:s')
- ];
- OrderService::save_order($init_order);
- if ($product->type == 'YEAR_ORDER') {
- Log::info('palmpaySpecial YEAR_ORDER');
- $this->yearOrder($order->uid, $order->distribution_channel_id, $order->price, $order->send_order_id);
- } elseif ($product->type == 'BOOK_ORDER') {
- Log::info('palmpaySpecial BOOK_ORDER');
- $this->bookOrder($product_id, $order->ui, $order->send_order_id, $order->price, $order->distribution_channel_id);
- } elseif ($product->type == 'TICKET_RECHARGE' || $product->type == 'NEW_USER') {
- Log::info('palmpaySpecial TICKET_RECHARGE');
- $this->userCharge($product, $order->uid);
- } elseif ($product->type == 'FOREVER') {
- Log::info('palmpaySpecial-------FOREVER');
- $this->foreverFreeOrder($order->uid, $order->distribution_channel_id, $order->price, $order->send_order_id);
- }
- } catch (\Exception $e) {
- Log::info($e);
- }
- }
- private function chargeGiveGift($uid, $property, $price, $charge_type)
- {
- $gift = BookGiftsService::chargeGiveGift($property, $price, $charge_type);
- if ($gift) {
- UserGiftService::addGift($uid, $gift);
- }
- return;
- }
- private function orderParamWso($uid, $order_id)
- {
- list($new_outer, $new_inner, $new_total) = ReadRecordService::getByMultiField($uid, 'new_outer', 'new_inner', 'new_total');
- if (!$new_outer && !$new_inner && !$new_total) {
- return;
- }
- if (!$new_total) return;
- $new_outer = $new_outer ? $new_outer : 0;
- $new_inner = $new_inner ? $new_inner : 0;
- $total_type = '';
- $total_param_id = 0;
- if (is_numeric($new_total)) {
- $send_order_info = SendOrderService::getById($new_total);
- $total_param_id = $new_total;
- $total_type = 'none';
- if ($send_order_info && isset($send_order_info->promotion_type)) {
- if ($send_order_info->promotion_type == 'EXTERNAL') {
- $total_type = 'OUTER';
- }
- if ($send_order_info->promotion_type == 'INTERNAL') {
- $total_type = 'INNER';
- }
- }
- }
- if (str_contains($new_total, 'custom')) {
- $total_type = 'CUSTOM';
- $temp = explode('_', $new_total);
- if (isset($temp[1]) && is_numeric($temp[1])) {
- $total_param_id = $temp[1];
- }
- }
- if (str_contains($new_total, 'template')) {
- $total_type = 'TEMPLATE';
- $temp = explode('_', $new_total);
- if (isset($temp[1]) && is_numeric($temp[1])) {
- $total_param_id = $temp[1];
- }
- }
- if ($total_type) {
- OrderParamWsoService::createOrder(
- $order_id,
- $new_inner,
- $new_outer,
- $total_param_id,
- $new_total,
- $total_type
- );
- }
- }
- private function exchangeUpdateAndCreated($order_id)
- {
- /*try{
- $info = DB::table('orders')->where('id',$order_id)->select('created_at','updated_at')->first();
- DB::table('orders')->where('id',$order_id)
- ->update([
- 'created_at'=>$info->updated_at,
- 'updated_at'=>$info->created_at
- ]);
- }catch (\Exception $e){}*/ }
- private function notifyXiyue($uid, $price, $channel_id, $openid, $type = 'recharge')
- {
- if ($channel_id != 6985) return;
- //$xiyue_user = DB::table('xiyue_zsy_users')->where('uid',$uid)->select('openid')->first();
- $xiyue_host = env('XIYUE_HOST');
- if ($xiyue_host) {
- $client = new Client(['timeout' => 5]);
- $url = $xiyue_host . '/order/success';
- $param = ['openid' => $openid, 'price' => $price];
- $param['sign'] = _sign($param, '8T5MJy4FsJoZspq8');
- try {
- $client->request('post', $url, ['form_params' => $param])->getBody()->getContents();
- } catch (\Exception $e) { }
- }
- }
- public function query()
- {
- $pay_merchant = PayMerchant::find(48);
- $instance = WechatPay::Union($pay_merchant->source, json_decode($pay_merchant->config_info, true));
- if ($instance->query('319420190918172727164500482012')) {
- \Log::info('success');
- }
- }
- public function refund()
- {
- $pay_merchant = PayMerchant::find(48);
- $instance = WechatPay::Union($pay_merchant->source, json_decode($pay_merchant->config_info, true));
- $data = [
- 'trade_no' => '319420190918172727164500482012',
- 'price' => 1
- ];
- if ($instance->refund($data)) {
- \Log::info('success');
- }
- }
- }
|