OrdersController.php 67 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602
  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. return '';
  1387. }
  1388. private function payAlert($pay_merchant_id, $trade_no = '', $pay_info = '', $n = 0)
  1389. {
  1390. $change_pay_id = 40;
  1391. if ($pay_merchant_id == 40) {
  1392. $change_pay_id = 9;
  1393. }
  1394. try {
  1395. $time = (int)date('G');
  1396. $change = false;
  1397. if ($time <= 8 || $time >= 23) {
  1398. if (!$pay_info && $pay_merchant_id != $change_pay_id) {
  1399. DB::table('distribution_channels')->where('pay_merchant_id', $pay_merchant_id)->update(['pay_merchant_id' => $change_pay_id]);
  1400. $change = true;
  1401. }
  1402. }
  1403. //$number,$template_type,$param=array()
  1404. $phone_arr = ['15868100210', '18072713392', '15088790066', '13858057394', '18668029091', '18668420256'];
  1405. //$phone_arr = ['18668029091'];
  1406. $param = ['pay_id'=>$pay_merchant_id];
  1407. if ($n) {
  1408. $template_type = 'pay_channel_remind';
  1409. //$content = '支付通道:' . $pay_merchant_id . ',获取授权信息失败';
  1410. } else {
  1411. $template_type = 'pay_channel_remind';
  1412. //$content = '支付通道:' . $pay_merchant_id . ',订单号为' . $trade_no . '支付异常,异常信息:' . json_encode($pay_info);
  1413. }
  1414. if ($change) {
  1415. $template_type = 'pay_channel_change';
  1416. $param = ['pay_id'=>$pay_merchant_id,'new_pay_id'=>$change_pay_id];
  1417. }
  1418. foreach ($phone_arr as $phone) {
  1419. AliSMS::send($phone, $template_type,$param);
  1420. }
  1421. } catch (\Exception $e) {
  1422. }
  1423. }
  1424. private function createSubstituteOrder($order_id, $uid, $pay_uid)
  1425. {
  1426. SubstituteOrderService::createOrder($order_id, $uid, $pay_uid);
  1427. }
  1428. private function recordOtherParam($order_id, $uid){
  1429. $gxhp = ReadRecordService::getByField($uid,'gxhp');
  1430. if($gxhp){
  1431. OrderParamService::create($order_id,$gxhp);
  1432. }
  1433. }
  1434. private function substituteOrderPrice($order_id,$prize_fee=500)
  1435. {
  1436. SubstituteOrderService::SubstituteOrderPrize($order_id, $prize_fee);
  1437. }
  1438. private function updateUserSendOrderId(int $uid,$send_order_id){
  1439. if($send_order_id && $uid){
  1440. $user = UserService::getById($uid);
  1441. if($user && !$user->send_order_id){
  1442. UserService::updateInfo($uid,compact('send_order_id'));
  1443. }
  1444. }
  1445. }
  1446. /**
  1447. * 测书智能推送统计 付费用户数、充值金额
  1448. * @param $bid
  1449. * @param $uid
  1450. * @param $price
  1451. */
  1452. private function smartPushTestBookPaidUv($bid,$uid,$price){
  1453. $smart_bid = ReadRecordService::getSmartPush($uid);
  1454. if( $smart_bid && in_array($bid,$smart_bid) ){
  1455. try{
  1456. $key = 'smartPushTestBookPaidUv:bid:%s';
  1457. Redis::sadd(sprintf($key,$bid),$uid);
  1458. $now_amount = Redis::hget('smartPushTestBookPaidAmount',$bid);
  1459. if(!$now_amount){
  1460. $now_amount = 0;
  1461. }
  1462. Redis::hset('smartPushTestBookPaidAmount',$bid,$now_amount+$price);
  1463. }catch (\Exception $e){
  1464. }
  1465. }
  1466. }
  1467. }