PHP程序里面
大佬們幫忙看看怎么判斷用戶已經(jīng)購買商品???
代碼是參考積分購物這個插件,把buy.php直接挪到內(nèi)容模塊下面。
然后在內(nèi)容模塊新建price作為支付字段,復制了一份積分購物的購買記錄表重命名作為記錄商品購買的記錄表
現(xiàn)在想要在內(nèi)容模塊的內(nèi)容頁面獲取用戶是否支付然后返回不同的內(nèi)容,大佬幫忙看看該如何寫下判斷?
{if ?????????????????????????????}
購買展示的內(nèi)容
{else}
<a href="{dr_url(MOD_DIR.'/buy/index')}&id={$id}">請購買后再查看</a>
{/if}
數(shù)據(jù)表

buy.php代碼
<?php namespace Phpcmf\Controllers;
class Buy extends \Phpcmf\Common {
public function index() {
$this->_module_init(APP_DIR);
$id = (int)\Phpcmf\Service::L('Input')->get('id');
(!$id) && exit($this->_msg(0, dr_lang('商品ID不能為空')));
!$this->uid && exit($this->_msg(0, '你還沒有登錄'));
$data = $this->content_model->get_row( $id);
!$data && $this->_msg(0, dr_lang('內(nèi)容【id#%s】不存在', $id));
!isset($data['price']) && $this->_msg(0, dr_lang('此模塊沒有找到price字段'));
$data['price_sku'] = dr_string2array($data['price_sku']);
if ($data['price_sku']) {
$price = [];
foreach ($data['price_sku'] as $gid => $v) {
if (in_array($gid, $this->member['groupid'])) {
$price[] = $v;
}
}
!$price && $this->_msg(0, dr_lang('當前用戶組無權(quán)限購買'));
$score = intval(min($price));
} else {
$score = intval($data['price']);
}
if ($score > 0) {
// 扣積分
if ((float)$this->member['score'] <= 0 ) {
$this->_msg(0, dr_lang('賬戶余額不足'));
} elseif ($this->member['score'] - $score < 0) {
$this->_msg(0, dr_lang('賬戶可用余額不足'));
}
// 扣款
\Phpcmf\Service::M('member')->add_score($this->uid, -$score, '積分購物消費<'.$data['title'].'>');
// 打款到作者
\Phpcmf\Service::M('member')->add_score($data['uid'], $score, '積分購物收入<'.$data['title'].'>');
// 記錄到日志表
\Phpcmf\Service::M()->table(SITE_ID.'_'.APP_DIR.'_score')->insert([
'cid' => $id,
'uid' => $this->uid,
'sellid' => $data['uid'],
'price' => $score,
'inputtime' => SYS_TIME,
]);
$this->_msg(1, dr_lang('支付成功'), dr_url_prefix($data['url'], APP_DIR, SITE_ID));
} else {
$this->_msg(0, dr_lang('當前商品為免費商品,不需要購買'));
}
}
}
你的代碼是入庫了一張表,判斷這張表是否有記錄就可以實現(xiàn)吧?、
{if $member.uid && \Phpcmf\Service::M()->table(SITE_ID.'_'.APP_DIR.'_score')->where('uid', $member.uid)->where('cid', $id)->counts()}試試這個代碼
回復@疾風 非常好的代碼 你真的是太帥了!