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;
	}
Beispiel #2
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' => '');
     }
 }