Esempio n. 1
0
 /**
  * 操作单个产品上下架
  * @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, '数据获取失败');
     }
 }