DefaultTemplate.php 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363
  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 addons\Printer\common\logic\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->ticket_nam);
  23. $content .= $printer->getCenterBold($data->mall_name);
  24. $content .= $printer->getBR("订单类型:{$data->order_type}");
  25. $content .= $printer->getBR("支付方式:{$data->payment_type}");
  26. $content .= $printer->getBR("发货方式:{$data->shippingTypText}");
  27. $content .= $printer->getBR("订单号:{$data->order_no}");
  28. $content .= $printer->getBR("下单时间:{$data->created_at}");
  29. $content .= $printer->getDivide();
  30. if ($data->is_attr == 0) {
  31. $content .= $printer->getTableNoAttr($data);
  32. } else {
  33. $content .= $printer->getTableAttr($data);
  34. }
  35. $content .= $printer->getDivide();
  36. $content .= $printer->getBR("商品总计:" . $printer->getPrice($data->original_goods_price));
  37. if (isset($data->send_type)&&$data->send_type == 0) {
  38. $content .= $printer->getBR("运费:" . $printer->getPrice($data->shipping_money));
  39. }
  40. if (isset($data->coupon_money) && $data->coupon_money) {
  41. $content .= $printer->getBR("优惠券优惠:" . $printer->getPrice($data->coupon_money));
  42. }
  43. if (isset($data->score_money) && $data->score_money) {
  44. $content .= $printer->getBR("积分抵扣:" . $printer->getPrice($data->score_money));
  45. }
  46. if (isset($data->member_discount_price) && $data->member_discount_price) {
  47. $content .= $printer->getBR("会员优惠:" . $printer->getPrice($data->member_discount_price));
  48. }
  49. if ($data->back_price < 0) {
  50. $subPrice = round(abs($data->back_price), 2);
  51. $content .= $printer->getBR("后台改价:" . $printer->getPrice($subPrice));
  52. } elseif ($data->back_price > 0) {
  53. $subPrice = round(abs($data->back_price), 2);
  54. $content .= $printer->getBR("后台改价:" . $printer->getPrice($subPrice));
  55. }
  56. if (count($data->plugin_data) > 0) {
  57. foreach ($data->plugin_data as $datum) {
  58. $content .= $printer->getBR($datum['label'] . $printer->getPrice($datum['value']));
  59. }
  60. }
  61. $content .= $printer->getBR("实际支付:" . $printer->getPrice($data->pay_money));
  62. $content .= $printer->getDivide();
  63. if (isset($data->send_type)&&$data->send_type != 1) {
  64. $content .= $printer->getBR("收货人:{$data->receiver_name}");
  65. $content .= $printer->getBR("收货地址:{$data->address}");
  66. $content .= $printer->getBR("收货人电话:{$data->mobile}");
  67. $content .= $data->remark ? $printer->getDivide() : '';
  68. } else {
  69. $content .= $printer->getBR("联系人:{$data->receiver_name}");
  70. $content .= $printer->getBR("联系人电话:{$data->receiver_name}");
  71. $content .= $printer->getDivide();
  72. $content .= $printer->getBR("门店信息");
  73. $content .= $printer->getBR("{$data->store_name}");
  74. $content .= $printer->getBR("{$data->store_mobile}");
  75. $content .= $printer->getBR("{$data->store_address}");
  76. $content .= $data->remark ? $printer->getDivide() : '';
  77. }
  78. $content .= $printer->getRemarkText("备注:{$data->remark}");
  79. return $content;
  80. }
  81. public function getContentByArray()
  82. {
  83. $printer = $this->printer;
  84. $data = $this->data;
  85. $content = [
  86. [
  87. 'handle' => 'times',
  88. 'content' => ''
  89. ],
  90. [
  91. 'handle' => 'centerBold',
  92. 'content' => $data->ticket_nam,
  93. 'show' => $data->ticket_nam ? 1 : 0
  94. ],
  95. [
  96. 'handle' => 'centerBold',
  97. 'content' => $data->mall_name
  98. ],
  99. [
  100. 'handle' => 'bR',
  101. 'content' => '订单类型:' . $data->order_type
  102. ],
  103. [
  104. 'handle' => 'bR',
  105. 'content' => '支付方式:' . $data->payment_type
  106. ],
  107. // [
  108. // 'handle' => 'bR',
  109. // 'content' => '发货方式:' . $data->shippingTypText
  110. // ],
  111. [
  112. 'handle' => 'bR',
  113. 'content' => '订单号:' . $data->order_no
  114. ],
  115. [
  116. 'handle' => 'bR',
  117. 'content' => '下单时间:' . $data->created_at
  118. ],
  119. [
  120. 'handle' => 'divide',
  121. 'content' => ''
  122. ],
  123. [
  124. 'handle' => 'tableNoAttr',
  125. 'content' => $data,
  126. 'show' => $data->is_attr == 0 ? 1 : 0
  127. ],
  128. [
  129. 'handle' => 'tableAttr',
  130. 'content' => $data,
  131. 'show' => $data->is_attr == 1 ? 1 : 0
  132. ],
  133. [
  134. 'handle' => 'divide',
  135. 'content' => ''
  136. ],
  137. [
  138. 'handle' => 'bR',
  139. 'children' => [
  140. [
  141. 'handle' => 'price',
  142. 'content' => $data->price
  143. ]
  144. ],
  145. 'content' => '商品总计:'
  146. ],
  147. // [
  148. // 'handle' => 'bR',
  149. // 'children' => [
  150. // [
  151. // 'handle' => 'price',
  152. // 'content' => $data->original_goods_price
  153. // ]
  154. // ],
  155. // 'content' => '商品总计:'
  156. // ],
  157. [
  158. 'handle' => 'bR',
  159. 'children' => [
  160. [
  161. 'handle' => 'price',
  162. 'content' => $data->shipping_money
  163. ]
  164. ],
  165. 'content' => '运费:',
  166. 'show' => isset($data->send_type)&&$data->send_type != 1 ? 1 : 0
  167. ],
  168. [
  169. 'handle' => 'bR',
  170. 'children' => [
  171. [
  172. 'handle' => 'price',
  173. 'content' => $data->coupon_money
  174. ]
  175. ],
  176. 'content' => '优惠券优惠:',
  177. 'show' => $data->coupon_money ? 1 : 0
  178. ],
  179. [
  180. 'handle' => 'bR',
  181. 'children' => [
  182. [
  183. 'handle' => 'price',
  184. 'content' => $data->score_money
  185. ]
  186. ],
  187. 'content' => '积分抵扣:',
  188. 'show' => $data->score_money ? 1 : 0
  189. ],
  190. [
  191. 'handle' => 'bR',
  192. 'children' => [
  193. [
  194. 'handle' => 'price',
  195. 'content' => $data->member_discount_price
  196. ]
  197. ],
  198. 'content' => '会员优惠:',
  199. 'show' => $data->member_discount_price ? 1 : 0
  200. ],
  201. [
  202. 'handle' => 'bR',
  203. 'children' => [
  204. [
  205. 'handle' => 'price',
  206. 'content' => abs($data->back_price)
  207. ]
  208. ],
  209. 'content' => '后台改价:',
  210. 'show' => $data->back_price != 0 ? 1 : 0
  211. ],
  212. ];
  213. if (count($data->plugin_data) > 0) {
  214. foreach ($data->plugin_data as $datum) {
  215. $content[] = [
  216. 'handle' => 'bR',
  217. 'children' => [
  218. [
  219. 'handle' => 'price',
  220. 'content' => $datum['value']
  221. ]
  222. ],
  223. 'content' => $datum['label'] . ':',
  224. 'show' => 1
  225. ];
  226. }
  227. }
  228. $content2 = [
  229. // [
  230. // 'handle' => 'bR',
  231. // 'children' => [
  232. // [
  233. // 'handle' => 'price',
  234. // 'content' => $data->pay_money
  235. // ]
  236. // ],
  237. // 'content' => '实际支付:'
  238. // ],
  239. [
  240. 'handle' => 'divide',
  241. 'content' => ''
  242. ],
  243. [
  244. 'handle' => 'bR',
  245. 'content' => (isset($data->send_type)&&$data->send_type != 1 ? '收货人:' : '联系人:') . $data->receiver_name,
  246. 'show' => $data->is_show_name
  247. ],
  248. [
  249. 'handle' => 'bR',
  250. 'content' => '收货地址' . $data->address,
  251. 'show' => $data->is_show_addr
  252. ],
  253. [
  254. 'handle' => 'bR',
  255. 'content' => (isset($data->send_type)&&$data->send_type != 1 ? '收货人电话:' : '联系人电话:') . $data->mobile,
  256. 'show' => $data->is_show_phone
  257. ],
  258. [
  259. 'handle' => 'divide',
  260. 'content' => ''
  261. ],
  262. // [
  263. // 'handle' => 'bR',
  264. // 'content' => '门店信息',
  265. // 'show' => $data->send_type == 1 ? 1 : 0
  266. // ],
  267. // [
  268. // 'handle' => 'bR',
  269. // 'content' => $data->store_name,
  270. // 'show' => $data->send_type == 1 ? 1 : 0
  271. // ],
  272. // [
  273. // 'handle' => 'bR',
  274. // 'content' => $data->store_mobile,
  275. // 'show' => $data->send_type == 1 ? 1 : 0
  276. // ],
  277. // [
  278. // 'handle' => 'bR',
  279. // 'content' => $data->store_address,
  280. // 'show' => $data->send_type == 1 ? 1 : 0
  281. // ],
  282. // [
  283. // 'handle' => 'divide',
  284. // 'content' => '',
  285. // 'show' => $data->send_type == 1 ? 1 : 0
  286. // ],
  287. [
  288. 'handle' => 'bR',
  289. 'content' => '商家联系方式:' . $data->contact_tel,
  290. 'show' => $data->is_show_mall_phone
  291. ],
  292. [
  293. 'handle' => 'bR',
  294. 'content' => '商家地址:' . $data->quick_map_address,
  295. 'show' => $data->is_show_mall_addr
  296. ],
  297. [
  298. 'handle' => 'divide',
  299. 'content' => '',
  300. 'show' => $data->is_show_mall_phone || $data->is_show_mall_addr
  301. ],
  302. [
  303. 'handle' => 'qr',
  304. 'content' => $data->qrcode_url,
  305. 'show' => $data->is_show_qrcode_url ? 1 : 0
  306. ],
  307. [
  308. 'handle' => 'divide',
  309. 'content' => '',
  310. 'show' => $data->is_show_qrcode_url
  311. ],
  312. [
  313. 'handle' => 'remarkText',
  314. 'content' => '备注:' . $data->remark,
  315. 'show' => $data->is_show_remark
  316. ],
  317. [
  318. 'handle' => 'remarkText',
  319. 'content' => '商家留言:' . $data->seller_remark,
  320. 'show' => $data->is_show_seller_remark ? 1 : 0
  321. ],
  322. [
  323. 'handle' => 'divide',
  324. 'content' => '',
  325. 'show' => $data->is_show_remark || $data->is_show_seller_remark
  326. ],
  327. [
  328. 'handle' => 'qr',
  329. 'content' => $data->mall_qrcode_url,
  330. 'show' => $data->is_show_mall_code
  331. ],
  332. [
  333. 'handle' => 'CenterBold',
  334. 'content' => $data->bottom_info,
  335. 'show' => $data->bottom_info ? 1 : 0
  336. ],
  337. ];
  338. $content = array_merge($content, $content2);//dd($data->order_form);
  339. // foreach ($data->order_form as $ofItem) {
  340. // if (isset($ofItem['key']) && $ofItem['key'] == 'text' || $ofItem['key'] == 'textarea') {
  341. // $label = isset($ofItem['label']) ? $ofItem['label'] : '';
  342. // $value = isset($ofItem['value']) ? $ofItem['value'] : '';
  343. //
  344. // $content[] = [
  345. // 'handle' => 'remarkText',
  346. // 'content' => "{$label}:" . $value,
  347. // 'show' => $label && $value ? 1 : 0,
  348. // ];
  349. // }
  350. // }
  351. // 执行效果同getContent
  352. return $content;
  353. }
  354. }