コード例 #1
0
 public function actionGetSitePersons()
 {
     $companyid = Yii::app()->request->getParam('companyid', 0);
     $padid = Yii::app()->request->getParam('padid', 0);
     $stlid = Yii::app()->request->getParam('stlid', 0);
     $splid = Yii::app()->request->getParam('splid', 0);
     $ret = array();
     $nowqueueno = "000";
     $queueno = "A001";
     $waitingno = 0;
     if (empty($companyid) || empty($padid)) {
         Yii::app()->end(json_encode(array('status' => false, 'msg' => '店铺或设备不存在!')));
     }
     $pad = Pad::model()->with("printer")->find(' t.dpid=:companyId and t.lid=:padid', array(':companyId' => $companyid, ':padid' => $padid));
     //var_dump($pad);exit;
     if (!empty($pad)) {
         //生成新的排队号
         $siteType = SiteType::model()->find(" dpid=:dpid and lid=:lid", array(":dpid" => $companyid, ":lid" => $stlid));
         //var_dump($siteType);exit;
         $criteria = new CDbCriteria();
         $criteria->condition = " dpid=" . $companyid . " and stlid=" . $stlid . " and splid=" . $splid . " and create_at >='" . date('Y-m-d', time()) . " 00:00:00' and create_at <='" . date('Y-m-d', time()) . " 23:59:59'";
         $criteria->order = ' lid ';
         $queuePerson = QueuePersons::model()->findAll($criteria);
         if (empty($siteType)) {
             Yii::app()->end(json_encode(array('status' => false, 'msg' => '座位类型不存在!')));
         }
         //var_dump($queuePerson);exit;
         if (!empty($queuePerson)) {
             $countsp = count($queuePerson);
             $queueno = $siteType->simplecode . substr("000" . (string) ($countsp + 1), -3);
             for ($sti = $countsp - 1; $sti >= 0; $sti--) {
                 if ($queuePerson[$sti]->status == "0") {
                     $waitingno++;
                 } else {
                     break;
                 }
             }
         } else {
             $queueno = $siteType->simplecode . "001";
             $waitingno = 0;
         }
         $se = new Sequence("queue_persons");
         $queuelid = $se->nextval();
         $data = array('lid' => $queuelid, 'dpid' => $companyid, 'create_at' => date('Y-m-d H:i:s', time()), 'update_at' => date('Y-m-d H:i:s', time()), 'stlid' => $stlid, 'splid' => $splid, 'queue_no' => $queueno, 'status' => '0', 'slid' => "0000000000", 'delete_flag' => '0');
         Yii::app()->db->createCommand()->insert('nb_queue_persons', $data);
         $waitingno++;
         //返回现有的等待人数
         $precode = "";
         $printserver = "0";
         //
         $memo = "排队号:" . $queueno . ",(还有" . $waitingno . "组在等待)";
         $ret = Helper::printQueue($pad, $precode, $printserver, $memo);
         if ($ret['status']) {
             $ret['waitingnum'] = $waitingno;
         }
     } else {
         $ret = array('status' => false, 'msg' => '没有找到PAD');
     }
     Yii::app()->end(json_encode($ret));
 }
コード例 #2
0
 public function actionGetOnePad()
 {
     $companyid = Yii::app()->request->getParam('companyid', 0);
     $padid = Yii::app()->request->getParam('padid', 0);
     if (!$companyid) {
         Yii::app()->end(json_encode(array('data' => array(), 'delay' => 400)));
     }
     $treeDataSource = array('data' => array(), 'delay' => 400);
     $pads = Pad::model()->findAll('dpid=:companyId and lid=:lid and delete_flag=0 ', array(':companyId' => $companyid, ':lid' => $padid));
     //var_dump($pads);exit;
     foreach ($pads as $c) {
         $tmp['name'] = $c['name'];
         $tmp['id'] = $c['lid'];
         $treeDataSource['data'][] = $tmp;
     }
     header('Content-type: application/Json');
     $endjson = json_encode($treeDataSource);
     Yii::app()->end("{$_GET['jsoncallback']}({$endjson});");
 }
