LewaimaiNotify.php 73 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709
  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. }