Info.php 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174
  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. $config = Dever::db('account/config')->find(array('key' => $config));
  55. if (!$config) {
  56. return $this->alert('账户信息不存在', $state);
  57. }
  58. $project = Dever::db('account/config_project')->find($config['project_id']);
  59. $user = Dever::db($project['source'])->find($uid);
  60. if (!$user) {
  61. return $this->alert('用户信息不存在', $state);
  62. }
  63. $type = Dever::db('account/config_type')->find(array('key' => $type));
  64. if (!$type) {
  65. return $this->alert('交易类型不存在', $state);
  66. }
  67. if ($type['project_id'] != -1 && $type['project_id'] != $config['project_id']) {
  68. return $this->alert('交易类型不正确', $state);
  69. }
  70. $data['uid'] = $uid;
  71. $data['config_id'] = $config['id'];
  72. $data['project_id'] = $config['project_id'];
  73. $data['clear'] = true;
  74. $info = Dever::db('account/info')->find($data);
  75. if (!$info) {
  76. $info['id'] = Dever::db('account/info')->insert($data);
  77. if (!$info['id']) {
  78. return $this->alert('用户信息不存在', $state);
  79. }
  80. $info['cash'] = 0;
  81. }
  82. $data['status'] = 2;
  83. $func = 'inc';
  84. if ($type['type'] == 2) {
  85. if ($info['cash'] < $cash) {
  86. return $this->alert('账户余额不足', $state);
  87. }
  88. $func = 'dec';
  89. }
  90. $data['info_id'] = $info['id'];
  91. $data['ycash'] = $cash;
  92. $data['cash'] = $cash;
  93. if ($type['key'] == 'tixian') {
  94. if ($config['is_withdraw'] == 2) {
  95. return $this->alert('当前账户不能提现', $state);
  96. }
  97. if ($config['withdraw_down'] > 0 && $cash < $config['withdraw_down']) {
  98. return $this->alert('提现金额不能少于' . $config['withdraw_down'], $state);
  99. }
  100. if ($config['withdraw_up'] > 0 && $cash > $config['withdraw_up']) {
  101. return $this->alert('提现金额不能大于' . $config['withdraw_up'], $state);
  102. }
  103. if ($cash > $info['cash']) {
  104. return $this->alert('提现金额不能大于账户余额', $state);
  105. }
  106. if ($config['withdraw_check']) {
  107. $msg = Dever::load($config['withdraw_check'], $uid, $cash);
  108. if ($msg != 'ok') {
  109. return $this->alert($msg, $state);
  110. }
  111. }
  112. if ($config['withdraw_audit'] == 1) {
  113. $data['status'] = 1;
  114. }
  115. if ($config['withdraw_fee']) {
  116. $fee = Dever::per($cash, $config['withdraw_fee']);
  117. $data['cash'] -= $fee;
  118. }
  119. }
  120. $data['type_id'] = $type['id'];
  121. if ($source) {
  122. $data['source'] = $source;
  123. }
  124. if ($source_id) {
  125. $data['source_id'] = $source_id;
  126. }
  127. if ($desc) {
  128. $data['desc'] = $desc;
  129. }
  130. if ($info) {
  131. $data['yue'] = $info['cash'] + $data['cash'];
  132. if ($type['type'] == 2 && $config['balance_alert'] && $data['yue'] <= $config['balance_alert']) {
  133. return $this->alert('账户余额不足', $state);
  134. }
  135. } else {
  136. $data['yue'] = 0;
  137. }
  138. $yue = $data['yue'];
  139. $data['method'] = $method;
  140. $id = Dever::load('account/lib/log')->create($data);
  141. if ($id) {
  142. $update = array();
  143. $update['where_id'] = $info['id'];
  144. $update['set_cash'] = $data['cash'];
  145. $update['set_col'] = $data['cash'];
  146. $update['clear'] = true;
  147. Dever::db('account/info')->$func($update);
  148. }
  149. return $yue;
  150. }
  151. private function alert($msg, $state = true)
  152. {
  153. if ($state) {
  154. return Dever::alert($msg);
  155. }
  156. return -1;
  157. }
  158. }