Info.php 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160
  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. 'project_name' => $project['name'],
  37. 'name' => $info['name'],
  38. );
  39. }
  40. return $result;
  41. }
  42. # 入账
  43. public function up_commit($uid, $cash, $type, $config, $desc = '', $source = '', $source_id = '', $method = 1, $state = true)
  44. {
  45. if ($cash == 0) {
  46. return $this->alert('金额不能为0', $state);
  47. }
  48. $config = Dever::db('account/config')->find(array('key' => $config));
  49. if (!$config) {
  50. return $this->alert('账户信息不存在', $state);
  51. }
  52. $project = Dever::db('account/config_project')->find($config['project_id']);
  53. $user = Dever::db($project['source'])->find($uid);
  54. if (!$user) {
  55. return $this->alert('用户信息不存在', $state);
  56. }
  57. $type = Dever::db('account/config_type')->find(array('key' => $type));
  58. if (!$type) {
  59. return $this->alert('交易类型不存在', $state);
  60. }
  61. if ($type['project_id'] != -1 && $type['project_id'] != $config['project_id']) {
  62. return $this->alert('交易类型不正确', $state);
  63. }
  64. $data['uid'] = $uid;
  65. $data['config_id'] = $config['id'];
  66. $data['project_id'] = $config['project_id'];
  67. $data['clear'] = true;
  68. $info = Dever::db('account/info')->find($data);
  69. if (!$info) {
  70. $info['id'] = Dever::db('account/info')->insert($data);
  71. if (!$info['id']) {
  72. return $this->alert('用户信息不存在', $state);
  73. }
  74. $info['cash'] = 0;
  75. }
  76. if ($type['key'] == 'tixian') {
  77. if ($config['is_withdraw'] == 2) {
  78. return $this->alert('当前账户不能提现', $state);
  79. }
  80. if ($config['withdraw_down'] > 0 && $cash < $config['withdraw_down']) {
  81. return $this->alert('提现金额不能少于' . $config['withdraw_down'], $state);
  82. }
  83. if ($config['withdraw_up'] > 0 && $cash > $config['withdraw_up']) {
  84. return $this->alert('提现金额不能大于' . $config['withdraw_up'], $state);
  85. }
  86. if ($cash > $info['cash']) {
  87. return $this->alert('提现金额不能大于账户余额', $state);
  88. }
  89. }
  90. $func = 'inc';
  91. if ($type['type'] == 2) {
  92. $cash = -1*$cash;
  93. $func = 'dec';
  94. }
  95. $data['info_id'] = $info['id'];
  96. $data['cash'] = $cash;
  97. $data['type_id'] = $type['id'];
  98. if ($source) {
  99. $data['source'] = $source;
  100. }
  101. if ($source_id) {
  102. $data['source_id'] = $source_id;
  103. }
  104. if ($desc) {
  105. $data['desc'] = $desc;
  106. }
  107. if ($info) {
  108. $data['yue'] = $info['cash'] + $data['cash'];
  109. } else {
  110. $data['yue'] = 0;
  111. }
  112. if ($data['yue'] < 0) {
  113. $data['yue'] = 0;
  114. }
  115. $yue = $data['yue'];
  116. $data['method'] = $method;
  117. $admin = Dever::load('manage/auth.data');
  118. if ($admin) {
  119. $data['admin_id'] = $admin['id'];
  120. }
  121. $data['clear'] = true;
  122. $id = Dever::db('account/info_log')->insert($data);
  123. if ($id) {
  124. $update = array();
  125. $update['where_id'] = $info['id'];
  126. $update['set_cash'] = $data['cash'];
  127. $update['set_col'] = $data['cash'];
  128. $update['clear'] = true;
  129. Dever::db('account/info')->$func($update);
  130. }
  131. return $yue;
  132. }
  133. private function alert($msg, $state = true)
  134. {
  135. if ($state) {
  136. return Dever::alert($msg);
  137. }
  138. return -1;
  139. }
  140. }