StorePrinterRepository.php 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
  4. // +----------------------------------------------------------------------
  5. // | Copyright (c) 2016~2024 https://www.crmeb.com All rights reserved.
  6. // +----------------------------------------------------------------------
  7. // | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
  8. // +----------------------------------------------------------------------
  9. // | Author: CRMEB Team <admin@crmeb.com>
  10. // +----------------------------------------------------------------------
  11. namespace app\common\repositories\store;
  12. use app\common\dao\store\StorePrinterDao;
  13. use app\common\repositories\BaseRepository;
  14. use crmeb\services\printer\Printer;
  15. use FormBuilder\Factory\Elm;
  16. use think\exception\ValidateException;
  17. use think\facade\Route;
  18. class StorePrinterRepository extends BaseRepository
  19. {
  20. public function __construct(StorePrinterDao $dao)
  21. {
  22. $this->dao = $dao;
  23. }
  24. /**
  25. * 创建或修改打印机表单
  26. *
  27. * 此方法用于生成用于添加或修改打印机的表单。根据$id$的存在与否,决定是创建新打印机还是修改已有的打印机。
  28. * 表单包含打印机的基本信息输入字段和一个选择打印机类型的选项,根据选择的打印机类型,显示不同的输入字段。
  29. *
  30. * @param int|null $id 打印机的ID。如果提供了ID,则表示修改现有打印机;如果为null,则表示创建新打印机。
  31. * @return \EasyWeChat\Kernel\Messages\Form|\FormBuilder\Form
  32. */
  33. public function form(?int $id)
  34. {
  35. // 根据$id$的存在与否决定是获取现有打印机的数据还是创建空的数据数组
  36. if ($id) {
  37. $formData = $this->dao->get($id)->toArray();
  38. $formActionUrl = Route::buildUrl('merchantStorePrinterUpdate', ['id' => $id])->build();
  39. } else {
  40. $formData = [];
  41. $formActionUrl = Route::buildUrl('merchantStorePrinterCreate')->build();
  42. }
  43. // 定义易联云打印机的表单字段
  44. $yun = [
  45. Elm::input('printer_name', '打印机名称:')->placeholder('请输入打印机名称')->required(),
  46. Elm::input('printer_appkey', '应用ID:')->placeholder('请输入应用ID')->required(),
  47. Elm::input('printer_appid', '用户ID:')->placeholder('请输入用户ID')->required(),
  48. Elm::input('printer_secret', '应用密匙:')->placeholder('请输入应用密匙')->required(),
  49. Elm::input('printer_terminal', '终端号:')->placeholder('请输入打印机终端号')->required()->appendRule('suffix', [
  50. 'type' => 'div',
  51. 'style' => ['color' => '#999999'],
  52. 'domProps' => [
  53. 'innerHTML' => '易联云打印机终端号打印机型号: 易联云打印机 K4无线版',
  54. ]
  55. ]),
  56. Elm::number('times', '打印联数:', 1)->min(1)->placeholder('请输入打印联数')->required(),
  57. Elm::radio('print_type', '打印时机:', 1)
  58. ->setOptions([
  59. ['value' => 1, 'label' => '支付后'],
  60. ['value' => 2, 'label' => '下单后'],
  61. ]),
  62. Elm::switches('status', '是否开启:', 1)->inactiveValue(0)->activeValue(1)->inactiveText('关')->activeText('开')
  63. ];
  64. // 定义飞鹅云打印机的表单字段
  65. $fei = [
  66. Elm::input('printer_name', '打印机名称:')->placeholder('请输入打印机名称')->required(),
  67. Elm::input('printer_appid', 'USER:')->placeholder('请输入USER')->required()->appendRule('suffix', [
  68. 'type' => 'div',
  69. 'style' => ['color' => '#999999'],
  70. 'domProps' => [
  71. 'innerHTML' => '飞鹅云后台注册账号',
  72. ]
  73. ]),
  74. Elm::input('printer_appkey', 'UKEY:')->placeholder('请输入UKEY')->required()->appendRule('suffix', [
  75. 'type' => 'div',
  76. 'style' => ['color' => '#999999'],
  77. 'domProps' => [
  78. 'innerHTML' => '飞鹅云后台注册账号后生成的UKEY 【备注:这不是填打印机的KEY】',
  79. ]
  80. ]),
  81. Elm::input('printer_terminal', '飞鹅云SN:')->placeholder('请输入飞鹅云打印机SN')->required()->appendRule('suffix', [
  82. 'type' => 'div',
  83. 'style' => ['color' => '#999999'],
  84. 'domProps' => [
  85. 'innerHTML' => '打印机标签上的编号,必须要在管理后台里添加打印机或调用API接口添加之后,才能调用API',
  86. ]
  87. ]),
  88. Elm::number('times', '打印联数:', 1)->min(1)->placeholder('请输入打印联数')->required(),
  89. Elm::radio('print_type', '打印时机:', 1)
  90. ->setOptions([
  91. ['value' => 1, 'label' => '支付后'],
  92. ['value' => 2, 'label' => '下单后'],
  93. ]),
  94. Elm::switches('status', '是否开启:', 1)->inactiveValue(0)->activeValue(1)->inactiveText('关')->activeText('开')
  95. ];
  96. // 根据打印机类型设置表单规则,包括易联云和飞鹅云两种类型的字段集合
  97. $form = Elm::createForm($formActionUrl);
  98. $form->setRule([
  99. Elm::radio('type', '打印机类型:', 0)
  100. ->setOptions([
  101. ['value' => 0, 'label' => '易联云打印机'],
  102. ['value' => 1, 'label' => '飞鹅云打印机'],
  103. ])->control([
  104. ['value' => 0, 'rule' => $yun],
  105. ['value' => 1, 'rule' => $fei]
  106. ]),
  107. ]);
  108. // 设置表单标题和初始数据,返回表单对象
  109. return $form->setTitle($id ? '修改打印机' : '添加打印机')->formData($formData);
  110. }
  111. /**
  112. * 获取商家列表
  113. *
  114. * 本函数用于根据条件查询商家信息,并支持分页查询。它接收查询条件、页码和每页的数量作为参数,
  115. * 返回包含商家数量和商家列表的数组。
  116. *
  117. * @param array $where 查询条件,以数组形式传递,用于指定查询的过滤条件。
  118. * @param int $page 当前页码,用于指定要返回的页码。
  119. * @param int $limit 每页的数量,用于指定每页返回的商家数量。
  120. * @return array 返回包含 'count' 和 'list' 两个元素的数组,'count' 为商家总数,'list' 为商家列表。
  121. */
  122. public function merList(array $where, int $page, int $limit)
  123. {
  124. // 根据查询条件获取查询对象
  125. $query = $this->dao->getSearch($where)->order('create_time DESC');
  126. // 计算满足条件的商家总数
  127. $count = $query->count();
  128. // 根据当前页码和每页的数量进行分页查询,并获取商家列表
  129. $list = $query->page($page, $limit)->select();
  130. // 将商家总数和商家列表打包成数组返回
  131. return compact('count', 'list');
  132. }
  133. /**
  134. * 系统列表查询方法
  135. * 用于根据条件获取系统列表的数据,支持分页查询
  136. *
  137. * @param array $where 查询条件数组
  138. * @param int $page 当前页码
  139. * @param int $limit 每页数据条数
  140. * @return array 返回包含数据总数和数据列表的数组
  141. */
  142. public function sysList(array $where, int $page, int $limit)
  143. {
  144. // 根据查询条件构造查询对象,并指定关联查询时 merchant 表只返回 mer_id 和 mer_name 两个字段
  145. $query = $this->dao->getSearch($where)->with([
  146. 'merchant' => function ($query) {
  147. $query->field('mer_id,mer_name');
  148. },
  149. ]);
  150. // 计算满足条件的数据总数
  151. $count = $query->count();
  152. // 根据当前页码和每页数据条数进行分页查询,并获取数据列表
  153. $list = $query->page($page, $limit)->select();
  154. // 将数据总数和数据列表一起返回
  155. return compact('count', 'list');
  156. }
  157. /**
  158. * 检查打印机配置
  159. *
  160. * 本函数用于验证商家的打印机配置是否完整且正确。它首先检查打印功能是否已开启,然后获取并验证相关配置参数,
  161. * 包括客户端ID、API密钥、合作伙伴ID和终端号码。如果任何一项配置缺失或无效,将抛出一个验证异常。
  162. *
  163. * @param int $merId 商家ID,用于获取商家的打印配置
  164. * @return array 返回包含打印机配置的数组,包括客户端ID、API密钥、合作伙伴ID和终端号码
  165. * @throws ValidateException 如果打印功能未开启或打印机配置不完整或无效,抛出此异常
  166. */
  167. public function checkPrinterConfig(int $merId)
  168. {
  169. // 检查打印功能是否已开启
  170. if (!merchantConfig($merId, 'printing_status'))
  171. throw new ValidateException('打印功能未开启');
  172. // 组装打印机配置数组
  173. $config = [
  174. 'clientId' => merchantConfig($merId, 'printing_client_id'),
  175. 'apiKey' => merchantConfig($merId, 'printing_api_key'),
  176. 'partner' => merchantConfig($merId, 'develop_id'),
  177. 'terminal' => merchantConfig($merId, 'terminal_number')
  178. ];
  179. // 验证打印机配置是否完整
  180. if (!$config['clientId'] || !$config['apiKey'] || !$config['partner'] || !$config['terminal'])
  181. throw new ValidateException('打印机配置错误');
  182. // 返回验证通过的打印机配置
  183. return $config;
  184. }
  185. /**
  186. * 根据商家ID获取打印机配置信息
  187. *
  188. * 本函数用于根据传入的商家ID,从数据库中查询该商家的打印机配置信息。
  189. * 如果商家未配置打印机或打印机配置无效,则会尝试从商家配置中获取相关信息。
  190. * 如果所有尝试都失败,则会抛出一个异常,提示打印功能未开启或未添加打印机。
  191. *
  192. * @param int $merId 商家ID,用于查询特定商家的打印机配置。
  193. * @return array 返回包含打印机配置信息的数组,每个元素代表一个打印机的配置。
  194. * @throws ValidateException 如果打印功能未开启或未添加打印机,则抛出此异常。
  195. */
  196. public function getPrinter(int $merId)
  197. {
  198. // 检查商家的打印功能是否开启,如果未开启则抛出异常
  199. if (!merchantConfig($merId, 'printing_status'))
  200. throw new ValidateException('打印功能未开启');
  201. // 从数据库中查询商家ID为$merId且状态为1的打印机配置,返回type, clientId, terminal, partner, apiKey列
  202. $res = $this->dao->getSearch(['mer_id' => $merId, 'status' => 1])->column('
  203. type,
  204. printer_appkey clientId,
  205. printer_terminal terminal,
  206. printer_appid partner,
  207. printer_secret apiKey
  208. ');
  209. // 如果查询结果为空,则尝试从商家配置中获取打印机配置信息
  210. if (!$res) {
  211. $config = [
  212. 'clientId' => merchantConfig($merId, 'printing_client_id'),
  213. 'apiKey' => merchantConfig($merId, 'printing_api_key'),
  214. 'partner' => merchantConfig($merId, 'develop_id'),
  215. 'terminal' => merchantConfig($merId, 'terminal_number')
  216. ];
  217. // 如果商家配置中存在不完整的打印机配置,则将该配置添加到查询结果中
  218. if (!$config['clientId'] || !$config['apiKey'] || !$config['partner'] || !$config['terminal']) {
  219. $res[] = $config;
  220. }
  221. }
  222. // 如果最终仍未能获取到有效的打印机配置,则抛出异常
  223. if (!$res) throw new ValidateException('请添加打印机');
  224. // 返回获取到的打印机配置信息
  225. return $res;
  226. }
  227. public function startPrint($merId, $order, $product, $print_type = 1)
  228. {
  229. $where = ['mer_id' => $merId, 'status' => 1];
  230. if (!is_null($print_type)) $where['print_type'] = $print_type;
  231. $list = $this->dao->getSearch([])->where($where)->select();
  232. foreach ($list as $item) {
  233. $content = '';
  234. if ($item['type'] == 0) { //易联云
  235. $name = 'yi_lian_yun';
  236. $configData = [
  237. 'partner' => $item['printer_appid'],
  238. 'clientId' => $item['printer_appkey'],
  239. 'apiKey' => $item['printer_secret'],
  240. 'terminal' => $item['printer_terminal'],
  241. 'type' => 0,
  242. ];
  243. $content = $this->ylyContent(json_decode($item['print_content'], true), $order, $product, $item['times'], $print_type);
  244. } else { //飞鹅云
  245. $name = 'fei_e_yun';
  246. $configData = [
  247. 'partner' => $item['printer_appid'],
  248. 'clientId' => $item['printer_appkey'],
  249. 'terminal' => $item['printer_terminal'],
  250. 'type' => 1,
  251. ];
  252. $content = $this->feyContent(json_decode($item['print_content'], true), $order, $product, $print_type);
  253. }
  254. $printer = new Printer($name, $configData);
  255. if ($content){
  256. $printer->setPrinterContent($content, $item['times'])->startPrinter();
  257. }
  258. }
  259. }
  260. public function ylyContent($printContent, $orderInfo, $product, $times, $print_type)
  261. {
  262. $goodsStr = '<table><tr><td>商品</td><td>单价</td><td>数量</td><td>金额</td></tr>';
  263. foreach ($product as $item) {
  264. $price = $item['price'];
  265. $num = $item['cart_num'];
  266. $prices = $item['total_price'];
  267. $goodsStr .= '<tr><td><FW2>----------------</FW2></td></tr>';
  268. $goodsStr .= '<tr>';
  269. $goodsStr .= "<td>{$item['store_name']} | {$item['suk']}</td><td>{$price}</td><td>{$num}</td><td>{$prices}</td>";
  270. $goodsStr .= '</tr>';
  271. if (in_array(1, $printContent['goods'])) {
  272. $goodsStr .= '<tr>';
  273. $goodsStr .= "<td>规格编码:{$item['bar_code']}</td>";
  274. $goodsStr .= '</tr>';
  275. }
  276. unset($price, $num, $prices);
  277. }
  278. $goodsStr .= '</table>';
  279. $addTime = $orderInfo['create_time'];
  280. $payTime = $orderInfo['pay_time'] ?? '';
  281. $printTime = date('Y-m-d H:i:s', time());
  282. $content = '';
  283. $content .= '<MN>' . $times . '</MN>';
  284. if ($printContent['header']) {
  285. $content .= '<FS2><center>' . $orderInfo->merchant->mer_name . '</center></FS2>';
  286. $content .= '<FH2><FW2>----------------</FW2></FH2>';
  287. }
  288. if ($printContent['delivery']) {
  289. if ($orderInfo['order_type'] == 0) {
  290. $content .= '配送方式:配送/快递 \r';
  291. } else {
  292. $content .= '配送方式:门店自提 \r';
  293. }
  294. $content .= '客户姓名: ' . $orderInfo['real_name'] . ' \r';
  295. $content .= '客户电话: ' . $orderInfo['user_phone'] . ' \r';
  296. if ($orderInfo['order_type'] == 0) $content .= '收货地址: ' . $orderInfo['user_address'] . ' \r';
  297. $content .= '<FH2><FW2>----------------</FW2></FH2>';
  298. }
  299. if ($printContent['buyer_remarks']) {
  300. $content .= '买家备注: ' . $orderInfo['mark'] . ' \r';
  301. $content .= '<FH2><FW2>----------------</FW2></FH2>';
  302. }
  303. if (in_array(0, $printContent['goods'])) {
  304. $content .= '*************商品***************';
  305. $content .= ' \r';
  306. $content .= $goodsStr;
  307. $content .= '********************************\r';
  308. $content .= '<FH2><FW2>----------------</FW2></FH2>';
  309. $content .= '<RA>合计:' . $orderInfo['total_price'] . '元</RA>';
  310. $content .= '<FH2><FW2>----------------</FW2></FH2>';
  311. }
  312. if ($printContent['preferential'] || $printContent['freight']) {
  313. if ($printContent['freight']) {
  314. $content .= '<RA>邮费:+' . $orderInfo['pay_postage'] . '元</RA>';
  315. }
  316. if ($printContent['preferential']) {
  317. $discount_price = bcadd($orderInfo['coupon_price'], $orderInfo['svip_discount'], 2);
  318. $content .= '<RA>优惠:-' . $discount_price . '元</RA>';
  319. $content .= '<RA>抵扣:-' . $orderInfo['integral_price'] . '元</RA>';
  320. }
  321. $content .= '<FH2><FW2>----------------</FW2></FH2>';
  322. }
  323. if (in_array(0, $printContent['pay'])) {
  324. if ($orderInfo['paid']) {
  325. switch ($orderInfo['pay_type']) {
  326. case 0:
  327. $content .= '<RA>支付方式:余额支付</RA>';
  328. break;
  329. case 1:
  330. //notbreak;
  331. case 2:
  332. //notbreak;
  333. case 3:
  334. //notbreak;
  335. case 6:
  336. $content .= '<RA>支付方式:微信支付</RA>';
  337. break;
  338. case 4:
  339. //notbreak;
  340. case 5:
  341. $content .= '<RA>支付方式:支付宝支付</RA>';
  342. break;
  343. case 7:
  344. $content .= '<RA>支付方式:线下支付</RA>';
  345. break;
  346. default:
  347. $content .= '<RA>支付方式:暂无</RA>';
  348. break;
  349. }
  350. } else {
  351. $content .= '<RA>支付方式:暂无</RA>';
  352. }
  353. }
  354. if (in_array(1, $printContent['pay'])) {
  355. $content .= '<RA>实际支付:' . $orderInfo['pay_price'] . '元</RA>';
  356. }
  357. if (count($printContent['pay'])) {
  358. $content .= '<FH2><FW2>----------------</FW2></FH2>';
  359. }
  360. if (in_array(0, $printContent['order'])) {
  361. $content .= '订单编号:' . $orderInfo['order_sn'] . '\r';
  362. }
  363. if (in_array(1, $printContent['order'])) {
  364. $content .= '下单时间:' . $addTime . '\r';
  365. }
  366. if (in_array(2, $printContent['order'])) {
  367. $content .= '支付时间:' . $payTime . '\r';
  368. }
  369. if (in_array(3, $printContent['order'])) {
  370. $content .= '打印时间:' . $printTime . '\r';
  371. }
  372. if (count($printContent['order'])) {
  373. $content .= '<FH2><FW2>----------------</FW2></FH2>';
  374. }
  375. if ($printContent['code'] && $printContent['code_url']) {
  376. $content .= '<QR>' . trim(systemConfig('site_url'),'/') . $printContent['code_url'] . '</QR>';
  377. $content .= ' \r';
  378. }
  379. if ($printContent['show_notice']) {
  380. $content .= '<center>' . $printContent['notice_content'] . '</center>';
  381. $content .= ' \r';
  382. }
  383. return $content;
  384. }
  385. public function feyContent($printContent, $orderInfo, $product, $print_type)
  386. {
  387. //halt($orderInfo->toArray());
  388. $printTime = date('Y-m-d H:i:s', time());
  389. $addTime = $orderInfo['create_time'];
  390. $payTime = $orderInfo['pay_time'] ?? '';
  391. $content = '';
  392. if ($printContent['header']) {
  393. $content .= '<CB>' . $orderInfo->merchant->mer_name . '</CB><BR>';
  394. $content .= '--------------------------------<BR>';
  395. }
  396. if ($printContent['delivery']) {
  397. if ($orderInfo['order_type'] == 0) {
  398. $content .= '配送方式:配送/快递<BR>';
  399. } else {
  400. $content .= '配送方式:门店自提<BR>';
  401. }
  402. $content .= '客户姓名: ' . $orderInfo['real_name'] . '<BR>';
  403. $content .= '客户电话: ' . $orderInfo['user_phone'] . '<BR>';
  404. if ($orderInfo['order_type'] == 0) $content .= '收货地址:' . $orderInfo['user_address'] . '<BR>';
  405. $content .= '--------------------------------<BR>';
  406. }
  407. if ($printContent['buyer_remarks']) {
  408. $content .= '买家备注:' . $orderInfo['mark'] . '<BR>';
  409. $content .= '--------------------------------<BR>';
  410. }
  411. if (in_array(0, $printContent['goods'])) {
  412. $content .= '<BR>';
  413. $content .= '**************商品**************<BR>';
  414. $content .= '<BR>';
  415. $content .= '名称 单价 数量 金额<BR>';
  416. foreach ($product as $item) {
  417. $content .= '--------------------------------<BR>';
  418. $name = $item['store_name'] . " | " . $item['suk'];
  419. $price = $item['price'];
  420. $num = $item['cart_num'];
  421. $prices = $item['total_price'];
  422. $kw3 = '';
  423. $kw1 = '';
  424. $kw2 = '';
  425. $kw4 = '';
  426. $str = $name;
  427. $blankNum = 14;//名称控制为14个字节
  428. $lan = mb_strlen($str, 'utf-8');
  429. $m = 0;
  430. $j = 1;
  431. $blankNum++;
  432. $result = array();
  433. if (strlen($price) < 6) {
  434. $k1 = 6 - strlen($price);
  435. for ($q = 0; $q < $k1; $q++) {
  436. $kw1 .= ' ';
  437. }
  438. $price = $price . $kw1;
  439. }
  440. if (strlen($num) < 3) {
  441. $k2 = 3 - strlen($num);
  442. for ($q = 0; $q < $k2; $q++) {
  443. $kw2 .= ' ';
  444. }
  445. $num = $num . $kw2;
  446. }
  447. if (strlen($prices) < 6) {
  448. $k3 = 6 - strlen($prices);
  449. for ($q = 0; $q < $k3; $q++) {
  450. $kw4 .= ' ';
  451. }
  452. $prices = $prices . $kw4;
  453. }
  454. for ($i = 0; $i < $lan; $i++) {
  455. $new = mb_substr($str, $m, $j, 'utf-8');
  456. $j++;
  457. if (mb_strwidth($new, 'utf-8') < $blankNum) {
  458. if ($m + $j > $lan) {
  459. $m = $m + $j;
  460. $tail = $new;
  461. $lenght = iconv("UTF-8", "GBK//IGNORE", $new);
  462. $k = 14 - strlen($lenght);
  463. for ($q = 0; $q < $k; $q++) {
  464. $kw3 .= ' ';
  465. }
  466. if ($m == $j) {
  467. $tail .= $kw3 . ' ' . $price . ' ' . $num . ' ' . $prices;
  468. } else {
  469. $tail .= $kw3 . '<BR>';
  470. }
  471. break;
  472. } else {
  473. $next_new = mb_substr($str, $m, $j, 'utf-8');
  474. if (mb_strwidth($next_new, 'utf-8') < $blankNum) {
  475. continue;
  476. } else {
  477. $m = $i + 1;
  478. $result[] = $new;
  479. $j = 1;
  480. }
  481. }
  482. }
  483. }
  484. $head = '';
  485. foreach ($result as $key => $value) {
  486. if ($key < 1) {
  487. $v_lenght = iconv("UTF-8", "GBK//IGNORE", $value);
  488. $v_lenght = strlen($v_lenght);
  489. if ($v_lenght == 13) $value = $value . " ";
  490. $head .= $value . ' ' . $price . ' ' . $num . ' ' . $prices;
  491. } else {
  492. $head .= $value . '<BR>';
  493. }
  494. }
  495. $content .= $head . $tail;
  496. if (in_array(1, $printContent['goods'])) {
  497. $content .= '规格编码:' . $item['bar_code'] . '<BR>';
  498. }
  499. unset($price);
  500. }
  501. $content .= '<BR>';
  502. $content .= '********************************<BR>';
  503. $content .= '<BR>';
  504. $content .= '--------------------------------<BR>';
  505. $content .= '<RIGHT>合计:' . number_format($orderInfo['total_price'], 2) . '元</RIGHT>';
  506. $content .= '--------------------------------<BR>';
  507. }
  508. if ($printContent['preferential'] || $printContent['freight']) {
  509. if ($printContent['freight']) {
  510. $content .= '<RIGHT>邮费:+' . number_format($orderInfo['pay_postage'], 2) . '元</RIGHT><BR>';
  511. }
  512. if ($printContent['preferential']) {
  513. $discount_price = bcadd($orderInfo['coupon_price'], $orderInfo['svip_discount'], 2);
  514. $content .= '<RIGHT>优惠:-' . number_format($discount_price, 2) . '元</RIGHT><BR>';
  515. $content .= '<RIGHT>抵扣:-' . number_format($orderInfo['integral_price'], 2) . '元</RIGHT>';
  516. }
  517. $content .= '--------------------------------<BR>';
  518. }
  519. if (in_array(0, $printContent['pay'])) {
  520. if ($orderInfo['paid']) {
  521. switch ($orderInfo['pay_type']) {
  522. case 0:
  523. $content .= '<RIGHT>支付方式:余额支付</RIGHT><BR>';
  524. break;
  525. case 1:
  526. //notbreak;
  527. case 2:
  528. //notbreak;
  529. case 3:
  530. //notbreak;
  531. case 6:
  532. $content .= '<RIGHT>支付方式:微信支付</RIGHT><BR>';
  533. break;
  534. case 4:
  535. //notbreak;
  536. case 5:
  537. $content .= '<RIGHT>支付方式:支付宝支付</RIGHT><BR>';
  538. break;
  539. case 7:
  540. $content .= '<RIGHT>支付方式:线下支付</RIGHT><BR>';
  541. break;
  542. default:
  543. $content .= '<RIGHT>支付方式:暂无</RIGHT><BR>';
  544. break;
  545. }
  546. } else {
  547. $content .= '<RIGHT>支付方式:暂无/未支付</RIGHT><BR>';
  548. }
  549. }
  550. if (in_array(1, $printContent['pay'])) {
  551. $content .= '<RIGHT>实际支付:' . number_format($orderInfo['pay_price'], 2) . '元</RIGHT>';
  552. }
  553. if (count($printContent['pay'])) {
  554. $content .= '--------------------------------<BR>';
  555. }
  556. if (in_array(0, $printContent['order'])) {
  557. $content .= '订单编号:' . $orderInfo['order_sn'] . '<BR>';
  558. }
  559. if (in_array(1, $printContent['order'])) {
  560. $content .= '下单时间: ' . $addTime . '<BR>';
  561. }
  562. if (in_array(2, $printContent['order'])) {
  563. $content .= '付款时间: ' . $payTime . '<BR>';
  564. }
  565. if (in_array(3, $printContent['order'])) {
  566. $content .= '打印时间: ' . $printTime . '<BR>';
  567. }
  568. if (count($printContent['order'])) {
  569. $content .= '--------------------------------<BR>';
  570. $content .= '<BR>';
  571. }
  572. if ($printContent['code'] && $printContent['code_url']) {
  573. $content .= '<QR>' . trim(systemConfig('site_url'),'/') . $printContent['code_url'] . '</QR>';
  574. }
  575. if ($printContent['show_notice']) {
  576. $content .= '<C>' . $printContent['notice_content'] . '</C>';
  577. }
  578. return $content;
  579. }
  580. }