123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172 |
- <?php
- namespace app\admin\model\unishop;
- use think\Model;
- use traits\model\SoftDelete;
- class Coupon extends Model
- {
- use SoftDelete;
- //数据库
- protected $connection = 'database';
- // 表名
- protected $name = 'unishop_coupon';
- // 自动写入时间戳字段
- protected $autoWriteTimestamp = 'int';
- // 定义时间戳字段名
- protected $createTime = 'createtime';
- protected $updateTime = 'updatetime';
- protected $deleteTime = 'deletetime';
- // 追加属性
- protected $append = [
- 'starttime_text',
- 'endtime_text'
- ];
- // 是否上架?
- const SWITCH_ON = 1; //是
- const SWITCH_OFF = 0; //否
- protected static function init()
- {
- self::afterInsert(function ($row) {
- $pk = $row->getPk();
- $row->getQuery()->where($pk, $row[$pk])->update(['weigh' => $row[$pk]]);
- });
- }
- public function getStarttimeTextAttr($value, $data)
- {
- $value = $value ? $value : (isset($data['starttime']) ? $data['starttime'] : '');
- return is_numeric($value) ? date("Y-m-d", $value) : $value;
- }
- public function getEndtimeTextAttr($value, $data)
- {
- $value = $value ? $value : (isset($data['endtime']) ? $data['endtime'] : '');
- return is_numeric($value) ? date("Y-m-d", $value) : $value;
- }
- protected function setStarttimeAttr($value)
- {
- return $value === '' ? null : ($value && !is_numeric($value) ? strtotime($value) : $value);
- }
- protected function setEndtimeAttr($value)
- {
- return $value === '' ? null : ($value && !is_numeric($value) ? strtotime($value) : $value);
- }
- }
|