OrdersController.php 27 KB

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