コード例 #3
0
 public function actionPrintList()
 {
     $orderId = Yii::app()->request->getParam('orderId', 0);
     //$companyId = Yii::app()->request->getParam('companyId');
     $padId = Yii::app()->request->getParam('padId');
     $typeId = Yii::app()->request->getParam('typeId');
     Until::validOperate($companyId, $this);
     $order = Order::model()->with('company')->find('t.lid=:id and t.dpid=:dpid', array(':id' => $orderId, ':dpid' => $this->companyId));
     $pad = Pad::model()->find(' dpid=:dpid and lid=:lid', array(':dpid' => $order->dpid, 'lid' => $padId));
     //前面加 barcode
     if (!empty($pad)) {
         $precode = "";
         //$precode="1D6B450B".strtoupper(implode('',unpack('H*', 'A'.$order->lid)))."0A".strtoupper(implode('',unpack('H*', 'A'.$order->lid)))."0A";
         //Yii::app()->end(json_encode(Helper::printList($order , $padid)));
         $printserver = "1";
         $memo = "";
         $ret = Helper::printList($order, $pad, $precode, $printserver, $memo);
     } else {
         $ret = array('status' => false, 'dpid' => $order->dpid, 'jobid' => "0", 'type' => 'none', 'msg' => yii::t('app', 'PAD不存在!'));
     }
     //exit;
     $this->renderPartial('printlist', array('orderId' => $orderId, 'ret' => $ret, 'typeId' => $typeId));
 }
