| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709 |
- <?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;
- }
- }
|