/** * * 生成座次号 */ public function actionCreateCode() { $id = Yii::app()->request->getParam('id'); $number = Yii::app()->request->getParam('number'); $model = SiteNo::model()->find('site_id=:siteId and company_id=:companyId and delete_flag=0', array(':siteId' => $id, ':companyId' => $this->companyId)); $model = $model ? $model : new SiteNo(); $code = rand(100000, 999999); $model->company_id = $this->companyId; $model->site_id = $id; $model->code = $code; $model->number = $number; $model->waiter_id = $this->waiterId; if ($model->save()) { echo $code; } else { echo 0; } Yii::app()->end(); }
public static function getHotsProduct($dpid = 0, $type = 1, $siteNoId = 0) { $command = Yii::app()->db; $siteId = 0; $siteNo = SiteNo::model()->find('lid=:lid', array(':lid' => $siteNoId)); if ($siteNo) { $siteId = $siteNo['site_id']; } switch ($type) { case 1: $sql = 'select t8.*,t9.order_id from (select t.price_discount,t.is_discount,t1.lid,t1.product_name, t1.original_price, t1.main_picture, t1.rank, t1.order_number, t1.favourite_number,0 as type from nb_product_discount t,nb_product t1 where t.product_id=t1.lid and t.dpid=:companyId and t1.status=0 and t1.delete_flag=0 and t1.is_show = 1 and t.is_set=0 and t.begin_time<:time and t.end_time>:time ' . ' union select t2.price_discount,t2.is_discount,t3.lid,t3.set_name as product_name, 0 as original_price, t3.main_picture, t3.rank, t3.order_number, t3.favourite_number,1 as type from nb_product_discount t2,nb_product_set t3 where t2.product_id=t3.lid and t2.dpid=:companyId and t3.status=0 and t3.delete_flag=0 and t2.is_set=1 and t2.begin_time<:time and t2.end_time>:time ' . ' union select t4.price,2 as is_discount,t5.lid,t5.product_name, t5.original_price, t5.main_picture, t5.rank, t5.order_number, t5.favourite_number,0 as type from nb_product_special t4,nb_product t5 where t4.product_id=t5.lid and t4.dpid=:companyId and t5.status=0 and t5.delete_flag=0 and t5.is_show = 1 and t4.is_set=0 and t4.begin_time<:time and t4.end_time>:time ' . ' union select t6.price,2 as is_discount,t7.lid,t7.product_name, t7.original_price, t7.main_picture, t7.rank, t7.order_number, t7.favourite_number,1 as type from nb_product_special t6,nb_product t7 where t6.product_id=t7.lid and t6.dpid=:companyId and t7.status=0 and t7.delete_flag=0 and t7.is_show = 1 and t6.is_set=1 and t6.begin_time<:time and t6.end_time>:time )t8 ' . ' LEFT JOIN (select order_id,product_id from nb_order_product t10 LEFT JOIN nb_order t11 on t10.order_id=t11.lid where t11.site_id=:siteId and t10.delete_flag=0 and t10.product_order_status=0 )t9 on t8.lid=t9.product_id '; break; case 2: $sql = 'select t.*,t1.order_id from (select lid , product_name, sum(price) as original_price, main_picture, rank, order_number, favourite_number, type from(select n.lid,n.set_name as product_name, n.main_picture, n.rank, n.order_number, n.favourite_number, n1.price,1 as type from nb_product_set n LEFT JOIN nb_product_set_detail n1 on n.lid=n1.set_id where n.dpid=:companyId and n1.dpid=:companyId and n.delete_flag=0 and n1.delete_flag=0 and n1.is_select=1)m group by lid)t' . ' LEFT JOIN (select order_id,product_id from nb_order_product t2 LEFT JOIN nb_order t3 on t2.order_id=t3.lid where t3.site_id=:siteId and t2.delete_flag=0 and t2.product_order_status=0 )t1 on t.lid=t1.product_id'; break; case 3: $sql = 'select t.*,t1.order_id from ' . ' (select lid,product_name, original_price, main_picture, rank, order_number, favourite_number,0 as type from nb_product where dpid=:companyId and status=0 and delete_flag=0 and is_show = 1 ' . 'union select lid , product_name, sum(price) as original_price, main_picture, rank, order_number, favourite_number, type from(select n.lid,n.set_name as product_name, n.main_picture, n.rank, n.order_number, n.favourite_number, n1.price,1 as type from nb_product_set n LEFT JOIN nb_product_set_detail n1 on n.lid=n1.set_id where n.dpid=:companyId and n1.dpid=:companyId and n.delete_flag=0 and n1.delete_flag=0 and n1.is_select=1)m group by lid)t ' . ' LEFT JOIN (select order_id,product_id from nb_order_product t2 LEFT JOIN nb_order t3 on t2.order_id=t3.lid where t3.site_id=:siteId and t2.delete_flag=0 and t2.product_order_status=0 )t1 on t.lid=t1.product_id order by favourite_number desc limit 10'; break; case 4: $sql = 'select t.*,t1.order_id from ' . ' (select lid,product_name, original_price, main_picture, rank, order_number, favourite_number,0 as type from nb_product where dpid=:companyId and status=0 and delete_flag=0 and is_show = 1 ' . 'union select lid , product_name, sum(price) as original_price, main_picture, rank, order_number, favourite_number, type from(select n.lid,n.set_name as product_name, n.main_picture, n.rank, n.order_number, n.favourite_number, n1.price,1 as type from nb_product_set n LEFT JOIN nb_product_set_detail n1 on n.lid=n1.set_id where n.dpid=:companyId and n1.dpid=:companyId and n.delete_flag=0 and n1.delete_flag=0 and n1.is_select=1)m group by lid)t ' . 'LEFT JOIN (select order_id,product_id from nb_order_product t2 LEFT JOIN nb_order t3 on t2.order_id=t3.lid where t3.site_id=:siteId and t2.delete_flag=0 and t2.product_order_status=0 )t1 on t.lid=t1.product_id order by order_number desc limit 10'; break; } $conn = $command->createCommand($sql); $conn->bindValue(':companyId', $dpid); $conn->bindValue(':siteId', $siteId); if ($type == 1) { $conn->bindValue(':time', date('Y-m-d H:i:s', time())); } $result = $conn->queryAll(); return $result; }
public function actionPrintOneKitchen() { $orderProductId = Yii::app()->request->getParam('orderProductId', 0); $companyId = Yii::app()->request->getParam('companyId'); $typeId = Yii::app()->request->getParam('typeId', 0); Until::validOperate($companyId, $this); $db = Yii::app()->db; //var_dump(Yii::app()->params->has_cache);exit; //$transaction = $db->beginTransaction(); try { $orderProduct = OrderProduct::model()->with('product')->find('t.lid=:id and t.dpid=:dpid and t.delete_flag=0', array(':id' => $orderProductId, ':dpid' => $companyId)); $order = Order::model()->with('company')->find('t.lid=:id and t.dpid=:dpid', array(':id' => $orderProduct->order_id, ':dpid' => $companyId)); $criteria = new CDbCriteria(); $criteria->condition = 't.status in ("1","2","3") and t.dpid=' . $order->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); if ($siteNo->is_temp == '0') { $site = Site::model()->with('siteType')->find('t.lid=:lid and t.dpid=:dpid', array(':lid' => $order->site_id, ':dpid' => $order->dpid)); } else { $site = new Site(); } if ($orderProduct->is_print == '0') { $reprint = false; } else { $reprint = true; } $ret = Helper::printKitchen($order, $orderProduct, $site, $siteNo, $reprint); // if($orderProduct->is_print=='0') // { // $orderProduct->is_print='1'; // $orderProduct->save(); // } //$transaction->commit(); //$ret=array('status'=>true,'jobid'=>"",'type'=>'none','msg'=>'发生异常'); } catch (Exception $e) { //$transaction->rollback(); //如果操作失败, 数据回滚 //var_dump($e);exit; $ret = array('status' => false, 'jobid' => "0", 'type' => 'none', 'msg' => yii::t('app', '发生异常')); //Yii::app()->end(json_encode($ret)); } //var_dump($ret);exit; $this->renderPartial('printresultone', array('orderId' => $order->lid, 'orderProductId' => $orderProductId, 'ret' => $ret, 'typeId' => $typeId)); }
public function actionPay() { $id = Yii::app()->request->getParam('id'); $order = Order::model()->find('order_id=:id', array(':id' => $id)); $siteNo = SiteNo::model()->find('id=:id', array(':id' => $order->site_no_id)); $order->order_status = 1; $order->pay_time = time(); $siteNo->delete_flag = 1; if ($order->save() && $siteNo->save()) { echo json_encode(array('status' => true, 'siteId' => $siteNo->site_id)); } else { echo json_encode(array('status' => false)); } exit; }
public function actionOrderList() { $isCode = 0; $orderId = 0; $seatnum = Yii::app()->request->getParam('code'); if ($seatnum != $this->seatNum) { $isCodeModel = SiteNo::model()->find('code=:code and delete_flag=0', array(':code' => $seatnum)); //判断是否是正式开台号 if ($isCodeModel) { $isCode = 1; $this->seatNum = $seatnum; } } else { //输入的和开台号相等 判断是否是真的座次号(可能输入临时的座次号) $isCodeModel = SiteNo::model()->find('code=:code and delete_flag=0', array(':code' => $seatnum)); //判断是否是正式开台号 if ($isCodeModel) { $isCode = 1; $this->seatNum = $seatnum; } } $model = Order::model()->with('siteNo')->find('t.order_status=0 and t.company_id=:companyId and code=:code and delete_flag=0', array(':code' => $this->seatNum, ':companyId' => $this->companyId)); if ($model) { $orderId = $model->order_id; } $time = $model ? $model->create_time : 0; $orderProducts = OrderProduct::getOrderProducts($orderId); $totalPrice = OrderProduct::getTotal($orderId); if ($model) { $priceInfo = Helper::calOrderConsume($model, $totalPrice); } else { if ($isCodeModel) { $priceInfo = Helper::lowConsumeInfo($isCodeModel->site_id); } } $this->render('orderlist', array('id' => $orderId, 'orderProducts' => $orderProducts, 'totalPrice' => $priceInfo, 'time' => $time, 'seatNum' => $this->seatNum, 'cid' => $this->companyId)); }
public static function getSiteStatus($siteId, $dpid, $istemp) { if ($istemp == 0) { $criteria1 = new CDbCriteria(); $criteria1->condition = ' t.dpid=' . $dpid . ' and t.lid=' . $siteId; $site = Site::model()->find($criteria1); if (!empty($site)) { $status = $site->status; } else { $status = 0; } } else { $criteria2 = new CDbCriteria(); $criteria2->condition = 't.status in ("1","2","3") and t.dpid=' . $dpid . ' and t.site_id=' . $siteId . ' and t.is_temp=' . $istemp; //$criteria2->condition = 't.status in ("9") and t.dpid='.$companyId.' and t.site_id='.$sid.' and t.is_temp='.$istemp ; $criteria2->order = ' t.lid desc '; $siteNo = SiteNo::model()->find($criteria2); if (!empty($siteNo)) { $status = $siteNo->status; } else { $status = 0; } } return $status; }
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' => ''); } }
public function actionUnionsite() { if (Yii::app()->request->isPostRequest) { $sid = Yii::app()->request->getPost('sid'); $companyId = Yii::app()->request->getPost('companyId'); $istemp = Yii::app()->request->getPost('istemp', '0'); $ssid = Yii::app()->request->getPost('ssid', 0); $sistemp = Yii::app()->request->getPost('sistemp', '0'); Until::validOperate($companyId, $this); //echo json_encode(array('status'=>0,'message'=>$sid.'dd'.$companyId.'dd'.$istemp.'dd'.$ssid.'dd'.$sistemp));exit; $db = Yii::app()->db; $transaction = $db->beginTransaction(); try { $number = 0; $status = '1'; $smodelsn = SiteNo::model()->find('dpid=:companyId and delete_flag=0 and site_id=:lid and is_temp=:istemp and status in ("1","2")', array(':companyId' => $companyId, ':lid' => $ssid, ':istemp' => $sistemp)); if ($sistemp == '0') { $smodel = Site::model()->find('dpid=:companyId and delete_flag=0 and lid=:lid', array(':companyId' => $companyId, ':lid' => $ssid)); $number = $smodel->number; $status = $smodel->status; } else { $number = $smodelsn->number; $status = $smodelsn->status; } //echo json_encode(array('status'=>0,'message'=>$number.'dd'.$status));exit; if ($istemp == "0") { $sqlsite = "update nb_site set status=IF(:sstatus>status,:sstatus,status),number=number+:snumber where lid=:sid and dpid=:companyId"; $commandsite = $db->createCommand($sqlsite); $commandsite->bindValue(":snumber", $number); $commandsite->bindValue(":sstatus", $status); $commandsite->bindValue(":sid", $sid); $commandsite->bindValue(":companyId", $companyId); $commandsite->execute(); } if ($sistemp == "0") { $sqlsite = "update nb_site set status='5' where lid=:sid and dpid=:companyId"; $commandsite = $db->createCommand($sqlsite); $commandsite->bindValue(":sid", $ssid); $commandsite->bindValue(":companyId", $companyId); $commandsite->execute(); } //echo json_encode(array('status'=>0,'message'=>$number.'dd'.$status));exit; //更新目标site_no人数和状态 $modelsn = SiteNo::model()->find('dpid=:companyId and delete_flag=0 and site_id=:lid and is_temp=:istemp and status in ("1","2")', array(':companyId' => $companyId, ':lid' => $sid, ':istemp' => $istemp)); if ($status > $modelsn->status) { $modelsn->status = $status; } $modelsn->number = $modelsn->number + $number; $modelsn->save(); //echo json_encode(array('status'=>0,'message'=>$number.'dd'.$status));exit; //更新源site_no,让上网密码code 指向目标订单 $smodelsn->status = '5'; $smodelsn->site_id = $modelsn->site_id; $smodelsn->is_temp = $modelsn->is_temp; $smodelsn->save(); //echo json_encode(array('status'=>0,'message'=>$number.'dd'.$status));exit; //更新目标订单状态和人数 $tocriteria = new CDbCriteria(); $tocriteria->condition = ' t.order_status in ("1","2") and t.dpid=' . $companyId . ' and t.site_id=' . $sid . ' and t.is_temp=' . $istemp; $tocriteria->order = ' t.lid desc '; $torder = Order::model()->find($tocriteria); if (empty($torder)) { //新生成订单 $torder = new Order(); $se = new Sequence("order"); $torder->lid = $se->nextval(); $torder->dpid = $companyId; $torder->username = Yii::app()->user->name; $torder->create_at = date('Y-m-d H:i:s', time()); $torder->lock_status = '0'; $torder->site_id = $sid; $torder->is_temp = $istemp; $torder->order_status = $status; $torder->number = $modelsn->number + $number; $torder->save(); } else { if ($status > $torder->order_status) { $torder->order_status = $status; } $torder->number = $torder->number + $number; $torder->save(); } //echo json_encode(array('status'=>0,'message'=>$number.'dd'.$status));exit; //... //更新源订单状态 $socriteria = new CDbCriteria(); $socriteria->condition = ' t.order_status in ("1","2") and t.dpid=' . $companyId . ' and t.site_id=' . $ssid . ' and t.is_temp=' . $sistemp; $socriteria->order = ' t.lid desc '; $sorder = Order::model()->find($socriteria); if (!empty($sorder)) { $sorder->order_status = "5"; $sorder->save(); } //echo json_encode(array('status'=>0,'message'=>$number.'dd'.$status));exit; //... //更新源订单明细,指向目标订单。 if (!empty($sorder)) { $sqlorder = "update nb_order_product set order_id=:torderid where dpid=:companyId and order_id=:sorderid"; $commandorder = $db->createCommand($sqlorder); $commandorder->bindValue(":torderid", $torder->lid); $commandorder->bindValue(":sorderid", $sorder->lid); $commandorder->bindValue(":companyId", $companyId); $commandorder->execute(); } //echo json_encode(array('status'=>0,'message'=>$number.'dd'.$status));exit; // $sqlorder="update nb_order set is_temp=:istemp,site_id=:sid where site_id=:ssid and is_temp=:sistemp and dpid=:companyId and order_status in ('1','2','3')"; // $commandorder=$db->createCommand($sqlorder); // $commandorder->bindValue(":sid" , $sid); // $commandorder->bindValue(":istemp" , $istemp); // $commandorder->bindValue(":ssid" , $ssid); // $commandorder->bindValue(":sistemp" , $sistemp); // $commandorder->bindValue(":companyId" , $companyId); // $commandorder->execute(); $transaction->commit(); //提交事务会真正的执行数据库操作 echo json_encode(array('status' => 1, 'message' => yii::t('app', '并台成功'))); return true; } catch (Exception $e) { $transaction->rollback(); //如果操作失败, 数据回滚 echo json_encode(array('status' => 0, 'message' => yii::t('app', '并台失败'))); //echo json_encode(array('status'=>0,'message'=> var_dump($e))); return false; } } }
public function actionGetsiteStatus() { Yii::app()->language = 'zh_cn'; $sid = Yii::app()->request->getParam('sid', '0'); $companyId = Yii::app()->request->getParam('companyId', '0'); $istemp = Yii::app()->request->getParam('istemp', '0'); $status = 0; if ($istemp == "0") { $criteria1 = new CDbCriteria(); $criteria1->condition = ' t.dpid=' . $companyId . ' and t.lid=' . $sid; $site = Site::model()->find($criteria1); if (empty($site)) { $status = $site->status; } else { $status = "0"; } } else { $criteria2 = new CDbCriteria(); $criteria2->condition = 't.status in ("1","2","3") and t.dpid=' . $companyId . ' and t.site_id=' . $sid . ' and t.is_temp=' . $istemp; //$criteria2->condition = 't.status in ("9") and t.dpid='.$companyId.' and t.site_id='.$sid.' and t.is_temp='.$istemp ; $criteria2->order = ' t.lid desc '; $siteNo = SiteNo::model()->find($criteria2); //var_dump($siteNo);exit; //if (empty($siteNo)) echo 'a';exit; if (empty($siteNo)) { $status = $siteNo->status; } else { $status = "0"; } } Yii::app()->end(json_encode(array("status" => $status))); }