OrdersController.php 28 KB

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