OrdersController.php 26 KB

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