diff --git a/app/Controller/v3/TestController.php b/app/Controller/v3/TestController.php
new file mode 100644
index 0000000..abfd0d0
--- /dev/null
+++ b/app/Controller/v3/TestController.php
@@ -0,0 +1,21 @@
+feiePrintService->feiePrint(163390234331914240);
+ return $this->success($res);
+ }
+}
\ No newline at end of file
diff --git a/app/Model/v3/OrderMain.php b/app/Model/v3/OrderMain.php
index 3e2c185..d5c41bf 100644
--- a/app/Model/v3/OrderMain.php
+++ b/app/Model/v3/OrderMain.php
@@ -107,7 +107,7 @@ class OrderMain extends Model
public function orders()
{
- return $this->hasMany(Order::class, 'order_main_id', 'id');
+ return $this->hasMany(Order::class, 'order_main_id', 'global_order_id');
}
public function orderGoods()
diff --git a/app/Service/v3/Implementations/FeiePrintService.php b/app/Service/v3/Implementations/FeiePrintService.php
index eca012b..08b9cf4 100644
--- a/app/Service/v3/Implementations/FeiePrintService.php
+++ b/app/Service/v3/Implementations/FeiePrintService.php
@@ -3,6 +3,7 @@
namespace App\Service\v3\Implementations;
use App\Libs\FeiePrintClient;
+use App\Model\v3\OrderMain;
use App\Service\v3\Interfaces\FeiePrintServiceInterface;
use Hyperf\DbConnection\Db;
@@ -41,28 +42,33 @@ class FeiePrintService implements FeiePrintServiceInterface
public function feiePrint($globalOrderId)
{
// TODO 对象数组=》二维数组
- $data = Db::table('lanzu_order_main as m')
- ->join('lanzu_order as o','o.order_main_id', '=', 'm.id','inner')
- ->join('lanzu_order_goods as g','o.id','=', 'g.order_id','inner')
- ->join('lanzu_feprint as f','m.market_id','=', 'f.market_id','inner')
- ->join('lanzu_store as s','s.id','=', 'o.store_id','inner')
- ->where('m.global_order_id', $globalOrderId)
- ->selectRaw("o.note as o_note,g.name,g.number,g.price,g.goods_unit,m.delivery_time_note as ps_time,m.address,m.note,m.name as user_name,m.delivery_money,m.money as m_money,m.coupon_money,m.services_money,f.sn,m.tel,m.order_num,g.id,g.spec,s.name as shopname")
- ->orderBy('s.id')
- ->get()
- ->toArray();
-
+ $data = OrderMain::query()->with(['orders' => function($query){
+ $query->with('store','orderGoods');
+ }
+ ])->where('global_order_id',$globalOrderId)->first();
+ // $data = Db::table('lanzu_order_main as m')
+ // ->join('lanzu_order as o','o.order_main_id', '=', 'm.global_order_id','inner')
+ // ->join('lanzu_order_goods as g','o.id','=', 'g.order_id','inner')
+ // ->join('lanzu_feprint as f','m.market_id','=', 'f.market_id','inner')
+ // ->join('lanzu_store_new as s','s.id','=', 'o.store_id','inner')
+ // ->where('m.global_order_id', $globalOrderId)
+ // ->selectRaw("o.note as o_note,g.name,g.number,g.price,g.goods_unit,m.delivery_time_note as ps_time,m.address,m.note,m.name as user_name,m.delivery_money,m.money as m_money,m.coupon_money,m.services_money,f.sn,m.tel,m.order_num,g.id,g.spec,s.name as shopname")
+ // ->orderBy('s.id')
+ // ->get()
+ // ->toArray();
+ // print_r($data);
+ // return $data;
if (empty($data)) {
return ;
}
- foreach ($data as $key => &$item) {
- $item = (array)$item;
- }
+ // foreach ($data['order'] as $key => &$item) {
+ // $item = (array)$item;
+ // }
- $content = $this->printFormat($data, 14, 6, 3, 6);
+ $content = $this->printFormat($data, 4, 14, 7, 7);
- $res = $this->printMsg($data[0]['sn'], $content, 1);
- return ($res);
+ //$res = $this->printMsg('920527381', $content, 1);
+ return $content;
}
/**
@@ -96,151 +102,166 @@ class FeiePrintService implements FeiePrintServiceInterface
protected function printFormat($arr, $A, $B, $C, $D)
{
+ $length = $A + $B +$C + $D;
$orderInfo = '懒族生活
';
- $orderInfo .= '名称 单价 数量 金额
';
+ $orderInfo .= '数量 名称 单价 金额
';
$orderInfo .= '--------------------------------
';
- $shopname = "";
$shopnum = 0;
- foreach ($arr as $k5 => $v5) {
- if ($shopname != $v5['shopname']) {
- if ($shopname != "") {
- $orderInfo .= '
';
- }
- $shopnum++;
- $orderInfo .= "(" . $shopnum . ")" .$v5['shopname'] . '
';
- $shopname = $v5['shopname'];
- }
- $name = $v5['name'];
- $name .= "(规格:". $v5['goods_unit'].")";
- $price = $v5['m_money'];
- $num = $v5['number'];
- $prices = sprintf("%.2f",$v5['m_money']*$v5['number']);
- $kw3 = '';
- $kw1 = '';
- $kw2 = '';
- $kw4 = '';
- $str = $name;
- $blankNum = $A;//名称控制为14个字节
- $lan = mb_strlen($str,'utf-8');
- $m = 0;
- $j=1;
- $blankNum++;
- $result = array();
- if(strlen($price) < $B){
- $k1 = $B - strlen($price);
- for($q=0;$q<$k1;$q++){
- $kw1 .= ' ';
- }
- $price = $kw1.$price;
- }
- if(strlen($num) < $C){
- $k2 = $C - strlen($num);
- for($q=0;$q<$k2;$q++){
- $kw2 .= ' ';
- }
- $num = $kw2.$num;
- }
- if(strlen($prices) < $D){
- $k3 = $D - strlen($prices);
- for($q=0;$q<$k3;$q++){
- $kw4 .= ' ';
- }
- $prices = $kw4.$prices;
- }
- for ($i=0;$i<$lan;$i++){
- $new = mb_substr($str,$m,$j,'utf-8');
- $j++;
- if(mb_strwidth($new,'utf-8')<$blankNum) {
- if($m+$j>$lan) {
- $m = $m+$j;
- $tail = $new;
- // $lenght = iconv("UTF-8", "GBK//IGNORE", $new);
- $k = $A - mb_strwidth($new,'utf-8');
- for($q=0;$q<$k;$q++){
- $kw3 .= ' ';
- }
- if($m==$j){
- $tail .= $kw3.' '.$price.' '.$num.' '.$prices;
- }else{
- $tail .= $kw3.'
';
- }
- break;
- }else{
- $next_new = mb_substr($str,$m,$j,'utf-8');
- if(mb_strwidth($next_new,'utf-8')<$blankNum) continue;
- else{
- $m = $i+1;
- $result[] = $new;
- $j=1;
- }
- }
- }
- }
- $head = '';
- foreach ($result as $key=>$value) {
- if($key < 1){
- // $v_lenght = iconv("UTF-8", "GBK//IGNORE", $value);
- $v_lenght = mb_strwidth($value,'utf-8');
- if($v_lenght == 13) $value = $value." ";
- $head .= $value.' '.$price.' '.$num.' '.$prices;
- }else{
- $head .= $value.'
';
- }
- }
- $orderInfo .= $head.$tail;
- if(!empty($v5['o_note'])){
- $orderInfo .= '备注:'.$v5['o_note'].'
';
+ foreach ($arr->orders as $k5 => $order) {
+ $orderInfo .= '
';
+ $shopnum++;
+ $orderInfo .= "(" . $shopnum . ")" .$order->store->name . '
';
+ foreach ($order['orderGoods'] as $goods){
+ $orderInfo .= str_pad($goods->number,$A,' ',STR_PAD_RIGHT);
+ $nameLength = mb_strwidth($goods->name,'utf-8');
+ $orderInfo .= str_pad($goods->name,$B+$nameLength,' ',STR_PAD_RIGHT);
+ $orderInfo .= str_pad($goods->price,$C,' ',STR_PAD_LEFT);
+ $orderInfo .= str_pad(bcmul($goods->number,$goods->price,2),$D,' ',STR_PAD_LEFT);
+ }
+ if(!empty($order->note)){
+ $note = '备注:'.$order->note;
+
+ // $noteLength = mb_strwidth($note);
+ // $noteTime = ceil($noteLength/32);
+ // $noteArr = $this->mb_str_split($note,$length);
+ // var_dump($noteArr,$noteTime);
+ // for ($i = 0;$i <= count($noteArr);$i++){
+ // $orderInfo .= str_pad($noteArr[$i],$length,' ',STR_PAD_RIGHT).'
';
+ // }
}
}
- // $time = date('Y-m-d H:i:s', time());
- $orderInfo .= '--------------------------------
';
- if ($arr[0]['services_money'] > 0) {
- $kw5 = '';
- $len = 24 - strlen($arr[0]['services_money']);
- for ($q = 0; $q < $len; $q++) {
- $kw5 .= ' ';
- }
- $orderInfo .= '服务费:' . $kw5 . $arr[0]['services_money'] . '
';
- }
- if($arr[0]['delivery_money'] > 0){
- $kw5 = '';
- $len = 24 - strlen($arr[0]['delivery_money']);
- for ($q = 0; $q < $len; $q++) {
- $kw5 .= ' ';
- }
- $orderInfo .= '配送费:'.$kw5.$arr[0]['delivery_money'].'
';
- }
- if($arr[0]['coupon_money'] > 0){
- $coupon_money = sprintf("%.2f",$arr[0]['coupon_money']);
- $kw6 = '';
- $len = 25 - strlen($coupon_money);
- for ($q = 0; $q < $len; $q++) {
- $kw6 .= ' ';
- }
- $orderInfo .= '红包:'.$kw6.'-'.$coupon_money.'
';
- }
- $total = '合计:'.$arr[0]['m_money'];
- $user_name = $arr[0]['user_name'];
- if(strlen($user_name)>18){
- $user_name=substr($user_name,0,18).'...';
- }
- $str = $user_name . $total;
- $kw5 = '';
- // $lenght = iconv("UTF-8", "GBK//IGNORE", $str);
- $total_len = 32 - mb_strwidth($str,'utf-8');
- for ($q = 0; $q < $total_len; $q++) {
- $kw5 .= ' ';
- }
- $total_str = $user_name.$kw5.$total;
- $orderInfo .= $total_str.'
';
- $orderInfo .= '送货地点:' . $arr[0]['address'] . '
';
- $tel = substr_replace( $arr[0]['tel'], '****', 3, 4);
- $orderInfo .= '联系电话:' . $tel . '
';
- $orderInfo .= '配送时间:' . $arr[0]['ps_time'] . '
';
- if(!empty($arr[0]['note'])){
- $orderInfo .= '备注:'.$arr[0]['note'].'
';
- }
+ // $name = $v5['name'];
+ // $name .= "(规格:". $v5['goods_unit'].")";
+ // $price = $v5['m_money'];
+ // $num = $v5['number'];
+ // $prices = sprintf("%.2f",$v5['m_money']*$v5['number']);
+ // $kw3 = '';
+ // $kw1 = '';
+ // $kw2 = '';
+ // $kw4 = '';
+ // $str = $name;
+ // $blankNum = $A;//名称控制为14个字节
+ // $lan = mb_strlen($str,'utf-8');
+ // $m = 0;
+ // $j=1;
+ // $blankNum++;
+ // $result = array();
+ // if(strlen($price) < $B){
+ // $k1 = $B - strlen($price);
+ // for($q=0;$q<$k1;$q++){
+ // $kw1 .= ' ';
+ // }
+ // $price = $kw1.$price;
+ // }
+ // if(strlen($num) < $C){
+ // $k2 = $C - strlen($num);
+ // for($q=0;$q<$k2;$q++){
+ // $kw2 .= ' ';
+ // }
+ // $num = $kw2.$num;
+ // }
+ // if(strlen($prices) < $D){
+ // $k3 = $D - strlen($prices);
+ // for($q=0;$q<$k3;$q++){
+ // $kw4 .= ' ';
+ // }
+ // $prices = $kw4.$prices;
+ // }
+ // for ($i=0;$i<$lan;$i++){
+ // $new = mb_substr($str,$m,$j,'utf-8');
+ // $j++;
+ // if(mb_strwidth($new,'utf-8')<$blankNum) {
+ // if($m+$j>$lan) {
+ // $m = $m+$j;
+ // $tail = $new;
+ // // $lenght = iconv("UTF-8", "GBK//IGNORE", $new);
+ // $k = $A - mb_strwidth($new,'utf-8');
+ // for($q=0;$q<$k;$q++){
+ // $kw3 .= ' ';
+ // }
+ // if($m==$j){
+ // $tail .= $kw3.' '.$price.' '.$num.' '.$prices;
+ // }else{
+ // $tail .= $kw3.'
';
+ // }
+ // break;
+ // }else{
+ // $next_new = mb_substr($str,$m,$j,'utf-8');
+ // if(mb_strwidth($next_new,'utf-8')<$blankNum) continue;
+ // else{
+ // $m = $i+1;
+ // $result[] = $new;
+ // $j=1;
+ // }
+ // }
+ // }
+ // }
+ // $head = '';
+ // foreach ($result as $key=>$value) {
+ // if($key < 1){
+ // // $v_lenght = iconv("UTF-8", "GBK//IGNORE", $value);
+ // $v_lenght = mb_strwidth($value,'utf-8');
+ // if($v_lenght == 13) $value = $value." ";
+ // $head .= $value.' '.$price.' '.$num.' '.$prices;
+ // }else{
+ // $head .= $value.'
';
+ // }
+ // }
+ // $orderInfo .= $head.$tail;
+ // if(!empty($v5['o_note'])){
+ // $orderInfo .= '备注:'.$v5['o_note'].'
';
+ // }
+ // }
+ // // $time = date('Y-m-d H:i:s', time());
+ // $orderInfo .= '--------------------------------
';
+ // if ($arr[0]['services_money'] > 0) {
+ // $kw5 = '';
+ // $len = 24 - strlen($arr[0]['services_money']);
+ // for ($q = 0; $q < $len; $q++) {
+ // $kw5 .= ' ';
+ // }
+ // $orderInfo .= '服务费:' . $kw5 . $arr[0]['services_money'] . '
';
+ // }
+ // if($arr[0]['delivery_money'] > 0){
+ // $kw5 = '';
+ // $len = 24 - strlen($arr[0]['delivery_money']);
+ // for ($q = 0; $q < $len; $q++) {
+ // $kw5 .= ' ';
+ // }
+ // $orderInfo .= '配送费:'.$kw5.$arr[0]['delivery_money'].'
';
+ // }
+ // if($arr[0]['coupon_money'] > 0){
+ // $coupon_money = sprintf("%.2f",$arr[0]['coupon_money']);
+ // $kw6 = '';
+ // $len = 25 - strlen($coupon_money);
+ // for ($q = 0; $q < $len; $q++) {
+ // $kw6 .= ' ';
+ // }
+ // $orderInfo .= '红包:'.$kw6.'-'.$coupon_money.'
';
+ // }
+ // $total = '合计:'.$arr[0]['m_money'];
+ // $user_name = $arr[0]['user_name'];
+ // if(strlen($user_name)>18){
+ // $user_name=substr($user_name,0,18).'...';
+ // }
+ // $str = $user_name . $total;
+ // $kw5 = '';
+ // // $lenght = iconv("UTF-8", "GBK//IGNORE", $str);
+ // $total_len = 32 - mb_strwidth($str,'utf-8');
+ // for ($q = 0; $q < $total_len; $q++) {
+ // $kw5 .= ' ';
+ // }
+ // $total_str = $user_name.$kw5.$total;
+ // $orderInfo .= $total_str.'
';
+ // $orderInfo .= '送货地点:' . $arr[0]['address'] . '
';
+ // $tel = substr_replace( $arr[0]['tel'], '****', 3, 4);
+ // $orderInfo .= '联系电话:' . $tel . '
';
+ // $orderInfo .= '配送时间:' . $arr[0]['ps_time'] . '
';
+ // if(!empty($arr[0]['note'])){
+ // $orderInfo .= '备注:'.$arr[0]['note'].'
';
+ // }
//$orderInfo .= 'http://www.feieyun.com';//把解析后的二维码生成的字符串用标签套上即可自动生成二维码
return $orderInfo;
}
+
}
\ No newline at end of file
diff --git a/config/routes.php b/config/routes.php
index afa19de..ed61c59 100644
--- a/config/routes.php
+++ b/config/routes.php
@@ -93,6 +93,7 @@ Router::addGroup('/v3/', function () {
Router::post('Search/market', 'App\Controller\v3\SearchController@market');
Router::post('market/services', 'App\Controller\v3\LocationController@getMarketsInfo');
Router::post('home/aboutLanzu', 'App\Controller\v3\HomeController@aboutLanzu');
+ Router::post('test/index', 'App\Controller\v3\TestController@index');
},['middleware' => [\App\Middleware\Auth\ApiMiddleware::class]]);
// 需要登录的路由