/** * 先处理特权产品 * * @Author tianyunzi * @DateTime 2016-01-05T11:05:59+0800 * @return [type] [description] */ public function speAction($cid) { echo $cid . "\n"; $pid = 0; while (1) { $proMysql = Pdspecialpro::find(array("conditions" => "pid > ?1 and cid = ?2", "bind" => array(1 => $pid, 2 => $cid), "columns" => "pid, proname, state", "limit" => 100, "order" => "pid asc")); $proMysqlRs = $proMysql->toArray(); if (empty($proMysqlRs)) { echo "=================cid=" . $cid . "的企业的所有产品都已经打入队列处理===============\n"; return true; } foreach ($proMysqlRs as $value) { $pid = $value["pid"]; if ($value["state"] != 1) { echo "============" . $pid . "产品状态不正常=============\n"; continue; } $this->writeRabbit($pid, $cid); } } }
/** * 统计产品条数 * @param string $condition 条件 * @param integer $type 选择数据表 默认1为正式表 2为M表 * @param array $bind 条件 * @return int 条数 */ public function productNum($condition, $type = 1, $bind = array()) { if (empty($condition)) { return $this->outputData(0); } if ($type == 1) { $count = \Gcproinfo\Models\Pdinfo::count(array($condition, "bind" => $bind)); } elseif ($type == 2) { $count = \Gcproinfo\Models\Mproduct::count(array($condition, "bind" => $bind)); } elseif ($type == 3) { $count = \Gcproinfo\Models\Pdoptimize::count(array($condition, "bind" => $bind)); } elseif ($type == 4) { $count = \Gcproinfo\Models\Pdspecialpro::count(array($condition, "bind" => $bind)); } elseif ($type == 5) { $count = \Gcproinfo\Models\Mspecialpro::count(array($condition, "bind" => $bind)); } return $this->outputData($count); }
/** * 获得一组商品的链接 支持普通和特权混合 超过30个就不支持了 * @param array $data 要查询的商品 结构是 array(pid,pid,pid,pid,) */ public function getGoodsLink($data, $is_img = 0) { $data = $this->di['filter']->sanitize($data, 'string', ''); if (empty($data) or !is_array($data) or count($data) > 50) { return $this->outputData(false, 600, '商品信息获取失败'); } $data = array_unique($data); $goods = $special = ''; foreach ($data as $v) { if ($v >= 900000000) { $special[] = $v; } else { $goods[] = $v; } } $rs1 = $rs0 = $link = array(); if (is_array($special)) { $special = implode(',', $special); $rs0 = Pdspecialpro::find(array('pid in (' . $special . ')', "bind" => array(), 'columns' => 'pid,cate2,cate3,state,picurl'))->toArray(); } if (is_array($goods)) { foreach ($goods as $k => $v) { $rs = Pdinfo::findFirst(array('pid = :pid:', "bind" => array('pid' => $v), 'columns' => 'pid,cate2,cate3,state,picurl')); if ($rs != false) { $rs1[] = array('pid' => $rs->pid, 'cate2' => $rs->cate2, 'cate3' => $rs->cate3, 'state' => $rs->state, 'picurl' => $rs->picurl); } } } $info = array_merge($rs0, $rs1); foreach ($info as $value) { if ($is_img == 1) { $link[$value['pid']]['link'] = \Xz\Func\UrlHelper::proLinkCre($value['pid'], $value['cate2'], $value['cate3']); $picurlArr = json_decode($value['picurl'], true); $link[$value['pid']]['picurl'] = $picurlArr[0]; $link[$value['pid']]['picurlarr'] = $picurlArr; } else { $link[$value['pid']] = \Xz\Func\UrlHelper::proLinkCre($value['pid'], $value['cate2'], $value['cate3']); } } return $this->outputData($link); }
/** * 获得单个特权商品详情 * @param int $supid 供应商supid * @param int $pid 商品id * @param int $isdesc 是否要商品详情 */ public function getSpecialDetails($supid, $pid, $isdesc = 0, $column = '*') { $supid = $this->di['filter']->sanitize($supid, 'int', 0); $pid = $this->di['filter']->sanitize($pid, 'int', 0); if (empty($supid) or empty($pid)) { return $this->outputData(false, 600, '商品信息获取失败'); } $params = ['conditions' => 'pid = :pid: and supid = :supid:', 'bind' => ['supid' => $supid, 'pid' => $pid], 'columns' => $column]; $goods = $this->setModel('Pdspecialpro')->get($params); if ($goods && isset($goods[0])) { $goods = $goods[0]; if (is_array($goods) && !empty($goods)) { if ($isdesc == 1) { $obj = new \Gcproinfo\Models\Pdspecialpro(); $desc = $obj->getDesc($pid); $goods['desc'] = ''; if (!empty($desc)) { $goods['desc'] = $desc; } return $this->outputData($goods); } else { return $this->outputData($goods); } } } else { return $this->outputData(false, 600, '商品信息获取失败'); } }
/** * 获得单个商品详情 * @param int $supid 供应商supid * @param int $pid 商品id * @param int $iscominfo 是否要企业数据 * @param int $isdesc 是否要商品详情 */ public function getGoodsDetails($supid, $pid, $iscominfo = 0, $isdesc = 0) { $supid = $this->di['filter']->sanitize($supid, 'int', 0); $pid = $this->di['filter']->sanitize($pid, 'int', 0); if (empty($supid) or empty($pid)) { return $this->outputData(false, 600, '商品信息获取失败'); } $obj = new \Gcproinfo\Models\Pdspecialpro(); $goods = Pdspecialpro::findFirst(array("conditions" => "pid = :pid: and supid = :supid:", "bind" => array('supid' => $supid, 'pid' => $pid))); if ($goods) { $goods = $goods->toArray(); if (is_array($goods) && !empty($goods)) { if ($iscominfo == 1 and $isdesc == 1) { $com = ComService::getInstance()->getComBySupid($supid); $data['goods'] = $goods; if ($com['code'] == 200 && is_array($com['data'])) { $data['com'] = $com['data']; } $desc = $obj->getDesc($pid); $data['goods']['desc'] = ''; if (!empty($desc)) { $data['goods']['desc'] = $desc; } return $this->outputData($data); } elseif ($iscominfo == 1) { $com = ComService::getInstance()->getComBySupid($supid); if ($com['code'] == 200 && is_array($com['data'])) { return $this->outputData(array('com' => $com['data'], 'goods' => $goods)); } } elseif ($isdesc == 1) { $desc = $obj->getDesc($pid); $goods['desc'] = ''; if (!empty($desc)) { $goods['desc'] = $desc; } return $this->outputData($goods); } else { return $this->outputData($goods); } } } else { return $this->outputData(false, 600, '商品信息获取失败'); } }
/** * [productByPids description] * @param array $pids [description] * @return [type] [description] */ public function productByPids($pids = array()) { if (empty($pids)) { return $this->outputData(false, 600, '产品PID数组为空'); } $cjpids = array(); $normalpids = array(); $specialpids = array(); foreach ($pids as $k => $v) { $pid = intval($v); if (empty($pid)) { continue; } if ($pid >= 900000000) { $specialpids[] = $pid; } elseif ($pid >= 500000000 && $pid < 900000000) { $cjpids[] = $pid; } else { $normalpids[] = $pid; } } $normalpids = array_unique($normalpids); $specialpids = array_unique($specialpids); $cjpids = array_unique($cjpids); $proInfo = array(); if (!empty($normalpids)) { $proInfoObj = Pdinfo::find(array('conditions' => "pid in (" . implode(',', $normalpids) . ")")); if (is_object($proInfoObj)) { $proInfo = $proInfoObj->toArray(); } } $spProInfo = array(); if (!empty($specialpids)) { $spProInfoObj = Pdspecialpro::find(array('conditions' => "pid in (" . implode(',', $specialpids) . ")")); if (is_object($spProInfoObj)) { $spProInfo = $spProInfoObj->toArray(); } } $cjProInfo = array(); if (!empty($cjpids)) { $cjProInfoObj = CaijiPdinfo::find(array('conditions' => "pid in (" . implode(',', $cjpids) . ")")); if (is_object($cjProInfoObj)) { $cjProInfo = $cjProInfoObj->toArray(); } } $result = array(); $result = array_merge($result, $proInfo); $result = array_merge($result, $cjProInfo); $result = array_merge($result, $spProInfo); $result = ArrayHelper::convertPrimary($result, 'pid'); return $this->outputData($result); }