OrdersController.php 67 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612
  1. <?php
  2. namespace App\Http\Controllers\Wap\Pay;
  3. use App\Modules\Book\Services\ChapterService;
  4. use App\Modules\OfficialAccount\Services\OfficialAccountService;
  5. use App\Modules\Subscribe\Services\OrderParamService;
  6. use App\Modules\Subscribe\Services\SubstituteOrderService;
  7. use App\Modules\User\Services\ReadRecordService;
  8. use Illuminate\Routing\Controller;
  9. use App\Libs\Pay\WechatPay;
  10. use Illuminate\Http\Request;
  11. use App\Modules\Subscribe\Services\YearOrderService;
  12. use App\Modules\Subscribe\Services\BookOrderService;
  13. use App\Modules\Subscribe\Services\OrderService;
  14. use App\Modules\Product\Services\ProductService;
  15. use App\Modules\Book\Services\BookConfigService;
  16. use App\Modules\User\Services\UserService;
  17. use App\Modules\Channel\Services\ChannelService;
  18. use Log;
  19. use DB;
  20. use Cookie;
  21. use Redis;
  22. use Hashids;
  23. use EasyWeChat\Foundation\Application;
  24. use EasyWeChat\Support\XML;
  25. use App\Modules\OfficialAccount\Services\ForceSubscribeService;
  26. use App\Jobs\SendTexts;
  27. use App\Jobs\SendStatisticsList;
  28. use App\Libs\AliSMS;
  29. use App\Modules\Activity\Services\ActivityService;
  30. use App\Modules\SendOrder\Services\SendOrderService;
  31. use GuzzleHttp\Client;
  32. class OrdersController extends Controller
  33. {
  34. /**
  35. * @apiDefine pay 支付
  36. */
  37. /**
  38. * 支付唤起入口
  39. * 功能:授权、请求支付参数、并跳转微信支付
  40. * TODO 暂时不创建订单
  41. * tail -f /var/www/ydy_wap_backend/storage/logs/laravel-2017-12-01.log
  42. * zwap/goToPay?distribution_channel_id=3&price=1&uid=3
  43. * @apiVersion 1.0.0
  44. * @apiDescription 支付
  45. * @api {get} http://pay.aizhuishu.com/goToPay 支付
  46. * @apiGroup pay
  47. * @apiName wxindex
  48. * @apiParam {Int} product_id product_id
  49. * @apiParam {Int} uid uid
  50. * @apiParam {Int} distribution_channel_id distribution_channel_id
  51. * @apiParam {String} pay_redirect_url pay_redirect_url
  52. * @apiSuccess {int} code 状态码
  53. * @apiSuccessExample {json} Success-Response:
  54. * HTTP/1.1 200 OK
  55. * {
  56. * code: 0,
  57. * msg: "",
  58. * data: {
  59. * }
  60. */
  61. function wxindex(Request $request)
  62. {
  63. $product_id = $request->has('product_id') ? $request->get('product_id') : '';
  64. $uid = $request->has('uid') ? $request->get('uid') : '';
  65. $distribution_channel_id = $request->has('distribution_channel_id') ? $request->get('distribution_channel_id') : '';
  66. $pay_redirect_url = $request->has('pay_redirect_url') ? $request->get('pay_redirect_url') : '';
  67. $send_order_id = $request->has('send_order_id') ? $request->get('send_order_id') : 0;
  68. $activity_id = $request->has('activity_id') ? $request->get('activity_id') : 0;
  69. $ip = $request->has('ip') ? $request->get('ip') : '';
  70. $n = $request->has('n') ? $request->get('n') : 0;
  71. if ($send_order_id && strlen($send_order_id) > 50) {
  72. try {
  73. $send_order_id = decrypt($send_order_id);
  74. } catch (\Exception $e) {
  75. $send_order_id = 0;
  76. }
  77. }
  78. if ($send_order_id && strlen($send_order_id) > 50) {
  79. $send_order_id = 0;
  80. }
  81. //活动判断
  82. if ($activity_id) {
  83. $limit = $request->get('limit', 0);
  84. if ($limit && $limit == 1) {
  85. $order = OrderService::userIsParticipateActivity($uid, $activity_id);
  86. if ($order) {
  87. $activity = ActivityService::getById($activity_id);
  88. if ($activity) {
  89. $url = env('PROTOCOL', 'https') . '://site' . encodeDistributionChannelId($distribution_channel_id) . '.' . env('CUSTOM_HOST', 'leyuee') . '.com' . $activity->activity_page;
  90. return redirect()->to($url);
  91. }
  92. return '';
  93. }
  94. }
  95. }
  96. $suid= $request->get('suid',0);
  97. if ($suid) {
  98. $user_info = UserService::getById($uid);
  99. $distribution_channel_id = $user_info->distribution_channel_id;
  100. $pay_redirect_url = 1;
  101. }
  102. if (empty($product_id) || empty($uid) || empty($distribution_channel_id) || empty($pay_redirect_url)) {
  103. return response()->error('WAP_PARAM_ERROR');
  104. }
  105. if($suid && $suid == $uid){
  106. return back();
  107. }
  108. $openid = $request->has('openid') ? $request->get('openid') : '';
  109. $bid = $request->has('bid') ? $request->get('bid') : 0;
  110. $hash_bid = $bid;
  111. $fromtype = $request->has('fromtype') ? $request->get('fromtype') : $request->get('from');
  112. if ($fromtype && strlen($fromtype) > 50) {
  113. try {
  114. $fromtype = decrypt($fromtype);
  115. } catch (\Exception $e) {
  116. $fromtype = 'main';
  117. }
  118. }
  119. if ($fromtype && strlen($fromtype) > 50) {
  120. $fromtype = 'main';
  121. }
  122. //根据分校id获取支付配置id
  123. Log::info($request->all());
  124. $channel = ChannelService::getById($distribution_channel_id);
  125. if (!$channel || !$channel->pay_merchant_id) {
  126. return response()->error('WAP_PARAM_ERROR');
  127. }
  128. //获取支付类型
  129. $pay_merchant = DB::table('pay_merchants')->select('id','appid', 'source', 'config_info')->where('id', $channel->pay_merchant_id)->where('is_enabled', 1)->first();
  130. if (!$pay_merchant || !$pay_merchant->appid || !$pay_merchant->source) return response()->error('WAP_PARAM_ERROR');
  131. if($pay_merchant->source == 'PALMPAYV2'){
  132. return redirect()->to($this->paympay($request,$pay_merchant));
  133. }
  134. //重定向 获取用户信息的次数
  135. $n++;
  136. if ($n >= 5) {
  137. //重定向次数过多,则授权公众号出问题
  138. $this->payAlert($channel->pay_merchant_id, '', '', $n);
  139. $back_url = env('PROTOCOL') . '://site' . encodeDistributionChannelId($distribution_channel_id) . '.' . env('CUSTOM_HOST') . '.com' . '/pay';
  140. return redirect()->to($back_url);
  141. }
  142. if (empty($openid)) {
  143. $trade_no = date("YmdHis") . str_shuffle(hexdec(uniqid()));
  144. if(isset($_SERVER['HTTP_X_FORWARDED_FOR']) && $_SERVER['HTTP_X_FORWARDED_FOR']){
  145. $ip = $_SERVER['HTTP_X_FORWARDED_FOR'];
  146. }else{
  147. $ip = get_client_ip();
  148. }
  149. $params = compact('uid', 'product_id', 'distribution_channel_id', 'send_order_id', 'bid', 'trade_no', 'pay_redirect_url', 'fromtype', 'activity_id', 'n','suid','ip');
  150. $redirect_url = env('CREATE_PAY_URL') . '?' . http_build_query($params);
  151. //$redirect_url = env('CREATE_PAY_URL').'?uid='.$uid.'&product_id='.$product_id.'&distribution_channel_id='
  152. // .$distribution_channel_id.'&send_order_id='.$send_order_id.'&bid='.$bid.'&pay_redirect_url='.urlencode($pay_redirect_url)
  153. $auth_url = env('AUTH_URL') . '?gzh_app_id=' . $pay_merchant->appid . '&redirect_url=' . urlencode($redirect_url);
  154. Log::info('redirect_auth_url:' . $auth_url);
  155. header("Location:" . $auth_url);
  156. exit();
  157. }
  158. $trade_no = $request->input('trade_no');
  159. $order_info = OrderService::getByTradeNo($trade_no);
  160. if ($order_info) return response()->error('WAP_SYS_ERROR');
  161. $cid = $request->has('cid') ? $request->get('cid') : '';
  162. $product_info = ProductService::getProductSingle($product_id,false);
  163. //新用户只能冲一次
  164. //Log::info('新用户只能冲一次:' .$product_info->type);
  165. if($this->isNewUserSecondCharge($product_info->type,$product_id,$uid)){
  166. $url = env('PROTOCOL', 'https') . '://site' . encodeDistributionChannelId($distribution_channel_id) . '.' . env('CUSTOM_HOST', 'leyuee') . '.com/pay';
  167. return redirect()->to($url);
  168. }
  169. $price = $product_info->price * 100;
  170. if ($uid < 32) {
  171. $price = 1;
  172. }
  173. try {
  174. $send_order_id = (int)Redis::hget('book_read:' . $uid, 'send_order_id');
  175. } catch (\Exception $e) {}
  176. $this->updateUserSendOrderId($uid,$send_order_id);
  177. if (in_array($uid, explode(',', env('TEST_UID')))) {
  178. $price = 1;
  179. }
  180. if ($bid) {
  181. try {
  182. $bid = Hashids::decode($bid)[0];
  183. } catch (\Exception $e) {$bid = 0;}
  184. }
  185. try {
  186. $key = 'leyuee:to_send_not_pay_uid:distribution_channel_id:' . $distribution_channel_id;
  187. Redis::hset($key, $uid, time());
  188. $date = date('Y-m-d');
  189. Redis::hincrby('order_stat:' . $distribution_channel_id, 'order_num_' . $date, 1);
  190. if ($send_order_id) {
  191. Redis::hincrby('order_promotion_stat:' . $send_order_id, 'order_num_' . $date, 1);
  192. Redis::hincrby('order_promotion_stat:' . $send_order_id, 'total', 1);
  193. }
  194. } catch (\Exception $e) {
  195. }
  196. $data = [];
  197. $data['price'] = $price;
  198. $data['create_ip'] = $ip;
  199. $data['openid'] = $openid;//
  200. $data['body'] = 'novel read';
  201. $official_name = $this->getSubscribeOfficialName($uid,$distribution_channel_id);
  202. if ($official_name) {
  203. $data['body'] = '搜索公众号' . $official_name . ',请继续阅读';
  204. }
  205. $data['detail'] = 'novel read';
  206. $data['trade_no'] = $trade_no;
  207. $data['remark'] = json_encode(
  208. [
  209. 'uid' => $uid,
  210. 'dcd' => $distribution_channel_id,
  211. 'bid' => $bid,
  212. 'cp' => $ip,
  213. 'pms' => $pay_merchant->source,
  214. 'pmi' => $channel->pay_merchant_id,
  215. 'pd' => $product_id,
  216. 'soi' => $send_order_id,
  217. ]
  218. );
  219. if ($product_info->type == 'YEAR_ORDER') {
  220. $order_type = 'YEAR';
  221. } elseif ($product_info->type == 'BOOK_ORDER') {
  222. $order_type = 'BOOK';
  223. } elseif ($product_info->type == 'TICKET_RECHARGE') {
  224. $order_type = 'RECHARGE';
  225. } elseif($product_info->type == 'NEW_USER'){
  226. $order_type = 'RECHARGE';
  227. }else{
  228. $order_type = 'UNKNOWN';
  229. }
  230. /*
  231. $this->createOrderTotal([
  232. 'distribution_channel_id'=>$distribution_channel_id,
  233. 'uid'=>$uid,
  234. 'product_id'=>$product_id,
  235. 'price'=>$price/100,
  236. 'pay_type'=>1,
  237. 'trade_no'=>$data['trade_no'],
  238. 'pay_merchant_source'=>$pay_merchant->source,
  239. 'pay_merchant_id'=>$channel->pay_merchant_id,
  240. 'create_ip'=>$request->getClientIp(),
  241. 'send_order_id'=>$send_order_id,
  242. 'order_type'=>$order_type,
  243. 'from_bid'=>$bid
  244. ]);*/
  245. $send_order_name = '';
  246. if ($send_order_id) {
  247. $send_order_info = SendOrderService::getById($send_order_id);
  248. if ($send_order_info && isset($send_order_info->name) && !empty($send_order_info->name)) {
  249. $send_order_name = $send_order_info->name;
  250. }
  251. }
  252. if($suid){
  253. $user_info = UserService::getById($uid);
  254. $distribution_channel_id = $user_info->distribution_channel_id;
  255. }
  256. $from_bid = ReadRecordService::getSimpleFirstReadRecord($uid);
  257. $inner_send_order_id = ReadRecordService::getInnerSendOrderId($uid);
  258. $init_order = [
  259. 'distribution_channel_id' => $distribution_channel_id,
  260. 'uid' => $uid,
  261. 'product_id' => $product_id,
  262. 'price' => $price / 100,
  263. 'pay_type' => 1,
  264. 'trade_no' => $data['trade_no'],
  265. 'pay_merchant_source' => $pay_merchant->source,
  266. 'pay_merchant_id' => $channel->pay_merchant_id,
  267. 'create_ip' => $ip,
  268. 'send_order_id' => $send_order_id,
  269. 'send_order_name' => $send_order_name,
  270. 'order_type' => $order_type,
  271. 'from_bid' => $from_bid,
  272. 'from_type' => $fromtype,
  273. 'activity_id' => $activity_id,
  274. 'inner_send_order_id'=>$inner_send_order_id
  275. ];
  276. $result = $this->createUnPayOrder($init_order);
  277. //订单创建成功后增加统计
  278. if($result)
  279. {
  280. $this->orderCreated($init_order);
  281. $this->recordOtherParam($result->id, $uid);
  282. }
  283. if ($request->get('suid')) {
  284. $this->createSubstituteOrder($result->id, $uid, $request->get('suid'));
  285. }
  286. Log::info($data);
  287. $config = [];
  288. if ($pay_merchant->config_info) {
  289. $config = json_decode($pay_merchant->config_info, true);
  290. }
  291. $wechatPay = WechatPay::instance($pay_merchant->source, $config);
  292. if (!$wechatPay) return response()->error('WAP_PARAM_ERROR');
  293. $pay_info = $wechatPay->send($data);
  294. if (!$pay_info) {
  295. $pay_info = $wechatPay->send($data);
  296. }
  297. if (!isset($pay_info['appId']) || !isset($pay_info['package'])) {
  298. //支付异常
  299. $this->payAlert($channel->pay_merchant_id, $trade_no, $pay_info);
  300. }
  301. $pay_info['pay_redirect_url'] = urldecode($pay_redirect_url);
  302. if ($request->has('cid')) {
  303. $pay_info['pay_redirect_url'] = $pay_info['pay_redirect_url'] . '&cid=' . $request->input('cid');
  304. }
  305. // if ($hash_bid) {
  306. // $pay_info['pay_redirect_url'] = $pay_info['pay_redirect_url'] . '&bid=' . $hash_bid;
  307. // }
  308. if ($suid) {
  309. $prize_fee = (int)(($product_info->price*100)*0.1);
  310. $help_pay_page_channel_id = env('HELP_PAY_PAGE_CHANNEL_ID', 123);
  311. $help_pay_page_channel_id = $distribution_channel_id;
  312. $url_format = '%s://site%s.%s.com/helppay?back=%s&su=%s';
  313. $pay_info['pay_redirect_url'] = $pay_redirect_url = sprintf(
  314. $url_format,
  315. env('PROTOCOL'),
  316. encodeDistributionChannelId($help_pay_page_channel_id),
  317. env('CUSTOM_HOST'),
  318. $prize_fee,
  319. $uid
  320. );
  321. }
  322. $pay_url_info = parse_url($pay_redirect_url);
  323. $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']);
  324. //$h5_scheme = env('H5_SCHEME','https');
  325. //$jsSdkSign = $this->jsSdkSign($pay_info,str_replace('http',$h5_scheme,url()->current()));
  326. Log::info('$pay_info is');
  327. $jsSdkSign = 0;
  328. Log::info($pay_info);
  329. Log::info('jsSdkSign---- :' . $jsSdkSign);
  330. $pay_order = $trade_no;
  331. // 注册动作-》创建订单
  332. $action_type = 'CreateOrder';
  333. $param = [
  334. 'openid' => isset($openid)?$openid:'0',
  335. 'uid' =>isset($uid)?$uid:'0',
  336. 'order_sn' => isset($trade_no)?$trade_no:'0',
  337. 'amount' => isset($price)?$price:'0',
  338. ];
  339. UserService::PushUserActionToQueue($action_type,$distribution_channel_id,$param);
  340. return view('pay.order.index', compact('pay_info', 'referer', 'jsSdkSign', 'pay_order'));
  341. }
  342. private function paympay(Request $request,$pay_merchant){
  343. $product_id = $request->get('product_id');
  344. $uid = $request->get('uid');
  345. $distribution_channel_id = $request->get('distribution_channel_id');
  346. $pay_redirect_url = $request->get('pay_redirect_url');
  347. $send_order_id = $request->get('send_order_id',0) ;
  348. $activity_id = $request->get('activity_id',0) ;
  349. $suid= $request->get('suid',0);
  350. $bid = $request->has('bid') ? $request->get('bid') : 0;
  351. $hash_bid = $bid;
  352. $fromtype = $request->has('fromtype') ? $request->get('fromtype') : $request->get('from','main');
  353. //根据分校id获取支付配置id
  354. Log::info($request->all());
  355. $trade_no =$trade_no = date("YmdHis") . str_shuffle(hexdec(uniqid()));
  356. $order_info = OrderService::getByTradeNo($trade_no);
  357. if ($order_info) return response()->error('WAP_SYS_ERROR');
  358. $cid = $request->has('cid') ? $request->get('cid') : '';
  359. $product_info = ProductService::getProductSingle($product_id,false);
  360. //新用户只能冲一次
  361. //Log::info('新用户只能冲一次:' .$product_info->type);
  362. if($this->isNewUserSecondCharge($product_info->type,$product_id,$uid)){
  363. $url = env('PROTOCOL', 'https') . '://site' . encodeDistributionChannelId($distribution_channel_id) . '.' . env('CUSTOM_HOST', 'leyuee') . '.com/pay';
  364. return redirect()->to($url);
  365. }
  366. $price = $product_info->price * 100;
  367. if ($uid < 32) {
  368. $price = 1;
  369. }
  370. if (!$send_order_id) {
  371. try {
  372. $send_order_id = (int)Redis::hget('book_read:' . $uid, 'send_order_id');
  373. } catch (\Exception $e) {}
  374. }
  375. $this->updateUserSendOrderId($uid,$send_order_id);
  376. if (in_array($uid, explode(',', env('TEST_UID')))) {
  377. $price = 1;
  378. }
  379. try {
  380. $key = 'leyuee:to_send_not_pay_uid:distribution_channel_id:' . $distribution_channel_id;
  381. Redis::hset($key, $uid, time());
  382. $date = date('Y-m-d');
  383. Redis::hincrby('order_stat:' . $distribution_channel_id, 'order_num_' . $date, 1);
  384. if ($send_order_id) {
  385. Redis::hincrby('order_promotion_stat:' . $send_order_id, 'order_num_' . $date, 1);
  386. Redis::hincrby('order_promotion_stat:' . $send_order_id, 'total', 1);
  387. }
  388. } catch (\Exception $e) {
  389. }
  390. if(isset($_SERVER['HTTP_X_FORWARDED_FOR']) && $_SERVER['HTTP_X_FORWARDED_FOR']){
  391. $ip = $_SERVER['HTTP_X_FORWARDED_FOR'];
  392. }else{
  393. $ip = get_client_ip();
  394. }
  395. $data = [];
  396. $data['price'] = $price;
  397. $data['create_ip'] = $ip;
  398. $data['body'] = 'novel read';
  399. $official_name = $this->getSubscribeOfficialName($uid,$distribution_channel_id);
  400. if ($official_name) {
  401. $data['body'] = '搜索公众号' . $official_name . ',请继续阅读';
  402. }
  403. $data['detail'] = 'novel read';
  404. $data['trade_no'] = $trade_no;
  405. if ($product_info->type == 'YEAR_ORDER') {
  406. $order_type = 'YEAR';
  407. } elseif ($product_info->type == 'BOOK_ORDER') {
  408. $order_type = 'BOOK';
  409. } elseif ($product_info->type == 'TICKET_RECHARGE') {
  410. $order_type = 'RECHARGE';
  411. } elseif($product_info->type == 'NEW_USER'){
  412. $order_type = 'RECHARGE';
  413. }else{
  414. $order_type = 'UNKNOWN';
  415. }
  416. $send_order_name = '';
  417. if ($send_order_id) {
  418. $send_order_info = SendOrderService::getById($send_order_id);
  419. if ($send_order_info && isset($send_order_info->name) && !empty($send_order_info->name)) {
  420. $send_order_name = $send_order_info->name;
  421. }
  422. }
  423. if($suid){
  424. $user_info = UserService::getById($uid);
  425. $distribution_channel_id = $user_info->distribution_channel_id;
  426. }
  427. $from_bid = ReadRecordService::getSimpleFirstReadRecord($uid);
  428. $inner_send_order_id = ReadRecordService::getInnerSendOrderId($uid);
  429. $init_order = [
  430. 'distribution_channel_id' => $distribution_channel_id,
  431. 'uid' => $uid,
  432. 'product_id' => $product_id,
  433. 'price' => $price / 100,
  434. 'pay_type' => 1,
  435. 'trade_no' => $data['trade_no'],
  436. 'pay_merchant_source' => 'PALMPAY',
  437. 'pay_merchant_id' => $pay_merchant->id,
  438. 'create_ip' => $ip,
  439. 'send_order_id' => $send_order_id,
  440. 'send_order_name' => $send_order_name,
  441. 'order_type' => $order_type,
  442. 'from_bid' => $from_bid,
  443. 'from_type' => $fromtype,
  444. 'activity_id' => $activity_id,
  445. 'inner_send_order_id'=>$inner_send_order_id
  446. ];
  447. $result = $this->createUnPayOrder($init_order);
  448. //订单创建成功后增加统计
  449. if($result)
  450. {
  451. $this->orderCreated($init_order);
  452. $this->recordOtherParam($result->id, $uid);
  453. }
  454. if ($suid) {
  455. $this->createSubstituteOrder($result->id, $uid, $suid);
  456. }
  457. if ($suid) {
  458. $prize_fee = (int)(($product_info->price*100)*0.1);
  459. //$help_pay_page_channel_id = env('HELP_PAY_PAGE_CHANNEL_ID', 123);
  460. $help_pay_page_channel_id = $distribution_channel_id;
  461. $url_format = '%s://site%s.%s.com/helppay?back=%s&su=%s';
  462. $pay_redirect_url = sprintf(
  463. $url_format,
  464. env('PROTOCOL'),
  465. encodeDistributionChannelId($help_pay_page_channel_id),
  466. env('CUSTOM_HOST'),
  467. $prize_fee,
  468. $uid
  469. );
  470. }
  471. $de_pay_redirect_url = urldecode($pay_redirect_url);
  472. /*if ($request->has('cid')) {
  473. $de_pay_redirect_url = $de_pay_redirect_url . '&cid=' . $request->get('cid');
  474. }*/
  475. $pay_url_info = parse_url($de_pay_redirect_url);
  476. $data['pay_wait_url'] = $pay_url_info['scheme'] . '://' . $pay_url_info['host'] . '/pay/waitv2?order=' . $data['trade_no'] . '&redirect=' . urlencode($de_pay_redirect_url);
  477. Log::info($data);
  478. $config = [];
  479. if ($pay_merchant->config_info) {
  480. $config = json_decode($pay_merchant->config_info, true);
  481. }
  482. $wechatPay = WechatPay::instance($pay_merchant->source, $config);
  483. \Log::info('$wechatPay is');
  484. //\Log::info($wechatPay);
  485. if (!$wechatPay) return response()->error('WAP_PARAM_ERROR');
  486. \Log::info('$wechatPay ok-------------------');
  487. $pay_info = $wechatPay->send($data);
  488. \Log::info('send ok-------------------');
  489. // 注册动作-》创建订单
  490. $action_type = 'CreateOrder';
  491. $param = [
  492. 'openid' => isset($openid)?$openid:'0',
  493. 'uid' =>isset($uid)?$uid:'0',
  494. 'order_sn' => isset($trade_no)?$trade_no:'0',
  495. 'amount' => isset($price)?$price:'0',
  496. ];
  497. \Log::info('FUCK_PALMPAYV2');
  498. UserService::PushUserActionToQueue($action_type,$distribution_channel_id,$param);
  499. return $pay_info;
  500. }
  501. public function waitPageV2(Request $request)
  502. {
  503. $order = $request->get('order');
  504. $order = (string)$order;
  505. $url = urldecode($request->get('redirect'));
  506. if(substr_count($url,'?') >1){
  507. $url = str_replace_last('?','&',$url);
  508. }
  509. $url_info = parse_url($url);
  510. if (isset($url_info['query']) && !empty($url_info['query'])) {
  511. parse_str($url_info['query'], $path);
  512. if (isset($path['success']) && $path['success'] == 0) {
  513. if (isset($url_info['path']) && str_contains($url_info['path'], 'reader') && isset($path['cid']) && !empty($path['cid'])) {
  514. $chapter_info = ChapterService::getChapterNameByIdNoCheck($path['cid']);
  515. $path['cid'] = $chapter_info->prev_cid;
  516. $url = sprintf('%s://%s/reader?%s', $url_info['scheme'], $url_info['host'], http_build_query($path));
  517. }
  518. return redirect($url);
  519. }
  520. }
  521. if(isset($url_info['path']) && str_contains($url_info['path'], 'pay')){
  522. $url = sprintf('%s://%s/recent', $url_info['scheme'], $url_info['host']);
  523. return redirect($url);
  524. }
  525. return view('pay.order.wait', compact('order', 'url'));
  526. }
  527. private function isNewUserSecondCharge($charge_type,$product_id,$uid){
  528. //Log::info('新用户只能冲一次:' .$charge_type);
  529. if($charge_type == 'NEW_USER'){
  530. $result = OrderService::getUserOrderByProductId($uid,$product_id);
  531. //Log::info('isNewUserSecondCharge-------------------------');
  532. //Log::info($result);
  533. if($result){
  534. return true;
  535. }
  536. }
  537. return false;
  538. }
  539. //订单创建后统计
  540. private function orderCreated($init_order)
  541. {
  542. try {
  543. if(isset($init_order['pay_merchant_id']))
  544. {
  545. $key = 'pay_merchant:'.$init_order['pay_merchant_id'];
  546. Redis::hincrby($key,'unpaid_num',1);
  547. Redis::hset($key,'last_create_time', time());
  548. }
  549. }catch (\Exception $e)
  550. {
  551. }
  552. }
  553. //订单回调后统计
  554. private function orderPaid($init_order)
  555. {
  556. try {
  557. if(isset($init_order['pay_merchant_id']))
  558. {
  559. $key = 'pay_merchant:'.$init_order['pay_merchant_id'];
  560. Redis::hset($key,'unpaid_num',0);
  561. }
  562. }catch (\Exception $e)
  563. {
  564. }
  565. }
  566. public function reportError(Request $request)
  567. {
  568. $data = $request->post('data');
  569. DB::table('pay_page_error')->insert([
  570. 'msg' => $data,
  571. 'created_at' => date('Y-m-d H:i:s'),
  572. 'updated_at' => date('Y-m-d H:i:s')
  573. ]);
  574. return response()->success();
  575. }
  576. private function jsSdkSign($pay_info, $url)
  577. {
  578. if (!isset($pay_info['appId']) || !isset($pay_info['package'])) {
  579. return 0;
  580. }
  581. $appid = $pay_info['appId'];
  582. $jsapi_ticket = Redis::hget($appid, 'jsapi_ticket');
  583. //如果能获取到jsapi_ticket 则直接签名
  584. if ($jsapi_ticket) {
  585. $sign_arr = [
  586. 'noncestr' => $pay_info['nonceStr'],
  587. 'jsapi_ticket' => $jsapi_ticket,
  588. 'timestamp' => $pay_info['timeStamp'],
  589. 'url' => $url
  590. ];
  591. return sha1($this->arr_to_url($sign_arr));
  592. }
  593. //获取不到jsapi_ticket
  594. $app_secret_info = DB::table('official_setting')->select('secret')->first();
  595. if ($app_secret_info && !empty($app_secret_info->secret)) {
  596. $client = new Client(['timeout' => 5]);
  597. try {
  598. //获取access_token
  599. $url = 'https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=' . $appid . '&secret=' . $app_secret_info->secret;
  600. $res = $client->request('get', $url)->getBody()->getContents();
  601. if (!$res) {
  602. return 0;
  603. }
  604. $res = json_decode($res, 1);
  605. if (!isset($res['access_token']) || empty($res['access_token'])) {
  606. return 0;
  607. }
  608. Redis::hset($appid, 'access_token', $res['access_token']);
  609. //获取jsapi_ticket
  610. $res = null;
  611. $url = 'https://api.weixin.qq.com/cgi-bin/ticket/getticket?access_token=' . $res['access_token'] . '&type=jsapi';
  612. $res = $client->request('get', $url)->getBody()->getContents();
  613. if (!$res) {
  614. return 0;
  615. }
  616. $res = json_decode($res, 1);
  617. if (!isset($res['ticket']) || empty($res['ticket'])) {
  618. return 0;
  619. }
  620. Redis::hset($appid, 'jsapi_ticket', $res['ticket']);
  621. Redis::EXPIRE($appid, 7000);
  622. $sign_arr = [
  623. 'noncestr' => $pay_info['nonceStr'],
  624. 'jsapi_ticket' => $res['ticket'],
  625. 'timestamp' => $pay_info['timeStamp'],
  626. 'url' => $url
  627. ];
  628. return sha1($this->arr_to_url($sign_arr));
  629. } catch (\Exception $e) {
  630. return 0;
  631. }
  632. }
  633. return 0;
  634. }
  635. public function waitPage(Request $request)
  636. {
  637. $order = $request->input('order');
  638. //$order = "201712081711401585932843356442";
  639. $order = (string)$order;
  640. $url = urldecode($request->input('redirect'));
  641. return view('pay.order.wait', compact('order', 'url'));
  642. //return view('pay.order.wait');
  643. }
  644. /**
  645. * 官方微信回调
  646. * @param Request $request
  647. * @return \Symfony\Component\HttpFoundation\Response
  648. */
  649. function wcback_official(Request $request)
  650. {
  651. $xml = XML::parse(strval($request->getContent()));
  652. Log::info('xml is');
  653. Log::info($xml);
  654. if (!$xml || !is_array($xml)) return 'fail';
  655. $remarks = json_decode($xml['attach'], true);
  656. $pay_merchant_id = $remarks['pmi'];
  657. $pay_merchant = DB::table('pay_merchants')->select('appid', 'source', 'config_info')->where('id', $pay_merchant_id)->where('is_enabled', 1)->first();
  658. $application = WechatPay::instance('OFFICIALPAY', json_decode($pay_merchant->config_info, true));
  659. //$app = new Application($options);
  660. $app = $application->app;
  661. $response = $app->payment->handleNotify(function ($notify, $successful) {
  662. if (!$successful) return 'fail';
  663. $trade_no = $notify->out_trade_no;
  664. $order = OrderService::getByTradeNo($trade_no);
  665. if (isset($order->status) && $order->status == 'PAID') {
  666. Log::info('has_pay:' . $trade_no);
  667. return true;
  668. }
  669. DB::beginTransaction();
  670. try {
  671. $transaction_id = $notify->transaction_id;
  672. $remarks = json_decode($notify->attach, true);
  673. $uid = $remarks['uid'];
  674. $distribution_channel_id = $remarks['dcd'];
  675. $product_id = $remarks['pd'];
  676. $product = ProductService::getProductSingle($product_id);
  677. $pay_merchant_source = $remarks['pms'];
  678. $pay_merchant_id = $remarks['pmi'];
  679. $send_order_id = $remarks['soi'];
  680. $create_ip = $remarks['cp'];
  681. $price = $product->price;
  682. $bid = $remarks['bid'];
  683. //$this->updateOrderTotal($trade_no,$transaction_id);
  684. $prize_fee = (int)(($product->price*100)*0.1);
  685. $this->substituteOrderPrice($order->id,$prize_fee);
  686. $this->smartPushTestBookPaidUv($order->from_bid,$order->uid,$order->price);
  687. // 更新其他定制Order表
  688. if ($product->type == 'YEAR_ORDER') {
  689. Log::info('YEAR_ORDERYEAR_ORDERYEAR_ORDERYEAR_ORDERYEAR_ORDERYEAR_ORDERYEAR_ORDERYEAR_ORDER');
  690. $order_type = 'YEAR';
  691. $this->yearOrder($uid, $distribution_channel_id, $price, $send_order_id);
  692. $order->order_type = $order_type;
  693. $order->status = 'PAID';
  694. $order->pay_end_at = date('Y-m-d H:i:s');
  695. $order->transaction_id = $transaction_id;
  696. $order->save();
  697. //$price = $price/100;
  698. /*
  699. $this->createOrder(
  700. compact(
  701. 'uid','distribution_channel_id','product_id','price','trade_no','send_order_id','order_type','pay_merchant_source',
  702. 'pay_merchant_id','create_ip','bid','transaction_id'
  703. )
  704. );*/
  705. } elseif ($product->type == 'BOOK_ORDER') {
  706. Log::info('BOOK_ORDERBOOK_ORDERBOOK_ORDERBOOK_ORDERBOOK_ORDERBOOK_ORDERBOOK_ORDERBOOK_ORDER');
  707. $order_type = 'BOOK';
  708. $this->bookOrder($product_id, $uid, $send_order_id, $price, $distribution_channel_id);
  709. $order->order_type = $order_type;
  710. $order->status = 'PAID';
  711. $order->pay_end_at = date('Y-m-d H:i:s');
  712. $order->transaction_id = $transaction_id;
  713. $order->save();
  714. //$price = $price/100;
  715. /*
  716. $this->createOrder(
  717. compact(
  718. 'uid','distribution_channel_id','product_id','price','trade_no','send_order_id','order_type','pay_merchant_source',
  719. 'pay_merchant_id','create_ip','bid','transaction_id'
  720. )
  721. );*/
  722. } elseif ($product->type == 'TICKET_RECHARGE') {
  723. Log::info('TICKET_RECHARGETICKET_RECHARGETICKET_RECHARGETICKET_RECHARGETICKET_RECHARGE');
  724. $order_type = 'RECHARGE';
  725. $this->userCharge($product, $uid);
  726. $order->order_type = $order_type;
  727. $order->status = 'PAID';
  728. $order->pay_end_at = date('Y-m-d H:i:s');
  729. $order->transaction_id = $transaction_id;
  730. $order->save();
  731. //$price = $price/100;
  732. /*
  733. $this->createOrder(
  734. compact(
  735. 'uid','distribution_channel_id','product_id','price','trade_no','send_order_id','order_type','pay_merchant_source',
  736. 'pay_merchant_id','create_ip','bid','transaction_id'
  737. ));*/
  738. } elseif ($product->type == 'FOREVER') {
  739. Log::info('FOREVER------------------------FOREVER');
  740. $order_type = 'FOREVER';
  741. $this->foreverFreeOrder($uid, $distribution_channel_id, $price, $send_order_id);
  742. $order->order_type = $order_type;
  743. $order->status = 'PAID';
  744. $order->pay_end_at = date('Y-m-d H:i:s');
  745. $order->transaction_id = $transaction_id;
  746. $order->save();
  747. } else {
  748. DB::rollback();
  749. return 'Order not exist.';
  750. }
  751. $this->successPayPushMsg($uid, $product, $order->id);
  752. $this->orderStatistical($order);
  753. $key = 'leyuee:to_send_not_pay_uid:distribution_channel_id:' . $distribution_channel_id;
  754. Redis::hdel($key, $uid);
  755. DB::commit();
  756. // 注册动作-》回调订单
  757. $action_type = 'CallBackOrder';
  758. $param = [
  759. 'order_sn' => isset($trade_no)?$trade_no:'0',
  760. 'openid' => isset($uid)?$uid:'0',// 没有openid,用uid写log
  761. ];
  762. UserService::PushUserActionToQueue($action_type,$distribution_channel_id,$param);
  763. return true;
  764. } catch (\Exception $e) {
  765. DB::rollback();
  766. return 'fail';
  767. }
  768. });
  769. return $response;
  770. }
  771. /**
  772. * 通联支付回调
  773. * @param Request $request
  774. */
  775. function wcback_allinpay(Request $request)
  776. {
  777. Log::info('wcback_allinpay_request');
  778. try {
  779. $data = $request->all();
  780. Log::info($request->all());
  781. if (!$data['trxreserved']) return 'fail';
  782. $pay_merchant_id = json_decode($data['trxreserved'], true)['pmi'];
  783. $pay_merchant = DB::table('pay_merchants')->select('appid', 'source', 'config_info')->where('id', $pay_merchant_id)->where('is_enabled', 1)->first();
  784. unset($data['_url']);
  785. if (!$pay_merchant->config_info) return 'fail';
  786. $wechatPay = WechatPay::instance('ALLINPAY', json_decode($pay_merchant->config_info, true));
  787. if ($wechatPay->NotifyValidSign($data, $wechatPay->appkey)) {
  788. Log::info('allinpay_notify_sign_success');
  789. /**
  790. * 只有0000表示交易成功或下单成功,其他为失败
  791. * 0000:交易成功
  792. * 3045,3088:交易超时
  793. * 3008:余额不足
  794. * 3999:交易失败
  795. * 2008:交易处理中
  796. * 3050:交易已撤销
  797. */
  798. if ($data['trxstatus'] == '0000') {
  799. // 修改表比较多,开启事务
  800. DB::beginTransaction();
  801. $trade_no = $data['cusorderid'];
  802. $transaction_id = $data['chnltrxid'];
  803. //$openid = $data['acct'];
  804. $remarks = $data['trxreserved'];
  805. // $remarks = '{"openid":"oEteU1VNvYozhXuu8TXhByPBtSl4","distribution_channel_id":2,"product_id":1,"uid":1,"price":"1","trade_no":"201711301937151585490779316114","create_ip":"::1","servicer":"AllinPay"}';
  806. $remarks = json_decode($remarks, true);
  807. Log::info('$remarks');
  808. Log::info($remarks);
  809. // 更新Order
  810. $order = OrderService::getByTradeNo($trade_no);
  811. // 防止重复推送
  812. if (isset($order->status) && $order->status == 'PAID') {
  813. Log::info('has_pay:' . $trade_no);
  814. echo 'success';
  815. exit();
  816. }
  817. $uid = $remarks['uid'];
  818. $distribution_channel_id = $remarks['dcd'];
  819. $product_id = $remarks['pd'];
  820. $product = ProductService::getProductSingle($product_id);
  821. $pay_merchant_source = $remarks['pms'];
  822. $pay_merchant_id = $remarks['pmi'];
  823. $send_order_id = $remarks['soi'];
  824. $create_ip = $remarks['cp'];
  825. $price = $product->price;
  826. $bid = $remarks['bid'];
  827. Log::info('save_order_end');
  828. //$this->updateOrderTotal($trade_no,$transaction_id);
  829. Log::info($product);
  830. Log::info('product_type:' . $product->type);
  831. $prize_fee = (int)(($product->price*100)*0.1);
  832. $this->substituteOrderPrice($order->id,$prize_fee);
  833. $this->smartPushTestBookPaidUv($order->from_bid,$order->uid,$order->price);
  834. // 更新其他定制Order表
  835. if ($product->type == 'YEAR_ORDER') {
  836. Log::info('YEAR_ORDERYEAR_ORDERYEAR_ORDERYEAR_ORDERYEAR_ORDERYEAR_ORDERYEAR_ORDERYEAR_ORDER');
  837. $order_type = 'YEAR';
  838. $this->yearOrder($uid, $distribution_channel_id, $price, $send_order_id);
  839. $order->order_type = $order_type;
  840. $order->status = 'PAID';
  841. $order->pay_end_at = date('Y-m-d H:i:s');
  842. $order->transaction_id = $transaction_id;
  843. $order->save();
  844. //$price = $price/100;
  845. /*
  846. $this->createOrder(
  847. compact(
  848. 'uid','distribution_channel_id','product_id','price','trade_no','send_order_id','order_type','pay_merchant_source',
  849. 'pay_merchant_id','create_ip','bid','transaction_id'
  850. )
  851. );*/
  852. } elseif ($product->type == 'BOOK_ORDER') {
  853. Log::info('BOOK_ORDERBOOK_ORDERBOOK_ORDERBOOK_ORDERBOOK_ORDERBOOK_ORDERBOOK_ORDERBOOK_ORDER');
  854. $order_type = 'BOOK';
  855. $this->bookOrder($product_id, $uid, $send_order_id, $price, $distribution_channel_id);
  856. $order->order_type = $order_type;
  857. $order->status = 'PAID';
  858. $order->pay_end_at = date('Y-m-d H:i:s');
  859. $order->transaction_id = $transaction_id;
  860. $order->save();
  861. //$price = $price/100;
  862. /*
  863. $this->createOrder(
  864. compact(
  865. 'uid','distribution_channel_id','product_id','price','trade_no','send_order_id','order_type','pay_merchant_source',
  866. 'pay_merchant_id','create_ip','bid','transaction_id'
  867. )
  868. );*/
  869. } elseif ($product->type == 'TICKET_RECHARGE' || $product->type=='NEW_USER') {
  870. Log::info('TICKET_RECHARGETICKET_RECHARGETICKET_RECHARGETICKET_RECHARGETICKET_RECHARGE');
  871. $order_type = 'RECHARGE';
  872. $this->userCharge($product, $uid);
  873. $order->order_type = $order_type;
  874. $order->status = 'PAID';
  875. $order->pay_end_at = date('Y-m-d H:i:s');
  876. $order->transaction_id = $transaction_id;
  877. $order->save();
  878. //$price = $price/100;
  879. /*
  880. $this->createOrder(
  881. compact(
  882. 'uid','distribution_channel_id','product_id','price','trade_no','send_order_id','order_type','pay_merchant_source',
  883. 'pay_merchant_id','create_ip','bid','transaction_id'
  884. ));*/
  885. } elseif ($product->type == 'FOREVER') {
  886. Log::info('FOREVER------------------------FOREVER');
  887. $order_type = 'FOREVER';
  888. $this->foreverFreeOrder($uid, $distribution_channel_id, $price, $send_order_id);
  889. $order->order_type = $order_type;
  890. $order->status = 'PAID';
  891. $order->pay_end_at = date('Y-m-d H:i:s');
  892. $order->transaction_id = $transaction_id;
  893. $order->save();
  894. }
  895. $this->successPayPushMsg($uid, $product, $order->id);
  896. $this->orderStatistical($order);
  897. DB::commit();
  898. //redis 删除未支付的uid
  899. try {
  900. $key = 'leyuee:to_send_not_pay_uid:distribution_channel_id:' . $distribution_channel_id;
  901. Redis::hdel($key, $uid);
  902. //Redis::srem($key,$uid);
  903. } catch (\Exception $e) {
  904. Log::info('redis remote error-----------------------');
  905. Log::info($e);
  906. }
  907. }
  908. } else {
  909. Log::info('allinpay_notify_sign_fail');
  910. }
  911. } catch (\Exception $e) {
  912. DB::rollBack();
  913. Log::info('receive_allinpay_ept:' . $e->getMessage());
  914. Log::info('pay_callback_end fail');
  915. echo 'fail';
  916. return ;
  917. }
  918. Log::info('pay_callback_end');
  919. echo "success";
  920. }
  921. public function wcback_lianlianpay(Request $request)
  922. {
  923. $data = $request->getContent();
  924. Log::info('wcback_lianlianpay call back enter');
  925. Log::info($request->getContent());
  926. $data = json_decode($data, true);
  927. if ($data['result_pay'] == 'SUCCESS') {
  928. $trade_no = $data['no_order'];
  929. $order = OrderService::getByTradeNo($trade_no);
  930. if (!$order) return response()->json(['ret_code' => '-1']);
  931. $pay_merchant_id = $order->pay_merchant_id;
  932. $pay_merchant = DB::table('pay_merchants')->select('appid', 'source', 'config_info')->where('id', $pay_merchant_id)->where('is_enabled', 1)->first();
  933. unset($data['_url']);
  934. if (!$pay_merchant->config_info) response()->json(['ret_code' => '-1']);
  935. $wechatPay = WechatPay::instance('LIANLIANPAY', json_decode($pay_merchant->config_info, true));
  936. $uid = $order->uid;
  937. $distribution_channel_id = $order->distribution_channel_id;
  938. $price = $order->price;
  939. $send_order_id = $order->send_order_id;
  940. $product_id = $order->product_id;
  941. if (!$wechatPay->rsaCheck($data)) {
  942. Log::info('sign check error');
  943. //return response()->json(['ret_code'=>'-1']);
  944. }
  945. // 防止重复推送
  946. if (isset($order->status) && $order->status == 'PAID') {
  947. Log::info('has_pay:' . $trade_no);
  948. return response()->json(['ret_code' => '0000', 'ret_msg' => '交易成功']);
  949. }
  950. DB::beginTransaction();
  951. try {
  952. $product = ProductService::getProductSingle($order->product_id);
  953. $transaction_id = $data['oid_paybill'];
  954. $prize_fee = (int)(($product->price*100));
  955. $this->substituteOrderPrice($order->id,$prize_fee);
  956. $this->smartPushTestBookPaidUv($order->from_bid,$order->uid,$order->price);
  957. // 更新其他定制Order表
  958. if ($product->type == 'YEAR_ORDER') {
  959. Log::info('YEAR_ORDERYEAR_ORDERYEAR_ORDERYEAR_ORDERYEAR_ORDERYEAR_ORDERYEAR_ORDERYEAR_ORDER');
  960. $order_type = 'YEAR';
  961. $this->yearOrder($uid, $distribution_channel_id, $price, $send_order_id);
  962. $order->order_type = $order_type;
  963. $order->status = 'PAID';
  964. $order->pay_end_at = date('Y-m-d H:i:s');
  965. $order->transaction_id = $transaction_id;
  966. $order->save();
  967. } elseif ($product->type == 'BOOK_ORDER') {
  968. Log::info('BOOK_ORDERBOOK_ORDERBOOK_ORDERBOOK_ORDERBOOK_ORDERBOOK_ORDERBOOK_ORDERBOOK_ORDER');
  969. $order_type = 'BOOK';
  970. $this->bookOrder($product_id, $uid, $send_order_id, $price, $distribution_channel_id);
  971. $order->order_type = $order_type;
  972. $order->status = 'PAID';
  973. $order->pay_end_at = date('Y-m-d H:i:s');
  974. $order->transaction_id = $transaction_id;
  975. $order->save();
  976. } elseif ($product->type == 'TICKET_RECHARGE' || $product->type=='NEW_USER') {
  977. Log::info('TICKET_RECHARGETICKET_RECHARGETICKET_RECHARGETICKET_RECHARGETICKET_RECHARGE');
  978. $order_type = 'RECHARGE';
  979. $this->userCharge($product, $uid);
  980. $order->order_type = $order_type;
  981. $order->status = 'PAID';
  982. $order->pay_end_at = date('Y-m-d H:i:s');
  983. $order->transaction_id = $transaction_id;
  984. $order->save();
  985. } elseif ($product->type == 'FOREVER') {
  986. Log::info('FOREVER------------------------FOREVER');
  987. $order_type = 'FOREVER';
  988. $this->foreverFreeOrder($uid, $distribution_channel_id, $price, $send_order_id);
  989. $order->order_type = $order_type;
  990. $order->status = 'PAID';
  991. $order->pay_end_at = date('Y-m-d H:i:s');
  992. $order->transaction_id = $transaction_id;
  993. $order->save();
  994. }
  995. $this->successPayPushMsg($uid, $product, $order->id);
  996. $this->orderStatistical($order);
  997. DB::commit();
  998. //redis 删除未支付的uid
  999. $key = 'leyuee:to_send_not_pay_uid:distribution_channel_id' . $distribution_channel_id;
  1000. Redis::hdel($key, $uid);
  1001. return response()->json(['ret_code' => '0000', 'ret_msg' => '交易成功']);
  1002. } catch (\Exception $e) {
  1003. DB::rollBack();
  1004. Log::info('lianlian:' . $e->getMessage());
  1005. echo 'fail';
  1006. return ;
  1007. }
  1008. }
  1009. echo 'success';
  1010. }
  1011. /**
  1012. * 微众支付回调
  1013. * @param Request $request
  1014. */
  1015. function wcback_palmpay(Request $request)
  1016. {
  1017. Log::info('wcback_palmpay_request');
  1018. try {
  1019. $data = $request->except('_url');
  1020. Log::info($request->all());
  1021. //订单
  1022. $trade_no = $data['outTradeNo'];
  1023. $order = OrderService::getByTradeNo($trade_no);
  1024. if (!$order) die('failed');
  1025. // 防止重复推送
  1026. if (isset($order->status) && $order->status == 'PAID') {
  1027. Log::info('has_pay:' . $trade_no);
  1028. echo 'success';
  1029. exit();
  1030. }
  1031. $pay_merchant = DB::table('pay_merchants')->select('appid', 'source', 'config_info')->where('id', $order->pay_merchant_id)->where('is_enabled', 1)->first();
  1032. //校验签名
  1033. $sign = _sign($data, json_decode($pay_merchant->config_info, 1)['appKey']);
  1034. if ($sign != $data['sign']) die('failed');
  1035. $transaction_id = $data['chorderid'];
  1036. if ($data['status'] == 'success') {
  1037. Log::info('wcback_palmpay_notify_sign_success');
  1038. if ($data['status'] == 'success') {
  1039. // 修改表比较多,开启事务
  1040. DB::beginTransaction();
  1041. // 更新Order
  1042. $order = OrderService::getByTradeNo($trade_no);
  1043. $uid = $order->uid;
  1044. $distribution_channel_id = $order->distribution_channel_id;
  1045. $product_id = $order->product_id;
  1046. $product = ProductService::getProductSingle($product_id);
  1047. $send_order_id = $order->send_order_id;
  1048. $price = $product->price;
  1049. Log::info('save_order_end');
  1050. Log::info($product);
  1051. Log::info('product_type:' . $product->type);
  1052. $prize_fee = (int)(($product->price*100)*0.1);
  1053. $this->substituteOrderPrice($order->id,$prize_fee);
  1054. $this->smartPushTestBookPaidUv($order->from_bid,$order->uid,$order->price);
  1055. // 更新其他定制Order表
  1056. if ($product->type == 'YEAR_ORDER') {
  1057. Log::info('YEAR_ORDERYEAR_ORDERYEAR_ORDERYEAR_ORDERYEAR_ORDERYEAR_ORDERYEAR_ORDERYEAR_ORDER');
  1058. $order_type = 'YEAR';
  1059. $this->yearOrder($uid, $distribution_channel_id, $price, $send_order_id);
  1060. $order->order_type = $order_type;
  1061. $order->status = 'PAID';
  1062. $order->pay_end_at = date('Y-m-d H:i:s');
  1063. $order->transaction_id = $transaction_id;
  1064. $order->save();
  1065. } elseif ($product->type == 'BOOK_ORDER') {
  1066. Log::info('BOOK_ORDERBOOK_ORDERBOOK_ORDERBOOK_ORDERBOOK_ORDERBOOK_ORDERBOOK_ORDERBOOK_ORDER');
  1067. $order_type = 'BOOK';
  1068. $this->bookOrder($product_id, $uid, $send_order_id, $price, $distribution_channel_id);
  1069. $order->order_type = $order_type;
  1070. $order->status = 'PAID';
  1071. $order->pay_end_at = date('Y-m-d H:i:s');
  1072. $order->transaction_id = $transaction_id;
  1073. $order->save();
  1074. } elseif ($product->type == 'TICKET_RECHARGE' || $product->type=='NEW_USER') {
  1075. Log::info('TICKET_RECHARGETICKET_RECHARGETICKET_RECHARGETICKET_RECHARGETICKET_RECHARGE');
  1076. $order_type = 'RECHARGE';
  1077. $this->userCharge($product, $uid);
  1078. $order->order_type = $order_type;
  1079. $order->status = 'PAID';
  1080. $order->pay_end_at = date('Y-m-d H:i:s');
  1081. $order->transaction_id = $transaction_id;
  1082. $order->save();
  1083. } elseif ($product->type == 'FOREVER') {
  1084. Log::info('FOREVER------------------------FOREVER');
  1085. $order_type = 'FOREVER';
  1086. $this->foreverFreeOrder($uid, $distribution_channel_id, $price, $send_order_id);
  1087. $order->order_type = $order_type;
  1088. $order->status = 'PAID';
  1089. $order->pay_end_at = date('Y-m-d H:i:s');
  1090. $order->transaction_id = $transaction_id;
  1091. $order->save();
  1092. }
  1093. $this->successPayPushMsg($uid, $product, $order->id);
  1094. $this->orderStatistical($order);
  1095. DB::commit();
  1096. //redis 删除未支付的uid
  1097. try {
  1098. $key = 'leyuee:to_send_not_pay_uid:distribution_channel_id:' . $distribution_channel_id;
  1099. Redis::hdel($key, $uid);
  1100. } catch (\Exception $e) {
  1101. Log::info('redis remote error-----------------------');
  1102. Log::info($e);
  1103. }
  1104. // 注册动作-》回调订单
  1105. $action_type = 'CallBackOrder';
  1106. $param = [
  1107. 'order_sn' => isset($trade_no)?$trade_no:'0',
  1108. 'openid' => isset($uid)?$uid:'0',// 没有openid,用uid写log
  1109. ];
  1110. UserService::PushUserActionToQueue($action_type,$distribution_channel_id,$param);
  1111. }
  1112. } else {
  1113. Log::info('wcback_palmpay_notify_sign_fail');
  1114. }
  1115. } catch (\Exception $e) {
  1116. var_dump($e->getMessage());
  1117. DB::rollBack();
  1118. Log::info('receive_wcback_palmpay_ept:' . $e->getMessage());
  1119. echo 'fail';
  1120. Log::info('pay_callback_end error');
  1121. return;
  1122. }
  1123. Log::info('pay_callback_end');
  1124. echo "success";
  1125. }
  1126. /**
  1127. * 公众号签名@华灯初上
  1128. * @param $params
  1129. * @return string
  1130. */
  1131. protected function getSign($params, $key)
  1132. {
  1133. $url = $this->arr_to_url($params, false);
  1134. $url = $url . '&key=' . $key;
  1135. $sign = md5($url);
  1136. return $sign;
  1137. }
  1138. /**
  1139. * 公众号签名@华灯初上
  1140. * @param $array
  1141. * @param bool $has_sign
  1142. * @return string
  1143. */
  1144. protected function arr_to_url($array, $has_sign = false)
  1145. {
  1146. ksort($array);
  1147. reset($array);
  1148. $arg = "";
  1149. while (list ($name, $val) = each($array)) {
  1150. if ($name == 'sign' && !$has_sign) continue;
  1151. if (strpos($name, "_") === 0)
  1152. continue;
  1153. if (is_array($val))
  1154. $val = join(',', $val);
  1155. if ($val === "")
  1156. continue;
  1157. $arg .= $name . "=" . $val . "&";
  1158. }
  1159. $arg = substr($arg, 0, count($arg) - 2);
  1160. return $arg;
  1161. }
  1162. /**
  1163. * 单本充值会掉
  1164. * @param $product_id
  1165. * @param $uid
  1166. * @param $send_order_id
  1167. * @param $fee
  1168. */
  1169. protected function bookOrder($product_id, $uid, $send_order_id, $fee, $distribution_channel_id)
  1170. {
  1171. $book_conf = BookConfigService::getBookByProduct($product_id);
  1172. $insert_data['bid'] = isset($book_conf->bid) ? $book_conf->bid : '';
  1173. $insert_data['book_name'] = isset($book_conf->book_name) ? $book_conf->book_name : '';
  1174. $insert_data['uid'] = $uid;
  1175. $insert_data['distribution_channel_id'] = $distribution_channel_id;
  1176. $insert_data['fee'] = $fee;
  1177. $insert_data['send_order_id'] = $send_order_id;
  1178. $insert_data['charge_balance'] = 0;
  1179. $insert_data['reward_balance'] = 0;
  1180. Log::info('start_save_book_order');
  1181. Log::info($insert_data);
  1182. return BookOrderService::save_book_order($insert_data);
  1183. }
  1184. /**
  1185. * 包年
  1186. * @param $uid
  1187. * @param $distribution_channel_id
  1188. * @param $fee
  1189. * @param $send_order_id
  1190. * @return mixed
  1191. */
  1192. protected function yearOrder($uid, $distribution_channel_id, $fee, $send_order_id)
  1193. {
  1194. Log::info('start_save_year_order');
  1195. $insert_data['uid'] = $uid;
  1196. $insert_data['distribution_channel_id'] = $distribution_channel_id;
  1197. $insert_data['fee'] = $fee;
  1198. $insert_data['send_order_id'] = $send_order_id;
  1199. Log::info($insert_data);
  1200. return YearOrderService::save_year_order($insert_data);
  1201. }
  1202. private function foreverFreeOrder($uid, $distribution_channel_id, $fee, $send_order_id)
  1203. {
  1204. Log::info('start_save_year_order');
  1205. ('start_forever_Free_Order');
  1206. $insert_data['uid'] = $uid;
  1207. $insert_data['distribution_channel_id'] = $distribution_channel_id;
  1208. $insert_data['fee'] = $fee;
  1209. $insert_data['send_order_id'] = $send_order_id;
  1210. Log::info($insert_data);
  1211. return YearOrderService::foreverFree($insert_data);
  1212. }
  1213. /**
  1214. * 用户充值
  1215. * @param $product
  1216. * @param $uid\
  1217. */
  1218. protected function userCharge($product, $uid)
  1219. {
  1220. $total = $product->price * 100 + $product->given;
  1221. UserService::addBalance($uid, $total, $product->price * 100, $product->given);
  1222. Log::info('update_user_balance_end:' . $uid . ' balance_add:' . $total);
  1223. }
  1224. /**
  1225. * 添加订单
  1226. * @param array $data
  1227. * @return mixed
  1228. */
  1229. protected function createOrder(array $data)
  1230. {
  1231. $insert_data = array();
  1232. $insert_data['uid'] = $data['uid'];
  1233. $insert_data['distribution_channel_id'] = $data['distribution_channel_id'];
  1234. $insert_data['product_id'] = $data['product_id'];
  1235. $insert_data['price'] = $data['price'];
  1236. $insert_data['status'] = 'PAID';
  1237. $insert_data['pay_type'] = 1;
  1238. $insert_data['trade_no'] = $data['trade_no'];
  1239. $insert_data['send_order_id'] = $data['send_order_id'];
  1240. $insert_data['order_type'] = $data['order_type'];
  1241. $insert_data['pay_merchant_source'] = $data['pay_merchant_source'];
  1242. $insert_data['pay_merchant_id'] = $data['pay_merchant_id'];
  1243. $insert_data['transaction_id'] = $data['transaction_id'];
  1244. $insert_data['pay_end_at'] = date('Y-m-d H:i:s');
  1245. $insert_data['create_ip'] = $data['create_ip'];
  1246. $insert_data['from_bid'] = $data['bid'];
  1247. Log::info('createOrder');
  1248. Log::info($insert_data);
  1249. return OrderService::save_order($insert_data);
  1250. }
  1251. /**
  1252. * 添加位置付订单
  1253. * @param $data
  1254. * @return mixed
  1255. */
  1256. protected function createUnPayOrder($data)
  1257. {
  1258. $data['status'] = 'UNPAID';
  1259. $data['transaction_id'] = '';
  1260. $data['pay_end_at'] = '0000-00-00 00:00:00';
  1261. return OrderService::save_order($data);
  1262. }
  1263. /**
  1264. * order total
  1265. * @param $data
  1266. *
  1267. */
  1268. protected function createOrderTotal($data)
  1269. {
  1270. $data['status'] = 'UNPAID';
  1271. $data['created_at'] = date('Y-m-d H:i:s');
  1272. $data['updated_at'] = date('Y-m-d H:i:s');
  1273. DB::table('orders_total')->insert($data);
  1274. }
  1275. protected function updateOrderTotal($trade_no, $transaction_id)
  1276. {
  1277. $data['status'] = 'PAID';
  1278. $data['transaction_id'] = $transaction_id;
  1279. $data['pay_end_at'] = date('Y-m-d H:i:s');
  1280. //DB::table('orders_total')->where('trade_no',$trade_no)->update($data);
  1281. }
  1282. protected function successPayPushMsg($uid, $product_info, $order_id)
  1283. {
  1284. try {
  1285. $force_sub_info = $this->getSubscribeV2($uid);
  1286. $data = UserService::getById($uid);
  1287. if (!in_array($data->distribution_channel_id, [5, 123])) {
  1288. //return false;
  1289. }
  1290. if ($force_sub_info) {
  1291. //$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>";
  1292. if (SubstituteOrderService::getByOrderId($order_id)) {
  1293. $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>";
  1294. } else {
  1295. $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>";
  1296. }
  1297. if ($product_info->type == 'YEAR_ORDER') {
  1298. $money_text = $product_info->price . '元(尊贵的年费VIP会员)';
  1299. } elseif ($product_info->type == 'TICKET_RECHARGE') {
  1300. if ($product_info->given) {
  1301. $money_text = $product_info->price . '元(' . ($product_info->price * 100) . '书币+赠送' . $product_info->given . '书币)';
  1302. } else {
  1303. $money_text = $product_info->price . '元(' . ($product_info->price * 100) . '书币)';
  1304. }
  1305. } else {
  1306. $money_text = '未知';
  1307. }
  1308. $delay = 0;
  1309. $url = env('PROTOCOL') . '://site' . encodeDistributionChannelId($data->distribution_channel_id) . '.' . env('CUSTOM_HOST') . '.com/continue';;
  1310. $content = sprintf($content_format, $data->nickname ? $data->nickname : '匿名', $uid, $money_text, $url);
  1311. foreach ($force_sub_info as $item){
  1312. $res['openid'] = $item->openid;
  1313. $res['appid'] = $item->appid;
  1314. $res['content'] = $content;
  1315. $res['type'] = 'one_task';
  1316. $res['send_time'] = date("Y-m-d H:i:s");
  1317. $res['task_id'] = md5('pay_success_push');
  1318. $send_data = array(
  1319. 'send_time' => date("Y-m-d H:i:s"),
  1320. 'data' => $res
  1321. );
  1322. dispatch((new SendTexts($send_data))->onConnection('rabbitmq')->delay($delay)->onQueue('send_texts_list'));
  1323. }
  1324. }
  1325. } catch (\Exception $e) {
  1326. Log::info('pay_success_push error');
  1327. Log::info($e);
  1328. }
  1329. return true;
  1330. }
  1331. private function orderStatistical($order)
  1332. {
  1333. try {
  1334. $send_data = array(
  1335. 'type' => 'order_info',
  1336. 'data' => $order->toArray()
  1337. );
  1338. $send = new SendStatisticsList($send_data);
  1339. $job = ($send)->onConnection('rabbitmq')->delay(0)->onQueue('send_statistics_list');
  1340. dispatch($job);
  1341. } catch (\Exception $e) {
  1342. Log::info($e);
  1343. }
  1344. //灵界的推送统计\App\Modules\Statistic\Services\WapVisitStatService::customerAllStats
  1345. try{
  1346. if($order->from_type){
  1347. $pv = Redis::hget('push:distribution_channel_id:allpv' ,$order->from_type);
  1348. if($pv){
  1349. Redis::sadd('push:all:paidnum:from:' . $order->from_type,$order->uid);
  1350. $old = Redis::hget('push:all:paidamount' ,$order->from_type);
  1351. if($old){
  1352. Redis::hset('push:all:paidamount' ,$order->from_type,$old+$order->price);
  1353. }else{
  1354. Redis::hset('push:all:paidamount' ,$order->from_type,$order->price);
  1355. }
  1356. }
  1357. }
  1358. if(isset($order->pay_merchant_id) && $order->pay_merchant_id)//临时统计队列清0 用于报警
  1359. {
  1360. $key = 'pay_merchant:'.$order->pay_merchant_id;
  1361. Redis::hset($key,'unpaid_num',0);
  1362. }
  1363. }catch (\Exception $e){}
  1364. }
  1365. private function getSubscribe($uid)
  1366. {
  1367. return ForceSubscribeService::forceSubscribeUsersByUid(['uid' => $uid]);
  1368. }
  1369. private function getSubscribeV2($uid)
  1370. {
  1371. return DB::table('force_subscribe_users')->where('uid',$uid)->where('is_subscribed', 1)->get();
  1372. }
  1373. public function getSubscribeOfficialName($uid,$distribution_channel_id)
  1374. {
  1375. $subscribe = $this->getSubscribe($uid);
  1376. if ($subscribe && isset($subscribe->appid)) {
  1377. $official = DB::table('official_accounts')->where('appid', $subscribe->appid)->select('nickname')->first();
  1378. if ($official && isset($official->nickname)) {
  1379. return $official->nickname;
  1380. }
  1381. }
  1382. $res = OfficialAccountService::canUseOfficialAccountByChannelId(compact('distribution_channel_id'));
  1383. if (isset($res->nickname) && !empty($res->nickname)) {
  1384. return $res->nickname;
  1385. }
  1386. try{
  1387. $official = DB::table('official_accounts')
  1388. ->where('distribution_channel_id', $distribution_channel_id)
  1389. ->where('is_auth',1)
  1390. ->orderBy('id','desc')
  1391. ->select('nickname')->first();
  1392. if ($official && isset($official->nickname)) {
  1393. return $official->nickname;
  1394. }
  1395. }catch (\Exception $e){}
  1396. return '';
  1397. }
  1398. private function payAlert($pay_merchant_id, $trade_no = '', $pay_info = '', $n = 0)
  1399. {
  1400. $change_pay_id = 40;
  1401. if ($pay_merchant_id == 40) {
  1402. $change_pay_id = 9;
  1403. }
  1404. try {
  1405. $time = (int)date('G');
  1406. $change = false;
  1407. if ($time <= 8 || $time >= 23) {
  1408. if (!$pay_info && $pay_merchant_id != $change_pay_id) {
  1409. DB::table('distribution_channels')->where('pay_merchant_id', $pay_merchant_id)->update(['pay_merchant_id' => $change_pay_id]);
  1410. $change = true;
  1411. }
  1412. }
  1413. //$number,$template_type,$param=array()
  1414. $phone_arr = ['15868100210', '18072713392', '15088790066', '13858057394', '18668029091', '18668420256'];
  1415. //$phone_arr = ['18668029091'];
  1416. $param = ['pay_id'=>$pay_merchant_id];
  1417. if ($n) {
  1418. $template_type = 'pay_channel_remind';
  1419. //$content = '支付通道:' . $pay_merchant_id . ',获取授权信息失败';
  1420. } else {
  1421. $template_type = 'pay_channel_remind';
  1422. //$content = '支付通道:' . $pay_merchant_id . ',订单号为' . $trade_no . '支付异常,异常信息:' . json_encode($pay_info);
  1423. }
  1424. if ($change) {
  1425. $template_type = 'pay_channel_change';
  1426. $param = ['pay_id'=>$pay_merchant_id,'new_pay_id'=>$change_pay_id];
  1427. }
  1428. foreach ($phone_arr as $phone) {
  1429. AliSMS::send($phone, $template_type,$param);
  1430. }
  1431. } catch (\Exception $e) {
  1432. }
  1433. }
  1434. private function createSubstituteOrder($order_id, $uid, $pay_uid)
  1435. {
  1436. SubstituteOrderService::createOrder($order_id, $uid, $pay_uid);
  1437. }
  1438. private function recordOtherParam($order_id, $uid){
  1439. $gxhp = ReadRecordService::getByField($uid,'gxhp');
  1440. if($gxhp){
  1441. OrderParamService::create($order_id,$gxhp);
  1442. }
  1443. }
  1444. private function substituteOrderPrice($order_id,$prize_fee=500)
  1445. {
  1446. SubstituteOrderService::SubstituteOrderPrize($order_id, $prize_fee);
  1447. }
  1448. private function updateUserSendOrderId(int $uid,$send_order_id){
  1449. if($send_order_id && $uid){
  1450. $user = UserService::getById($uid);
  1451. if($user && !$user->send_order_id){
  1452. UserService::updateInfo($uid,compact('send_order_id'));
  1453. }
  1454. }
  1455. }
  1456. /**
  1457. * 测书智能推送统计 付费用户数、充值金额
  1458. * @param $bid
  1459. * @param $uid
  1460. * @param $price
  1461. */
  1462. private function smartPushTestBookPaidUv($bid,$uid,$price){
  1463. $smart_bid = ReadRecordService::getSmartPush($uid);
  1464. if( $smart_bid && in_array($bid,$smart_bid) ){
  1465. try{
  1466. $key = 'smartPushTestBookPaidUv:bid:%s';
  1467. Redis::sadd(sprintf($key,$bid),$uid);
  1468. $now_amount = Redis::hget('smartPushTestBookPaidAmount',$bid);
  1469. if(!$now_amount){
  1470. $now_amount = 0;
  1471. }
  1472. Redis::hset('smartPushTestBookPaidAmount',$bid,$now_amount+$price);
  1473. }catch (\Exception $e){
  1474. }
  1475. }
  1476. }
  1477. }