LewaimaiNotify.php 73 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708
  1. <?php
  2. require_once 'PHPMailer.php';
  3. include_once dirname(__FILE__) . '/PrinterHelper.php';
  4. class LewaimaiNotify
  5. {
  6. private $orderid;
  7. private $orderModel;
  8. private $adminModel;
  9. private $shopModel;
  10. private $IsPrinterConfirmed = false;
  11. private $orderCount = 0; //第几次下单
  12. private $pointsetModel;
  13. //进行订单通知,包含所有通知方式
  14. //orderid是订单ID,后面的model是为了提高效率,如果在调用这个函数之前已经获取过,就直接传入,没有就不传
  15. public static function NewOrderNotify($orderid, $orderModel = NULL, $adminModel = NULL, $shopModel = NULL)
  16. {
  17. $lewaimainotify = new LewaimaiNotify();
  18. $lewaimainotify->SendNewOrderNotify($orderid, $orderModel, $adminModel, $shopModel);
  19. }
  20. public static function OrderPrintOnly($orderid, $orderModel = NULL, $adminModel = NULL, $shopModel = NULL)
  21. {
  22. $lewaimainotify = new LewaimaiNotify();
  23. $lewaimainotify->PrinteOrderOnly($orderid, $orderModel, $adminModel, $shopModel);
  24. }
  25. //取消订单通知
  26. public static function CancelOrderNotify($orderid, $orderModel = NULL, $adminModel = NULL, $shopModel = NULL)
  27. {
  28. $lewaimainotify = new LewaimaiNotify();
  29. $lewaimainotify->SendCancelOrderNotify($orderid, $orderModel, $adminModel, $shopModel);
  30. }
  31. //积分兑换奖品通知
  32. public static function PointPrizeOrderNotify($orderid)
  33. {
  34. $lewaimainotify = new LewaimaiNotify();
  35. $lewaimainotify->SendPointPrizeOrderNotify($orderid);
  36. }
  37. //自由打印内容
  38. public static function ShopContentPrint($shop_id, $content)
  39. {
  40. $lewaimainotify = new LewaimaiNotify();
  41. $lewaimainotify->PrintShopContent($shop_id, $content);
  42. }
  43. public function SendNewOrderNotify($orderid, $orderModel = NULL, $adminModel = NULL, $shopModel = NULL)
  44. {
  45. $this->orderid = $orderid;
  46. if ($orderModel)
  47. {
  48. $this->orderModel = $orderModel;
  49. }
  50. else
  51. {
  52. $this->orderModel = LewaimaiOrder::model()->findByPk($orderid);
  53. if (!$this->orderModel)
  54. {
  55. Yii::log("not this order! SendOrderNotify failed!");
  56. return ;
  57. }
  58. }
  59. if ($adminModel)
  60. {
  61. $this->adminModel = $adminModel;
  62. }
  63. else
  64. {
  65. $this->adminModel = Admin::model()->findByPk($this->orderModel->admin_id);
  66. if (!$this->adminModel)
  67. {
  68. Yii::log("not found the admin_id! SendOrderNotify failed!");
  69. return ;
  70. }
  71. }
  72. if ($shopModel)
  73. {
  74. $this->shopModel = $shopModel;
  75. }
  76. else
  77. {
  78. $shop_id = $this->orderModel->shop_id;
  79. $this->shopModel = Config::model()->findByPk($shop_id);
  80. if (!$this->shopModel)
  81. {
  82. Yii::log("not found the shop! SendOrderNotify failed!");
  83. return ;
  84. }
  85. }
  86. //先处理打印机提醒
  87. if($this->adminModel->autoprinter)
  88. {
  89. $this->PrintNewOrder();
  90. }
  91. //再处理短信提醒
  92. $this->SendNewOrderSMS();
  93. //再处理EMAIL提醒
  94. $this->SendNewOrderEmail();
  95. //再处理微信订单提醒的问题
  96. $this->SendNewOrderWeixin();
  97. //发送APP提醒
  98. $url="http://appserver.lewaimai.com/index.php?r=order/push&order_id=" . $orderid;
  99. LewaimaiHttp::GET_ASYNC($url);
  100. //处理订单被打印机确认后的逻辑
  101. $this->HandOrderConfirmed();
  102. }
  103. public function PrinteOrderOnly($orderid, $orderModel = NULL, $adminModel = NULL, $shopModel = NULL)
  104. {
  105. $this->orderid = $orderid;
  106. if ($orderModel)
  107. {
  108. $this->orderModel = $orderModel;
  109. }
  110. else
  111. {
  112. $this->orderModel = LewaimaiOrder::model()->findByPk($orderid);
  113. if (!$this->orderModel)
  114. {
  115. Yii::log("not this order! SendOrderNotify failed!");
  116. return ;
  117. }
  118. }
  119. if ($adminModel)
  120. {
  121. $this->adminModel = $adminModel;
  122. }
  123. else
  124. {
  125. $this->adminModel = Admin::model()->findByPk($this->orderModel->admin_id);
  126. if (!$this->adminModel)
  127. {
  128. Yii::log("not found the admin_id! SendOrderNotify failed!");
  129. return ;
  130. }
  131. }
  132. if ($shopModel)
  133. {
  134. $this->shopModel = $shopModel;
  135. }
  136. else
  137. {
  138. $shop_id = $this->orderModel->shop_id;
  139. $this->shopModel = Config::model()->findByPk($shop_id);
  140. if (!$this->shopModel)
  141. {
  142. Yii::log("not found the shop! SendOrderNotify failed!");
  143. return ;
  144. }
  145. }
  146. $this->PrintNewOrder();
  147. }
  148. public function SendCancelOrderNotify($orderid, $orderModel = NULL, $adminModel = NULL, $shopModel = NULL)
  149. {
  150. $this->orderid = $orderid;
  151. if ($orderModel)
  152. {
  153. $this->orderModel = $orderModel;
  154. }
  155. else
  156. {
  157. $this->orderModel = LewaimaiOrder::model()->findByPk($orderid);
  158. if (!$this->orderModel)
  159. {
  160. Yii::log("not this order! SendOrderNotify failed!");
  161. return ;
  162. }
  163. }
  164. if ($adminModel)
  165. {
  166. $this->adminModel = $adminModel;
  167. }
  168. else
  169. {
  170. $this->adminModel = Admin::model()->findByPk($this->orderModel->admin_id);
  171. if (!$this->adminModel)
  172. {
  173. Yii::log("not found the admin_id! SendOrderNotify failed!");
  174. return ;
  175. }
  176. }
  177. if ($shopModel)
  178. {
  179. $this->shopModel = $shopModel;
  180. }
  181. else
  182. {
  183. $shop_id = $this->orderModel->shop_id;
  184. $this->shopModel = Config::model()->findByPk($shop_id);
  185. if (!$this->shopModel)
  186. {
  187. Yii::log("not found the shop! SendOrderNotify failed!");
  188. return ;
  189. }
  190. }
  191. //处理打印机,对于取消的订单,不管是否开启自动打印,都要打印
  192. $this->PrintCancelOrder();
  193. //再处理短信提醒
  194. $this->SendCancelOrderSMS();
  195. //再处理EMAIL提醒
  196. $this->SendCancelOrderEmail();
  197. //再处理微信订单提醒的问题
  198. $this->SendCancelOrderWeixin();
  199. }
  200. public function SendPointPrizeOrderNotify($orderid)
  201. {
  202. $this->orderid = $orderid;
  203. $this->orderModel = LewaimaiPointprizeOrder::model()->findByPk($orderid);
  204. if (!$this->orderModel)
  205. {
  206. Yii::log("not this order! SendPointPrizeOrderNotify failed!");
  207. return ;
  208. }
  209. $adminId = $this->orderModel->admin_id;
  210. $this->pointsetModel = PointSet::model()->findByPk($adminId);
  211. if (!$this->pointsetModel)
  212. {
  213. Yii::log("not pointsetModel! SendPointPrizeOrderNotify failed!");
  214. return ;
  215. }
  216. if ($this->pointsetModel->is_printer)
  217. {
  218. //处理打印机
  219. $this->PrintPointPrizeOrder();
  220. }
  221. //处理短信提醒
  222. $this->SendPointPrizeOrderSMS();
  223. //处理邮件提醒
  224. $this->SendPointPrizeOrderEmail();
  225. //处理微信提醒
  226. $this->SendPointPrizeOrderWeixin();
  227. }
  228. //这个是处理自由打印
  229. public function PrintShopContent($shop_id, $content)
  230. {
  231. $shopprinterModels = ShopPrinter::model()->findAll("shop_id = " . $shop_id);
  232. foreach ($shopprinterModels as $shopprinterModel)
  233. {
  234. $printer_id = $shopprinterModel->printer_id;
  235. $printerModel = Printer::model()->findByPk($printer_id);
  236. if (!$printerModel)
  237. {
  238. continue;
  239. }
  240. $printer_type = $printerModel->printer_type;
  241. $lewaimai_sn = $printerModel->lewaimai_sn;
  242. $member_code = $printerModel->member_code;
  243. $feyin_key = $printerModel->feyin_key;
  244. $device_no = $printerModel->device_no;
  245. $shopcode = $printerModel->shopcode;
  246. $printer_num = $printerModel->printer_num;
  247. $printer_info = $printerModel->printer_info;
  248. $is_cut = $printerModel->is_cut;
  249. $big_ordernum = $printerModel->big_ordernum;
  250. $big_name = $printerModel->big_name;
  251. $big_phone = $printerModel->big_phone;
  252. $big_address = $printerModel->big_address;
  253. $big_content = $printerModel->big_content;
  254. $big_price = $printerModel->big_price;
  255. if ($printer_type == 1 || $printer_type == 2)
  256. {
  257. for ($i = 0; $i < $printer_num; $i++)
  258. {
  259. $content = $content . $returnString;
  260. if ($i != $printer_num - 1)
  261. {
  262. $content = $content . "\r\n\r\n\r\n";
  263. }
  264. }
  265. }
  266. elseif ($printer_type == 3)
  267. {
  268. if ($is_cut)
  269. {
  270. $content = "<1B40><1B40><1B40>" . $content . "<0D0A><0D0A><0D0A><0D0A><0D0A><0D0A>" . "<1D5642000A0A>";
  271. }
  272. else
  273. {
  274. $content = "<1B40><1B40><1B40>" . $content . "<0D0A><0D0A><0D0A><0D0A><0D0A><0D0A><0D0A><0D0A>";
  275. }
  276. }
  277. if ($printer_type == 1)
  278. {
  279. $this->SendFeyinPrinterMessage($member_code, $device_no, $feyin_key, $content);
  280. }
  281. elseif ($printer_type == 2)
  282. {
  283. $this->SendKeLaiLePrinterMessage($shopcode, $content);
  284. }
  285. elseif ($printer_type == 3)
  286. {
  287. $this->SendLewaimaiPrinterMessage(1, $lewaimai_sn, $printer_num, $content);
  288. }
  289. }
  290. }
  291. private function PrintNewOrder()
  292. {
  293. $shopprinterModels = ShopPrinter::model()->findAll("shop_id = " . $this->shopModel->id);
  294. foreach ($shopprinterModels as $shopprinterModel)
  295. {
  296. $printer_id = $shopprinterModel->printer_id;
  297. $printerModel = Printer::model()->findByPk($printer_id);
  298. if (!$printerModel)
  299. {
  300. continue;
  301. }
  302. $printer_type = $printerModel->printer_type;
  303. $autoconfirmed = $printerModel->autoconfirmed;
  304. if($autoconfirmed && ($printer_type == 1 || $printer_type == 2))
  305. {
  306. $this->IsPrinterConfirmed = true;
  307. }
  308. $lewaimai_sn = $printerModel->lewaimai_sn;
  309. $member_code = $printerModel->member_code;
  310. $feyin_key = $printerModel->feyin_key;
  311. $device_no = $printerModel->device_no;
  312. $shopcode = $printerModel->shopcode;
  313. $printer_num = $printerModel->printer_num;
  314. $printer_info = $printerModel->printer_info;
  315. $is_cut = $printerModel->is_cut;
  316. $big_ordernum = $printerModel->big_ordernum;
  317. $big_name = $printerModel->big_name;
  318. $big_phone = $printerModel->big_phone;
  319. $big_address = $printerModel->big_address;
  320. $big_content = $printerModel->big_content;
  321. $big_price = $printerModel->big_price;
  322. if ($printer_type == 1)
  323. {
  324. $content = $this->GetPrinterOrderContent(2, $printer_num, $printer_info, $is_cut, $big_ordernum, $big_name, $big_phone, $big_address, $big_content, $big_price);
  325. $this->SendFeyinPrinterMessage($member_code, $device_no, $feyin_key, $content);
  326. }
  327. elseif ($printer_type == 2)
  328. {
  329. $content = $this->GetPrinterOrderContent(3, $printer_num, $printer_info, $is_cut, $big_ordernum, $big_name, $big_phone, $big_address, $big_content, $big_price);
  330. $this->SendKeLaiLePrinterMessage($shopcode, $content, $this->orderid, $this->orderModel->total_price, $this->orderModel->charge_type);
  331. }
  332. elseif ($printer_type == 3)
  333. {
  334. $content = $this->GetPrinterOrderContent(1, $printer_num, $printer_info, $is_cut, $big_ordernum, $big_name, $big_phone, $big_address, $big_content, $big_price);
  335. $this->SendLewaimaiPrinterMessage($this->orderid, $lewaimai_sn, $printer_num, $content);
  336. }
  337. }
  338. }
  339. //处理短信订单提醒
  340. private function SendNewOrderSMS()
  341. {
  342. $smsvalid = $this->shopModel->smsvalid;
  343. if ($smsvalid)
  344. {
  345. $sms_phone = $this->shopModel->sms_phone;
  346. $OrderString = $this->GetNewOrderSMSString();
  347. $OrderStringLen = mb_strlen($OrderString, 'utf8');
  348. $OrderStringLen = $OrderStringLen + 6; //加上【乐外卖】的长度
  349. $StringQuota = ceil($OrderStringLen/67);
  350. $sms_quota = $this->adminModel->sms_quota;
  351. if ($sms_quota - $StringQuota >= 0)
  352. {
  353. $smsString = $OrderString . "\n" . '发送"#' . $this->orderid . '"确认此订单。';
  354. if (LewaimaiHttp::SendSMSMessage($sms_phone, $smsString))
  355. {
  356. /*更新短信余额*/
  357. $connection = Yii::app()->db;
  358. $sql = "UPDATE wx_admin SET sms_quota = sms_quota - {$StringQuota} WHERE id = " . $this->adminModel->id;
  359. $command = $connection->createCommand($sql);
  360. $command->execute();
  361. /*短信历史记录*/
  362. $phoneMessageHistory = new LewaimaiPhoneMessageHistory();
  363. $phoneMessageHistory->admin_id = $this->orderModel->admin_id;
  364. $phoneMessageHistory->lewaimai_customer_id = $this->orderModel->lewaimai_customer_id;
  365. $phoneMessageHistory->type = 1;
  366. $phoneMessageHistory->phone = $sms_phone;
  367. $phoneMessageHistory->content = $OrderString;
  368. $phoneMessageHistory->order_id = $this->orderid;
  369. $phoneMessageHistory->number = $StringQuota;
  370. $phoneMessageHistory->save();
  371. }
  372. }
  373. }
  374. }
  375. //获取短信内容提醒
  376. private function GetNewOrderSMSString()
  377. {
  378. $shopname = $this->shopModel->shopname;
  379. $OrderString = "“" . $shopname . "”订单 :\n";
  380. $mergeModel = LewaimaiMergeOrderSet::model()->find('admin_id='.$this->orderModel->admin_id.' and shop_id='.$this->orderModel->shop_id);
  381. if ($this->adminModel->order_num_type == 0)
  382. {
  383. $orderNo = $this->orderModel->admin_num;
  384. }
  385. else
  386. {
  387. $orderNo = $this->shopModel->order_prefix . $this->orderModel->shop_num;
  388. }
  389. if ($this->orderCount)
  390. {
  391. $orderCount = $this->orderCount;
  392. }
  393. else
  394. {
  395. if($this->shopModel->showordernum_type == 0)
  396. {
  397. //计算是第几次下单
  398. $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')");
  399. }
  400. else
  401. {
  402. $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')");
  403. }
  404. }
  405. //判断该顾客是不是店铺的会员
  406. $memberModel = LewaimaiMember::model()->find("lewaimai_customer_id = " . $this->orderModel->lewaimai_customer_id . " AND admin_id = " . $this->orderModel->admin_id);
  407. if($this->shopModel->showordernum == 1)
  408. {
  409. if ($memberModel)
  410. {
  411. $OrderString .= "(会员,第" . $orderCount . "次下单)\n";
  412. }
  413. else
  414. {
  415. $OrderString .= "(第" . $orderCount . "次下单)\n";
  416. }
  417. }
  418. $OrderString .= "订单编号:" . $orderNo . "\n";
  419. if($mergeModel and $mergeModel->is_open == 1)
  420. {
  421. if($this->orderModel->mergeorder_id > 0)
  422. {
  423. $OrderString .= "是否是拼单:是\n";
  424. $mergeorderModel = LewaimaiMergeOrder::model() -> findByPk($this->orderModel->mergeorder_id);
  425. $OrderString .= "拼单名字:".$mergeorderModel->name."\n";
  426. $OrderString .= "拼单人数:".$mergeorderModel->nownum."\n";
  427. $OrderString .= "拼单折扣:".$this->orderModel->mergeorder_discount."\n";
  428. }
  429. else
  430. {
  431. $OrderString .= "是否是拼单:不是\n";
  432. }
  433. }
  434. $orderItemModels = LewaimaiOrderItem::model()->findAll("lewaimai_order_id = " . $this->orderid);
  435. foreach ($orderItemModels as $orderItem)
  436. {
  437. $newOrderString = $orderItem->food_name . " " . $orderItem->quantity . "份" . " ¥" . sprintf("%.1f", $orderItem->quantity * $orderItem->price) . "\n";
  438. $OrderString = $OrderString . $newOrderString;
  439. }
  440. $fieldString = '';
  441. $order_field = unserialize($this->orderModel->order_field);
  442. foreach($order_field as $key => $val)
  443. {
  444. $fieldString .= $val["name"] . ":" . $val["content"] . "\n";
  445. }
  446. $delivertime = $this->orderModel->delivertime;
  447. $delivertimeinfo = '';
  448. if($delivertime)
  449. {
  450. $delivertimeinfo = '配送时间: '.$this->orderModel->delivery_date.' '.$delivertime . "\n";
  451. }
  452. if($this->shopModel->open_selftake)
  453. {
  454. if($this->orderModel->is_selftake)
  455. {
  456. $quhuofangshi = "配送方式:到店自取\n";
  457. }
  458. else
  459. {
  460. $quhuofangshi = "配送方式:店家配送\n";
  461. }
  462. }
  463. else
  464. {
  465. $quhuofangshi = '';
  466. }
  467. $nameinfo = "姓名:" . $this->orderModel->nickname . "\n";
  468. $phoneinfo = "电话:" . $this->orderModel->phone . "\n";
  469. $addressinfo = "地址:" . $this->orderModel->address . "\n";
  470. if ($this->orderModel->memo && $this->orderModel->memo != "")
  471. {
  472. $noteinfo = "备注:" . $this->orderModel->memo . "\n";
  473. }
  474. else
  475. {
  476. $noteinfo = "";
  477. }
  478. if ($this->orderModel->is_member_delete)
  479. {
  480. $member_delete_info = "会员优惠:" . $this->orderModel->member_delete . "元" . "\n";
  481. }
  482. else
  483. {
  484. $member_delete_info = "";
  485. }
  486. if($this->orderModel->promotion)
  487. {
  488. $promotion = explode(':',$this->orderModel->promotion);
  489. $promotioninfo = '满'.$promotion[0].'元,减'.$promotion[1].'元'."\n";
  490. }
  491. else
  492. {
  493. $promotioninfo = '';
  494. }
  495. if ($this->orderModel->is_discount == 1)
  496. {
  497. $discountInfo = "店铺折扣:" . $this->orderModel->discount_value . "折" . "\n";
  498. }
  499. else
  500. {
  501. $discountInfo = "";
  502. }
  503. if ($this->orderModel->delivery_fee != 0)
  504. {
  505. $delivery_fee_info = "外送费:¥" . $this->orderModel->delivery_fee . "\n";
  506. }
  507. else
  508. {
  509. $delivery_fee_info = "";
  510. }
  511. $addservicestring = "";
  512. $addservice = unserialize($this->orderModel->addservice);
  513. if(is_array($addservice))
  514. {
  515. foreach($addservice as $addservicekey => $addserviceval)
  516. {
  517. $addservicestring .= $addservicekey.':'.$addserviceval."元\n";
  518. }
  519. }
  520. if ($this->orderModel->is_coupon == 1)
  521. {
  522. $couponInfo = "优惠券:" . $this->orderModel->coupon_value . "元" . "\n ";
  523. }
  524. else
  525. {
  526. $couponInfo = "";
  527. }
  528. $totalpriceInfo = "合计:¥" . $this->orderModel->total_price;
  529. if ($this->orderModel->charge_type == 1)
  530. {
  531. $totalpriceInfo = $totalpriceInfo . "(未付款)";
  532. }
  533. else
  534. {
  535. $totalpriceInfo = $totalpriceInfo . "(已付款)";
  536. }
  537. $OrderString = $OrderString .$quhuofangshi. $nameinfo . $phoneinfo . $addressinfo . $fieldString . $delivertimeinfo . $noteinfo . $member_delete_info .$promotioninfo. $discountInfo . $delivery_fee_info . $addservicestring . $couponInfo . $totalpriceInfo;
  538. return $OrderString;
  539. }
  540. //发送取消订单的短信提醒
  541. private function SendCancelOrderSMS()
  542. {
  543. $smsvalid = $this->shopModel->smsvalid;
  544. if ($smsvalid)
  545. {
  546. $sms_phone = $this->shopModel->sms_phone;
  547. $OrderString = $this->GetCancelOrderSMSString();
  548. $OrderStringLen = mb_strlen($OrderString, 'utf8');
  549. $OrderStringLen = $OrderStringLen + 6; //加上【乐外卖】的长度
  550. $StringQuota = ceil($OrderStringLen/67);
  551. $sms_quota = $this->adminModel->sms_quota;
  552. if ($sms_quota - $StringQuota >= 0)
  553. {
  554. $smsString = $OrderString . "\n" . '发送"#' . $this->orderid . '"确认此订单。';
  555. if (LewaimaiHttp::SendSMSMessage($sms_phone, $smsString))
  556. {
  557. /*更新短信余额*/
  558. $connection = Yii::app()->db;
  559. $sql = "UPDATE wx_admin SET sms_quota = sms_quota - {$StringQuota} WHERE id = " . $this->adminModel->id;
  560. $command = $connection->createCommand($sql);
  561. $command->execute();
  562. /*短信历史记录*/
  563. $phoneMessageHistory = new LewaimaiPhoneMessageHistory();
  564. $phoneMessageHistory->admin_id = $this->orderModel->admin_id;
  565. $phoneMessageHistory->lewaimai_customer_id = $this->orderModel->lewaimai_customer_id;
  566. $phoneMessageHistory->type = 4;
  567. $phoneMessageHistory->phone = $sms_phone;
  568. $phoneMessageHistory->content = $OrderString;
  569. $phoneMessageHistory->order_id = $this->orderid;
  570. $phoneMessageHistory->number = $StringQuota;
  571. $phoneMessageHistory->save();
  572. }
  573. }
  574. }
  575. }
  576. private function SendPointPrizeOrderSMS()
  577. {
  578. //判断是否发短信
  579. $smsvalid = $this->pointsetModel->is_duanxin;
  580. if (!$smsvalid)
  581. {
  582. return ;
  583. }
  584. $sms_phone = $this->pointsetModel->iphone;
  585. $OrderString = $this->GetPointPrizeOrderSMSString();
  586. $OrderStringLen = mb_strlen($OrderString,'utf8');
  587. $OrderStringLen = $OrderStringLen + 6; //加上【乐外卖】的长度
  588. $StringQuota = ceil($OrderStringLen/67);
  589. $adminModel = Admin::model()->findByPk($this->orderModel->admin_id);
  590. if ($adminModel)
  591. {
  592. $sms_quota = $adminModel->sms_quota;
  593. if ($sms_quota - $StringQuota >= 0){
  594. if (LewaimaiHttp::SendSMSMessage($sms_phone, $OrderString)) {
  595. /*更新短信余额*/
  596. $connection = Yii::app()->db;
  597. $sql = "UPDATE wx_admin SET sms_quota = sms_quota - {$StringQuota} WHERE id = " . $adminModel->id;
  598. $command = $connection->createCommand($sql);
  599. $command->execute();
  600. /*短信历史记录*/
  601. $phoneMessageHistory = new LewaimaiPhoneMessageHistory();
  602. $phoneMessageHistory->admin_id = $this->orderModel->admin_id;
  603. $phoneMessageHistory->lewaimai_customer_id = $this->orderModel->lewaimai_customer_id;
  604. $phoneMessageHistory->type = 5;
  605. $phoneMessageHistory->phone = $sms_phone;
  606. $phoneMessageHistory->content = $OrderString;
  607. $phoneMessageHistory->order_id = $this->orderid;
  608. $phoneMessageHistory->number = $StringQuota;
  609. $phoneMessageHistory->save();
  610. }
  611. }
  612. }
  613. }
  614. //处理打印机自动确认后的订单状态问题
  615. private function HandOrderConfirmed()
  616. {
  617. if (!$this->IsPrinterConfirmed)
  618. {
  619. return ;
  620. }
  621. //将订单改为确认状态
  622. $connection = Yii::app()->db;
  623. $sql = "UPDATE wx_lewaimai_order SET order_status = 'CONFIRMED' WHERE id = " . $this->orderid;
  624. $command = $connection->createCommand($sql);
  625. $command->execute();
  626. //给顾客发送订单确认的短信提醒
  627. $this->SendOrderConfirmedSMS();
  628. //给顾客发送订单确认的模板消息通知
  629. LewaimaiWeixinTemplate::SendOrderConfirmedTemplate($this->orderid, $this->orderModel);
  630. //处理订单确认后的商品销量问题
  631. $this->OrderConfirmedAddFoodSales();
  632. }
  633. //给顾客发送订单确认的短信提醒
  634. private function SendOrderConfirmedSMS()
  635. {
  636. //处理打印机确认订单时候的短信提醒问题
  637. if($this->adminModel->is_confirm_msg == 1)
  638. {
  639. $sms_quota = $this->adminModel->sms_quota;
  640. $content = $this->shopModel->confirmmsg;
  641. $ContentStringLen = mb_strlen($content,'utf8');
  642. $ContentStringLen = $ContentStringLen + 6;
  643. $StringQuota = ceil($ContentStringLen/67);
  644. if($sms_quota - $StringQuota >= 0)
  645. {
  646. if(LewaimaiHttp::SendSMSMessage($this->orderModel->phone, $content))
  647. {
  648. /*更新短信余额*/
  649. $connection = Yii::app()->db;
  650. $sql = "UPDATE wx_admin SET sms_quota = sms_quota - {$StringQuota} WHERE id = " . $this->adminModel->id;
  651. $command = $connection->createCommand($sql);
  652. $command->execute();
  653. /*短信历史记录*/
  654. $phoneMessageHistory = new LewaimaiPhoneMessageHistory();
  655. $phoneMessageHistory->admin_id = $this->adminModel->id;
  656. $phoneMessageHistory->type = 3;
  657. $phoneMessageHistory->phone = $this->orderModel->phone;
  658. $phoneMessageHistory->content = $content;
  659. $phoneMessageHistory->order_id = $this->orderid;
  660. $phoneMessageHistory->number = $StringQuota;
  661. $phoneMessageHistory->save();
  662. }
  663. }
  664. }
  665. }
  666. //修改商品的销量
  667. private function OrderConfirmedAddFoodSales()
  668. {
  669. $fooditemlist = LewaimaiOrderItem::model()->findAll("lewaimai_order_id='$this->orderid'");
  670. $time = strtotime(date('Y-m-d H:i:s'));
  671. $todaystart = strtotime(date('Y-m-d'));
  672. foreach($fooditemlist as $fooditem)
  673. {
  674. $foodModel = Food::Model()->findByPk($fooditem->food_id);
  675. if($foodModel)
  676. {
  677. $foodModel->ordered_count += $fooditem->quantity;
  678. if($todaystart > $foodModel->lastsaletime)
  679. {
  680. $foodModel->todaysales = $fooditem->quantity;
  681. $foodModel->lastsaletime = $time;
  682. }
  683. else
  684. {
  685. $foodModel->todaysales += $fooditem->quantity;
  686. }
  687. if(!$foodModel->save())
  688. {
  689. foreach ($foodModel->errors as $key => $value)
  690. {
  691. foreach ($value as $valuestring);
  692. {
  693. Yii::log("food Model valuestring:" . $valuestring);
  694. }
  695. }
  696. }
  697. }
  698. }
  699. }
  700. private function GetCancelOrderSMSString()
  701. {
  702. $shopname = $this->shopModel->shopname;
  703. $OrderString = "***订单取消通知***\n“" . $shopname . "”的一笔订单已被顾客取消,订单信息如下:\n";
  704. $adminModel = $this->adminModel;
  705. $mergeModel = LewaimaiMergeOrderSet::model()->find('admin_id='.$this->orderModel->admin_id.' and shop_id='.$this->orderModel->shop_id);
  706. if ($adminModel->order_num_type == 0)
  707. {
  708. $orderNo = $this->orderModel->admin_num;
  709. }
  710. else
  711. {
  712. $orderNo = $this->shopModel->order_prefix . $this->orderModel->shop_num;
  713. }
  714. if ($this->orderCount)
  715. {
  716. $orderCount = $this->orderCount;
  717. }
  718. else
  719. {
  720. if($this->shopModel->showordernum_type == 0)
  721. {
  722. //计算是第几次下单
  723. $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')");
  724. }
  725. else
  726. {
  727. $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')");
  728. }
  729. }
  730. //判断该顾客是不是店铺的会员
  731. $memberModel = LewaimaiMember::model()->find("lewaimai_customer_id = " . $this->orderModel->lewaimai_customer_id . " AND admin_id = " . $this->orderModel->admin_id);
  732. if($this->shopModel->showordernum == 1)
  733. {
  734. if ($memberModel)
  735. {
  736. $OrderString .= "(会员,第" . $orderCount . "次下单)\n";
  737. }
  738. else
  739. {
  740. $OrderString .= "(第" . $orderCount . "次下单)\n";
  741. }
  742. }
  743. $OrderString .= "订单编号:" . $orderNo . "\n";
  744. if($mergeModel and $mergeModel->is_open==1)
  745. {
  746. if($this->orderModel->mergeorder_id > 0)
  747. {
  748. $OrderString .= "是否是拼单:是\n";
  749. $mergeorderModel = LewaimaiMergeOrder::model() -> findByPk($this->orderModel->mergeorder_id);
  750. $OrderString .= "拼单名字:".$mergeorderModel->name."\n";
  751. $OrderString .= "拼单人数:".$mergeorderModel->nownum."\n";
  752. $OrderString .= "拼单折扣:".$this->orderModel->mergeorder_discount."\n";
  753. }
  754. else
  755. {
  756. $OrderString .= "是否是拼单:不是\n";
  757. }
  758. }
  759. $ordertime = "下单时间:" . $this->orderModel->init_date . "\n";
  760. $fieldString = '';
  761. $order_field = unserialize($this->orderModel->order_field);
  762. foreach($order_field as $key => $val)
  763. {
  764. $fieldString .= $val["name"] . ":" . $val["content"] . "\n";
  765. }
  766. $delivertime = $this->orderModel->delivertime;
  767. $delivertimeinfo = '';
  768. if($delivertime)
  769. {
  770. $delivertimeinfo = '配送时间: '.$this->orderModel->delivery_date.' '.$delivertime. "\n";
  771. }
  772. if($this->shopModel->open_selftake)
  773. {
  774. if($this->orderModel->is_selftake)
  775. {
  776. $quhuofangshi = "配送方式:到店自取\n";
  777. }
  778. else
  779. {
  780. $quhuofangshi = "配送方式:店家配送\n";
  781. }
  782. }
  783. else
  784. {
  785. $quhuofangshi = '';
  786. }
  787. $nameinfo = "姓名:" . $this->orderModel->nickname . "\n";
  788. $phoneinfo = "电话:" . $this->orderModel->phone . "\n";
  789. $addressinfo = "地址:" . $this->orderModel->address . "\n";
  790. $totalpriceInfo = "合计:¥" . $this->orderModel->total_price;
  791. if ($this->orderModel->charge_type == 1)
  792. {
  793. $totalpriceInfo = $totalpriceInfo . "(未付款)\n";
  794. }
  795. elseif ($this->orderModel->charge_type == 2)
  796. {
  797. $totalpriceInfo = $totalpriceInfo . "(余额付款)\n";
  798. }
  799. else
  800. {
  801. $totalpriceInfo = $totalpriceInfo . "(在线支付)\n";
  802. }
  803. $CancelOrderString = $OrderString . $quhuofangshi.$ordertime . $nameinfo . $phoneinfo . $addressinfo . $fieldString . $delivertimeinfo . $totalpriceInfo;
  804. return $CancelOrderString;
  805. }
  806. private function GetPointPrizeOrderSMSString()
  807. {
  808. $OrderString = "积分兑奖通知 :\n";
  809. $orderItemModels = LewaimaiPointprizeOrderItem::model()->findAll("lewaimai_order_id = " . $this->orderModel->id);
  810. foreach ($orderItemModels as $orderItem)
  811. {
  812. $newOrderString = $orderItem->prize_name . " " . $orderItem->quantity . "份" . "\n";
  813. $OrderString = $OrderString . $newOrderString;
  814. }
  815. $nameinfo = "姓名:" . $this->orderModel->name . "\n";
  816. $phoneinfo = "电话:" . $this->orderModel->phone . "\n";
  817. $addressinfo = "地址:" . $this->orderModel->address . "\n";
  818. $noteinfo = "备注:" . $this->orderModel->memo . "\n";
  819. $OrderString = $OrderString . $nameinfo . $phoneinfo . $addressinfo . $noteinfo;
  820. return $OrderString;
  821. }
  822. private function SendNewOrderEmail()
  823. {
  824. //判断是否发邮件
  825. $emailvalid = $this->shopModel->emailvalid;
  826. if (!$emailvalid)
  827. {
  828. return ;
  829. }
  830. $email_address = $this->shopModel->email_address;
  831. $adminId = $this->orderModel->admin_id;
  832. $shopId = $this->orderModel->shop_id;
  833. $orderModel = $this->orderModel;
  834. $nickname = $this->orderModel->nickname;
  835. $phone = $this->orderModel->phone;
  836. $address = $this->orderModel->address;
  837. $note = $this->orderModel->memo;
  838. $totalPrice = $this->orderModel->total_price;
  839. $delivery_fee = $this->orderModel->delivery_fee;
  840. $order_field = $this->orderModel->order_field;
  841. $delivertime = $this->orderModel->delivertime;
  842. $receiveEmail = $email_address;
  843. $receiveName = '';
  844. $mergeModel = LewaimaiMergeOrderSet::model()->find('admin_id='.$this->orderModel->admin_id.' and shop_id='.$this->orderModel->shop_id);
  845. $mergeString = '';
  846. if($mergeModel and $mergeModel->is_open==1)
  847. {
  848. if($this->orderModel->mergeorder_id > 0)
  849. {
  850. $mergeorderModel = LewaimaiMergeOrder::model() -> findByPk($this->orderModel->mergeorder_id);
  851. $mergeString = '
  852. <tr>
  853. <td><strong>是否是拼单:</strong></td>
  854. <td>是</td>
  855. </tr>';
  856. $mergeString .= '
  857. <tr>
  858. <td><strong>拼单名字:</strong></td>
  859. <td>'.$mergeorderModel->name.'</td>
  860. </tr>';
  861. $mergeString .= '
  862. <tr>
  863. <td><strong>拼单人数:</strong></td>
  864. <td>'.$mergeorderModel->nownum.'</td>
  865. </tr>';
  866. $mergeString .= '
  867. <tr>
  868. <td><strong>拼单折扣:</strong></td>
  869. <td>'.$this->orderModel->mergeorder_discount.'</td>
  870. </tr>';
  871. }
  872. else
  873. {
  874. $mergeString = '
  875. <tr>
  876. <td><strong>是否是拼单:</strong></td>
  877. <td>不是</td>
  878. </tr>';
  879. }
  880. }
  881. // 获取店铺名字
  882. $shopModel = $this->shopModel;
  883. if ($this->orderCount)
  884. {
  885. $orderCount = $this->orderCount;
  886. }
  887. else
  888. {
  889. //计算是第几次下单
  890. if($shopModel->showordernum_type == 0)
  891. {
  892. $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')");
  893. }
  894. else
  895. {
  896. $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')");
  897. }
  898. }
  899. $shopname = $shopModel->shopname;
  900. if($shopModel->open_selftake)
  901. {
  902. if($this->orderModel->is_selftake)
  903. {
  904. $quhuofangshi = '
  905. <tr>
  906. <td><strong>配送方式:</strong></td>
  907. <td>到店自取</td>
  908. </tr>';
  909. }
  910. else
  911. {
  912. $quhuofangshi = '
  913. <tr>
  914. <td><strong>配送方式:</strong></td>
  915. <td>店家配送</td>
  916. </tr>';
  917. }
  918. }
  919. else
  920. {
  921. $quhuofangshi = '';
  922. }
  923. // 处理预设选项
  924. $order_field = unserialize($order_field);
  925. $fieldString = "";
  926. foreach($order_field as $key => $val)
  927. {
  928. $fieldString .= '
  929. <tr>
  930. <td valign="top"><strong>' . $val["name"] . ':</strong></td>
  931. <td>' . $val["content"] . '</td>
  932. </tr>';
  933. }
  934. $DefaultOrderString = '
  935. <tr>
  936. <td><strong>订单详情:</strong></td>
  937. <td></td>
  938. </tr>';
  939. $orderItemModels = LewaimaiOrderItem::model()->findAll("lewaimai_order_id = " . $orderModel->id);
  940. if (!$orderItemModels)
  941. {
  942. $OrderString = $DefaultOrderString;
  943. }
  944. elseif (count($orderItemModels) == 1)
  945. {
  946. $orderItemModel = $orderItemModels[0];
  947. $OrderString = '
  948. <tr>
  949. <td><strong>订单详情:</strong></td>
  950. <td>' . $orderItemModel->food_name . " " . $orderItemModel->quantity . "份" . " ¥" . sprintf("%.1f", $orderItemModel->quantity*$orderItemModel->price) . '</td>
  951. </tr>';
  952. }
  953. else
  954. {
  955. $orderItemModel = $orderItemModels[0];
  956. $OrderString = '
  957. <tr>
  958. <td><strong>订单详情:</strong></td>
  959. <td>' . $orderItemModel->food_name . " " . $orderItemModel->quantity . "份" . " ¥" . sprintf("%.1f", $orderItemModel->quantity*$orderItemModel->price) . '</td>
  960. </tr>';
  961. for ($i = 1; $i < count($orderItemModels); $i++)
  962. {
  963. $orderItemModel = $orderItemModels[$i];
  964. $newOrderString = '
  965. <tr>
  966. <td></td>
  967. <td>' . $orderItemModel->food_name . " " . $orderItemModel->quantity . "份" . " ¥" . sprintf("%.1f", $orderItemModel->quantity*$orderItemModel->price) . '</td>
  968. </tr>';
  969. $OrderString = $OrderString . $newOrderString;
  970. }
  971. }
  972. $adminModel = $this->adminModel;
  973. if ($adminModel->order_num_type == 0)
  974. {
  975. $orderNo = $orderModel->admin_num;
  976. }
  977. else
  978. {
  979. $orderNo = $shopModel->order_prefix . $orderModel->shop_num;
  980. }
  981. $deliverinfo = "";
  982. if($delivertime)
  983. {
  984. $deliverinfo = '<tr><td><strong>配送时间:</strong></td><td>'.$orderModel->delivery_date.' '.$delivertime.'</td></tr>';
  985. }
  986. //判断该顾客是不是店铺的会员
  987. $memberModel = LewaimaiMember::model()->find("lewaimai_customer_id = " . $this->orderModel->lewaimai_customer_id . " AND admin_id = " . $this->orderModel->admin_id);
  988. if($shopModel->showordernum == 1)
  989. {
  990. if ($memberModel)
  991. {
  992. $nickname .= "(会员,第" . $orderCount . "次下单)";
  993. }
  994. else
  995. {
  996. $nickname .= "(第" . $orderCount . "次下单)";
  997. }
  998. }
  999. $Subject = '您有一笔乐外卖新订单,请尽快处理!';
  1000. $Content = '
  1001. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  1002. <html xmlns="http://www.w3.org/1999/xhtml">
  1003. <head>
  1004. <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  1005. <title>无标题文档</title>
  1006. <style type="text/css">
  1007. body,td,th {
  1008. font-size: 18px;
  1009. }
  1010. .price {
  1011. color: #F00;
  1012. }
  1013. </style>
  1014. </head>
  1015. <body>
  1016. <table width="100%" align="center">
  1017. <tr>
  1018. <td colspan="2" align="center"><h1><strong>乐外卖订单信息</strong></h1>
  1019. <hr /></td>
  1020. </tr>
  1021. <tr>
  1022. <td width="100"><strong>订单编号:</strong></td>
  1023. <td>' . $orderNo . '</td>
  1024. </tr>'
  1025. .$mergeString.
  1026. '<tr>
  1027. <td><strong>店铺名称:</strong></td>
  1028. <td>' . $shopname . '</td>
  1029. </tr>
  1030. '.$quhuofangshi.'
  1031. <tr>
  1032. <td><strong>姓名:</strong></td>
  1033. <td>' . $nickname . '</td>
  1034. </tr>
  1035. <tr>
  1036. <td><strong>电话:</strong></td>
  1037. <td>' . $phone . '</td>
  1038. </tr>
  1039. <tr>
  1040. <td valign="top"><strong>地址:</strong></td>
  1041. <td>' . $address . '</td>
  1042. </tr>' .
  1043. $fieldString .
  1044. $deliverinfo .
  1045. '<tr>
  1046. <td><strong>下单时间:</strong></td>
  1047. <td>' . date("Y-m-d H:i:s") . '</td>
  1048. </tr>
  1049. ' . $OrderString . '
  1050. <tr>
  1051. <td valign="top"><strong>备注:</strong></td>
  1052. <td>' . $note . '</td>
  1053. </tr>
  1054. ';
  1055. if ($orderModel->is_member_delete)
  1056. {
  1057. $memberdeleteInfo = '
  1058. <tr>
  1059. <td><strong>会员优惠:</strong></td>
  1060. <td>' . $orderModel->member_delete . '元</td>
  1061. </tr>';
  1062. }
  1063. else
  1064. {
  1065. $memberdeleteInfo = "";
  1066. }
  1067. if($orderModel->promotion)
  1068. {
  1069. $promotion = explode(':',$orderModel->promotion);
  1070. $promotioninfo = '
  1071. <tr>
  1072. <td><strong></strong></td>
  1073. <td>满' . $promotion[0] . '元送'.$promotion[1].'元</td>
  1074. </tr>';
  1075. }
  1076. else
  1077. {
  1078. $promotioninfo = '';
  1079. }
  1080. if ($orderModel->is_discount == 1)
  1081. {
  1082. $discountInfo = '
  1083. <tr>
  1084. <td><strong>店铺折扣:</strong></td>
  1085. <td>' . $orderModel->discount_value . '折</td>
  1086. </tr>';
  1087. }
  1088. else
  1089. {
  1090. $discountInfo = "";
  1091. }
  1092. $delivery_fee_string = '
  1093. <tr>
  1094. <td><strong>外送费:</strong></td>
  1095. <td>¥' . $delivery_fee . '</td>
  1096. </tr>';
  1097. if ($delivery_fee != 0)
  1098. {
  1099. $delivery_fee_info = $delivery_fee_string;
  1100. }
  1101. else
  1102. {
  1103. $delivery_fee_info = "";
  1104. }
  1105. $addservicestring = "";
  1106. $addservice = unserialize($orderModel->addservice);
  1107. if(is_array($addservice))
  1108. {
  1109. foreach($addservice as $addservicekey => $addserviceval)
  1110. {
  1111. $addservicestring .= '
  1112. <tr>
  1113. <td><strong>'.$addservicekey.':</strong></td>
  1114. <td>' . $addserviceval . '元</td>
  1115. </tr>';
  1116. }
  1117. }
  1118. if ($orderModel->is_coupon == 1)
  1119. {
  1120. $couponInfo = '
  1121. <tr>
  1122. <td><strong>优惠券:</strong></td>
  1123. <td>' . $orderModel->coupon_value . '元</td>
  1124. </tr>';
  1125. }
  1126. else
  1127. {
  1128. $couponInfo = "";
  1129. }
  1130. if ($orderModel->charge_type == 1)
  1131. {
  1132. $totalpriceInfo = '
  1133. <tr>
  1134. <td><strong>总金额:</strong></td>
  1135. <td><span class="price">¥' . $totalPrice . '</span>(未付款)</td>
  1136. </tr>';
  1137. }
  1138. else
  1139. {
  1140. $totalpriceInfo = '
  1141. <tr>
  1142. <td><strong>总金额:</strong></td>
  1143. <td><span class="price">¥' . $totalPrice . '</span>(已付款)</td>
  1144. </tr>';
  1145. }
  1146. $Content = $Content . $memberdeleteInfo . $promotioninfo . $discountInfo . $delivery_fee_info . $addservicestring . $couponInfo . $totalpriceInfo .
  1147. '</table>
  1148. </body>
  1149. </html>
  1150. ';
  1151. SendEmail($receiveEmail, $receiveName, $Subject, $Content);
  1152. }
  1153. private function SendNewOrderWeixin()
  1154. {
  1155. //判断是否发微信消息
  1156. $weixinvalid = $this->shopModel->weixinvalid;
  1157. if (!$weixinvalid)
  1158. {
  1159. return ;
  1160. }
  1161. LewaimaiWeixinTemplate::SendNewOrderTemplate($this->orderid, $this->orderModel, $this->shopModel);
  1162. }
  1163. private function SendCancelOrderWeixin()
  1164. {
  1165. //判断是否发微信消息
  1166. $weixinvalid = $this->shopModel->weixinvalid;
  1167. if (!$weixinvalid)
  1168. {
  1169. return ;
  1170. }
  1171. LewaimaiWeixinTemplate::SendCancelOrderTemplate($this->orderid, $this->orderModel, $this->shopModel);
  1172. }
  1173. private function SendPointPrizeOrderWeixin()
  1174. {
  1175. $weixinvalid = $this->pointsetModel->is_weixin;
  1176. if (!$weixinvalid)
  1177. {
  1178. return ;
  1179. }
  1180. LewaimaiWeixinTemplate::SendPointPrizeOrderTemplate($this->orderModel->id, $this->orderModel, $this->pointsetModel, $this->GetPointPrizeOrderSMSString());
  1181. }
  1182. private function SendCancelOrderEmail()
  1183. {
  1184. $emailvalid = $this->shopModel->emailvalid;
  1185. if (!$emailvalid)
  1186. {
  1187. return ;
  1188. }
  1189. $email_address = $this->shopModel->email_address;
  1190. $adminId = $this->orderModel->admin_id;
  1191. $shopId = $this->orderModel->shop_id;
  1192. $orderModel = $this->orderModel;
  1193. $nickname = $this->orderModel->nickname;
  1194. $phone = $this->orderModel->phone;
  1195. $address = $this->orderModel->address;
  1196. $note = $this->orderModel->memo;
  1197. $totalPrice = $this->orderModel->total_price;
  1198. $delivery_fee = $this->orderModel->delivery_fee;
  1199. $order_field = $this->orderModel->order_field;
  1200. $delivertime = $this->orderModel->delivertime;
  1201. $receiveEmail = $email_address;
  1202. $mergeModel = LewaimaiMergeOrderSet::model()->find('admin_id='.$this->orderModel->admin_id.' and shop_id='.$this->orderModel->shop_id);
  1203. $mergeString = '';
  1204. if($mergeModel and $mergeModel->is_open==1)
  1205. {
  1206. if($this->orderModel->mergeorder_id > 0)
  1207. {
  1208. $mergeorderModel = LewaimaiMergeOrder::model() -> findByPk($this->orderModel->mergeorder_id);
  1209. $mergeString = '
  1210. <tr>
  1211. <td><strong>是否是拼单:</strong></td>
  1212. <td>是</td>
  1213. </tr>';
  1214. $mergeString .= '
  1215. <tr>
  1216. <td><strong>拼单名字:</strong></td>
  1217. <td>'.$mergeorderModel->name.'</td>
  1218. </tr>';
  1219. $mergeString .= '
  1220. <tr>
  1221. <td><strong>拼单人数:</strong></td>
  1222. <td>'.$mergeorderModel->nownum.'</td>
  1223. </tr>';
  1224. $mergeString .= '
  1225. <tr>
  1226. <td><strong>拼单折扣:</strong></td>
  1227. <td>'.$this->orderModel->mergeorder_discount.'</td>
  1228. </tr>';
  1229. }
  1230. else
  1231. {
  1232. $mergeString = '
  1233. <tr>
  1234. <td><strong>是否是拼单:</strong></td>
  1235. <td>不是</td>
  1236. </tr>';
  1237. }
  1238. }
  1239. // 获取店铺名字
  1240. $shopModel = $this->shopModel;
  1241. if ($this->orderCount)
  1242. {
  1243. $orderCount = $this->orderCount;
  1244. }
  1245. else
  1246. {
  1247. if($this->shopModel->showordernum_type == 0)
  1248. {
  1249. //计算是第几次下单
  1250. $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')");
  1251. }
  1252. else
  1253. {
  1254. $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')");
  1255. }
  1256. }
  1257. $receiveName = '';
  1258. $shopname = $shopModel->shopname;
  1259. if($shopModel->open_selftake){
  1260. if($this->orderModel->is_selftake)
  1261. {
  1262. $quhuofangshi = '
  1263. <tr>
  1264. <td><strong>配送方式:</strong></td>
  1265. <td>到店自取</td>
  1266. </tr>';
  1267. }
  1268. else
  1269. {
  1270. $quhuofangshi = '
  1271. <tr>
  1272. <td><strong>配送方式:</strong></td>
  1273. <td>店家配送</td>
  1274. </tr>';
  1275. }
  1276. }
  1277. else
  1278. {
  1279. $quhuofangshi = '';
  1280. }
  1281. // 处理预设选项
  1282. $order_field = unserialize($order_field);
  1283. $fieldString = "";
  1284. foreach($order_field as $key => $val)
  1285. {
  1286. $fieldString .= '
  1287. <tr>
  1288. <td valign="top"><strong>' . $val["name"] . ':</strong></td>
  1289. <td>' . $val["content"] . '</td>
  1290. </tr>';
  1291. }
  1292. $DefaultOrderString = '
  1293. <tr>
  1294. <td><strong>订单详情:</strong></td>
  1295. <td></td>
  1296. </tr>';
  1297. $orderItemModels = LewaimaiOrderItem::model()->findAll("lewaimai_order_id = " . $orderModel->id);
  1298. if (!$orderItemModels)
  1299. {
  1300. $OrderString = $DefaultOrderString;
  1301. }
  1302. elseif (count($orderItemModels) == 1)
  1303. {
  1304. $orderItemModel = $orderItemModels[0];
  1305. $OrderString = '
  1306. <tr>
  1307. <td><strong>订单详情:</strong></td>
  1308. <td>' . $orderItemModel->food_name . " " . $orderItemModel->quantity . "份" . " ¥" . sprintf("%.1f", $orderItemModel->quantity*$orderItemModel->price) . '</td>
  1309. </tr>';
  1310. }
  1311. else
  1312. {
  1313. $orderItemModel = $orderItemModels[0];
  1314. $OrderString = '
  1315. <tr>
  1316. <td><strong>订单详情:</strong></td>
  1317. <td>' . $orderItemModel->food_name . " " . $orderItemModel->quantity . "份" . " ¥" . sprintf("%.1f", $orderItemModel->quantity*$orderItemModel->price) . '</td>
  1318. </tr>';
  1319. for ($i = 1; $i < count($orderItemModels); $i++)
  1320. {
  1321. $orderItemModel = $orderItemModels[$i];
  1322. $newOrderString = '
  1323. <tr>
  1324. <td></td>
  1325. <td>' . $orderItemModel->food_name . " " . $orderItemModel->quantity . "份" . " ¥" . sprintf("%.1f", $orderItemModel->quantity*$orderItemModel->price) . '</td>
  1326. </tr>';
  1327. $OrderString = $OrderString . $newOrderString;
  1328. }
  1329. }
  1330. $delivery_fee_string = '
  1331. <tr>
  1332. <td><strong>外送费:</strong></td>
  1333. <td>¥' . $delivery_fee . '</td>
  1334. </tr>';
  1335. if ($delivery_fee != 0)
  1336. {
  1337. $delivery_fee_info = $delivery_fee_string;
  1338. }
  1339. else
  1340. {
  1341. $delivery_fee_info = "";
  1342. }
  1343. $adminModel = $this->adminModel;
  1344. if ($adminModel->order_num_type == 0)
  1345. {
  1346. $orderNo = $orderModel->admin_num;
  1347. }
  1348. else
  1349. {
  1350. $orderNo = $shopModel->order_prefix . $orderModel->shop_num;
  1351. }
  1352. $deliverinfo = "";
  1353. if($delivertime)
  1354. {
  1355. $deliverinfo = '<tr><td><strong>配送时间:</strong></td><td>'.$orderModel->delivery_date.' '.$delivertime.'</td></tr>';
  1356. }
  1357. //判断该顾客是不是店铺的会员
  1358. $memberModel = LewaimaiMember::model()->find("lewaimai_customer_id = " . $this->orderModel->lewaimai_customer_id . " AND admin_id = " . $this->orderModel->admin_id);
  1359. if($shopModel->showordernum == 1)
  1360. {
  1361. if ($memberModel)
  1362. {
  1363. $nickname .= "(会员,第" . $orderCount . "次下单)";
  1364. }
  1365. else
  1366. {
  1367. $nickname .= "(第" . $orderCount . "次下单)";
  1368. }
  1369. }
  1370. $Subject = '乐外卖订单取消通知!';
  1371. $Content = '
  1372. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  1373. <html xmlns="http://www.w3.org/1999/xhtml">
  1374. <head>
  1375. <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  1376. <title>无标题文档</title>
  1377. <style type="text/css">
  1378. body,td,th {
  1379. font-size: 18px;
  1380. }
  1381. .price {
  1382. color: #F00;
  1383. }
  1384. </style>
  1385. </head>
  1386. <body>
  1387. <table width="100%" align="center">
  1388. <tr>
  1389. <td colspan="2" align="center"><h1><strong>被取消订单信息</strong></h1>
  1390. <hr /></td>
  1391. </tr>
  1392. <tr>
  1393. <td width="100"><strong>订单编号:</strong></td>
  1394. <td>' . $orderNo . '</td>
  1395. </tr>'
  1396. .$mergeString.
  1397. '<tr>
  1398. <td><strong>店铺名称:</strong></td>
  1399. <td>' . $shopname . '</td>
  1400. </tr>
  1401. '.$quhuofangshi.'
  1402. <tr>
  1403. <td><strong>姓名:</strong></td>
  1404. <td>' . $nickname . '</td>
  1405. </tr>
  1406. <tr>
  1407. <td><strong>电话:</strong></td>
  1408. <td>' . $phone . '</td>
  1409. </tr>
  1410. <tr>
  1411. <td valign="top"><strong>地址:</strong></td>
  1412. <td>' . $address . '</td>
  1413. </tr>' .
  1414. $fieldString .
  1415. $deliverinfo .
  1416. '<tr>
  1417. <td><strong>下单时间:</strong></td>
  1418. <td>' . date("Y-m-d H:i:s") . '</td>
  1419. </tr>
  1420. ' . $OrderString . '
  1421. <tr>
  1422. <td valign="top"><strong>备注:</strong></td>
  1423. <td>' . $note . '</td>
  1424. </tr>
  1425. ';
  1426. if ($orderModel->is_member_delete)
  1427. {
  1428. $memberdeleteInfo = '
  1429. <tr>
  1430. <td><strong>会员优惠:</strong></td>
  1431. <td>' . $orderModel->member_delete . '元</td>
  1432. </tr>';
  1433. }
  1434. else
  1435. {
  1436. $memberdeleteInfo = "";
  1437. }
  1438. if($orderModel->promotion)
  1439. {
  1440. $promotion = explode(':',$orderModel->promotion);
  1441. $promotioninfo = '
  1442. <tr>
  1443. <td><strong></strong></td>
  1444. <td>满' . $promotion[0] . '元减'.$promotion[1].'</td>
  1445. </tr>';
  1446. }
  1447. else
  1448. {
  1449. $promotioninfo = '';
  1450. }
  1451. if ($orderModel->is_discount == 1)
  1452. {
  1453. $discountInfo = '
  1454. <tr>
  1455. <td><strong>店铺折扣:</strong></td>
  1456. <td>' . $orderModel->discount_value . '折</td>
  1457. </tr>';
  1458. }
  1459. else
  1460. {
  1461. $discountInfo = "";
  1462. }
  1463. $addservicestring = "";
  1464. $addservice = unserialize($orderModel->addservice);
  1465. if(is_array($addservice))
  1466. {
  1467. foreach($addservice as $addservicekey => $addserviceval)
  1468. {
  1469. $addservicestring .= '
  1470. <tr>
  1471. <td><strong>'.$addservicekey.':</strong></td>
  1472. <td>' . $addserviceval . '元</td>
  1473. </tr>';
  1474. }
  1475. }
  1476. if ($orderModel->is_coupon == 1)
  1477. {
  1478. $couponInfo = '
  1479. <tr>
  1480. <td><strong>优惠券:</strong></td>
  1481. <td>' . $orderModel->coupon_value . '元</td>
  1482. </tr>';
  1483. }
  1484. else
  1485. {
  1486. $couponInfo = "";
  1487. }
  1488. if ($orderModel->charge_type == 1)
  1489. {
  1490. $totalpriceInfo = '
  1491. <tr>
  1492. <td><strong>总金额:</strong></td>
  1493. <td><span class="price">¥' . $totalPrice . '</span>(未付款)</td>
  1494. </tr>';
  1495. }
  1496. else
  1497. {
  1498. $totalpriceInfo = '
  1499. <tr>
  1500. <td><strong>总金额:</strong></td>
  1501. <td><span class="price">¥' . $totalPrice . '</span>(已付款)</td>
  1502. </tr>';
  1503. }
  1504. $Content = $Content . $memberdeleteInfo . $promotioninfo . $discountInfo . $delivery_fee_info . $addservicestring . $couponInfo . $totalpriceInfo .
  1505. '</table>' . '<p style="font-size: 22px; color:red; font-weight: bold;">该笔订单已经被顾客取消,请不要进行配送,如有疑问请电话联系顾客!</p>' .
  1506. '</body>
  1507. </html>
  1508. ';
  1509. SendEmail($receiveEmail, $receiveName, $Subject, $Content);
  1510. }
  1511. private function SendPointPrizeOrderEmail()
  1512. {
  1513. //判断是否发邮件
  1514. $emailvalid = $this->pointsetModel->is_emaill;
  1515. if (!$emailvalid)
  1516. {
  1517. return ;
  1518. }
  1519. $email_address = $this->pointsetModel->email;
  1520. $adminId = $this->orderModel->admin_id;
  1521. $orderModel = $this->orderModel;
  1522. $name = $this->orderModel->name;
  1523. $phone = $this->orderModel->phone;
  1524. $address = $this->orderModel->address;
  1525. $note = $this->orderModel->memo;
  1526. $receiveEmail = $email_address;
  1527. $receiveName = '';
  1528. $DefaultOrderString = '
  1529. <tr>
  1530. <td><strong>兑奖详情:</strong></td>
  1531. <td></td>
  1532. </tr>';
  1533. $orderItemModels = LewaimaiPointprizeOrderItem::model()->findAll("lewaimai_order_id = " . $orderModel->id);
  1534. if (!$orderItemModels)
  1535. {
  1536. $OrderString = $DefaultOrderString;
  1537. }
  1538. elseif (count($orderItemModels) == 1)
  1539. {
  1540. $orderItemModel = $orderItemModels[0];
  1541. $OrderString = '
  1542. <tr>
  1543. <td><strong>订单详情:</strong></td>
  1544. <td>' . $orderItemModel->prize_name . " " . $orderItemModel->quantity . "份" . '</td>
  1545. </tr>';
  1546. }
  1547. else
  1548. {
  1549. $orderItemModel = $orderItemModels[0];
  1550. $OrderString = '
  1551. <tr>
  1552. <td><strong>订单详情:</strong></td>
  1553. <td>' . $orderItemModel->prize_name . " " . $orderItemModel->quantity . "份" . '</td>
  1554. </tr>';
  1555. for ($i = 1; $i < count($orderItemModels); $i++)
  1556. {
  1557. $orderItemModel = $orderItemModels[$i];
  1558. $newOrderString = '
  1559. <tr>
  1560. <td></td>
  1561. <td>' . $orderItemModel->prize_name . " " . $orderItemModel->quantity . "份" . '</td>
  1562. </tr>';
  1563. $OrderString = $OrderString . $newOrderString;
  1564. }
  1565. }
  1566. $Subject = '您有一笔积分兑奖订单,请尽快处理!';
  1567. $Content = '
  1568. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  1569. <html xmlns="http://www.w3.org/1999/xhtml">
  1570. <head>
  1571. <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  1572. <title>无标题文档</title>
  1573. <style type="text/css">
  1574. body,td,th {
  1575. font-size: 18px;
  1576. }
  1577. .price {
  1578. color: #F00;
  1579. }
  1580. </style>
  1581. </head>
  1582. <body>
  1583. <table width="100%" align="center">
  1584. <tr>
  1585. <td colspan="2" align="center"><h1><strong>积分兑奖信息</strong></h1>
  1586. <hr /></td>
  1587. </tr>
  1588. <tr>
  1589. <td width="100"><strong>姓名:</strong></td>
  1590. <td>' . $name . '</td>
  1591. </tr>
  1592. <tr>
  1593. <td><strong>电话:</strong></td>
  1594. <td>' . $phone . '</td>
  1595. </tr>
  1596. <tr>
  1597. <td valign="top"><strong>地址:</strong></td>
  1598. <td>' . $address . '</td>
  1599. </tr>' .
  1600. '<tr>
  1601. <td><strong>下单时间:</strong></td>
  1602. <td>' . date("Y-m-d H:i:s") . '</td>
  1603. </tr>
  1604. ' . $OrderString . '
  1605. <tr>
  1606. <td valign="top"><strong>备注:</strong></td>
  1607. <td>' . $note . '</td>
  1608. </tr>
  1609. ';
  1610. $Content = $Content .
  1611. '</table>
  1612. </body>
  1613. </html>
  1614. ';
  1615. SendEmail($receiveEmail, $receiveName, $Subject, $Content);
  1616. }
  1617. private function PrintCancelOrder()
  1618. {
  1619. $shopprinterModels = ShopPrinter::model()->findAll("shop_id = " . $this->shopModel->id);
  1620. foreach ($shopprinterModels as $shopprinterModel)
  1621. {
  1622. $printer_id = $shopprinterModel->printer_id;
  1623. $printerModel = Printer::model()->findByPk($printer_id);
  1624. if (!$printerModel)
  1625. {
  1626. continue;
  1627. }
  1628. $printer_type = $printerModel->printer_type;
  1629. $lewaimai_sn = $printerModel->lewaimai_sn;
  1630. $member_code = $printerModel->member_code;
  1631. $feyin_key = $printerModel->feyin_key;
  1632. $device_no = $printerModel->device_no;
  1633. $shopcode = $printerModel->shopcode;
  1634. $printer_num = $printerModel->printer_num;
  1635. $printer_info = $printerModel->printer_info;
  1636. $is_cut = $printerModel->is_cut;
  1637. $big_ordernum = $printerModel->big_ordernum;
  1638. $big_name = $printerModel->big_name;
  1639. $big_phone = $printerModel->big_phone;
  1640. $big_address = $printerModel->big_address;
  1641. $big_content = $printerModel->big_content;
  1642. $big_price = $printerModel->big_price;
  1643. if ($printer_type == 1)
  1644. {
  1645. $content = $this->GetPrinterCancelOrderContent(2, $printer_info, $is_cut);
  1646. $this->SendFeyinPrinterMessage($member_code, $device_no, $feyin_key, $content);
  1647. }
  1648. elseif ($printer_type == 2)
  1649. {
  1650. $content = $this->GetPrinterCancelOrderContent(3, $printer_info, $is_cut);
  1651. $this->SendKeLaiLePrinterMessage($shopcode, $content);
  1652. }
  1653. elseif ($printer_type == 3)
  1654. {
  1655. $content = $this->GetPrinterCancelOrderContent(1, $printer_info, $is_cut);
  1656. $this->SendLewaimaiPrinterMessage(1, $lewaimai_sn, $printer_num, $content);
  1657. }
  1658. }
  1659. }
  1660. private function PrintPointPrizeOrder()
  1661. {
  1662. $printerModel = Printer::model()->findByPk($this->pointsetModel->printer_id);
  1663. if (!$printerModel)
  1664. {
  1665. Yii::log("no this printer! PrintPointPrizeOrder failed!");
  1666. return ;
  1667. }
  1668. $printer_type = $printerModel->printer_type;
  1669. $lewaimai_sn = $printerModel->lewaimai_sn;
  1670. $member_code = $printerModel->member_code;
  1671. $feyin_key = $printerModel->feyin_key;
  1672. $device_no = $printerModel->device_no;
  1673. $shopcode = $printerModel->shopcode;
  1674. $printer_num = $printerModel->printer_num;
  1675. $printer_info = $printerModel->printer_info;
  1676. $is_cut = $printerModel->is_cut;
  1677. $big_ordernum = $printerModel->big_ordernum;
  1678. $big_name = $printerModel->big_name;
  1679. $big_phone = $printerModel->big_phone;
  1680. $big_address = $printerModel->big_address;
  1681. $big_content = $printerModel->big_content;
  1682. $big_price = $printerModel->big_price;
  1683. if ($printer_type == 1)
  1684. {
  1685. $content = $this->GetPrinterPointPrizeOrderContent(2, $is_cut);
  1686. $this->SendFeyinPrinterMessage($member_code, $device_no, $feyin_key, $content);
  1687. }
  1688. elseif ($printer_type == 2)
  1689. {
  1690. $content = $this->GetPrinterPointPrizeOrderContent(3, $is_cut);
  1691. $this->SendKeLaiLePrinterMessage($shopcode, $content);
  1692. }
  1693. elseif ($printer_type == 3)
  1694. {
  1695. $content = $this->GetPrinterPointPrizeOrderContent(1, $is_cut);
  1696. $this->SendLewaimaiPrinterMessage(1, $lewaimai_sn, $printer_num, $content);
  1697. }
  1698. }
  1699. private function SendLewaimaiPrinterMessage($orderid, $lewaimai_sn, $printer_num, $content)
  1700. {
  1701. $dingdanID = $orderid; //订单号
  1702. $dayinjisn = $lewaimai_sn; //打印机ID号
  1703. $pages = $printer_num; //联数
  1704. $dingdan = $content; //订单内容
  1705. $replyURL = "http://www.lewaimai.com/lewaimaiprinter/orderstatus";//回复确认URL
  1706. if($pages <= 0 || $pages > 4)
  1707. {
  1708. Yii::log("乐外卖打印机打印联数不能大于4!");
  1709. return false;
  1710. }
  1711. if(empty($dingdanID)||empty($dayinjisn)||empty($pages)||empty($dingdan)||empty($replyURL))
  1712. {
  1713. return false;
  1714. }
  1715. $url = 'http://lewaimaiprinter.lewaimai.com:60002';//POST指向的API链接
  1716. // 提交API的内容
  1717. $data = array(
  1718. 'dingdanID'=>'dingdanID='.$dingdanID, //订单号
  1719. 'dayinjisn'=>'dayinjisn='.$dayinjisn, //打印机ID号
  1720. 'dingdan'=>'dingdan='.$dingdan, //订单内容
  1721. 'pages'=>'pages='.$pages, //联数
  1722. 'replyURL'=>'replyURL='.$replyURL); //回复确认URL
  1723. $post_data = implode('&',$data);
  1724. LewaimaiHttp::POST_ASYNC($url, array(), array(CURLOPT_POSTFIELDS=>$post_data));
  1725. return true;
  1726. }
  1727. private function SendFeyinPrinterMessage($MEMBER_CODE, $DEVICE_NO, $FEYIN_KEY, $Content)
  1728. {
  1729. $msgNo = microtime() . LewaimaiString::create_noncestr(16);
  1730. $msg = array(
  1731. 'memberCode' => $MEMBER_CODE,
  1732. 'msgDetail' => $Content,
  1733. 'deviceNo' => $DEVICE_NO,
  1734. 'msgNo' => $msgNo
  1735. );
  1736. $msg['reqTime'] = number_format(1000 * time(), 0, '', '');
  1737. $content = $msg['memberCode'] . $msg['msgDetail'] . $msg['deviceNo'] . $msg['msgNo'] . $msg['reqTime'] . $FEYIN_KEY;
  1738. $msg['securityCode'] = md5($content);
  1739. $msg['mode'] = 2;
  1740. $post_url = "my.feyin.net/api/sendMsg";
  1741. LewaimaiHttp::POST_ASYNC($post_url, $msg);
  1742. return true;
  1743. }
  1744. private function SendKeLaiLePrinterMessage($shopCode, $content, $orderid = '', $total_price = '', $charge_type = '')
  1745. {
  1746. // app params
  1747. $appid = 'wp2a061b92bbd950cc';
  1748. $appSecret = '45b19efd84889e727cc29da91d7ffb15';
  1749. // request params
  1750. $reqParams = array(
  1751. 'appid' => $appid,
  1752. 'timestamp' => time(),
  1753. 'shopCode' => $shopCode,
  1754. 'content' => $content,
  1755. 'orderCode' => $orderid,
  1756. 'price' => $total_price,
  1757. 'charge_type' => $charge_type,
  1758. );
  1759. // generate sign;
  1760. $params = array();
  1761. foreach ($reqParams as $key=>$val)
  1762. $params[$key]=$val;
  1763. ksort($params); //SORT_STRING | SORT_FLAG_CASE);
  1764. $arr = array();
  1765. foreach ($params as $key => $val)
  1766. $arr[] = "$key=$val";
  1767. $reqParams['sign'] = sha1(implode('&', $arr).$appSecret);
  1768. $jsonString = CJSON::encode($reqParams);
  1769. $post_url = 'http://p.kelaile.cn/api/service/print';
  1770. LewaimaiHttp::POST_ASYNC($post_url, array(), array(CURLOPT_POSTFIELDS=>$jsonString));
  1771. return true;
  1772. }
  1773. //printer_type 1:乐外卖打印机 2:飞印打印机 3:客来乐打印机
  1774. 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)
  1775. {
  1776. $admin_id = $this->orderModel->admin_id;
  1777. $shop_id = $this->orderModel->shop_id;
  1778. $delivery_fee = $this->orderModel->delivery_fee;
  1779. $total_price = $this->orderModel->total_price;
  1780. $total_point = $this->orderModel->total_point;
  1781. $nickname = $this->orderModel->nickname;
  1782. $phone = $this->orderModel->phone;
  1783. $address = $this->orderModel->address;
  1784. $memo = $this->orderModel->memo;
  1785. $init_date = $this->orderModel->init_date;
  1786. //计算是第几次下单
  1787. if($this->shopModel->showordernum_type == 0)
  1788. {
  1789. $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')");
  1790. }
  1791. else
  1792. {
  1793. $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')");
  1794. }
  1795. if (!$this->orderCount)
  1796. {
  1797. $this->orderCount = $orderCount;
  1798. }
  1799. //判断该顾客是不是店铺的会员
  1800. $memberModel = LewaimaiMember::model()->find("lewaimai_customer_id = " . $this->orderModel->lewaimai_customer_id . " AND admin_id = " . $this->orderModel->admin_id);
  1801. if($this->shopModel->showordernum == 1)
  1802. {
  1803. if ($memberModel)
  1804. {
  1805. $nickname .= "(会员,第" . $orderCount . "次下单)";
  1806. }
  1807. else
  1808. {
  1809. $nickname .= "(第" . $orderCount . "次下单)";
  1810. }
  1811. }
  1812. //求预设选项
  1813. $order_field = unserialize($this->orderModel->order_field);
  1814. $fieldString = "";
  1815. foreach($order_field as $key => $val)
  1816. {
  1817. $fieldString .= $val["name"] . ":" . $val["content"] . "\r\n";
  1818. }
  1819. //支付方式
  1820. $charge_type = $this->orderModel->charge_type;
  1821. if ($charge_type == 1)
  1822. {
  1823. $chargeString = "货到付款";
  1824. }
  1825. elseif ($charge_type == 2)
  1826. {
  1827. $chargeString = "余额支付(已付款)";
  1828. }
  1829. elseif ($charge_type == 3)
  1830. {
  1831. $chargeString = "在线支付(已付款)";
  1832. }
  1833. $is_discount = $this->orderModel->is_discount;
  1834. $discount_value = $this->orderModel->discount_value;
  1835. $is_coupon = $this->orderModel->is_coupon;
  1836. $coupon_value = $this->orderModel->coupon_value;
  1837. $is_member_delete = $this->orderModel->is_member_delete;
  1838. $member_delete = $this->orderModel->member_delete;
  1839. if ($is_member_delete)
  1840. {
  1841. $memberdeleteString = "会员优惠:" . $member_delete . "元";
  1842. $memberdeleteString = RightString($memberdeleteString) . "\r\n";
  1843. }
  1844. else
  1845. {
  1846. $memberdeleteString = '';
  1847. }
  1848. if($this->orderModel->promotion)
  1849. {
  1850. $promotion = explode(':',$this->orderModel->promotion);
  1851. $promotioninfo = '满'.$promotion[0].'元,减'.$promotion[1].'元';
  1852. $promotioninfo = RightString($promotioninfo) . "\r\n";
  1853. }
  1854. else
  1855. {
  1856. $promotioninfo = '';
  1857. }
  1858. if ($is_discount)
  1859. {
  1860. $discountString = "店铺折扣:" . $discount_value . "折";
  1861. $discountString = RightString($discountString) . "\r\n";
  1862. }
  1863. else
  1864. {
  1865. $discountString = "";
  1866. }
  1867. if ($is_coupon)
  1868. {
  1869. $couponString = "优惠券:" . $coupon_value . "元";
  1870. $couponString = RightString($couponString) . "\r\n";
  1871. }
  1872. else
  1873. {
  1874. $couponString = "";
  1875. }
  1876. $shopname = $this->shopModel->shopname;
  1877. $orderphone = $this->shopModel->orderphone;
  1878. // 读取订单详情
  1879. $orderItemModels = LewaimaiOrderItem::model()->findAll("lewaimai_order_id = " . $this->orderid);
  1880. $totalNum = 0;
  1881. $order_item_string = "";
  1882. foreach ($orderItemModels as $orderItemModel)
  1883. {
  1884. $food_name = $orderItemModel->food_name;
  1885. $price = $orderItemModel->price;
  1886. $price = sprintf("%.1f", $price);
  1887. $quantity = $orderItemModel->quantity;
  1888. $item_total_price = $orderItemModel->price * $orderItemModel->quantity;
  1889. $item_total_price = sprintf("%.1f", $item_total_price);
  1890. $showFoodName = HandleFoodName($food_name);
  1891. $showPrice = HandleNum($price);
  1892. $showQuantity = HandleNum($quantity);
  1893. $showItemTotalPrice = HandleNum($item_total_price);
  1894. $item_string = $showFoodName . $showPrice . " " . $showQuantity . " " . $showItemTotalPrice;
  1895. $order_item_string = $order_item_string . $item_string . "\r\n";
  1896. $totalNum += $quantity;
  1897. }
  1898. if ($big_content)
  1899. {
  1900. if ($printer_type == 1)
  1901. {
  1902. $order_item_string = GetHalfWidthBigStringLewaimai($order_item_string);
  1903. }
  1904. elseif ($printer_type == 2)
  1905. {
  1906. $order_item_string = GetHalfWidthBigStringFeyin($order_item_string);
  1907. }
  1908. }
  1909. //处理配送费
  1910. if ($delivery_fee != 0)
  1911. {
  1912. $delivery_fee = sprintf("%.1f", $delivery_fee);
  1913. $showFoodName = HandleFoodName("外送费");
  1914. $showPrice = HandleNum("");
  1915. $showQuantity = HandleNum("");
  1916. $showItemTotalPrice = HandleNum($delivery_fee);
  1917. $delivery_fee_string = $showFoodName . $showPrice . " " . $showQuantity . " " . $showItemTotalPrice;
  1918. $order_item_string = $order_item_string . $delivery_fee_string . "\r\n";
  1919. }
  1920. if ($this->adminModel->order_num_type == 0)
  1921. {
  1922. $orderNo = $this->orderModel->admin_num;
  1923. }
  1924. else
  1925. {
  1926. $orderNo = $this->shopModel->order_prefix . $this->orderModel->shop_num;
  1927. }
  1928. $delivertime = $this->orderModel->delivertime;
  1929. $delivertimeinfo = '';
  1930. if($delivertime)
  1931. {
  1932. $delivertimeinfo = '配送时间: '.$this->orderModel->delivery_date.' '.$delivertime . "\r\n";
  1933. }
  1934. //开始计算returnString
  1935. if ($printer_type == 1)
  1936. {
  1937. $returnString = CenterTitleLeWaiMai($shopname) . "\r\n" . "\r\n";
  1938. }
  1939. elseif ($printer_type == 2)
  1940. {
  1941. $returnString = CenterTitleFeyin($shopname) . "\r\n" . "\r\n";
  1942. }
  1943. elseif ($printer_type == 3)
  1944. {
  1945. $returnString = CenterString($shopname) . "\r\n" . "\r\n";
  1946. }
  1947. if ($big_ordernum)
  1948. {
  1949. if ($printer_type == 1)
  1950. {
  1951. $ordernumString = GetHalfWidthBigStringLewaimai('订单编号:' . $orderNo) . "\r\n" ;
  1952. }
  1953. elseif ($printer_type == 2)
  1954. {
  1955. $ordernumString = GetHalfWidthBigStringFeyin('订单编号:' . $orderNo) . "\r\n" ;
  1956. }
  1957. }
  1958. else
  1959. {
  1960. $ordernumString = '订单编号:' . $orderNo . "\r\n" ;
  1961. }
  1962. $mergeModel = LewaimaiMergeOrderSet::model()->find('admin_id='.$this->orderModel->admin_id.' and shop_id='.$this->orderModel->shop_id);
  1963. $mergeString = '';
  1964. if($mergeModel and $mergeModel->is_open==1)
  1965. {
  1966. if($this->orderModel->mergeorder_id > 0)
  1967. {
  1968. $mergeString = "是否是拼单:是\r\n";
  1969. $mergeorderModel = LewaimaiMergeOrder::model() -> findByPk($this->orderModel->mergeorder_id);
  1970. $mergeString .= "拼单名字:".$mergeorderModel->name."\r\n";
  1971. $mergeString .= "拼单人数:".$mergeorderModel->nownum."\r\n";
  1972. $mergeString .= "拼单折扣:".$this->orderModel->mergeorder_discount."\r\n";
  1973. }
  1974. else
  1975. {
  1976. $mergeString = "是否是拼单:不是\r\n";
  1977. }
  1978. }
  1979. if($this->shopModel->open_selftake)
  1980. {
  1981. if($this->orderModel->is_selftake)
  1982. {
  1983. $quhuofangshi = "取货方式:到店自取\r\n";
  1984. }
  1985. else
  1986. {
  1987. $quhuofangshi = "取货方式:店家配送\r\n";
  1988. }
  1989. }
  1990. else
  1991. {
  1992. $quhuofangshi = '';
  1993. }
  1994. $returnString .= $ordernumString . $mergeString . $quhuofangshi;
  1995. if ($big_name)
  1996. {
  1997. if ($printer_type == 1)
  1998. {
  1999. $nameString = GetHalfWidthBigStringLewaimai('姓名:' . $nickname) . "\r\n" ;
  2000. }
  2001. elseif ($printer_type == 2)
  2002. {
  2003. $nameString = GetHalfWidthBigStringFeyin('姓名:' . $nickname) . "\r\n" ;
  2004. }
  2005. }
  2006. else
  2007. {
  2008. $nameString = '姓名:' . $nickname . "\r\n";
  2009. }
  2010. if ($big_phone)
  2011. {
  2012. if ($printer_type == 1)
  2013. {
  2014. $phoneString = GetHalfWidthBigStringLewaimai('电话:' . $phone) . "\r\n";
  2015. }
  2016. elseif ($printer_type == 2)
  2017. {
  2018. $phoneString = GetHalfWidthBigStringFeyin('电话:' . $phone) . "\r\n";
  2019. }
  2020. }
  2021. else
  2022. {
  2023. $phoneString = '电话:' . $phone . "\r\n";
  2024. }
  2025. if ($big_address)
  2026. {
  2027. if ($printer_type == 1)
  2028. {
  2029. $addressString = GetHalfWidthBigStringLewaimai('地址:' . $address) . "\r\n";
  2030. }
  2031. elseif ($printer_type == 2)
  2032. {
  2033. $addressString = GetHalfWidthBigStringFeyin('地址:' . $address) . "\r\n";
  2034. }
  2035. }
  2036. else
  2037. {
  2038. $addressString = '地址:' . $address . "\r\n";
  2039. }
  2040. $returnString .= $nameString . $phoneString . $addressString;
  2041. $addserviceString = "";
  2042. $addservice = unserialize($this->orderModel->addservice);
  2043. if(is_array($addservice))
  2044. {
  2045. foreach($addservice as $addservicekey => $addserviceval)
  2046. {
  2047. $addserviceString .= RightString($addservicekey.':'.$addserviceval."元"). "\r\n";
  2048. }
  2049. }
  2050. $returnString .= $fieldString .
  2051. $delivertimeinfo .
  2052. '下单时间:' . $init_date . "\r\n" .
  2053. '--------------------------------' . "\r\n" .
  2054. '商品 单价 数量 金额 ' . "\r\n" .
  2055. $order_item_string .
  2056. "\r\n" .
  2057. '备注:' . $memo . "\r\n" .
  2058. '--------------------------------' . "\r\n" .
  2059. $memberdeleteString .
  2060. $promotioninfo .
  2061. $discountString .
  2062. $couponString .
  2063. $addserviceString;
  2064. if ($big_price)
  2065. {
  2066. if ($printer_type == 1)
  2067. {
  2068. $priceString = GetHalfWidthBigStringLewaimai(RightString("共" . $totalNum . "份,合计:" . $total_price . "元"));
  2069. }
  2070. elseif ($printer_type == 2)
  2071. {
  2072. $priceString = GetHalfWidthBigStringFeyin(RightString("共" . $totalNum . "份,合计:" . $total_price . "元"));
  2073. }
  2074. }
  2075. else
  2076. {
  2077. $priceString = RightString("共" . $totalNum . "份,合计:" . $total_price . "元");
  2078. }
  2079. $returnString .= $priceString . "\r\n" .
  2080. RightString($chargeString) . "\r\n" .
  2081. "\r\n" .
  2082. CenterString($printer_info);
  2083. $content = "";
  2084. if ($printer_type == 1)
  2085. {
  2086. if ($is_cut)
  2087. {
  2088. $content = "<1B40><1B40><1B40>" . $returnString . "<0D0A><0D0A><0D0A><0D0A><0D0A><0D0A>" . "<1D5642000A0A>";
  2089. }
  2090. else
  2091. {
  2092. $content = "<1B40><1B40><1B40>" . $returnString . "<0D0A><0D0A><0D0A><0D0A><0D0A><0D0A><0D0A><0D0A>";
  2093. }
  2094. }
  2095. elseif ($printer_type == 2 || $printer_type == 3)
  2096. {
  2097. for ($i = 0; $i < $printer_num; $i++)
  2098. {
  2099. $content = $content . $returnString;
  2100. if ($i != $printer_num - 1)
  2101. {
  2102. $content = $content . "\r\n\r\n\r\n";
  2103. }
  2104. }
  2105. }
  2106. return $content;
  2107. }
  2108. //printer_type 1:乐外卖打印机 2:飞印打印机 3:客来乐打印机
  2109. private function GetPrinterCancelOrderContent($printer_type, $printer_info, $is_cut = 0)
  2110. {
  2111. $admin_id = $this->orderModel->admin_id;
  2112. $shop_id = $this->orderModel->shop_id;
  2113. $delivery_fee = $this->orderModel->delivery_fee;
  2114. $total_price = $this->orderModel->total_price;
  2115. $total_point = $this->orderModel->total_point;
  2116. $nickname = $this->orderModel->nickname;
  2117. $phone = $this->orderModel->phone;
  2118. $address = $this->orderModel->address;
  2119. $memo = $this->orderModel->memo;
  2120. $init_date = $this->orderModel->init_date;
  2121. $mergeModel = LewaimaiMergeOrderSet::model()->find('admin_id='.$this->orderModel->admin_id.' and shop_id='.$this->orderModel->shop_id);
  2122. $mergeString = '';
  2123. if($mergeModel and $mergeModel->is_open==1)
  2124. {
  2125. if($this->orderModel->mergeorder_id > 0)
  2126. {
  2127. $mergeString = "是否是拼单:是\r\n";
  2128. $mergeorderModel = LewaimaiMergeOrder::model() -> findByPk($this->orderModel->mergeorder_id);
  2129. $mergeString .= "拼单名字:".$mergeorderModel->name."\r\n";
  2130. $mergeString .= "拼单人数:".$mergeorderModel->nownum."\r\n";
  2131. $mergeString .= "拼单折扣:".$this->orderModel->mergeorder_discount."\r\n";
  2132. }
  2133. else
  2134. {
  2135. $mergeString = "是否是拼单:不是\r\n";
  2136. }
  2137. }
  2138. //求预设选项
  2139. $order_field = unserialize($this->orderModel->order_field);
  2140. $fieldString = "";
  2141. foreach($order_field as $key => $val)
  2142. {
  2143. $fieldString .= $val["name"] . ":" . $val["content"] . "\r\n";
  2144. }
  2145. //支付方式
  2146. $charge_type = $this->orderModel->charge_type;
  2147. if ($charge_type == 1)
  2148. {
  2149. $chargeString = "货到付款";
  2150. }
  2151. elseif ($charge_type == 2)
  2152. {
  2153. $chargeString = "余额支付(已付款)";
  2154. }
  2155. elseif ($charge_type == 3)
  2156. {
  2157. $chargeString = "在线支付(已付款)";
  2158. }
  2159. $is_discount = $this->orderModel->is_discount;
  2160. $discount_value = $this->orderModel->discount_value;
  2161. $is_coupon = $this->orderModel->is_coupon;
  2162. $coupon_value = $this->orderModel->coupon_value;
  2163. if ($is_discount)
  2164. {
  2165. $discountString = "会员折扣:" . $discount_value . "折";
  2166. $discountString = RightString($discountString) . "\r\n";
  2167. }
  2168. else
  2169. {
  2170. $discountString = "";
  2171. }
  2172. if ($is_coupon)
  2173. {
  2174. $couponString = "优惠券:" . $coupon_value . "元";
  2175. $couponString = RightString($couponString) . "\r\n";
  2176. }
  2177. else
  2178. {
  2179. $couponString = "";
  2180. }
  2181. // 读取店铺名
  2182. $shopname = $this->shopModel->shopname;
  2183. $orderphone = $this->shopModel->orderphone;
  2184. // 读取订单详情
  2185. $orderItemModels = LewaimaiOrderItem::model()->findAll("lewaimai_order_id = " . $this->orderid);
  2186. $order_item_string = "";
  2187. foreach ($orderItemModels as $orderItemModel)
  2188. {
  2189. $food_name = $orderItemModel->food_name;
  2190. $price = $orderItemModel->price;
  2191. $price = sprintf("%.1f", $price);
  2192. $quantity = $orderItemModel->quantity;
  2193. $item_total_price = $orderItemModel->price * $orderItemModel->quantity;
  2194. $item_total_price = sprintf("%.1f", $item_total_price);
  2195. $showFoodName = HandleFoodName($food_name);
  2196. $showPrice = HandleNum($price);
  2197. $showQuantity = HandleNum($quantity);
  2198. $showItemTotalPrice = HandleNum($item_total_price);
  2199. $item_string = $showFoodName . $showPrice . " " . $showQuantity . " " . $showItemTotalPrice;
  2200. $order_item_string = $order_item_string . $item_string . "\r\n";
  2201. }
  2202. //处理配送费
  2203. if ($delivery_fee != 0)
  2204. {
  2205. $delivery_fee = sprintf("%.1f", $delivery_fee);
  2206. $showFoodName = HandleFoodName("外送费");
  2207. $showPrice = HandleNum("");
  2208. $showQuantity = HandleNum("");
  2209. $showItemTotalPrice = HandleNum($delivery_fee);
  2210. $delivery_fee_string = $showFoodName . $showPrice . " " . $showQuantity . " " . $showItemTotalPrice;
  2211. $order_item_string = $order_item_string . $delivery_fee_string . "\r\n";
  2212. }
  2213. if ($this->adminModel->order_num_type == 0)
  2214. {
  2215. $orderNo = $this->orderModel->admin_num;
  2216. }
  2217. else
  2218. {
  2219. $orderNo = $this->shopModel->order_prefix . $this->orderModel->shop_num;
  2220. }
  2221. $delivertime = $this->orderModel->delivertime;
  2222. $delivertimeinfo = '';
  2223. if($delivertime)
  2224. {
  2225. $delivertimeinfo = '配送时间: '.$this->orderModel->delivery_date.' '.$delivertime . "\r\n";
  2226. }
  2227. if ($printer_type == 1)
  2228. {
  2229. $returnString = CenterTitleLeWaiMai("订单取消通知") . "\r\n" . "\r\n";
  2230. }
  2231. elseif ($printer_type == 2)
  2232. {
  2233. $returnString = CenterTitleFeyin("订单取消通知") . "\r\n" . "\r\n";
  2234. }
  2235. else
  2236. {
  2237. $returnString = CenterString("订单取消通知") . "\r\n" . "\r\n";
  2238. }
  2239. $returnString .= '店铺:' . $shopname . "\r\n" .
  2240. '订单编号:' . $orderNo . "\r\n" .$mergeString;
  2241. if($this->shopModel->open_selftake)
  2242. {
  2243. if($this->orderModel->is_selftake)
  2244. {
  2245. $quhuofangshi = "取货方式:到店自取\r\n";
  2246. }
  2247. else
  2248. {
  2249. $quhuofangshi = "取货方式:店家配送\r\n";
  2250. }
  2251. }
  2252. else
  2253. {
  2254. $quhuofangshi = '';
  2255. }
  2256. $returnString .= $quhuofangshi;
  2257. $returnString .= '姓名:' . $nickname . "\r\n" .
  2258. '电话:' . $phone . "\r\n" .
  2259. '地址:' . $address . "\r\n" ;
  2260. $returnString .= $fieldString .
  2261. $delivertimeinfo .
  2262. '下单时间:' . $init_date . "\r\n" .
  2263. '--------------------------------' . "\r\n" .
  2264. '商品 单价 数量 金额 ' . "\r\n" .
  2265. $order_item_string .
  2266. "\r\n" .
  2267. '备注:' . $memo . "\r\n" .
  2268. '--------------------------------' . "\r\n" .
  2269. $discountString .
  2270. $couponString .
  2271. RightString("合计:" . $total_price . "元") . "\r\n" .
  2272. RightString($chargeString) . "\r\n" .
  2273. "\r\n" .
  2274. CenterString($printer_info) . "\r\n";
  2275. if ($printer_type == 1)
  2276. {
  2277. if ($is_cut)
  2278. {
  2279. $content = "<1B40><1B40><1B40>" . $returnString . "<0D0A><0D0A><0D0A><0D0A><0D0A><0D0A>" . "<1D5642000A0A>";
  2280. }
  2281. else
  2282. {
  2283. $content = "<1B40><1B40><1B40>" . $returnString . "<0D0A><0D0A><0D0A><0D0A><0D0A><0D0A><0D0A><0D0A>";
  2284. }
  2285. }
  2286. elseif ($printer_type == 2 || $printer_type == 3)
  2287. {
  2288. $content = $returnString;
  2289. }
  2290. return $content;
  2291. }
  2292. //printer_type 1:乐外卖打印机 2:飞印打印机 3:客来乐打印机
  2293. private function GetPrinterPointPrizeOrderContent($printer_type, $is_cut = 0)
  2294. {
  2295. $orderModel = $this->orderModel;
  2296. $admin_id = $orderModel->admin_id;
  2297. $total_point = $orderModel->total_point;
  2298. $name = $orderModel->name;
  2299. $phone = $orderModel->phone;
  2300. $address = $orderModel->address;
  2301. $memo = $orderModel->memo;
  2302. $init_time = $orderModel->init_time;
  2303. // 读取订单详情
  2304. $orderItemModels = LewaimaiPointprizeOrderItem::model()->findAll("lewaimai_order_id = " . $this->orderid);
  2305. $order_item_string = "";
  2306. foreach ($orderItemModels as $orderItemModel)
  2307. {
  2308. $prize_name = $orderItemModel->prize_name;
  2309. $quantity = $orderItemModel->quantity;
  2310. $item_string = $prize_name . " " . $quantity . " 份\r\n";
  2311. $order_item_string = $order_item_string . $item_string;
  2312. }
  2313. if ($printer_type == 1)
  2314. {
  2315. $returnString = CenterTitleLeWaiMai("积分兑奖通知") . "\r\n" . "\r\n";
  2316. }
  2317. elseif ($printer_type == 2)
  2318. {
  2319. $returnString = CenterTitleFeyin("积分兑奖通知") . "\r\n" . "\r\n";
  2320. }
  2321. else
  2322. {
  2323. $returnString = CenterString("积分兑奖通知") . "\r\n" . "\r\n";
  2324. }
  2325. $returnString .= '姓名:' . $name . "\r\n" .
  2326. '电话:' . $phone . "\r\n" .
  2327. '地址:' . $address . "\r\n" ;
  2328. $returnString .= '兑奖时间:' . $init_time . "\r\n" .
  2329. '--------------------------------' . "\r\n" .
  2330. $order_item_string .
  2331. '--------------------------------' . "\r\n" .
  2332. '备注:' . $memo . "\r\n";
  2333. if ($printer_type == 1)
  2334. {
  2335. if ($is_cut)
  2336. {
  2337. $content = "<1B40><1B40><1B40>" . $returnString . "<0D0A><0D0A><0D0A><0D0A><0D0A><0D0A>" . "<1D5642000A0A>";
  2338. }
  2339. else
  2340. {
  2341. $content = "<1B40><1B40><1B40>" . $returnString . "<0D0A><0D0A><0D0A><0D0A><0D0A><0D0A><0D0A><0D0A>";
  2342. }
  2343. }
  2344. elseif ($printer_type == 2 || $printer_type == 3)
  2345. {
  2346. $content = $returnString;
  2347. }
  2348. return $content;
  2349. }
  2350. }