SupplierTicketPrintServices.php 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
  4. // +----------------------------------------------------------------------
  5. // | Copyright (c) 2016~2020 https://www.crmeb.com All rights reserved.
  6. // +----------------------------------------------------------------------
  7. // | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
  8. // +----------------------------------------------------------------------
  9. // | Author: CRMEB Team <admin@crmeb.com>
  10. // +----------------------------------------------------------------------
  11. namespace app\services\supplier;
  12. use app\dao\supplier\SupplierTicketPrintDao;
  13. use app\services\BaseServices;
  14. use think\exception\ValidateException;
  15. /**
  16. * 小票打印
  17. * Class SupplierTicketPrintServices
  18. * @package app\services\supplier
  19. * @mixin SupplierTicketPrintDao
  20. */
  21. class SupplierTicketPrintServices extends BaseServices
  22. {
  23. /**
  24. * 构造方法
  25. * SupplierTicketPrintServices constructor.
  26. * @param SupplierTicketPrintDao $dao
  27. */
  28. public function __construct(SupplierTicketPrintDao $dao)
  29. {
  30. $this->dao = $dao;
  31. }
  32. /**
  33. * 获取打印配置
  34. * @param int $supplierId
  35. * @param string $field
  36. * @return array
  37. * @throws \think\db\exception\DataNotFoundException
  38. * @throws \think\db\exception\DbException
  39. * @throws \think\db\exception\ModelNotFoundException
  40. */
  41. public function getTicketInfo(int $supplierId, string $field = '*')
  42. {
  43. $info = $this->dao->getOne(['supplier_id' => $supplierId], $field);
  44. if ($info) {
  45. $data = $info->toArray();
  46. } else {
  47. $data = [
  48. 'id' => 0,
  49. 'supplier_id' => $supplierId,
  50. 'develop_id' => 0,
  51. 'api_key' => '',
  52. 'client_id' => '',
  53. 'terminal_number' => '',
  54. 'status' => 0,
  55. ];
  56. }
  57. return $data;
  58. }
  59. /**
  60. * 更新打印配置
  61. * @param int $supplierId
  62. * @param $data
  63. * @return bool
  64. * @throws \think\db\exception\DataNotFoundException
  65. * @throws \think\db\exception\DbException
  66. * @throws \think\db\exception\ModelNotFoundException
  67. */
  68. public function savePrintData(int $supplierId, $data)
  69. {
  70. $info = $this->dao->getOne(['supplier_id' => $supplierId], 'id, supplier_id');
  71. if ($info) {
  72. $res = $this->dao->update($info['id'], $data);
  73. } else {
  74. $data['supplier_id'] = $supplierId;
  75. $res = $this->dao->save($data);
  76. }
  77. if (!$res) throw new ValidateException('保存失败!');
  78. return true;
  79. }
  80. }