| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157 |
- <?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($saveRelation, $relations, $printTemplateId)
- {
- $relation_arr = [];
- foreach ($relations as $relation) {
- $owner_id = $relation['owner_id'];
- $logistic_id = $relation['logistic_id'];
- if(!array_key_exists($owner_id,$relation_arr)) $relation_arr[$owner_id] = [];
- $relation_arr[$owner_id][$logistic_id] = ['name' => $relation->logistic->name];
- }
- $delete_items = [
- 'owner_id' => [],
- 'items' => [],
- ];
- $params = [];
- foreach ($saveRelation as $owner_id => $data) {
- if(array_key_exists($owner_id,$relation_arr) && $data['isActivation'] == false){
- $delete_items['owner_id'][] = $owner_id;
- continue;
- }
- $logistic_relation = $relation_arr[$owner_id] ?? [];
- foreach ($data['logistics'] as $logistic_id => $logistic) {
- if ($logistic['isActivation'] == false){
- // 未激活
- if(array_key_exists($logistic_id,$logistic_relation)){
- $delete_items['items'][] = [
- 'owner_id' => $owner_id,
- 'logistic_id' => $logistic_id
- ];
- }
- } else if($logistic['isActivation'] == true){
- // 激活
- if (!array_key_exists($logistic_id,$logistic_relation)){
- $params[] = [
- 'owner_name'=>$data['name'],
- 'logistic_name'=>$logistic['name'],
- 'owner_id' => $owner_id,
- 'logistic_id' => $logistic_id,
- 'print_template_id' => $printTemplateId,
- ];
- }
- }
- }
- }
- if ($delete_items['owner_id']) OwnerLogisticPrintTemplate::query()->whereIn('owner_id', $delete_items['owner_id'])->where('print_template_id', $printTemplateId)->delete();
- if ($delete_items['items']) {
- foreach ($delete_items['items'] as $item) {
- OwnerLogisticPrintTemplate::query()->where('owner_id', $item['owner_id'])->where('logistic_id', $item['logistic_id'])->delete();
- }
- }
- if (!$params) return;
- OwnerLogisticPrintTemplate::query()->insert($params);
- }
- 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,
- ];
- }
- }
|