<?php namespace Phpcmf\Model\Tixian;
class Tixian extends \Phpcmf\Model
{
public function cash_price($member) {
if (!$member) {
return 0;
}
$price = [];
$config = \Phpcmf\Service::M('app')->get_config('tixian');
if ($config['group_price'] && is_array($config['group_price'])) {
foreach ($config['group_price'] as $gid => $value) {
if (in_array($gid, $member['groupid'])) {
$price[] = $value;
}
}
if ($price) {
return intval(min($price));
}
}
return 0;
}
public function min_price() {
$config = \Phpcmf\Service::M('app')->get_config('tixian');
return $config['min'];
}
public function add_cash($post) {
if (!$this->uid || !$post) {
return dr_return_data(0, dr_lang('参数错误'));
} elseif (strlen($post['value']) > 8) {
return dr_return_data(0, dr_lang('金额不规范'));
}
$price = $this->cash_price($this->member);
$rt = $this->table('member_cashlog')->insert([
'uid' => $this->uid,
'username' => $this->member['username'],
'content' => dr_safe_replace($post['content']),
'value' => $post['value'],
'money' => $price ? $post['value'] - $post['value'] * ($price/100) : $post['value'],
'status' => 0,
'result' => '',
'paytime' => 0,
'inputtime' => SYS_TIME,
]);
if (!$rt['code']) {
return $rt;
}
$rt2 = \Phpcmf\Service::M('member')->add_freeze($this->uid, $post['value']);
if (!$rt2['code']) {
$this->table('member_cashlog')->delete($rt['code']);
}
return $rt;
}
public function cash_fail($id, $post, $old) {
$this->table('member_cashlog')->update($id, [
'result' => $post['result'],
'status' => 1, ]);
return \Phpcmf\Service::M('member')->cancel_freeze($old['uid'], $old['value']);
}
public function cash_successs($id, $post, $old) {
$rt = \Phpcmf\Service::M('member')->use_freeze($old['uid'], $old['value']);
if (!$rt['code']) {
return $rt;
}
$this->table('member_cashlog')->update($id, [
'result' => $post['result'],
'status' => 2, 'paytime' => SYS_TIME,
]);
return \Phpcmf\Service::M('pay')->add_paylog([
'uid' => $old['uid'],
'username' => $old['username'],
'touid' => $old['uid'],
'tousername' => $old['username'],
'mid' => 'cash',
'title' => dr_lang('现金提现'),
'value' => -$old['value'],
'type' => 'finecms',
'status' => 1,
'url' => '',
'result' => $post['result'],
'paytime' => SYS_TIME,
'inputtime' => SYS_TIME,
]);
}
}