123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160 |
- <?php
- namespace Account\Lib;
- use Dever;
- class Info
- {
- 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) {
- $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'];
- } else {
- $data['yue'] = 0;
- }
- if ($data['yue'] < 0) {
- $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;
- }
- }
|