<?php namespace Phpcmf\Model\Yuedusf;class Buy extends \Phpcmf\Model
{
private $row;
public function get_myfield() {
return [
'fieldtype' => 'Pay', 'fieldname' => 'price',
'setting' => [
'option' => [
'payfile' => 'yuedusf.html', 'is_finecms' => 1, ],
]
];
}
public function paytype() {
return '<span class="label label-danger"> 阅读 </span>'; }
public function pay_before($id, $num, $sku, $siteid) {
$value = $this->get_price($id, $num, $sku, $siteid);
if ($value <= 0) {
return '价格值['.$value.']不规范';
}
return '';
}
public function get_price($id, $num, $sku, $siteid, $gids = []) {
if (!$gids) {
$gids = $this->member['groupid'];
}
$data = $this->_get_row($id, $sku, $siteid);
if ($data['yuedusf_sku']) {
$arr = [];
$value = dr_string2array($data['yuedusf_sku']);
foreach ($value as $gid => $t) {
if (in_array($gid, $gids)) {
$arr[] = $t;
}
}
return min($arr); } else {
return $data['yuedusf'];
}
}
public function get_row($id, $num, $sku, $siteid) {
$data = $this->_get_row($id, $sku, $siteid);
return [
'price' => $this->get_price($id, $num, $sku, $siteid),
'title' => '[阅读收费插件] '.$data['title'],
'sell_uid' => $data['uid'], 'sell_username' => $data['author'], ];
}
public function success($id, $paylog, $num, $sku) {
$data = $this->get_row($id, $num, $sku, $paylog['site']);
\Phpcmf\Service::M('Pay')->add_money($data['sell_uid'], $data['price']);
\Phpcmf\Service::M('Pay')->add_paylog([
'uid' => $data['sell_uid'],
'username' => $data['sell_username'],
'touid' => $paylog['uid'],
'tousername' => $paylog['username'],
'mid' => $paylog['mid'],
'title' => '[收入]'.$paylog['title'],
'value' => $data['price'],
'type' => 'system',
'status' => 1,
'result' => '',
'url' => '',
'paytime' => SYS_TIME,
'inputtime' => SYS_TIME,
]);
$this->table($paylog['site'].'_'.$sku.'_yuedusf')->insert([
'cid' => $id,
'buy_uid' => $paylog['uid'],
'sell_uid' => $data['sell_uid'],
'value' => $data['price'],
'inputtime' => SYS_TIME,
]);
}
private function _get_row($id, $sku, $siteid) {
if (isset($this->row[$id]) && $this->row[$id]) {
return $this->row[$id];
}
$this->row[$id] = $this->table($siteid.'_'.dr_safe_filename($sku))->get($id);
return $this->row[$id];
}
public function call_url($id, $paylog) {
list($a, $b, $c, $d, $e) = explode('-', $paylog['mid']);
return dr_url_prefix('index.php?s='.$e.'&c=show&id='.$c); }
public function get_buy_price($mid, $cid, $uid) {
if (!$mid || !$cid) {
return '参数不对';
}
$data = $this->_get_row($cid, $mid, SITE_ID);
if (!$data) {
return '内容不存在';
}
if (!$data['yuedusf_sku']) {
if ($data['yuedusf'] == 0) {
return 0; }
}
$member = dr_member_info($uid);
if (!$member) {
return '未登录';
}
return $this->get_price($cid, 1, $mid, SITE_ID, $member['groupid']);
}
public function is_buy($mid, $cid, $uid) {
if (!$mid || !$cid) {
return 0;
} elseif (!dr_is_module($mid)) {
return 0;
}
$data = $this->_get_row($cid, $mid, SITE_ID);
if (!$data) {
return 0;
}
if (!$data['yuedusf_sku']) {
if ($data['yuedusf'] == 0) {
return 1; }
}
$member = dr_member_info($uid);
if (!$member) {
return 0;
}
$price = $this->get_price($cid, 1, $mid, SITE_ID, $member['groupid']);
if ($price == 0) {
return 1; }
if ($this->table(SITE_ID.'_'.$mid.'_yuedusf')->where('buy_uid', (int)$uid)->where('cid', (int)$cid)->getRow()) {
return 1;
} else {
return 0;
}
}
}