public function afterSave() { $info = json_encode(array('pid' => $this->pid, 'cid' => $this->cid)); $rabbit = new RabbitMQ($this->di['config']->rabbitmq_write->toArray()); $rabbit->setBroadcast('v3product', 'product', $info); }
/** * 操作单个产品上下架 * @param int $pid 产品id * @param int $cid 供应商cid * @param int online 0是下架 1是上架 */ public function operaGoods($pid, $cid, $online = 1) { $rabbit = new RabbitMQ($this->di['config']->rabbitmq_write->toArray()); $di = \Phalcon\Di::getDefault(); $cid = intval($cid); $pid = intval($pid); if (empty($pid) or empty($cid)) { return $this->outputData(false, 600, '参数有误'); } $info = \Gcproinfo\Models\Pdinfo::findFirst(array('pid = :pid: and cid = :cid:', 'bind' => array('pid' => $pid, 'cid' => $cid))); if ($info) { $rs = $di->getShared('gcproinfo')->update('pd_info', array('online'), array($online), 'pid = ' . $pid . ' and cid = ' . $cid); $infoMq = json_encode(array('pid' => $pid, 'cid' => $cid)); $rabbit->setBroadcast('v3product', 'product', $infoMq); if ($rs) { $di->getShared('gcproinfo')->update('pd_pidgid', array('online'), array($online), 'pid = ' . $pid . ' and cid = ' . $cid); if ($online) { $desc = $info->getDesc($info->pid); if (empty($desc)) { $desc = ''; } $comInfo = ComBaseService::getInstance()->getComInfo($info->supid, 'comname'); $comname = ''; if ($comInfo['code'] == 200 and is_array($comInfo['data'])) { $comname = $comInfo['data']['comname']; } $rabbit->setBroadcast('v3prodesc', 'prodesc', json_encode(array('pid' => $info->pid, 'cid' => $info->cid, 'cname' => $comname, 'prodesc' => $desc, 'cateid' => array($info->cate1, $info->cate2, $info->cate3, 0, 0), 'table' => 'product', 'op' => 'weijin'))); $mProduct = \Gcproinfo\Models\Mproduct::findFirst(array('pid = :pid:', 'bind' => array('pid' => $info->pid))); if ($mProduct) { if ($mProduct->state == -8) { $mProduct->state = -7; $mProduct->save(); } } } return $this->outputData(1); } } else { return $this->outputData(false, 600, '数据获取失败'); } }
/** * 删除特权临时商品 * @param int $supid 供应商id * @param int $pid 商品id */ public function delTempGoods($id, $supid = 0) { $supid = intval($supid); if (empty($id) or !is_array($id)) { return $this->outputData(false, 600, '参数有误'); } $rabbit = new RabbitMQ($this->di['config']->rabbitmq_write->toArray()); foreach ($id as $v) { if (empty($supid)) { $condition = 'id=:id:'; $bind['id'] = $v; } else { $condition = 'supid=:supid: and id=:id:'; $bind['supid'] = $supid; $bind['id'] = $v; } $temp = Mspecialpro::findFirst(array("conditions" => $condition, "bind" => $bind)); if ($temp) { $temp->state = -7; $temp->save(); //删除索引 UserSearchService::getInstance()->deleteMSpecial((int) $v, (int) $temp->cid); $rabbit->setBroadcast('v3prodesc', 'prodesc', json_encode(array('pid' => $v, 'cid' => $temp->cid, 'table' => 'mspecial', 'op' => 'delete'))); } } return $this->outputData(1); }