123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219 |
- <?php
- namespace Account\Lib;
- use Dever;
- class Info
- {
- # 获取账户
- public function getInfo($uid, $config_id = false)
- {
- if (!$config_id) {
- $config = Dever::db('account/config')->one(array('type' => 1));
- } else {
- $config = Dever::db('account/config')->one($config_id);
- }
-
- if ($config) {
- $where = array();
- $where['uid'] = $uid;
- $where['config_id'] = $config['id'];
- $account = Dever::db('account/info')->one($where);
- if ($account) {
- return array('name' => $config['name'], 'cash' => $account['cash'], 'z_cash' => $account['z_cash'], 't_cash' => $account['t_cash']);
- } else {
- return array();
- }
- }
- return array();
- }
- # 获取列表
- public function getList($uid, $config_id = false, $type = false, $type_id = false)
- {
- if (!$config_id) {
- $config = Dever::db('account/config')->one(array('type' => 1));
- } else {
- $config = Dever::db('account/config')->one($config_id);
- }
-
- if ($config) {
- $where = array();
- $where['uid'] = $uid;
- $where['config_id'] = $config['id'];
- $result = Dever::db('account/info_log')->getList($where);
- }
- if ($result) {
- $type = Dever::db('account/config_type')->getData();
- foreach ($result as $k => $v) {
- $result[$k]['cdate'] = date('Y-m-d H:i:s', $v['cdate']);
- if (isset($type[$v['type_id']])) {
- $result[$k]['type_name'] = $type[$v['type_id']]['name'];
- } else {
- $result[$k]['type_name'] = '未知';
- }
- }
- }
-
- return $result;
- }
- public function test_api()
- {
- //return $this->up(1, 500, 'tixian', 'role_zijin', 'test');
- return $this->up_commit(1, 1, 'chongzhi', 'role_zijin', 'test');
- }
- public function getName($uid, $config_id)
- {
- $name = $uid;
- $info = Dever::db('account/config')->find($config_id);
- if ($info) {
- $project = Dever::db('account/config_project')->find($info['project_id']);
- $source = Dever::db($project['source'])->find($uid);
- if ($source) {
- return $source[$project['source_name']];
- }
- }
- return $name;
- }
- public function getSearch($config_id)
- {
- $result = '';
- $info = Dever::db('account/config')->find($config_id);
- if ($info) {
- $project = Dever::db('account/config_project')->find($info['project_id']);
- $result = array
- (
- 'api' => $project['source'] . '-all',
- 'col' => $project['source_name'],
- 'result' => 'id',
- 'search' => 'uid',
- 'project_name' => $project['name'],
- 'name' => $info['name'],
- );
- }
-
- return $result;
- }
- # 入账
- public function up_commit($uid, $cash, $type, $config, $desc = '', $source = '', $source_id = '', $method = 1, $state = true)
- {
- if ($cash == 0) {
- return $this->alert('金额不能为0', $state);
- }
-
- $config = Dever::db('account/config')->find(array('key' => $config));
- if (!$config) {
- return $this->alert('账户信息不存在', $state);
- }
- $project = Dever::db('account/config_project')->find($config['project_id']);
- $user = Dever::db($project['source'])->find($uid);
- if (!$user) {
- return $this->alert('用户信息不存在', $state);
- }
- $type = Dever::db('account/config_type')->find(array('key' => $type));
- if (!$type) {
- return $this->alert('交易类型不存在', $state);
- }
- if ($type['project_id'] != -1 && $type['project_id'] != $config['project_id']) {
- return $this->alert('交易类型不正确', $state);
- }
- $data['uid'] = $uid;
- $data['config_id'] = $config['id'];
- $data['project_id'] = $config['project_id'];
- $data['clear'] = true;
- $info = Dever::db('account/info')->find($data);
- if (!$info) {
- $info['id'] = Dever::db('account/info')->insert($data);
- if (!$info['id']) {
- return $this->alert('用户信息不存在', $state);
- }
- $info['cash'] = 0;
- }
- if ($type['key'] == 'tixian') {
- if ($config['is_withdraw'] == 2) {
- return $this->alert('当前账户不能提现', $state);
- }
- if ($config['withdraw_down'] > 0 && $cash < $config['withdraw_down']) {
- return $this->alert('提现金额不能少于' . $config['withdraw_down'], $state);
- }
- if ($config['withdraw_up'] > 0 && $cash > $config['withdraw_up']) {
- return $this->alert('提现金额不能大于' . $config['withdraw_up'], $state);
- }
- if ($cash > $info['cash']) {
- return $this->alert('提现金额不能大于账户余额', $state);
- }
- }
- $func = 'inc';
- if ($type['type'] == 2) {
- if ($info['cash'] < $cash) {
- return $this->alert('账户余额不足', $state);
- }
- $cash = -1*$cash;
- $func = 'dec';
- }
- $data['info_id'] = $info['id'];
- $data['cash'] = $cash;
- $data['type_id'] = $type['id'];
- if ($source) {
- $data['source'] = $source;
- }
- if ($source_id) {
- $data['source_id'] = $source_id;
- }
- if ($desc) {
- $data['desc'] = $desc;
- }
- if ($info) {
- $data['yue'] = $info['cash'] + $data['cash'];
- if ($type['type'] == 2 && $config['balance_alert'] && $data['yue'] <= $config['balance_alert']) {
- return $this->alert('账户余额不足', $state);
- }
- } else {
- $data['yue'] = 0;
- }
- $yue = $data['yue'];
- $data['method'] = $method;
- $admin = Dever::load('manage/auth.data');
- if ($admin) {
- $data['admin_id'] = $admin['id'];
- }
-
- $data['clear'] = true;
- $id = Dever::db('account/info_log')->insert($data);
- if ($id) {
- $update = array();
- $update['where_id'] = $info['id'];
- $update['set_cash'] = $data['cash'];
- $update['set_col'] = $data['cash'];
- $update['clear'] = true;
- Dever::db('account/info')->$func($update);
- }
- return $yue;
- }
- private function alert($msg, $state = true)
- {
- if ($state) {
- return Dever::alert($msg);
- }
- return -1;
- }
- }
|