SendNewOrderNotify($orderid, $orderModel, $adminModel, $shopModel); } public static function OrderPrintOnly($orderid, $orderModel = NULL, $adminModel = NULL, $shopModel = NULL) { $lewaimainotify = new LewaimaiNotify(); $lewaimainotify->PrinteOrderOnly($orderid, $orderModel, $adminModel, $shopModel); } //取消订单通知 public static function CancelOrderNotify($orderid, $orderModel = NULL, $adminModel = NULL, $shopModel = NULL) { $lewaimainotify = new LewaimaiNotify(); $lewaimainotify->SendCancelOrderNotify($orderid, $orderModel, $adminModel, $shopModel); } //积分兑换奖品通知 public static function PointPrizeOrderNotify($orderid) { $lewaimainotify = new LewaimaiNotify(); $lewaimainotify->SendPointPrizeOrderNotify($orderid); } //自由打印内容 public static function ShopContentPrint($shop_id, $content) { $lewaimainotify = new LewaimaiNotify(); $lewaimainotify->PrintShopContent($shop_id, $content); } public function SendNewOrderNotify($orderid, $orderModel = NULL, $adminModel = NULL, $shopModel = NULL) { $this->orderid = $orderid; if ($orderModel) { $this->orderModel = $orderModel; } else { $this->orderModel = LewaimaiOrder::model()->findByPk($orderid); if (!$this->orderModel) { Yii::log("not this order! SendOrderNotify failed!"); return ; } } if ($adminModel) { $this->adminModel = $adminModel; } else { $this->adminModel = Admin::model()->findByPk($this->orderModel->admin_id); if (!$this->adminModel) { Yii::log("not found the admin_id! SendOrderNotify failed!"); return ; } } if ($shopModel) { $this->shopModel = $shopModel; } else { $shop_id = $this->orderModel->shop_id; $this->shopModel = Config::model()->findByPk($shop_id); if (!$this->shopModel) { Yii::log("not found the shop! SendOrderNotify failed!"); return ; } } //先处理打印机提醒 if($this->adminModel->autoprinter) { $this->PrintNewOrder(); } //再处理短信提醒 $this->SendNewOrderSMS(); //再处理EMAIL提醒 $this->SendNewOrderEmail(); //再处理微信订单提醒的问题 $this->SendNewOrderWeixin(); //发送APP提醒 $url="http://appserver.lewaimai.com/index.php?r=order/push&order_id=" . $orderid; LewaimaiHttp::GET_ASYNC($url); //处理订单被打印机确认后的逻辑 $this->HandOrderConfirmed(); } public function PrinteOrderOnly($orderid, $orderModel = NULL, $adminModel = NULL, $shopModel = NULL) { $this->orderid = $orderid; if ($orderModel) { $this->orderModel = $orderModel; } else { $this->orderModel = LewaimaiOrder::model()->findByPk($orderid); if (!$this->orderModel) { Yii::log("not this order! SendOrderNotify failed!"); return ; } } if ($adminModel) { $this->adminModel = $adminModel; } else { $this->adminModel = Admin::model()->findByPk($this->orderModel->admin_id); if (!$this->adminModel) { Yii::log("not found the admin_id! SendOrderNotify failed!"); return ; } } if ($shopModel) { $this->shopModel = $shopModel; } else { $shop_id = $this->orderModel->shop_id; $this->shopModel = Config::model()->findByPk($shop_id); if (!$this->shopModel) { Yii::log("not found the shop! SendOrderNotify failed!"); return ; } } $this->PrintNewOrder(); } public function SendCancelOrderNotify($orderid, $orderModel = NULL, $adminModel = NULL, $shopModel = NULL) { $this->orderid = $orderid; if ($orderModel) { $this->orderModel = $orderModel; } else { $this->orderModel = LewaimaiOrder::model()->findByPk($orderid); if (!$this->orderModel) { Yii::log("not this order! SendOrderNotify failed!"); return ; } } if ($adminModel) { $this->adminModel = $adminModel; } else { $this->adminModel = Admin::model()->findByPk($this->orderModel->admin_id); if (!$this->adminModel) { Yii::log("not found the admin_id! SendOrderNotify failed!"); return ; } } if ($shopModel) { $this->shopModel = $shopModel; } else { $shop_id = $this->orderModel->shop_id; $this->shopModel = Config::model()->findByPk($shop_id); if (!$this->shopModel) { Yii::log("not found the shop! SendOrderNotify failed!"); return ; } } //处理打印机,对于取消的订单,不管是否开启自动打印,都要打印 $this->PrintCancelOrder(); //再处理短信提醒 $this->SendCancelOrderSMS(); //再处理EMAIL提醒 $this->SendCancelOrderEmail(); //再处理微信订单提醒的问题 $this->SendCancelOrderWeixin(); } public function SendPointPrizeOrderNotify($orderid) { $this->orderid = $orderid; $this->orderModel = LewaimaiPointprizeOrder::model()->findByPk($orderid); if (!$this->orderModel) { Yii::log("not this order! SendPointPrizeOrderNotify failed!"); return ; } $adminId = $this->orderModel->admin_id; $this->pointsetModel = PointSet::model()->findByPk($adminId); if (!$this->pointsetModel) { Yii::log("not pointsetModel! SendPointPrizeOrderNotify failed!"); return ; } if ($this->pointsetModel->is_printer) { //处理打印机 $this->PrintPointPrizeOrder(); } //处理短信提醒 $this->SendPointPrizeOrderSMS(); //处理邮件提醒 $this->SendPointPrizeOrderEmail(); //处理微信提醒 $this->SendPointPrizeOrderWeixin(); } //这个是处理自由打印 public function PrintShopContent($shop_id, $content) { $shopprinterModels = ShopPrinter::model()->findAll("shop_id = " . $shop_id); foreach ($shopprinterModels as $shopprinterModel) { $printer_id = $shopprinterModel->printer_id; $printerModel = Printer::model()->findByPk($printer_id); if (!$printerModel) { continue; } $printer_type = $printerModel->printer_type; $lewaimai_sn = $printerModel->lewaimai_sn; $member_code = $printerModel->member_code; $feyin_key = $printerModel->feyin_key; $device_no = $printerModel->device_no; $shopcode = $printerModel->shopcode; $printer_num = $printerModel->printer_num; $printer_info = $printerModel->printer_info; $is_cut = $printerModel->is_cut; $big_ordernum = $printerModel->big_ordernum; $big_name = $printerModel->big_name; $big_phone = $printerModel->big_phone; $big_address = $printerModel->big_address; $big_content = $printerModel->big_content; $big_price = $printerModel->big_price; if ($printer_type == 1 || $printer_type == 2) { for ($i = 0; $i < $printer_num; $i++) { $content = $content . $returnString; if ($i != $printer_num - 1) { $content = $content . "\r\n\r\n\r\n"; } } } elseif ($printer_type == 3) { if ($is_cut) { $content = "<1B40><1B40><1B40>" . $content . "<0D0A><0D0A><0D0A><0D0A><0D0A><0D0A>" . "<1D5642000A0A>"; } else { $content = "<1B40><1B40><1B40>" . $content . "<0D0A><0D0A><0D0A><0D0A><0D0A><0D0A><0D0A><0D0A>"; } } if ($printer_type == 1) { $this->SendFeyinPrinterMessage($member_code, $device_no, $feyin_key, $content); } elseif ($printer_type == 2) { $this->SendKeLaiLePrinterMessage($shopcode, $content); } elseif ($printer_type == 3) { $this->SendLewaimaiPrinterMessage(1, $lewaimai_sn, $printer_num, $content); } } } private function PrintNewOrder() { $shopprinterModels = ShopPrinter::model()->findAll("shop_id = " . $this->shopModel->id); foreach ($shopprinterModels as $shopprinterModel) { $printer_id = $shopprinterModel->printer_id; $printerModel = Printer::model()->findByPk($printer_id); if (!$printerModel) { continue; } $printer_type = $printerModel->printer_type; $autoconfirmed = $printerModel->autoconfirmed; if($autoconfirmed && ($printer_type == 1 || $printer_type == 2)) { $this->IsPrinterConfirmed = true; } $lewaimai_sn = $printerModel->lewaimai_sn; $member_code = $printerModel->member_code; $feyin_key = $printerModel->feyin_key; $device_no = $printerModel->device_no; $shopcode = $printerModel->shopcode; $printer_num = $printerModel->printer_num; $printer_info = $printerModel->printer_info; $is_cut = $printerModel->is_cut; $big_ordernum = $printerModel->big_ordernum; $big_name = $printerModel->big_name; $big_phone = $printerModel->big_phone; $big_address = $printerModel->big_address; $big_content = $printerModel->big_content; $big_price = $printerModel->big_price; if ($printer_type == 1) { $content = $this->GetPrinterOrderContent(2, $printer_num, $printer_info, $is_cut, $big_ordernum, $big_name, $big_phone, $big_address, $big_content, $big_price); $this->SendFeyinPrinterMessage($member_code, $device_no, $feyin_key, $content); } elseif ($printer_type == 2) { $content = $this->GetPrinterOrderContent(3, $printer_num, $printer_info, $is_cut, $big_ordernum, $big_name, $big_phone, $big_address, $big_content, $big_price); $this->SendKeLaiLePrinterMessage($shopcode, $content, $this->orderid, $this->orderModel->total_price, $this->orderModel->charge_type); } elseif ($printer_type == 3) { $content = $this->GetPrinterOrderContent(1, $printer_num, $printer_info, $is_cut, $big_ordernum, $big_name, $big_phone, $big_address, $big_content, $big_price); $this->SendLewaimaiPrinterMessage($this->orderid, $lewaimai_sn, $printer_num, $content); } } } //处理短信订单提醒 private function SendNewOrderSMS() { $smsvalid = $this->shopModel->smsvalid; if ($smsvalid) { $sms_phone = $this->shopModel->sms_phone; $OrderString = $this->GetNewOrderSMSString(); $OrderStringLen = mb_strlen($OrderString, 'utf8'); $OrderStringLen = $OrderStringLen + 6; //加上【乐外卖】的长度 $StringQuota = ceil($OrderStringLen/67); $sms_quota = $this->adminModel->sms_quota; if ($sms_quota - $StringQuota >= 0) { $smsString = $OrderString . "\n" . '发送"#' . $this->orderid . '"确认此订单。'; if (LewaimaiHttp::SendSMSMessage($sms_phone, $smsString)) { /*更新短信余额*/ $connection = Yii::app()->db; $sql = "UPDATE wx_admin SET sms_quota = sms_quota - {$StringQuota} WHERE id = " . $this->adminModel->id; $command = $connection->createCommand($sql); $command->execute(); /*短信历史记录*/ $phoneMessageHistory = new LewaimaiPhoneMessageHistory(); $phoneMessageHistory->admin_id = $this->orderModel->admin_id; $phoneMessageHistory->lewaimai_customer_id = $this->orderModel->lewaimai_customer_id; $phoneMessageHistory->type = 1; $phoneMessageHistory->phone = $sms_phone; $phoneMessageHistory->content = $OrderString; $phoneMessageHistory->order_id = $this->orderid; $phoneMessageHistory->number = $StringQuota; $phoneMessageHistory->save(); } } } } //获取短信内容提醒 private function GetNewOrderSMSString() { $shopname = $this->shopModel->shopname; $OrderString = "“" . $shopname . "”订单 :\n"; $mergeModel = LewaimaiMergeOrderSet::model()->find('admin_id='.$this->orderModel->admin_id.' and shop_id='.$this->orderModel->shop_id); if ($this->adminModel->order_num_type == 0) { $orderNo = $this->orderModel->admin_num; } else { $orderNo = $this->shopModel->order_prefix . $this->orderModel->shop_num; } if ($this->orderCount) { $orderCount = $this->orderCount; } else { if($this->shopModel->showordernum_type == 0) { //计算是第几次下单 $orderCount = LewaimaiOrder::model()->count("admin_id = " . $this->orderModel->admin_id . " AND lewaimai_customer_id = " . $this->orderModel->lewaimai_customer_id . " AND shop_id = " . $this->orderModel->shop_id ." AND order_status IN ('CONFIRMED','SUCCEEDED','OPEN','CANCELLED','FAILED')"); } else { $orderCount = LewaimaiOrder::model()->count("admin_id = " . $this->orderModel->admin_id . " AND lewaimai_customer_id = " . $this->orderModel->lewaimai_customer_id . " AND order_status IN ('CONFIRMED','SUCCEEDED','OPEN','CANCELLED','FAILED')"); } } //判断该顾客是不是店铺的会员 $memberModel = LewaimaiMember::model()->find("lewaimai_customer_id = " . $this->orderModel->lewaimai_customer_id . " AND admin_id = " . $this->orderModel->admin_id); if($this->shopModel->showordernum == 1) { if ($memberModel) { $OrderString .= "(会员,第" . $orderCount . "次下单)\n"; } else { $OrderString .= "(第" . $orderCount . "次下单)\n"; } } $OrderString .= "订单编号:" . $orderNo . "\n"; if($mergeModel and $mergeModel->is_open == 1) { if($this->orderModel->mergeorder_id > 0) { $OrderString .= "是否是拼单:是\n"; $mergeorderModel = LewaimaiMergeOrder::model() -> findByPk($this->orderModel->mergeorder_id); $OrderString .= "拼单名字:".$mergeorderModel->name."\n"; $OrderString .= "拼单人数:".$mergeorderModel->nownum."\n"; $OrderString .= "拼单折扣:".$this->orderModel->mergeorder_discount."\n"; } else { $OrderString .= "是否是拼单:不是\n"; } } $orderItemModels = LewaimaiOrderItem::model()->findAll("lewaimai_order_id = " . $this->orderid); foreach ($orderItemModels as $orderItem) { $newOrderString = $orderItem->food_name . " " . $orderItem->quantity . "份" . " ¥" . sprintf("%.1f", $orderItem->quantity * $orderItem->price) . "\n"; $OrderString = $OrderString . $newOrderString; } $fieldString = ''; $order_field = unserialize($this->orderModel->order_field); foreach($order_field as $key => $val) { $fieldString .= $val["name"] . ":" . $val["content"] . "\n"; } $delivertime = $this->orderModel->delivertime; $delivertimeinfo = ''; if($delivertime) { $delivertimeinfo = '配送时间: '.$this->orderModel->delivery_date.' '.$delivertime . "\n"; } if($this->shopModel->open_selftake) { if($this->orderModel->is_selftake) { $quhuofangshi = "配送方式:到店自取\n"; } else { $quhuofangshi = "配送方式:店家配送\n"; } } else { $quhuofangshi = ''; } $nameinfo = "姓名:" . $this->orderModel->nickname . "\n"; $phoneinfo = "电话:" . $this->orderModel->phone . "\n"; $addressinfo = "地址:" . $this->orderModel->address . "\n"; if ($this->orderModel->memo && $this->orderModel->memo != "") { $noteinfo = "备注:" . $this->orderModel->memo . "\n"; } else { $noteinfo = ""; } if ($this->orderModel->is_member_delete) { $member_delete_info = "会员优惠:" . $this->orderModel->member_delete . "元" . "\n"; } else { $member_delete_info = ""; } if($this->orderModel->promotion) { $promotion = explode(':',$this->orderModel->promotion); $promotioninfo = '满'.$promotion[0].'元,减'.$promotion[1].'元'."\n"; } else { $promotioninfo = ''; } if ($this->orderModel->is_discount == 1) { $discountInfo = "店铺折扣:" . $this->orderModel->discount_value . "折" . "\n"; } else { $discountInfo = ""; } if ($this->orderModel->delivery_fee != 0) { $delivery_fee_info = "外送费:¥" . $this->orderModel->delivery_fee . "\n"; } else { $delivery_fee_info = ""; } $addservicestring = ""; $addservice = unserialize($this->orderModel->addservice); if(is_array($addservice)) { foreach($addservice as $addservicekey => $addserviceval) { $addservicestring .= $addservicekey.':'.$addserviceval."元\n"; } } if ($this->orderModel->is_coupon == 1) { $couponInfo = "优惠券:" . $this->orderModel->coupon_value . "元" . "\n "; } else { $couponInfo = ""; } $totalpriceInfo = "合计:¥" . $this->orderModel->total_price; if ($this->orderModel->charge_type == 1) { $totalpriceInfo = $totalpriceInfo . "(未付款)"; } else { $totalpriceInfo = $totalpriceInfo . "(已付款)"; } $OrderString = $OrderString .$quhuofangshi. $nameinfo . $phoneinfo . $addressinfo . $fieldString . $delivertimeinfo . $noteinfo . $member_delete_info .$promotioninfo. $discountInfo . $delivery_fee_info . $addservicestring . $couponInfo . $totalpriceInfo; return $OrderString; } //发送取消订单的短信提醒 private function SendCancelOrderSMS() { $smsvalid = $this->shopModel->smsvalid; if ($smsvalid) { $sms_phone = $this->shopModel->sms_phone; $OrderString = $this->GetCancelOrderSMSString(); $OrderStringLen = mb_strlen($OrderString, 'utf8'); $OrderStringLen = $OrderStringLen + 6; //加上【乐外卖】的长度 $StringQuota = ceil($OrderStringLen/67); $sms_quota = $this->adminModel->sms_quota; if ($sms_quota - $StringQuota >= 0) { $smsString = $OrderString . "\n" . '发送"#' . $this->orderid . '"确认此订单。'; if (LewaimaiHttp::SendSMSMessage($sms_phone, $smsString)) { /*更新短信余额*/ $connection = Yii::app()->db; $sql = "UPDATE wx_admin SET sms_quota = sms_quota - {$StringQuota} WHERE id = " . $this->adminModel->id; $command = $connection->createCommand($sql); $command->execute(); /*短信历史记录*/ $phoneMessageHistory = new LewaimaiPhoneMessageHistory(); $phoneMessageHistory->admin_id = $this->orderModel->admin_id; $phoneMessageHistory->lewaimai_customer_id = $this->orderModel->lewaimai_customer_id; $phoneMessageHistory->type = 4; $phoneMessageHistory->phone = $sms_phone; $phoneMessageHistory->content = $OrderString; $phoneMessageHistory->order_id = $this->orderid; $phoneMessageHistory->number = $StringQuota; $phoneMessageHistory->save(); } } } } private function SendPointPrizeOrderSMS() { //判断是否发短信 $smsvalid = $this->pointsetModel->is_duanxin; if (!$smsvalid) { return ; } $sms_phone = $this->pointsetModel->iphone; $OrderString = $this->GetPointPrizeOrderSMSString(); $OrderStringLen = mb_strlen($OrderString,'utf8'); $OrderStringLen = $OrderStringLen + 6; //加上【乐外卖】的长度 $StringQuota = ceil($OrderStringLen/67); $adminModel = Admin::model()->findByPk($this->orderModel->admin_id); if ($adminModel) { $sms_quota = $adminModel->sms_quota; if ($sms_quota - $StringQuota >= 0){ if (LewaimaiHttp::SendSMSMessage($sms_phone, $OrderString)) { /*更新短信余额*/ $connection = Yii::app()->db; $sql = "UPDATE wx_admin SET sms_quota = sms_quota - {$StringQuota} WHERE id = " . $adminModel->id; $command = $connection->createCommand($sql); $command->execute(); /*短信历史记录*/ $phoneMessageHistory = new LewaimaiPhoneMessageHistory(); $phoneMessageHistory->admin_id = $this->orderModel->admin_id; $phoneMessageHistory->lewaimai_customer_id = $this->orderModel->lewaimai_customer_id; $phoneMessageHistory->type = 5; $phoneMessageHistory->phone = $sms_phone; $phoneMessageHistory->content = $OrderString; $phoneMessageHistory->order_id = $this->orderid; $phoneMessageHistory->number = $StringQuota; $phoneMessageHistory->save(); } } } } //处理打印机自动确认后的订单状态问题 private function HandOrderConfirmed() { if (!$this->IsPrinterConfirmed) { return ; } //将订单改为确认状态 $connection = Yii::app()->db; $sql = "UPDATE wx_lewaimai_order SET order_status = 'CONFIRMED' WHERE id = " . $this->orderid; $command = $connection->createCommand($sql); $command->execute(); //给顾客发送订单确认的短信提醒 $this->SendOrderConfirmedSMS(); //给顾客发送订单确认的模板消息通知 LewaimaiWeixinTemplate::SendOrderConfirmedTemplate($this->orderid, $this->orderModel); //处理订单确认后的商品销量问题 $this->OrderConfirmedAddFoodSales(); } //给顾客发送订单确认的短信提醒 private function SendOrderConfirmedSMS() { //处理打印机确认订单时候的短信提醒问题 if($this->adminModel->is_confirm_msg == 1) { $sms_quota = $this->adminModel->sms_quota; $content = $this->shopModel->confirmmsg; $ContentStringLen = mb_strlen($content,'utf8'); $ContentStringLen = $ContentStringLen + 6; $StringQuota = ceil($ContentStringLen/67); if($sms_quota - $StringQuota >= 0) { if(LewaimaiHttp::SendSMSMessage($this->orderModel->phone, $content)) { /*更新短信余额*/ $connection = Yii::app()->db; $sql = "UPDATE wx_admin SET sms_quota = sms_quota - {$StringQuota} WHERE id = " . $this->adminModel->id; $command = $connection->createCommand($sql); $command->execute(); /*短信历史记录*/ $phoneMessageHistory = new LewaimaiPhoneMessageHistory(); $phoneMessageHistory->admin_id = $this->adminModel->id; $phoneMessageHistory->type = 3; $phoneMessageHistory->phone = $this->orderModel->phone; $phoneMessageHistory->content = $content; $phoneMessageHistory->order_id = $this->orderid; $phoneMessageHistory->number = $StringQuota; $phoneMessageHistory->save(); } } } } //修改商品的销量 private function OrderConfirmedAddFoodSales() { $fooditemlist = LewaimaiOrderItem::model()->findAll("lewaimai_order_id='$this->orderid'"); $time = strtotime(date('Y-m-d H:i:s')); $todaystart = strtotime(date('Y-m-d')); foreach($fooditemlist as $fooditem) { $foodModel = Food::Model()->findByPk($fooditem->food_id); if($foodModel) { $foodModel->ordered_count += $fooditem->quantity; if($todaystart > $foodModel->lastsaletime) { $foodModel->todaysales = $fooditem->quantity; $foodModel->lastsaletime = $time; } else { $foodModel->todaysales += $fooditem->quantity; } if(!$foodModel->save()) { foreach ($foodModel->errors as $key => $value) { foreach ($value as $valuestring); { Yii::log("food Model valuestring:" . $valuestring); } } } } } } private function GetCancelOrderSMSString() { $shopname = $this->shopModel->shopname; $OrderString = "***订单取消通知***\n“" . $shopname . "”的一笔订单已被顾客取消,订单信息如下:\n"; $adminModel = $this->adminModel; $mergeModel = LewaimaiMergeOrderSet::model()->find('admin_id='.$this->orderModel->admin_id.' and shop_id='.$this->orderModel->shop_id); if ($adminModel->order_num_type == 0) { $orderNo = $this->orderModel->admin_num; } else { $orderNo = $this->shopModel->order_prefix . $this->orderModel->shop_num; } if ($this->orderCount) { $orderCount = $this->orderCount; } else { if($this->shopModel->showordernum_type == 0) { //计算是第几次下单 $orderCount = LewaimaiOrder::model()->count("admin_id = " . $this->orderModel->admin_id . " AND lewaimai_customer_id = " . $this->orderModel->lewaimai_customer_id . " AND shop_id = " . $this->orderModel->shop_id ." AND order_status IN ('CONFIRMED','SUCCEEDED','OPEN','CANCELLED','FAILED')"); } else { $orderCount = LewaimaiOrder::model()->count("admin_id = " . $this->orderModel->admin_id . " AND lewaimai_customer_id = " . $this->orderModel->lewaimai_customer_id . " AND order_status IN ('CONFIRMED','SUCCEEDED','OPEN','CANCELLED','FAILED')"); } } //判断该顾客是不是店铺的会员 $memberModel = LewaimaiMember::model()->find("lewaimai_customer_id = " . $this->orderModel->lewaimai_customer_id . " AND admin_id = " . $this->orderModel->admin_id); if($this->shopModel->showordernum == 1) { if ($memberModel) { $OrderString .= "(会员,第" . $orderCount . "次下单)\n"; } else { $OrderString .= "(第" . $orderCount . "次下单)\n"; } } $OrderString .= "订单编号:" . $orderNo . "\n"; if($mergeModel and $mergeModel->is_open==1) { if($this->orderModel->mergeorder_id > 0) { $OrderString .= "是否是拼单:是\n"; $mergeorderModel = LewaimaiMergeOrder::model() -> findByPk($this->orderModel->mergeorder_id); $OrderString .= "拼单名字:".$mergeorderModel->name."\n"; $OrderString .= "拼单人数:".$mergeorderModel->nownum."\n"; $OrderString .= "拼单折扣:".$this->orderModel->mergeorder_discount."\n"; } else { $OrderString .= "是否是拼单:不是\n"; } } $ordertime = "下单时间:" . $this->orderModel->init_date . "\n"; $fieldString = ''; $order_field = unserialize($this->orderModel->order_field); foreach($order_field as $key => $val) { $fieldString .= $val["name"] . ":" . $val["content"] . "\n"; } $delivertime = $this->orderModel->delivertime; $delivertimeinfo = ''; if($delivertime) { $delivertimeinfo = '配送时间: '.$this->orderModel->delivery_date.' '.$delivertime. "\n"; } if($this->shopModel->open_selftake) { if($this->orderModel->is_selftake) { $quhuofangshi = "配送方式:到店自取\n"; } else { $quhuofangshi = "配送方式:店家配送\n"; } } else { $quhuofangshi = ''; } $nameinfo = "姓名:" . $this->orderModel->nickname . "\n"; $phoneinfo = "电话:" . $this->orderModel->phone . "\n"; $addressinfo = "地址:" . $this->orderModel->address . "\n"; $totalpriceInfo = "合计:¥" . $this->orderModel->total_price; if ($this->orderModel->charge_type == 1) { $totalpriceInfo = $totalpriceInfo . "(未付款)\n"; } elseif ($this->orderModel->charge_type == 2) { $totalpriceInfo = $totalpriceInfo . "(余额付款)\n"; } else { $totalpriceInfo = $totalpriceInfo . "(在线支付)\n"; } $CancelOrderString = $OrderString . $quhuofangshi.$ordertime . $nameinfo . $phoneinfo . $addressinfo . $fieldString . $delivertimeinfo . $totalpriceInfo; return $CancelOrderString; } private function GetPointPrizeOrderSMSString() { $OrderString = "积分兑奖通知 :\n"; $orderItemModels = LewaimaiPointprizeOrderItem::model()->findAll("lewaimai_order_id = " . $this->orderModel->id); foreach ($orderItemModels as $orderItem) { $newOrderString = $orderItem->prize_name . " " . $orderItem->quantity . "份" . "\n"; $OrderString = $OrderString . $newOrderString; } $nameinfo = "姓名:" . $this->orderModel->name . "\n"; $phoneinfo = "电话:" . $this->orderModel->phone . "\n"; $addressinfo = "地址:" . $this->orderModel->address . "\n"; $noteinfo = "备注:" . $this->orderModel->memo . "\n"; $OrderString = $OrderString . $nameinfo . $phoneinfo . $addressinfo . $noteinfo; return $OrderString; } private function SendNewOrderEmail() { //判断是否发邮件 $emailvalid = $this->shopModel->emailvalid; if (!$emailvalid) { return ; } $email_address = $this->shopModel->email_address; $adminId = $this->orderModel->admin_id; $shopId = $this->orderModel->shop_id; $orderModel = $this->orderModel; $nickname = $this->orderModel->nickname; $phone = $this->orderModel->phone; $address = $this->orderModel->address; $note = $this->orderModel->memo; $totalPrice = $this->orderModel->total_price; $delivery_fee = $this->orderModel->delivery_fee; $order_field = $this->orderModel->order_field; $delivertime = $this->orderModel->delivertime; $receiveEmail = $email_address; $receiveName = ''; $mergeModel = LewaimaiMergeOrderSet::model()->find('admin_id='.$this->orderModel->admin_id.' and shop_id='.$this->orderModel->shop_id); $mergeString = ''; if($mergeModel and $mergeModel->is_open==1) { if($this->orderModel->mergeorder_id > 0) { $mergeorderModel = LewaimaiMergeOrder::model() -> findByPk($this->orderModel->mergeorder_id); $mergeString = ' 是否是拼单: 是 '; $mergeString .= ' 拼单名字: '.$mergeorderModel->name.' '; $mergeString .= ' 拼单人数: '.$mergeorderModel->nownum.' '; $mergeString .= ' 拼单折扣: '.$this->orderModel->mergeorder_discount.' '; } else { $mergeString = ' 是否是拼单: 不是 '; } } // 获取店铺名字 $shopModel = $this->shopModel; if ($this->orderCount) { $orderCount = $this->orderCount; } else { //计算是第几次下单 if($shopModel->showordernum_type == 0) { $orderCount = LewaimaiOrder::model()->count("admin_id = " . $this->orderModel->admin_id . " AND lewaimai_customer_id = " . $this->orderModel->lewaimai_customer_id . " AND shop_id = " . $this->orderModel->shop_id ." AND order_status IN ('CONFIRMED','SUCCEEDED','OPEN','CANCELLED','FAILED')"); } else { $orderCount = LewaimaiOrder::model()->count("admin_id = " . $this->orderModel->admin_id . " AND lewaimai_customer_id = " . $this->orderModel->lewaimai_customer_id . " AND order_status IN ('CONFIRMED','SUCCEEDED','OPEN','CANCELLED','FAILED')"); } } $shopname = $shopModel->shopname; if($shopModel->open_selftake) { if($this->orderModel->is_selftake) { $quhuofangshi = ' 配送方式: 到店自取 '; } else { $quhuofangshi = ' 配送方式: 店家配送 '; } } else { $quhuofangshi = ''; } // 处理预设选项 $order_field = unserialize($order_field); $fieldString = ""; foreach($order_field as $key => $val) { $fieldString .= ' ' . $val["name"] . ': ' . $val["content"] . ' '; } $DefaultOrderString = ' 订单详情: '; $orderItemModels = LewaimaiOrderItem::model()->findAll("lewaimai_order_id = " . $orderModel->id); if (!$orderItemModels) { $OrderString = $DefaultOrderString; } elseif (count($orderItemModels) == 1) { $orderItemModel = $orderItemModels[0]; $OrderString = ' 订单详情: ' . $orderItemModel->food_name . " " . $orderItemModel->quantity . "份" . " ¥" . sprintf("%.1f", $orderItemModel->quantity*$orderItemModel->price) . ' '; } else { $orderItemModel = $orderItemModels[0]; $OrderString = ' 订单详情: ' . $orderItemModel->food_name . " " . $orderItemModel->quantity . "份" . " ¥" . sprintf("%.1f", $orderItemModel->quantity*$orderItemModel->price) . ' '; for ($i = 1; $i < count($orderItemModels); $i++) { $orderItemModel = $orderItemModels[$i]; $newOrderString = ' ' . $orderItemModel->food_name . " " . $orderItemModel->quantity . "份" . " ¥" . sprintf("%.1f", $orderItemModel->quantity*$orderItemModel->price) . ' '; $OrderString = $OrderString . $newOrderString; } } $adminModel = $this->adminModel; if ($adminModel->order_num_type == 0) { $orderNo = $orderModel->admin_num; } else { $orderNo = $shopModel->order_prefix . $orderModel->shop_num; } $deliverinfo = ""; if($delivertime) { $deliverinfo = '配送时间:'.$orderModel->delivery_date.' '.$delivertime.''; } //判断该顾客是不是店铺的会员 $memberModel = LewaimaiMember::model()->find("lewaimai_customer_id = " . $this->orderModel->lewaimai_customer_id . " AND admin_id = " . $this->orderModel->admin_id); if($shopModel->showordernum == 1) { if ($memberModel) { $nickname .= "(会员,第" . $orderCount . "次下单)"; } else { $nickname .= "(第" . $orderCount . "次下单)"; } } $Subject = '您有一笔乐外卖新订单,请尽快处理!'; $Content = ' 无标题文档 ' .$mergeString. ' '.$quhuofangshi.' ' . $fieldString . $deliverinfo . ' ' . $OrderString . ' '; if ($orderModel->is_member_delete) { $memberdeleteInfo = ' '; } else { $memberdeleteInfo = ""; } if($orderModel->promotion) { $promotion = explode(':',$orderModel->promotion); $promotioninfo = ' '; } else { $promotioninfo = ''; } if ($orderModel->is_discount == 1) { $discountInfo = ' '; } else { $discountInfo = ""; } $delivery_fee_string = ' '; if ($delivery_fee != 0) { $delivery_fee_info = $delivery_fee_string; } else { $delivery_fee_info = ""; } $addservicestring = ""; $addservice = unserialize($orderModel->addservice); if(is_array($addservice)) { foreach($addservice as $addservicekey => $addserviceval) { $addservicestring .= ' '; } } if ($orderModel->is_coupon == 1) { $couponInfo = ' '; } else { $couponInfo = ""; } if ($orderModel->charge_type == 1) { $totalpriceInfo = ' '; } else { $totalpriceInfo = ' '; } $Content = $Content . $memberdeleteInfo . $promotioninfo . $discountInfo . $delivery_fee_info . $addservicestring . $couponInfo . $totalpriceInfo . '

