/** * 获得一组商品和企业的信息 * @param array $data 要查询的商品 结构是 array('pid'=>'cid','pid'=>'cid') * @param string $column 要显示的字段 默认为全部 */ public function getComGoodsbyid($data, $column = '*') { $data = $this->di['filter']->sanitize($data, 'string', ''); $column = $this->di['filter']->sanitize($column, 'string', ''); if (empty($data) or !is_array($data) or empty($column)) { return $this->outputData(false, 600, '商品信息获取失败'); } $goods = $special = $cidArr = ''; foreach ($data as $k => $v) { if ($k >= 900000000) { $special[] = $k; } else { $goods[] = $k; $cidArr[] = $v; } } $rs1 = $rs2 = array(); if (is_array($special)) { $special = implode(',', $special); $rs1 = Pdspecialpro::find(array('pid in (' . $special . ') and state in (1,-2,-3)', "bind" => array(), 'columns' => $column))->toArray(); } if (is_array($goods) and is_array($cidArr)) { $goods = implode(',', $goods); $cid = implode(',', $cidArr); $rs2 = Pdinfo::find(array('cid in (' . $cid . ') and pid in (' . $goods . ') and state in(0,1,-1,-2)', "bind" => array(), 'columns' => $column))->toArray(); } $rs1 = array_merge($rs1, $rs2); if (is_array($rs1)) { $supidArr = array(); foreach ($rs1 as $v) { $supidArr[] = $v['supid']; } $comlist = array(); if (is_array($supidArr) and !empty($supidArr)) { $com = ComService::getInstance()->getListBySups($supidArr); if ($com['code'] && !empty($com['data']) && is_array($com['data'])) { foreach ($com['data'] as $v2) { $comlist[$v2['supid']] = $v2; } } } foreach ($rs1 as $k1 => $v1) { if (isset($comlist[$v1['supid']])) { $rs1[$k1]['comname'] = $comlist[$v1['supid']]['comname']; } } return $this->outputData($rs1); } else { return $this->outputData(false, 600, '商品信息获取失败'); } }
/** * 商品搜索 * @param array $where 条件 * @param string $column 要显示的字段 * @param string $wd 要搜索的关键词 * @param integer $offset 分页 * @param integer $limit 分页 * @param integer $type 1是主表 2是审核表 * @param string $order 排序 * @param integer $is_op 默认为不是op 0不是op 1是op 主要用来调取不同的企业接口 */ public function search($where = array(), $column = "pid,cid,supid,proname,pricetype,minprice,maxprice,siteprice,addtime,uptime,star,cate2,cate3,unit,picurl,is_op", $wd = '', $offset = 0, $limit = 20, $type = 1, $order = 'uptime DESC', $is_op = 0, $islike = 0) { $condition = '1'; $bind = array(); $wd = trim($wd); $offset = $this->di['filter']->sanitize($offset, 'int', 0); $limit = $this->di['filter']->sanitize($limit, 'int', 20); if (!isset($where['supid'])) { $condition .= ' and supid > 0'; } if (is_array($where)) { foreach ($where as $key => $value) { if (is_array($value)) { $value = $this->di['filter']->sanitize($value, "string", ''); $condition .= ' and ' . $key . ' in(' . implode(',', $value) . ')'; } else { $value = $this->di['filter']->sanitize($value, "string", 0); $condition .= ' and ' . $key . '=:' . $key . ':'; $bind[$key] = $value; } } } if (!isset($where['state'])) { if ($type == 1) { $condition .= ' and state in(1,-2,-3)'; } else { $condition .= ' and state in(0,-1)'; } } if (!empty($wd)) { $wd = $this->di['filter']->sanitize($wd, "string", ''); $condition .= ' and proname like "%' . $wd . '%"'; } if ($type == 1) { $goods = Pdspecialpro::find(array($condition, "bind" => $bind, 'columns' => $column, 'order' => $order, 'offset' => $offset, 'limit' => $limit))->toArray(); $count = Pdspecialpro::count(array($condition, "bind" => $bind)); } elseif ($type == 2) { $goods = Mspecialpro::find(array($condition, 'bind' => $bind, 'columns' => $column, 'order' => $order, 'offset' => $offset, 'limit' => $limit))->toArray(); $count = Mspecialpro::count(array($condition, "bind" => $bind)); } if (!empty($goods) && is_array($goods)) { foreach ($goods as $v) { $supidArr[] = $v['supid']; } $comlist = array(); if (isset($supidArr) && is_array($supidArr) && !empty($supidArr)) { if ($is_op == 1) { //这个只能运营商才能用的企业接口, 查的是供应商和运营商关系表, $com = OpSupService::getInstance()->getBysupid($supidArr); } else { //这个接口才是查的company表 $com = ComService::getInstance()->getListBySups($supidArr); } if ($com['code'] && !empty($com['data']) && is_array($com['data'])) { foreach ($com['data'] as $v2) { $comlist[$v2['supid']] = $v2; } } foreach ($goods as $k1 => $v1) { if (isset($comlist[$v1['supid']])) { $goods[$k1]['comname'] = $comlist[$v1['supid']]['comname']; if ($is_op == 1) { $goods[$k1]['opuserid'] = $comlist[$v1['supid']]['opuserid']; $goods[$k1]['opuser'] = $comlist[$v1['supid']]['opuser']; } } } } if ($islike == 1) { foreach ($goods as $k2 => $v2) { if (isset($v2['pid']) && isset($v2['cate2']) && isset($v2['cate3'])) { $url = \Xz\Func\UrlHelper::proLinkCre($v2['pid'], $v2['cate2'], $v2['cate3']); } if (!empty($url)) { $goods[$k2]['link'] = $url; } } } $goods['count'] = $count; return $this->outputData($goods); } else { $goods['count'] = 0; return $this->outputData($goods); } }