易物php,system/common/model/goods.php · Dragon/易物 - Gitee.com

这是一个PHP类,用于实现商品选项获取和商品列表的查询。类包含两个主要方法:getOption用于获取指定商品ID和选项ID的商品选项,getList则用于根据各种条件(如分页、关键词、分类、促销状态等)获取商品列表。商品列表查询考虑了会员等级和用户组的显示限制,并对结果进行了媒体处理。
摘要由CSDN通过智能技术生成

if (!defined('IN_IA')) {

exit('Access Denied');

}

if (!class_exists('GoodsModel')) {

class GoodsModel

{

public function getOption($goodsid = 0, $optionid = 0)

{

global $_W;

return pdo_fetch('select * from ' . tablename('eshop_goods_option') . ' where id=:id and goodsid=:goodsid and uniacid=:uniacid', array(

':id' => $optionid,

':uniacid' => $_W['uniacid'],

':goodsid' => $goodsid

));

}

public function getList($args = array())

{

global $_W;

$page = !empty($args['page']) ? intval($args['page']) : 1;

$pagesize = !empty($args['pagesize']) ? intval($args['pagesize']) : 10;

$random = !empty($args['random']) ? $args['random'] : false;

$order = !empty($args['order']) ? $args['order'] : ' displayorder desc,createtime desc';

$orderby = !empty($args['by']) ? $args['by'] : '';

$ids = !empty($args['ids']) ? trim($args['ids']) : '';

$condition = ' and `uniacid` = :uniacid AND `deleted` = 0 and status=1';

$params = array(

':uniacid' => $_W['uniacid']

);

if (!empty($ids)) {

$condition .= " and id in ( " . $ids . ")";

}

$isnew = !empty($args['isnew']) ? 1 : 0;

if (!empty($isnew)) {

$condition .= " and isnew=1";

}

$ishot = !empty($args['ishot']) ? 1 : 0;

if (!empty($ishot)) {

$condition .= " and ishot=1";

}

$isrecommand = !empty($args['isrecommand']) ? 1 : 0;

if (!empty($isrecommand)) {

$condition .= " and isrecommand=1";

}

$isdiscount = !empty($args['isdiscount']) ? 1 : 0;

if (!empty($isdiscount)) {

$condition .= " and isdiscount=1";

}

$istime = !empty($args['istime']) ? 1 : 0;

if (!empty($istime)) {

$condition .= " and istime=1 and " . time() . ">=timestart and " . time() . "<=timeend";

}

if (isset($args['nocommission'])) {

$condition .= ' AND `nocommission`=' . intval($args['nocommission']);

}

$keywords = !empty($args['keywords']) ? $args['keywords'] : '';

if (!empty($keywords)) {

$condition .= ' AND `title` LIKE :title';

$params[':title'] = '%' . trim($keywords) . '%';

}

$tcate = intval($args['tcate']);

if (!empty($tcate)) {

$condition .= " AND ( `tcate` = :tcate or FIND_IN_SET({$tcate},tcates)<>0 )";

$params[':tcate'] = intval($tcate);

} else {

$ccate = intval($args['ccate']);

if (!empty($ccate)) {

$condition .= " AND ( `ccate` = :ccate or FIND_IN_SET({$ccate},ccates)<>0 )";

$params[':ccate'] = intval($ccate);

} else {

$pcate = intval($args['pcate']);

if (!empty($pcate)) {

$condition .= " AND ( `pcate` = :pcate or FIND_IN_SET({$pcate},pcates)<>0 )";

$params[':pcate'] = intval($pcate);

}

}

}

if(is_login_account())

{

$openid = m('user')->getOpenid(true);

$member = m('member')->getMember($openid);

$levelid = intval($member['level']);

$groupid = intval($member['groupid']);

$condition .= " and ( ifnull(showlevels,'')='' or FIND_IN_SET( {$levelid},showlevels)<>0 ) ";

$condition .= " and ( ifnull(showgroups,'')='' or FIND_IN_SET( {$groupid},showgroups)<>0 ) ";

}

if (!$random) {

$sql = "SELECT id,title,thumb,marketprice,productprice,sales,total,description FROM " . tablename('eshop_goods') . " where 1 {$condition} ORDER BY {$order} {$orderby} LIMIT " . ($page - 1) * $pagesize . ',' . $pagesize;

} else {

$sql = "SELECT id,title,thumb,marketprice,productprice,sales,total,description FROM " . tablename('eshop_goods') . " where 1 {$condition} ORDER BY rand() LIMIT " . $pagesize;

}

$list = pdo_fetchall($sql, $params);

$list = set_medias($list, 'thumb');

return $list;

}

public function getComments($goodsid = '0', $args = array())

{

global $_W;

$page = !empty($args['page']) ? intval($args['page']) : 1;

$pagesize = !empty($args['pagesize']) ? intval($args['pagesize']) : 10;

$condition = ' and `uniacid` = :uniacid AND `goodsid` = :goodsid and deleted=0';

$params = array(

':uniacid' => $_W['uniacid'],

':goodsid' => $goodsid

);

$sql = "SELECT id,nickname,headimgurl,content,images FROM " . tablename('eshop_goods_comment') . " where 1 {$condition} ORDER BY createtime desc LIMIT " . ($page - 1) * $pagesize . ',' . $pagesize;

$list = pdo_fetchall($sql, $params);

foreach ($list as &$row) {

$row['images'] = set_medias(unserialize($row['images']));

}

unset($row);

return $list;

}

}

}

一键复制

编辑

Web IDE

原始数据

按行查看

历史

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值