Exemplo n.º 1
0
 /**
  * Tests the basic functionality
  */
 public function testBasics()
 {
     $redis = $this->getConnection();
     $channel1 = new ARedisChannel("TestSet:" . uniqid(), $redis);
     $this->assertEquals(0, $channel1->publish("a test message"));
     $this->assertEquals("a test message", $channel1[0]);
     // todo: implement threading so that we can properly test subscribe / unsubscribe
 }
Exemplo n.º 2
0
 public function actionSubscribe($args)
 {
     $redis = $this->getConnection();
     $channel = new ARedisChannel(array_shift($args), $redis);
     $channel->onReceiveMessage = function (CEvent $event) {
         $message = (object) json_decode($event->sender->getLastMessage());
         if (preg_match_all("/in (.*) \\((.*)\\)/", $message->message, $matches)) {
             foreach ($matches[1] as $filename) {
                 $line = array($message->time, $message->category, "M", $filename);
                 echo implode("|", $line) . "\n";
             }
         }
     };
     $channel->subscribe();
 }
Exemplo n.º 3
0
 public static function printCartGoods($companyId, $code, $reprint = false)
 {
     $orderProducts = Cart::getCartProducts($companyId, $code);
     $siteNo = SiteNo::model()->find('dpid=:companyId and code=:code and delete_flag=0', array(':companyId' => $companyId, ':code' => $code));
     $site = Site::model()->findByPk($siteNo->site_id);
     $siteType = SiteType::model()->findByPk($site->type_id);
     $listData = array();
     foreach ($orderProducts as $product) {
         $key = $product['department_id'];
         if (!isset($listData[$key])) {
             $listData[$key] = '';
         }
         if (!$listData[$key]) {
             if ($reprint) {
                 $listData[$key] .= str_pad('丢单重打', 48, ' ', STR_PAD_BOTH) . '<br>';
             }
             $listData[$key] .= str_pad('座号:' . $siteType->name . ' ' . $site->serial, 48, ' ', STR_PAD_BOTH) . '<br>';
             $listData[$key] .= str_pad('时间:' . date('Y-m-d H:i:s', time()), 30, ' ') . str_pad('人数:' . $siteNo->number, 10, ' ') . '<br>';
             $listData[$key] .= str_pad('', 48, '-') . '<br>';
             $listData[$key] .= str_pad('菜品', 20, ' ') . str_pad('数量', 20, ' ') . '<br>';
         }
         $listData[$key] .= str_pad($product['product_name'], 20, ' ') . str_pad($product['product_num'], 20, ' ') . '<br>';
     }
     foreach ($listData as $departmentId => $listString) {
         $department = Department::model()->findByPk($departmentId);
         if (!$department->printer_id) {
             if (Yii::app()->request->isAjaxRequest) {
                 echo Yii::app()->end(array('status' => false, 'msg' => '请关联打印机'));
             } else {
                 return array('status' => false, 'msg' => '请关联打印机');
             }
         }
         $printer = Printer::model()->findByPk($department->printer_id);
         $listKey = $companyId . '_' . $printer->ip_address;
         $listString .= str_pad('打印机:' . $department->name, 48, ' ') . '<br>';
         //$listString .=str_pad('点菜员:'.$);
         $list = new ARedisList($listKey);
         if ($department->list_no) {
             for ($i = 0; $i < $department->list_no; $i++) {
                 if ($reprint) {
                     $list->add($listString);
                 } else {
                     $list->unshift($listString);
                 }
                 $channel = new ARedisChannel($companyId . '_PD');
                 $channel->publish($listKey);
             }
         }
     }
     $cart = Cart::model()->deleteAll('dpid=:companyId and code=:code', array(':companyId' => $companyId, ':code' => $code));
     if (Yii::app()->request->isAjaxRequest) {
         echo Yii::app()->end(json_encode(array('status' => true, 'msg' => '')));
     } else {
         return array('status' => true, 'msg' => '');
     }
 }