OrdersController.php 26 KB

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