ChannelRechargeCoin.php 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559
  1. <?php
  2. /**
  3. * 渠道充值接口控制器
  4. *
  5. */
  6. namespace app\guildapi\controller;
  7. use app\common\library\WeixinPay;
  8. use app\service\PayService;
  9. use think\Db;
  10. use think\Config;
  11. use think\Exception;
  12. class ChannelRechargeCoin extends Guild
  13. {
  14. protected $nowTime;
  15. protected $payRequestLimit = 5; //重复下单的限制时间
  16. protected $redis; //redis的句柄对象
  17. /**
  18. * 不进行父类的登录验证,所以增加构造方法重写了父类的初始化方法
  19. */
  20. public function _initialize()
  21. {
  22. parent::_initialize();
  23. $this->nowTime = NOW_TIMESTAMP;
  24. $this->redis = \think\Cache::store('default')->handler();
  25. }
  26. /**
  27. * 我的充值列表
  28. * @return [type] [description]
  29. */
  30. public function index()
  31. {
  32. //判断当前账号是否有此功能
  33. if (!in_array($this->_channelLevel, [1, 2])) {
  34. $this->jsonResult('', 0, '您无权限使用该功能');
  35. }
  36. $list_rows = $this->input('list_rows', 10);
  37. $page = $this->input('page', 1);
  38. $type = $this->input('type', '0', 'intval'); //1(充值收入),2(充值支出),3(直充),4(结算充值收入),5(结算充值支出)
  39. $account = $this->input('account', '', 'trim'); //收入账号
  40. $apply_begin_time = $this->input('apply_begin_time', '', 'trim');
  41. $apply_end_time = $this->input('apply_end_time', '', 'trim');
  42. $finish_begin_time = $this->input('finish_begin_time', '', 'trim');
  43. $finish_end_time = $this->input('finish_end_time', '', 'trim');
  44. $condition = [];
  45. if ($account) {
  46. $condition['channel_name'] = $account;
  47. }
  48. if ($type == 1) {
  49. $condition['channel_id'] = $this->_channelId;
  50. $condition['recharge_type'] = 1;
  51. } else if ($type == 2) {
  52. $condition['send_channel_id'] = $this->_channelId;
  53. $condition['recharge_type'] = 1;
  54. } else if ($type == 3) {
  55. $condition['channel_id'] = $this->_channelId;
  56. $condition['recharge_type'] = 2;
  57. } else if ($type == 4) {
  58. $condition['channel_id'] = $this->_channelId;
  59. $condition['recharge_type'] = 3;
  60. } else if ($type == 5) {
  61. $condition['send_channel_id'] = $this->_channelId;
  62. $condition['recharge_type'] = 3;
  63. }
  64. //申请开始时间和结束时间不为空时
  65. if ($apply_begin_time != '' && $apply_end_time != '') {
  66. $condition['create_time'] = [
  67. ['>=', strtotime($apply_begin_time)],
  68. ['<=', strtotime($apply_end_time . ' 23:59:59')],
  69. ];
  70. } //开始时间不为空时
  71. elseif ($apply_begin_time != '') {
  72. $condition['create_time'] = ['>=', strtotime($apply_begin_time)];
  73. } //结束时间不为空时
  74. elseif ($apply_end_time != '') {
  75. $condition['create_time'] = ['<=', strtotime($apply_end_time . ' 23:59:59')];
  76. }
  77. //到账开始时间和结束时间不为空时
  78. if ($finish_begin_time != '' && $finish_end_time != '') {
  79. $condition['finish_time'] = [
  80. ['>=', strtotime($finish_begin_time)],
  81. ['<=', strtotime($finish_end_time . ' 23:59:59')],
  82. ];
  83. } //开始时间不为空时
  84. elseif ($finish_begin_time != '') {
  85. $condition['finish_time'] = ['>=', strtotime($finish_begin_time)];
  86. } //结束时间不为空时
  87. elseif ($finish_end_time != '') {
  88. $condition['finish_time'] = ['<=', strtotime($finish_end_time . ' 23:59:59')];
  89. }
  90. // var_dump($condition);
  91. $rechargeList = model('ChannelRechargeCoin')
  92. ->where($condition)
  93. ->whereRaw('channel_id=' . $this->_channelId . ' or send_channel_id=' . $this->_channelId)
  94. ->order('id desc')
  95. ->paginate(['list_rows' => $list_rows, 'page' => $page])
  96. ->toArray();
  97. // echo model('ChannelRecharge')->getLastSql()."-----lastsql------<br>";
  98. foreach ($rechargeList['data'] as $k=>$v){
  99. if($v['recharge_type'] == 1){
  100. $rechargeList['data'][$k]['recharge_type_str'] = '申请';
  101. }else if($v['recharge_type'] == 2){
  102. $rechargeList['data'][$k]['recharge_type_str'] = '直充';
  103. }else{
  104. $rechargeList['data'][$k]['recharge_type_str'] = '结算币充值';
  105. }
  106. }
  107. $this->jsonResult($rechargeList, 20000, '获取列表成功');
  108. }
  109. /**
  110. * 充值审核列表
  111. * @return [type] [description]
  112. */
  113. public function checklist()
  114. {
  115. //判断当前账号是否有此功能
  116. if (!in_array($this->_channelLevel, [1])) {
  117. $this->jsonResult('', 0, '您无权限使用该功能');
  118. }
  119. $list_rows = input('list_rows', 10);
  120. $page = input('page', 1);
  121. $account = $this->input('account', '', 'trim');
  122. $orderid = $this->input('orderid', '', 'trim');
  123. $apply_begin_time = $this->input('apply_begin_time', '', 'trim');
  124. $apply_end_time = $this->input('apply_end_time', '', 'trim');
  125. $condition = [];
  126. $condition['send_channel_id'] = $this->_channelId;
  127. if ($orderid) {
  128. $condition['orderid'] = $orderid;
  129. }
  130. if ($account) {
  131. $condition['channel_name'] = $account;
  132. }
  133. //申请开始时间和结束时间不为空时
  134. if ($apply_begin_time != '' && $apply_end_time != '') {
  135. $condition['create_time'] = [
  136. ['>=', strtotime($apply_begin_time)],
  137. ['<=', strtotime($apply_end_time . ' 23:59:59')],
  138. ];
  139. } //开始时间不为空时
  140. elseif ($apply_begin_time != '') {
  141. $condition['create_time'] = ['>=', strtotime($apply_begin_time)];
  142. } //结束时间不为空时
  143. elseif ($apply_end_time != '') {
  144. $condition['create_time'] = ['<=', strtotime($apply_end_time . ' 23:59:59')];
  145. }
  146. $rechargeList = model('ChannelRechargeCoin')
  147. ->where($condition)
  148. ->paginate(['list_rows' => $list_rows, 'page' => $page])
  149. ->toArray();
  150. $this->jsonResult($rechargeList, 20000, '获取列表成功');
  151. }
  152. /**
  153. * 充值审核(查看)
  154. */
  155. public function audit()
  156. {
  157. if ($this->request->isPost()) {
  158. $id = intval($this->input('id')); //渠道ID
  159. if (!in_array($this->_channelLevel, [1])) {
  160. $this->jsonResult('', 0, '您不能进行该操作');
  161. }
  162. if (!$id) {
  163. $this->jsonResult('', 0, '请选择要审核的记录');
  164. }
  165. $rechargeInfo = model('ChannelRechargeCoin')->where(['id' => $id, 'send_channel_id' => $this->_channelId])->find();
  166. if (empty($rechargeInfo)) {
  167. $this->jsonResult('', 0, '记录不存在或您无权限操作');
  168. }
  169. $this->jsonResult($rechargeInfo, 20000, '获取记录成功');
  170. exit;
  171. } else {
  172. $this->jsonResult('', 0, '非法请求');
  173. }
  174. }
  175. //充值审核(操作)
  176. function doAudit()
  177. {
  178. if ($this->request->isPost()) {
  179. $id = intval($this->input('id')); //渠道ID
  180. $status = intval($this->input('status')); //审核状态:1(审核通过),2(审核不通过)
  181. $remark = $this->input('remark', '', 'trim'); //审核备注
  182. if (!in_array($this->_channelLevel, [1])) {
  183. $this->jsonResult('', 0, '您不能进行该操作');
  184. }
  185. if (!$id) {
  186. $this->jsonResult('', 0, '请选择要审核的记录');
  187. }
  188. if ($status <> 1 && $status <> 2) {
  189. $this->jsonResult('', 0, '非法审核状态');
  190. }
  191. $rechargeInfo = model('ChannelRechargeCoin')->where(['id' => $id, 'send_channel_id' => $this->_channelId])->find();
  192. if (empty($rechargeInfo)) {
  193. $this->jsonResult('', 0, '记录不存在或您无权限操作');
  194. } else if ($rechargeInfo['status'] <> 0) {
  195. $this->jsonResult('', 0, '该记录已审核过');
  196. }
  197. $channelInfo = model("Channel")->where(['id' => $this->_channelId])->find();
  198. if ($channelInfo) {
  199. if ($channelInfo['amount'] < $rechargeInfo['amount']) {
  200. $this->jsonResult('', 0, '您当前余额不足,不能进行审核发币');
  201. }
  202. } else {
  203. $this->jsonResult('', 0, '您的账号有异常,请联系管理员');
  204. }
  205. $auditData = array();
  206. $auditData['id'] = $id;
  207. $auditData['status'] = $status;
  208. $auditData['finish_time'] = NOW_TIMESTAMP;
  209. $auditData['check_remark'] = $remark;
  210. $auditData['check_admin_type'] = 2;
  211. $auditData['check_admin_name'] = $this->_channelName;
  212. Db::startTrans();
  213. try {
  214. //审核通过
  215. if ($status == 1) {
  216. $detData = array();
  217. $detData['channel_id'] = $this->_channelId;
  218. $detData['channel_name'] = $this->_channelName;
  219. $detData['change_amount'] = -$rechargeInfo['amount'];
  220. $detData['account_type'] = 3; //平台币账户
  221. $detData['type'] = 5; //充值支出
  222. $detData['out_orderid'] = $rechargeInfo['orderid'];
  223. $detData['create_time'] = NOW_TIMESTAMP;
  224. $insertDetId = model('ChannelAccountDet')->insertGetId($detData);
  225. if (!$insertDetId) {
  226. throw new Exception("添加账户变动明细失败");
  227. }
  228. $updData = array();
  229. $updData['amount_coin'] = Db::raw("amount_coin-" . $rechargeInfo['amount']);
  230. $updData['update_time'] = time();
  231. $updFromResult = model('Channel')->where(['id' => $this->_channelId, 'amount_coin' => array('egt', $rechargeInfo['amount'])])->update($updData);
  232. if (!$updFromResult) {
  233. throw new Exception("账户金额变动失败");
  234. }
  235. $detData = array();
  236. $detData['channel_id'] = $rechargeInfo['channel_id'];
  237. $detData['channel_name'] = $rechargeInfo['channel_name'];
  238. $detData['change_amount'] = $rechargeInfo['amount'];
  239. $detData['account_type'] = 3; //平台币账户
  240. $detData['type'] = 4; //充值收入
  241. $detData['out_orderid'] = $rechargeInfo['orderid'];
  242. $detData['create_time'] = NOW_TIMESTAMP;
  243. $insertDetId = model('ChannelAccountDet')->insertGetId($detData);
  244. if (!$insertDetId) {
  245. throw new Exception("添加账户变动明细失败");
  246. }
  247. $updData = array();
  248. $updData['amount_coin'] = Db::raw("amount_coin+" . $rechargeInfo['amount']);
  249. $updData['update_time'] = time();
  250. $updToResult = model('Channel')->where(['id' => $rechargeInfo['channel_id']])->update($updData);
  251. if (!$updToResult) {
  252. throw new Exception("账户金额变动失败");
  253. }
  254. $auditData['finish_status'] = 1;
  255. $result = model('ChannelRechargeCoin')->where(['id' => $id, 'status' => array('in', [0])])->update($auditData);
  256. if (!$result) {
  257. throw new Exception("充值审核失败");
  258. }
  259. } else if ($status == 2) { //审核不通过
  260. $result = model('ChannelRechargeCoin')->where(['id' => $id, 'status' => array('in', [0])])->update($auditData);
  261. if (!$result) {
  262. throw new Exception("充值审核失败");
  263. }
  264. }
  265. Db::commit();
  266. } catch (\Exception $e) {
  267. Db::rollback();
  268. $this->jsonResult('', 0, '添加失败: ' . $e->getMessage());
  269. }
  270. $this->jsonResult('', 20000, '审核成功');
  271. exit;
  272. } else {
  273. $this->jsonResult('', 0, '非法请求');
  274. }
  275. }
  276. /**
  277. * 充值页面
  278. */
  279. public function recharge()
  280. {
  281. if ($this->request->isPost()) {
  282. //判断当前账号是否有充值权限
  283. if (!in_array($this->_channelLevel, [1, 2])) {
  284. $this->jsonResult('', 0, '您无权限进行充值相关操作');
  285. } else {
  286. $channelInfo = model("Channel")->field("id,name,level,parent_id,amount_coin,js_amount")->where(['id' => $this->_channelId])->find();
  287. if (!$channelInfo) {
  288. $this->jsonResult('', 0, '账号异常,请重新登录后再试');
  289. }
  290. $adminInfo = model("ChannelAdmin")->field("id,username,channel_id,pay_password,secondary_password")->where(['id' => session('guild_info')['id'], 'channel_id' => $this->_channelId])->find();
  291. if (!$adminInfo) {
  292. $this->jsonResult('', 0, '账号异常,请重新登录后再试');
  293. } else if (!$adminInfo['secondary_password']) {
  294. $this->jsonResult('', 0, '请先设置二级密码后才能进行操作');
  295. }
  296. //判断支付金额
  297. // $condis = array();
  298. // $condis['channel_id'] = $this->_channelId;
  299. // $condis['begin_time'] = array('elt',$this->nowTime);
  300. // $condis['end_time'] = array('egt',$this->nowTime);
  301. // $rechargeRatio = model("ChannelRechargeCoinRatio")->where($condis)->find();
  302. // if(!empty($rechargeRatio) && $rechargeRatio['ratio']){
  303. // $rechargeRatio = $rechargeRatio['ratio'];
  304. // }
  305. // else{
  306. // $rechargeRatio = 100;
  307. // }
  308. $channelInfo['recharge_ratio'] = 100;
  309. $this->jsonResult($channelInfo, 20000, '获取充值相关信息成功');
  310. }
  311. exit;
  312. } else {
  313. $this->jsonResult('', 0, '非法请求');
  314. exit;
  315. }
  316. }
  317. /**
  318. * 充值操作处理
  319. */
  320. public function doRecharge()
  321. {
  322. if ($this->request->isPost()) {
  323. $amount = $this->input('amount'); //充值金额
  324. $real_amount = $this->input('real_amount'); //支付金额
  325. $recharge_type = $this->input('recharge_type'); //充值方式:1(申请),2(直充),3(结算币充值)
  326. $paytype = $this->input('paytype'); //支付类型:zfb(支付宝),wxpay(微信)
  327. $out_order_no = $this->input('out_order_no'); //交易凭证
  328. $remark = $this->input('remark'); //备注
  329. $orderid = makeOrderid('CPSCOIN');
  330. $checkResult = $this->validate($this->input, 'ChannelRechargeCoin.add');
  331. if (true !== $checkResult) {
  332. $this->jsonResult('', 0, $checkResult);
  333. }
  334. //判断当前账号是否有充值权限
  335. if (!in_array($this->_channelLevel, [1, 2])) {
  336. $this->jsonResult('', 0, '您不能进行充值');
  337. }
  338. if (!in_array($recharge_type, [1, 2, 3])) {
  339. $this->jsonResult('', 0, '非正确的充值方式');
  340. } else {
  341. if ($recharge_type == 2 && !in_array($paytype, ['zfbsmzf', 'kdsm'])) {
  342. $this->jsonResult('', 0, '非正确的支付类型');
  343. }
  344. }
  345. if ($this->_channelLevel == 2 && $recharge_type <> 1) {
  346. $this->jsonResult('', 0, '您只能使用申请方式充值');
  347. }
  348. if (abs(intval($real_amount * 100) / 100 - $real_amount) > 0.01) {
  349. $this->jsonResult('', 0, '请正确填写支付金额!');
  350. } else {
  351. //判断支付金额
  352. // $condis = array();
  353. // $condis['channel_id'] = $this->_channelId;
  354. // $condis['begin_time'] = array('elt', $this->nowTime);
  355. // $condis['end_time'] = array('egt', $this->nowTime);
  356. // $rechargeRatio = model("ChannelRechargeCoinRatio")->where($condis)->find();
  357. // if(!empty($rechargeRatio) && $rechargeRatio['ratio']){
  358. // $rechargeRatio = $rechargeRatio['ratio'];
  359. // }
  360. // else{
  361. // $rechargeRatio = 100;
  362. // }
  363. $rechargeRatio = 100;
  364. $discountAmt = floatval($amount * $rechargeRatio / 100);
  365. if ($discountAmt <> $real_amount) {
  366. $this->jsonResult('', 0, '充值金额异常,请刷新页面后重新充值');
  367. }
  368. }
  369. $channelInfo = model("Channel")->where(['id' => $this->_channelId])->find();
  370. if ($channelInfo && $channelInfo['parent_id']) {
  371. if ($recharge_type == 3 && $channelInfo['js_amount'] < $amount) {
  372. $this->jsonResult('', 0, '您的结算币余额不足');
  373. }
  374. } else {
  375. $this->jsonResult('', 0, '您的账号有异常,请联系管理员');
  376. }
  377. //指定时间内,禁止重复下单
  378. if (!requestDuplicateCheck('recharge_pay_duplicate_' . $this->_channelId, $this->payRequestLimit)) {
  379. $this->jsonResult('', 0, '充值请求过多,请于' . $this->payRequestLimit . 's以后,再次进行充值操作');
  380. }
  381. $rechargeData = array();
  382. $rechargeData['orderid'] = $orderid;
  383. $rechargeData['channel_id'] = $this->_channelId;
  384. $rechargeData['channel_name'] = $this->_channelName;
  385. if ($this->_channelLevel == 1) {
  386. $rechargeData['send_channel_id'] = '0';
  387. $rechargeData['send_channel_name'] = '平台';
  388. } else if ($this->_channelLevel == 2) {
  389. $parentChannelInfo = model("Channel")->where(['id' => $channelInfo['parent_id']])->find();
  390. $rechargeData['send_channel_id'] = $parentChannelInfo['id'];
  391. $rechargeData['send_channel_name'] = $parentChannelInfo['name'];
  392. }
  393. $rechargeData['amount'] = $amount;
  394. $rechargeData['real_amount'] = $real_amount;
  395. $rechargeData['recharge_type'] = $recharge_type;
  396. $rechargeData['paytype'] = $paytype;
  397. $rechargeData['out_order_no'] = $out_order_no;
  398. $rechargeData['remark'] = $remark;
  399. $rechargeData['recharge_ratio'] = $rechargeRatio;
  400. $rechargeData['status'] = 0;
  401. $rechargeData['create_time'] = time();
  402. // 启动事务
  403. Db::startTrans();
  404. try {
  405. $result = []; //返回值
  406. //结算币充值
  407. if ($recharge_type == 3) {
  408. $rechargeData['status'] = 1;
  409. $rechargeData['finish_status'] = 1;
  410. $rechargeData['finish_time'] = NOW_TIMESTAMP;
  411. $insertRechargeId = model("ChannelRechargeCoin")->insert($rechargeData);
  412. if (!$insertRechargeId) {
  413. throw new Exception("创建订单失败! ");
  414. }
  415. $detData = array();
  416. $detData['channel_id'] = $this->_channelId;
  417. $detData['channel_name'] = $this->_channelName;
  418. $detData['change_amount'] = -$amount;
  419. $detData['account_type'] = 2; //结算账户
  420. $detData['type'] = 7; //结算充值
  421. $detData['out_orderid'] = $orderid;
  422. $detData['create_time'] = NOW_TIMESTAMP;
  423. $insertDetId = model('ChannelAccountDet')->insertGetId($detData);
  424. if (!$insertDetId) {
  425. throw new Exception("添加账户变动明细失败");
  426. }
  427. $updData = array();
  428. $updData['js_amount'] = Db::raw("js_amount-" . $amount);
  429. $updData['update_time'] = time();
  430. $updResult = model('Channel')->where(['id' => $this->_channelId, 'js_amount' => array('egt', $amount)])->update($updData);
  431. if (!$updResult) {
  432. throw new Exception("账户金额变动失败");
  433. }
  434. $detData = array();
  435. $detData['channel_id'] = $this->_channelId;
  436. $detData['channel_name'] = $this->_channelName;
  437. $detData['change_amount'] = $amount;
  438. $detData['account_type'] = 3; //平台币账户
  439. $detData['type'] = 4; //充值收入
  440. $detData['out_orderid'] = $orderid;
  441. $detData['create_time'] = NOW_TIMESTAMP;
  442. $insertDetId = model('ChannelAccountDet')->insertGetId($detData);
  443. if (!$insertDetId) {
  444. throw new Exception("添加账户变动明细失败");
  445. }
  446. $updData = array();
  447. $updData['amount_coin'] = Db::raw("amount_coin+" . $amount);
  448. $updData['update_time'] = time();
  449. $updResult = model('Channel')->where(['id' => $this->_channelId])->update($updData);
  450. if (!$updResult) {
  451. throw new Exception("账户金额变动失败");
  452. }
  453. } else {
  454. $insertRechargeId = model("ChannelRechargeCoin")->insert($rechargeData);
  455. if (!$insertRechargeId) {
  456. throw new Exception("创建订单失败! ");
  457. }
  458. }
  459. // 提交事务
  460. Db::commit();
  461. $this->redis->del('recharge_pay_duplicate_' . $this->_channelId);
  462. if ($recharge_type == 2) {
  463. //第三方支付用的商品简单描述 (去除&+等特殊字符)
  464. $payBody = "cps充值";
  465. $pay = new PayService();
  466. //支付方式是支付宝或者支付宝混合支付时
  467. if ($paytype == 'zfbsmzf') {
  468. //支付宝支付参数
  469. $notify_url = "http://" . HTTP_HOST_URL . "/v1.cps_notify/alipayAop.html";
  470. // $notify_url = Config::get('ali_pay_config')['notify_url'];
  471. $qrcodePay = $pay->chargeByZfbWap($orderid, $rechargeData['real_amount'], $payBody, '', $notify_url);
  472. $qrcodePay = str_replace("method='POST'","method='POST' target='_blank'",$qrcodePay);
  473. $result['alipay_param'] = $qrcodePay;
  474. } //支付方式是微信官方h5支付或者微信官方h5混合支付时
  475. elseif ($paytype == 'kdsm') {
  476. throw new Exception("非法操作! ");
  477. // $notify_url = "http://" . HTTP_HOST_URL . "/v1.cps_notify/kdh5zhifu.html";
  478. // // $notify_url = Config::get('kdh5')['notify_coin_url'];
  479. // $kdsm_param = $pay->getkdsmweixinParam($orderid, $rechargeData['real_amount'], $payBody, $notify_url);
  480. // $dataPay = [
  481. // 'id' => $insertRechargeId,
  482. // 'orderid' => $orderid,
  483. // 'kdsm_param' => $kdsm_param,
  484. // 'real_amount' => priceFormat($real_amount),
  485. // 'create_time' => date('Y-m-d'),
  486. // 'goods' => 'cps充值',
  487. // ];
  488. // $pay_url = Config::get('kdh5')['pay_url'] . '?data=' . opensslEncrypt(json_encode($dataPay));
  489. // $result = ['kdsm_param' => $pay_url];
  490. }
  491. }
  492. } catch (\Exception $e) {
  493. // 回滚事务
  494. Db::rollback();
  495. $this->jsonResult('', 0, '订单生成失败' . $e->getMessage());
  496. }
  497. $result['orderid'] = $orderid;
  498. $this->jsonResult($result, 20000, '订单生成成功');
  499. exit;
  500. } else {
  501. $this->jsonResult('', 0, '非法请求');
  502. exit;
  503. }
  504. }
  505. }