188 lines
5.3 KiB
PHP
188 lines
5.3 KiB
PHP
<?php
|
|
|
|
namespace app\common\model;
|
|
|
|
use app\common\service\CommonService;
|
|
use app\common\service\DemandBiddingService;
|
|
use think\Model;
|
|
|
|
|
|
class Demands extends Model
|
|
{
|
|
|
|
|
|
|
|
|
|
|
|
// 表名
|
|
protected $name = 'demands';
|
|
|
|
// 自动写入时间戳字段
|
|
protected $autoWriteTimestamp = 'integer';
|
|
|
|
// 定义时间戳字段名
|
|
protected $createTime = 'createtime';
|
|
protected $updateTime = 'updatetime';
|
|
protected $deleteTime = false;
|
|
|
|
// 追加属性
|
|
protected $append = [
|
|
'type_text',
|
|
'limit_time_text',
|
|
'createtime_ago',
|
|
'status_text',
|
|
'work_status_text',
|
|
'accept_status_text',
|
|
'settle_status_text',
|
|
'publish_status_text'
|
|
];
|
|
|
|
protected $type = [
|
|
'images' => 'array',
|
|
'files' => 'array',
|
|
];
|
|
|
|
|
|
protected static function init()
|
|
{
|
|
self::afterInsert(function ($row) {
|
|
if (!empty($row['weigh'])) {
|
|
$pk = $row->getPk();
|
|
$row->getQuery()->where($pk, $row[$pk])->update(['weigh' => $row[$pk]]);
|
|
}
|
|
});
|
|
}
|
|
|
|
|
|
public function getTypeList()
|
|
{
|
|
return ['0' => __('Type 0'), '1' => __('Type 1')];
|
|
}
|
|
|
|
public function getStatusList()
|
|
{
|
|
return ['0' => __('Status 0'), '1' => __('Status 1'), '2' => __('Status 2'), '3' => __('Status 3'), '4' => __('Status 4'), '5' => __('Status 5'), '6' => __('Status 6'), '7' => __('Status 7')];
|
|
}
|
|
|
|
public function getWorkStatusList()
|
|
{
|
|
return ['0' => __('Work_status 0'), '1' => __('Work_status 1'), '2' => __('Work_status 2'), '3' => __('Work_status 3')];
|
|
}
|
|
|
|
public function getAcceptStatusList()
|
|
{
|
|
return ['0' => __('Accept_status 0'), '1' => __('Accept_status 1'), '2' => __('Accept_status 2'), '3' => __('Accept_status 3')];
|
|
}
|
|
|
|
public function getSettleStatusList()
|
|
{
|
|
return ['0' => __('Settle_status 0'), '1' => __('Settle_status 1'), '2' => __('Settle_status 2'), '3' => __('Settle_status 3')];
|
|
}
|
|
|
|
public function getPublishStatusList()
|
|
{
|
|
return ['0' => __('Publish_status 0'), '1' => __('Publish_status 1'), '2' => __('Publish_status 2'), '3' => __('Publish_status 3')];
|
|
}
|
|
|
|
public function getBiddingStatusList()
|
|
{
|
|
return ['0' => __('Bidding_status 0'), '1' => __('Bidding_status 1')];
|
|
}
|
|
|
|
|
|
public function getTypeTextAttr($value, $data)
|
|
{
|
|
$value = $value ? $value : (isset($data['type']) ? $data['type'] : '');
|
|
$list = $this->getTypeList();
|
|
return isset($list[$value]) ? $list[$value] : '';
|
|
}
|
|
|
|
|
|
public function getLimitTimeTextAttr($value, $data)
|
|
{
|
|
return $data['limit_time'];
|
|
}
|
|
|
|
|
|
public function getStatusTextAttr($value, $data)
|
|
{
|
|
$value = $value ? $value : (isset($data['status']) ? $data['status'] : '');
|
|
$list = $this->getStatusList();
|
|
return isset($list[$value]) ? $list[$value] : '';
|
|
}
|
|
|
|
|
|
public function getWorkStatusTextAttr($value, $data)
|
|
{
|
|
$value = $value ? $value : (isset($data['work_status']) ? $data['work_status'] : '');
|
|
$list = $this->getWorkStatusList();
|
|
return isset($list[$value]) ? $list[$value] : '';
|
|
}
|
|
|
|
|
|
public function getAcceptStatusTextAttr($value, $data)
|
|
{
|
|
$value = $value ? $value : (isset($data['accept_status']) ? $data['accept_status'] : '');
|
|
$list = $this->getAcceptStatusList();
|
|
return isset($list[$value]) ? $list[$value] : '';
|
|
}
|
|
|
|
|
|
public function getSettleStatusTextAttr($value, $data)
|
|
{
|
|
$value = $value ? $value : (isset($data['settle_status']) ? $data['settle_status'] : '');
|
|
$list = $this->getSettleStatusList();
|
|
return isset($list[$value]) ? $list[$value] : '';
|
|
}
|
|
|
|
public function getCreatetimeAgoAttr($value, $data)
|
|
{
|
|
return isset($data['createtime']) ? time2ago($data['createtime']) : '';
|
|
}
|
|
|
|
|
|
public function getPublishStatusTextAttr($value, $data)
|
|
{
|
|
$value = $value ? $value : (isset($data['publish_status']) ? $data['publish_status'] : '');
|
|
$list = $this->getPublishStatusList();
|
|
return isset($list[$value]) ? $list[$value] : '';
|
|
}
|
|
|
|
protected function setLimitTimeAttr($value)
|
|
{
|
|
return $value === '' ? null : ($value && !is_numeric($value) ? strtotime($value) : $value);
|
|
}
|
|
|
|
|
|
public function user()
|
|
{
|
|
return $this->hasOne('User', 'id', 'user_id')->field('id,nickname,avatar');
|
|
}
|
|
|
|
public function demandBiddings()
|
|
{
|
|
return $this->hasMany('app\common\model\demand\Biddings', 'demand_id', 'id')->field('id,demand_id,user_id,quoted_price,need_days,remark,bidding_status,process_status,createtime');
|
|
}
|
|
|
|
public function orders()
|
|
{
|
|
return $this->hasMany('Orders', 'parent_order_no', 'parent_order_no');
|
|
}
|
|
|
|
//
|
|
public function demandContracts()
|
|
{
|
|
return $this->hasOne('app\common\model\demand\Contracts', 'demand_id', 'id');
|
|
}
|
|
|
|
public function winBidding()
|
|
{
|
|
return $this->hasOne('app\common\model\demand\Biddings', 'demand_id', 'id')->where('bidding_status', DemandBiddingService::STATUS_BIDDING_WIN);
|
|
}
|
|
|
|
public function demandGroupChat()
|
|
{
|
|
return $this->hasOne('app\common\model\demand\group\Chat', 'demand_id', 'id')->where('status', CommonService::STATUS_ON);
|
|
}
|
|
}
|