コード例 #4
0
ファイル: CreateOrder.php プロジェクト: song-yuan/wymenujp
 /**
  * 
  * 大pad下单并打印
  * 
  */
 public static function createPadOrder($dpid, $goodsIds, $padId)
 {
     $isTemp = $goodsIds['client_is_temp'];
     $site_id = $goodsIds['client_site_id'];
     $siteName = $goodsIds['client_site_name'];
     $reprint = $goodsIds['client_reprint'];
     $waitorname = $goodsIds['client_waitor_name'];
     //订单的状态,临时做下单时挂单状态,非临时做下单直接厨打
     $orderStatus = "2";
     $orderPorductStatus = "1";
     if ($isTemp == "1") {
         $orderStatus = "1";
         $orderPorductStatus = "0";
     }
     unset($goodsIds['client_is_temp']);
     unset($goodsIds['client_site_id']);
     unset($goodsIds['client_site_name']);
     unset($goodsIds['client_reprint']);
     unset($goodsIds['client_waitor_name']);
     $siteStatus = self::getSiteStatus($site_id, $dpid, $isTemp);
     if (empty($siteStatus)) {
         throw new Exception(json_encode(array('status' => false, 'dpid' => $dpid, 'jobid' => "0", 'type' => 'local', 'msg' => yii::t('app', '请先开台后下单!'))));
     }
     $sellOff = array();
     $printOrderProducts = array();
     $time = date('Y-m-d H:i:s', time());
     $db = Yii::app()->db;
     //return json_encode(array('status'=>false,'msg'=>$waitorname));
     $transaction = $db->beginTransaction();
     try {
         if ($site_id == 0) {
             //未开台的临时台
             $se = new Sequence("site_no");
             $lid = $se->nextval();
             $code = rand(1000, 9999);
             $se = new Sequence("temp_site");
             $site_id = $se->nextval();
             $data = array('lid' => $lid, 'dpid' => $dpid, 'create_at' => date('Y-m-d H:i:s', time()), 'update_at' => date('Y-m-d H:i:s', time()), 'is_temp' => $isTemp, 'site_id' => $site_id, 'status' => $orderStatus, 'code' => $code, 'number' => 1, 'delete_flag' => '0');
             $db->createCommand()->insert('nb_site_no', $data);
             $feedback_memo = '开台';
             $se = new Sequence("order");
             $orderId = $se->nextval();
             $data = array('lid' => $orderId, 'dpid' => $dpid, 'site_id' => $site_id, 'create_at' => $time, 'username' => $waitorname, 'is_temp' => $isTemp, 'order_status' => $orderStatus, 'number' => 1, 'update_at' => $time, 'remark' => yii::t('app', '无'), 'taste_memo' => "");
             $db->createCommand()->insert('nb_order', $data);
             $sef = new Sequence("order_feedback");
             $lidf = $sef->nextval();
             $dataf = array('lid' => $lidf, 'dpid' => $dpid, 'create_at' => date('Y-m-d H:i:s', time()), 'update_at' => date('Y-m-d H:i:s', time()), 'is_temp' => $isTemp, 'site_id' => $site_id, 'is_deal' => '0', 'feedback_id' => 0, 'order_id' => 0, 'is_order' => '1', 'feedback_memo' => $feedback_memo, 'delete_flag' => '0');
             $db->createCommand()->insert('nb_order_feedback', $dataf);
         } else {
             //已经开台的固定台或临时台,
             //$feedback_memo = yii::t('app','点单');
             // 				//查找site表
             // 				$sql = 'select * from nb_site_no where site_id='.$site_id.' and dpid='.$dpid.' order by lid desc';
             // 				$siteModel = $db->createCommand($sql)->queryRow();
             // 				if(!$siteModel){
             // 					throw new Exception(json_encode( array('status'=>false,'dpid'=>$dpid,'msg'=>yii::t('app','存在该座次号,请重新选座次下单!')),JSON_UNESCAPED_UNICODE));
             // 				}
             // 				 //如果该座位 状态开台未下单
             //	            if(0 < $siteModel['status'] && $siteModel['status'] < 4){
             //	            	//先查找是否已经存在订单
             //	            	$sql = 'select * from nb_order where site_id='.$site_id.' and dpid='.$dpid.' and is_temp='.$isTemp.' order by lid desc';
             $criteria = new CDbCriteria();
             $criteria->condition = ' t.order_status in ("1","2","3") and  t.dpid=' . $dpid . ' and t.site_id=' . $site_id . ' and t.is_temp=' . $isTemp;
             $criteria->order = ' t.lid desc ';
             $orderModel = Order::model()->find($criteria);
             $criteria->condition = ' t.status in ("1","2","3") and  t.dpid=' . $dpid . ' and t.site_id=' . $site_id . ' and t.is_temp=' . $isTemp;
             $criteria->order = ' t.lid desc ';
             $siteNo = SiteNo::model()->find($criteria);
             $siteNo->status = $orderStatus;
             $siteNo->update_at = date('Y-m-d H:i:s', time());
             $siteNo->save();
             if ($isTemp == "0") {
                 $site = Site::model()->find(" t.dpid=:dpid and t.lid=:siteid", array(':dpid' => $siteNo->dpid, ':siteid' => $siteNo->site_id));
                 $site->status = $orderStatus;
                 $site->update_at = date('Y-m-d H:i:s', time());
                 $site->save();
             }
             if ($orderModel) {
                 $orderId = $orderModel['lid'];
             } else {
                 //生成订单
                 $se = new Sequence("order");
                 $orderId = $se->nextval();
                 $data = array('lid' => $orderId, 'dpid' => $dpid, 'site_id' => $site_id, 'create_at' => $time, 'username' => $waitorname, 'is_temp' => $isTemp, 'order_status' => $orderStatus, 'number' => $siteNo->number, 'update_at' => $time, 'remark' => yii::t('app', '无'), 'taste_memo' => "");
                 $db->createCommand()->insert('nb_order', $data);
                 //更新site表状态
                 //						$sql = 'update nb_site set status=1 where lid='.$site_id.' and dpid='.$dpid.' order by lid desc';
                 //					    $db->createCommand($sql)->execute();
                 //					    //更新site_no表状态
                 //					    $sql = 'update nb_site_no set status=1 where site_id='.$site_id.' and dpid='.$dpid.' and is_temp='.$isTemp.' order by lid desc';
                 //					    $db->createCommand($sql)->execute();
             }
         }
         //            return json_encode(array('status'=>false,'msg'=>"test"));
         //订单产品 $goodsIds = array('goods_id'=>goods_num,'set_id,1'=>set_num);
         $orderPrice = 0;
         foreach ($goodsIds as $key => $num) {
             $se = new Sequence("order_product");
             $orderProductId = $se->nextval();
             $goodsArr = explode(',', $key);
             if (count($goodsArr) > 1) {
                 // 套餐
                 $sql = 'select * from nb_product_set where dpid=' . $dpid . ' and lid=' . $goodsArr[0];
                 $result = $db->createCommand($sql)->queryRow();
                 if ($result) {
                     if ($result['store_number'] == 0 || $result['store_number'] > 0 && $result['store_number'] < 1) {
                         throw new Exception(json_encode(array('status' => false, 'dpid' => $dpid, 'jobid' => "0", 'type' => 'local', 'msg' => yii::t('app', $result['set_name'] . '库存不足!'))));
                     }
                 } else {
                     throw new Exception(json_encode(array('status' => false, 'dpid' => $dpid, 'jobid' => "0", 'type' => 'local', 'msg' => yii::t('app', '没有找到该产品请清空后重新下单!'))));
                 }
                 //添加选择的套餐明细
                 foreach ($num as $setDetail) {
                     $detailId = key($setDetail);
                     $productSet = self::getSetProductId($dpid, $detailId);
                     $orderProductData = array('lid' => $orderProductId, 'dpid' => $dpid, 'create_at' => $time, 'order_id' => $orderId, 'set_id' => $goodsArr[0], 'product_id' => $productSet['product_id'], 'price' => $productSet['price'], 'update_at' => $time, 'amount' => $productSet['number'], 'taste_memo' => "", 'product_order_status' => $orderPorductStatus);
                     $db->createCommand()->insert('nb_order_product', $orderProductData);
                     $se = new Sequence("order_product");
                     $orderProductId = $se->nextval();
                     $orderPrice += $productSet['price'] * $productSet['number'];
                     array_push($printOrderProducts, array('amount' => $productSet['number'], 'price' => $productSet['price'], 'product_name' => ProductClass::getProductName($productSet['product_id'], $dpid)));
                 }
                 if ($result['store_number'] > 0) {
                     $sql = 'update nb_product_set set store_number=store_number-1 where dpid=' . $dpid . ' and lid=' . $goodsArr[0];
                     $db->createCommand($sql)->execute();
                     array_push($sellOff, array("product_id" => sprintf("%010d", $goodsArr[0]), "type" => "set", "num" => $result['store_number'] - 1));
                 }
             } else {
                 //单品 如果有口味  num-eq =>array('taste_id1','taste_id2') num 是数量 eq是序号 $goodsArr[0] 产品id
                 if ($goodsArr[0] == 'quandan') {
                     //全单口味
                     foreach ($num as $tasteId => $taste) {
                         $se = new Sequence("order_taste");
                         $orderTasteId = $se->nextval();
                         $orderTasteData = array('lid' => $orderTasteId, 'dpid' => $dpid, 'create_at' => $time, 'order_id' => $orderId, 'taste_id' => $tasteId, 'is_order' => 1, 'update_at' => $time);
                         $db->createCommand()->insert('nb_order_taste', $orderTasteData);
                     }
                 } else {
                     $sql = 'select * from nb_product where dpid=' . $dpid . ' and lid=' . $goodsArr[0];
                     $result = $db->createCommand($sql)->queryRow();
                     $productPrice = self::getProductPrice($dpid, $key, 0);
                     if (is_array($num)) {
                         //有口味$num = num-eq 格式
                         foreach ($num as $k => $v) {
                             $numEq = explode('-', $k);
                             $amount = $numEq[0];
                             if ($result) {
                                 if ($result['store_number'] == 0 || $result['store_number'] > 0 && $result['store_number'] < $amount) {
                                     throw new Exception(json_encode(array('status' => false, 'dpid' => $dpid, 'jobid' => "0", 'type' => 'local', 'msg' => yii::t('app', $result['product_name'] . '库存不足!'))));
                                 }
                             } else {
                                 throw new Exception(json_encode(array('status' => false, 'dpid' => $dpid, 'jobid' => "0", 'type' => 'local', 'msg' => yii::t('app', '没有找到该产品请清空后重新下单!'))));
                             }
                             //每一个eq 生成一个订单
                             $orderProductData = array('lid' => $orderProductId, 'dpid' => $dpid, 'create_at' => $time, 'order_id' => $orderId, 'set_id' => 0, 'product_id' => $goodsArr[0], 'price' => $productPrice, 'update_at' => $time, 'amount' => $amount, 'taste_memo' => "", 'product_order_status' => $orderPorductStatus);
                             $db->createCommand()->insert('nb_order_product', $orderProductData);
                             $orderPrice += $productPrice * $amount;
                             array_push($printOrderProducts, array('amount' => $amount, 'price' => $productPrice, 'product_name' => ProductClass::getProductName($goodsArr[0], $dpid)));
                             //该订单对应的多个口味
                             foreach ($v as $tasteId => $val) {
                                 if ($tasteId) {
                                     $orderTastSe = new Sequence("order_taste");
                                     $orderTasteId = $orderTastSe->nextval();
                                     $orderTasteData = array('lid' => $orderTasteId, 'dpid' => $dpid, 'create_at' => $time, 'update_at' => $time, 'taste_id' => $tasteId, 'order_id' => $orderProductId, 'is_order' => 0);
                                     $db->createCommand()->insert('nb_order_taste', $orderTasteData);
                                 }
                             }
                             $se = new Sequence("order_product");
                             $orderProductId = $se->nextval();
                             if ($result['store_number'] > 0) {
                                 $sql = 'update nb_product set store_number=store_number-' . $amount . ' where dpid=' . $dpid . ' and lid=' . $goodsArr[0];
                                 $db->createCommand($sql)->execute();
                                 array_push($sellOff, array("product_id" => sprintf("%010d", $goodsArr[0]), "type" => "product", "num" => $result['store_number'] - $amount));
                             }
                             $sqladd = 'update nb_product set order_number=order_number+' . $amount . ',favourite_number=favourite_number+' . $amount . ' where dpid=' . $dpid . ' and lid=' . $goodsArr[0];
                             $db->createCommand($sqladd)->execute();
                         }
                     } else {
                         if ($result) {
                             if ($result['store_number'] == 0 || $result['store_number'] > 0 && $result['store_number'] < $num) {
                                 throw new Exception(json_encode(array('status' => false, 'dpid' => $dpid, 'jobid' => "0", 'type' => 'local', 'msg' => yii::t('app', $result['product_name'] . '库存不足!'))));
                             }
                         } else {
                             throw new Exception(json_encode(array('status' => false, 'dpid' => $dpid, 'jobid' => "0", 'type' => 'local', 'msg' => yii::t('app', '没有找到该产品请清空后重新下单!'))));
                         }
                         $orderProductData = array('lid' => $orderProductId, 'dpid' => $dpid, 'create_at' => $time, 'order_id' => $orderId, 'set_id' => 0, 'product_id' => $goodsArr[0], 'price' => $productPrice, 'update_at' => $time, 'amount' => $num, 'taste_memo' => "", 'product_order_status' => $orderPorductStatus);
                         $db->createCommand()->insert('nb_order_product', $orderProductData);
                         $orderPrice += $productPrice * $num;
                         array_push($printOrderProducts, array('amount' => $num, 'price' => $productPrice, 'product_name' => ProductClass::getProductName($goodsArr[0], $dpid)));
                         if ($result['store_number'] > 0) {
                             $sql = 'update nb_product set store_number=store_number-' . $num . ' where dpid=' . $dpid . ' and lid=' . $goodsArr[0];
                             $db->createCommand($sql)->execute();
                             array_push($sellOff, array("product_id" => sprintf("%010d", $goodsArr[0]), "type" => "product", "num" => $result['store_number'] - $num));
                         }
                         $sqladd = 'update nb_product set order_number=order_number+' . $num . ',favourite_number=favourite_number+' . $num . ' where dpid=' . $dpid . ' and lid=' . $goodsArr[0];
                         $db->createCommand($sqladd)->execute();
                     }
                 }
             }
         }
         $sql = 'update nb_order set should_total=' . $orderPrice . ' where lid=' . $orderId . ' and dpid=' . $dpid;
         $db->createCommand($sql)->execute();
         //                        $sql = 'update nb_site_no set status='.$orderPrice.' where lid='.$orderId.' and dpid='.$dpid;
         //			$db->createCommand($sql)->execute();
         //			return json_encode(array('status'=>false,'msg'=>"test22"));
         //厨打
         if ($orderId != '0') {
             $order = Order::model()->with('company')->find(' t.lid=:lid and t.dpid=:dpid and t.order_status in(1,2,3)', array(':lid' => $orderId, ':dpid' => $dpid));
             //Yii::app()->end(json_encode(array('status'=>false,'msg'=>"234")));
             if (empty($order)) {
                 return json_encode(array('status' => false, 'msg' => "该订单不存在"));
             }
         }
         //           return json_encode(array('status'=>false,'msg'=>"test2236"));
         if ($order->is_temp == "0") {
             //               return json_encode(array('status'=>false,'msg'=>"test2235"));
             $criteria = new CDbCriteria();
             $criteria->condition = 't.dpid=' . $dpid . ' and t.site_id=' . $order->site_id . ' and t.is_temp=' . $order->is_temp;
             $criteria->order = ' t.lid desc ';
             $siteNo = SiteNo::model()->find($criteria);
             //order site 和 siteno都需要更新状态 所以要取出来
             $criteria2 = new CDbCriteria();
             $criteria2->condition = 't.dpid=' . $dpid . ' and t.lid=' . $order->site_id;
             $criteria2->order = ' t.lid desc ';
             $site = Site::model()->with("siteType")->find($criteria2);
             //            return json_encode(array('status'=>false,'msg'=>"test8"));
             $printList = Helper::printKitchenAll3($order, $site, $siteNo, false);
         } else {
             //                return json_encode(array('status'=>false,'msg'=>"test223"));
             $pad = Pad::model()->with('printer')->find(' t.dpid=:dpid and t.lid=:lid', array(':dpid' => $order->dpid, 'lid' => $padId));
             //前面加 barcode
             $precode = "1D6B450B" . strtoupper(implode('', unpack('H*', 'A' . $order->lid))) . "0A" . strtoupper(implode('', unpack('H*', 'A' . $order->lid))) . "0A";
             $orderProducts = OrderProduct::getOrderProducts($order->lid, $order->dpid);
             //var_dump($orderProducts);exit;
             //return json_encode(array('status'=>false,'msg'=>"test2234"));
             $memo = "清单";
             $printList = Helper::printList($order, $orderProducts, $pad, $precode, "0", $memo);
         }
         if (!$printList['status']) {
             throw new Exception(json_encode($printList));
         }
         //$printList2=array_merge($printList,array('sitenoid'=> $lid));
         //            }
         $transaction->commit();
         //估清产品通知
         if (!empty($sellOff)) {
             Gateway::getOnlineStatus();
             $store = Store::instance('wymenu');
             $pads = Pad::model()->findAll(" dpid = :dpid and delete_flag='0' and pad_type in ('0','1','2')", array(":dpid" => $dpid));
             //var_dump($pads);exit;
             $sendjsondata = json_encode(array("company_id" => $dpid, "do_id" => "sell_off", "do_data" => $sellOff));
             //var_dump($sendjsondata);exit;
             foreach ($pads as $pad) {
                 $clientId = $store->get("padclient_" . $dpid . $pad->lid);
                 //var_dump($clientId,$print_data);exit;
                 if (!empty($clientId)) {
                     Gateway::sendToClient($clientId, $sendjsondata);
                 }
             }
         }
         return json_encode($printList);
     } catch (Exception $e) {
         $transaction->rollback();
         //如果操作失败, 数据回滚
         throw new Exception($e->getMessage());
         //return $e->getMessage();
     }
 }
