OrdersController.php 29 KB

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