12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697 |
- <?php
- namespace app\admin\model;
- use think\Model;
- /**
- * ReqOrder
- */
- class ReqOrder extends Model
- {
- // 表名
- protected $name = 'req_order';
- // 自动写入时间戳字段
- protected $autoWriteTimestamp = true;
- // 追加属性
- protected $append = [
- 'city_text',
- ];
- public function getCityAttr($value): array
- {
- if ($value === '' || $value === null) return [];
- if (!is_array($value)) {
- return explode(',', $value);
- }
- return $value;
- }
- public function setCityAttr($value): string
- {
- return is_array($value) ? implode(',', $value) : $value;
- }
- public function getCityTextAttr($value, $row): string
- {
- if ($row['city'] === '' || $row['city'] === null) return '';
- $cityNames = \think\facade\Db::name('area')->whereIn('id', $row['city'])->column('name');
- return $cityNames ? implode(',', $cityNames) : '';
- }
- public function getRequireItemAttr($value): array
- {
- if ($value === '' || $value === null) return [];
- if (!is_array($value)) {
- return explode(',', $value);
- }
- return $value;
- }
- public function setRequireItemAttr($value): string
- {
- return is_array($value) ? implode(',', $value) : $value;
- }
- public function getPrepayAmountAttr($value): float
- {
- return (float)$value;
- }
- public function getPrepayImageAttr($value): array
- {
- if ($value === '' || $value === null) return [];
- if (!is_array($value)) {
- return explode(',', $value);
- }
- return $value;
- }
- public function setPrepayImageAttr($value): string
- {
- return is_array($value) ? implode(',', $value) : $value;
- }
- public function getSettleAmountAttr($value): float
- {
- return (float)$value;
- }
- public function department()
- {
- return $this->belongsTo(\app\admin\model\department\Department::class, 'req_corp', 'id');
- }
- public function admin()
- {
- return $this->belongsTo(\app\admin\model\Admin::class, 'req_user_id', 'id');
- }
- public function supplier()
- {
- return $this->belongsTo(\app\admin\model\Supplier::class, 'supplier_id', 'id');
- }
- }
|