乐外卖订单信息


订单编号: ' . $orderNo . '
店铺名称: ' . $shopname . '
姓名: ' . $nickname . '
电话: ' . $phone . '
地址: ' . $address . '
下单时间: ' . date("Y-m-d H:i:s") . '
备注: ' . $note . '
会员优惠: ' . $orderModel->member_delete . '元
满' . $promotion[0] . '元送'.$promotion[1].'元
店铺折扣: ' . $orderModel->discount_value . '折
外送费: ¥' . $delivery_fee . '
'.$addservicekey.': ' . $addserviceval . '元
优惠券: ' . $orderModel->coupon_value . '元
总金额: ¥' . $totalPrice . '(未付款)
总金额: ¥' . $totalPrice . '(已付款)
'; SendEmail($receiveEmail, $receiveName, $Subject, $Content); } private function SendNewOrderWeixin() { //判断是否发微信消息 $weixinvalid = $this->shopModel->weixinvalid; if (!$weixinvalid) { return ; } LewaimaiWeixinTemplate::SendNewOrderTemplate($this->orderid, $this->orderModel, $this->shopModel); } private function SendCancelOrderWeixin() { //判断是否发微信消息 $weixinvalid = $this->shopModel->weixinvalid; if (!$weixinvalid) { return ; } LewaimaiWeixinTemplate::SendCancelOrderTemplate($this->orderid, $this->orderModel, $this->shopModel); } private function SendPointPrizeOrderWeixin() { $weixinvalid = $this->pointsetModel->is_weixin; if (!$weixinvalid) { return ; } LewaimaiWeixinTemplate::SendPointPrizeOrderTemplate($this->orderModel->id, $this->orderModel, $this->pointsetModel, $this->GetPointPrizeOrderSMSString()); } private function SendCancelOrderEmail() { $emailvalid = $this->shopModel->emailvalid; if (!$emailvalid) { return ; } $email_address = $this->shopModel->email_address; $adminId = $this->orderModel->admin_id; $shopId = $this->orderModel->shop_id; $orderModel = $this->orderModel; $nickname = $this->orderModel->nickname; $phone = $this->orderModel->phone; $address = $this->orderModel->address; $note = $this->orderModel->memo; $totalPrice = $this->orderModel->total_price; $delivery_fee = $this->orderModel->delivery_fee; $order_field = $this->orderModel->order_field; $delivertime = $this->orderModel->delivertime; $receiveEmail = $email_address; $mergeModel = LewaimaiMergeOrderSet::model()->find('admin_id='.$this->orderModel->admin_id.' and shop_id='.$this->orderModel->shop_id); $mergeString = ''; if($mergeModel and $mergeModel->is_open==1) { if($this->orderModel->mergeorder_id > 0) { $mergeorderModel = LewaimaiMergeOrder::model() -> findByPk($this->orderModel->mergeorder_id); $mergeString = ' 是否是拼单: 是 '; $mergeString .= ' 拼单名字: '.$mergeorderModel->name.' '; $mergeString .= ' 拼单人数: '.$mergeorderModel->nownum.' '; $mergeString .= ' 拼单折扣: '.$this->orderModel->mergeorder_discount.' '; } else { $mergeString = ' 是否是拼单: 不是 '; } } // 获取店铺名字 $shopModel = $this->shopModel; if ($this->orderCount) { $orderCount = $this->orderCount; } else { if($this->shopModel->showordernum_type == 0) { //计算是第几次下单 $orderCount = LewaimaiOrder::model()->count("admin_id = " . $this->orderModel->admin_id . " AND lewaimai_customer_id = " . $this->orderModel->lewaimai_customer_id . " AND shop_id = " . $this->orderModel->shop_id ." AND order_status IN ('CONFIRMED','SUCCEEDED','OPEN','CANCELLED','FAILED')"); } else { $orderCount = LewaimaiOrder::model()->count("admin_id = " . $this->orderModel->admin_id . " AND lewaimai_customer_id = " . $this->orderModel->lewaimai_customer_id . " AND order_status IN ('CONFIRMED','SUCCEEDED','OPEN','CANCELLED','FAILED')"); } } $receiveName = ''; $shopname = $shopModel->shopname; if($shopModel->open_selftake){ if($this->orderModel->is_selftake) { $quhuofangshi = ' 配送方式: 到店自取 '; } else { $quhuofangshi = ' 配送方式: 店家配送 '; } } else { $quhuofangshi = ''; } // 处理预设选项 $order_field = unserialize($order_field); $fieldString = ""; foreach($order_field as $key => $val) { $fieldString .= ' ' . $val["name"] . ': ' . $val["content"] . ' '; } $DefaultOrderString = ' 订单详情: '; $orderItemModels = LewaimaiOrderItem::model()->findAll("lewaimai_order_id = " . $orderModel->id); if (!$orderItemModels) { $OrderString = $DefaultOrderString; } elseif (count($orderItemModels) == 1) { $orderItemModel = $orderItemModels[0]; $OrderString = ' 订单详情: ' . $orderItemModel->food_name . " " . $orderItemModel->quantity . "份" . " ¥" . sprintf("%.1f", $orderItemModel->quantity*$orderItemModel->price) . ' '; } else { $orderItemModel = $orderItemModels[0]; $OrderString = ' 订单详情: ' . $orderItemModel->food_name . " " . $orderItemModel->quantity . "份" . " ¥" . sprintf("%.1f", $orderItemModel->quantity*$orderItemModel->price) . ' '; for ($i = 1; $i < count($orderItemModels); $i++) { $orderItemModel = $orderItemModels[$i]; $newOrderString = ' ' . $orderItemModel->food_name . " " . $orderItemModel->quantity . "份" . " ¥" . sprintf("%.1f", $orderItemModel->quantity*$orderItemModel->price) . ' '; $OrderString = $OrderString . $newOrderString; } } $delivery_fee_string = ' 外送费: ¥' . $delivery_fee . ' '; if ($delivery_fee != 0) { $delivery_fee_info = $delivery_fee_string; } else { $delivery_fee_info = ""; } $adminModel = $this->adminModel; if ($adminModel->order_num_type == 0) { $orderNo = $orderModel->admin_num; } else { $orderNo = $shopModel->order_prefix . $orderModel->shop_num; } $deliverinfo = ""; if($delivertime) { $deliverinfo = '配送时间:'.$orderModel->delivery_date.' '.$delivertime.''; } //判断该顾客是不是店铺的会员 $memberModel = LewaimaiMember::model()->find("lewaimai_customer_id = " . $this->orderModel->lewaimai_customer_id . " AND admin_id = " . $this->orderModel->admin_id); if($shopModel->showordernum == 1) { if ($memberModel) { $nickname .= "(会员,第" . $orderCount . "次下单)"; } else { $nickname .= "(第" . $orderCount . "次下单)"; } } $Subject = '乐外卖订单取消通知!'; $Content = ' 无标题文档 ' .$mergeString. ' '.$quhuofangshi.' ' . $fieldString . $deliverinfo . ' ' . $OrderString . ' '; if ($orderModel->is_member_delete) { $memberdeleteInfo = ' '; } else { $memberdeleteInfo = ""; } if($orderModel->promotion) { $promotion = explode(':',$orderModel->promotion); $promotioninfo = ' '; } else { $promotioninfo = ''; } if ($orderModel->is_discount == 1) { $discountInfo = ' '; } else { $discountInfo = ""; } $addservicestring = ""; $addservice = unserialize($orderModel->addservice); if(is_array($addservice)) { foreach($addservice as $addservicekey => $addserviceval) { $addservicestring .= ' '; } } if ($orderModel->is_coupon == 1) { $couponInfo = ' '; } else { $couponInfo = ""; } if ($orderModel->charge_type == 1) { $totalpriceInfo = ' '; } else { $totalpriceInfo = ' '; } $Content = $Content . $memberdeleteInfo . $promotioninfo . $discountInfo . $delivery_fee_info . $addservicestring . $couponInfo . $totalpriceInfo . '

