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, ]; } }