| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123 |
- <?php
- namespace App\Services;
- use App\OwnerLogisticPrintTemplate;
- use App\Traits\ServiceAppAop;
- use App\PrintTemplate;
- class PrintTemplateService
- {
- use ServiceAppAop;
- protected $modelClass = PrintTemplate::class;
- public function saveRelation($relations)
- {
- $ownerLogisticPrintTemplate = OwnerLogisticPrintTemplate::query()->where('print_template_id',$relations[0]['print_template_id'])->get()->toArray();
- // 不存在的
- $params = array_udiff_assoc($relations,$ownerLogisticPrintTemplate,function($itemA,$itemB){
- return ($itemA['owner_id'] === $itemB['owner_id'] && $itemA['logistic_id'] === $itemB['logistic_id'] ) ? 0:1;
- });
- // 存在的
- $deleteParams = array_udiff_assoc($ownerLogisticPrintTemplate,$relations,function($itemA,$itemB){
- return ($itemA['owner_id'] === $itemB['owner_id'] && $itemA['logistic_id'] === $itemB['logistic_id'] ) ? 0:1;
- });
- OwnerLogisticPrintTemplate::query()->insert($params);
- foreach ($deleteParams as $deleteParam){
- $item = OwnerLogisticPrintTemplate::query()->where(['print_template_id'=>$deleteParam['print_template_id'],'owner_id'=>$deleteParam['owner_id'],'logistic_id'=>$deleteParam['logistic_id']])->first();
- $item->delete();
- }
- }
- public function getParts(): array
- {
- return [
- [
- 'name' => '背景',
- 'value' => $this->getBg()
- ],
- [
- 'name' => '文本框',
- 'value' => $this->getTextBox()
- ],
- [
- 'name' => '条纹码',
- 'value' => $this->getStripeCode()
- ],
- [
- 'name' => '二维码',
- 'value' => $this->getQrCode()
- ],
- [
- 'name' => '图片',
- 'value' => $this->getImage()
- ]
- ];
- }
- private function getTextBox(): array
- {
- return [
- 'type' => 'textBox',
- 'border-style' => 'none',
- 'border-width' => 1,
- 'font-size' => 12,
- 'width' => 250,
- 'height' => 50,
- 'left' => '',
- 'top' => '',
- 'white-space' => 'pre',
- 'justify-content' => 'center',
- // flex-start 开头|flex-end 结尾|center 居中|space-between|space-around|initial|inherit;
- 'align-items' => 'center'
- // stretch 拉伸平铺|center居中|flex-start 容器开头|flex-end容器结尾|baseline容器基线|initial|inherit
- ];
- }
- private function getStripeCode(): array
- {
- return [
- 'type' => 'stripeCode',
- 'width' => 404,
- 'left' => 100,
- 'top' => 0,
- 'scale' => 1,
- ];
- }
- private function getBg(): array
- {
- return [
- 'type' => 'bg',
- 'width' => 600,
- 'height' => 900,
- ];
- }
- private function getQrCode(): array
- {
- return [
- 'type' => 'qRCode',
- 'width' => 100,
- 'height' => 100,
- 'left' => 0,
- 'top' => 0,
- ];
- }
- private function getImage(): array
- {
- return [
- 'type' => 'image',
- 'width' => 100,
- 'height' => 100,
- 'left' => 0,
- 'top' => 0,
- 'value' => 'none',
- 'scale' => 1,
- ];
- }
- }
|