You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 

108 lines
2.8 KiB

  1. <?php
  2. /**
  3. * 分销用户钱包
  4. * Created by PhpStorm.
  5. * User: admin
  6. * Date: 2017/5/4
  7. * Time: 10:29
  8. */
  9. namespace common\util;
  10. use common\models\FxUserAccount;
  11. use common\models\FxUserAmountLog;
  12. use common\models\OrderMain;
  13. class FxAmount
  14. {
  15. /**
  16. * 余额支付
  17. * @param $fx_uid
  18. * @param $amount
  19. * @return array
  20. */
  21. public static function pay($fx_uid, $amount)
  22. {
  23. /****判断余额是否充足***/
  24. $fxUserAccount = new FxUserAccount();
  25. $info = $fxUserAccount->getMyCommission($fx_uid);
  26. if ($info['remaining_sum'] < $amount) {
  27. return Util::returnArrEr('账户余额不足!');
  28. }
  29. /**扣除余额**/
  30. $flag = $fxUserAccount->deductAmount($fx_uid, $amount);
  31. if ($flag) {
  32. static::addLog($fx_uid, 2, $amount, '');
  33. return Util::returnArrSu();
  34. } else {
  35. return Util::returnArrEr('余额支付失败!');
  36. }
  37. }
  38. /**
  39. * 退款
  40. * @param $fx_uid
  41. * @param $amount
  42. * @return array
  43. */
  44. public static function refund($fx_uid, $amount)
  45. {
  46. $fxUserAccount = new FxUserAccount();
  47. $flag = $fxUserAccount->rechargeAmount($fx_uid, $amount);
  48. if ($flag) {
  49. static::addLog($fx_uid, 3, $amount, '');
  50. return Util::returnArrSu();
  51. } else {
  52. return Util::returnArrEr('退款失败![amount_1001]');
  53. }
  54. }
  55. /**
  56. * 充值
  57. * @param $fx_uid
  58. * @param $amount
  59. * @return array
  60. */
  61. public static function recharge($fx_uid, $amount)
  62. {
  63. $fxUserAccount = new FxUserAccount();
  64. $flag = $fxUserAccount->rechargeAmount($fx_uid, $amount);
  65. if ($flag) {
  66. static::addLog($fx_uid, 1, $amount, '');
  67. return Util::returnArrSu();
  68. } else {
  69. return Util::returnArrEr('充值失败![amount_1002]');
  70. }
  71. }
  72. /**
  73. * 添加日志
  74. * @param $fx_uid
  75. * @param $trade_type int 交易类型 1、充值 2、支出 3、退款
  76. * @param $amount
  77. * @param $msg
  78. * @return array
  79. */
  80. public static function addLog($fx_uid, $trade_type, $amount, $msg)
  81. {
  82. $fxUserAccount = new FxUserAccount();
  83. $info = $fxUserAccount->getMyCommission($fx_uid);
  84. $remaining_sum = $info['remaining_sum'];
  85. $fxUserAmountLog = new FxUserAmountLog();
  86. return $fxUserAmountLog->addLog($fx_uid, $trade_type, $amount, $remaining_sum, $msg);
  87. }
  88. /**
  89. * 取消订单加扣款
  90. * @param $params
  91. * @return array
  92. */
  93. public function cancelOrder($params)
  94. {
  95. $order = new OrderMain();
  96. $orderInfo = $order->getOrderInfo($params['order_id']);
  97. $fx_uid = $orderInfo['fx_uid'];
  98. return self::refund($fx_uid, $params['refund_fee']);
  99. }
  100. }