DefaultTemplate.php 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310
  1. <?php
  2. /**
  3. * @link:http://www.gdqijianshi.com/
  4. * @copyright: Copyright (c) 2020 广东七件事集团
  5. * Created by PhpStorm
  6. * Author: zal
  7. * Date: 2020-04-01
  8. * Time: 21:49
  9. */
  10. namespace common\helpers\printer\templates;
  11. /**
  12. * Class FirstTemplate
  13. * @package common\helpers\printer\prints\templates
  14. */
  15. class DefaultTemplate extends BaseTemplate
  16. {
  17. public function getContent()
  18. {
  19. $data = $this->data;
  20. $printer = $this->printer;
  21. $content = $printer->getTimes();
  22. $content .= $printer->getCenterBold($data->mall_name);
  23. $content .= $printer->getBR("订单类型:{$data->order_type}");
  24. $content .= $printer->getBR("支付方式:{$data->payment_type}");
  25. $content .= $printer->getBR("发货方式:{$data->shippingTypText}");
  26. $content .= $printer->getBR("订单号:{$data->order_no}");
  27. $content .= $printer->getBR("下单时间:{$data->created_at}");
  28. $content .= $printer->getDivide();
  29. if ($data->is_attr == 0) {
  30. $content .= $printer->getTableNoAttr($data);
  31. } else {
  32. $content .= $printer->getTableAttr($data);
  33. }
  34. $content .= $printer->getDivide();
  35. $content .= $printer->getBR("商品总计:" . $printer->getPrice($data->original_goods_price));
  36. if ($data->send_type == 0) {
  37. $content .= $printer->getBR("运费:" . $printer->getPrice($data->shipping_money));
  38. }
  39. if (isset($data->coupon_money) && $data->coupon_money) {
  40. $content .= $printer->getBR("优惠券优惠:" . $printer->getPrice($data->coupon_money));
  41. }
  42. if (isset($data->score_money) && $data->score_money) {
  43. $content .= $printer->getBR("积分抵扣:" . $printer->getPrice($data->score_money));
  44. }
  45. if (isset($data->member_discount_price) && $data->member_discount_price) {
  46. $content .= $printer->getBR("会员优惠:" . $printer->getPrice($data->member_discount_price));
  47. }
  48. if ($data->back_price < 0) {
  49. $subPrice = round(abs($data->back_price), 2);
  50. $content .= $printer->getBR("后台改价:" . $printer->getPrice($subPrice));
  51. } elseif ($data->back_price > 0) {
  52. $subPrice = round(abs($data->back_price), 2);
  53. $content .= $printer->getBR("后台改价:" . $printer->getPrice($subPrice));
  54. }
  55. if (count($data->plugin_data) > 0) {
  56. foreach ($data->plugin_data as $datum) {
  57. $content .= $printer->getBR($datum['label'] . $printer->getPrice($datum['value']));
  58. }
  59. }
  60. $content .= $printer->getBR("实际支付:" . $printer->getPrice($data->pay_money));
  61. $content .= $printer->getDivide();
  62. if ($data->send_type != 1) {
  63. $content .= $printer->getBR("收货人:{$data->receiver_name}");
  64. $content .= $printer->getBR("收货地址:{$data->address}");
  65. $content .= $printer->getBR("收货人电话:{$data->mobile}");
  66. $content .= $printer->getDivide();
  67. } else {
  68. $content .= $printer->getBR("联系人:{$data->receiver_name}");
  69. $content .= $printer->getBR("联系人电话:{$data->receiver_name}");
  70. $content .= $printer->getDivide();
  71. $content .= $printer->getBR("门店信息");
  72. $content .= $printer->getBR("{$data->store_name}");
  73. $content .= $printer->getBR("{$data->store_mobile}");
  74. $content .= $printer->getBR("{$data->store_address}");
  75. $content .= $printer->getDivide();
  76. }
  77. if ($data->remark) {
  78. $content .= $printer->getRemarkText("备注:{$data->remark}");
  79. } else {
  80. foreach ($data->order_form as $ofItem) {
  81. if (isset($ofItem['key']) && $ofItem['key'] == 'text' || $ofItem['key'] == 'textarea') {
  82. $label = isset($ofItem['label']) ? $ofItem['label'] : '';
  83. $value = isset($ofItem['value']) ? $ofItem['value'] : '';
  84. if ($label && $value) {
  85. $content .= $printer->getRemarkText("{$label}:{$value}");
  86. }
  87. }
  88. }
  89. }
  90. return $content;
  91. }
  92. public function getContentByArray()
  93. {
  94. $data = $this->data;
  95. $content = [
  96. [
  97. 'handle' => 'times',
  98. 'content' => ''
  99. ],
  100. [
  101. 'handle' => 'centerBold',
  102. 'content' => $data->mall_name
  103. ],
  104. [
  105. 'handle' => 'bR',
  106. 'content' => '订单类型:' . $data->order_type
  107. ],
  108. [
  109. 'handle' => 'bR',
  110. 'content' => '支付方式:' . $data->payment_type
  111. ],
  112. [
  113. 'handle' => 'bR',
  114. 'content' => '发货方式:' . $data->shippingTypText
  115. ],
  116. [
  117. 'handle' => 'bR',
  118. 'content' => '订单号:' . $data->order_no
  119. ],
  120. [
  121. 'handle' => 'bR',
  122. 'content' => '下单时间:' . $data->created_at
  123. ],
  124. [
  125. 'handle' => 'divide',
  126. 'content' => ''
  127. ],
  128. [
  129. 'handle' => 'tableNoAttr',
  130. 'content' => $data,
  131. 'show' => $data->is_attr == 0 ? 1 : 0
  132. ],
  133. [
  134. 'handle' => 'tableAttr',
  135. 'content' => $data,
  136. 'show' => $data->is_attr == 1 ? 1 : 0
  137. ],
  138. [
  139. 'handle' => 'divide',
  140. 'content' => ''
  141. ],
  142. [
  143. 'handle' => 'bR',
  144. 'children' => [
  145. [
  146. 'handle' => 'price',
  147. 'content' => $data->original_goods_price
  148. ]
  149. ],
  150. 'content' => '商品总计:'
  151. ],
  152. [
  153. 'handle' => 'bR',
  154. 'children' => [
  155. [
  156. 'handle' => 'price',
  157. 'content' => $data->shipping_money
  158. ]
  159. ],
  160. 'content' => '运费:',
  161. 'show' => $data->send_type != 1 ? 1 : 0
  162. ],
  163. [
  164. 'handle' => 'bR',
  165. 'children' => [
  166. [
  167. 'handle' => 'price',
  168. 'content' => $data->coupon_money
  169. ]
  170. ],
  171. 'content' => '优惠券优惠:',
  172. 'show' => $data->coupon_money ? 1 : 0
  173. ],
  174. [
  175. 'handle' => 'bR',
  176. 'children' => [
  177. [
  178. 'handle' => 'price',
  179. 'content' => $data->score_money
  180. ]
  181. ],
  182. 'content' => '积分抵扣:',
  183. 'show' => $data->score_money ? 1 : 0
  184. ],
  185. [
  186. 'handle' => 'bR',
  187. 'children' => [
  188. [
  189. 'handle' => 'price',
  190. 'content' => $data->member_discount_price
  191. ]
  192. ],
  193. 'content' => '会员优惠:',
  194. 'show' => $data->member_discount_price ? 1 : 0
  195. ],
  196. [
  197. 'handle' => 'bR',
  198. 'children' => [
  199. [
  200. 'handle' => 'price',
  201. 'content' => abs($data->back_price)
  202. ]
  203. ],
  204. 'content' => '后台改价:',
  205. 'show' => $data->back_price != 0 ? 1 : 0
  206. ],
  207. ];
  208. if (count($data->plugin_data) > 0) {
  209. foreach ($data->plugin_data as $datum) {
  210. $content[] = [
  211. 'handle' => 'bR',
  212. 'children' => [
  213. [
  214. 'handle' => 'price',
  215. 'content' => $datum['value']
  216. ]
  217. ],
  218. 'content' => $datum['label'] . ':',
  219. 'show' => 1
  220. ];
  221. }
  222. }
  223. $content2 = [
  224. [
  225. 'handle' => 'bR',
  226. 'children' => [
  227. [
  228. 'handle' => 'price',
  229. 'content' => $data->pay_money
  230. ]
  231. ],
  232. 'content' => '实际支付:'
  233. ],
  234. [
  235. 'handle' => 'divide',
  236. 'content' => ''
  237. ],
  238. [
  239. 'handle' => 'bR',
  240. 'content' => ($data->send_type != 1 ? '收货人:' : '联系人:') . $data->receiver_name
  241. ],
  242. [
  243. 'handle' => 'bR',
  244. 'content' => '收货地址' . $data->address,
  245. 'show' => $data->send_type != 1 ? 1 : 0
  246. ],
  247. [
  248. 'handle' => 'bR',
  249. 'content' => ($data->send_type != 1 ? '收货人电话:' : '联系人电话:') . $data->mobile
  250. ],
  251. [
  252. 'handle' => 'divide',
  253. 'content' => ''
  254. ],
  255. [
  256. 'handle' => 'bR',
  257. 'content' => '门店信息',
  258. 'show' => $data->send_type == 1 ? 1 : 0
  259. ],
  260. [
  261. 'handle' => 'bR',
  262. 'content' => $data->store_name,
  263. 'show' => $data->send_type == 1 ? 1 : 0
  264. ],
  265. [
  266. 'handle' => 'bR',
  267. 'content' => $data->store_mobile,
  268. 'show' => $data->send_type == 1 ? 1 : 0
  269. ],
  270. [
  271. 'handle' => 'bR',
  272. 'content' => $data->store_address,
  273. 'show' => $data->send_type == 1 ? 1 : 0
  274. ],
  275. [
  276. 'handle' => 'divide',
  277. 'content' => '',
  278. 'show' => $data->send_type == 1 ? 1 : 0
  279. ],
  280. [
  281. 'handle' => 'remarkText',
  282. 'content' => '备注:' . $data->remark,
  283. 'show' => $data->remark ? 1 : 0
  284. ],
  285. ];
  286. $content = array_merge($content, $content2);//dd($data->order_form);
  287. // foreach ($data->order_form as $ofItem) {
  288. // if (isset($ofItem['key']) && $ofItem['key'] == 'text' || $ofItem['key'] == 'textarea') {
  289. // $label = isset($ofItem['label']) ? $ofItem['label'] : '';
  290. // $value = isset($ofItem['value']) ? $ofItem['value'] : '';
  291. //
  292. // $content[] = [
  293. // 'handle' => 'remarkText',
  294. // 'content' => "{$label}:" . $value,
  295. // 'show' => $label && $value ? 1 : 0,
  296. // ];
  297. // }
  298. // }
  299. // 执行效果同getContent
  300. return $content;
  301. }
  302. }