Info.php 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219
  1. <?php
  2. namespace Account\Lib;
  3. use Dever;
  4. class Info
  5. {
  6. # 获取账户
  7. public function getInfo($uid, $config_id = false)
  8. {
  9. if (!$config_id) {
  10. $config = Dever::db('account/config')->one(array('type' => 1));
  11. } else {
  12. $config = Dever::db('account/config')->one($config_id);
  13. }
  14. if ($config) {
  15. $where = array();
  16. $where['uid'] = $uid;
  17. $where['config_id'] = $config['id'];
  18. $account = Dever::db('account/info')->one($where);
  19. if ($account) {
  20. return array('name' => $config['name'], 'cash' => $account['cash'], 'z_cash' => $account['z_cash'], 't_cash' => $account['t_cash']);
  21. } else {
  22. return array();
  23. }
  24. }
  25. return array();
  26. }
  27. # 获取列表
  28. public function getList($uid, $config_id = false, $type = false, $type_id = false)
  29. {
  30. if (!$config_id) {
  31. $config = Dever::db('account/config')->one(array('type' => 1));
  32. } else {
  33. $config = Dever::db('account/config')->one($config_id);
  34. }
  35. if ($config) {
  36. $where = array();
  37. $where['uid'] = $uid;
  38. $where['config_id'] = $config['id'];
  39. $result = Dever::db('account/info_log')->getList($where);
  40. }
  41. if ($result) {
  42. $type = Dever::db('account/config_type')->getData();
  43. foreach ($result as $k => $v) {
  44. $result[$k]['cdate'] = date('Y-m-d H:i:s', $v['cdate']);
  45. if (isset($type[$v['type_id']])) {
  46. $result[$k]['type_name'] = $type[$v['type_id']]['name'];
  47. } else {
  48. $result[$k]['type_name'] = '未知';
  49. }
  50. }
  51. }
  52. return $result;
  53. }
  54. public function test_api()
  55. {
  56. //return $this->up(1, 500, 'tixian', 'role_zijin', 'test');
  57. return $this->up_commit(1, 1, 'chongzhi', 'role_zijin', 'test');
  58. }
  59. public function getName($uid, $config_id)
  60. {
  61. $name = $uid;
  62. $info = Dever::db('account/config')->find($config_id);
  63. if ($info) {
  64. $project = Dever::db('account/config_project')->find($info['project_id']);
  65. $source = Dever::db($project['source'])->find($uid);
  66. if ($source) {
  67. return $source[$project['source_name']];
  68. }
  69. }
  70. return $name;
  71. }
  72. public function getSearch($config_id)
  73. {
  74. $result = '';
  75. $info = Dever::db('account/config')->find($config_id);
  76. if ($info) {
  77. $project = Dever::db('account/config_project')->find($info['project_id']);
  78. $result = array
  79. (
  80. 'api' => $project['source'] . '-all',
  81. 'col' => $project['source_name'],
  82. 'result' => 'id',
  83. 'search' => 'uid',
  84. 'project_name' => $project['name'],
  85. 'name' => $info['name'],
  86. );
  87. }
  88. return $result;
  89. }
  90. # 入账
  91. public function up_commit($uid, $cash, $type, $config, $desc = '', $source = '', $source_id = '', $method = 1, $state = true)
  92. {
  93. if ($cash == 0) {
  94. return $this->alert('金额不能为0', $state);
  95. }
  96. $config = Dever::db('account/config')->find(array('key' => $config));
  97. if (!$config) {
  98. return $this->alert('账户信息不存在', $state);
  99. }
  100. $project = Dever::db('account/config_project')->find($config['project_id']);
  101. $user = Dever::db($project['source'])->find($uid);
  102. if (!$user) {
  103. return $this->alert('用户信息不存在', $state);
  104. }
  105. $type = Dever::db('account/config_type')->find(array('key' => $type));
  106. if (!$type) {
  107. return $this->alert('交易类型不存在', $state);
  108. }
  109. if ($type['project_id'] != -1 && $type['project_id'] != $config['project_id']) {
  110. return $this->alert('交易类型不正确', $state);
  111. }
  112. $data['uid'] = $uid;
  113. $data['config_id'] = $config['id'];
  114. $data['project_id'] = $config['project_id'];
  115. $data['clear'] = true;
  116. $info = Dever::db('account/info')->find($data);
  117. if (!$info) {
  118. $info['id'] = Dever::db('account/info')->insert($data);
  119. if (!$info['id']) {
  120. return $this->alert('用户信息不存在', $state);
  121. }
  122. $info['cash'] = 0;
  123. }
  124. if ($type['key'] == 'tixian') {
  125. if ($config['is_withdraw'] == 2) {
  126. return $this->alert('当前账户不能提现', $state);
  127. }
  128. if ($config['withdraw_down'] > 0 && $cash < $config['withdraw_down']) {
  129. return $this->alert('提现金额不能少于' . $config['withdraw_down'], $state);
  130. }
  131. if ($config['withdraw_up'] > 0 && $cash > $config['withdraw_up']) {
  132. return $this->alert('提现金额不能大于' . $config['withdraw_up'], $state);
  133. }
  134. if ($cash > $info['cash']) {
  135. return $this->alert('提现金额不能大于账户余额', $state);
  136. }
  137. }
  138. $func = 'inc';
  139. if ($type['type'] == 2) {
  140. if ($info['cash'] < $cash) {
  141. return $this->alert('账户余额不足', $state);
  142. }
  143. $cash = -1*$cash;
  144. $func = 'dec';
  145. }
  146. $data['info_id'] = $info['id'];
  147. $data['cash'] = $cash;
  148. $data['type_id'] = $type['id'];
  149. if ($source) {
  150. $data['source'] = $source;
  151. }
  152. if ($source_id) {
  153. $data['source_id'] = $source_id;
  154. }
  155. if ($desc) {
  156. $data['desc'] = $desc;
  157. }
  158. if ($info) {
  159. $data['yue'] = $info['cash'] + $data['cash'];
  160. if ($type['type'] == 2 && $config['balance_alert'] && $data['yue'] <= $config['balance_alert']) {
  161. return $this->alert('账户余额不足', $state);
  162. }
  163. } else {
  164. $data['yue'] = 0;
  165. }
  166. $yue = $data['yue'];
  167. $data['method'] = $method;
  168. $admin = Dever::load('manage/auth.data');
  169. if ($admin) {
  170. $data['admin_id'] = $admin['id'];
  171. }
  172. $data['clear'] = true;
  173. $id = Dever::db('account/info_log')->insert($data);
  174. if ($id) {
  175. $update = array();
  176. $update['where_id'] = $info['id'];
  177. $update['set_cash'] = $data['cash'];
  178. $update['set_col'] = $data['cash'];
  179. $update['clear'] = true;
  180. Dever::db('account/info')->$func($update);
  181. }
  182. return $yue;
  183. }
  184. private function alert($msg, $state = true)
  185. {
  186. if ($state) {
  187. return Dever::alert($msg);
  188. }
  189. return -1;
  190. }
  191. }