Info.php 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  1. <?php
  2. namespace Account\Lib;
  3. use Dever;
  4. class Info
  5. {
  6. public function test_api()
  7. {
  8. //return $this->up(1, 500, 'tixian', 'role_zijin', 'test');
  9. return $this->up_commit(1, 1, 'chongzhi', 'role_zijin', 'test');
  10. }
  11. public function getName($uid, $config_id)
  12. {
  13. $name = $uid;
  14. $info = Dever::db('account/config')->find($config_id);
  15. if ($info) {
  16. $project = Dever::db('account/config_project')->find($info['project_id']);
  17. $source = Dever::db($project['source'])->find($uid);
  18. if ($source) {
  19. return $source[$project['source_name']];
  20. }
  21. }
  22. return $name;
  23. }
  24. public function getSearch($config_id)
  25. {
  26. $result = '';
  27. $info = Dever::db('account/config')->find($config_id);
  28. if ($info) {
  29. $project = Dever::db('account/config_project')->find($info['project_id']);
  30. $result = array
  31. (
  32. 'api' => $project['source'] . '-all',
  33. 'col' => $project['source_name'],
  34. 'result' => 'id',
  35. 'search' => 'uid',
  36. );
  37. }
  38. return $result;
  39. }
  40. # 入账
  41. public function up_commit($uid, $cash, $type, $config, $desc = '', $source = '', $source_id = '', $method = 1)
  42. {
  43. if ($cash == 0) {
  44. Dever::alert('金额不能为0');
  45. }
  46. $config = Dever::db('account/config')->find(array('key' => $config));
  47. if (!$config) {
  48. Dever::alert('账户信息不存在');
  49. }
  50. $project = Dever::db('account/config_project')->find($config['project_id']);
  51. $user = Dever::db($project['source'])->find($uid);
  52. if (!$user) {
  53. Dever::alert('用户信息不存在');
  54. }
  55. $type = Dever::db('account/config_type')->find(array('key' => $type));
  56. if (!$type) {
  57. Dever::alert('交易类型不存在');
  58. }
  59. if ($type['project_id'] != -1 && $type['project_id'] != $config['project_id']) {
  60. Dever::alert('交易类型不正确');
  61. }
  62. $data['uid'] = $uid;
  63. $data['config_id'] = $config['id'];
  64. $data['project_id'] = $config['project_id'];
  65. $data['clear'] = true;
  66. $info = Dever::db('account/info')->find($data);
  67. if (!$info) {
  68. $info['id'] = Dever::db('account/info')->insert($data);
  69. if (!$info['id']) {
  70. Dever::alert('用户信息不存在');
  71. }
  72. $info['cash'] = 0;
  73. }
  74. if ($type['key'] == 'tixian') {
  75. if ($config['is_withdraw'] == 2) {
  76. Dever::alert('当前账户不能提现');
  77. }
  78. if ($config['withdraw_down'] > 0 && $cash < $config['withdraw_down']) {
  79. Dever::alert('提现金额不能少于' . $config['withdraw_down']);
  80. }
  81. if ($config['withdraw_up'] > 0 && $cash > $config['withdraw_up']) {
  82. Dever::alert('提现金额不能大于' . $config['withdraw_up']);
  83. }
  84. if ($cash > $info['cash']) {
  85. Dever::alert('提现金额不能大于账户余额');
  86. }
  87. }
  88. $func = 'inc';
  89. if ($type['type'] == 2) {
  90. $cash = -1*$cash;
  91. $func = 'dec';
  92. }
  93. $data['cash'] = $cash;
  94. $data['type_id'] = $type['id'];
  95. if ($source) {
  96. $data['source'] = $source;
  97. }
  98. if ($source_id) {
  99. $data['source_id'] = $source_id;
  100. }
  101. if ($desc) {
  102. $data['desc'] = $desc;
  103. }
  104. if ($info) {
  105. $data['yue'] = $info['cash'] + $data['cash'];
  106. } else {
  107. $data['yue'] = 0;
  108. }
  109. if ($data['yue'] < 0) {
  110. $data['yue'] = 0;
  111. }
  112. $yue = $data['yue'];
  113. $data['method'] = $method;
  114. $admin = Dever::load('manage/auth.data');
  115. if ($admin) {
  116. $data['admin_id'] = $admin['id'];
  117. }
  118. $data['clear'] = true;
  119. $id = Dever::db('account/info_log')->insert($data);
  120. if ($id) {
  121. $update = array();
  122. $update['where_id'] = $info['id'];
  123. $update['set_cash'] = $data['cash'];
  124. $update['set_col'] = $data['cash'];
  125. $update['clear'] = true;
  126. Dever::db('account/info')->$func($update);
  127. }
  128. return $yue;
  129. }
  130. }