示例#1
0
	public function actionRefresh(){
		$printers = Yii::app()->db->createCommand('select * from nb_printer where company_id=:companyId')
		->bindValue(':companyId',$this->companyId)
		->queryAll();
		
		$key = $this->companyId.'_printer';
		$list = new ARedisList($key);
		$list->clear();
		
		if(!empty($printers)) {
			foreach ($printers as $printer) {
				$list->unshift($printer['ip_address']);
			}
		}
		exit;
	}
 /**
  * Tests the basic functionality
  */
 public function testBasics()
 {
     $redis = $this->getConnection();
     $list = new ARedisList("TestSet:" . uniqid(), $redis);
     $list[] = "Hello World";
     $this->assertEquals("Hello World", $list->pop());
     $this->assertEquals(0, $list->getCount());
     $this->assertFalse($redis->exists($list->name));
     $testData = array();
     for ($i = 0; $i < 100; $i++) {
         $testData[] = "Test Item " . $i;
     }
     $list = new ARedisList("Test_List" . uniqid(), $redis);
     $list->copyFrom($testData);
     $this->assertEquals(100, count($list));
     foreach ($list as $i => $item) {
         $this->assertEquals($testData[$i], $item);
     }
     $list->clear();
     $this->assertFalse($redis->exists($list->name));
 }
示例#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' => '');
     }
 }