UpdateMoney.php 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. <?php
  2. namespace Biz\Pay;
  3. /**
  4. * 资金变动
  5. * @author UpdateMoney
  6. * */
  7. class UpdateMoney {
  8. /**
  9. * 资金变更
  10. * @param string $orderId 订单ID
  11. * @param string $accountId 用户ID
  12. * @param float $money 变动金额:正为加,负为减
  13. * @return [type]
  14. */
  15. public function Index($orderId = '', $accountId = '', $money = '') {
  16. $moneyInfo = array();
  17. $userInfo = array();
  18. if ($orderId == '' && $accountId == '') {
  19. return -1;
  20. }
  21. if ($orderId == '') {
  22. //用户余额变更
  23. $userInfo = M('account_detailed')->select('cash,available_cash')->
  24. where('account_identity', $accountId)->find();
  25. $newCash = array(
  26. 'cash' => $userInfo['cash'] + $money,
  27. 'available_cash' => $userInfo['available_cash'] + $money,
  28. );
  29. $res = M('account_detailed')->where('account_identity', $accountId)->update($newCash);
  30. if ($res > 0) {
  31. return 1;
  32. } else {
  33. return -1;
  34. }
  35. } else {
  36. //用户资金明细、余额变更
  37. $moneyInfo = M('fund_detailed')->select('account_identity,money,status')->where('order_id', $orderId)->find();
  38. if ($moneyInfo['status'] == 1) {
  39. return 1;
  40. }
  41. $userInfo = M('account_detailed')->select('cash,available_cash')->
  42. where('account_identity', $moneyInfo['account_identity'])->find();
  43. $newCash = array(
  44. 'cash' => $userInfo['cash'] + $moneyInfo['money'],
  45. 'available_cash' => $userInfo['available_cash'] + $moneyInfo['money'],
  46. );
  47. $sw = new DBExtension();
  48. $sw->B();
  49. $sw->ST('fund_detailed')->W('order_id', $orderId)->U(array('status' => 1, 'cur_cash' => $newCash['available_cash']));
  50. $sw->ST('account_detailed')->W('account_identity', $moneyInfo['account_identity'])->U($newCash);
  51. $res = $sw->C();
  52. if ($res) {
  53. return 1;
  54. } else {
  55. return -1;
  56. }
  57. }
  58. }
  59. }