/** * 被下单、加菜、在线支付、信息反馈等调用 * 对应的cmd分别是XD、JC、ZXZF、XXFK * data的格式按照接口文档封装 */ protected function saveMsg($cmd, $data) { $db = Yii::app()->db; $se = new Sequence("data_sync"); $this->lid = $se->nextval(); $sql = 'insert into nb_data_sync(lid,dpid,cmd_code,cmd_data,create_at,is_interface,sync_result) values(:lid,:dpid,:cmd_code,:cmd_data,sysdate(),:is_interface,:sync_result)'; $command = $db->createCommand($sql); $command->bindValue(":lid", $this->lid); $command->bindValue(":dpid", $this->dpid); $command->bindValue(":cmd_code", $cmd); $command->bindValue(":cmd_data", $data); $command->bindValue(":is_interface", '1'); $command->bindValue(":sync_result", '0'); $command->execute(); /*$ds=new DataSync; $se=new Sequence("data_sync"); $this->lid = $se->nextval(); $ds->dpid = $this->dpid; $ds->lid = $this->lid; $ds->cmd_code = $cmd; $ds->cmd_data =$data; $ds->create_at = date('y-m-d h:i:s',time()); $ds->is_interface = '1'; $ds->sync_result = '0'; $ds->save();*/ }
public function actionCreate() { $model = new Product(); $model->dpid = $this->companyId; //$model->create_time = time(); if (Yii::app()->request->isPostRequest) { $model->attributes = Yii::app()->request->getPost('Product'); $se = new Sequence("product"); $model->lid = $se->nextval(); $model->create_at = date('Y-m-d H:i:s', time()); $model->update_at = date('Y-m-d H:i:s', time()); $model->delete_flag = '0'; $py = new Pinyin(); $model->simple_code = $py->py($model->product_name); //var_dump($model);exit; if ($model->save()) { Yii::app()->user->setFlash('success', yii::t('app', '添加成功!')); $this->redirect(array('product/index', 'companyId' => $this->companyId)); } } $categories = $this->getCategoryList(); //$departments = $this->getDepartments(); //echo 'ss';exit; $this->render('create', array('model' => $model, 'categories' => $categories)); }
public function actionCreate() { $typeId = Yii::app()->request->getParam('typeId', 0); $model = new Site(); $model->dpid = $this->companyId; $model->type_id = $typeId; if (Yii::app()->request->isPostRequest) { $model->attributes = Yii::app()->request->getPost('Site'); $se = new Sequence("site"); $model->lid = $se->nextval(); $model->create_at = date('Y-m-d H:i:s', time()); $model->update_at = date('Y-m-d H:i:s', time()); $model->delete_flag = '0'; //var_dump($model);exit; if ($model->save()) { Yii::app()->user->setFlash('success', yii::t('app', '添加成功')); $this->redirect(array('site/index', 'typeId' => $typeId, 'companyId' => $this->companyId)); } } $types = $this->getTypes(); $floors = $this->getFloors(); $sitepersons = $this->getSitePersons(); //var_dump($floors); //var_dump($types);exit; $this->render('create', array('model' => $model, 'types' => $types, 'floors' => $floors, 'sitepersons' => $sitepersons)); }
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)); }
public function actionCreate() { $model = new ProductAddition(); $model->dpid = $this->companyId; $pslid = Yii::app()->request->getParam('psid'); $model->mproduct_id = $pslid; if (Yii::app()->request->isPostRequest) { $model->attributes = Yii::app()->request->getPost('ProductAddition'); //var_dump($model->attributes);exit; $se = new Sequence("product_addition"); $model->lid = $se->nextval(); $model->create_at = date('Y-m-d H:i:s', time()); $model->update_at = date('Y-m-d H:i:s', time()); $model->delete_flag = '0'; //var_dump($model);exit; if ($model->save()) { Yii::app()->user->setFlash('success', yii::t('app', '添加成功')); $this->redirect(array('productAddition/detail', 'companyId' => $this->companyId, 'lid' => $model->mproduct_id)); } } $categories = $this->getCategories(); $categoryId = 0; $products = $this->getProducts($categoryId); $productslist = CHtml::listData($products, 'lid', 'product_name'); $this->render('detailcreate', array('model' => $model, 'categories' => $categories, 'categoryId' => $categoryId, 'products' => $productslist)); }
public function saveCmd($cmd) { //$ds=new DataSync(); $db = Yii::app()->db; $se = new Sequence("data_sync"); $this->lid = $se->nextval(); $sql = 'insert into nb_data_sync(lid,dpid,cmd_code,cmd_data,create_at,is_interface,sync_result) values(:lid,:dpid,:cmd_code,:cmd_data,sysdate(),:is_interface,:sync_result)'; $command = $db->createCommand($sql); $command->bindValue(":lid", $this->lid); $command->bindValue(":dpid", $this->dpid); $command->bindValue(":cmd_code", $cmd); $command->bindValue(":cmd_data", ''); $command->bindValue(":is_interface", '1'); $command->bindValue(":sync_result", '0'); $command->execute(); /* $ds->dpid = $this->dpid; $ds->lid = $this->lid; $ds->cmd_code = $cmd; $ds->cmd_data = ''; $ds->create_at = date('y-m-d h:i:s',time()); $ds->is_interface = '1'; $ds->sync_result = '0'; //var_dump($ds); if(!$ds->save()) { var_dump($ds->getErrors()); echo 'insert error!!!!'; }*/ }
public function actionCreate() { $model = new SitePersons(); $model->dpid = $this->companyId; if (Yii::app()->request->isPostRequest) { $model->attributes = Yii::app()->request->getPost('SitePersons'); $se = new Sequence("site_type"); $model->lid = $se->nextval(); $model->create_at = date('Y-m-d H:i:s', time()); $model->update_at = date('Y-m-d H:i:s', time()); //var_dump($model);exit; if ($model->save()) { Yii::app()->user->setFlash('success', yii::t('app', '添加成功')); $this->redirect(array('sitePersons/index', 'companyId' => $this->companyId)); } } $this->render('create', array('model' => $model)); }
public function actionCreate() { $model = new Printer(); $model->dpid = $this->companyId; if (Yii::app()->request->isPostRequest) { $model->attributes = Yii::app()->request->getPost('Printer'); $se = new Sequence("printer"); $model->lid = $se->nextval(); $model->create_at = date('Y-m-d H:i:s', time()); $model->update_at = date('Y-m-d H:i:s', time()); $model->delete_flag = '0'; if ($model->save()) { Yii::app()->user->setFlash('success', yii::t('app', '添加成功')); $this->redirect(array('printer/index', 'companyId' => $this->companyId)); } } $this->render('create', array('model' => $model)); }
public function actionCreate() { $companyId = Helper::getCompanyId(Yii::app()->request->getParam('companyId')); $model = new CompanyWifi(); $model->dpid = $companyId; if (Yii::app()->request->isPostRequest) { $model->attributes = Yii::app()->request->getPost('CompanyWifi'); $se = new Sequence("company_wifi"); $model->lid = $se->nextval(); $model->create_at = date('Y-m-d H:i:s'); $model->update_at = date('Y-m-d H:i:s'); if ($model->save()) { Yii::app()->user->setFlash('success', yii::t('app', '添加成功')); $this->redirect(array('companyWifi/index', 'companyId' => $companyId)); } } $this->render('create', array('model' => $model)); }
public function actionCreate() { $companyId = Helper::getCompanyId(Yii::app()->request->getParam('companyId')); $model = new PaymentMethod(); $model->dpid = $companyId; if (Yii::app()->request->isPostRequest) { $model->attributes = Yii::app()->request->getPost('PaymentMethod'); $se = new Sequence("payment_method"); $model->lid = $se->nextval(); $model->create_at = date('Y-m-d H:i:s'); $model->update_at = date('Y-m-d H:i:s', time()); // var_dump($model->attributes);exit; if ($model->save()) { Yii::app()->user->setFlash('success', yii::t('app', '添加成功')); $this->redirect(array('payMethod/index', 'companyId' => $companyId)); } } $this->render('create', array('model' => $model)); }
public function actionCreate() { $allflag = Yii::app()->request->getParam('allflag', 0); $model = new Feedback(); $model->dpid = $this->companyId; if (Yii::app()->request->isPostRequest) { $model->attributes = Yii::app()->request->getPost('Feedback'); $se = new Sequence("feedback"); $model->lid = $se->nextval(); $model->allflag = $allflag; $model->create_at = date('Y-m-d H:i:s', time()); $model->update_at = date('Y-m-d H:i:s', time()); $model->delete_flag = '0'; //var_dump($model);exit; if ($model->save()) { Yii::app()->user->setFlash('success', yii::t('app', '添加成功')); $this->redirect(array('feedback/index', 'companyId' => $this->companyId, 'allflag' => $allflag)); } } $this->render('create', array('model' => $model, 'allflag' => $allflag)); }
public function actionCreate() { $this->layout = '/layouts/main_picture'; $pid = Yii::app()->request->getParam('pid', 0); $model = new ProductCategory(); $model->dpid = $this->companyId; if ($pid) { $model->pid = $pid; } if (Yii::app()->request->isPostRequest) { $model->attributes = Yii::app()->request->getPost('ProductCategory'); $category = ProductCategory::model()->find('dpid=:dpid and category_name=:name and delete_flag=0', array(':dpid' => $this->companyId, ':name' => $model->category_name)); if ($category) { $this->redirect(array('productCategory/index', 'id' => $category->lid, 'companyId' => $this->companyId)); } $se = new Sequence("product_category"); $model->lid = $se->nextval(); $model->create_at = date('Y-m-d H:i:s', time()); $model->delete_flag = '0'; $model->update_at = date('Y-m-d H:i:s', time()); if ($model->save()) { //var_dump($model);exit; $self = ProductCategory::model()->find('lid=:pid and dpid=:dpid', array(':pid' => $model->lid, ':dpid' => $this->companyId)); if ($self->pid != '0') { $parent = ProductCategory::model()->find('lid=:pid and dpid=:dpid', array(':pid' => $model->pid, ':dpid' => $this->companyId)); $self->tree = $parent->tree . ',' . $self->lid; } else { $self->tree = '0,' . $self->lid; } //var_dump($model);exit; $self->update(); Yii::app()->user->setFlash('success', yii::t('app', '添加成功')); $this->redirect(array('productCategory/index', 'id' => $self->lid, 'companyId' => $this->companyId)); } else { Yii::app()->user->setFlash('error', yii::t('app', '添加失败')); $this->redirect(array('productCategory/index', 'companyId' => $this->companyId)); } } $this->render('_form1', array('model' => $model, 'action' => $this->createUrl('productCategory/create', array('companyId' => $this->companyId)))); }
public function actionCreate() { $productId = Yii::app()->request->getParam('productId'); $model = new ProductDiscount(); $model->dpid = $this->companyId; $product = Product::model()->find('lid=:lid and dpid=:dpid and delete_flag=0', array(':lid' => $productId, ':dpid' => $this->companyId)); // $productSets = ProductSet::model()->findAll('dpid=:dpid and delete_flag=0 and is_discount=1 and status=0',array(':dpid'=>$this->companyId)); if (Yii::app()->request->isPostRequest) { $postData = Yii::app()->request->getPost('ProductDiscount'); $model->attributes = $postData; $se = new Sequence("retreat"); $model->lid = $se->nextval(); $model->create_at = date('Y-m-d H:i:s', time()); $model->update_at = date('Y-m-d H:i:s', time()); if ($model->save()) { Yii::app()->user->setFlash('success', yii::t('app', '添加成功')); $this->redirect(array('productSales/updatedetail', 'companyId' => $this->companyId, 'id' => $productId)); } } // var_dump($products);exit; $this->render('create', array('model' => $model, 'product' => $product)); }
public function save() { if ($this->lid) { $model = User::model()->find('lid=:id', array(':id' => $this->lid)); } else { $model = new User(); $se = new Sequence("user"); $model->lid = $se->nextval(); $model->create_at = date('Y-m-d H:i:s', time()); $model->delete_flag = '0'; //$model->lid = $this->getPkValue(); } $model->username = $this->username; $model->mobile = $this->mobile; $model->staff_no = $this->staff_no; $model->email = $this->email; $model->role = $this->role; $model->dpid = $this->dpid; $model->status = 1; if ($this->password_old != $this->password) { $model->password_hash = $this->password; } if ($model->validate()) { if ($this->password_old != $this->password) { $model->password_hash = Helper::genPassword($this->password); } //var_dump($model);exit; $model->save(); return true; } else { $this->addErrors($model->getErrors()); if ($passwordError = $model->getError('password_hash')) { $this->addError('password', $passwordError); } return false; } }
public function actionCharge() { $model = new MemberRecharge(); $model->dpid = $this->companyId; //Until::validOperate($model->dpid, $this); if (Yii::app()->request->isPostRequest) { $model->attributes = Yii::app()->request->getPost('MemberRecharge'); $rfid = Yii::app()->request->getPost('rfid'); $transaction = Yii::app()->db->beginTransaction(); try { $member = MemberCard::model()->find('rfid=:rfid and selfcode=:selfcode and dpid=:dpid', array(':rfid' => $rfid, ':selfcode' => $model->member_card_id, ':dpid' => $this->companyId)); Until::validOperate($member->lid, $this); //var_dump($member);exit; $member->all_money = $member->all_money + $model->reality_money + $model->give_money; $se = new Sequence("member_recharge"); $model->lid = $se->nextval(); $model->update_at = date('Y-m-d H:i:s', time()); $model->create_at = date('Y-m-d H:i:s', time()); $model->delete_flag = '0'; if ($model->save() && $member->update()) { $transaction->commit(); Yii::app()->user->setFlash('success', yii::t('app', '充值成功')); } else { $transaction->rollback(); Yii::app()->user->setFlash('error', yii::t('app', '充值失败')); } } catch (Exception $e) { Yii::app()->user->setFlash('error', yii::t('app', '充值失败')); $transaction->rollback(); } $this->redirect(array('member/index', 'companyId' => $this->companyId)); } $this->renderPartial('charge', array('model' => $model)); }
public static function openSite($companyId = 0, $siteNumber = 1, $istemp = 1, $sid = 0) { $db = Yii::app()->db; //return array('status'=>0,'msg'=>yii::t('app','开台失败122'),'siteid'=>"111"); $transaction = $db->beginTransaction(); try { if ($istemp == "0") { $sqlsite = "update nb_site set status=1,number=:number where lid=:sid and dpid=:companyId"; $commandsite = $db->createCommand($sqlsite); $commandsite->bindValue(":number", $siteNumber); $commandsite->bindValue(":sid", $sid); $commandsite->bindValue(":companyId", $companyId); $commandsite->execute(); } $se = new Sequence("site_no"); $lid = $se->nextval(); $site_id = $sid; if ($istemp != 0) { $se = new Sequence("temp_site"); $site_id = $se->nextval(); } //return array('status'=>0,'message'=>"dddddd22",'siteid'=>$sid); ///开台之前删除可能产生的脏数据 $sqlsiteno = "update nb_site_no set status='7' where site_id=:sid and is_temp=:istemp and dpid=:companyId and status in ('1','2')"; $commandsiteno = $db->createCommand($sqlsiteno); $commandsiteno->bindValue(":sid", $sid); $commandsiteno->bindValue(":istemp", $istemp); $commandsiteno->bindValue(":companyId", $companyId); $commandsiteno->execute(); ///// $code = "0000"; //SiteClass::getCode($companyId); $data = array('lid' => $lid, 'dpid' => $companyId, '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' => '1', 'code' => $code, 'number' => $siteNumber, 'delete_flag' => '0'); $db->createCommand()->insert('nb_site_no', $data); ///***********insert to order feedback // $sef=new Sequence("order_feedback"); // $lidf = $sef->nextval(); // $dataf = array( // 'lid'=>$lidf, // 'dpid'=>$companyId, // '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'=>'开台', // 'delete_flag'=>'0' // ); // $db->createCommand()->insert('nb_order_feedback',$dataf); ///*************print $transaction->commit(); //提交事务会真正的执行数据库操作 return array('status' => 1, 'msg' => yii::t('app', '开台成功'), 'siteid' => $site_id); //return true; } catch (Exception $e) { $transaction->rollback(); //如果操作失败, 数据回滚 return array('status' => 0, 'msg' => yii::t('app', '开台失败'), 'siteid' => $site_id); //return false; } }
public function actionDetailCreate() { $model = new PrinterWayDetail(); $model->dpid = $this->companyId; $pwlid = Yii::app()->request->getParam('pwid'); $model->print_way_id = $pwlid; if (Yii::app()->request->isPostRequest) { $model->attributes = Yii::app()->request->getPost('PrinterWayDetail'); $se = new Sequence("print_way_detail"); $model->lid = $se->nextval(); $model->create_at = date('Y-m-d H:i:s', time()); $model->delete_flag = '0'; $model->update_at = date('Y-m-d H:i:s', time()); if ($model->save()) { Yii::app()->user->setFlash('success', yii::t('app', '添加成功')); $this->redirect(array('printerWay/detailindex', 'companyId' => $this->companyId, 'lid' => $model->print_way_id)); } } $printers = $this->getPrinters(); $floors = $this->getFloors(); $this->render('detailcreate', array('model' => $model, 'printers' => $printers, 'floors' => $floors)); }
public static function saveProductTaste($dpid, $productId, $tastesIds = array()) { $transaction = Yii::app()->db->beginTransaction(); try { $sql = 'delete from nb_product_taste where dpid=:dpid and product_id=:productId'; $conn = Yii::app()->db->createCommand($sql); $conn->bindValue(':dpid', $dpid); $conn->bindValue(':productId', $productId); $conn->execute(); if (!empty($tastesIds)) { foreach ($tastesIds as $taste) { // $sql = 'SELECT NEXTVAL("product_taste") AS id'; // $maxId = Yii::app()->db->createCommand($sql)->queryRow(); $se = new Sequence("product_taste"); $lid = $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()), 'taste_group_id' => $taste, 'product_id' => $productId); Yii::app()->db->createCommand()->insert('nb_product_taste', $data); } } $transaction->commit(); //提交事务会真正的执行数据库操作 return true; } catch (Exception $e) { $transaction->rollback(); //如果操作失败, 数据回滚 return false; } }
public static function printConetent2(Printer $printer, $contents, $precode, $sufcode, $printserver, $orderid) { Gateway::getOnlineStatus(); $store = Store::instance('wymenu'); $contentCode = ""; $contentCodeAll = ""; foreach ($contents as $content) { //内容编码 if ($printer->language == '1') { foreach ($content as $line) { //$strcontent=mb_convert_encoding($line,"GBK","UTF-8"); //$contentCode.=strtoupper(implode('',unpack('H*', $strcontent)))."0A"; $strcontent = mb_convert_encoding(substr($line, 2), "GBK", "UTF-8"); $strfontsize = substr($line, 0, 2); if ($strfontsize == "br") { $contentCode .= "0A"; } else { $contentCode .= "1D21" . $strfontsize . strtoupper(implode('', unpack('H*', $strcontent))); } } } elseif ($printer->language == '2') { $contentCode .= "1C43011C26"; //日文前导符号 foreach ($content as $line) { //$strcontent=mb_convert_encoding($line,"SJIS","UTF-8"); //$contentCode.=strtoupper(implode('',unpack('H*', $strcontent)))."0A"; $strcontent = mb_convert_encoding(substr($line, 2), "SJIS", "UTF-8"); $strfontsize = substr($line, 0, 2); if ($strfontsize == "br") { $contentCode .= "0A"; } else { $contentCode .= "1D21" . $strfontsize . strtoupper(implode('', unpack('H*', $strcontent))); } } } else { return array('status' => false, 'dpid' => $printer->dpid, 'jobid' => '0', 'type' => 'none', 'msg' => yii::t('app', '无法确定打印机语言!')); } //加barcode和切纸 $contentCode = $precode . $contentCode . $sufcode; $contentCodeAll = $contentCodeAll . $contentCode; $contentCode = ""; } //任务构建 $se = new Sequence("printer_job_id"); $jobid = $se->nextval(); if ($printserver == '1') { if ($printer->printer_type != '0') { return array('status' => false, 'dpid' => $printer->dpid, 'jobid' => '0', 'type' => 'net', 'msg' => yii::t('app', '网络打印的打印机必须是网络打印机!')); } $print_data = array("do_id" => "ipPrintContent", "company_id" => $printer->dpid, "job_id" => $jobid, "printer" => $printer->address, "content" => $contentCode); //$store = Store::instance('wymenu'); //echo 'ss';exit; $clientId = $store->get("client_" . $printer->dpid); //var_dump($clientId,$print_data);exit; if (!empty($clientId)) { Gateway::sendToClient($clientId, json_encode($print_data)); //Gateway::sendToAll(json_encode($print_data)); return array('status' => true, 'dpid' => $printer->dpid, 'jobid' => $jobid, 'type' => 'net', 'msg' => ''); } else { return array('status' => false, 'dpid' => $printer->dpid, 'jobid' => '0', 'type' => 'net', 'msg' => yii::t('app', '打印服务器找不到!')); } /////////////////// ///打印任务不再发送,返回job编号,有pad自己去取 } else { //主动的同步打印 0 // if($printer->printer_type=='1')//local // { // //$ret = $store->set($companyId."_".$jobid,'1C43011C2688A488A482AE82AF82B182F182C982BF82CD0A0A0A0A0A0A1D5601',0,60); // $store->set($printer->dpid."_".$jobid,$contentCode,0,120);//should 120测试1200 // return array('status'=>true,'dpid'=>$printer->dpid,'jobid'=>$jobid,'type'=>'local','msg'=>''); // }else{ $seorderprintjobs = new Sequence("order_printjobs"); $orderjobId = $seorderprintjobs->nextval(); $time = date('Y-m-d H:i:s', time()); //插入一条 $orderPrintJob = array('lid' => $orderjobId, 'dpid' => $printer->dpid, 'create_at' => $time, 'orderid' => $orderid, 'jobid' => $jobid, 'update_at' => $time, 'address' => $printer->address, 'content' => $contentCodeAll, 'printer_type' => "0", 'finish_flag' => '0', 'delete_flag' => '0'); Yii::app()->db->createCommand()->insert('nb_order_printjobs', $orderPrintJob); $store->set($printer->dpid . "_" . $jobid, $contentCodeAll, 0, 30); //should 120测试1200 return array('status' => true, 'dpid' => $printer->dpid, 'jobid' => $jobid, 'type' => 'net', 'address' => $printer->address, 'msg' => ''); // } } }
public function actionShiftlogout() { $companyId = Yii::app()->request->getParam('companyId'); $begin_time = Yii::app()->request->getParam('begin_time', '0000-00-00 00:00:00'); $save = Yii::app()->request->getParam('save', "0"); $db = Yii::app()->db; $userarr = explode("_", Yii::app()->user->userId); $sqllogintime = 'select create_at from nb_b_login where out_time="0000-00-00 00:00:00" and user_id =' . $userarr[0] . ' and dpid="' . $userarr[1] . '" order by create_at'; $logintime = $db->createCommand($sqllogintime)->queryAll(); if (empty($logintime)) { Yii::app()->user->logout(); //$this->redirect('index'); } if ($begin_time = "0000-00-00 00:00:00") { $begin_time = $logintime[0]["create_at"]; } $end_time = date('Y-m-d H:i:s', time()); //var_dump($begin_time,$end_time);exit; $sqlorder = 'select count(*) as ordernumber, sum(reality_total) as ordermoney from nb_order where order_status in (3,4,8) and dpid = "' . $companyId . '" and update_at >="' . $begin_time . '" and update_at <="' . $end_time . '"'; $orderdata = $db->createCommand($sqlorder)->queryRow(); //var_dump($sqlorder,$orderdata);exit; $sqlmembercharge = 'select sum(reality_money) from nb_member_recharge where dpid="' . $companyId . '" and update_at >="' . $begin_time . '" and update_at <="' . $end_time . '" and delete_flag=0'; $memberCharge = $db->createCommand($sqlmembercharge)->queryScalar(); // $sqlmemberconsume='select sum(consumer_money) from nb_member_consumer where dpid="'.$companyId. // '" and update_at >="'.$begin_time.'" and update_at <="'.$end_time.'" and delete_flag=0'; // $memberConsume=$db->createCommand($sqlmemberconsume)->queryScalar(); $sqlmemberconsume = 'select sum(pay_amount) from nb_order_pay where paytype =4 and dpid = "' . $companyId . '" and update_at >="' . $begin_time . '" and update_at <="' . $end_time . '"'; //var_dump($sqlmemberconsume);exit; $memberConsume = $db->createCommand($sqlmemberconsume)->queryScalar(); $sqlcash = 'select sum(pay_amount) from nb_order_pay where paytype =0 and dpid = "' . $companyId . '" and update_at >="' . $begin_time . '" and update_at <="' . $end_time . '"'; $cashTotal = $db->createCommand($sqlcash)->queryScalar(); $sqlunion = 'select sum(pay_amount) from nb_order_pay where paytype =5 and dpid = "' . $companyId . '" and update_at >="' . $begin_time . '" and update_at <="' . $end_time . '"'; $unionTotal = $db->createCommand($sqlunion)->queryScalar(); empty($orderdata['ordermoney']) ? 0 : $orderdata['ordermoney']; //($memberCharge,$memberConsume,$cashTotal,$sqlunion,$unionTotal);exit; if ($save == "1") { //insert shift $se = new Sequence("shift_detail"); $lid = $se->nextval(); //$userarray= explode("_",Yii::app()->user->userId); $data = array('lid' => $lid, 'dpid' => $companyId, 'create_at' => date('Y-m-d H:i:s', time()), 'update_at' => date('Y-m-d H:i:s', time()), 'userid' => $userarr[0], 'begin_time' => $begin_time, 'end_time' => $end_time, 'order_num' => $orderdata['ordernumber'], 'order_money' => empty($orderdata['ordermoney']) ? 0 : $orderdata['ordermoney'], 'member_charge' => empty($memberCharge) ? 0 : $memberCharge, 'member_consume' => empty($memberConsume) ? 0 : $memberConsume, 'cash_total' => empty($cashTotal) ? 0 : $cashTotal, 'union_total' => empty($unionTotal) ? 0 : $unionTotal, 'weixin_total' => 0, 'zhifubao_total' => 0, 'other_total' => 0, 'delete_flag' => "0"); Yii::app()->db->createCommand()->insert('nb_shift_detail', $data); //update loginin $sqlloginup = 'update nb_b_login set out_time="' . $end_time . '" where out_time="0000-00-00 00:00:00" and user_id =' . $userarr[0] . ' and dpid=' . $userarr[1]; $db->createCommand($sqlloginup)->execute(); //Yii::app()->user->logout(); $this->redirect('/wymenuv2/admin/login'); } $this->render('shiftlogout', array('logintime' => $logintime, 'begin_time' => $begin_time, 'end_time' => $end_time, 'order_number' => $orderdata['ordernumber'], 'order_money' => empty($orderdata['ordermoney']) ? 0 : $orderdata['ordermoney'], 'member_charge' => empty($memberCharge) ? 0 : $memberCharge, 'member_consume' => empty($memberConsume) ? 0 : $memberConsume, 'cash_total' => empty($cashTotal) ? 0 : $cashTotal, 'union_total' => empty($unionTotal) ? 0 : $unionTotal)); }
public function actionDetailCreate() { $groupid = Yii::app()->request->getParam('groupid', 0); $groupname = Yii::app()->request->getParam('groupname', 0); $type = Yii::app()->request->getParam('type', '0'); $model = new Taste(); $model->dpid = $this->companyId; if (Yii::app()->request->isPostRequest) { $model->attributes = Yii::app()->request->getPost('Taste'); $se = new Sequence("taste"); $model->taste_group_id = $groupid; $model->allflae = $type; //$model->lid = $se->nextval(); //$model->create_at = date('Y-m-d H:i:s',time()); $model->delete_flag = '0'; $data = array('lid' => substr("0000000000" . $se->nextval(), -10), 'dpid' => $model->dpid, 'create_at' => date('Y-m-d H:i:s', time()), 'update_at' => date('Y-m-d H:i:s', time()), 'taste_group_id' => $groupid, 'allflae' => $type, 'name' => $model->name, 'delete_flag' => '0'); //var_dump($data);exit; if (Yii::app()->db->createCommand()->insert('nb_taste', $data)) { // var_dump($model);exit; // if($model->save()) { Yii::app()->user->setFlash('success', yii::t('app', '添加成功')); $this->redirect(array('taste/detailIndex', 'companyId' => $this->companyId, 'groupname' => $groupname, 'groupid' => $groupid, 'type' => $type)); } } $this->render('detailCreate', array('model' => $model, 'groupid' => $groupid, 'groupname' => $groupname, 'type' => $type)); }
public function actionDetailCreate() { $model = new ProductSetDetail(); $model->dpid = $this->companyId; $pslid = Yii::app()->request->getParam('psid'); $model->set_id = $pslid; if (Yii::app()->request->isPostRequest) { $model->attributes = Yii::app()->request->getPost('ProductSetDetail'); $se = new Sequence("porduct_set_detail"); $model->lid = $se->nextval(); $model->create_at = date('Y-m-d H:i:s', time()); $model->delete_flag = '0'; $modelsp = Yii::app()->db->createCommand('select count(*) as num from nb_product_set_detail t where t.dpid=' . $this->companyId . ' and t.set_id=' . $pslid . ' and t.delete_flag=0 and group_no=' . $model->group_no)->queryRow(); //var_dump($modelsp);exit; if ($model->is_select == "1") { $sqlgroup = "update nb_product_set_detail set is_select=0 where group_no=" . $model->group_no . " and dpid=" . $this->companyId . " and set_id=" . $model->set_id; Yii::app()->db->createCommand($sqlgroup)->execute(); } if ($model->save()) { Yii::app()->user->setFlash('success', yii::t('app', '添加成功')); $this->redirect(array('productSet/detailindex', 'companyId' => $this->companyId, 'lid' => $model->set_id)); } } $maxgroupno = $this->getMaxGroupNo($pslid); $categories = $this->getCategories(); $categoryId = 0; $products = $this->getProducts($categoryId); $productslist = CHtml::listData($products, 'lid', 'product_name'); $this->render('detailcreate', array('model' => $model, 'categories' => $categories, 'categoryId' => $categoryId, 'products' => $productslist, 'maxgroupno' => $maxgroupno)); }
public function actionDailyclose() { $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())); // $criteria->select = 't.paytype, t.payment_method_id,t.lid,t.dpid, t.update_at,t.order_status,t.should_total,sum(t.reality_total) as should_all'; // //利用Yii框架CDB语句时,聚合函数要在model的类里面进行公共变量定义,如:变量should_all在order的class里面定义为public $should_all; // //$criteria->select = 'sum(t.should_total) as should_all'; //代表了要查询的字段,默认select='*'; // $criteria->addCondition("t.dpid= ".$this->companyId); // $criteria->addInCondition('t.order_status', array(3,4)); // $criteria->addCondition("t.update_at >='$begin_time 00:00:00'"); // $criteria->addCondition("t.update_at <='$end_time 23:59:59'"); // $criteria->with = array("company","paymentMethod"); //连接表 // $criteria->order = 't.lid ASC' ;//排序条件 // $criteria->group = 't.paytype'; // // $models = Order::model()->findAll($criteria); $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->with = array("paymentMethod"); //连接表 $criteria->group = "t.paytype"; $models = OrderPay::model()->findAll($criteria); $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(); $transaction->commit(); //提交事务会真正的执行数据库操作 echo 1; } catch (Exception $e) { $transaction->rollback(); //如果操作失败, 数据回滚 echo 0; } exit; }
public function actionEditProduct() { $id = Yii::app()->request->getParam('id', 0); $setid = Yii::app()->request->getParam('setid', 0); $orderId = Yii::app()->request->getParam('orderId'); $typeId = Yii::app()->request->getParam('typeId'); $companyId = Yii::app()->request->getParam('companyId'); //$orderProduct=null; //$models=null; //$modelsp=null; //if($setid=='0000000000') //{ $orderProduct = OrderProduct::model()->with(array('product', 'productSet'))->find('t.lid=:id and t.dpid=:dpid', array(':id' => $id, ':dpid' => $companyId)); //} if (Yii::app()->request->isPostRequest) { Until::validOperate($companyId, $this); $isset = Yii::app()->request->getPost('isset', 0); //$setid = Yii::app()->request->getParam('setid',0); $selsetlist = Yii::app()->request->getPost('selsetlist', 0); //var_dump($orderProduct);exit; $orderProduct->attributes = Yii::app()->request->getPost('OrderProduct'); //var_dump(Yii::app()->request->getPost('OrderProduct'));exit; //var_dump($selsetlist,$isset);exit; $db = Yii::app()->db; $transaction = $db->beginTransaction(); try { if ($isset == 0) { $orderProduct->save(); } else { if (strlen($selsetlist) > 10) { $productIdlist = explode(',', $selsetlist); //$setid=Yii::app()->request->getPost('OrderProduct'); //var_dump($setid['set_id']);exit; $db->createCommand('delete from nb_order_product where set_id=:setid and dpid=:dpid')->execute(array(':setid' => $orderProduct->set_id, ':dpid' => $companyId)); foreach ($productIdlist as $productId) { //var_dump($productId);exit; $sorderProduct = new OrderProduct(); $sorderProduct->dpid = $companyId; $sorderProduct->delete_flag = '0'; $sorderProduct->product_order_status = '0'; $sorderProduct->set_id = $orderProduct->set_id; $sorderProduct->order_id = $orderProduct->order_id; $sorderProduct->create_at = date('Y-m-d H:i:s', time()); $productUnit = explode('|', $productId); $sorderProduct->product_id = $productUnit[0]; $sorderProduct->amount = $productUnit[1]; $sorderProduct->price = $productUnit[2]; $sorderProduct->is_giving = '0'; $sorderProduct->zhiamount = 0; $se = new Sequence("order_product"); $sorderProduct->lid = $se->nextval(); //var_dump($sorderProduct);exit; $sorderProduct->save(); } } } $transaction->commit(); Yii::app()->user->setFlash('success', yii::t('app', '修改成功')); //echo '333';exit; $this->redirect(array('defaultOrder/order', 'companyId' => $this->companyId, 'orderId' => $orderProduct->order_id, 'typeId' => $typeId)); } catch (Exception $e) { $transaction->rollback(); //如果操作失败, 数据回滚 //var_dump($e); //echo json_encode(array('status'=>0,'message'=>'换台失败')); Yii::app()->user->setFlash('success', yii::t('app', '添加失败')); return false; } } $this->renderPartial('editproduct', array('orderid' => $orderId, 'orderProduct' => $orderProduct, 'typeId' => $typeId)); }
public static function saveImg($dpid, $productId, $pictures) { $db = Yii::app()->db; $sql = 'delete from nb_product_picture where product_id=' . $productId; $db->createCommand($sql)->execute(); if (!empty($pictures)) { foreach ($pictures as $pic) { $se = new Sequence("product_picture"); $lid = $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_set' => 0, 'product_id' => $productId, 'pic_path' => $pic); $db->createCommand()->insert('nb_product_picture', $data); } return true; } return false; }
public static function createOrder($companyId, $orderId, $orderStatus, $productList, $orderTasteIds, $orderTasteMemo, $callId, Order $order, Site $site, SiteNo $siteNo) { $sellOff = array(); ////////////// //return json_encode(array('status'=>false,'msg'=>"test1")); ///////////// $time = date('Y-m-d H:i:s', time()); $db = Yii::app()->db; $transaction = $db->beginTransaction(); $se = new Sequence("order_product"); $setaste = new Sequence("order_taste"); $orderProductStatus = 0; if ($orderStatus > 1) { $orderProductStatus = 1; } try { ///先删除所有为下单的临时菜品,后插入 $sql = 'delete from nb_order_product where dpid=' . $companyId . ' and product_order_status=0 and order_id =' . $orderId; $result = $db->createCommand($sql)->execute(); //return array('status'=>false,'msg'=>"test11"); //插入订单单品 if (!empty($productList)) { $productListArr = explode(";", $productList); foreach ($productListArr as $tvalue) { //更新库存//失败则返回 $productDetailArr = explode(",", $tvalue); $productdata = Product::model()->find('lid=:lid and dpid=:dpid', array(':lid' => $productDetailArr[2], ':dpid' => $companyId)); //return json_encode(array('status'=>true,'msg'=>$productdata->store_number.$productDetailArr[2].$productDetailArr[3])); if ($productdata->store_number == 0 || $productdata->store_number > 0 && $productdata->store_number < $productDetailArr[3]) { $transaction->rollback(); return array('status' => false, 'msg' => $productdata->product_name . "数量不足"); } ////////套餐数量判断////////////////////////// //不是临时挂单就更新库存,更新下单数和点赞数,发送更新库存消息 if ($orderStatus > 1) { $productdata->order_number = $productdata->order_number + $productDetailArr[4]; $productdata->favourite_number = $productdata->favourite_number + $productDetailArr[4]; if ($productdata->store_number > 0) { $productdata->store_number = $productdata->store_number - $productDetailArr[4]; array_push($sellOff, array("product_id" => sprintf("%010d", $productDetailArr[2]), "type" => "product", "num" => $productdata->store_number)); } ///套餐数量减//////////// } $productdata->save(); //return array('status'=>false,'msg'=>"test111333"); if ($productDetailArr[3] == "0") { //插入 $orderProductId = $se->nextval(); //插入一条 $orderProductData = array('lid' => $orderProductId, 'dpid' => $companyId, 'create_at' => $time, 'order_id' => $orderId, 'set_id' => $productDetailArr[1], 'product_id' => $productDetailArr[2], 'offprice' => $productDetailArr[5], 'price' => $productDetailArr[6], 'update_at' => $time, 'amount' => $productDetailArr[4], 'is_giving' => $productDetailArr[7], 'taste_memo' => $productDetailArr[9], 'product_order_status' => $orderProductStatus); //return array('status'=>false,'msg'=>"test14444".implode("..",$orderProductData)); $db->createCommand()->insert('nb_order_product', $orderProductData); } //修改为先删除后插入,防止以后一个菜品被分开点多分。 ////else{ // //更新 // $orderProductData= OrderProduct::model()->find('lid=:lid and dpid=:dpid' , array(':lid'=>$productDetailArr[0],':dpid'=>$companyId)); // $orderProductData->price=$productDetailArr[3]; // $orderProductData->amount=$productDetailArr[2]; // $orderProductData->is_giving=$productDetailArr[4]; // $orderProductData->taste_memo=$productDetailArr[6]; // $orderProductData->save(); // } //insert taste//delete and insert taste $orderProductTasteIds = str_replace("|", ",", $productDetailArr[8]); if (!empty($orderProductTasteIds)) { $orderProductTasteIds = substr($orderProductTasteIds, 0, strlen($orderProductTasteIds) - 1); $orderProductTasteArr = explode(",", $orderProductTasteIds); $sql2 = 'delete from nb_order_taste where dpid=' . $companyId . ' and is_order=0 and order_id = ' . $productDetailArr[0]; //return json_encode(array('status'=>true,'msg'=>$orderProductTasteIds)); $result = $db->createCommand($sql2)->execute(); //重新插入 if (!empty($orderProductTasteArr)) { foreach ($orderProductTasteArr as $tvalue) { $orderProductTasteId = $setaste->nextval(); //return json_encode(array('status'=>false,'msg'=>$productDetailArr[0]."|".$tvalue."|".$orderTasteId)); $orderProductTasteAll = array('lid' => $orderProductTasteId, 'dpid' => $companyId, 'create_at' => $time, 'update_at' => $time, 'order_id' => $orderProductId, 'taste_id' => $tvalue, 'is_order' => "0", 'delete_flag' => "0"); $db->createCommand()->insert('nb_order_taste', $orderProductTasteAll); } } } } } if (!empty($site)) { if ($site->status < $orderStatus) { $site->status = $orderStatus; $site->update_at = $time; $site->save(); } } if (!empty($siteNo)) { if ($siteNo->status < $orderStatus) { $siteNo->status = $orderStatus; $siteNo->update_at = $time; $siteNo->save(); } } if ($order->order_status < $orderStatus) { $order->order_status = $orderStatus; $order->update_at = $time; } $order->taste_memo = $orderTasteMemo; $order->callno = $callId; $order->save(); //删除全单口味 $orderTasteIds = str_replace("|", ",", $orderTasteIds); if (!empty($orderTasteIds)) { //return json_encode(array('status'=>false,'msg'=>$orderTasteIds)); $orderTasteIds = substr($orderTasteIds, 0, strlen($orderTasteIds) - 1); $orderTasteArr = explode(",", $orderTasteIds); $sql = 'delete from nb_order_taste where dpid=' . $companyId . ' and is_order=1 and order_id =' . $orderId; $result = $db->createCommand($sql)->execute(); //重新插入 //return json_encode(array('status'=>false,'msg'=>"test3")); //$se=new Sequence("order_taste"); if (!empty($orderTasteArr)) { foreach ($orderTasteArr as $tvalue) { $orderTasteId = $setaste->nextval(); $orderTasteAll = array('lid' => $orderTasteId, 'dpid' => $companyId, 'create_at' => $time, 'update_at' => $time, 'order_id' => $orderId, 'taste_id' => $tvalue, 'is_order' => "1", 'delete_flag' => "0"); $db->createCommand()->insert('nb_order_taste', $orderTasteAll); } } } // if(!$savejson["status"]) // { // $ret=json_encode($savejson); // }else{ if ($orderStatus > 1) { $ret = Helper::printKitchenAll3($order, $site, $siteNo, false); if (!$ret['status']) { $transaction->rollback(); } else { $transaction->commit(); } } else { $ret = array('status' => true, 'msg' => "保存成功", 'jobs' => array()); $transaction->commit(); } //估清产品通知 // if(!empty($sellOff)){ // //return array('status'=>false,'msg'=>"沽清:".$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 array('status'=>true,'msg'=>"保存成功",'jobs'=>array()); return $ret; } catch (Exception $ex) { $transaction->rollback(); return array('status' => false, 'msg' => $e->getMessage(), 'jobs' => array()); } }
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; } } }
/** * * 大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(); } }
public function actionCompanyCreate() { $model = new UserCompany(); $model->dpid = $this->companyId; $userid = Yii::app()->request->getParam('userid'); $model->user_id = $userid; if (Yii::app()->request->isPostRequest) { $model->attributes = Yii::app()->request->getPost('UserCompany'); $se = new Sequence("user_company"); $model->lid = $se->nextval(); $model->create_at = date('Y-m-d H:i:s', time()); $model->update_at = date('Y-m-d H:i:s', time()); $model->delete_flag = '0'; if ($model->save()) { Yii::app()->user->setFlash('success', yii::t('app', '添加成功')); $this->redirect(array('user/companyIndex', 'companyId' => $this->companyId, 'lid' => $model->user_id)); } } $companys = $this->getCompanys(); $companyslist = CHtml::listData($companys, 'dpid', 'company_name'); $this->render('companycreate', array('model' => $model, 'companyslist' => $companyslist)); }
public function actionInsertSync() { //一份钟的随机时间,防止高并发 //$now = new DateTime(date('Y-m-d H:i:s',time())); //echo $now->format('Y-m-d H-i-s'); //$now->modify("-1 minute"); //echo $now->format('Y-m-d H-i-s'); //exit; $randtime = rand(1, 60); echo $randtime; sleep($randtime); //启用本地模式时,才存在同步,云端不存在同步 //等于L是,本地系统知道连接到本地系统,云端根据该company的is2_cloud //判断是否使用本地服务器,如果是云端开台,点单等功能不能操作,否则冲突。 //云端更新云端数据,本地更新本地数据,数据更新时要检查,不能随便更新。 //图片下载,图片上传(phpcurl 和 move_upload_file上传,暂时不做) $dpid = Yii::app()->request->getParam('companyId', 0); $typeId = Yii::app()->request->getParam('typeId', 0); $date = Yii::app()->request->getParam('date', '2015-08-15 19:00:00'); if (Yii::app()->params['cloud_local'] == 'l') { $dbcloud; $dblocal; try { //echo "1";exit; $dbcloud = Yii::app()->dbcloud; //echo "0";exit; $dblocal = Yii::app()->dblocal; //echo "2";exit; } catch (Exception $ex) { echo $ex->getMessage(); return; } //$dbcloud=Yii::app()->dbcloud; echo "dbcloud <br>"; //云端和本地插入dataSync同步记录,但不设成功标志 $se = new Sequence("data_sync"); $lid = $se->nextval(); $data = array('lid' => $lid, 'dpid' => $dpid, 'cmd_code' => '2cloud', 'create_at' => date('Y-m-d H:i:s', time()), 'update_at' => date('Y-m-d H:i:s', time()), 'cmd_data' => '', 'sync_result' => '0', 'is_interface' => '0'); //var_dump($data);exit; $dbcloud->createCommand()->insert('nb_data_sync', $data); //var_dump($data);exit; $dblocal->createCommand()->insert('nb_data_sync', $data); echo "insert nb_data_sync <br>"; //获取最后一次成功的dataSync的时间 $sql = "select create_at from nb_data_sync where dpid=" . $dpid . " and sync_result=1 order by create_at desc limit 1"; $cloudtime = $dbcloud->createCommand($sql)->queryScalar(); $localtime = $dblocal->createCommand($sql)->queryScalar(); //$sqlsuccess = "update nb_data_sync set sync_result='1' where dpid=".$dpid." and lid=".$lid; if (empty($cloudtime)) { $cloudtime = "2015-08-15 19:00:00"; } else { //echo $cloudtime; $tempnow = new DateTime($cloudtime); //$tempnow->modify("-120 minute"); $tempnow->modify("-2 hour"); $cloudtime = $tempnow->format('Y-m-d H:i:s'); //echo $cloudtime; exit; } if (empty($localtime)) { $localtime = "2015-08-15 19:00:00"; } else { $tempnow = new DateTime($localtime); //$tempnow->modify("-120 minute");hour $tempnow->modify("-2 hour"); $localtime = $tempnow->format('Y-m-d H:i:s'); } echo "typeId:" . $typeId . "<br>"; if ($typeId == "1") { $cloudtime = "2015-08-15 19:00:00"; $localtime = "2015-08-15 19:00:00"; } if ($date != "2015-08-15 19:00:00") { $cloudtime = "{$date}"; $localtime = "{$date}"; } echo "get cloud tiem:" . $cloudtime . " and local time:" . $localtime . " <br>"; //exit; //var_dump($cloudtime,$localtime);exit; //轮询以下表(云端和本地都会操作的,) //云端生成,本地操作的表, 如:site,member_card等被本地平凡修改的的有吗? $synctalbe = array("nb_b_login", "nb_close_account", "nb_close_account_detail", "nb_feedback", "nb_floor", "nb_member_card", "nb_member_consumer", "nb_member_recharge", "nb_online_pay", "nb_order", "nb_order_pay", "nb_order_product", "nb_order_retreat", "nb_order_taste", "nb_pad", "nb_pad_printerlist", "nb_payment_method", "nb_printer", "nb_printer_way", "nb_printer_way_detail", "nb_product", "nb_product_addition", "nb_product_category", "nb_product_discount", "nb_product_out", "nb_product_picture", "nb_product_printerway", "nb_product_set", "nb_product_set_detail", "nb_product_special", "nb_product_taste", "nb_product_tempprice", "nb_retreat", "nb_site", "nb_site_no", "nb_site_type", "nb_taste", "nb_taste_group", "nb_user", "nb_user_company"); ////特殊的更新 $syncSpecialTalbe = array("nb_site" => array("status", "number"), "nb_member_card" => array("all_money"), "nb_product" => array("store_number", "order_number", "favourite_number")); $isalllocalsuccess = 1; $isallcloudsuccess = 1; foreach ($synctalbe as $t) { $deletelist1 = ""; $clouddataarr = array(); $deletelist2 = ""; $localspecialdataarr = array(); $deletelist3 = ""; $localdataarr = array(); //将这个时间点开始的云端数据取出 $sql1 = "select * from " . $t . " where lid%2=0 and dpid=" . $dpid . " and update_at >= '" . $cloudtime . "'"; //var_dump($sql1);exit; $clouddata = $dbcloud->createCommand($sql1)->queryAll(); echo "cloud -> local:" . $t . ":" . count($clouddata) . "<br>"; if (!empty($clouddata)) { $deletelist1 = "("; foreach ($clouddata as $cdata) { $deletelist1 = $deletelist1 . $cdata['lid'] . ","; $clouddataarr[$cdata['lid']] = $cdata; } $deletelist1 = $deletelist1 . "0000000000" . ")"; } //特殊的更新内容,先将云端的取出来,然后取出本地的双号,更新云端的数据,及取出的数组。 //用这个数据更新本地的 //本地的正常更新 if (!empty($syncSpecialTalbe[$t])) { $specialfield = $syncSpecialTalbe[$t]; $localspecialdata = $dblocal->createCommand($sql1)->queryAll(); echo "cloud -> local(special):" . $t . ":" . count($localspecialdata) . "<br>"; if (!empty($localspecialdata)) { $deletelist2 = "("; foreach ($localspecialdata as $sdata) { $deletelist2 = $deletelist2 . $sdata['lid'] . ","; $localspecialdataarr[$sdata['lid']] = $sdata; } $deletelist2 = $deletelist2 . "0000000000" . ")"; //更新$localspecialdata //更新$clouddata foreach ($localspecialdataarr as $sadata) { if (!empty($clouddataarr[$sadata['lid']])) { foreach ($specialfield as $sfield) { $clouddataarr[$sadata['lid']][$sfield] = $sadata[$sfield]; } $localspecialdataarr[$sadata['lid']] = $clouddataarr[$sadata['lid']]; } } //云端删除$localspecialdata //云端插入$localspecialdata //$dbcloud->createCommand($sqlsuccess)->execute(); $transactionspecial = $dblocal->beginTransaction(); try { $dbcloud->createCommand("delete from " . $t . " where dpid=" . $dpid . " and lid in " . $deletelist2)->execute(); //$dblocal->createCommand("delete from ".$t." where dpid=".$dpid." and lid%2=0 and create_at>='".$cloudtime."'")->execute(); foreach ($localspecialdataarr as $lsd) { $dbcloud->createCommand()->insert($t, $lsd); } $transactionspecial->commit(); } catch (Exception $ex) { echo $ex->getMessage(); $transactionspecial->rollback(); $isallcloudsuccess = 0; //break; //continue; //exit; } } } //$sql2 = "select * from ".$t." where lid%2=0 and dpid=".$dpid." and create_at >= '".$cloudtime."'"; //$cloudlocal=$dblocal->createCommand($sql2)->queryAll(); //对比数据,删除并插入和对方不一样的数据,要设置事务, //$cloudupdate= array_diff($clouddata, $cloudlocal); //$dblocal->begainTransaction(); //var_dump($clouddata,$cloudlocal);exit; if (!empty($clouddataarr)) { $transactionlocal = $dblocal->beginTransaction(); try { $dblocal->createCommand("delete from " . $t . " where dpid=" . $dpid . " and lid in " . $deletelist1)->execute(); //$dblocal->createCommand("delete from ".$t." where dpid=".$dpid." and lid%2=0 and create_at>='".$cloudtime."'")->execute(); foreach ($clouddataarr as $cd) { $dblocal->createCommand()->insert($t, $cd); } //$dbcloud->createCommand($sqlsuccess)->execute(); $transactionlocal->commit(); } catch (Exception $ex) { echo $ex->getMessage(); $transactionlocal->rollback(); $isallcloudsuccess = 0; //break; //continue; //exit; } } //将这个时间点开始的本地数据取出///云端不可能修改本地,只有本地修改云端。 $sql3 = "select * from " . $t . " where lid%2=1 and dpid=" . $dpid . " and update_at >= '" . $localtime . "'"; $localdata = $dblocal->createCommand($sql3)->queryAll(); echo "local->cloud" . $t . ":" . count($localdata) . "<br>"; //var_dump($localdata); //$sql4 = "select * from ".$t." where lid%2=1 and dpid=".$dpid." and create_at >= ".$localtime; //$localcoud=$dbcloud->createCommand($sql4)->queryAll(); //对比数据,删除并插入和对方不一样的数据,要设置事务, //$localupdate= array_diff($localdata, $localcoud); //$dblocal->begainTransaction(); if (!empty($localdata)) { $transactioncloud = $dbcloud->beginTransaction(); try { $deletelist3 = "("; foreach ($localdata as $ldata) { $deletelist3 = $deletelist3 . $ldata['lid'] . ","; $localdataarr[$ldata['lid']] = $ldata; } $deletelist3 = $deletelist3 . "0000000000" . ")"; //var_dump($deletelist2);exit; //$deletelist2= "(".implode(",",array_column($localdata, 'lid')).")"; //var_dump("delete from ".$t." where dpid=".$dpid." and lid in".$deletelist2);exit; $dbcloud->createCommand("delete from " . $t . " where dpid=" . $dpid . " and lid in" . $deletelist3)->execute(); foreach ($localdata as $ld) { $dbcloud->createCommand()->insert($t, $ld); } //$dblocal->createCommand($sqlsuccess)->execute(); $transactioncloud->commit(); } catch (Exception $ex) { $transactioncloud->rollback(); $isalllocalsuccess = 0; //break; //continue; } } } //删除同步时间之前的所有的打印记录//删除1天谴的消息记录 $sqldeleteprintjobs = "delete from nb_order_printjobs where dpid=" . $dpid . " and create_at <= '" . $localtime . "'"; $dblocal->createCommand($sqldeleteprintjobs)->execute(); $sqldeleteorderfeed = "delete from nb_order_feedback where dpid=" . $dpid . " and create_at <= '" . $localtime . "'"; $dblocal->createCommand($sqldeleteorderfeed)->execute(); //更新dataSync同步记录为成功状态, echo "all success;" . "<br>"; $sqlsuccess = "update nb_data_sync set sync_result='1' where dpid=" . $dpid . " and lid=" . $lid; if ($isalllocalsuccess == 1) { $localtime = $dblocal->createCommand($sqlsuccess)->execute(); } if ($isallcloudsuccess == 1) { $cloudtime = $dbcloud->createCommand($sqlsuccess)->execute(); } //downimagefile echo "download image" . "<br>"; $this->clientDownImg($dpid); } }