コード例 #5
0
 public function actionResetall()
 {
     $typeId = Yii::app()->request->getParam('typeId');
     $db = Yii::app()->db;
     $sql = '';
     if ($typeId == 'product') {
         $sql = 'update nb_product set store_number = -1 where dpid=' . $this->companyId;
     } else {
         $sql = 'update nb_product_set set store_number = -1 where dpid=' . $this->companyId;
     }
     //var_dump($sql);exit;
     $command = $db->createCommand($sql);
     if ($command->execute()) {
         Gateway::getOnlineStatus();
         $store = Store::instance('wymenu');
         $pads = Pad::model()->findAll(" dpid = :dpid and delete_flag='0' and pad_type in ('1','2')", array(":dpid" => $this->companyId));
         //var_dump($pads);exit;
         $sendjsondata = json_encode(array("company_id" => $this->companyId, "do_id" => "sell_off", "do_data" => array(array("product_id" => $id, "type" => $typeId, "num" => $store_number))));
         //var_dump($sendjsondata);exit;
         foreach ($pads as $pad) {
             $clientId = $store->get("padclient_" . $this->companyId . $pad->lid);
             //var_dump($clientId,$print_data);exit;
             if (!empty($clientId)) {
                 Gateway::sendToClient($clientId, $sendjsondata);
             }
         }
         Yii::app()->end(json_encode(array("status" => "success")));
     } else {
         Yii::app()->end(json_encode(array("status" => "fail")));
     }
 }