被取消订单信息


订单编号: ' . $orderNo . '
店铺名称: ' . $shopname . '
姓名: ' . $nickname . '
电话: ' . $phone . '
地址: ' . $address . '
下单时间: ' . date("Y-m-d H:i:s") . '
备注: ' . $note . '
会员优惠: ' . $orderModel->member_delete . '元
满' . $promotion[0] . '元减'.$promotion[1].'
店铺折扣: ' . $orderModel->discount_value . '折
'.$addservicekey.': ' . $addserviceval . '元
优惠券: ' . $orderModel->coupon_value . '元
总金额: ¥' . $totalPrice . '(未付款)
总金额: ¥' . $totalPrice . '(已付款)
' . '

该笔订单已经被顾客取消,请不要进行配送,如有疑问请电话联系顾客!

' . ' '; SendEmail($receiveEmail, $receiveName, $Subject, $Content); } private function SendPointPrizeOrderEmail() { //判断是否发邮件 $emailvalid = $this->pointsetModel->is_emaill; if (!$emailvalid) { return ; } $email_address = $this->pointsetModel->email; $adminId = $this->orderModel->admin_id; $orderModel = $this->orderModel; $name = $this->orderModel->name; $phone = $this->orderModel->phone; $address = $this->orderModel->address; $note = $this->orderModel->memo; $receiveEmail = $email_address; $receiveName = ''; $DefaultOrderString = ' 兑奖详情: '; $orderItemModels = LewaimaiPointprizeOrderItem::model()->findAll("lewaimai_order_id = " . $orderModel->id); if (!$orderItemModels) { $OrderString = $DefaultOrderString; } elseif (count($orderItemModels) == 1) { $orderItemModel = $orderItemModels[0]; $OrderString = ' 订单详情: ' . $orderItemModel->prize_name . " " . $orderItemModel->quantity . "份" . ' '; } else { $orderItemModel = $orderItemModels[0]; $OrderString = ' 订单详情: ' . $orderItemModel->prize_name . " " . $orderItemModel->quantity . "份" . ' '; for ($i = 1; $i < count($orderItemModels); $i++) { $orderItemModel = $orderItemModels[$i]; $newOrderString = ' ' . $orderItemModel->prize_name . " " . $orderItemModel->quantity . "份" . ' '; $OrderString = $OrderString . $newOrderString; } } $Subject = '您有一笔积分兑奖订单,请尽快处理!'; $Content = ' 无标题文档 ' . ' ' . $OrderString . ' '; $Content = $Content . '

