OrdersController.php 26 KB

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