PrintTemplateService.php 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. <?php
  2. namespace App\Services;
  3. use App\OwnerLogisticPrintTemplate;
  4. use App\Traits\ServiceAppAop;
  5. use App\PrintTemplate;
  6. class PrintTemplateService
  7. {
  8. use ServiceAppAop;
  9. protected $modelClass = PrintTemplate::class;
  10. public function saveRelation($relations)
  11. {
  12. $ownerLogisticPrintTemplate = OwnerLogisticPrintTemplate::query()->where('print_template_id',$relations[0]['print_template_id'])->get()->toArray();
  13. // 不存在的
  14. $params = array_udiff_assoc($relations,$ownerLogisticPrintTemplate,function($itemA,$itemB){
  15. return ($itemA['owner_id'] === $itemB['owner_id'] && $itemA['logistic_id'] === $itemB['logistic_id'] ) ? 0:1;
  16. });
  17. // 存在的
  18. $deleteParams = array_udiff_assoc($ownerLogisticPrintTemplate,$relations,function($itemA,$itemB){
  19. return ($itemA['owner_id'] === $itemB['owner_id'] && $itemA['logistic_id'] === $itemB['logistic_id'] ) ? 0:1;
  20. });
  21. OwnerLogisticPrintTemplate::query()->insert($params);
  22. foreach ($deleteParams as $deleteParam){
  23. $item = OwnerLogisticPrintTemplate::query()->where(['print_template_id'=>$deleteParam['print_template_id'],'owner_id'=>$deleteParam['owner_id'],'logistic_id'=>$deleteParam['logistic_id']])->first();
  24. $item->delete();
  25. }
  26. }
  27. public function getParts(): array
  28. {
  29. return [
  30. [
  31. 'name' => '背景',
  32. 'value' => $this->getBg()
  33. ],
  34. [
  35. 'name' => '文本框',
  36. 'value' => $this->getTextBox()
  37. ],
  38. [
  39. 'name' => '条纹码',
  40. 'value' => $this->getStripeCode()
  41. ],
  42. [
  43. 'name' => '二维码',
  44. 'value' => $this->getQrCode()
  45. ],
  46. [
  47. 'name' => '图片',
  48. 'value' => $this->getImage()
  49. ]
  50. ];
  51. }
  52. private function getTextBox(): array
  53. {
  54. return [
  55. 'type' => 'textBox',
  56. 'border-style' => 'none',
  57. 'border-width' => 1,
  58. 'font-size' => 12,
  59. 'width' => 250,
  60. 'height' => 50,
  61. 'left' => '',
  62. 'top' => '',
  63. 'white-space' => 'pre',
  64. 'justify-content' => 'center',
  65. // flex-start 开头|flex-end 结尾|center 居中|space-between|space-around|initial|inherit;
  66. 'align-items' => 'center'
  67. // stretch 拉伸平铺|center居中|flex-start 容器开头|flex-end容器结尾|baseline容器基线|initial|inherit
  68. ];
  69. }
  70. private function getStripeCode(): array
  71. {
  72. return [
  73. 'type' => 'stripeCode',
  74. 'width' => 404,
  75. 'left' => 100,
  76. 'top' => 0,
  77. 'scale' => 1,
  78. ];
  79. }
  80. private function getBg(): array
  81. {
  82. return [
  83. 'type' => 'bg',
  84. 'width' => 600,
  85. 'height' => 900,
  86. ];
  87. }
  88. private function getQrCode(): array
  89. {
  90. return [
  91. 'type' => 'qRCode',
  92. 'width' => 100,
  93. 'height' => 100,
  94. 'left' => 0,
  95. 'top' => 0,
  96. ];
  97. }
  98. private function getImage(): array
  99. {
  100. return [
  101. 'type' => 'image',
  102. 'width' => 100,
  103. 'height' => 100,
  104. 'left' => 0,
  105. 'top' => 0,
  106. 'value' => 'none',
  107. 'scale' => 1,
  108. ];
  109. }
  110. }