/** * 获取订单的商品列表. * @param $orderId */ public function getOrderProductByOrderId($orderId) { if (empty($orderId)) { return ''; } $list = OrderProduct::model()->findAllByAttributes(array('order_id' => $orderId)); if (empty($list)) { return ''; } // todo 图片待处理 $newList = array(); foreach ($list as $row) { $temp = $row->getAttributes(); if ($row->type == 1) { $temp['images']['cover'] = '/images/public/tab.png'; } elseif ($row->type == 2) { $zineInfo = Zine::model()->findByPk($row['product_id']); if ($zineInfo) { $temp['images']['cover'] = '/images/zine/' . $zineInfo['mcover']; } else { $temp['images']['cover'] = ''; } } else { $temp['images'] = Product::model()->getProductFaceImageByProductId($row->product_id); } $temp['total_price'] = $temp['sell_price'] * $temp['quantity']; $newList[$row->id] = $temp; } return $newList; }
public function createReservation($data) { $result = new Reservations(); $result->createTime = date('Y-m-d H:i:s', time()); foreach ($data as $k => $v) { $result->{$k} = $v; } $type = User::model()->findByAttributes(array('id' => $data['userId'])); if ($data['type'] == 1 && $type == 1) { $orderid = Order::model()->findAllByAttributes(array('status' => 1, 'userId' => Yii::app()->user->id, 'type' => 1)); if ($orderid) { $now = date('Ymd', strtotime(substr($data['startTime'], 0, 10))); foreach ($orderid as $list) { $dp = OrderProduct::model()->find('endDate>=' . $now . ' and orderId=' . $list['id'] . ' and startDate<=' . $now); if ($dp) { break; } } $dp->usedTimes++; $dp->save(); $result->orderId = $dp['orderId']; $result->save(); } } if ($result->save()) { $data = array('code' => 200, 'message' => 'SUCCESS'); } return $data; }
public function run() { $this->controller->pageTitle = 'Book a Workspace'; $now = date('Y-m-d', time()); $date = Yii::app()->request->getParam('date'); $date = $date == '' ? $now : $date; $proxy = new CHub(); $result = $proxy->getHubList(); if (Yii::app()->request->isAjaxRequest) { $id = Yii::app()->request->getParam('id'); $hub = Yii::app()->request->getParam('hub'); $date = Yii::app()->request->getParam('date'); if ($id) { $date = date('Ymd', strtotime($date)); $record = Reservations::model()->findAll('startTime =' . date('Ymd', strtotime($date)) . '100000' . ' and userId=' . Yii::app()->user->id . ' and type=1 and status=1'); $orderid = Order::model()->findAllByAttributes(array('status' => 1, 'userId' => Yii::app()->user->id, 'type' => 1)); if ($orderid) { foreach ($orderid as $list) { $order = OrderProduct::model()->find('endDate>=' . $date . ' and orderId=' . $list['id'] . ' and startDate<=' . $date); if ($order) { break; } } if ($order) { echo CJSON::encode(array('code' => 200, 'data' => array('num' => $order['totalTimes'] - $order['usedTimes'], 'count' => count($record)))); } else { echo CJSON::encode(array('code' => 200, 'data' => array('num' => 0))); } } else { $code = CodeUsed::model()->findAll('userId=' . Yii::app()->user->id); if ($code) { foreach ($code as $list) { $value = Code::model()->find('endDate>=' . $date . ' and id=' . $list['codeId'] . ' and startDate<=' . $date); if ($value) { break; } } if ($value) { echo CJSON::encode(array('code' => 200, 'data' => array('num' => 1, 'count' => count($record)))); } else { echo CJSON::encode(array('code' => 200, 'data' => array('num' => 0))); } } else { echo CJSON::encode(array('code' => 200, 'data' => array('num' => 0))); } } } else { $proxy = new CReservation(); $result = $proxy->getNumber($date); if ($result['code'] == 200) { $data = array('code' => 200, 'data' => $result); echo CJSON::encode($data); } } } else { $this->controller->render('workspacelist', array('data' => $result['data'], 'date' => $date)); } }
public function afterUninstall() { Yii::app()->settings->clear($this->id); //Yii::app()->unintallComponent('cart'); $db = Yii::app()->db; $tablesArray = array(Order::model()->tableName(), OrderHistory::model()->tableName(), OrderProduct::model()->tableName(), OrderStatus::model()->tableName(), OrderProductHistroy::model()->tableName(), ShopPaymentMethod::model()->tableName(), ShopPaymentMethodTranslate::model()->tableName(), ShopDeliveryMethod::model()->tableName(), ShopDeliveryMethodTranslate::model()->tableName(), ShopDeliveryPayment::model()->tableName(), ProductNotifications::model()->tableName()); foreach ($tablesArray as $table) { $db->createCommand()->dropTable($table); } return parent::afterInstall(); }
public function actionView($id) { if (Yii::app()->user->isGuest) { throw new CHttpException(404, 'The requested page does not exist.'); } $model = $this->loadModel($id); if ($model->user_id != Yii::app()->user->id) { throw new CHttpException(404, 'The requested page does not exist.'); } $dataProvider = new CActiveDataProvider('Order'); $products = OrderProduct::model()->orderProducts($id); $this->render('view', compact('model', 'products')); }
/** * 订单详情页面 */ public function actionInfo() { $oInfo = Order::model()->getOrderInfo($_REQUEST['id']); $opList = OrderProduct::model()->findAllByAttributes(array('order_id' => $_REQUEST['id'])); $oLog = OrderLog::model()->findAllByAttributes(array('order_id' => $_REQUEST['id'])); $oShipping = OrderShipping::model()->findAllByAttributes(array('order_id' => $_REQUEST['id'])); $shippingList = Shipping::model()->getShippingList(); $viewData = array(); $viewData['oInfo'] = $oInfo; $viewData['opList'] = $opList; $viewData['oLog'] = $oLog; $viewData['oShipping'] = $oShipping; $viewData['shippingList'] = $shippingList; $this->render('info', $viewData); }
public static function getReturnUrlByOrder($model) { if (!$model instanceof Order) { $model = Order::model()->with('campaign', 'click')->findByPk($model); } if (!$model->order_id) { return null; } $sql = 'SELECT * FROM `orders_products` WHERE `order_id`=:order_id ORDER BY `created` LIMIT 1'; $productModel = OrderProduct::model()->findBySql($sql, array(':order_id' => $model->order_id)); $array = array('order_id' => $model->order_id, 'amount' => number_format($model->amount_product + $model->amount_shipping, 2, '.', ''), 'e_mail' => $model->customer->email, 'Bill_First' => $model->billingAddress->fname, 'Bill_Last' => $model->billingAddress->lname, 'Bill_Address1' => $model->billingAddress->address1, 'Bill_Address2' => $model->billingAddress->address2, 'Bill_City' => $model->billingAddress->city, 'Bill_State' => $model->billingAddress->state_id, 'Bill_Zip' => $model->billingAddress->zip, 'Bill_Country' => $model->billingAddress->country->country_name, 'Bill_Phone' => $model->billingAddress->phone, 'Bill_Email' => $model->customer->email, 'Ship_First' => $model->address->fname, 'Ship_Last' => $model->address->lname, 'Ship_Address1' => $model->address->address1, 'Ship_Address2' => $model->address->address2, 'Ship_City' => $model->address->city, 'Ship_State' => $model->address->state_id, 'Ship_Zip' => $model->address->zip, 'Ship_Country' => $model->address->country->country_name, 'Ship_Phone' => $model->address->phone, 'ShippingId' => $model->shipping_id, 'ShippingPrice' => number_format($model->amount_shipping, 2, '.', ''), 'SubTotal' => number_format($model->amount_product, 2, '.', ''), 'ipAddress' => long2ip($model->ip), 'product1Id' => $productModel->product_id, 'AFID' => $model->aff_id, 'SID' => $model->click->SID, 'c1' => $model->click->c1, 'c2' => $model->click->c2, 'c3' => $model->click->c3); return 'https://' . $model->campaign->return_url . '?' . http_build_query($array); }
/** * Updates a particular model. * If update is successful, the browser will be redirected to the 'view' page. * @param integer $id the ID of the model to be updated */ public function actionUpdate($id) { $model = $this->loadModel($id); if ($model === null) { throw new CHttpException(404, 'The requested page does not exist.'); } $dataProvider = new CActiveDataProvider('Order'); $products = OrderProduct::model()->orderProducts($id); // Uncomment the following line if AJAX validation is needed // $this->performAjaxValidation($model); if (isset($_POST['Order'])) { $model->order_status_id = $_POST['Order']['order_status_id']; $model->save(); Yii::app()->user->setFlash('error', "Статус заказа изменен!"); } $this->render('update', compact('model', 'products')); }
public function checkProduct($orderId) { return OrderProduct::model()->findByAttributes(array('orderId' => $orderId)); }
public static function getFeedbackSite($companyId, $siteId, $istemp, $orderId, $isOrder) { if ($siteId !== '0000000000') { return SiteClass::getSiteNmae($companyId, $siteId, $istemp); } if ($orderId !== '0000000000') { if ($isOrder == '1') { $order = Order::model()->find(" dpid=:dpid and lid=:orderid", array(':dpid' => $companyId, ':orderid' => $orderId)); return SiteClass::getSiteNmae($companyId, $order->site_id, $order->istemp); } else { $orderProduct = OrderProduct::model()->with("order")->find(" dpid=:dpid and lid=:orderid", array(':dpid' => $companyId, ':orderid' => $orderId)); return SiteClass::getSiteNmae($companyId, $orderProduct->order->site_id, $orderProduct->order->istemp); } } }
public function actionDeleteProduct() { $id = Yii::app()->request->getParam('id'); $orderProduct = OrderProduct::model()->findByPk($id); if ($orderProduct) { if ($orderProduct->amount > 1) { $restNum = $orderProduct->amount - 1; $orderProduct->saveAttributes(array('amount' => $restNum)); $data = array('status' => true, 'amount' => $restNum, 'price' => $orderProduct->price); } else { $orderProduct->delete(); $data = array('status' => true, 'amount' => 0, 'price' => 0); } $data['total'] = OrderProduct::getTotal($orderProduct->order_id); echo json_encode($data); exit; } echo json_encode(array('status' => false)); exit; }
public function actionPrintKitchenResultOne() { $companyId = Yii::app()->request->getParam('companyId'); $jobid = Yii::app()->request->getParam('jobid'); $orderProductId = Yii::app()->request->getParam('orderProductId'); Until::validOperate($companyId, $this); $db = Yii::app()->db; //$jobstatus=false; Gateway::getOnlineStatus(); $store = Store::instance('wymenu'); $jobresult = $store->get('job_' . $companyId . "_" . $jobid . '_result'); //var_dump($jobresult);exit; if (empty($jobresult)) { $ret = array('status' => false, 'msg' => yii::t('app', '任务未返回')); } else { if ($jobresult == "success") { //var_dump($companyId,$orderProductId);exit; $orderProduct = OrderProduct::model()->find(' dpid=:dpid and lid=:lid', array(':dpid' => $companyId, ':lid' => $orderProductId)); // if($orderProduct->is_print=='0') // { // $orderProduct->is_print='1'; // $orderProduct->save(); // } if ($orderProduct->is_print == '0') { $orderProduct->is_print = '1'; $orderProduct->save(); } $ret = array('status' => true, 'msg' => yii::t('app', '打印成功')); } else { $ret = array('status' => false, 'msg' => yii::t('app', '打印机执行任务失败')); } } Yii::app()->end(json_encode($ret)); //get status from memcache //if error change product kitchen status in db //if timenum=0 return finish or all success }
public static function printKitchenAll3(Order $order, Site $site, SiteNo $siteNo, $reprint) { $printers_a = array(); $orderproducts_a = array(); $printer2orderproducts_a = array(); $jobids = array(); $printercontent_a = array(); //return array('status'=>true,'dpid'=>$order->dpid,'allnum'=>"0",'type'=>'none','msg'=>"dddd"); //$orderProductTastes = OrderTaste::model()->with('taste')->findAll('t.order_id=:orderid and t.dpid=:dpid and t.is_order=0', array(':orderid'=>$orderProduct->lid,':dpid'=>$orderProduct->dpid)); //$orderProductTasteEx = $orderProduct->taste_memo; //var_dump($orderProductTasteEx);exit; //$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)); //var_dump($site->floor_id,$orderProduct->product->printer_way_id);exit; $floor_id = '0'; if ($order->is_temp == '0') { $floor_id = $site->floor_id; } $orderProducts = OrderProduct::model()->with('product')->findAll('t.order_id=:id and t.dpid=:dpid and t.is_print=0 and t.delete_flag=0', array(':id' => $order->lid, ':dpid' => $order->dpid)); if (empty($orderProducts)) { return array('status' => false, 'dpid' => $order->dpid, 'allnum' => "0", 'type' => 'none', 'msg' => yii::t('app', '没有要打印的菜品!')); } //foreach printer_way //传菜厨打、整单厨打、配菜和制作厨打 $printerways = PrinterWay::model()->findAll(" dpid = :dpid and delete_flag=0", array(':dpid' => $order->dpid)); if (empty($printerways)) { return array('status' => false, 'dpid' => $order->dpid, 'allnum' => "0", 'type' => 'none', 'msg' => "没有打印方案"); } //var_dump($printerways);exit; foreach ($printerways as $printerway) { $printer2orderproducts_a = array(); foreach ($orderProducts as $orderProduct) { $orderproducts_a[$orderProduct->lid] = $orderProduct; $productprinterwaynow = ProductPrinterway::model()->find("dpid=:dpid and printer_way_id=:pwi and product_id=:pid", array(':dpid' => $order->dpid, ':pwi' => $printerway->lid, ':pid' => $orderProduct->product_id)); //var_dump($printerway->lid,$productprinterwaynow);exit; if (!empty($productprinterwaynow)) { //不是每个产品都对应所有打印方案 // return array('status'=>false,'dpid'=>$order->dpid,'allnum'=>"0",'type'=>'none','msg'=>"部分产品没有设置打印方案"); // }else{ $printwaydetails = PrinterWayDetail::model()->findAll('floor_id=:floorid and print_way_id=:pwi and dpid=:dpid and delete_flag=0', array(':floorid' => $floor_id, ':pwi' => $printerway->lid, ':dpid' => $order->dpid)); foreach ($printwaydetails as $printway) { $printer = Printer::model()->find('lid=:printerId and dpid=:dpid', array(':printerId' => $printway->printer_id, ':dpid' => $order->dpid)); if (empty($printer)) { return array('status' => false, 'dpid' => $printer->dpid, 'allnum' => "0", 'type' => 'none', 'msg' => yii::t('app', '打印方案没有设置厨房打印机')); } if (!array_key_exists($printer->lid, $printers_a)) { $printers_a[$printer->lid] = $printer; //add isonpaper listno } if (array_key_exists($printer->lid, $printer2orderproducts_a)) { array_push($printer2orderproducts_a[$printer->lid], $orderProduct->lid); } else { $printer2orderproducts_a[$printer->lid] = array($orderProduct->lid); } if ($printer->printer_type != '0') { return array('status' => false, 'dpid' => $printer->dpid, 'allnum' => "0", 'type' => 'none', 'msg' => yii::t('app', '厨打打印机必须是网络打印机')); } } } } //return array('status'=>false,'dpid'=>$order->dpid,'allnum'=>"0",'type'=>'none','msg'=>"测试3"); //如果是整体, // if(empty($printer2orderproducts_a)) // { // return array('status'=>false,'dpid'=>$order->dpid,'allnum'=>"0",'type'=>'none','msg'=>"没有找到打印机和产品关系"); // } if ($printerway->is_onepaper == "1") { foreach ($printer2orderproducts_a as $key => $values) { $printer = $printers_a[$key]; $productids = ""; //$listData = array("22".Helper::getPlaceholderLenBoth($order->company->company_name, 16));// $listData = array("22" . Helper::setPrinterTitle($order->company->company_name, 8)); array_push($listData, "br"); //array_push($listData,"22"."+++总单+++"); array_push($listData, "22" . "<" . $printerway->name . ">"); array_push($listData, "00"); array_push($listData, "br"); if ($reprint) { $strreprint = yii::t('app', "*****重复厨打,请留意!!!"); array_push($listData, "11" . $strreprint); } array_push($listData, "br"); $strSite = ""; if ($order->is_temp == '1') { array_push($listData, "00" . yii::t('app', '临时座:')); array_push($listData, "11" . $siteNo->site_id % 1000); } else { array_push($listData, "00" . yii::t('app', '座号:')); array_push($listData, "11" . $site->siteType->name . ' ' . $site->serial); } array_push($listData, "00" . yii::t('app', '人数:') . $order->number); //return array('status'=>true,'dpid'=>$order->dpid,'allnum'=>"0",'type'=>'none','msg'=>"测试1"); if (!empty($order->callno)) { array_push($listData, "00" . " " . yii::t('app', '呼叫号:')); array_push($listData, "11" . $order->callno); } array_push($listData, "br"); array_push($listData, "00" . str_pad('', 48, '-')); $productids = ""; foreach ($values as $value) { if (empty($productids)) { $productids .= $value; } else { $productids .= "," . $value; } $orderProduct = $orderproducts_a[$value]; if ($orderProduct->amount < 1) { continue; } //array_push($listData,Helper::getPlaceholderLen($value->product->product_name,38).Helper::getPlaceholderLen($orderProduct->amount." X ".$value->product->product_unit,10)); array_push($listData, "11" . str_pad($orderProduct->amount . "X" . $orderProduct->product->product_unit, 8, " ") . Helper::setProductName($orderProduct->product->product_name, 12, 8)); array_push($listData, "br"); $orderProductTastes = OrderTaste::model()->with('taste')->findAll('t.order_id=:orderid and t.dpid=:dpid and t.is_order=0', array(':orderid' => $orderProduct->lid, ':dpid' => $orderProduct->dpid)); $orderProductTasteEx = $orderProduct->taste_memo; $strTaste = yii::t('app', "单品口味:") . $orderProductTasteEx; $existTaste = 0; if (!empty($orderProductTasteEx)) { $existTaste = 1; } foreach ($orderProductTastes as $orderProductTaste) { $strTaste .= '/' . $orderProductTaste->taste->name; $existTaste = 1; } if ($existTaste == 1) { array_push($listData, "11" . $strTaste); array_push($listData, "br"); } array_push($listData, "00" . str_pad('', 48, '-')); } $orderTastes = OrderTaste::model()->with('taste')->findAll('t.order_id=:orderid and t.dpid=:dpid and t.is_order=1', array(':orderid' => $order->lid, ':dpid' => $order->dpid)); $orderTasteEx = $order->taste_memo; array_push($listData, "00" . str_pad('', 48, '-')); $strAllTaste = yii::t('app', "全单口味:") . $orderTasteEx; $existTaste = 0; if (!empty($orderTasteEx)) { $existTaste = 1; } foreach ($orderTastes as $orderTaste) { $strAllTaste .= '/' . $orderTaste->taste->name; $existTaste = 1; } if ($existTaste == 1) { array_push($listData, "11" . $strAllTaste); array_push($listData, "br"); array_push($listData, "00" . str_pad('', 48, '-')); } array_push($listData, "00" . yii::t('app', '操作员:') . $order->username . " " . date('Y-m-d H:i:s', time())); // $precode=""; // //后面加切纸 // $sufcode="0A0A0A0A0A0A1D5601"; // //var_dump($listData);exit; // $printret=array(); // $printserver="0";//0通过自己同步打印,1通过打印服务器打印 // // //份数循环 // for($i=0;$i<$printerway->list_no;$i++){ ////////////// // $printret=Helper::printConetent($printer,$listData,$precode,$sufcode,$printserver); // //array_push($jobids,$printret['jobid']."_".$order->lid);//将所有单品的id链接上去,便于更新下单状态,打印成功后下单状态和打印状态变更,数量加1 // array_push($jobids,$printret['jobid']."_".$printret['address']."_".$productids); // $productids=""; // if(!$printret['status']) // { // return array('status'=>false,'allnum'=>count($jobids),'msg'=>$printret['msg']); // } // } //return $printret; /////尝试用整体打印$printercontent_a for ($i = 0; $i < $printerway->list_no; $i++) { if (array_key_exists($key, $printercontent_a)) { array_push($printercontent_a[$key], $listData); } else { $printercontent_a[$key] = array($listData); } } } } else { ////如果不是整体,分开打印 ////////////// foreach ($printer2orderproducts_a as $key => $values) { $printer = $printers_a[$key]; $productids = ""; //$listData = array("22".Helper::getPlaceholderLenBoth($order->company->company_name, 16));// //组装头 $listDataHeader = array("22" . Helper::setPrinterTitle($order->company->company_name, 8)); array_push($listData, "br"); //array_push($listData,"22"."---分菜单---"); array_push($listData, "22" . "<" . $printerway->name . ">"); array_push($listDataHeader, "00"); array_push($listDataHeader, "br"); if ($reprint) { $strreprint = yii::t('app', "*****重复厨打,请留意!!!"); array_push($listDataHeader, "11" . $strreprint); } array_push($listDataHeader, "br"); $strSite = ""; if ($order->is_temp == '1') { array_push($listDataHeader, "00" . yii::t('app', '临时座:')); array_push($listDataHeader, "11" . $siteNo->site_id % 1000); } else { array_push($listDataHeader, "00" . yii::t('app', '座号:')); array_push($listDataHeader, "11" . $site->siteType->name . ' ' . $site->serial); } array_push($listDataHeader, "00" . yii::t('app', '人数:') . $order->number); if (!empty($order->callno)) { array_push($listDataHeader, "00" . " " . yii::t('app', '呼叫号:')); array_push($listDataHeader, "11" . $order->callno); } array_push($listDataHeader, "br"); array_push($listDataHeader, "00" . str_pad('', 48, '-')); //组装尾部 $orderTastes = OrderTaste::model()->with('taste')->findAll('t.order_id=:orderid and t.dpid=:dpid and t.is_order=1', array(':orderid' => $order->lid, ':dpid' => $order->dpid)); $orderTasteEx = $order->taste_memo; $listDataTail = array("00" . str_pad('', 48, '-')); //array_push($listData,"00".str_pad('',48,'-')); $strAllTaste = yii::t('app', "全单口味:") . $orderTasteEx; $existTaste = 0; if (!empty($orderTasteEx)) { $existTaste = 1; } foreach ($orderTastes as $orderTaste) { $strAllTaste .= '/' . $orderTaste->taste->name; $existTaste = 1; } if ($existTaste == 1) { array_push($listDataTail, "11" . $strAllTaste); array_push($listDataTail, "br"); array_push($listDataTail, "00" . str_pad('', 48, '-')); } array_push($listDataTail, "00" . yii::t('app', '操作员:') . $order->username . " " . date('Y-m-d H:i:s', time())); //生成body并打印 $productids = ""; foreach ($values as $value) { $listDataBody = array(); //组装身体 //$productids=""; if (empty($productids)) { $productids .= $value; } else { $productids .= "," . $value; } $orderProduct = $orderproducts_a[$value]; if ($orderProduct->amount < 1) { continue; } //array_push($listData,Helper::getPlaceholderLen($value->product->product_name,38).Helper::getPlaceholderLen($orderProduct->amount." X ".$value->product->product_unit,10)); array_push($listDataBody, "11" . str_pad($orderProduct->amount . "X" . $orderProduct->product->product_unit, 8, " ") . Helper::setProductName($orderProduct->product->product_name, 12, 8)); array_push($listDataBody, "br"); $orderProductTastes = OrderTaste::model()->with('taste')->findAll('t.order_id=:orderid and t.dpid=:dpid and t.is_order=0', array(':orderid' => $orderProduct->lid, ':dpid' => $orderProduct->dpid)); $orderProductTasteEx = $orderProduct->taste_memo; $strTaste = yii::t('app', "单品口味:") . $orderProductTasteEx; $existTaste = 0; if (!empty($orderProductTasteEx)) { $existTaste = 1; } foreach ($orderProductTastes as $orderProductTaste) { $strTaste .= '/' . $orderProductTaste->taste->name; $existTaste = 1; } if ($existTaste == 1) { array_push($listDataBody, "11" . $strTaste); array_push($listDataBody, "br"); } $listData = array_merge($listDataHeader, $listDataBody, $listDataTail); // $precode=""; //后面加切纸 // $sufcode="0A0A0A0A0A0A1D5601"; // //var_dump($listData);exit; // $printret=array(); // $printserver="0"; ///自己去轮询 // //份数循环 // for($i=0;$i<$printerway->list_no;$i++){ ////////////// // $printret=Helper::printConetent($printer,$listData,$precode,$sufcode,$printserver); // //array_push($jobids,$printret['jobid']."_".$order->lid);//将所有单品的id链接上去,便于更新下单状态,打印成功后下单状态和打印状态变更,数量加1 // array_push($jobids,$printret['jobid']."_".$printret['address']."_".$productids); // $productids=""; // if(!$printret['status']) // { // return array('status'=>false,'allnum'=>count($jobids),'msg'=>$printret['msg']); // } // } for ($i = 0; $i < $printerway->list_no; $i++) { if (array_key_exists($key, $printercontent_a)) { array_push($printercontent_a[$key], $listData); } else { $printercontent_a[$key] = array($listData); } } } //return array('status'=>true,'dpid'=>$order->dpid,'allnum'=>"0",'type'=>'none','msg'=>"测试n"); } } } //return array('status'=>true,'dpid'=>$order->dpid,'allnum'=>"0",'type'=>'none','msg'=>"测试13"); //整体打印 $jobids2 = array(); $precode = ""; $sufcode = "0A0A0A0A0A0A1D5601"; //var_dump($listData);exit; $printret = array(); $printserver = "0"; ///自己去轮询 //份数循环 foreach ($printercontent_a as $key => $values) { ////////////// //$printret=Helper::printConetent($printer,$listData,$precode,$sufcode,$printserver); $printer2 = $printers_a[$key]; $printret = Helper::printConetent2($printer2, $values, $precode, $sufcode, $printserver, $order->lid); //array_push($jobids,$printret['jobid']."_".$order->lid);//将所有单品的id链接上去,便于更新下单状态,打印成功后下单状态和打印状态变更,数量加1 array_push($jobids2, "0_" . $printret['jobid'] . "_" . $printret['address']); if (!$printret['status']) { return array('status' => false, 'allnum' => count($jobids), 'msg' => $printret['msg']); } } //var_dump(json_encode($jobids));exit; Gateway::getOnlineStatus(); $store = Store::instance('wymenu'); $store->set("kitchenjobs_" . $order->dpid . "_" . $order->lid, json_encode($jobids2), 0, 300); $ret = array('status' => true, 'orderid' => $order->lid, 'dpid' => $order->dpid, 'allnum' => count($jobids2), 'msg' => '打印任务正常发布', "jobs" => $jobids2); //return array('status'=>true,'dpid'=>$order->dpid,'allnum'=>"0",'type'=>'none','msg'=>"测试14"); //更新菜品状态为已打印 $sqlorderproduct = "update nb_order_product set is_print='1' where dpid=" . $order->dpid . " and order_id =" . $order->lid; $commandorderproduct = Yii::app()->db->createCommand($sqlorderproduct); $commandorderproduct->execute(); return $ret; }
/** * 订单详情 */ public function actionOrder() { $userId = $this->user_id; if (empty($userId)) { $this->redirect('/user/login'); } $orderSn = addslashes(trim($_REQUEST['ordersn'])); try { $oInfo = Order::model()->getUserOrderInfoBySn($userId, $orderSn); if (empty($oInfo) || !$oInfo['id']) { $this->redirect('/?from=no_order'); } $orderProduct = OrderProduct::model()->getOrderProductByOrderId($oInfo['id']); $status = Order::model()->getOrderStatusForUserPage($oInfo); $logs = OrderLog::model()->findAllByAttributes(array('order_id' => $oInfo['id'])); } catch (exception $e) { $this->redirect('/?from=order_error'); } $viewData = array(); $viewData['info'] = $oInfo; $viewData['status'] = $status; $viewData['logs'] = $logs; $viewData['orderProduct'] = $orderProduct; $this->render('/user/order', $viewData); }
/** * Delete ordered product from order * * @param $id */ public function deleteProduct($id) { $model = OrderProduct::model()->findByPk($id); if ($model) { $model->delete(); $event = new CModelEvent($this, array('ordered_product' => $model)); $this->onProductDeleted($event); } }
function updateAction() { if (isset($_POST['ajax'])) { if (isset($_POST['attachOrder']) && $this->access->actionAccess('attachOrder')) { $orderID = AF::get($_POST, 'order_id'); $campID = AF::get($_POST, 'camp_id', 0); if (!$orderID) { Message::echoJsonError(__('order_attach_no_fields')); } $order = new Order(); $order->fillFromDbPk($orderID); $o = clone $order; $r = Orders::createAttachedOrder($order, $campID, true); unset($order); unset($o); if ($r) { Message::echoJsonSuccess(array('message' => __('order_attach_success'), 'order_id' => $r)); } else { Message::echoJsonError(__('order_attach_error')); } } } /* if(isset($_POST['ajax'])) { if( isset($_POST['add_rocket']) && $this->access->actionAccess('rocket') ) { $orderID = AF::get($_POST, 'order_id'); $rocket = AF::get($_POST, 'rocket', 0); if(!$orderID) Message::echoJsonError(__('order_rocket_no_fields')); $newRocket = ($rocket) ? 0 : 1; $orderModel = new Order(); $orderModel->order_id = $orderID; $orderModel->rocket = $newRocket; $orderModel->setIsNewRecord(false); if($orderModel->save(false)) Message::echoJsonSuccess(__('order_rocket_action_'.$newRocket)); else Message::echoJsonError(__('order_rocket_not_action_'.$newRocket)); } if(isset($_POST['update_expiry_date']) && $this->access->actionAccess('update')) { $expiryMonth = AF::get($_POST,'expiry_month'); $expiryYear = AF::get($_POST,'expiry_year'); $orderID = AF::get($_POST,'order_id'); if(!$orderID) Message::echoJsonError(__('order_incorrect_order_id')); if(!$expiryMonth || (int)$expiryMonth > 12 || !$expiryYear || (int) $expiryYear < date('Y')) Message::echoJsonError(__('order_incorrect_expiry_date')); $pacnetModel = new OrderPn(); $pacnetModel->order_id = $orderID; $pacnetModel->expiry_date = OrderPn::convertExpiryDateFormat($expiryMonth, $expiryYear); $pacnetModel->setIsNewRecord(false); if($pacnetModel->save(false)) { OrderLog::createLog($this->user->user_id, $orderID, 16, $pacnetModel->expiry_date); Message::echoJsonSuccess(__('order_updeted_expiry_date')); } else Message::echoJsonError(__('order_not_updeted_expiry_date')); } if(isset($_POST['update_cc_cvv']) && $this->access->actionAccess('update')) { $ccCvv = AF::get($_POST,'cc_cvv'); $orderID = AF::get($_POST,'order_id'); if(!$orderID) Message::echoJsonError(__('order_incorrect_order_id')); if(!$ccCvv || strlen($ccCvv) > 4 || strlen($ccCvv) < 3) Message::echoJsonError(__('order_incorrect_cc_cvv')); $pacnetModel = new OrderPn(); $pacnetModel->fillFromDbPk($orderID); $arrayNote1 = unserialize(NoteBase64::decode($pacnetModel->note1)); $arrayNote1['ccc'] = $ccCvv; $pacnetModel->note1 = NoteBase64::encode(serialize($arrayNote1)); $pacnetModel->IsNewRecord = false; if($pacnetModel->save(false)) { OrderLog::createLog($this->user->user_id, $orderID, 17, '***'); Message::echoJsonSuccess(__('order_updeted_cc_cvv')); } else Message::echoJsonSuccess(__('order_not_updeted_cc_cvv')); } } */ //$model = new Order(); $id = AF::get($this->params, 'id', FALSE); if (!$id) { throw new AFHttpException(0, 'no_id'); } if (isset($_POST['set_void']) && $this->access->actionAccess('order_refund')) { $orderLogsModel = new OrderLog(); $orderLogsModel->user_id = $this->user->user_id; $orderLogsModel->action = 3; if (!$orderLogsModel->canVoid()) { $this->redirect(); } $orderModel = new Order(); $orderModel->fillFromDbPk($id); if ($orderModel->status == 'void') { $this->redirect(); } $orderModel->status = 'void'; $orderModel->amount_refunded = '(`amount_product`+`amount_shipping`):sql'; $orderModel->model_uset_id = $this->user->user_id; // remove recurring by all product /* if($orderModel->recurring == '0' || $orderModel->recurring == -1) $saveModel->recurring = 'NULL:sql'; */ if ($orderModel->save(false)) { //$saveModel-> $jobModel = new Job(); $jobModel->order_id = $orderModel->order_id; $jobModel->job_type = 'refund'; $jobModel->addNew(); //Set void events Event::setEvents($orderModel->order_id, 6); OrderLog::createLog($this->user->user_id, $id, 3); } } if (isset($_POST['set_shipping_address'])) { $orderModel = new Order(); $orderModel->fillFromDbPk($id); $orderModel->address_id = $_POST['shipping_address']; $orderModel->save(); } if (isset($_POST['set_billing_address'])) { $orderModel = new Order(); $orderModel->fillFromDbPk($id); $orderModel->address_id = $_POST['billing_address']; $orderModel->save(); } if (isset($_POST['cancel_retries']) && $this->access->actionAccess('update')) { $orderModel = Order::model()->findByPk($id); if ($orderModel->cancelRetries($this->user->user_id)) { // save success } else { // failed, now what? } $this->redirect(); } if (isset($_POST['order_form_cancel_retry_set_recurring_next']) && $this->access->actionAccess('update')) { $productID = (int) AF::get($_POST, 'product_id'); $recurringNext = AF::get($_POST, 'recurring_next'); $parentOrder = Order::model()->findByPk($id); // have to use a different method of Order class population to not overwrite $parentOrder $childOrder = new Order(); $childID = $parentOrder->hasDeclinedRebilled(); if (!$childID) { return false; } $childOrder->fillFromDbPk($childID); if ($childOrder->cancelRetries($this->user->user_id)) { // set rebill date $orderProduct = new OrderProduct(); $orderProduct->fillFromDbPks(array('order_id' => $id, 'product_id' => $productID)); $orderProduct->addFlags('recurring'); $orderProduct->recurring_next = $recurringNext; if ($orderProduct->save()) { OrderLog::createLog($this->user->user_id, $id, 12, $recurringNext); $this->redirect(); } else { return false; } } else { // failed, now what? return false; } } if (isset($_POST['discount_next_retries']) && $this->access->actionAccess('update')) { $discount = (int) AF::get($_POST, 'count_discount_next_retries'); //$productID = (int) AF::get($_POST, 'product_id'); if ($discount <= 0 || $discount > 100) { $this->redirect(); } /* $orderModel=new Order(); $orderModel->fillFromDbPk($id); */ $orderModel = Order::model()->with('campaign')->findByPk($id); if ($orderModel) { $orderModel->amount_product = $orderModel->amount_product - $orderModel->amount_product * $discount / 100; $orderModel->model_uset_id = $this->user->user_id; if ($orderModel->save(false)) { OrderLog::createLog($this->user->user_id, $id, 24, 'Discount ' . $discount . '%. New price ' . Currency::getSingPrice($orderModel->amount_product, $orderModel->campaign->currency_id)); } } $this->redirect(); /* $orderProduct=new OrderProduct(); $orderProduct->order_id=$id; $orderProduct->product_id=$productID; //$orderProduct->fillFromDbPks(array('order_id'=>$id, 'product_id'=>$productID)); $orderProduct->discount_next=$discount; if($orderProduct->tempUpdate()) { OrderLog::createLog($this->user->user_id, $id, 24, 'Discount '.$discount.'%. New price '.$saveModel->amount_product); } */ /* $orderModel = new Order(); $orderModel->fillFromDbPk($id); $saveModel = new Order(); $saveModel->order_id = $id; $saveModel->amount_product = $orderModel->amount_product - ($orderModel->amount_product*$discount/100); $saveModel->model_uset_id = $this->user->user_id; $saveModel->IsNewRecord = false; if($saveModel->save(false)) { OrderLog::createLog($this->user->user_id, $id, 24, 'Discount '.$discount.'%. New price '.$saveModel->amount_product); } $this->redirect(); */ } if (isset($_POST['set_returned']) && $this->access->actionAccess('update')) { $reason = AF::get($_POST, 'returned_reason'); if ($this->access->actionAccess('order_refund') && $reason) { $orderTempModel = new Order(); $orderTempModel->fillFromDbPk($id); $saveModel = new Order(); $saveModel->order_id = $id; $saveModel->returned = $reason; $saveModel->status = 'returned'; $saveModel->model_uset_id = $this->user->user_id; $saveModel->IsNewRecord = false; $saveModel->save(false); // disable recurring to order products $orderProducts = OrderProducts::getProductsByOrderID($saveModel->order_id); foreach ($orderProducts as $orderProduct) { $orderProduct->removeFlags('recurring'); $orderProduct->tempUpdate(); } Event::setEvents($saveModel->order_id, 7); OrderLog::createLog($this->user->user_id, $id, 10, $reason); } $this->redirect(); } if (isset($_POST['set_flags']) && $this->access->actionAccess('update')) { $flags = AF::get($_POST, 'flags', false); if (!$flags) { $flags = array(); } $orderModel = new Order(); $orderModel->fillFromDbPk($id); $orderModel->removeFlags(array('fraud', 'chargeback')); $orderModel->addFlags($flags); $orderModel->save(false); $customerModel = new Customer(); $customerModel->fillFromDbPk($orderModel->customer_id); $customerModel->removeFlags('blacklisted'); $customerModel->addFlags($flags); $customerModel->save(false); // Blacklisting must cancel all recurring if ($customerModel->isFlag('blacklisted') || $orderModel->isFlag('chargeback')) { Client::chargeBack($orderModel->customer_id); } OrderLog::createLog($this->user->user_id, $id, 11, implode(',', $flags)); $this->redirect(); } if (isset($_POST['set_recurring']) && $this->access->actionAccess('update')) { $productID = (int) AF::get($_POST, 'product_id'); $isSet = (int) AF::get($_POST, 'is_set', 0); $orderProduct = OrderProduct::model()->find('order_id = :order_id AND product_id = :product_id', array(':order_id' => $id, ':product_id' => $productID)); if ($isSet) { $orderProduct->addFlags('recurring'); if (!$orderProduct->recurring_next) { $updateDate = true; } else { $date = new DateTime($orderProduct->recurring_next); $updateDate = $date->getTimestamp() < time() ? true : false; } if ($updateDate) { OrderProduct::updateRecurringNext($orderProduct->order_product_id); } } else { $orderProduct->removeFlags('recurring'); } if ($orderProduct->save()) { OrderLog::createLog($this->user->user_id, $id, 4, $isSet ? 'yes' : 'no'); } $this->redirect(); } if (isset($_POST['stop_next_recurring']) && $this->access->actionAccess('update')) { $stopNextRecurring = AF::get($_POST, 'stop_next_recurring'); $op_id = AF::get($_POST, 'order_product_id'); $orderProduct = OrderProduct::model()->findByPk($op_id); if ($orderProduct->isFlag('recurring')) { if ($stopNextRecurring === '0' || $stopNextRecurring === '-1') { if ($stopNextRecurring === '-1') { $orderProduct->addFlags('stop_next_recurring'); } else { $orderProduct->removeFlags('stop_next_recurring'); } $orderProduct->save(); $notes = $stopNextRecurring === '0' ? 'no' : 'yes'; OrderLog::createLog($this->user->user_id, $id, 7, $notes); } } $this->redirect(); } if (isset($_POST['cc_number']) && $this->access->actionAccess('update')) { $pacnetModel = new OrderPn(); //$pacnetModel->fillFromDbPk($id); $pacnetModel->order_id = $id; $ccNumber = trim(AF::get($_POST, 'cc_number')); if ($ccNumber) { $pacnetModel->card_number = OrderPn::convertCreditCardNumberFormat($ccNumber); $arrayNote1 = unserialize(NoteBase64::decode($pacnetModel->note1)); $arrayNote1['ccn'] = $ccNumber; $pacnetModel->note1 = NoteBase64::encode(serialize($arrayNote1)); $pacnetModel->IsNewRecord = false; $pacnetModel->save(false); OrderLog::createLog($this->user->user_id, $id, 14, '**** **** **** ' . $pacnetModel->cc_number_last_four); } $this->redirect(); } if (isset($_POST['set_recurring_next']) && $this->access->actionAccess('update')) { $productID = (int) AF::get($_POST, 'product_id'); $recurringNext = AF::get($_POST, 'recurring_next'); $orderProduct = new OrderProduct(); $orderProduct->order_id = $id; $orderProduct->product_id = $productID; //$orderProduct->fillFromDbPks(array('order_id'=>$id, 'product_id'=>$productID)); $orderProduct->recurring_next = $recurringNext; if ($orderProduct->tempUpdate()) { OrderLog::createLog($this->user->user_id, $id, 12, $recurringNext); } $this->redirect(); /* $saveModel = new Order(); $saveModel->order_id = $id; $saveModel->recurring_next = AF::get($_POST, 'recurring_next'); if($saveModel->recurring_next) { $saveModel->model_uset_id = $this->user->user_id; $saveModel->IsNewRecord = false; $saveModel->save(false); OrderLog::createLog($this->user->user_id, $id, 12, $saveModel->recurring_next); } $this->redirect(); */ } $model = Order::model()->with('customer', 'campaign', 'affiliate', 'click', 'payment', 'gateway')->restrictions(array('campaign_id', 'aff_id'))->findByPk($id); if (!$model) { throw new AFHttpException(0, 'incorrect_id'); } if (isset($_POST['amount_refunded']) && $this->access->actionAccess('update')) { $amount_refunded = AF::get($_POST, 'amount_refunded', 0); $model->refunded($amount_refunded); if (!$model->errors) { $jobModel = new Job(); $jobModel->order_id = $model->order_id; $jobModel->job_type = 'refund'; $jobModel->addNew(); OrderLog::createLog($this->user->user_id, $id, 13, $amount_refunded); } } if (isset($_POST['set_discount_next']) && $this->access->actionAccess('update')) { $discount = (int) AF::get($_POST, 'discount_next'); $productID = (int) AF::get($_POST, 'product_id'); if ($discount <= 0 || $discount > 100) { $this->redirect(); } $orderProduct = new OrderProduct(); $orderProduct->order_id = $id; $orderProduct->product_id = $productID; $orderProduct->discount_next = $discount; if ($orderProduct->tempUpdate()) { OrderLog::createLog($this->user->user_id, $id, 6, $discount); } $this->redirect(); } /* $infoPayment = array( 'payment_type' => Payments::typeName($model->payment_type), 'payment_method' => Payments::methodName($model->payment_type,$model->payment_method), //'payment_status' => $model->payment_status, ); $addInfoPayment = array(); if($model->payment_type == 'gc') { $addInfoPayment = array( 'bank_code' => $model->bank_code, 'issuer_id' => $model->issuer_id, 'bank_name' => $model->bank_name, 'bank_city' => $model->bank_city, 'branch_code' => $model->branch_code, 'checkdigit' => $model->checkdigit, 'account_number' => $model->account_number, 'account_holder' => $model->account_holder, ); } elseif($model->payment_type == 'pn') { $addInfoPayment = array( 'cc_number' => '<span id="update_order_cc_number">'.$model->card_number.'</span> <a id="a_cc_update" href="javascript:AF.Orders.editCcNumber()"><i class="icon-edit"></i></a>', 'ccv' => '<span id="update_order_cc_cvv">***</span> <a id="a_cvv_update" href="javascript:AF.Orders.editCcCvv()"><i class="icon-edit"></i></a>', 'expiry_date' => '<span id="update_order_expiry_date">'.$model->expiry_date_formatted.'</span> <a id="a_expiry_date_update" href="javascript:AF.Orders.editExpiryDate()"><i class="icon-edit"></i></a>', ); } $infoPayment = array_merge($infoPayment, $addInfoPayment); */ /* $productModel = new Product(); $productModel->fillFromDbPk($model->product_id); $recurringTotal = 0; if( $productModel->product_next_id && ($model->recurring === '0' || $model->recurring === '-1') ) { $nextProductModel = new Product(); $nextProductModel->fillFromDbPk($productModel->product_next_id); $shippingModel = new Shipping(); $shippingModel->fillFromDbPk($model->shipping_id); $recurringTotal = ($nextProductModel->product_price + $shippingModel->amount_subscription); $recurringTotal = number_format( ($recurringTotal - ($recurringTotal*$model->discount_next/100) ), 2); } $recurringTotal = Currency::getSingPrice($recurringTotal, $model->currency_id); */ /* $nextProductModel = new Product(); $nextProductModel->fillFromDbPk($productModel->product_next_id); */ /* $msql=SafeMySQL::getInstance(); $sql="SELECT c.*, a.* FROM `orders` as o JOIN `customers` as c USING (`customer_id`) JOIN `addresses` as a USING (`address_id`) WHERE o.`order_id`=?i"; $allFields=$msql->getRow($sql, $model->order_id); fb($allFields); */ $customerAddresses = Address::model()->getExistingAddresses($model->customer_id); $orderProducts = $model->getOrderProducts(); $orderLogsModel = new OrderLog(); $orderLogsModel->user_id = $this->user->user_id; $orderLogsModel->action = 3; $canVoid = $orderLogsModel->canVoid(); $pagination = new Pagination(array('action' => $this->action, 'controller' => $this->controller, 'params' => $this->params)); //$orderModels = AFActiveDataProvider::models('OrderLog', $this->params, $pagination); $orderModels = new OrderLogs('OrderLog'); $dataProvider = $orderModels->getByOrderID($id); $maxAmountChargeback = 0; foreach ($dataProvider as $item) { if (in_array($item->action, array(29, 30)) && $item->amount) { $maxAmountChargeback += $item->amount; } } // we need to do some formatting here $paymentCRM = $model->payment->crmFormat(); // grab attachment campaign info $attached = $model->getAttachedOrders(); $model->user_id_updated = $this->user->user_id; $model->updated = 'NOW():sql'; $modelAttempt = new Attempt(); $modelAttempt->getLastOrderAttempt($model->order_id, Attempt::DEBIT_TYPE); //order children $orderChildren = Orders::getChildren($model->order_id); $this->addToPageTitle('Update Orders'); Assets::js('jquery.form'); Assets::css('jquery-ui'); Assets::js('//code.jquery.com/ui/1.10.3/jquery-ui.js'); Assets::js('dateRange/jquery.daterange'); $this->render('update', array('model' => $model, 'paymentModel' => $paymentCRM, 'orderProducts' => $orderProducts, 'canVoid' => $canVoid, 'dataProvider' => $dataProvider, 'customerAddresses' => $customerAddresses, 'attached' => $attached, 'maxAmountChargeback' => $maxAmountChargeback, 'modelAttempt' => $modelAttempt, 'orderChildren' => $orderChildren)); }
public function deleteOrderProduct() { $criteria = new CDbCriteria(); $criteria->addCondition('dpid=:dpid and site_id=:siteId and is_temp=:isTemp'); $criteria->params = array(':dpid' => $this->siteNo->dpid, ':siteId' => $this->siteNo->site_id, ':isTemp' => $this->siteNo->is_temp); $criteria->order = 'lid desc'; $order = Order::model()->find($criteria); if ($this->product['type']) { $orderProduct = OrderProduct::model()->updateAll(array('delete_flag' => 1, 'update_at' => date('Y-m-d H:i:s', time())), 'order_id=:orderId and dpid=:dpid and set_id=:productId and product_order_status=0', array(':orderId' => $order->lid, ':dpid' => $this->companyId, ':productId' => $this->product['lid'])); if ($orderProduct) { return true; } else { return false; } } else { $orderProduct = OrderProduct::model()->find('order_id=:orderId and dpid=:dpid and product_id=:productId and product_order_status=0', array(':orderId' => $order->lid, ':dpid' => $this->companyId, ':productId' => $this->product['lid'])); $orderProduct->delete_flag = 1; $orderProduct->update_at = date('Y-m-d H:i:s', time()); if ($orderProduct->update()) { return true; } else { return false; } } }
public static function subtractOrder($id) { $porders = OrderProduct::model()->findAll('order_id=:id', array(':id' => $id)); if (!empty($porders)) { foreach ($porders as $porder) { $option = OrderOption::model()->find('order_id=' . $id . ' AND order_product_id=' . $porder->id); if (!empty($option)) { $pvalue = ProductOptionValue::model()->findByPk($option->product_option_value_id); if (!empty($pvalue)) { $pvalue->quantity -= $porder->quantity; $pvalue->save(); } } else { $pvalue = Product::model()->findByPk($porder->product_id); if (!empty($pvalue)) { $pvalue->quantity -= $porder->quantity; $pvalue->save(); } } } } }
public function actionProductsalesExport() { $objPHPExcel = new PHPExcel(); $str = Yii::app()->request->getParam('str'); //var_dump($str);exit(); $text = Yii::app()->request->getParam('text'); $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())); //$catId = Yii::app()->request->getParam('cid',0); //var_dump($catId);exit; $criteria = new CDbCriteria(); //$sql = 'select year(t.create_at) as y_all,month(t.create_at) as m_all,day(t.create_at) as d_all,t.update_at,t.lid,t.dpid,t1.dpid,t.product_id,t1.lid,t1.product_name,t.price,t.amount,t.is_retreat,sum(t.price) as all_money,sum(t.amount) as all_total from nb_order_product t left join nb_product t1 on(t1.lid = t.product_id and t.dpid = t1.dpid ) where t.delete_flag=0 and t1.delete_flag = 0 and t.product_order_status=1 group by t.product_id,t.amount,is_retreat,month(t.create_at)'; //var_dump($sql);exit; $criteria->select = 'year(t.update_at) as y_all,month(t.update_at) as m_all,day(t.update_at) as d_all,t.update_at,t.lid,t.dpid,t.product_id,t.price,t.amount,t.is_retreat,sum(t.price) as all_money,sum(t.amount) as all_total, sum(t.price*t.amount) as all_price'; $criteria->with = array('company', 'product'); $criteria->condition = 't.is_retreat=0 and t.product_order_status=1 and t.delete_flag=0 and t.dpid=' . $this->companyId; if ($str) { $criteria->condition = 't.is_retreat=0 and t.product_order_status=1 and t.delete_flag=0 and t.dpid in(' . $str . ')'; } $criteria->addCondition("t.update_at >='{$begin_time} 00:00:00'"); $criteria->addCondition("t.update_at <='{$end_time} 23:59:59'"); if ($text == 1) { $criteria->group = 't.product_id,year(t.update_at)'; $criteria->order = 'year(t.update_at) asc,t.dpid asc'; } elseif ($text == 2) { $criteria->group = 't.product_id,month(t.update_at)'; $criteria->order = 'year(t.update_at) asc,month(t.update_at) asc,t.dpid asc'; } else { $criteria->group = 't.product_id,day(t.update_at)'; $criteria->order = 'year(t.update_at) asc,month(t.update_at) asc,day(t.update_at) asc,t.dpid asc'; } // $criteria->order = 't.update_at asc'; $models = OrderProduct::model()->findAll($criteria); //var_dump($models);exit(); //设置第1行的行高 $objPHPExcel->getActiveSheet()->getRowDimension('1')->setRowHeight(30); //设置第2行的行高 $objPHPExcel->getActiveSheet()->getRowDimension('2')->setRowHeight(15); $objPHPExcel->getActiveSheet()->getRowDimension('3')->setRowHeight(30); //设置字体 $objPHPExcel->getDefaultStyle()->getFont()->setName('宋体'); $objPHPExcel->getDefaultStyle()->getFont()->setSize(16); $styleArray1 = array('font' => array('bold' => true, 'color' => array('rgb' => '000000'), 'size' => '20'), 'alignment' => array('horizontal' => PHPExcel_Style_Alignment::HORIZONTAL_CENTER, 'vertical' => PHPExcel_Style_Alignment::VERTICAL_CENTER)); $styleArray2 = array('font' => array('color' => array('rgb' => 'ff0000'), 'size' => '16'), 'alignment' => array('horizontal' => PHPExcel_Style_Alignment::HORIZONTAL_CENTER, 'vertical' => PHPExcel_Style_Alignment::VERTICAL_CENTER)); $objPHPExcel->setActiveSheetIndex(0)->setCellValue('A1', '产品销售报表')->setCellValue('A2', yii::t('app', '报表生成时间:') . date('Y-m-d h:i:s', time()))->setCellValue('A3', '时间')->setCellValue('B3', '店铺名称')->setCellValue('C3', '单品名称')->setCellValue('D3', '售出数量')->setCellValue('E3', '总销售额')->setCellValue('F3', '备注'); $j = 4; foreach ($models as $v) { //print_r($v); if ($text == 1) { $objPHPExcel->setActiveSheetIndex(0)->setCellValue('A' . $j, $v->y_all)->setCellValue('B' . $j, $v->company->company_name)->setCellValue('C' . $j, $v->product->product_name)->setCellValue('D' . $j, $v->all_total)->setCellValue('E' . $j, $v->all_price)->setCellValue('F' . $j); } elseif ($text == 2) { $objPHPExcel->setActiveSheetIndex(0)->setCellValue('A' . $j, $v->y_all . '-' . $v->m_all)->setCellValue('B' . $j, $v->company->company_name)->setCellValue('C' . $j, $v->product->product_name)->setCellValue('D' . $j, $v->all_total)->setCellValue('E' . $j, $v->all_price)->setCellValue('F' . $j); } elseif ($text == 3) { $objPHPExcel->setActiveSheetIndex(0)->setCellValue('A' . $j, $v->y_all . '-' . $v->m_all . '-' . $v->d_all)->setCellValue('B' . $j, $v->company->company_name)->setCellValue('C' . $j, $v->product->product_name)->setCellValue('D' . $j, $v->all_total)->setCellValue('E' . $j, $v->all_price)->setCellValue('F' . $j); } //设置填充颜色 $objPHPExcel->getActiveSheet()->getStyle('A' . $j)->getFill()->setFillType(PHPExcel_Style_Fill::FILL_SOLID); $objPHPExcel->getActiveSheet()->getStyle('A' . $j)->getFill()->getStartColor()->setARGB('fae9e5'); //设置字体靠左 $objPHPExcel->getActiveSheet()->getStyle('A' . $j . ':C' . $j)->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_LEFT); $objPHPExcel->getActiveSheet()->getStyle('N' . $j)->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_LEFT); $j++; } //合并单元格 $objPHPExcel->getActiveSheet()->mergeCells('A1:F1'); $objPHPExcel->getActiveSheet()->mergeCells('A2:F2'); //单元格加粗,居中: // 将A1单元格设置为加粗,居中 $objPHPExcel->getActiveSheet()->getStyle('A1')->applyFromArray($styleArray1); //加粗字体 $objPHPExcel->getActiveSheet()->getStyle('A3:F3')->getFont()->setBold(true); //设置字体垂直居中 $objPHPExcel->getActiveSheet()->getStyle('A3:F3')->getAlignment()->setVertical(PHPExcel_Style_Alignment::VERTICAL_CENTER); //设置字体水平居中 $objPHPExcel->getActiveSheet()->getStyle('A3:F3')->getAlignment()->setVertical(PHPExcel_Style_Alignment::HORIZONTAL_CENTER); //字体靠左 $objPHPExcel->getActiveSheet()->getStyle('A2')->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_RIGHT); //设置填充颜色 $objPHPExcel->getActiveSheet()->getStyle('A3:F3')->getFill()->setFillType(PHPExcel_Style_Fill::FILL_SOLID); $objPHPExcel->getActiveSheet()->getStyle('A3:F3')->getFill()->getStartColor()->setARGB('fdfc8d'); //设置每列宽度 $objPHPExcel->getActiveSheet()->getColumnDimension('A')->setWidth(15); $objPHPExcel->getActiveSheet()->getColumnDimension('B')->setWidth(20); $objPHPExcel->getActiveSheet()->getColumnDimension('C')->setWidth(20); $objPHPExcel->getActiveSheet()->getColumnDimension('D')->setWidth(12); $objPHPExcel->getActiveSheet()->getColumnDimension('E')->setWidth(15); $objPHPExcel->getActiveSheet()->getColumnDimension('F')->setWidth(20); $objPHPExcel->getActiveSheet()->getColumnDimension('G')->setWidth(20); //输出 $objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel5'); $filename = "产品销售报表.xls"; header('Content-Type: application/vnd.ms-excel'); header('Content-Disposition: attachment;filename="' . $filename . '"'); header('Cache-Control: max-age=0'); $objWriter->save('php://output'); }
/** * Массив объектов OrderProduct * @param $products */ private function updateOrderProducts($products) { if (!$this->productsChanged) { return; } $validOrderProductIds = []; foreach ($products as $var) { /* @var $var OrderProduct */ if ($var->getIsNewRecord()) { $var->order_id = $this->id; } if ($var->save()) { $validOrderProductIds[] = $var->id; } } $criteria = new CDbCriteria(); $criteria->addCondition('order_id = :order_id'); $criteria->params = [':order_id' => $this->id]; $criteria->addNotInCondition('id', $validOrderProductIds); OrderProduct::model()->deleteAll($criteria); }
/** * 处理取消订单的库存 * @param $orderId */ public function dealWithCancelOrderProductStock($orderId) { if (!$orderId) { throw new exception('订单的id不能为空!'); } $list = OrderProduct::model()->findAllByAttributes(array('order_id' => $orderId)); if (empty($list)) { throw new exception('订单商品为空!'); } foreach ($list as $row) { if ($row['type'] == 1) { $pInfo = Tab::model()->findByPk($row['product_id']); } elseif ($row['type'] == 2) { $pInfo = Zine::model()->findByPk($row['product_id']); } else { $pInfo = Product::model()->findByPk($row['product_id']); } if (empty($pInfo)) { throw new exception('商品【' . $row['product_name'] . '】不存在!'); } $pInfo->quantity += $row['quantity']; $flag = $pInfo->save(); if (empty($flag)) { throw new exception('商品【' . $row['product_name'] . '】库存恢复失败!'); } if (!$row['type']) { $stockInfo = ProductStock::model()->findByAttributes(array('product_id' => $row['product_id'], 'attr_id' => $row['size_id'])); if (empty($stockInfo)) { throw new exception('商品【' . $row['product_name'] . '】库存不存在!'); } $stockInfo->quantity += $row['quantity']; $flag = $stockInfo->save(); if (empty($flag)) { throw new exception('订单【' . $row['product_name'] . '】库存恢复失败!'); } } } return true; }