Exchange.php 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. <?php
  2. namespace app\api\controller\user;
  3. use app\models\user\UserMoney;
  4. use app\Request;
  5. use crmeb\services\UtilService;
  6. class Exchange
  7. {
  8. //闪兑
  9. public function exchange(Request $request)
  10. {
  11. list($origin_money_type, $money_type, $num) = UtilService::postMore([['origin_money_type', '', '', '', ['not_empty_check', function ($item) {
  12. $money_type = sys_data('money_type');
  13. $flag = false;
  14. foreach ($money_type as $v) {
  15. if ($v['code'] == $item) {
  16. if (!$v['do_exchange']) {
  17. return false;
  18. }
  19. $flag = true;
  20. }
  21. }
  22. return $flag;
  23. }], ['请选择支付币种', '请选择正确的支付币种']], ['money_type', '', '', '', ['not_empty_check', function ($item) {
  24. $money_type = sys_data('money_type');
  25. $flag = false;
  26. foreach ($money_type as $v) {
  27. if ($v['code'] == $item) {
  28. if (!$v['exchange']) {
  29. return false;
  30. }
  31. $flag = true;
  32. }
  33. }
  34. return $flag;
  35. }], ['请选择兑换币种', '请选择正确的兑换币种']], ['num', 0, '', '', ['not_empty_check', function ($item) {
  36. return $item > 0 && is_integer((int)$item);
  37. }], ['请输入要兑换数量', '请输入大于0的整数']]], $request, true);
  38. $res = UserMoney::exchangeMoney($request->uid(), $origin_money_type, $money_type, $num);
  39. if (!$res) {
  40. return app('json')->fail(UserMoney::getErrorInfo());
  41. } else {
  42. return app('json')->success('闪兑成功');
  43. }
  44. }
  45. }