You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

80 lines
2.3 KiB

1 year ago
<?php
namespace app\admin\model\ykjp\information\basisinfo;
use think\Model;
use traits\model\SoftDelete;
class Warehouse extends Model {
use SoftDelete;
// 表名
protected $name = 'ykjp_warehouse';
// 自动写入时间戳字段
protected $autoWriteTimestamp = 'int';
// 定义时间戳字段名
protected $createTime = 'createtime';
protected $updateTime = 'updatetime';
protected $deleteTime = 'deletetime';
// 追加属性
protected $append = [
'type_text',
'status_text',
'area_text',
];
public function getTypeList() {
return ['自有仓' => __('自有仓'), '合作仓' => __('合作仓')];
}
public function getTypeTextAttr($value, $data) {
$value = $value ? $value : (isset($data['type']) ? $data['type'] : '');
$list = $this->getTypeList();
return isset($list[$value]) ? $list[$value] : '';
}
public function object_array($array) {
if (is_object($array)) {
$array = (array) $array;
} if (is_array($array)) {
foreach ($array as $key => $value) {
$array[$key] = $this->object_array($value);
}
}
return $array;
}
public function getStatusTextAttr($value, $data)
{
return $data['status'] == '1' ? '启用中' : '禁用中';
}
public function getAreaTextAttr($value, $data)
{
$area_text = '';
if(isset($data['service_type']) && $data['service_type'] === 'area') {
$province_ids = [];
if(!empty($data['service_province_ids']) ) {
$province_ids = explode(',', $data['service_province_ids']);
}
$city_ids = [];
if(!empty($data['service_city_ids'])) {
$city_ids = explode(',', $data['service_city_ids']);
}
$area_ids = [];
if(!empty($data['service_area_ids'])) {
$area_ids = explode(',', $data['service_area_ids']);
}
$ids = array_merge($province_ids, $city_ids, $area_ids);
if(!empty($ids)) {
$areaArray = \app\admin\model\shopro\Area::where('id', 'in', $ids)->column('name');
$area_text = implode(',', $areaArray);
}
}
return $area_text;
}
}