OrdersController.php 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692
  1. <?php
  2. namespace App\Http\Controllers\QuickApp\Order;
  3. use App\Consts\ErrorConst;
  4. use App\Libs\Utils;
  5. use App\Modules\Activity\Models\Activity;
  6. use App\Modules\Statistic\Services\AdVisitStatService;
  7. use App\Http\Controllers\QuickApp\BaseController;
  8. use Illuminate\Http\Request;
  9. use App\Modules\Subscribe\Services\BookOrderService;
  10. use App\Modules\Subscribe\Services\ChapterOrderService;
  11. use App\Modules\Subscribe\Services\OrderService;
  12. use App\Http\Controllers\QuickApp\Order\Transformers\BookOrderTransformer;
  13. use App\Http\Controllers\QuickApp\Order\Transformers\ChapterOrderTransformer;
  14. use App\Http\Controllers\QuickApp\Order\Transformers\ChargeListTransformer;
  15. use App\Libs\Pay\PayFactory;
  16. use Hashids;
  17. use App\Modules\Product\Services\ProductService;
  18. use App\Modules\Book\Services\BookConfigService;
  19. use App\Modules\Book\Services\BookService;
  20. use App\Modules\Channel\Services\PayTemplateService;
  21. use App\Modules\Subscribe\Models\Order;
  22. use App\Modules\Trade\Models\Order as TradeOrder;
  23. use App\Modules\Trade\Pay\OrderArousePayFactory;
  24. use App\Modules\Trade\Pay\OrderPaySuccess;
  25. use App\Modules\Trade\Services\PayMerchantService;
  26. use EasyWeChat\Support\XML;
  27. class OrdersController extends BaseController
  28. {
  29. /**
  30. * @apiDefine Order 订单
  31. */
  32. /**
  33. *
  34. */
  35. private $chargeList;
  36. public function exchangeList()
  37. {
  38. foreach ($this->chargeList as &$item) {
  39. if (!$item->switch_to) continue;
  40. $order = Order::where('uid', $this->uid)->where('status', 'PAID')->where('product_id', $item->id)->first();
  41. if ($order) {
  42. $change = ProductService::getProductSingle($item->switch_to);
  43. $item->id = $change->id;
  44. $item->price = $change->price;
  45. $item->given = $change->given;
  46. }
  47. }
  48. }
  49. /**
  50. * @apiVersion 1.0.0
  51. * @apiDescription 充值列表
  52. * @api {get} order/chargeList 充值列表
  53. * @apiHeader {String} [Authorization] token
  54. * @apiGroup Order
  55. * @apiName chargeList
  56. * @apiSuccess {int} code 状态码
  57. * @apiSuccess {String} msg 信息
  58. * @apiSuccess {object} data 结果集
  59. * @apiSuccessExample {json} Success-Response:
  60. * HTTP/1.1 200 OK
  61. * {
  62. * code: 0,
  63. * msg: "",
  64. * data: [
  65. * {
  66. * product_id: 1,
  67. * price: "30.00元",
  68. * vip: 0,
  69. * intro: [
  70. * {
  71. * label: 3000,
  72. * important: false
  73. * },
  74. * {
  75. * label: "书币",
  76. * important: true
  77. * }
  78. * ]
  79. * },
  80. * {
  81. * product_id: 2,
  82. * price: "50.00元",
  83. * vip: 1,
  84. * intro: [
  85. * {
  86. * label: 5000,
  87. * important: false
  88. * },
  89. * {
  90. * label: "1000+",
  91. * important: true
  92. * },
  93. * {
  94. * label: "书币",
  95. * important: false
  96. * }
  97. * ]
  98. * },
  99. * {
  100. * product_id: 5,
  101. * price: "365.00元",
  102. * vip: 0,
  103. * intro: [
  104. * {
  105. * label: "年费VIP会员",
  106. * important: true
  107. * }
  108. * ]
  109. * }
  110. * ]
  111. * }
  112. */
  113. public function chargeList(Request $request)
  114. {
  115. $bid = $request->input('bid', '');
  116. $temp = $bid;
  117. $template_id = PayTemplateService::getPayTemplate($this->distribution_channel_id);
  118. $book_config = null;
  119. if ($bid) {
  120. $bid = Hashids::decode($bid)[0];
  121. $book_config = BookConfigService::getBookById($bid);
  122. }
  123. if ($template_id == 2) { //模板2只有在长篇小说过来的用户才显示
  124. //部分渠道需要2元模板不管哪个入口进来都展示
  125. $exclude_channels = explode(',', env('PRICE_TWO_SHOW_ALL_CHANNEL'));
  126. if (!in_array($this->distribution_channel_id, $exclude_channels)) {
  127. if ($book_config) {
  128. if ($book_config->charge_type == 'BOOK') $template_id = 1;
  129. }
  130. }
  131. }
  132. $res = ProductService::getChargeProduct($template_id);
  133. if (!$res) {
  134. return response()->error('WAP_SYS_ERROR');
  135. }
  136. $this->chargeList = $res;
  137. $this->exchangeList();
  138. //TODO 长篇小数才有模板2
  139. $uid = $this->uid;
  140. $is_first_recharge = OrderService::judgeUserFirstRecharge($uid);
  141. $data = [];
  142. $appad = 0;
  143. foreach ($res as $v) {
  144. if ($template_id == 7 && $book_config && $book_config->charge_type == 'BOOK' && $v->price == 2) {
  145. continue;
  146. }
  147. if ($template_id == 2 && $v->type == 'NEW_USER' && !$bid) {
  148. //2元模版,直接进充值,不出现
  149. continue;
  150. }
  151. if ($v->type == 'NEW_USER' && $is_first_recharge) {
  152. if (
  153. env('NO_NEW_USER_CHARGE') &&
  154. in_array(
  155. $this->distribution_channel_id,
  156. explode(',', env('NO_NEW_USER_CHARGE'))
  157. )
  158. ) {
  159. continue;
  160. }
  161. $temp = [
  162. 'price' => (float)$v->price . '元',
  163. 'is_year_order' => 0,
  164. 'is_month_order' => 0,
  165. 'text' => sprintf('%s+%s书币', $v->price * 100, $v->given),
  166. 'today_special' => $v->is_default,
  167. 'first_charge' => true,
  168. 'save_text' => round($v->given / 100, 1) . '元',
  169. 'product_id' => $v->id,
  170. ];
  171. $data[] = $temp;
  172. } elseif ($v->type == 'YEAR_ORDER') {
  173. if ($v->type == 'NEW_USER') {
  174. continue;
  175. }
  176. $save_text = '年费vip会员';
  177. $text = '每天1元,全年免费看';
  178. $temp = [
  179. 'price' => (int)$v->price . '元',
  180. 'is_year_order' => 1,
  181. 'is_month_order' => 0,
  182. 'text' => $text,
  183. 'today_special' => $v->is_default,
  184. 'first_charge' => false,
  185. 'save_text' => $save_text,
  186. 'product_id' => $v->id,
  187. ];
  188. $data[] = $temp;
  189. } else {
  190. if ($v->type == 'NEW_USER') {
  191. continue;
  192. }
  193. $save_text = '';
  194. if ($v->given) {
  195. $save_text = round($v->given / 100, 1) . '元';
  196. $text = sprintf('%s+%s书币', $v->price * 100, $v->given);
  197. } else {
  198. $text = sprintf('%s书币', $v->price * 100);
  199. }
  200. $temp = [
  201. 'price' => (float)$v->price . '元',
  202. 'is_year_order' => 0,
  203. 'is_month_order' => 0,
  204. 'text' => $text,
  205. 'today_special' => $v->is_default,
  206. 'first_charge' => false,
  207. 'save_text' => $save_text,
  208. 'product_id' => $v->id,
  209. ];
  210. $data[] = $temp;
  211. }
  212. }
  213. return response()->success($data);
  214. }
  215. /**
  216. * @apiVersion 1.0.0
  217. * @apiDescription 单本消费记录
  218. * @api {get} order/bookOrderList 单本消费记录
  219. * @apiHeader {String} [Authorization] token
  220. * @apiGroup Order
  221. * @apiName bookOrderList
  222. * @apiParam {String} [page_size] 分页大小
  223. * @apiParam {String} [page] 页码
  224. * @apiSuccess {int} code 状态码
  225. * @apiSuccess {String} msg 信息
  226. * @apiSuccess {object} data 结果集
  227. * @apiSuccess {Int} uid uid
  228. * @apiSuccess {Int} bid bid
  229. * @apiSuccess {Int} book_name 书名
  230. * @apiSuccess {Int} fee 钱
  231. * @apiSuccess {String} created_at 时间
  232. * @apiSuccessExample {json} Success-Response:
  233. * HTTP/1.1 200 OK
  234. * {
  235. * code: 0,
  236. * msg: "",
  237. * data: list:[
  238. * {
  239. * uid: 4,
  240. * bid: 1,
  241. * book_name: "dfsedfertrwet",
  242. * fee: 100,
  243. * created_at: "2017-12-02 16:24:54"
  244. * }
  245. * ]
  246. * meta: {
  247. * total: 1,
  248. * per_page: 15,
  249. * current_page: 1,
  250. * last_page: 1,
  251. * next_page_url: "",
  252. * prev_page_url: ""
  253. * }
  254. * }
  255. * }
  256. */
  257. public function bookOrderList(Request $request)
  258. {
  259. $page_size = $request->input('page_size', 15);
  260. $book_order = BookOrderService::getRecord($this->uid, $page_size);
  261. return response()->pagination(new BookOrderTransformer(), $book_order);
  262. }
  263. /**
  264. * @apiVersion 1.0.0
  265. * @apiDescription 章节消费记录
  266. * @api {get} order/chapterOrderList 章节消费记录
  267. * @apiHeader {String} [Authorization] token
  268. * @apiGroup Order
  269. * @apiName chapterOrderList
  270. * @apiParam {String} [page_size] 分页大小
  271. * @apiParam {String} [page] 页码
  272. * @apiSuccess {int} code 状态码
  273. * @apiSuccess {String} msg 信息
  274. * @apiSuccess {object} data 结果集
  275. * @apiSuccess {Int} uid uid
  276. * @apiSuccess {Int} bid bid
  277. * @apiSuccess {Int} cid cid
  278. * @apiSuccess {Int} chapter_name 章节名
  279. * @apiSuccess {Int} book_name 书名
  280. * @apiSuccess {Int} fee 钱
  281. * @apiSuccess {String} created_at 时间
  282. * @apiSuccessExample {json} Success-Response:
  283. * HTTP/1.1 200 OK
  284. * {
  285. * code: 0,
  286. * msg: "",
  287. * data: list:[
  288. * {
  289. * uid: 4,
  290. * bid: 1,
  291. * cid: 1,
  292. * chapter_name: "sdfsd",
  293. * book_name: "dfsedfertrwet",
  294. * fee: 100,
  295. * created_at: "2017-12-02 16:24:54"
  296. * }
  297. * ]
  298. * meta: {
  299. * total: 1,
  300. * per_page: 15,
  301. * current_page: 1,
  302. * last_page: 1,
  303. * next_page_url: "",
  304. * prev_page_url: ""
  305. * }
  306. * }
  307. */
  308. public function chapterOrderList(Request $request)
  309. {
  310. $chapter_model = new ChapterOrderService();
  311. $page_size = $request->input('page_size', 15);
  312. $chapter_order = $chapter_model->getByUid($this->uid, $page_size);
  313. foreach ($chapter_order as $item) {
  314. if ($item->fee == 0) {
  315. $result = AdVisitStatService::getInfoV2($this->uid, $item->cid, ['UNLOCK', 'UNLOCK_2']);
  316. $item->fee = '解锁';
  317. }
  318. }
  319. return response()->pagination(new ChapterOrderTransformer(), $chapter_order);
  320. }
  321. /**
  322. * @apiVersion 1.0.0
  323. * @apiDescription 充值记录
  324. * @api {get} order/chargeRecordLists 充值记录
  325. * @apiParam {String} [token] token
  326. * @apiHeader {String} [Authorization] token 两个token任选其一
  327. * @apiGroup Order
  328. * @apiName chargeRecordLists
  329. * @apiParam {String} [page_size] 分页大小
  330. * @apiParam {String} [page] 页码
  331. * @apiSuccess {int} code 状态码
  332. * @apiSuccess {String} msg 信息
  333. * @apiSuccess {object} data 结果集
  334. * @apiSuccess {String} data.price 价格
  335. * @apiSuccess {String} data.status 状态
  336. * @apiSuccess {String} data.trade_no 订单号
  337. * @apiSuccess {String} data.created_at 时间
  338. * @apiSuccessExample {json} Success-Response:
  339. * HTTP/1.1 200 OK
  340. * {
  341. * code: 0,
  342. * msg: "",
  343. * data: {
  344. * list: [
  345. * {
  346. * id: 134,
  347. * price: "1.00",
  348. * status: "PAID",
  349. * trade_no: "201712021915481585670623626232",
  350. * created_at: "2017-12-02 19:15:56"
  351. * }
  352. * ],
  353. * meta: {
  354. * total: 1,
  355. * per_page: 15,
  356. * current_page: 1,
  357. * last_page: 1,
  358. * next_page_url: "",
  359. * prev_page_url: ""
  360. * }
  361. * }
  362. * }
  363. */
  364. public function chargeRecordLists(Request $request)
  365. {
  366. $page_size = $request->input('page_size', 15);
  367. $res = OrderService::getOrderList($this->uid, $page_size);
  368. return response()->pagination(new ChargeListTransformer(), $res);
  369. }
  370. private function getPayParams(Request $request)
  371. {
  372. myLog('pay-order')->info('request', ['params' => $request->all()]);
  373. $uid = $this->uid;
  374. $product_id = $request->get('product_id', 0);
  375. $send_order_id = $this->send_order_id;
  376. if (!$product_id) {
  377. return false;
  378. }
  379. $bid = $request->get('bid', 0);
  380. if ($bid) {
  381. $from_bid = BookService::decodeBidStatic($bid);
  382. }
  383. $trade_no = date("YmdHis") . hexdec(uniqid());
  384. $product_info = ProductService::getProductSingle($product_id);
  385. if (!getProp($product_info, 'id')) {
  386. return false;
  387. }
  388. $distribution_channel_id = $this->distribution_channel_id;
  389. $price = $product_info->price * 100;
  390. if (in_array($uid, explode(',', env('TEST_UID')))) {
  391. $price = 1;
  392. }
  393. $from_type = 'QuickApp';
  394. if ($product_info->type == 'YEAR_ORDER') {
  395. $order_type = 'YEAR';
  396. } elseif ($product_info->type == 'QUARTER') {
  397. $order_type = 'QUARTER';
  398. } elseif ($product_info->type == 'BOOK_ORDER') {
  399. $order_type = 'BOOK';
  400. } elseif ($product_info->type == 'TICKET_RECHARGE') {
  401. $order_type = 'RECHARGE';
  402. } else {
  403. $order_type = '';
  404. }
  405. $create_ip = _getIp();
  406. // 活动
  407. $activity_token = $request->get('activity_token', '');
  408. $activity_id = 0;
  409. if ($activity_token) {
  410. $activity = Activity::getActivityBuToken($activity_token);
  411. $activity_id = (int)getProp($activity, 'id');
  412. // 校验活动次数
  413. $settingJson = getProp($activity, 'setting');
  414. if ($settingJson) {
  415. $setting = json_decode($settingJson, true);
  416. $productInfos = getProp($setting, 'product_info', []);
  417. $productInfo = collect($productInfos)->firstWhere('product_id', $product_id);
  418. $limit = (int)getProp($productInfo, 'limit');
  419. if ($limit > 0) {
  420. // 查询用户通过该活动已经充值的次数
  421. $paidNum = TradeOrder::getActivityOrderNum([
  422. 'uid' => $uid,
  423. 'begin_time' => getProp($activity, 'start_time'),
  424. 'end_time' => getProp($activity, 'end_time'),
  425. 'status' => 'PAID',
  426. 'activity_id' => $activity_id
  427. ]);
  428. // 活动充值次数限制
  429. if ($paidNum >= $limit) {
  430. Utils::throwError(ErrorConst::ACTIVITY_CHARGE_OUT_OF_LIMIT);
  431. }
  432. }
  433. }
  434. }
  435. return compact(
  436. 'distribution_channel_id',
  437. 'uid',
  438. 'product_id',
  439. 'price',
  440. 'trade_no',
  441. 'create_ip',
  442. 'send_order_id',
  443. 'from_bid',
  444. 'from_type',
  445. 'order_type',
  446. 'activity_id'
  447. );
  448. }
  449. /**
  450. * @apiVersion 1.0.0
  451. * @apiDescription 支付
  452. * @api {get} goToPay 微信APP支付
  453. * @apiGroup pay
  454. * @apiName wxindex
  455. * @apiParam {Int} product_id product_id
  456. * @apiParam {Int} send_order_id send_order_id
  457. * @apiParam {String} bid bid
  458. * @apiHeader {String} [Authorization] token
  459. * @apiSuccess {int} code 状态码
  460. * @apiSuccess {String} msg 信息
  461. * @apiSuccess {Object} data 信息
  462. * @apiSuccess {Object} data.trade_no 订单号
  463. * @apiSuccess {Object} data.appId 唤起支付的appId
  464. * @apiSuccess {Object} data.mch_id 唤起支付的mch_id
  465. * @apiSuccess {Object} data.nonce_str 唤起支付的nonce_str
  466. * @apiSuccess {Object} data.prepay_id 唤起支付的prepay_id
  467. * @apiSuccess {Object} data.sign 唤起支付的sign
  468. * @apiSuccess {Object} data.trade_type 唤起支付trade_type
  469. * @apiSuccessExample {json} Success-Response:
  470. * HTTP/1.1 200 OK
  471. * {
  472. * code: 0,
  473. * msg: "",
  474. * data: {
  475. *
  476. * }
  477. */
  478. function wxIndex(Request $request)
  479. {
  480. if ($params = $this->getPayParams($request)) {
  481. $params['pay_merchant_id'] = $this->app_pay_merchat_id;
  482. } else {
  483. return response()->error('QAPP_PARAM_ERROR');
  484. }
  485. $app = OrderArousePayFactory::wx($this->uid);
  486. // 微信支付参数
  487. $params['trade_type'] = 'APP'; //交易类型
  488. $result = $app->handle($params);
  489. if ($result) {
  490. $result['trade_no'] = $params['trade_no'];
  491. return response()->success($result);
  492. } else {
  493. return response()->error('APP_CREATE_WECHAT_ORDER_FAIL');
  494. }
  495. }
  496. /**
  497. * @apiVersion 1.0.0
  498. * @apiDescription 微信H5支付
  499. * @api {get} goToH5Pay 微信H5支付
  500. * @apiGroup pay
  501. * @apiName wxH5Index
  502. * @apiParam {Int} product_id product_id
  503. * @apiParam {Int} send_order_id send_order_id
  504. * @apiParam {String} bid bid
  505. * @apiHeader {String} [Authorization] token
  506. * @apiSuccess {int} code 状态码
  507. * @apiSuccess {String} msg 信息
  508. * @apiSuccess {Object} data 信息
  509. * @apiSuccess {Object} data.trade_no 订单号
  510. * @apiSuccess {Object} data.appId 唤起支付的appId
  511. * @apiSuccess {Object} data.mch_id 唤起支付的mch_id
  512. * @apiSuccess {Object} data.nonce_str 唤起支付的nonce_str
  513. * @apiSuccess {Object} data.prepay_id 唤起支付的prepay_id
  514. * @apiSuccess {Object} data.sign 唤起支付的sign
  515. * @apiSuccess {Object} data.trade_type 唤起支付trade_type
  516. * @apiSuccess {Object} data.mweb_url 唤起支付mweb_url
  517. * @apiSuccessExample {json} Success-Response:
  518. * HTTP/1.1 200 OK
  519. * {
  520. * code: 0,
  521. * msg: "",
  522. * data: {
  523. *
  524. * }
  525. */
  526. function wxH5Index(Request $request)
  527. {
  528. if ($params = $this->getPayParams($request)) {
  529. $params['pay_merchant_id'] = $this->h5_pay_merchat_id;
  530. } else {
  531. return response()->error('QAPP_PARAM_ERROR');
  532. }
  533. $app = OrderArousePayFactory::wx($this->uid);
  534. // 微信支付参数
  535. $params['trade_type'] = 'MWEB'; //交易类型
  536. $result = $app->handle($params);
  537. if ($result) {
  538. $result['trade_no'] = $params['trade_no'];
  539. return response()->success($result);
  540. } else {
  541. return response()->error('APP_CREATE_WECHAT_ORDER_FAIL');
  542. }
  543. }
  544. /**
  545. * @apiVersion 1.0.0
  546. * @apiDescription 支付宝APP支付
  547. * @api {get} goToAliPay 支付宝APP支付
  548. * @apiGroup pay
  549. * @apiName aliIndex
  550. * @apiParam {Int} product_id product_id
  551. * @apiParam {Int} send_order_id send_order_id
  552. * @apiParam {String} bid bid
  553. * @apiHeader {String} [Authorization] token
  554. * @apiSuccess {Object} data.order_info 唤起支付信息str
  555. * @apiSuccess {Object} data.trade_no 订单号
  556. * @apiSuccessExample {json} Success-Response:
  557. * HTTP/1.1 200 OK
  558. * {
  559. * code: 0,
  560. * msg: "",
  561. * data:""
  562. *
  563. */
  564. public function aliIndex(Request $request)
  565. {
  566. if ($params = $this->getPayParams($request)) {
  567. $params['pay_merchant_id'] = $this->ali_pay_merchat_id;
  568. $params['type'] = 'App';
  569. } else {
  570. return response()->error('QAPP_PARAM_ERROR');
  571. }
  572. $app = OrderArousePayFactory::ali($this->uid);
  573. $order_info = $app->handle($params);
  574. return response()->success(['trade_no' => $params['trade_no'], 'order_info' => $order_info]);
  575. }
  576. /**
  577. * @apiVersion 1.0.0
  578. * @apiDescription 订单查询
  579. * @api {get} checkOrder 订单查询
  580. * @apiGroup pay
  581. * @apiName checkOrder
  582. * @apiParam {String} [token] token
  583. * @apiHeader {String} [Authorization] token 两个token任选其一
  584. * @apiParam {String} order order
  585. * @apiSuccess {int} code 状态码
  586. * @apiSuccess {String} msg 信息
  587. * @apiSuccess {Object} data 信息
  588. * @apiSuccessExample {json} Success-Response:
  589. * HTTP/1.1 200 OK
  590. * {
  591. * code: 0,
  592. * msg: "",
  593. * data: {
  594. *
  595. * }
  596. */
  597. public function checkOrder(Request $request)
  598. {
  599. $order = $request->input('order');
  600. $order_info = OrderService::getByTradeNo($order);
  601. if ($order_info && $order_info->status == 'PAID') {
  602. return response()->success();
  603. }
  604. return response()->success($order);
  605. }
  606. /**
  607. * 官方微信回调
  608. */
  609. function wxback(Request $request)
  610. {
  611. $xml = XML::parse(strval($request->getContent()));
  612. myLog('wxpay')->info($xml);
  613. if (isset($xml['attach'])) {
  614. $pay_merchant_id = (int)$xml['attach'];
  615. $config = PayMerchantService::findPayConfig($pay_merchant_id);
  616. $app = PayFactory::official($config);
  617. $response = $app->notify()->handleNotify(function ($notify, $successful) {
  618. if (!$successful) {
  619. return 'fail';
  620. }
  621. if (OrderPaySuccess::handle($notify->out_trade_no, $notify->transaction_id)) {
  622. return true;
  623. } else {
  624. return 'fail';
  625. }
  626. });
  627. return $response;
  628. } else {
  629. return 'fail';
  630. }
  631. }
  632. /**
  633. * 支付宝支付回调
  634. */
  635. function aliback(Request $request)
  636. {
  637. $param = $request->except('_url');
  638. myLog('alipay')->info($param);
  639. $trade_no = isset($param['out_trade_no']) ? $param['out_trade_no'] : '';
  640. if ($trade_no) {
  641. $order = Order::where('trade_no', $trade_no)->first();
  642. $pay_merchant_id = $order ? $order->pay_merchant_id : 0;
  643. $pay_merchant_id = $pay_merchant_id ? $pay_merchant_id : 140;
  644. $config = PayMerchantService::findAliPayConfig($pay_merchant_id);
  645. $app = PayFactory::aliPay($config);
  646. if ($app->notify($param)) {
  647. if (OrderPaySuccess::handle($param['out_trade_no'], $param['trade_no'])) {
  648. return response('success');
  649. } else {
  650. return response('fail');
  651. }
  652. }
  653. }
  654. myLog('alipay')->info('sign fail');
  655. return response('fail');
  656. }
  657. function wait(Request $request)
  658. {
  659. $param = $request->except('_url');
  660. return view('pay.middleware')->with($param);
  661. }
  662. }