OrderUtils.php 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. <?php
  2. /**
  3. * OrderUtils.php UTF-8
  4. * 玩家面板
  5. *
  6. * @date : 2018/4/27 20:35
  7. *
  8. * @license 这不是一个自由软件,未经授权不许任何使用和传播。
  9. * @author : wuyonghong <wyh@huosdk.com>
  10. * @version : HUOSDK 8.0
  11. */
  12. namespace huolib\utils;
  13. use huolib\constant\PaywayConst;
  14. use huolib\status\OrderStatus;
  15. class OrderUtils {
  16. CONST AMOUNT_MAX = 10000;
  17. CONST AMOUNT_MIN = 0.01;
  18. /**
  19. * 校验SDK订单
  20. *
  21. * @param array $order_data
  22. *
  23. * @return int
  24. */
  25. public static function checkSdkOrder($order_data = []) {
  26. if (empty($order_data)) {
  27. return OrderStatus::INVALID_PARAMS;
  28. }
  29. if (!isset($order_data['amount']) || $order_data['amount'] <= 0) {
  30. return OrderStatus::INVALID_PARAMS;
  31. }
  32. return OrderStatus::NO_ERROR;
  33. }
  34. /**
  35. * 校验支付方式
  36. *
  37. * @param $payway
  38. *
  39. * @return int
  40. */
  41. public static function checkPayway($payway = '') {
  42. if (empty($payway)) {
  43. return OrderStatus::PAYWAY_INCORRECT;
  44. }
  45. $_rs = PaywayConst::getMsg($payway);
  46. if (false == $_rs) {
  47. return OrderStatus::PAYWAY_INCORRECT;
  48. }
  49. return OrderStatus::NO_ERROR;
  50. }
  51. /**
  52. * 校验支付方式
  53. *
  54. * @param float $amount
  55. *
  56. * @return int
  57. */
  58. public static function checkAmount($amount = 0.0) {
  59. if (empty($amount) || !is_numeric($amount)) {
  60. return OrderStatus::ORDER_AMOUNT_IS_ZERO;
  61. }
  62. if ($amount < self::AMOUNT_MIN) {
  63. return OrderStatus::ORDER_AMOUNT_TOO_LOW;
  64. }
  65. if ($amount > self::AMOUNT_MAX) {
  66. return OrderStatus::ORDER_AMOUNT_TOO_HIGH;
  67. }
  68. return OrderStatus::NO_ERROR;
  69. }
  70. }