Info.php 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239
  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', $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['status'] = 2;
  113. $data['uid'] = $uid;
  114. $data['config_id'] = $config['id'];
  115. $data['project_id'] = $config['project_id'];
  116. $data['clear'] = true;
  117. $info = Dever::db('account/info')->find($data);
  118. if (!$info) {
  119. $info['id'] = Dever::db('account/info')->insert($data);
  120. if (!$info['id']) {
  121. return $this->alert('用户信息不存在', $state);
  122. }
  123. $info['cash'] = 0;
  124. }
  125. $func = 'inc';
  126. if ($type['type'] == 2) {
  127. if ($info['cash'] < $cash) {
  128. return $this->alert('账户余额不足', $state);
  129. }
  130. $cash = -1*$cash;
  131. $func = 'dec';
  132. }
  133. $data['info_id'] = $info['id'];
  134. $data['ycash'] = $cash;
  135. $data['cash'] = $cash;
  136. if ($type['key'] == 'tixian') {
  137. if ($config['is_withdraw'] == 2) {
  138. return $this->alert('当前账户不能提现', $state);
  139. }
  140. if ($config['withdraw_down'] > 0 && $cash < $config['withdraw_down']) {
  141. return $this->alert('提现金额不能少于' . $config['withdraw_down'], $state);
  142. }
  143. if ($config['withdraw_up'] > 0 && $cash > $config['withdraw_up']) {
  144. return $this->alert('提现金额不能大于' . $config['withdraw_up'], $state);
  145. }
  146. if ($cash > $info['cash']) {
  147. return $this->alert('提现金额不能大于账户余额', $state);
  148. }
  149. if ($config['withdraw_check']) {
  150. $msg = Dever::load($config['withdraw_check'], $uid, $cash);
  151. if ($msg != 'ok') {
  152. return $this->alert($msg, $state);
  153. }
  154. }
  155. if ($config['withdraw_audit'] == 1) {
  156. $data['status'] = 1;
  157. }
  158. if ($config['withdraw_fee']) {
  159. $fee = Dever::per($cash, $config['withdraw_fee']);
  160. $data['cash'] -= $fee;
  161. }
  162. }
  163. $data['type_id'] = $type['id'];
  164. if ($source) {
  165. $data['source'] = $source;
  166. }
  167. if ($source_id) {
  168. $data['source_id'] = $source_id;
  169. }
  170. if ($desc) {
  171. $data['desc'] = $desc;
  172. }
  173. if ($info) {
  174. $data['yue'] = $info['cash'] + $data['cash'];
  175. if ($type['type'] == 2 && $config['balance_alert'] && $data['yue'] <= $config['balance_alert']) {
  176. return $this->alert('账户余额不足', $state);
  177. }
  178. } else {
  179. $data['yue'] = 0;
  180. }
  181. $yue = $data['yue'];
  182. $data['method'] = $method;
  183. if ($data['status'] == 2) {
  184. $admin = Dever::load('manage/auth.data');
  185. if ($admin) {
  186. $data['audit_admin'] = $admin['id'];
  187. }
  188. $data['audit_date'] = time();
  189. }
  190. $data['clear'] = true;
  191. $id = Dever::db('account/info_log')->insert($data);
  192. if ($id) {
  193. $update = array();
  194. $update['where_id'] = $info['id'];
  195. $update['set_cash'] = $data['cash'];
  196. $update['set_col'] = $data['cash'];
  197. $update['clear'] = true;
  198. Dever::db('account/info')->$func($update);
  199. }
  200. return $yue;
  201. }
  202. private function alert($msg, $state = true)
  203. {
  204. if ($state) {
  205. return Dever::alert($msg);
  206. }
  207. return -1;
  208. }
  209. }