积分兑奖信息


姓名: ' . $name . '
电话: ' . $phone . '
地址: ' . $address . '
下单时间: ' . date("Y-m-d H:i:s") . '
备注: ' . $note . '
'; SendEmail($receiveEmail, $receiveName, $Subject, $Content); } private function PrintCancelOrder() { $shopprinterModels = ShopPrinter::model()->findAll("shop_id = " . $this->shopModel->id); foreach ($shopprinterModels as $shopprinterModel) { $printer_id = $shopprinterModel->printer_id; $printerModel = Printer::model()->findByPk($printer_id); if (!$printerModel) { continue; } $printer_type = $printerModel->printer_type; $lewaimai_sn = $printerModel->lewaimai_sn; $member_code = $printerModel->member_code; $feyin_key = $printerModel->feyin_key; $device_no = $printerModel->device_no; $shopcode = $printerModel->shopcode; $printer_num = $printerModel->printer_num; $printer_info = $printerModel->printer_info; $is_cut = $printerModel->is_cut; $big_ordernum = $printerModel->big_ordernum; $big_name = $printerModel->big_name; $big_phone = $printerModel->big_phone; $big_address = $printerModel->big_address; $big_content = $printerModel->big_content; $big_price = $printerModel->big_price; if ($printer_type == 1) { $content = $this->GetPrinterCancelOrderContent(2, $printer_info, $is_cut); $this->SendFeyinPrinterMessage($member_code, $device_no, $feyin_key, $content); } elseif ($printer_type == 2) { $content = $this->GetPrinterCancelOrderContent(3, $printer_info, $is_cut); $this->SendKeLaiLePrinterMessage($shopcode, $content); } elseif ($printer_type == 3) { $content = $this->GetPrinterCancelOrderContent(1, $printer_info, $is_cut); $this->SendLewaimaiPrinterMessage(1, $lewaimai_sn, $printer_num, $content); } } } private function PrintPointPrizeOrder() { $printerModel = Printer::model()->findByPk($this->pointsetModel->printer_id); if (!$printerModel) { Yii::log("no this printer! PrintPointPrizeOrder failed!"); return ; } $printer_type = $printerModel->printer_type; $lewaimai_sn = $printerModel->lewaimai_sn; $member_code = $printerModel->member_code; $feyin_key = $printerModel->feyin_key; $device_no = $printerModel->device_no; $shopcode = $printerModel->shopcode; $printer_num = $printerModel->printer_num; $printer_info = $printerModel->printer_info; $is_cut = $printerModel->is_cut; $big_ordernum = $printerModel->big_ordernum; $big_name = $printerModel->big_name; $big_phone = $printerModel->big_phone; $big_address = $printerModel->big_address; $big_content = $printerModel->big_content; $big_price = $printerModel->big_price; if ($printer_type == 1) { $content = $this->GetPrinterPointPrizeOrderContent(2, $is_cut); $this->SendFeyinPrinterMessage($member_code, $device_no, $feyin_key, $content); } elseif ($printer_type == 2) { $content = $this->GetPrinterPointPrizeOrderContent(3, $is_cut); $this->SendKeLaiLePrinterMessage($shopcode, $content); } elseif ($printer_type == 3) { $content = $this->GetPrinterPointPrizeOrderContent(1, $is_cut); $this->SendLewaimaiPrinterMessage(1, $lewaimai_sn, $printer_num, $content); } } private function SendLewaimaiPrinterMessage($orderid, $lewaimai_sn, $printer_num, $content) { $dingdanID = $orderid; //订单号 $dayinjisn = $lewaimai_sn; //打印机ID号 $pages = $printer_num; //联数 $dingdan = $content; //订单内容 $replyURL = "http://www.lewaimai.com/lewaimaiprinter/orderstatus";//回复确认URL if($pages <= 0 || $pages > 4) { Yii::log("乐外卖打印机打印联数不能大于4!"); return false; } if(empty($dingdanID)||empty($dayinjisn)||empty($pages)||empty($dingdan)||empty($replyURL)) { return false; } $url = 'http://lewaimaiprinter.lewaimai.com:60002';//POST指向的API链接 // 提交API的内容 $data = array( 'dingdanID'=>'dingdanID='.$dingdanID, //订单号 'dayinjisn'=>'dayinjisn='.$dayinjisn, //打印机ID号 'dingdan'=>'dingdan='.$dingdan, //订单内容 'pages'=>'pages='.$pages, //联数 'replyURL'=>'replyURL='.$replyURL); //回复确认URL $post_data = implode('&',$data); LewaimaiHttp::POST_ASYNC($url, array(), array(CURLOPT_POSTFIELDS=>$post_data)); return true; } private function SendFeyinPrinterMessage($MEMBER_CODE, $DEVICE_NO, $FEYIN_KEY, $Content) { $msgNo = microtime() . LewaimaiString::create_noncestr(16); $msg = array( 'memberCode' => $MEMBER_CODE, 'msgDetail' => $Content, 'deviceNo' => $DEVICE_NO, 'msgNo' => $msgNo ); $msg['reqTime'] = number_format(1000 * time(), 0, '', ''); $content = $msg['memberCode'] . $msg['msgDetail'] . $msg['deviceNo'] . $msg['msgNo'] . $msg['reqTime'] . $FEYIN_KEY; $msg['securityCode'] = md5($content); $msg['mode'] = 2; $post_url = "my.feyin.net/api/sendMsg"; LewaimaiHttp::POST_ASYNC($post_url, $msg); return true; } private function SendKeLaiLePrinterMessage($shopCode, $content, $orderid = '', $total_price = '', $charge_type = '') { // app params $appid = 'wp2a061b92bbd950cc'; $appSecret = '45b19efd84889e727cc29da91d7ffb15'; // request params $reqParams = array( 'appid' => $appid, 'timestamp' => time(), 'shopCode' => $shopCode, 'content' => $content, 'orderCode' => $orderid, 'price' => $total_price, 'charge_type' => $charge_type, ); // generate sign; $params = array(); foreach ($reqParams as $key=>$val) $params[$key]=$val; ksort($params); //SORT_STRING | SORT_FLAG_CASE); $arr = array(); foreach ($params as $key => $val) $arr[] = "$key=$val"; $reqParams['sign'] = sha1(implode('&', $arr).$appSecret); $jsonString = CJSON::encode($reqParams); $post_url = 'http://p.kelaile.cn/api/service/print'; LewaimaiHttp::POST_ASYNC($post_url, array(), array(CURLOPT_POSTFIELDS=>$jsonString)); return true; } //printer_type 1:乐外卖打印机 2:飞印打印机 3:客来乐打印机 private function GetPrinterOrderContent($printer_type = 1, $printer_num, $printer_info, $is_cut = 0, $big_ordernum = 0, $big_name = 0, $big_phone = 0, $big_address = 0, $big_content = 0, $big_price = 0) { $admin_id = $this->orderModel->admin_id; $shop_id = $this->orderModel->shop_id; $delivery_fee = $this->orderModel->delivery_fee; $total_price = $this->orderModel->total_price; $total_point = $this->orderModel->total_point; $nickname = $this->orderModel->nickname; $phone = $this->orderModel->phone; $address = $this->orderModel->address; $memo = $this->orderModel->memo; $init_date = $this->orderModel->init_date; //计算是第几次下单 if($this->shopModel->showordernum_type == 0) { $orderCount = LewaimaiOrder::model()->count("admin_id = " . $this->orderModel->admin_id . " AND lewaimai_customer_id = " . $this->orderModel->lewaimai_customer_id . " AND shop_id = " . $this->orderModel->shop_id . " AND order_status IN ('CONFIRMED','SUCCEEDED','OPEN','CANCELLED','FAILED')"); } else { $orderCount = LewaimaiOrder::model()->count("admin_id = " . $this->orderModel->admin_id . " AND lewaimai_customer_id = " . $this->orderModel->lewaimai_customer_id . " AND order_status IN ('CONFIRMED','SUCCEEDED','OPEN','CANCELLED','FAILED')"); } if (!$this->orderCount) { $this->orderCount = $orderCount; } //判断该顾客是不是店铺的会员 $memberModel = LewaimaiMember::model()->find("lewaimai_customer_id = " . $this->orderModel->lewaimai_customer_id . " AND admin_id = " . $this->orderModel->admin_id); if($this->shopModel->showordernum == 1) { if ($memberModel) { $nickname .= "(会员,第" . $orderCount . "次下单)"; } else { $nickname .= "(第" . $orderCount . "次下单)"; } } //求预设选项 $order_field = unserialize($this->orderModel->order_field); $fieldString = ""; foreach($order_field as $key => $val) { $fieldString .= $val["name"] . ":" . $val["content"] . "\r\n"; } //支付方式 $charge_type = $this->orderModel->charge_type; if ($charge_type == 1) { $chargeString = "货到付款"; } elseif ($charge_type == 2) { $chargeString = "余额支付(已付款)"; } elseif ($charge_type == 3) { $chargeString = "在线支付(已付款)"; } $is_discount = $this->orderModel->is_discount; $discount_value = $this->orderModel->discount_value; $is_coupon = $this->orderModel->is_coupon; $coupon_value = $this->orderModel->coupon_value; $is_member_delete = $this->orderModel->is_member_delete; $member_delete = $this->orderModel->member_delete; if ($is_member_delete) { $memberdeleteString = "会员优惠:" . $member_delete . "元"; $memberdeleteString = RightString($memberdeleteString) . "\r\n"; } else { $memberdeleteString = ''; } if($this->orderModel->promotion) { $promotion = explode(':',$this->orderModel->promotion); $promotioninfo = '满'.$promotion[0].'元,减'.$promotion[1].'元'; $promotioninfo = RightString($promotioninfo) . "\r\n"; } else { $promotioninfo = ''; } if ($is_discount) { $discountString = "店铺折扣:" . $discount_value . "折"; $discountString = RightString($discountString) . "\r\n"; } else { $discountString = ""; } if ($is_coupon) { $couponString = "优惠券:" . $coupon_value . "元"; $couponString = RightString($couponString) . "\r\n"; } else { $couponString = ""; } $shopname = $this->shopModel->shopname; $orderphone = $this->shopModel->orderphone; // 读取订单详情 $orderItemModels = LewaimaiOrderItem::model()->findAll("lewaimai_order_id = " . $this->orderid); $totalNum = 0; $order_item_string = ""; foreach ($orderItemModels as $orderItemModel) { $food_name = $orderItemModel->food_name; $price = $orderItemModel->price; $price = sprintf("%.1f", $price); $quantity = $orderItemModel->quantity; $item_total_price = $orderItemModel->price * $orderItemModel->quantity; $item_total_price = sprintf("%.1f", $item_total_price); $showFoodName = HandleFoodName($food_name); $showPrice = HandleNum($price); $showQuantity = HandleNum($quantity); $showItemTotalPrice = HandleNum($item_total_price); $item_string = $showFoodName . $showPrice . " " . $showQuantity . " " . $showItemTotalPrice; $order_item_string = $order_item_string . $item_string . "\r\n"; $totalNum += $quantity; } if ($big_content) { if ($printer_type == 1) { $order_item_string = GetHalfWidthBigStringLewaimai($order_item_string); } elseif ($printer_type == 2) { $order_item_string = GetHalfWidthBigStringFeyin($order_item_string); } } //处理配送费 if ($delivery_fee != 0) { $delivery_fee = sprintf("%.1f", $delivery_fee); $showFoodName = HandleFoodName("外送费"); $showPrice = HandleNum(""); $showQuantity = HandleNum(""); $showItemTotalPrice = HandleNum($delivery_fee); $delivery_fee_string = $showFoodName . $showPrice . " " . $showQuantity . " " . $showItemTotalPrice; $order_item_string = $order_item_string . $delivery_fee_string . "\r\n"; } if ($this->adminModel->order_num_type == 0) { $orderNo = $this->orderModel->admin_num; } else { $orderNo = $this->shopModel->order_prefix . $this->orderModel->shop_num; } $delivertime = $this->orderModel->delivertime; $delivertimeinfo = ''; if($delivertime) { $delivertimeinfo = '配送时间: '.$this->orderModel->delivery_date.' '.$delivertime . "\r\n"; } //开始计算returnString if ($printer_type == 1) { $returnString = CenterTitleLeWaiMai($shopname) . "\r\n" . "\r\n"; } elseif ($printer_type == 2) { $returnString = CenterTitleFeyin($shopname) . "\r\n" . "\r\n"; } elseif ($printer_type == 3) { $returnString = CenterString($shopname) . "\r\n" . "\r\n"; } if ($big_ordernum) { if ($printer_type == 1) { $ordernumString = GetHalfWidthBigStringLewaimai('订单编号:' . $orderNo) . "\r\n" ; } elseif ($printer_type == 2) { $ordernumString = GetHalfWidthBigStringFeyin('订单编号:' . $orderNo) . "\r\n" ; } } else { $ordernumString = '订单编号:' . $orderNo . "\r\n" ; } $mergeModel = LewaimaiMergeOrderSet::model()->find('admin_id='.$this->orderModel->admin_id.' and shop_id='.$this->orderModel->shop_id); $mergeString = ''; if($mergeModel and $mergeModel->is_open==1) { if($this->orderModel->mergeorder_id > 0) { $mergeString = "是否是拼单:是\r\n"; $mergeorderModel = LewaimaiMergeOrder::model() -> findByPk($this->orderModel->mergeorder_id); $mergeString .= "拼单名字:".$mergeorderModel->name."\r\n"; $mergeString .= "拼单人数:".$mergeorderModel->nownum."\r\n"; $mergeString .= "拼单折扣:".$this->orderModel->mergeorder_discount."\r\n"; } else { $mergeString = "是否是拼单:不是\r\n"; } } if($this->shopModel->open_selftake) { if($this->orderModel->is_selftake) { $quhuofangshi = "取货方式:到店自取\r\n"; } else { $quhuofangshi = "取货方式:店家配送\r\n"; } } else { $quhuofangshi = ''; } $returnString .= $ordernumString . $mergeString . $quhuofangshi; if ($big_name) { if ($printer_type == 1) { $nameString = GetHalfWidthBigStringLewaimai('姓名:' . $nickname) . "\r\n" ; } elseif ($printer_type == 2) { $nameString = GetHalfWidthBigStringFeyin('姓名:' . $nickname) . "\r\n" ; } } else { $nameString = '姓名:' . $nickname . "\r\n"; } if ($big_phone) { if ($printer_type == 1) { $phoneString = GetHalfWidthBigStringLewaimai('电话:' . $phone) . "\r\n"; } elseif ($printer_type == 2) { $phoneString = GetHalfWidthBigStringFeyin('电话:' . $phone) . "\r\n"; } } else { $phoneString = '电话:' . $phone . "\r\n"; } if ($big_address) { if ($printer_type == 1) { $addressString = GetHalfWidthBigStringLewaimai('地址:' . $address) . "\r\n"; } elseif ($printer_type == 2) { $addressString = GetHalfWidthBigStringFeyin('地址:' . $address) . "\r\n"; } } else { $addressString = '地址:' . $address . "\r\n"; } $returnString .= $nameString . $phoneString . $addressString; $addserviceString = ""; $addservice = unserialize($this->orderModel->addservice); if(is_array($addservice)) { foreach($addservice as $addservicekey => $addserviceval) { $addserviceString .= RightString($addservicekey.':'.$addserviceval."元"). "\r\n"; } } $returnString .= $fieldString . $delivertimeinfo . '下单时间:' . $init_date . "\r\n" . '--------------------------------' . "\r\n" . '商品 单价 数量 金额 ' . "\r\n" . $order_item_string . "\r\n" . '备注:' . $memo . "\r\n" . '--------------------------------' . "\r\n" . $memberdeleteString . $promotioninfo . $discountString . $couponString . $addserviceString; if ($big_price) { if ($printer_type == 1) { $priceString = GetHalfWidthBigStringLewaimai(RightString("共" . $totalNum . "份,合计:" . $total_price . "元")); } elseif ($printer_type == 2) { $priceString = GetHalfWidthBigStringFeyin(RightString("共" . $totalNum . "份,合计:" . $total_price . "元")); } } else { $priceString = RightString("共" . $totalNum . "份,合计:" . $total_price . "元"); } $returnString .= $priceString . "\r\n" . RightString($chargeString) . "\r\n" . "\r\n" . CenterString($printer_info); $content = ""; if ($printer_type == 1) { if ($is_cut) { $content = "<1B40><1B40><1B40>" . $returnString . "<0D0A><0D0A><0D0A><0D0A><0D0A><0D0A>" . "<1D5642000A0A>"; } else { $content = "<1B40><1B40><1B40>" . $returnString . "<0D0A><0D0A><0D0A><0D0A><0D0A><0D0A><0D0A><0D0A>"; } } elseif ($printer_type == 2 || $printer_type == 3) { for ($i = 0; $i < $printer_num; $i++) { $content = $content . $returnString; if ($i != $printer_num - 1) { $content = $content . "\r\n\r\n\r\n"; } } } return $content; } //printer_type 1:乐外卖打印机 2:飞印打印机 3:客来乐打印机 private function GetPrinterCancelOrderContent($printer_type, $printer_info, $is_cut = 0) { $admin_id = $this->orderModel->admin_id; $shop_id = $this->orderModel->shop_id; $delivery_fee = $this->orderModel->delivery_fee; $total_price = $this->orderModel->total_price; $total_point = $this->orderModel->total_point; $nickname = $this->orderModel->nickname; $phone = $this->orderModel->phone; $address = $this->orderModel->address; $memo = $this->orderModel->memo; $init_date = $this->orderModel->init_date; $mergeModel = LewaimaiMergeOrderSet::model()->find('admin_id='.$this->orderModel->admin_id.' and shop_id='.$this->orderModel->shop_id); $mergeString = ''; if($mergeModel and $mergeModel->is_open==1) { if($this->orderModel->mergeorder_id > 0) { $mergeString = "是否是拼单:是\r\n"; $mergeorderModel = LewaimaiMergeOrder::model() -> findByPk($this->orderModel->mergeorder_id); $mergeString .= "拼单名字:".$mergeorderModel->name."\r\n"; $mergeString .= "拼单人数:".$mergeorderModel->nownum."\r\n"; $mergeString .= "拼单折扣:".$this->orderModel->mergeorder_discount."\r\n"; } else { $mergeString = "是否是拼单:不是\r\n"; } } //求预设选项 $order_field = unserialize($this->orderModel->order_field); $fieldString = ""; foreach($order_field as $key => $val) { $fieldString .= $val["name"] . ":" . $val["content"] . "\r\n"; } //支付方式 $charge_type = $this->orderModel->charge_type; if ($charge_type == 1) { $chargeString = "货到付款"; } elseif ($charge_type == 2) { $chargeString = "余额支付(已付款)"; } elseif ($charge_type == 3) { $chargeString = "在线支付(已付款)"; } $is_discount = $this->orderModel->is_discount; $discount_value = $this->orderModel->discount_value; $is_coupon = $this->orderModel->is_coupon; $coupon_value = $this->orderModel->coupon_value; if ($is_discount) { $discountString = "会员折扣:" . $discount_value . "折"; $discountString = RightString($discountString) . "\r\n"; } else { $discountString = ""; } if ($is_coupon) { $couponString = "优惠券:" . $coupon_value . "元"; $couponString = RightString($couponString) . "\r\n"; } else { $couponString = ""; } // 读取店铺名 $shopname = $this->shopModel->shopname; $orderphone = $this->shopModel->orderphone; // 读取订单详情 $orderItemModels = LewaimaiOrderItem::model()->findAll("lewaimai_order_id = " . $this->orderid); $order_item_string = ""; foreach ($orderItemModels as $orderItemModel) { $food_name = $orderItemModel->food_name; $price = $orderItemModel->price; $price = sprintf("%.1f", $price); $quantity = $orderItemModel->quantity; $item_total_price = $orderItemModel->price * $orderItemModel->quantity; $item_total_price = sprintf("%.1f", $item_total_price); $showFoodName = HandleFoodName($food_name); $showPrice = HandleNum($price); $showQuantity = HandleNum($quantity); $showItemTotalPrice = HandleNum($item_total_price); $item_string = $showFoodName . $showPrice . " " . $showQuantity . " " . $showItemTotalPrice; $order_item_string = $order_item_string . $item_string . "\r\n"; } //处理配送费 if ($delivery_fee != 0) { $delivery_fee = sprintf("%.1f", $delivery_fee); $showFoodName = HandleFoodName("外送费"); $showPrice = HandleNum(""); $showQuantity = HandleNum(""); $showItemTotalPrice = HandleNum($delivery_fee); $delivery_fee_string = $showFoodName . $showPrice . " " . $showQuantity . " " . $showItemTotalPrice; $order_item_string = $order_item_string . $delivery_fee_string . "\r\n"; } if ($this->adminModel->order_num_type == 0) { $orderNo = $this->orderModel->admin_num; } else { $orderNo = $this->shopModel->order_prefix . $this->orderModel->shop_num; } $delivertime = $this->orderModel->delivertime; $delivertimeinfo = ''; if($delivertime) { $delivertimeinfo = '配送时间: '.$this->orderModel->delivery_date.' '.$delivertime . "\r\n"; } if ($printer_type == 1) { $returnString = CenterTitleLeWaiMai("订单取消通知") . "\r\n" . "\r\n"; } elseif ($printer_type == 2) { $returnString = CenterTitleFeyin("订单取消通知") . "\r\n" . "\r\n"; } else { $returnString = CenterString("订单取消通知") . "\r\n" . "\r\n"; } $returnString .= '店铺:' . $shopname . "\r\n" . '订单编号:' . $orderNo . "\r\n" .$mergeString; if($this->shopModel->open_selftake) { if($this->orderModel->is_selftake) { $quhuofangshi = "取货方式:到店自取\r\n"; } else { $quhuofangshi = "取货方式:店家配送\r\n"; } } else { $quhuofangshi = ''; } $returnString .= $quhuofangshi; $returnString .= '姓名:' . $nickname . "\r\n" . '电话:' . $phone . "\r\n" . '地址:' . $address . "\r\n" ; $returnString .= $fieldString . $delivertimeinfo . '下单时间:' . $init_date . "\r\n" . '--------------------------------' . "\r\n" . '商品 单价 数量 金额 ' . "\r\n" . $order_item_string . "\r\n" . '备注:' . $memo . "\r\n" . '--------------------------------' . "\r\n" . $discountString . $couponString . RightString("合计:" . $total_price . "元") . "\r\n" . RightString($chargeString) . "\r\n" . "\r\n" . CenterString($printer_info) . "\r\n"; if ($printer_type == 1) { if ($is_cut) { $content = "<1B40><1B40><1B40>" . $returnString . "<0D0A><0D0A><0D0A><0D0A><0D0A><0D0A>" . "<1D5642000A0A>"; } else { $content = "<1B40><1B40><1B40>" . $returnString . "<0D0A><0D0A><0D0A><0D0A><0D0A><0D0A><0D0A><0D0A>"; } } elseif ($printer_type == 2 || $printer_type == 3) { $content = $returnString; } return $content; } //printer_type 1:乐外卖打印机 2:飞印打印机 3:客来乐打印机 private function GetPrinterPointPrizeOrderContent($printer_type, $is_cut = 0) { $orderModel = $this->orderModel; $admin_id = $orderModel->admin_id; $total_point = $orderModel->total_point; $name = $orderModel->name; $phone = $orderModel->phone; $address = $orderModel->address; $memo = $orderModel->memo; $init_time = $orderModel->init_time; // 读取订单详情 $orderItemModels = LewaimaiPointprizeOrderItem::model()->findAll("lewaimai_order_id = " . $this->orderid); $order_item_string = ""; foreach ($orderItemModels as $orderItemModel) { $prize_name = $orderItemModel->prize_name; $quantity = $orderItemModel->quantity; $item_string = $prize_name . " " . $quantity . " 份\r\n"; $order_item_string = $order_item_string . $item_string; } if ($printer_type == 1) { $returnString = CenterTitleLeWaiMai("积分兑奖通知") . "\r\n" . "\r\n"; } elseif ($printer_type == 2) { $returnString = CenterTitleFeyin("积分兑奖通知") . "\r\n" . "\r\n"; } else { $returnString = CenterString("积分兑奖通知") . "\r\n" . "\r\n"; } $returnString .= '姓名:' . $name . "\r\n" . '电话:' . $phone . "\r\n" . '地址:' . $address . "\r\n" ; $returnString .= '兑奖时间:' . $init_time . "\r\n" . '--------------------------------' . "\r\n" . $order_item_string . '--------------------------------' . "\r\n" . '备注:' . $memo . "\r\n"; if ($printer_type == 1) { if ($is_cut) { $content = "<1B40><1B40><1B40>" . $returnString . "<0D0A><0D0A><0D0A><0D0A><0D0A><0D0A>" . "<1D5642000A0A>"; } else { $content = "<1B40><1B40><1B40>" . $returnString . "<0D0A><0D0A><0D0A><0D0A><0D0A><0D0A><0D0A><0D0A>"; } } elseif ($printer_type == 2 || $printer_type == 3) { $content = $returnString; } return $content; } }