| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708 |
- <?php
- require_once 'PHPMailer.php';
- include_once dirname(__FILE__) . '/PrinterHelper.php';
- class LewaimaiNotify
- {
- private $orderid;
- private $orderModel;
-
- private $adminModel;
- private $shopModel;
-
- private $IsPrinterConfirmed = false;
- private $orderCount = 0; //第几次下单
-
- private $pointsetModel;
-
- //进行订单通知,包含所有通知方式
- //orderid是订单ID,后面的model是为了提高效率,如果在调用这个函数之前已经获取过,就直接传入,没有就不传
- public static function NewOrderNotify($orderid, $orderModel = NULL, $adminModel = NULL, $shopModel = NULL)
- {
- $lewaimainotify = new LewaimaiNotify();
- $lewaimainotify->SendNewOrderNotify($orderid, $orderModel, $adminModel, $shopModel);
- }
-
- public static function OrderPrintOnly($orderid, $orderModel = NULL, $adminModel = NULL, $shopModel = NULL)
- {
- $lewaimainotify = new LewaimaiNotify();
- $lewaimainotify->PrinteOrderOnly($orderid, $orderModel, $adminModel, $shopModel);
- }
-
- //取消订单通知
- public static function CancelOrderNotify($orderid, $orderModel = NULL, $adminModel = NULL, $shopModel = NULL)
- {
- $lewaimainotify = new LewaimaiNotify();
- $lewaimainotify->SendCancelOrderNotify($orderid, $orderModel, $adminModel, $shopModel);
- }
-
- //积分兑换奖品通知
- public static function PointPrizeOrderNotify($orderid)
- {
- $lewaimainotify = new LewaimaiNotify();
- $lewaimainotify->SendPointPrizeOrderNotify($orderid);
- }
-
- //自由打印内容
- public static function ShopContentPrint($shop_id, $content)
- {
- $lewaimainotify = new LewaimaiNotify();
- $lewaimainotify->PrintShopContent($shop_id, $content);
- }
-
- public function SendNewOrderNotify($orderid, $orderModel = NULL, $adminModel = NULL, $shopModel = NULL)
- {
- $this->orderid = $orderid;
-
- if ($orderModel)
- {
- $this->orderModel = $orderModel;
- }
- else
- {
- $this->orderModel = LewaimaiOrder::model()->findByPk($orderid);
- if (!$this->orderModel)
- {
- Yii::log("not this order! SendOrderNotify failed!");
- return ;
- }
- }
-
- if ($adminModel)
- {
- $this->adminModel = $adminModel;
- }
- else
- {
- $this->adminModel = Admin::model()->findByPk($this->orderModel->admin_id);
- if (!$this->adminModel)
- {
- Yii::log("not found the admin_id! SendOrderNotify failed!");
- return ;
- }
- }
-
- if ($shopModel)
- {
- $this->shopModel = $shopModel;
- }
- else
- {
- $shop_id = $this->orderModel->shop_id;
- $this->shopModel = Config::model()->findByPk($shop_id);
- if (!$this->shopModel)
- {
- Yii::log("not found the shop! SendOrderNotify failed!");
- return ;
- }
- }
- //先处理打印机提醒
- if($this->adminModel->autoprinter)
- {
- $this->PrintNewOrder();
- }
-
- //再处理短信提醒
- $this->SendNewOrderSMS();
-
- //再处理EMAIL提醒
- $this->SendNewOrderEmail();
-
- //再处理微信订单提醒的问题
- $this->SendNewOrderWeixin();
-
- //发送APP提醒
- $url="http://appserver.lewaimai.com/index.php?r=order/push&order_id=" . $orderid;
- LewaimaiHttp::GET_ASYNC($url);
-
- //处理订单被打印机确认后的逻辑
- $this->HandOrderConfirmed();
- }
-
- public function PrinteOrderOnly($orderid, $orderModel = NULL, $adminModel = NULL, $shopModel = NULL)
- {
- $this->orderid = $orderid;
-
- if ($orderModel)
- {
- $this->orderModel = $orderModel;
- }
- else
- {
- $this->orderModel = LewaimaiOrder::model()->findByPk($orderid);
- if (!$this->orderModel)
- {
- Yii::log("not this order! SendOrderNotify failed!");
- return ;
- }
- }
-
- if ($adminModel)
- {
- $this->adminModel = $adminModel;
- }
- else
- {
- $this->adminModel = Admin::model()->findByPk($this->orderModel->admin_id);
- if (!$this->adminModel)
- {
- Yii::log("not found the admin_id! SendOrderNotify failed!");
- return ;
- }
- }
-
- if ($shopModel)
- {
- $this->shopModel = $shopModel;
- }
- else
- {
- $shop_id = $this->orderModel->shop_id;
- $this->shopModel = Config::model()->findByPk($shop_id);
- if (!$this->shopModel)
- {
- Yii::log("not found the shop! SendOrderNotify failed!");
- return ;
- }
- }
-
- $this->PrintNewOrder();
- }
-
- public function SendCancelOrderNotify($orderid, $orderModel = NULL, $adminModel = NULL, $shopModel = NULL)
- {
- $this->orderid = $orderid;
-
- if ($orderModel)
- {
- $this->orderModel = $orderModel;
- }
- else
- {
- $this->orderModel = LewaimaiOrder::model()->findByPk($orderid);
- if (!$this->orderModel)
- {
- Yii::log("not this order! SendOrderNotify failed!");
- return ;
- }
- }
-
- if ($adminModel)
- {
- $this->adminModel = $adminModel;
- }
- else
- {
- $this->adminModel = Admin::model()->findByPk($this->orderModel->admin_id);
- if (!$this->adminModel)
- {
- Yii::log("not found the admin_id! SendOrderNotify failed!");
- return ;
- }
- }
-
- if ($shopModel)
- {
- $this->shopModel = $shopModel;
- }
- else
- {
- $shop_id = $this->orderModel->shop_id;
- $this->shopModel = Config::model()->findByPk($shop_id);
- if (!$this->shopModel)
- {
- Yii::log("not found the shop! SendOrderNotify failed!");
- return ;
- }
- }
-
- //处理打印机,对于取消的订单,不管是否开启自动打印,都要打印
- $this->PrintCancelOrder();
-
- //再处理短信提醒
- $this->SendCancelOrderSMS();
-
- //再处理EMAIL提醒
- $this->SendCancelOrderEmail();
-
- //再处理微信订单提醒的问题
- $this->SendCancelOrderWeixin();
- }
-
- public function SendPointPrizeOrderNotify($orderid)
- {
- $this->orderid = $orderid;
-
- $this->orderModel = LewaimaiPointprizeOrder::model()->findByPk($orderid);
- if (!$this->orderModel)
- {
- Yii::log("not this order! SendPointPrizeOrderNotify failed!");
- return ;
- }
-
- $adminId = $this->orderModel->admin_id;
- $this->pointsetModel = PointSet::model()->findByPk($adminId);
- if (!$this->pointsetModel)
- {
- Yii::log("not pointsetModel! SendPointPrizeOrderNotify failed!");
- return ;
- }
-
- if ($this->pointsetModel->is_printer)
- {
- //处理打印机
- $this->PrintPointPrizeOrder();
- }
-
- //处理短信提醒
- $this->SendPointPrizeOrderSMS();
-
- //处理邮件提醒
- $this->SendPointPrizeOrderEmail();
-
- //处理微信提醒
- $this->SendPointPrizeOrderWeixin();
- }
-
- //这个是处理自由打印
- public function PrintShopContent($shop_id, $content)
- {
- $shopprinterModels = ShopPrinter::model()->findAll("shop_id = " . $shop_id);
-
- foreach ($shopprinterModels as $shopprinterModel)
- {
- $printer_id = $shopprinterModel->printer_id;
-
- $printerModel = Printer::model()->findByPk($printer_id);
- if (!$printerModel)
- {
- continue;
- }
-
- $printer_type = $printerModel->printer_type;
-
- $lewaimai_sn = $printerModel->lewaimai_sn;
-
- $member_code = $printerModel->member_code;
- $feyin_key = $printerModel->feyin_key;
- $device_no = $printerModel->device_no;
-
- $shopcode = $printerModel->shopcode;
-
- $printer_num = $printerModel->printer_num;
- $printer_info = $printerModel->printer_info;
-
- $is_cut = $printerModel->is_cut;
-
- $big_ordernum = $printerModel->big_ordernum;
- $big_name = $printerModel->big_name;
- $big_phone = $printerModel->big_phone;
- $big_address = $printerModel->big_address;
- $big_content = $printerModel->big_content;
- $big_price = $printerModel->big_price;
-
- if ($printer_type == 1 || $printer_type == 2)
- {
- for ($i = 0; $i < $printer_num; $i++)
- {
- $content = $content . $returnString;
- if ($i != $printer_num - 1)
- {
- $content = $content . "\r\n\r\n\r\n";
- }
- }
- }
- elseif ($printer_type == 3)
- {
- if ($is_cut)
- {
- $content = "<1B40><1B40><1B40>" . $content . "<0D0A><0D0A><0D0A><0D0A><0D0A><0D0A>" . "<1D5642000A0A>";
- }
- else
- {
- $content = "<1B40><1B40><1B40>" . $content . "<0D0A><0D0A><0D0A><0D0A><0D0A><0D0A><0D0A><0D0A>";
- }
- }
-
- if ($printer_type == 1)
- {
- $this->SendFeyinPrinterMessage($member_code, $device_no, $feyin_key, $content);
- }
- elseif ($printer_type == 2)
- {
- $this->SendKeLaiLePrinterMessage($shopcode, $content);
- }
- elseif ($printer_type == 3)
- {
- $this->SendLewaimaiPrinterMessage(1, $lewaimai_sn, $printer_num, $content);
- }
- }
- }
-
- private function PrintNewOrder()
- {
- $shopprinterModels = ShopPrinter::model()->findAll("shop_id = " . $this->shopModel->id);
-
- foreach ($shopprinterModels as $shopprinterModel)
- {
- $printer_id = $shopprinterModel->printer_id;
-
- $printerModel = Printer::model()->findByPk($printer_id);
- if (!$printerModel)
- {
- continue;
- }
-
- $printer_type = $printerModel->printer_type;
-
- $autoconfirmed = $printerModel->autoconfirmed;
- if($autoconfirmed && ($printer_type == 1 || $printer_type == 2))
- {
- $this->IsPrinterConfirmed = true;
- }
-
- $lewaimai_sn = $printerModel->lewaimai_sn;
-
- $member_code = $printerModel->member_code;
- $feyin_key = $printerModel->feyin_key;
- $device_no = $printerModel->device_no;
-
- $shopcode = $printerModel->shopcode;
-
- $printer_num = $printerModel->printer_num;
- $printer_info = $printerModel->printer_info;
-
- $is_cut = $printerModel->is_cut;
-
- $big_ordernum = $printerModel->big_ordernum;
- $big_name = $printerModel->big_name;
- $big_phone = $printerModel->big_phone;
- $big_address = $printerModel->big_address;
- $big_content = $printerModel->big_content;
- $big_price = $printerModel->big_price;
-
- if ($printer_type == 1)
- {
- $content = $this->GetPrinterOrderContent(2, $printer_num, $printer_info, $is_cut, $big_ordernum, $big_name, $big_phone, $big_address, $big_content, $big_price);
- $this->SendFeyinPrinterMessage($member_code, $device_no, $feyin_key, $content);
- }
- elseif ($printer_type == 2)
- {
- $content = $this->GetPrinterOrderContent(3, $printer_num, $printer_info, $is_cut, $big_ordernum, $big_name, $big_phone, $big_address, $big_content, $big_price);
- $this->SendKeLaiLePrinterMessage($shopcode, $content, $this->orderid, $this->orderModel->total_price, $this->orderModel->charge_type);
- }
- elseif ($printer_type == 3)
- {
- $content = $this->GetPrinterOrderContent(1, $printer_num, $printer_info, $is_cut, $big_ordernum, $big_name, $big_phone, $big_address, $big_content, $big_price);
- $this->SendLewaimaiPrinterMessage($this->orderid, $lewaimai_sn, $printer_num, $content);
- }
- }
- }
-
- //处理短信订单提醒
- private function SendNewOrderSMS()
- {
- $smsvalid = $this->shopModel->smsvalid;
- if ($smsvalid)
- {
- $sms_phone = $this->shopModel->sms_phone;
-
- $OrderString = $this->GetNewOrderSMSString();
- $OrderStringLen = mb_strlen($OrderString, 'utf8');
- $OrderStringLen = $OrderStringLen + 6; //加上【乐外卖】的长度
- $StringQuota = ceil($OrderStringLen/67);
-
- $sms_quota = $this->adminModel->sms_quota;
- if ($sms_quota - $StringQuota >= 0)
- {
- $smsString = $OrderString . "\n" . '发送"#' . $this->orderid . '"确认此订单。';
- if (LewaimaiHttp::SendSMSMessage($sms_phone, $smsString))
- {
- /*更新短信余额*/
- $connection = Yii::app()->db;
- $sql = "UPDATE wx_admin SET sms_quota = sms_quota - {$StringQuota} WHERE id = " . $this->adminModel->id;
- $command = $connection->createCommand($sql);
- $command->execute();
-
- /*短信历史记录*/
- $phoneMessageHistory = new LewaimaiPhoneMessageHistory();
- $phoneMessageHistory->admin_id = $this->orderModel->admin_id;
- $phoneMessageHistory->lewaimai_customer_id = $this->orderModel->lewaimai_customer_id;
- $phoneMessageHistory->type = 1;
- $phoneMessageHistory->phone = $sms_phone;
- $phoneMessageHistory->content = $OrderString;
- $phoneMessageHistory->order_id = $this->orderid;
- $phoneMessageHistory->number = $StringQuota;
- $phoneMessageHistory->save();
- }
- }
- }
- }
-
- //获取短信内容提醒
- private function GetNewOrderSMSString()
- {
- $shopname = $this->shopModel->shopname;
- $OrderString = "“" . $shopname . "”订单 :\n";
-
- $mergeModel = LewaimaiMergeOrderSet::model()->find('admin_id='.$this->orderModel->admin_id.' and shop_id='.$this->orderModel->shop_id);
- if ($this->adminModel->order_num_type == 0)
- {
- $orderNo = $this->orderModel->admin_num;
- }
- else
- {
- $orderNo = $this->shopModel->order_prefix . $this->orderModel->shop_num;
- }
-
- if ($this->orderCount)
- {
- $orderCount = $this->orderCount;
- }
- else
- {
- if($this->shopModel->showordernum_type == 0)
- {
- //计算是第几次下单
- $orderCount = LewaimaiOrder::model()->count("admin_id = " . $this->orderModel->admin_id . " AND lewaimai_customer_id = " . $this->orderModel->lewaimai_customer_id . " AND shop_id = " . $this->orderModel->shop_id ." AND order_status IN ('CONFIRMED','SUCCEEDED','OPEN','CANCELLED','FAILED')");
- }
- else
- {
- $orderCount = LewaimaiOrder::model()->count("admin_id = " . $this->orderModel->admin_id . " AND lewaimai_customer_id = " . $this->orderModel->lewaimai_customer_id . " AND order_status IN ('CONFIRMED','SUCCEEDED','OPEN','CANCELLED','FAILED')");
- }
- }
-
- //判断该顾客是不是店铺的会员
- $memberModel = LewaimaiMember::model()->find("lewaimai_customer_id = " . $this->orderModel->lewaimai_customer_id . " AND admin_id = " . $this->orderModel->admin_id);
- if($this->shopModel->showordernum == 1)
- {
- if ($memberModel)
- {
- $OrderString .= "(会员,第" . $orderCount . "次下单)\n";
- }
- else
- {
- $OrderString .= "(第" . $orderCount . "次下单)\n";
- }
- }
-
- $OrderString .= "订单编号:" . $orderNo . "\n";
-
- if($mergeModel and $mergeModel->is_open == 1)
- {
- if($this->orderModel->mergeorder_id > 0)
- {
- $OrderString .= "是否是拼单:是\n";
- $mergeorderModel = LewaimaiMergeOrder::model() -> findByPk($this->orderModel->mergeorder_id);
- $OrderString .= "拼单名字:".$mergeorderModel->name."\n";
- $OrderString .= "拼单人数:".$mergeorderModel->nownum."\n";
- $OrderString .= "拼单折扣:".$this->orderModel->mergeorder_discount."\n";
- }
- else
- {
- $OrderString .= "是否是拼单:不是\n";
- }
- }
-
- $orderItemModels = LewaimaiOrderItem::model()->findAll("lewaimai_order_id = " . $this->orderid);
- foreach ($orderItemModels as $orderItem)
- {
- $newOrderString = $orderItem->food_name . " " . $orderItem->quantity . "份" . " ¥" . sprintf("%.1f", $orderItem->quantity * $orderItem->price) . "\n";
-
- $OrderString = $OrderString . $newOrderString;
- }
- $fieldString = '';
- $order_field = unserialize($this->orderModel->order_field);
- foreach($order_field as $key => $val)
- {
- $fieldString .= $val["name"] . ":" . $val["content"] . "\n";
- }
-
- $delivertime = $this->orderModel->delivertime;
- $delivertimeinfo = '';
- if($delivertime)
- {
- $delivertimeinfo = '配送时间: '.$this->orderModel->delivery_date.' '.$delivertime . "\n";
- }
-
- if($this->shopModel->open_selftake)
- {
- if($this->orderModel->is_selftake)
- {
- $quhuofangshi = "配送方式:到店自取\n";
- }
- else
- {
- $quhuofangshi = "配送方式:店家配送\n";
- }
- }
- else
- {
- $quhuofangshi = '';
- }
-
- $nameinfo = "姓名:" . $this->orderModel->nickname . "\n";
- $phoneinfo = "电话:" . $this->orderModel->phone . "\n";
- $addressinfo = "地址:" . $this->orderModel->address . "\n";
-
- if ($this->orderModel->memo && $this->orderModel->memo != "")
- {
- $noteinfo = "备注:" . $this->orderModel->memo . "\n";
- }
- else
- {
- $noteinfo = "";
- }
-
- if ($this->orderModel->is_member_delete)
- {
- $member_delete_info = "会员优惠:" . $this->orderModel->member_delete . "元" . "\n";
- }
- else
- {
- $member_delete_info = "";
- }
-
- if($this->orderModel->promotion)
- {
- $promotion = explode(':',$this->orderModel->promotion);
- $promotioninfo = '满'.$promotion[0].'元,减'.$promotion[1].'元'."\n";
- }
- else
- {
- $promotioninfo = '';
- }
-
- if ($this->orderModel->is_discount == 1)
- {
- $discountInfo = "店铺折扣:" . $this->orderModel->discount_value . "折" . "\n";
- }
- else
- {
- $discountInfo = "";
- }
-
- if ($this->orderModel->delivery_fee != 0)
- {
- $delivery_fee_info = "外送费:¥" . $this->orderModel->delivery_fee . "\n";
- }
- else
- {
- $delivery_fee_info = "";
- }
-
- $addservicestring = "";
- $addservice = unserialize($this->orderModel->addservice);
- if(is_array($addservice))
- {
- foreach($addservice as $addservicekey => $addserviceval)
- {
- $addservicestring .= $addservicekey.':'.$addserviceval."元\n";
- }
- }
-
- if ($this->orderModel->is_coupon == 1)
- {
- $couponInfo = "优惠券:" . $this->orderModel->coupon_value . "元" . "\n ";
- }
- else
- {
- $couponInfo = "";
- }
-
- $totalpriceInfo = "合计:¥" . $this->orderModel->total_price;
-
- if ($this->orderModel->charge_type == 1)
- {
- $totalpriceInfo = $totalpriceInfo . "(未付款)";
- }
- else
- {
- $totalpriceInfo = $totalpriceInfo . "(已付款)";
- }
-
- $OrderString = $OrderString .$quhuofangshi. $nameinfo . $phoneinfo . $addressinfo . $fieldString . $delivertimeinfo . $noteinfo . $member_delete_info .$promotioninfo. $discountInfo . $delivery_fee_info . $addservicestring . $couponInfo . $totalpriceInfo;
-
- return $OrderString;
- }
-
- //发送取消订单的短信提醒
- private function SendCancelOrderSMS()
- {
- $smsvalid = $this->shopModel->smsvalid;
- if ($smsvalid)
- {
- $sms_phone = $this->shopModel->sms_phone;
-
- $OrderString = $this->GetCancelOrderSMSString();
- $OrderStringLen = mb_strlen($OrderString, 'utf8');
- $OrderStringLen = $OrderStringLen + 6; //加上【乐外卖】的长度
- $StringQuota = ceil($OrderStringLen/67);
-
- $sms_quota = $this->adminModel->sms_quota;
- if ($sms_quota - $StringQuota >= 0)
- {
- $smsString = $OrderString . "\n" . '发送"#' . $this->orderid . '"确认此订单。';
- if (LewaimaiHttp::SendSMSMessage($sms_phone, $smsString))
- {
- /*更新短信余额*/
- $connection = Yii::app()->db;
- $sql = "UPDATE wx_admin SET sms_quota = sms_quota - {$StringQuota} WHERE id = " . $this->adminModel->id;
- $command = $connection->createCommand($sql);
- $command->execute();
-
- /*短信历史记录*/
- $phoneMessageHistory = new LewaimaiPhoneMessageHistory();
- $phoneMessageHistory->admin_id = $this->orderModel->admin_id;
- $phoneMessageHistory->lewaimai_customer_id = $this->orderModel->lewaimai_customer_id;
- $phoneMessageHistory->type = 4;
- $phoneMessageHistory->phone = $sms_phone;
- $phoneMessageHistory->content = $OrderString;
- $phoneMessageHistory->order_id = $this->orderid;
- $phoneMessageHistory->number = $StringQuota;
- $phoneMessageHistory->save();
- }
- }
- }
- }
-
- private function SendPointPrizeOrderSMS()
- {
- //判断是否发短信
- $smsvalid = $this->pointsetModel->is_duanxin;
- if (!$smsvalid)
- {
- return ;
- }
-
- $sms_phone = $this->pointsetModel->iphone;
-
- $OrderString = $this->GetPointPrizeOrderSMSString();
- $OrderStringLen = mb_strlen($OrderString,'utf8');
- $OrderStringLen = $OrderStringLen + 6; //加上【乐外卖】的长度
-
- $StringQuota = ceil($OrderStringLen/67);
-
- $adminModel = Admin::model()->findByPk($this->orderModel->admin_id);
- if ($adminModel)
- {
- $sms_quota = $adminModel->sms_quota;
- if ($sms_quota - $StringQuota >= 0){
- if (LewaimaiHttp::SendSMSMessage($sms_phone, $OrderString)) {
- /*更新短信余额*/
- $connection = Yii::app()->db;
- $sql = "UPDATE wx_admin SET sms_quota = sms_quota - {$StringQuota} WHERE id = " . $adminModel->id;
- $command = $connection->createCommand($sql);
- $command->execute();
-
- /*短信历史记录*/
- $phoneMessageHistory = new LewaimaiPhoneMessageHistory();
- $phoneMessageHistory->admin_id = $this->orderModel->admin_id;
- $phoneMessageHistory->lewaimai_customer_id = $this->orderModel->lewaimai_customer_id;
- $phoneMessageHistory->type = 5;
- $phoneMessageHistory->phone = $sms_phone;
- $phoneMessageHistory->content = $OrderString;
- $phoneMessageHistory->order_id = $this->orderid;
- $phoneMessageHistory->number = $StringQuota;
- $phoneMessageHistory->save();
- }
- }
- }
- }
-
- //处理打印机自动确认后的订单状态问题
- private function HandOrderConfirmed()
- {
- if (!$this->IsPrinterConfirmed)
- {
- return ;
- }
-
- //将订单改为确认状态
- $connection = Yii::app()->db;
- $sql = "UPDATE wx_lewaimai_order SET order_status = 'CONFIRMED' WHERE id = " . $this->orderid;
- $command = $connection->createCommand($sql);
- $command->execute();
-
- //给顾客发送订单确认的短信提醒
- $this->SendOrderConfirmedSMS();
-
- //给顾客发送订单确认的模板消息通知
- LewaimaiWeixinTemplate::SendOrderConfirmedTemplate($this->orderid, $this->orderModel);
-
- //处理订单确认后的商品销量问题
- $this->OrderConfirmedAddFoodSales();
- }
-
- //给顾客发送订单确认的短信提醒
- private function SendOrderConfirmedSMS()
- {
- //处理打印机确认订单时候的短信提醒问题
- if($this->adminModel->is_confirm_msg == 1)
- {
- $sms_quota = $this->adminModel->sms_quota;
-
- $content = $this->shopModel->confirmmsg;
- $ContentStringLen = mb_strlen($content,'utf8');
- $ContentStringLen = $ContentStringLen + 6;
- $StringQuota = ceil($ContentStringLen/67);
- if($sms_quota - $StringQuota >= 0)
- {
- if(LewaimaiHttp::SendSMSMessage($this->orderModel->phone, $content))
- {
- /*更新短信余额*/
- $connection = Yii::app()->db;
- $sql = "UPDATE wx_admin SET sms_quota = sms_quota - {$StringQuota} WHERE id = " . $this->adminModel->id;
- $command = $connection->createCommand($sql);
- $command->execute();
-
- /*短信历史记录*/
- $phoneMessageHistory = new LewaimaiPhoneMessageHistory();
- $phoneMessageHistory->admin_id = $this->adminModel->id;
- $phoneMessageHistory->type = 3;
- $phoneMessageHistory->phone = $this->orderModel->phone;
- $phoneMessageHistory->content = $content;
- $phoneMessageHistory->order_id = $this->orderid;
- $phoneMessageHistory->number = $StringQuota;
- $phoneMessageHistory->save();
- }
- }
- }
- }
-
- //修改商品的销量
- private function OrderConfirmedAddFoodSales()
- {
- $fooditemlist = LewaimaiOrderItem::model()->findAll("lewaimai_order_id='$this->orderid'");
- $time = strtotime(date('Y-m-d H:i:s'));
- $todaystart = strtotime(date('Y-m-d'));
-
- foreach($fooditemlist as $fooditem)
- {
- $foodModel = Food::Model()->findByPk($fooditem->food_id);
- if($foodModel)
- {
- $foodModel->ordered_count += $fooditem->quantity;
- if($todaystart > $foodModel->lastsaletime)
- {
- $foodModel->todaysales = $fooditem->quantity;
- $foodModel->lastsaletime = $time;
- }
- else
- {
- $foodModel->todaysales += $fooditem->quantity;
- }
-
- if(!$foodModel->save())
- {
- foreach ($foodModel->errors as $key => $value)
- {
- foreach ($value as $valuestring);
- {
- Yii::log("food Model valuestring:" . $valuestring);
- }
- }
- }
- }
- }
- }
-
- private function GetCancelOrderSMSString()
- {
- $shopname = $this->shopModel->shopname;
- $OrderString = "***订单取消通知***\n“" . $shopname . "”的一笔订单已被顾客取消,订单信息如下:\n";
-
- $adminModel = $this->adminModel;
- $mergeModel = LewaimaiMergeOrderSet::model()->find('admin_id='.$this->orderModel->admin_id.' and shop_id='.$this->orderModel->shop_id);
- if ($adminModel->order_num_type == 0)
- {
- $orderNo = $this->orderModel->admin_num;
- }
- else
- {
- $orderNo = $this->shopModel->order_prefix . $this->orderModel->shop_num;
- }
-
- if ($this->orderCount)
- {
- $orderCount = $this->orderCount;
- }
- else
- {
- if($this->shopModel->showordernum_type == 0)
- {
- //计算是第几次下单
- $orderCount = LewaimaiOrder::model()->count("admin_id = " . $this->orderModel->admin_id . " AND lewaimai_customer_id = " . $this->orderModel->lewaimai_customer_id . " AND shop_id = " . $this->orderModel->shop_id ." AND order_status IN ('CONFIRMED','SUCCEEDED','OPEN','CANCELLED','FAILED')");
- }
- else
- {
- $orderCount = LewaimaiOrder::model()->count("admin_id = " . $this->orderModel->admin_id . " AND lewaimai_customer_id = " . $this->orderModel->lewaimai_customer_id . " AND order_status IN ('CONFIRMED','SUCCEEDED','OPEN','CANCELLED','FAILED')");
- }
- }
-
- //判断该顾客是不是店铺的会员
- $memberModel = LewaimaiMember::model()->find("lewaimai_customer_id = " . $this->orderModel->lewaimai_customer_id . " AND admin_id = " . $this->orderModel->admin_id);
- if($this->shopModel->showordernum == 1)
- {
- if ($memberModel)
- {
- $OrderString .= "(会员,第" . $orderCount . "次下单)\n";
- }
- else
- {
- $OrderString .= "(第" . $orderCount . "次下单)\n";
- }
- }
-
- $OrderString .= "订单编号:" . $orderNo . "\n";
-
- if($mergeModel and $mergeModel->is_open==1)
- {
- if($this->orderModel->mergeorder_id > 0)
- {
- $OrderString .= "是否是拼单:是\n";
- $mergeorderModel = LewaimaiMergeOrder::model() -> findByPk($this->orderModel->mergeorder_id);
- $OrderString .= "拼单名字:".$mergeorderModel->name."\n";
- $OrderString .= "拼单人数:".$mergeorderModel->nownum."\n";
- $OrderString .= "拼单折扣:".$this->orderModel->mergeorder_discount."\n";
- }
- else
- {
- $OrderString .= "是否是拼单:不是\n";
- }
- }
- $ordertime = "下单时间:" . $this->orderModel->init_date . "\n";
-
- $fieldString = '';
- $order_field = unserialize($this->orderModel->order_field);
- foreach($order_field as $key => $val)
- {
- $fieldString .= $val["name"] . ":" . $val["content"] . "\n";
- }
-
- $delivertime = $this->orderModel->delivertime;
- $delivertimeinfo = '';
- if($delivertime)
- {
- $delivertimeinfo = '配送时间: '.$this->orderModel->delivery_date.' '.$delivertime. "\n";
- }
-
- if($this->shopModel->open_selftake)
- {
- if($this->orderModel->is_selftake)
- {
- $quhuofangshi = "配送方式:到店自取\n";
- }
- else
- {
- $quhuofangshi = "配送方式:店家配送\n";
- }
- }
- else
- {
- $quhuofangshi = '';
- }
-
- $nameinfo = "姓名:" . $this->orderModel->nickname . "\n";
- $phoneinfo = "电话:" . $this->orderModel->phone . "\n";
- $addressinfo = "地址:" . $this->orderModel->address . "\n";
-
- $totalpriceInfo = "合计:¥" . $this->orderModel->total_price;
-
- if ($this->orderModel->charge_type == 1)
- {
- $totalpriceInfo = $totalpriceInfo . "(未付款)\n";
- }
- elseif ($this->orderModel->charge_type == 2)
- {
- $totalpriceInfo = $totalpriceInfo . "(余额付款)\n";
- }
- else
- {
- $totalpriceInfo = $totalpriceInfo . "(在线支付)\n";
- }
-
- $CancelOrderString = $OrderString . $quhuofangshi.$ordertime . $nameinfo . $phoneinfo . $addressinfo . $fieldString . $delivertimeinfo . $totalpriceInfo;
-
- return $CancelOrderString;
- }
-
- private function GetPointPrizeOrderSMSString()
- {
- $OrderString = "积分兑奖通知 :\n";
-
- $orderItemModels = LewaimaiPointprizeOrderItem::model()->findAll("lewaimai_order_id = " . $this->orderModel->id);
- foreach ($orderItemModels as $orderItem)
- {
- $newOrderString = $orderItem->prize_name . " " . $orderItem->quantity . "份" . "\n";
-
- $OrderString = $OrderString . $newOrderString;
- }
-
- $nameinfo = "姓名:" . $this->orderModel->name . "\n";
- $phoneinfo = "电话:" . $this->orderModel->phone . "\n";
- $addressinfo = "地址:" . $this->orderModel->address . "\n";
-
- $noteinfo = "备注:" . $this->orderModel->memo . "\n";
-
- $OrderString = $OrderString . $nameinfo . $phoneinfo . $addressinfo . $noteinfo;
-
- return $OrderString;
- }
-
- private function SendNewOrderEmail()
- {
- //判断是否发邮件
- $emailvalid = $this->shopModel->emailvalid;
- if (!$emailvalid)
- {
- return ;
- }
-
- $email_address = $this->shopModel->email_address;
-
- $adminId = $this->orderModel->admin_id;
- $shopId = $this->orderModel->shop_id;
- $orderModel = $this->orderModel;
-
- $nickname = $this->orderModel->nickname;
- $phone = $this->orderModel->phone;
- $address = $this->orderModel->address;
- $note = $this->orderModel->memo;
-
- $totalPrice = $this->orderModel->total_price;
- $delivery_fee = $this->orderModel->delivery_fee;
- $order_field = $this->orderModel->order_field;
- $delivertime = $this->orderModel->delivertime;
-
- $receiveEmail = $email_address;
- $receiveName = '';
-
- $mergeModel = LewaimaiMergeOrderSet::model()->find('admin_id='.$this->orderModel->admin_id.' and shop_id='.$this->orderModel->shop_id);
- $mergeString = '';
- if($mergeModel and $mergeModel->is_open==1)
- {
- if($this->orderModel->mergeorder_id > 0)
- {
- $mergeorderModel = LewaimaiMergeOrder::model() -> findByPk($this->orderModel->mergeorder_id);
- $mergeString = '
- <tr>
- <td><strong>是否是拼单:</strong></td>
- <td>是</td>
- </tr>';
- $mergeString .= '
- <tr>
- <td><strong>拼单名字:</strong></td>
- <td>'.$mergeorderModel->name.'</td>
- </tr>';
- $mergeString .= '
- <tr>
- <td><strong>拼单人数:</strong></td>
- <td>'.$mergeorderModel->nownum.'</td>
- </tr>';
- $mergeString .= '
- <tr>
- <td><strong>拼单折扣:</strong></td>
- <td>'.$this->orderModel->mergeorder_discount.'</td>
- </tr>';
- }
- else
- {
- $mergeString = '
- <tr>
- <td><strong>是否是拼单:</strong></td>
- <td>不是</td>
- </tr>';
- }
- }
-
- // 获取店铺名字
- $shopModel = $this->shopModel;
-
- if ($this->orderCount)
- {
- $orderCount = $this->orderCount;
- }
- else
- {
- //计算是第几次下单
- if($shopModel->showordernum_type == 0)
- {
- $orderCount = LewaimaiOrder::model()->count("admin_id = " . $this->orderModel->admin_id . " AND lewaimai_customer_id = " . $this->orderModel->lewaimai_customer_id . " AND shop_id = " . $this->orderModel->shop_id ." AND order_status IN ('CONFIRMED','SUCCEEDED','OPEN','CANCELLED','FAILED')");
- }
- else
- {
- $orderCount = LewaimaiOrder::model()->count("admin_id = " . $this->orderModel->admin_id . " AND lewaimai_customer_id = " . $this->orderModel->lewaimai_customer_id . " AND order_status IN ('CONFIRMED','SUCCEEDED','OPEN','CANCELLED','FAILED')");
- }
- }
-
- $shopname = $shopModel->shopname;
-
- if($shopModel->open_selftake)
- {
- if($this->orderModel->is_selftake)
- {
- $quhuofangshi = '
- <tr>
- <td><strong>配送方式:</strong></td>
- <td>到店自取</td>
- </tr>';
- }
- else
- {
- $quhuofangshi = '
- <tr>
- <td><strong>配送方式:</strong></td>
- <td>店家配送</td>
- </tr>';
- }
- }
- else
- {
- $quhuofangshi = '';
- }
-
- // 处理预设选项
- $order_field = unserialize($order_field);
- $fieldString = "";
- foreach($order_field as $key => $val)
- {
- $fieldString .= '
- <tr>
- <td valign="top"><strong>' . $val["name"] . ':</strong></td>
- <td>' . $val["content"] . '</td>
- </tr>';
- }
-
- $DefaultOrderString = '
- <tr>
- <td><strong>订单详情:</strong></td>
- <td></td>
- </tr>';
-
- $orderItemModels = LewaimaiOrderItem::model()->findAll("lewaimai_order_id = " . $orderModel->id);
- if (!$orderItemModels)
- {
- $OrderString = $DefaultOrderString;
- }
- elseif (count($orderItemModels) == 1)
- {
- $orderItemModel = $orderItemModels[0];
- $OrderString = '
- <tr>
- <td><strong>订单详情:</strong></td>
- <td>' . $orderItemModel->food_name . " " . $orderItemModel->quantity . "份" . " ¥" . sprintf("%.1f", $orderItemModel->quantity*$orderItemModel->price) . '</td>
- </tr>';
- }
- else
- {
- $orderItemModel = $orderItemModels[0];
- $OrderString = '
- <tr>
- <td><strong>订单详情:</strong></td>
- <td>' . $orderItemModel->food_name . " " . $orderItemModel->quantity . "份" . " ¥" . sprintf("%.1f", $orderItemModel->quantity*$orderItemModel->price) . '</td>
- </tr>';
-
- for ($i = 1; $i < count($orderItemModels); $i++)
- {
- $orderItemModel = $orderItemModels[$i];
-
- $newOrderString = '
- <tr>
- <td></td>
- <td>' . $orderItemModel->food_name . " " . $orderItemModel->quantity . "份" . " ¥" . sprintf("%.1f", $orderItemModel->quantity*$orderItemModel->price) . '</td>
- </tr>';
-
- $OrderString = $OrderString . $newOrderString;
- }
- }
- $adminModel = $this->adminModel;
- if ($adminModel->order_num_type == 0)
- {
- $orderNo = $orderModel->admin_num;
- }
- else
- {
- $orderNo = $shopModel->order_prefix . $orderModel->shop_num;
- }
-
- $deliverinfo = "";
- if($delivertime)
- {
- $deliverinfo = '<tr><td><strong>配送时间:</strong></td><td>'.$orderModel->delivery_date.' '.$delivertime.'</td></tr>';
- }
-
- //判断该顾客是不是店铺的会员
- $memberModel = LewaimaiMember::model()->find("lewaimai_customer_id = " . $this->orderModel->lewaimai_customer_id . " AND admin_id = " . $this->orderModel->admin_id);
- if($shopModel->showordernum == 1)
- {
- if ($memberModel)
- {
- $nickname .= "(会员,第" . $orderCount . "次下单)";
- }
- else
- {
- $nickname .= "(第" . $orderCount . "次下单)";
- }
- }
- $Subject = '您有一笔乐外卖新订单,请尽快处理!';
- $Content = '
- <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
- <html xmlns="http://www.w3.org/1999/xhtml">
- <head>
- <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
- <title>无标题文档</title>
- <style type="text/css">
- body,td,th {
- font-size: 18px;
- }
- .price {
- color: #F00;
- }
- </style>
- </head>
-
- <body>
- <table width="100%" align="center">
- <tr>
- <td colspan="2" align="center"><h1><strong>乐外卖订单信息</strong></h1>
- <hr /></td>
- </tr>
- <tr>
- <td width="100"><strong>订单编号:</strong></td>
- <td>' . $orderNo . '</td>
- </tr>'
- .$mergeString.
- '<tr>
- <td><strong>店铺名称:</strong></td>
- <td>' . $shopname . '</td>
- </tr>
- '.$quhuofangshi.'
- <tr>
- <td><strong>姓名:</strong></td>
- <td>' . $nickname . '</td>
- </tr>
-
- <tr>
- <td><strong>电话:</strong></td>
- <td>' . $phone . '</td>
- </tr>
-
- <tr>
- <td valign="top"><strong>地址:</strong></td>
- <td>' . $address . '</td>
- </tr>' .
-
- $fieldString .
- $deliverinfo .
-
- '<tr>
- <td><strong>下单时间:</strong></td>
- <td>' . date("Y-m-d H:i:s") . '</td>
- </tr>
-
- ' . $OrderString . '
-
- <tr>
- <td valign="top"><strong>备注:</strong></td>
- <td>' . $note . '</td>
- </tr>
- ';
-
- if ($orderModel->is_member_delete)
- {
- $memberdeleteInfo = '
- <tr>
- <td><strong>会员优惠:</strong></td>
- <td>' . $orderModel->member_delete . '元</td>
- </tr>';
- }
- else
- {
- $memberdeleteInfo = "";
- }
-
- if($orderModel->promotion)
- {
- $promotion = explode(':',$orderModel->promotion);
- $promotioninfo = '
- <tr>
- <td><strong></strong></td>
- <td>满' . $promotion[0] . '元送'.$promotion[1].'元</td>
- </tr>';
- }
- else
- {
- $promotioninfo = '';
- }
-
- if ($orderModel->is_discount == 1)
- {
- $discountInfo = '
- <tr>
- <td><strong>店铺折扣:</strong></td>
- <td>' . $orderModel->discount_value . '折</td>
- </tr>';
- }
- else
- {
- $discountInfo = "";
- }
-
- $delivery_fee_string = '
- <tr>
- <td><strong>外送费:</strong></td>
- <td>¥' . $delivery_fee . '</td>
- </tr>';
-
- if ($delivery_fee != 0)
- {
- $delivery_fee_info = $delivery_fee_string;
- }
- else
- {
- $delivery_fee_info = "";
- }
-
- $addservicestring = "";
- $addservice = unserialize($orderModel->addservice);
- if(is_array($addservice))
- {
- foreach($addservice as $addservicekey => $addserviceval)
- {
- $addservicestring .= '
- <tr>
- <td><strong>'.$addservicekey.':</strong></td>
- <td>' . $addserviceval . '元</td>
- </tr>';
- }
- }
- if ($orderModel->is_coupon == 1)
- {
- $couponInfo = '
- <tr>
- <td><strong>优惠券:</strong></td>
- <td>' . $orderModel->coupon_value . '元</td>
- </tr>';
- }
- else
- {
- $couponInfo = "";
- }
-
- if ($orderModel->charge_type == 1)
- {
- $totalpriceInfo = '
- <tr>
- <td><strong>总金额:</strong></td>
- <td><span class="price">¥' . $totalPrice . '</span>(未付款)</td>
- </tr>';
- }
- else
- {
- $totalpriceInfo = '
- <tr>
- <td><strong>总金额:</strong></td>
- <td><span class="price">¥' . $totalPrice . '</span>(已付款)</td>
- </tr>';
- }
- $Content = $Content . $memberdeleteInfo . $promotioninfo . $discountInfo . $delivery_fee_info . $addservicestring . $couponInfo . $totalpriceInfo .
- '</table>
- </body>
- </html>
- ';
-
- SendEmail($receiveEmail, $receiveName, $Subject, $Content);
- }
-
- private function SendNewOrderWeixin()
- {
- //判断是否发微信消息
- $weixinvalid = $this->shopModel->weixinvalid;
- if (!$weixinvalid)
- {
- return ;
- }
-
- LewaimaiWeixinTemplate::SendNewOrderTemplate($this->orderid, $this->orderModel, $this->shopModel);
- }
-
- private function SendCancelOrderWeixin()
- {
- //判断是否发微信消息
- $weixinvalid = $this->shopModel->weixinvalid;
- if (!$weixinvalid)
- {
- return ;
- }
-
- LewaimaiWeixinTemplate::SendCancelOrderTemplate($this->orderid, $this->orderModel, $this->shopModel);
- }
-
- private function SendPointPrizeOrderWeixin()
- {
- $weixinvalid = $this->pointsetModel->is_weixin;
- if (!$weixinvalid)
- {
- return ;
- }
-
- LewaimaiWeixinTemplate::SendPointPrizeOrderTemplate($this->orderModel->id, $this->orderModel, $this->pointsetModel, $this->GetPointPrizeOrderSMSString());
- }
-
- private function SendCancelOrderEmail()
- {
- $emailvalid = $this->shopModel->emailvalid;
- if (!$emailvalid)
- {
- return ;
- }
-
- $email_address = $this->shopModel->email_address;
-
- $adminId = $this->orderModel->admin_id;
- $shopId = $this->orderModel->shop_id;
- $orderModel = $this->orderModel;
- $nickname = $this->orderModel->nickname;
- $phone = $this->orderModel->phone;
- $address = $this->orderModel->address;
- $note = $this->orderModel->memo;
-
- $totalPrice = $this->orderModel->total_price;
- $delivery_fee = $this->orderModel->delivery_fee;
- $order_field = $this->orderModel->order_field;
- $delivertime = $this->orderModel->delivertime;
-
- $receiveEmail = $email_address;
-
- $mergeModel = LewaimaiMergeOrderSet::model()->find('admin_id='.$this->orderModel->admin_id.' and shop_id='.$this->orderModel->shop_id);
- $mergeString = '';
- if($mergeModel and $mergeModel->is_open==1)
- {
- if($this->orderModel->mergeorder_id > 0)
- {
- $mergeorderModel = LewaimaiMergeOrder::model() -> findByPk($this->orderModel->mergeorder_id);
- $mergeString = '
- <tr>
- <td><strong>是否是拼单:</strong></td>
- <td>是</td>
- </tr>';
- $mergeString .= '
- <tr>
- <td><strong>拼单名字:</strong></td>
- <td>'.$mergeorderModel->name.'</td>
- </tr>';
- $mergeString .= '
- <tr>
- <td><strong>拼单人数:</strong></td>
- <td>'.$mergeorderModel->nownum.'</td>
- </tr>';
- $mergeString .= '
- <tr>
- <td><strong>拼单折扣:</strong></td>
- <td>'.$this->orderModel->mergeorder_discount.'</td>
- </tr>';
- }
- else
- {
- $mergeString = '
- <tr>
- <td><strong>是否是拼单:</strong></td>
- <td>不是</td>
- </tr>';
- }
- }
-
- // 获取店铺名字
- $shopModel = $this->shopModel;
-
- if ($this->orderCount)
- {
- $orderCount = $this->orderCount;
- }
- else
- {
- if($this->shopModel->showordernum_type == 0)
- {
- //计算是第几次下单
- $orderCount = LewaimaiOrder::model()->count("admin_id = " . $this->orderModel->admin_id . " AND lewaimai_customer_id = " . $this->orderModel->lewaimai_customer_id . " AND shop_id = " . $this->orderModel->shop_id ." AND order_status IN ('CONFIRMED','SUCCEEDED','OPEN','CANCELLED','FAILED')");
- }
- else
- {
- $orderCount = LewaimaiOrder::model()->count("admin_id = " . $this->orderModel->admin_id . " AND lewaimai_customer_id = " . $this->orderModel->lewaimai_customer_id . " AND order_status IN ('CONFIRMED','SUCCEEDED','OPEN','CANCELLED','FAILED')");
- }
- }
-
- $receiveName = '';
- $shopname = $shopModel->shopname;
- if($shopModel->open_selftake){
- if($this->orderModel->is_selftake)
- {
- $quhuofangshi = '
- <tr>
- <td><strong>配送方式:</strong></td>
- <td>到店自取</td>
- </tr>';
- }
- else
- {
- $quhuofangshi = '
- <tr>
- <td><strong>配送方式:</strong></td>
- <td>店家配送</td>
- </tr>';
- }
- }
- else
- {
- $quhuofangshi = '';
- }
- // 处理预设选项
- $order_field = unserialize($order_field);
- $fieldString = "";
- foreach($order_field as $key => $val)
- {
- $fieldString .= '
- <tr>
- <td valign="top"><strong>' . $val["name"] . ':</strong></td>
- <td>' . $val["content"] . '</td>
- </tr>';
- }
-
- $DefaultOrderString = '
- <tr>
- <td><strong>订单详情:</strong></td>
- <td></td>
- </tr>';
-
- $orderItemModels = LewaimaiOrderItem::model()->findAll("lewaimai_order_id = " . $orderModel->id);
- if (!$orderItemModels)
- {
- $OrderString = $DefaultOrderString;
- }
- elseif (count($orderItemModels) == 1)
- {
- $orderItemModel = $orderItemModels[0];
- $OrderString = '
- <tr>
- <td><strong>订单详情:</strong></td>
- <td>' . $orderItemModel->food_name . " " . $orderItemModel->quantity . "份" . " ¥" . sprintf("%.1f", $orderItemModel->quantity*$orderItemModel->price) . '</td>
- </tr>';
- }
- else
- {
- $orderItemModel = $orderItemModels[0];
- $OrderString = '
- <tr>
- <td><strong>订单详情:</strong></td>
- <td>' . $orderItemModel->food_name . " " . $orderItemModel->quantity . "份" . " ¥" . sprintf("%.1f", $orderItemModel->quantity*$orderItemModel->price) . '</td>
- </tr>';
-
- for ($i = 1; $i < count($orderItemModels); $i++)
- {
- $orderItemModel = $orderItemModels[$i];
-
- $newOrderString = '
- <tr>
- <td></td>
- <td>' . $orderItemModel->food_name . " " . $orderItemModel->quantity . "份" . " ¥" . sprintf("%.1f", $orderItemModel->quantity*$orderItemModel->price) . '</td>
- </tr>';
-
- $OrderString = $OrderString . $newOrderString;
- }
- }
-
- $delivery_fee_string = '
- <tr>
- <td><strong>外送费:</strong></td>
- <td>¥' . $delivery_fee . '</td>
- </tr>';
-
- if ($delivery_fee != 0)
- {
- $delivery_fee_info = $delivery_fee_string;
- }
- else
- {
- $delivery_fee_info = "";
- }
-
- $adminModel = $this->adminModel;
- if ($adminModel->order_num_type == 0)
- {
- $orderNo = $orderModel->admin_num;
- }
- else
- {
- $orderNo = $shopModel->order_prefix . $orderModel->shop_num;
- }
- $deliverinfo = "";
- if($delivertime)
- {
- $deliverinfo = '<tr><td><strong>配送时间:</strong></td><td>'.$orderModel->delivery_date.' '.$delivertime.'</td></tr>';
- }
-
- //判断该顾客是不是店铺的会员
- $memberModel = LewaimaiMember::model()->find("lewaimai_customer_id = " . $this->orderModel->lewaimai_customer_id . " AND admin_id = " . $this->orderModel->admin_id);
- if($shopModel->showordernum == 1)
- {
- if ($memberModel)
- {
- $nickname .= "(会员,第" . $orderCount . "次下单)";
- }
- else
- {
- $nickname .= "(第" . $orderCount . "次下单)";
- }
- }
-
- $Subject = '乐外卖订单取消通知!';
- $Content = '
- <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
- <html xmlns="http://www.w3.org/1999/xhtml">
- <head>
- <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
- <title>无标题文档</title>
- <style type="text/css">
- body,td,th {
- font-size: 18px;
- }
- .price {
- color: #F00;
- }
- </style>
- </head>
-
- <body>
- <table width="100%" align="center">
- <tr>
- <td colspan="2" align="center"><h1><strong>被取消订单信息</strong></h1>
- <hr /></td>
- </tr>
-
- <tr>
- <td width="100"><strong>订单编号:</strong></td>
- <td>' . $orderNo . '</td>
- </tr>'
- .$mergeString.
- '<tr>
- <td><strong>店铺名称:</strong></td>
- <td>' . $shopname . '</td>
- </tr>
- '.$quhuofangshi.'
- <tr>
- <td><strong>姓名:</strong></td>
- <td>' . $nickname . '</td>
- </tr>
-
- <tr>
- <td><strong>电话:</strong></td>
- <td>' . $phone . '</td>
- </tr>
-
- <tr>
- <td valign="top"><strong>地址:</strong></td>
- <td>' . $address . '</td>
- </tr>' .
-
- $fieldString .
- $deliverinfo .
-
- '<tr>
- <td><strong>下单时间:</strong></td>
- <td>' . date("Y-m-d H:i:s") . '</td>
- </tr>
-
- ' . $OrderString . '
-
- <tr>
- <td valign="top"><strong>备注:</strong></td>
- <td>' . $note . '</td>
- </tr>
- ';
-
- if ($orderModel->is_member_delete)
- {
- $memberdeleteInfo = '
- <tr>
- <td><strong>会员优惠:</strong></td>
- <td>' . $orderModel->member_delete . '元</td>
- </tr>';
- }
- else
- {
- $memberdeleteInfo = "";
- }
-
- if($orderModel->promotion)
- {
- $promotion = explode(':',$orderModel->promotion);
- $promotioninfo = '
- <tr>
- <td><strong></strong></td>
- <td>满' . $promotion[0] . '元减'.$promotion[1].'</td>
- </tr>';
- }
- else
- {
- $promotioninfo = '';
- }
-
- if ($orderModel->is_discount == 1)
- {
- $discountInfo = '
- <tr>
- <td><strong>店铺折扣:</strong></td>
- <td>' . $orderModel->discount_value . '折</td>
- </tr>';
- }
- else
- {
- $discountInfo = "";
- }
-
- $addservicestring = "";
- $addservice = unserialize($orderModel->addservice);
- if(is_array($addservice))
- {
- foreach($addservice as $addservicekey => $addserviceval)
- {
- $addservicestring .= '
- <tr>
- <td><strong>'.$addservicekey.':</strong></td>
- <td>' . $addserviceval . '元</td>
- </tr>';
- }
- }
-
- if ($orderModel->is_coupon == 1)
- {
- $couponInfo = '
- <tr>
- <td><strong>优惠券:</strong></td>
- <td>' . $orderModel->coupon_value . '元</td>
- </tr>';
- }
- else
- {
- $couponInfo = "";
- }
-
- if ($orderModel->charge_type == 1)
- {
- $totalpriceInfo = '
- <tr>
- <td><strong>总金额:</strong></td>
- <td><span class="price">¥' . $totalPrice . '</span>(未付款)</td>
- </tr>';
- }
- else
- {
- $totalpriceInfo = '
- <tr>
- <td><strong>总金额:</strong></td>
- <td><span class="price">¥' . $totalPrice . '</span>(已付款)</td>
- </tr>';
- }
-
- $Content = $Content . $memberdeleteInfo . $promotioninfo . $discountInfo . $delivery_fee_info . $addservicestring . $couponInfo . $totalpriceInfo .
- '</table>' . '<p style="font-size: 22px; color:red; font-weight: bold;">该笔订单已经被顾客取消,请不要进行配送,如有疑问请电话联系顾客!</p>' .
- '</body>
- </html>
- ';
-
- SendEmail($receiveEmail, $receiveName, $Subject, $Content);
- }
-
- private function SendPointPrizeOrderEmail()
- {
- //判断是否发邮件
- $emailvalid = $this->pointsetModel->is_emaill;
- if (!$emailvalid)
- {
- return ;
- }
-
- $email_address = $this->pointsetModel->email;
-
- $adminId = $this->orderModel->admin_id;
- $orderModel = $this->orderModel;
- $name = $this->orderModel->name;
- $phone = $this->orderModel->phone;
- $address = $this->orderModel->address;
- $note = $this->orderModel->memo;
-
- $receiveEmail = $email_address;
- $receiveName = '';
-
- $DefaultOrderString = '
- <tr>
- <td><strong>兑奖详情:</strong></td>
- <td></td>
- </tr>';
-
- $orderItemModels = LewaimaiPointprizeOrderItem::model()->findAll("lewaimai_order_id = " . $orderModel->id);
- if (!$orderItemModels)
- {
- $OrderString = $DefaultOrderString;
- }
- elseif (count($orderItemModels) == 1)
- {
- $orderItemModel = $orderItemModels[0];
- $OrderString = '
- <tr>
- <td><strong>订单详情:</strong></td>
- <td>' . $orderItemModel->prize_name . " " . $orderItemModel->quantity . "份" . '</td>
- </tr>';
- }
- else
- {
- $orderItemModel = $orderItemModels[0];
- $OrderString = '
- <tr>
- <td><strong>订单详情:</strong></td>
- <td>' . $orderItemModel->prize_name . " " . $orderItemModel->quantity . "份" . '</td>
- </tr>';
-
- for ($i = 1; $i < count($orderItemModels); $i++)
- {
- $orderItemModel = $orderItemModels[$i];
-
- $newOrderString = '
- <tr>
- <td></td>
- <td>' . $orderItemModel->prize_name . " " . $orderItemModel->quantity . "份" . '</td>
- </tr>';
-
- $OrderString = $OrderString . $newOrderString;
- }
- }
-
- $Subject = '您有一笔积分兑奖订单,请尽快处理!';
- $Content = '
- <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
- <html xmlns="http://www.w3.org/1999/xhtml">
- <head>
- <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
- <title>无标题文档</title>
- <style type="text/css">
- body,td,th {
- font-size: 18px;
- }
- .price {
- color: #F00;
- }
- </style>
- </head>
-
- <body>
- <table width="100%" align="center">
- <tr>
- <td colspan="2" align="center"><h1><strong>积分兑奖信息</strong></h1>
- <hr /></td>
- </tr>
-
- <tr>
- <td width="100"><strong>姓名:</strong></td>
- <td>' . $name . '</td>
- </tr>
-
- <tr>
- <td><strong>电话:</strong></td>
- <td>' . $phone . '</td>
- </tr>
-
- <tr>
- <td valign="top"><strong>地址:</strong></td>
- <td>' . $address . '</td>
- </tr>' .
-
- '<tr>
- <td><strong>下单时间:</strong></td>
- <td>' . date("Y-m-d H:i:s") . '</td>
- </tr>
-
- ' . $OrderString . '
-
- <tr>
- <td valign="top"><strong>备注:</strong></td>
- <td>' . $note . '</td>
- </tr>
- ';
-
- $Content = $Content .
- '</table>
- </body>
- </html>
- ';
-
- SendEmail($receiveEmail, $receiveName, $Subject, $Content);
- }
-
- private function PrintCancelOrder()
- {
- $shopprinterModels = ShopPrinter::model()->findAll("shop_id = " . $this->shopModel->id);
-
- foreach ($shopprinterModels as $shopprinterModel)
- {
- $printer_id = $shopprinterModel->printer_id;
-
- $printerModel = Printer::model()->findByPk($printer_id);
- if (!$printerModel)
- {
- continue;
- }
-
- $printer_type = $printerModel->printer_type;
-
- $lewaimai_sn = $printerModel->lewaimai_sn;
-
- $member_code = $printerModel->member_code;
- $feyin_key = $printerModel->feyin_key;
- $device_no = $printerModel->device_no;
-
- $shopcode = $printerModel->shopcode;
-
- $printer_num = $printerModel->printer_num;
- $printer_info = $printerModel->printer_info;
-
- $is_cut = $printerModel->is_cut;
-
- $big_ordernum = $printerModel->big_ordernum;
- $big_name = $printerModel->big_name;
- $big_phone = $printerModel->big_phone;
- $big_address = $printerModel->big_address;
- $big_content = $printerModel->big_content;
- $big_price = $printerModel->big_price;
-
- if ($printer_type == 1)
- {
- $content = $this->GetPrinterCancelOrderContent(2, $printer_info, $is_cut);
- $this->SendFeyinPrinterMessage($member_code, $device_no, $feyin_key, $content);
- }
- elseif ($printer_type == 2)
- {
- $content = $this->GetPrinterCancelOrderContent(3, $printer_info, $is_cut);
- $this->SendKeLaiLePrinterMessage($shopcode, $content);
- }
- elseif ($printer_type == 3)
- {
- $content = $this->GetPrinterCancelOrderContent(1, $printer_info, $is_cut);
- $this->SendLewaimaiPrinterMessage(1, $lewaimai_sn, $printer_num, $content);
- }
- }
- }
-
- private function PrintPointPrizeOrder()
- {
- $printerModel = Printer::model()->findByPk($this->pointsetModel->printer_id);
- if (!$printerModel)
- {
- Yii::log("no this printer! PrintPointPrizeOrder failed!");
- return ;
- }
-
- $printer_type = $printerModel->printer_type;
-
- $lewaimai_sn = $printerModel->lewaimai_sn;
-
- $member_code = $printerModel->member_code;
- $feyin_key = $printerModel->feyin_key;
- $device_no = $printerModel->device_no;
-
- $shopcode = $printerModel->shopcode;
-
- $printer_num = $printerModel->printer_num;
- $printer_info = $printerModel->printer_info;
-
- $is_cut = $printerModel->is_cut;
-
- $big_ordernum = $printerModel->big_ordernum;
- $big_name = $printerModel->big_name;
- $big_phone = $printerModel->big_phone;
- $big_address = $printerModel->big_address;
- $big_content = $printerModel->big_content;
- $big_price = $printerModel->big_price;
-
- if ($printer_type == 1)
- {
- $content = $this->GetPrinterPointPrizeOrderContent(2, $is_cut);
- $this->SendFeyinPrinterMessage($member_code, $device_no, $feyin_key, $content);
- }
- elseif ($printer_type == 2)
- {
- $content = $this->GetPrinterPointPrizeOrderContent(3, $is_cut);
- $this->SendKeLaiLePrinterMessage($shopcode, $content);
- }
- elseif ($printer_type == 3)
- {
- $content = $this->GetPrinterPointPrizeOrderContent(1, $is_cut);
- $this->SendLewaimaiPrinterMessage(1, $lewaimai_sn, $printer_num, $content);
- }
- }
-
- private function SendLewaimaiPrinterMessage($orderid, $lewaimai_sn, $printer_num, $content)
- {
- $dingdanID = $orderid; //订单号
- $dayinjisn = $lewaimai_sn; //打印机ID号
- $pages = $printer_num; //联数
- $dingdan = $content; //订单内容
- $replyURL = "http://www.lewaimai.com/lewaimaiprinter/orderstatus";//回复确认URL
-
- if($pages <= 0 || $pages > 4)
- {
- Yii::log("乐外卖打印机打印联数不能大于4!");
- return false;
- }
-
- if(empty($dingdanID)||empty($dayinjisn)||empty($pages)||empty($dingdan)||empty($replyURL))
- {
- return false;
- }
-
- $url = 'http://lewaimaiprinter.lewaimai.com:60002';//POST指向的API链接
- // 提交API的内容
- $data = array(
- 'dingdanID'=>'dingdanID='.$dingdanID, //订单号
- 'dayinjisn'=>'dayinjisn='.$dayinjisn, //打印机ID号
- 'dingdan'=>'dingdan='.$dingdan, //订单内容
- 'pages'=>'pages='.$pages, //联数
- 'replyURL'=>'replyURL='.$replyURL); //回复确认URL
-
- $post_data = implode('&',$data);
-
- LewaimaiHttp::POST_ASYNC($url, array(), array(CURLOPT_POSTFIELDS=>$post_data));
- return true;
- }
-
- private function SendFeyinPrinterMessage($MEMBER_CODE, $DEVICE_NO, $FEYIN_KEY, $Content)
- {
- $msgNo = microtime() . LewaimaiString::create_noncestr(16);
-
- $msg = array(
- 'memberCode' => $MEMBER_CODE,
- 'msgDetail' => $Content,
- 'deviceNo' => $DEVICE_NO,
- 'msgNo' => $msgNo
- );
-
- $msg['reqTime'] = number_format(1000 * time(), 0, '', '');
- $content = $msg['memberCode'] . $msg['msgDetail'] . $msg['deviceNo'] . $msg['msgNo'] . $msg['reqTime'] . $FEYIN_KEY;
- $msg['securityCode'] = md5($content);
- $msg['mode'] = 2;
-
- $post_url = "my.feyin.net/api/sendMsg";
- LewaimaiHttp::POST_ASYNC($post_url, $msg);
- return true;
- }
-
- private function SendKeLaiLePrinterMessage($shopCode, $content, $orderid = '', $total_price = '', $charge_type = '')
- {
- // app params
- $appid = 'wp2a061b92bbd950cc';
- $appSecret = '45b19efd84889e727cc29da91d7ffb15';
-
- // request params
- $reqParams = array(
- 'appid' => $appid,
- 'timestamp' => time(),
- 'shopCode' => $shopCode,
- 'content' => $content,
- 'orderCode' => $orderid,
- 'price' => $total_price,
- 'charge_type' => $charge_type,
- );
-
- // generate sign;
- $params = array();
- foreach ($reqParams as $key=>$val)
- $params[$key]=$val;
-
- ksort($params); //SORT_STRING | SORT_FLAG_CASE);
- $arr = array();
- foreach ($params as $key => $val)
- $arr[] = "$key=$val";
-
- $reqParams['sign'] = sha1(implode('&', $arr).$appSecret);
-
- $jsonString = CJSON::encode($reqParams);
-
- $post_url = 'http://p.kelaile.cn/api/service/print';
- LewaimaiHttp::POST_ASYNC($post_url, array(), array(CURLOPT_POSTFIELDS=>$jsonString));
-
- return true;
- }
-
- //printer_type 1:乐外卖打印机 2:飞印打印机 3:客来乐打印机
- private function GetPrinterOrderContent($printer_type = 1, $printer_num, $printer_info, $is_cut = 0, $big_ordernum = 0, $big_name = 0, $big_phone = 0, $big_address = 0, $big_content = 0, $big_price = 0)
- {
- $admin_id = $this->orderModel->admin_id;
- $shop_id = $this->orderModel->shop_id;
- $delivery_fee = $this->orderModel->delivery_fee;
- $total_price = $this->orderModel->total_price;
- $total_point = $this->orderModel->total_point;
- $nickname = $this->orderModel->nickname;
- $phone = $this->orderModel->phone;
- $address = $this->orderModel->address;
- $memo = $this->orderModel->memo;
- $init_date = $this->orderModel->init_date;
-
- //计算是第几次下单
- if($this->shopModel->showordernum_type == 0)
- {
- $orderCount = LewaimaiOrder::model()->count("admin_id = " . $this->orderModel->admin_id . " AND lewaimai_customer_id = " . $this->orderModel->lewaimai_customer_id . " AND shop_id = " . $this->orderModel->shop_id . " AND order_status IN ('CONFIRMED','SUCCEEDED','OPEN','CANCELLED','FAILED')");
- }
- else
- {
- $orderCount = LewaimaiOrder::model()->count("admin_id = " . $this->orderModel->admin_id . " AND lewaimai_customer_id = " . $this->orderModel->lewaimai_customer_id . " AND order_status IN ('CONFIRMED','SUCCEEDED','OPEN','CANCELLED','FAILED')");
- }
-
- if (!$this->orderCount)
- {
- $this->orderCount = $orderCount;
- }
-
- //判断该顾客是不是店铺的会员
- $memberModel = LewaimaiMember::model()->find("lewaimai_customer_id = " . $this->orderModel->lewaimai_customer_id . " AND admin_id = " . $this->orderModel->admin_id);
- if($this->shopModel->showordernum == 1)
- {
- if ($memberModel)
- {
- $nickname .= "(会员,第" . $orderCount . "次下单)";
- }
- else
- {
- $nickname .= "(第" . $orderCount . "次下单)";
- }
- }
-
- //求预设选项
- $order_field = unserialize($this->orderModel->order_field);
- $fieldString = "";
- foreach($order_field as $key => $val)
- {
- $fieldString .= $val["name"] . ":" . $val["content"] . "\r\n";
- }
-
- //支付方式
- $charge_type = $this->orderModel->charge_type;
- if ($charge_type == 1)
- {
- $chargeString = "货到付款";
- }
- elseif ($charge_type == 2)
- {
- $chargeString = "余额支付(已付款)";
- }
- elseif ($charge_type == 3)
- {
- $chargeString = "在线支付(已付款)";
- }
-
- $is_discount = $this->orderModel->is_discount;
- $discount_value = $this->orderModel->discount_value;
-
- $is_coupon = $this->orderModel->is_coupon;
- $coupon_value = $this->orderModel->coupon_value;
-
- $is_member_delete = $this->orderModel->is_member_delete;
- $member_delete = $this->orderModel->member_delete;
-
- if ($is_member_delete)
- {
- $memberdeleteString = "会员优惠:" . $member_delete . "元";
- $memberdeleteString = RightString($memberdeleteString) . "\r\n";
- }
- else
- {
- $memberdeleteString = '';
- }
-
- if($this->orderModel->promotion)
- {
- $promotion = explode(':',$this->orderModel->promotion);
- $promotioninfo = '满'.$promotion[0].'元,减'.$promotion[1].'元';
- $promotioninfo = RightString($promotioninfo) . "\r\n";
- }
- else
- {
- $promotioninfo = '';
- }
-
- if ($is_discount)
- {
- $discountString = "店铺折扣:" . $discount_value . "折";
- $discountString = RightString($discountString) . "\r\n";
- }
- else
- {
- $discountString = "";
- }
-
- if ($is_coupon)
- {
- $couponString = "优惠券:" . $coupon_value . "元";
- $couponString = RightString($couponString) . "\r\n";
- }
- else
- {
- $couponString = "";
- }
-
- $shopname = $this->shopModel->shopname;
- $orderphone = $this->shopModel->orderphone;
-
- // 读取订单详情
- $orderItemModels = LewaimaiOrderItem::model()->findAll("lewaimai_order_id = " . $this->orderid);
-
- $totalNum = 0;
- $order_item_string = "";
- foreach ($orderItemModels as $orderItemModel)
- {
- $food_name = $orderItemModel->food_name;
-
- $price = $orderItemModel->price;
- $price = sprintf("%.1f", $price);
-
- $quantity = $orderItemModel->quantity;
-
- $item_total_price = $orderItemModel->price * $orderItemModel->quantity;
- $item_total_price = sprintf("%.1f", $item_total_price);
-
- $showFoodName = HandleFoodName($food_name);
- $showPrice = HandleNum($price);
- $showQuantity = HandleNum($quantity);
- $showItemTotalPrice = HandleNum($item_total_price);
-
- $item_string = $showFoodName . $showPrice . " " . $showQuantity . " " . $showItemTotalPrice;
-
- $order_item_string = $order_item_string . $item_string . "\r\n";
-
- $totalNum += $quantity;
- }
-
- if ($big_content)
- {
- if ($printer_type == 1)
- {
- $order_item_string = GetHalfWidthBigStringLewaimai($order_item_string);
- }
- elseif ($printer_type == 2)
- {
- $order_item_string = GetHalfWidthBigStringFeyin($order_item_string);
- }
- }
-
- //处理配送费
- if ($delivery_fee != 0)
- {
- $delivery_fee = sprintf("%.1f", $delivery_fee);
-
- $showFoodName = HandleFoodName("外送费");
- $showPrice = HandleNum("");
- $showQuantity = HandleNum("");
- $showItemTotalPrice = HandleNum($delivery_fee);
-
- $delivery_fee_string = $showFoodName . $showPrice . " " . $showQuantity . " " . $showItemTotalPrice;
-
- $order_item_string = $order_item_string . $delivery_fee_string . "\r\n";
- }
-
- if ($this->adminModel->order_num_type == 0)
- {
- $orderNo = $this->orderModel->admin_num;
- }
- else
- {
- $orderNo = $this->shopModel->order_prefix . $this->orderModel->shop_num;
- }
-
- $delivertime = $this->orderModel->delivertime;
- $delivertimeinfo = '';
- if($delivertime)
- {
- $delivertimeinfo = '配送时间: '.$this->orderModel->delivery_date.' '.$delivertime . "\r\n";
- }
-
- //开始计算returnString
- if ($printer_type == 1)
- {
- $returnString = CenterTitleLeWaiMai($shopname) . "\r\n" . "\r\n";
- }
- elseif ($printer_type == 2)
- {
- $returnString = CenterTitleFeyin($shopname) . "\r\n" . "\r\n";
- }
- elseif ($printer_type == 3)
- {
- $returnString = CenterString($shopname) . "\r\n" . "\r\n";
- }
-
- if ($big_ordernum)
- {
- if ($printer_type == 1)
- {
- $ordernumString = GetHalfWidthBigStringLewaimai('订单编号:' . $orderNo) . "\r\n" ;
- }
- elseif ($printer_type == 2)
- {
- $ordernumString = GetHalfWidthBigStringFeyin('订单编号:' . $orderNo) . "\r\n" ;
- }
- }
- else
- {
- $ordernumString = '订单编号:' . $orderNo . "\r\n" ;
- }
-
- $mergeModel = LewaimaiMergeOrderSet::model()->find('admin_id='.$this->orderModel->admin_id.' and shop_id='.$this->orderModel->shop_id);
- $mergeString = '';
- if($mergeModel and $mergeModel->is_open==1)
- {
- if($this->orderModel->mergeorder_id > 0)
- {
- $mergeString = "是否是拼单:是\r\n";
- $mergeorderModel = LewaimaiMergeOrder::model() -> findByPk($this->orderModel->mergeorder_id);
- $mergeString .= "拼单名字:".$mergeorderModel->name."\r\n";
- $mergeString .= "拼单人数:".$mergeorderModel->nownum."\r\n";
- $mergeString .= "拼单折扣:".$this->orderModel->mergeorder_discount."\r\n";
- }
- else
- {
- $mergeString = "是否是拼单:不是\r\n";
- }
- }
-
- if($this->shopModel->open_selftake)
- {
- if($this->orderModel->is_selftake)
- {
- $quhuofangshi = "取货方式:到店自取\r\n";
- }
- else
- {
- $quhuofangshi = "取货方式:店家配送\r\n";
- }
- }
- else
- {
- $quhuofangshi = '';
- }
-
- $returnString .= $ordernumString . $mergeString . $quhuofangshi;
-
- if ($big_name)
- {
- if ($printer_type == 1)
- {
- $nameString = GetHalfWidthBigStringLewaimai('姓名:' . $nickname) . "\r\n" ;
- }
- elseif ($printer_type == 2)
- {
- $nameString = GetHalfWidthBigStringFeyin('姓名:' . $nickname) . "\r\n" ;
- }
- }
- else
- {
- $nameString = '姓名:' . $nickname . "\r\n";
- }
-
- if ($big_phone)
- {
- if ($printer_type == 1)
- {
- $phoneString = GetHalfWidthBigStringLewaimai('电话:' . $phone) . "\r\n";
- }
- elseif ($printer_type == 2)
- {
- $phoneString = GetHalfWidthBigStringFeyin('电话:' . $phone) . "\r\n";
- }
- }
- else
- {
- $phoneString = '电话:' . $phone . "\r\n";
- }
-
- if ($big_address)
- {
- if ($printer_type == 1)
- {
- $addressString = GetHalfWidthBigStringLewaimai('地址:' . $address) . "\r\n";
- }
- elseif ($printer_type == 2)
- {
- $addressString = GetHalfWidthBigStringFeyin('地址:' . $address) . "\r\n";
- }
- }
- else
- {
- $addressString = '地址:' . $address . "\r\n";
- }
-
- $returnString .= $nameString . $phoneString . $addressString;
-
- $addserviceString = "";
- $addservice = unserialize($this->orderModel->addservice);
- if(is_array($addservice))
- {
- foreach($addservice as $addservicekey => $addserviceval)
- {
- $addserviceString .= RightString($addservicekey.':'.$addserviceval."元"). "\r\n";
- }
- }
-
- $returnString .= $fieldString .
- $delivertimeinfo .
- '下单时间:' . $init_date . "\r\n" .
- '--------------------------------' . "\r\n" .
- '商品 单价 数量 金额 ' . "\r\n" .
- $order_item_string .
- "\r\n" .
- '备注:' . $memo . "\r\n" .
- '--------------------------------' . "\r\n" .
- $memberdeleteString .
- $promotioninfo .
- $discountString .
- $couponString .
- $addserviceString;
-
- if ($big_price)
- {
- if ($printer_type == 1)
- {
- $priceString = GetHalfWidthBigStringLewaimai(RightString("共" . $totalNum . "份,合计:" . $total_price . "元"));
- }
- elseif ($printer_type == 2)
- {
- $priceString = GetHalfWidthBigStringFeyin(RightString("共" . $totalNum . "份,合计:" . $total_price . "元"));
- }
- }
- else
- {
- $priceString = RightString("共" . $totalNum . "份,合计:" . $total_price . "元");
- }
-
- $returnString .= $priceString . "\r\n" .
- RightString($chargeString) . "\r\n" .
- "\r\n" .
- CenterString($printer_info);
-
- $content = "";
- if ($printer_type == 1)
- {
- if ($is_cut)
- {
- $content = "<1B40><1B40><1B40>" . $returnString . "<0D0A><0D0A><0D0A><0D0A><0D0A><0D0A>" . "<1D5642000A0A>";
- }
- else
- {
- $content = "<1B40><1B40><1B40>" . $returnString . "<0D0A><0D0A><0D0A><0D0A><0D0A><0D0A><0D0A><0D0A>";
- }
- }
- elseif ($printer_type == 2 || $printer_type == 3)
- {
- for ($i = 0; $i < $printer_num; $i++)
- {
- $content = $content . $returnString;
- if ($i != $printer_num - 1)
- {
- $content = $content . "\r\n\r\n\r\n";
- }
- }
- }
-
- return $content;
- }
-
- //printer_type 1:乐外卖打印机 2:飞印打印机 3:客来乐打印机
- private function GetPrinterCancelOrderContent($printer_type, $printer_info, $is_cut = 0)
- {
- $admin_id = $this->orderModel->admin_id;
- $shop_id = $this->orderModel->shop_id;
- $delivery_fee = $this->orderModel->delivery_fee;
- $total_price = $this->orderModel->total_price;
- $total_point = $this->orderModel->total_point;
- $nickname = $this->orderModel->nickname;
- $phone = $this->orderModel->phone;
- $address = $this->orderModel->address;
- $memo = $this->orderModel->memo;
- $init_date = $this->orderModel->init_date;
-
- $mergeModel = LewaimaiMergeOrderSet::model()->find('admin_id='.$this->orderModel->admin_id.' and shop_id='.$this->orderModel->shop_id);
- $mergeString = '';
- if($mergeModel and $mergeModel->is_open==1)
- {
- if($this->orderModel->mergeorder_id > 0)
- {
- $mergeString = "是否是拼单:是\r\n";
- $mergeorderModel = LewaimaiMergeOrder::model() -> findByPk($this->orderModel->mergeorder_id);
- $mergeString .= "拼单名字:".$mergeorderModel->name."\r\n";
- $mergeString .= "拼单人数:".$mergeorderModel->nownum."\r\n";
- $mergeString .= "拼单折扣:".$this->orderModel->mergeorder_discount."\r\n";
- }
- else
- {
- $mergeString = "是否是拼单:不是\r\n";
- }
- }
-
- //求预设选项
- $order_field = unserialize($this->orderModel->order_field);
- $fieldString = "";
- foreach($order_field as $key => $val)
- {
- $fieldString .= $val["name"] . ":" . $val["content"] . "\r\n";
- }
-
- //支付方式
- $charge_type = $this->orderModel->charge_type;
- if ($charge_type == 1)
- {
- $chargeString = "货到付款";
- }
- elseif ($charge_type == 2)
- {
- $chargeString = "余额支付(已付款)";
- }
- elseif ($charge_type == 3)
- {
- $chargeString = "在线支付(已付款)";
- }
-
- $is_discount = $this->orderModel->is_discount;
- $discount_value = $this->orderModel->discount_value;
-
- $is_coupon = $this->orderModel->is_coupon;
- $coupon_value = $this->orderModel->coupon_value;
-
- if ($is_discount)
- {
- $discountString = "会员折扣:" . $discount_value . "折";
- $discountString = RightString($discountString) . "\r\n";
- }
- else
- {
- $discountString = "";
- }
-
- if ($is_coupon)
- {
- $couponString = "优惠券:" . $coupon_value . "元";
- $couponString = RightString($couponString) . "\r\n";
- }
- else
- {
- $couponString = "";
- }
-
- // 读取店铺名
- $shopname = $this->shopModel->shopname;
- $orderphone = $this->shopModel->orderphone;
-
- // 读取订单详情
- $orderItemModels = LewaimaiOrderItem::model()->findAll("lewaimai_order_id = " . $this->orderid);
-
- $order_item_string = "";
- foreach ($orderItemModels as $orderItemModel)
- {
- $food_name = $orderItemModel->food_name;
-
- $price = $orderItemModel->price;
- $price = sprintf("%.1f", $price);
-
- $quantity = $orderItemModel->quantity;
-
- $item_total_price = $orderItemModel->price * $orderItemModel->quantity;
- $item_total_price = sprintf("%.1f", $item_total_price);
-
- $showFoodName = HandleFoodName($food_name);
- $showPrice = HandleNum($price);
- $showQuantity = HandleNum($quantity);
- $showItemTotalPrice = HandleNum($item_total_price);
-
- $item_string = $showFoodName . $showPrice . " " . $showQuantity . " " . $showItemTotalPrice;
-
- $order_item_string = $order_item_string . $item_string . "\r\n";
- }
-
- //处理配送费
- if ($delivery_fee != 0)
- {
- $delivery_fee = sprintf("%.1f", $delivery_fee);
-
- $showFoodName = HandleFoodName("外送费");
- $showPrice = HandleNum("");
- $showQuantity = HandleNum("");
- $showItemTotalPrice = HandleNum($delivery_fee);
-
- $delivery_fee_string = $showFoodName . $showPrice . " " . $showQuantity . " " . $showItemTotalPrice;
-
- $order_item_string = $order_item_string . $delivery_fee_string . "\r\n";
- }
-
- if ($this->adminModel->order_num_type == 0)
- {
- $orderNo = $this->orderModel->admin_num;
- }
- else
- {
- $orderNo = $this->shopModel->order_prefix . $this->orderModel->shop_num;
- }
-
- $delivertime = $this->orderModel->delivertime;
- $delivertimeinfo = '';
- if($delivertime)
- {
- $delivertimeinfo = '配送时间: '.$this->orderModel->delivery_date.' '.$delivertime . "\r\n";
- }
-
- if ($printer_type == 1)
- {
- $returnString = CenterTitleLeWaiMai("订单取消通知") . "\r\n" . "\r\n";
- }
- elseif ($printer_type == 2)
- {
- $returnString = CenterTitleFeyin("订单取消通知") . "\r\n" . "\r\n";
- }
- else
- {
- $returnString = CenterString("订单取消通知") . "\r\n" . "\r\n";
- }
-
- $returnString .= '店铺:' . $shopname . "\r\n" .
- '订单编号:' . $orderNo . "\r\n" .$mergeString;
-
- if($this->shopModel->open_selftake)
- {
- if($this->orderModel->is_selftake)
- {
- $quhuofangshi = "取货方式:到店自取\r\n";
- }
- else
- {
- $quhuofangshi = "取货方式:店家配送\r\n";
- }
- }
- else
- {
- $quhuofangshi = '';
- }
-
- $returnString .= $quhuofangshi;
- $returnString .= '姓名:' . $nickname . "\r\n" .
- '电话:' . $phone . "\r\n" .
- '地址:' . $address . "\r\n" ;
-
- $returnString .= $fieldString .
- $delivertimeinfo .
- '下单时间:' . $init_date . "\r\n" .
- '--------------------------------' . "\r\n" .
- '商品 单价 数量 金额 ' . "\r\n" .
- $order_item_string .
- "\r\n" .
- '备注:' . $memo . "\r\n" .
- '--------------------------------' . "\r\n" .
- $discountString .
- $couponString .
- RightString("合计:" . $total_price . "元") . "\r\n" .
- RightString($chargeString) . "\r\n" .
- "\r\n" .
- CenterString($printer_info) . "\r\n";
-
- if ($printer_type == 1)
- {
- if ($is_cut)
- {
- $content = "<1B40><1B40><1B40>" . $returnString . "<0D0A><0D0A><0D0A><0D0A><0D0A><0D0A>" . "<1D5642000A0A>";
- }
- else
- {
- $content = "<1B40><1B40><1B40>" . $returnString . "<0D0A><0D0A><0D0A><0D0A><0D0A><0D0A><0D0A><0D0A>";
- }
- }
- elseif ($printer_type == 2 || $printer_type == 3)
- {
- $content = $returnString;
- }
-
- return $content;
- }
-
- //printer_type 1:乐外卖打印机 2:飞印打印机 3:客来乐打印机
- private function GetPrinterPointPrizeOrderContent($printer_type, $is_cut = 0)
- {
- $orderModel = $this->orderModel;
-
- $admin_id = $orderModel->admin_id;
- $total_point = $orderModel->total_point;
- $name = $orderModel->name;
- $phone = $orderModel->phone;
- $address = $orderModel->address;
- $memo = $orderModel->memo;
- $init_time = $orderModel->init_time;
-
- // 读取订单详情
- $orderItemModels = LewaimaiPointprizeOrderItem::model()->findAll("lewaimai_order_id = " . $this->orderid);
-
- $order_item_string = "";
- foreach ($orderItemModels as $orderItemModel)
- {
- $prize_name = $orderItemModel->prize_name;
- $quantity = $orderItemModel->quantity;
-
- $item_string = $prize_name . " " . $quantity . " 份\r\n";
-
- $order_item_string = $order_item_string . $item_string;
- }
-
- if ($printer_type == 1)
- {
- $returnString = CenterTitleLeWaiMai("积分兑奖通知") . "\r\n" . "\r\n";
- }
- elseif ($printer_type == 2)
- {
- $returnString = CenterTitleFeyin("积分兑奖通知") . "\r\n" . "\r\n";
- }
- else
- {
- $returnString = CenterString("积分兑奖通知") . "\r\n" . "\r\n";
- }
-
- $returnString .= '姓名:' . $name . "\r\n" .
- '电话:' . $phone . "\r\n" .
- '地址:' . $address . "\r\n" ;
-
- $returnString .= '兑奖时间:' . $init_time . "\r\n" .
- '--------------------------------' . "\r\n" .
- $order_item_string .
- '--------------------------------' . "\r\n" .
- '备注:' . $memo . "\r\n";
-
- if ($printer_type == 1)
- {
- if ($is_cut)
- {
- $content = "<1B40><1B40><1B40>" . $returnString . "<0D0A><0D0A><0D0A><0D0A><0D0A><0D0A>" . "<1D5642000A0A>";
- }
- else
- {
- $content = "<1B40><1B40><1B40>" . $returnString . "<0D0A><0D0A><0D0A><0D0A><0D0A><0D0A><0D0A><0D0A>";
- }
- }
- elseif ($printer_type == 2 || $printer_type == 3)
- {
- $content = $returnString;
- }
-
- return $content;
- }
- }
|