コード例 #6
0
ファイル: Helper.php プロジェクト: song-yuan/wymenujp
 public static function printPadList(Order $order, $padid)
 {
     $pad = Pad::model()->find(' dpid=:dpid and lid=:lid', array(':dpid' => $order->dpid, 'lid' => $padid));
     $printer = Printer::model()->find('lid=:printerId and dpid=:dpid', array(':printerId' => $pad->printer_id, ':dpid' => $order->dpid));
     if (empty($printer)) {
         return array('status' => false, 'dpid' => $order->dpid, 'jobid' => "0", 'type' => 'none', 'msg' => yii::t('app', 'PAD还没有设置默认打印机'));
     }
     $hasData = false;
     $orderProducts = OrderProduct::getOrderProducts($order->lid, $order->dpid);
     ///site error because tempsite and reserve**************
     if ($order->is_temp == 0) {
         $site = Site::model()->find('lid=:lid and dpid=:dpid', array(':lid' => $order->site_id, ':dpid' => $order->dpid));
         $siteType = SiteType::model()->find('lid=:lid and dpid=:dpid', array(':lid' => $site->type_id, ':dpid' => $order->dpid));
         $strSite = Helper::getPlaceholderLen(yii::t('app', '座号:') . $siteType->name . ' ' . $site->serial, 48);
     } else {
         $strSite = Helper::getPlaceholderLen(yii::t('app', '座号:临时座') . $order->site_id % 1000, 48);
     }
     ///////$listKey = $order->dpid.'_'.$printer->ip_address;
     //var_dump($list);exit;
     //$listData = array(Helper::getPlaceholderLenBoth($order->company->company_name, 48));
     $listData = array("22" . Helper::setPrinterTitle($order->company->company_name, 8));
     array_push($listData, $strSite);
     array_push($listData, str_pad('', 48, '-'));
     foreach ($orderProducts as $product) {
         //var_dump($product);exit;
         $hasData = true;
         if (Yii::app()->language == 'jp') {
             array_push($listData, Helper::getPlaceholderLen($product['product_name'], 36) . Helper::getPlaceholderLen($product['amount'] . " X " . number_format($product['price'], 0), 12));
         } else {
             array_push($listData, Helper::getPlaceholderLen($product['product_name'], 24) . Helper::getPlaceholderLen($product['amount'] . $product['product_unit'], 12) . Helper::getPlaceholderLen(number_format($product['price'], 2), 12));
         }
     }
     array_push($listData, str_pad('', 48, '-'));
     array_push($listData, str_pad(yii::t('app', '合计:') . $order->reality_total, 24, ' ') . str_pad(yii::t('app', '时间:') . time(), 24, ' '));
     array_push($listData, str_pad(yii::t('app', '服务员:') . $order->username, 48, ' '));
     //前面加 barcode
     $precode = "1D6B450B" . strtoupper(implode('', unpack('H*', 'A' . $order->lid))) . "0A" . strtoupper(implode('', unpack('H*', 'A' . $order->lid))) . "0A";
     //后面加切纸
     $sufcode = "0A0A0A0A0A0A1D5601";
     if ($hasData) {
         return Helper::printConetent($printer, $listData, $precode, $sufcode);
     } else {
         return array('status' => false, 'dpid' => $printer->dpid, 'jobid' => "0", 'type' => 'none', 'msg' => yii::t('app', '没有要打印的菜品'));
     }
 }
