Info.php 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180
  1. <?php
  2. namespace Account\Lib;
  3. use Dever;
  4. class Info
  5. {
  6. # 获取用户账户基本信息
  7. public function getUserInfo($uid, $config_id = false)
  8. {
  9. $info = $this->getInfo($uid, $config_id);
  10. return array('name' => $info['config']['name'], 'cash' => $info['cash']);
  11. }
  12. # 获取账户信息
  13. public function getInfo($uid, $config_id = false, $check = 0)
  14. {
  15. $key = Dever::input('account_key');
  16. if ($key) {
  17. $config = Dever::db('account/config')->one(array('key' => $account));
  18. } else {
  19. if (!$config_id) {
  20. $config = Dever::db('account/config')->one(array('type' => 1));
  21. } else {
  22. $config = Dever::db('account/config')->one($config_id);
  23. }
  24. }
  25. if ($config) {
  26. # 检测是否可以充值
  27. if ($check == 1 && $config['is_pay'] == 2) {
  28. Dever::alert('当前账户不允许充值');
  29. }
  30. # 检测是否可以提现
  31. if ($check == 2 && $config['is_withdraw'] == 2) {
  32. Dever::alert('当前账户不允许提现');
  33. }
  34. $where = array();
  35. $where['uid'] = $uid;
  36. $where['config_id'] = $config['id'];
  37. $account = Dever::db('account/info')->one($where);
  38. if (!$account) {
  39. $id = Dever::db('account/info')->insert($where);
  40. $account = Dever::db('account/info')->one($id);
  41. }
  42. $account['config'] = $config;
  43. return $account;
  44. } else {
  45. Dever::alert('钱包配置不存在');
  46. }
  47. }
  48. # 入账
  49. public function up_commit($uid, $cash, $type, $config, $desc = '', $source = '', $source_id = '', $method = 1, $state = true)
  50. {
  51. if ($cash == 0) {
  52. return $this->alert('金额不能为0', $state);
  53. }
  54. if (!is_array($config)) {
  55. $config = Dever::db('account/config')->find(array('key' => $config));
  56. }
  57. if (!$config) {
  58. return $this->alert('账户信息不存在', $state);
  59. }
  60. $project = Dever::db('account/config_project')->find($config['project_id']);
  61. $user = Dever::db($project['source'])->find($uid);
  62. if (!$user) {
  63. return $this->alert('用户信息不存在', $state);
  64. }
  65. if (!is_array($type)) {
  66. $type = Dever::db('account/config_type')->find(array('key' => $type));
  67. }
  68. if (!$type) {
  69. return $this->alert('交易类型不存在', $state);
  70. }
  71. if ($type['project_id'] != -1 && $type['project_id'] != $config['project_id']) {
  72. return $this->alert('交易类型不正确', $state);
  73. }
  74. $data['uid'] = $uid;
  75. $data['config_id'] = $config['id'];
  76. $data['project_id'] = $config['project_id'];
  77. $data['clear'] = true;
  78. $info = Dever::db('account/info')->find($data);
  79. if (!$info) {
  80. $info['id'] = Dever::db('account/info')->insert($data);
  81. if (!$info['id']) {
  82. return $this->alert('用户信息不存在', $state);
  83. }
  84. $info['cash'] = 0;
  85. }
  86. $data['status'] = 2;
  87. $func = 'inc';
  88. if ($type['type'] == 2) {
  89. if ($info['cash'] < $cash) {
  90. return $this->alert('账户余额不足', $state);
  91. }
  92. $func = 'dec';
  93. }
  94. $data['info_id'] = $info['id'];
  95. $data['ycash'] = $cash;
  96. $data['cash'] = $cash;
  97. if ($type['key'] == 'tixian') {
  98. if ($config['is_withdraw'] == 2) {
  99. return $this->alert('当前账户不能提现', $state);
  100. }
  101. if ($config['withdraw_down'] > 0 && $cash < $config['withdraw_down']) {
  102. return $this->alert('提现金额不能少于' . $config['withdraw_down'], $state);
  103. }
  104. if ($config['withdraw_up'] > 0 && $cash > $config['withdraw_up']) {
  105. return $this->alert('提现金额不能大于' . $config['withdraw_up'], $state);
  106. }
  107. if ($cash > $info['cash']) {
  108. return $this->alert('提现金额不能大于账户余额', $state);
  109. }
  110. if ($config['withdraw_check']) {
  111. $msg = Dever::load($config['withdraw_check'], $uid, $cash);
  112. if ($msg != 'ok') {
  113. return $this->alert($msg, $state);
  114. }
  115. }
  116. if ($config['withdraw_audit'] == 1) {
  117. $data['status'] = 1;
  118. }
  119. if ($config['withdraw_fee']) {
  120. $fee = Dever::per($cash, $config['withdraw_fee']);
  121. $data['cash'] -= $fee;
  122. }
  123. }
  124. $data['type_id'] = $type['id'];
  125. if ($source) {
  126. $data['source'] = $source;
  127. }
  128. if ($source_id) {
  129. $data['source_id'] = $source_id;
  130. }
  131. if ($desc) {
  132. $data['desc'] = $desc;
  133. }
  134. if ($info) {
  135. $data['yue'] = $info['cash'] + $data['cash'];
  136. if ($type['type'] == 2 && $config['balance_alert'] && $data['yue'] <= $config['balance_alert']) {
  137. return $this->alert('账户余额不足', $state);
  138. }
  139. } else {
  140. $data['yue'] = 0;
  141. }
  142. $yue = $data['yue'];
  143. $data['method'] = $method;
  144. $id = Dever::load('account/lib/log')->create($data);
  145. if ($id) {
  146. $update = array();
  147. $update['where_id'] = $info['id'];
  148. $update['set_cash'] = $data['cash'];
  149. $update['set_col'] = $data['cash'];
  150. $update['clear'] = true;
  151. Dever::db('account/info')->$func($update);
  152. }
  153. return $yue;
  154. }
  155. private function alert($msg, $state = true)
  156. {
  157. if ($state) {
  158. return Dever::alert($msg);
  159. }
  160. return -1;
  161. }
  162. }