getInfo($uid, $config_id); return array('name' => $info['config']['name'], 'cash' => $info['cash'], 'info_id' => $info['id']); } # 获取账户信息 public function getInfo($uid, $config_id = false, $check = 0) { $key = Dever::input('account_key'); if ($key) { $config = Dever::db('account/config')->one(array('key' => $key)); } else { if (!$config_id) { $config = Dever::db('account/config')->one(array('type' => 1)); } else { $config = Dever::db('account/config')->one($config_id); } } if ($config) { # 检测是否可以充值 if ($check == 1 && $config['is_pay'] == 2) { Dever::alert('当前账户不允许充值'); } # 检测是否可以提现 if ($check == 2 && $config['is_withdraw'] == 2) { Dever::alert('当前账户不允许提现'); } $where = array(); $where['uid'] = $uid; $where['config_id'] = $config['id']; $account = Dever::db('account/info')->one($where); if (!$account) { $id = Dever::db('account/info')->insert($where); $account = Dever::db('account/info')->one($id); } $account['config'] = $config; return $account; } else { Dever::alert('钱包配置不存在'); } } # 入账 public function up_commit($uid, $cash, $type, $config, $desc = '', $source = '', $source_id = '', $method = 1, $state = true, $result = false) { if ($cash == 0) { return $this->alert('金额不能为0', $state); } if (!is_array($config)) { $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); } if (!is_array($type)) { $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; } $data['status'] = 2; $scash = $cash; $func = 'inc'; if ($type['type'] == 2) { if ($info['cash'] < $cash) { return $this->alert('账户余额不足', $state); } $func = 'dec'; $scash = $scash*-1; } $data['info_id'] = $info['id']; $data['ycash'] = $cash; $data['cash'] = $cash; 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); } if ($config['withdraw_check']) { $msg = Dever::load($config['withdraw_check'], $uid, $cash); if ($msg != 'ok') { return $this->alert($msg, $state); } } if ($config['withdraw_audit'] == 1) { $data['status'] = 1; } if ($config['withdraw_fee']) { $fee = Dever::per($cash, $config['withdraw_fee']); $data['cash'] -= $fee; } } $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) { if ($type['key'] == 'tixian') { $data['yue'] = $info['cash'] - $data['ycash']; } else { $data['yue'] = $info['cash'] + $scash; } 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; $id = Dever::load('account/lib/log')->create($data); if ($id) { $update = array(); $update['where_id'] = $info['id']; $update['set_cash'] = $scash; $update['set_col'] = $data['ycash']; $update['clear'] = true; Dever::db('account/info')->$func($update); } if ($result) { $data['id'] = $id; return $data; } return $yue; } private function alert($msg, $state = true) { if ($state) { return Dever::alert($msg); } return -1; } }