コード例 #7
0
 public function actionOpensiteprint()
 {
     if (Yii::app()->request->isPostRequest) {
         $sid = Yii::app()->request->getPost('sid');
         $siteNumber = Yii::app()->request->getPost('siteNumber');
         $companyId = Yii::app()->request->getPost('companyId');
         $padId = Yii::app()->request->getPost('padId', "0000000000");
         if (!Until::validOperateJson($companyId, $this)) {
             $ret = json_encode(array('status' => 0, 'msg' => yii::t('app', '云端不能操作本地数据'), 'siteid' => $sid));
             Yii::app()->end($ret);
         }
         //$sid = Yii::app()->request->getPost('sid');
         $istemp = Yii::app()->request->getPost('istemp', '0');
         $ret = SiteClass::openSite($companyId, $siteNumber, $istemp, $sid);
         if ($ret["status"] == 1) {
             $siteno;
             $site = new Site();
             $siteid = $ret['siteid'];
             $criteria = new CDbCriteria();
             $criteria->condition = 't.dpid=' . $companyId . ' and t.site_id=' . $siteid . ' and t.is_temp=' . $istemp;
             $criteria->order = ' t.lid desc ';
             $siteno = SiteNo::model()->find($criteria);
             //Yii::app()->end(json_encode(array('status'=>0,'msg'=>"222")));
             //order site 和 siteno都需要更新状态 所以要取出来
             if ($istemp == "0") {
                 $criteria2 = new CDbCriteria();
                 $criteria2->condition = 't.dpid=' . $companyId . ' and t.lid=' . $siteid;
                 $criteria2->order = ' t.lid desc ';
                 $site = Site::model()->with("siteType")->find($criteria2);
             }
             $pad = Pad::model()->find(' dpid=:dpid and lid=:lid', array(':dpid' => $companyId, 'lid' => $padId));
             if (!empty($pad)) {
                 //$precode="1B70001EFF00";//开钱箱
                 $precode = "";
                 $printserver = "1";
                 $memo = "请等待叫号!";
                 $ret = Helper::printSite($siteno, $site, $pad, $precode, $printserver, $memo);
             } else {
                 $ret = array('status' => 0, 'msg' => yii::t('app', '没有找到PAD'), 'siteid' => $siteid);
             }
         }
         Yii::app()->end(json_encode($ret));
     }
 }
