| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849 |
- <?php
- namespace app\admin\model;
- use think\Model;
- class Customer extends Model
- {
- // 表名
- protected $table = 'customer';
-
- // 自动写入时间戳字段
- protected $autoWriteTimestamp = false;
- // 定义时间戳字段名
- protected $createTime = false;
- protected $updateTime = false;
- protected $deleteTime = false;
- // 追加属性
- protected $append = [
- ];
- protected static function init()
- {
- self::beforeWrite(function ($model) {
- $data = $model->getData();
- foreach (['phone', 'email'] as $field) {
- if (!array_key_exists($field, $data)) {
- continue;
- }
- $v = $data[$field];
- if ($v === null || $v === '') {
- continue;
- }
- $v = str_replace([',', ';', ';', '|', '|', "\n", "\r", "\t"], ',', (string)$v);
- $parts = preg_split('/\s*,\s*/', $v, -1, PREG_SPLIT_NO_EMPTY);
- $parts = array_map('trim', $parts);
- $parts = array_filter($parts, function ($s) {
- return $s !== '';
- });
- $model->setAttr($field, implode(',', $parts));
- }
- });
- }
- }
|