DispatchAutosend.php
2.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
<?php
namespace addons\shopro\model;
use addons\shopro\exception\Exception;
use think\Model;
use traits\model\SoftDelete;
/**
* dispatch 自动发货模板
*/
class DispatchAutosend extends Model
{
use SoftDelete;
protected $name = 'shopro_dispatch_autosend';
// 开启自动写入时间戳字段
protected $autoWriteTimestamp = 'int';
// 定义时间戳字段名
protected $createTime = 'createtime';
protected $updateTime = 'updatetime';
protected $deleteTime = 'deletetime';
protected $hidden = ['createtime', 'updatetime', 'deletetime'];
// 追加属性
protected $append = [
];
/**
* 处理自动发货内容
*/
public static function getParamsContent($content) {
$contents = json_decode($content, true);
$contents = $contents ? : [];
$newContents = [];
foreach ($contents as $key => $content) {
foreach ($content as $k => $v) {
$newContents[] = [
'name' => $k,
'value' => $v
];
}
}
return json_encode($newContents);
}
public static function getParamsContentText($content) {
// 这里的params content 是 getParamsContent 的处理结果,现在给他转成字符串
$contents = json_decode($content, true);
$contents = $contents ?: [];
$newContents = '';
foreach ($contents as $key => $content) {
if (isset($content['name'])) {
// 正常格式
$newContents .= $content['name'] . ':'. $content['value'] . ' ';
} else {
// 非正常格式
if (is_array($content)) {
$content_for = str_replace('{', '', json_encode($content));
$content_for = str_replace('}', '', $content_for);
$content_for = preg_replace("/(\"){1}/", " ", $content_for); // 去除 "
$content_for = preg_replace("/\s(?=\s)/", "\\1", $content_for); // 去除多余空格
$newContents .= $content_for;
} else {
$newContents .= $content;
}
}
}
return $newContents;
}
}