コード例 #8
0
ファイル: PadController.php プロジェクト: song-yuan/wymenujp
 public function actionDelete()
 {
     $companyId = Helper::getCompanyId(Yii::app()->request->getParam('companyId'));
     $ids = Yii::app()->request->getPost('ids');
     Until::isUpdateValid($ids, $companyId, $this);
     //0,表示企业任何时候都在云端更新。
     //var_dump($ids);exit;
     if (!empty($ids)) {
         foreach ($ids as $id) {
             $model = Pad::model()->find('lid=:id and dpid=:companyId', array(':id' => $id, ':companyId' => $companyId));
             if ($model) {
                 $model->saveAttributes(array('delete_flag' => 1, 'update_at' => date('Y-m-d H:i:s', time())));
             }
         }
         $this->redirect(array('pad/index', 'companyId' => $companyId));
     } else {
         Yii::app()->user->setFlash('error', yii::t('app', '请选择要删除的项目'));
         $this->redirect(array('pad/index', 'companyId' => $companyId));
     }
 }
コード例 #9
0
 public function actionOrderDaliyCollectPrint()
 {
     $criteria = new CDbCriteria();
     $begin_time = Yii::app()->request->getParam('begin_time', date('Y-m-d', time()));
     $end_time = Yii::app()->request->getParam('end_time', date('Y-m-d', time()));
     $padid = Yii::app()->request->getParam('padid');
     $ret = array();
     $criteria->select = 't.paytype, t.payment_method_id,t.dpid, t.update_at,sum(t.pay_amount) as should_all';
     //利用Yii框架CDB语句时,聚合函数要在model的类里面进行公共变量定义,如:变量should_all在order的class里面定义为public $should_all;
     //$criteria->select = 'sum(t.should_total) as should_all'; //代表了要查询的字段,默认select='*';
     $criteria->with = array("order");
     //连接表
     $criteria->addCondition("t.dpid= " . $this->companyId);
     $criteria->addCondition("order.update_at >='{$begin_time} 00:00:00'");
     $criteria->addCondition("order.update_at <='{$end_time} 23:59:59'");
     $criteria->group = "t.paytype";
     $models = OrderPay::model()->findAll($criteria);
     if (count($models) == 0) {
         $ret = array('status' => false, 'msg' => "没有数据!");
         Yii::app()->end(json_encode($ret));
     }
     //var_dump($model[0]->order);exit;
     //Yii::app()->end(json_encode(array('status'=>false,'msg'=>"111")));
     ////////////////
     $transaction = Yii::app()->db->beginTransaction();
     try {
         $userId = Yii::app()->user->userId;
         // lid_dpid
         $userIdArr = explode('_', $userId);
         $se = new Sequence("close_account");
         $clid = $se->nextval();
         $closeA = new CloseAccount();
         $closeAdata = array('lid' => $clid, 'dpid' => $this->companyId, 'create_at' => date('Y-m-d H:i:s', time()), 'update_at' => date('Y-m-d H:i:s', time()), 'user_id' => $userIdArr[0], 'begin_time' => $begin_time, 'end_time' => $end_time, 'close_day' => date('Y-m-d H:i:s', time()), 'all_money' => 0);
         $closeA->attributes = $closeAdata;
         $closeA->save();
         $totalMoney = 0;
         foreach ($models as $model) {
             //插入明细表
             $se = new Sequence("close_account_detail");
             $lid = $se->nextval();
             $closeADel = new CloseAccountDetail();
             $closeADeldata = array('lid' => $lid, 'dpid' => $this->companyId, 'create_at' => date('Y-m-d H:i:s', time()), 'update_at' => date('Y-m-d H:i:s', time()), 'close_account_id' => $clid, 'paytype' => $model->paytype, 'payment_method_id' => $model->payment_method_id, 'all_money' => $model->should_all);
             $closeADel->attributes = $closeADeldata;
             $closeADel->save();
             $totalMoney += $model->should_all;
         }
         //更改订单表状态
         //Order::model()->updateAll(array('order_status'=>8),'update_at >=:begin_time and :end_time >=update_at and order_status in (3,4) and dpid=:dpid',array(':begin_time'=>$begin_time,':end_time'=>$end_time));
         $sqlorderup = "update nb_order set order_status=8 where dpid={$this->companyId} and update_at >='{$begin_time} 00:00:00' and update_at<='{$end_time} 23:59:59' and order_status in (4)";
         //var_dump($sqlorderup);exit;
         Yii::app()->db->createCommand($sqlorderup)->execute();
         $cmodel = CloseAccount::model()->find('lid=:lid and dpid=:dpid', array(':lid' => $clid, 'dpid' => $this->companyId));
         $cmodel->all_money = $totalMoney;
         $cmodel->update();
         ///////////////////////
         $pad = Pad::model()->with('printer')->find(' t.dpid=:dpid and t.lid=:lid', array(':dpid' => $this->companyId, 'lid' => $padid));
         //前面加 barcode
         $precode = "";
         $memo = "日结对账单";
         $ret = Helper::printCloseAccount($this->companyId, $models, $pad, $precode, "0", $memo);
         $transaction->commit();
         //提交事务会真正的执行数据库操作
         //echo 1;
     } catch (Exception $e) {
         $transaction->rollback();
         //如果操作失败, 数据回滚
         //echo 0;
         $ret = array('status' => false, 'msg' => "请重试!");
     }
     Yii::app()->end(json_encode($ret));
 }
コード例 #10
0
 public function actionPrintPadList()
 {
     $orderId = Yii::app()->request->getParam('orderId', 0);
     $companyId = Yii::app()->request->getParam('companyId');
     $padId = Yii::app()->request->getParam('padId');
     $order = Order::model()->with('company')->find('t.lid=:id and t.dpid=:dpid', array(':id' => $orderId, ':dpid' => $companyId));
     $pad = Pad::model()->with('printer')->find(' t.dpid=:dpid and t.lid=:lid', array(':dpid' => $order->dpid, 'lid' => $padId));
     //要判断打印机类型错误,必须是local。
     if ($pad->printer->printer_type != '1') {
         Yii::app()->end(json_encode(array('status' => false, 'jobid' => "0", 'type' => 'local', 'msg' => yii::t('app', '必须是本地打印机!'))));
     } else {
         //前面加 barcode
         $precode = "1D6B450B" . strtoupper(implode('', unpack('H*', 'A' . $order->lid))) . "0A" . strtoupper(implode('', unpack('H*', 'A' . $order->lid))) . "0A";
         Yii::app()->end(json_encode(Helper::printList($order, $pad, $precode)));
     }
 }