|
- <?php
-
- namespace addons\unishop\model;
-
-
- use think\Model;
- use traits\model\SoftDelete;
-
- /**
- * 收货地址模型
- * Class Favorite
- * @package addons\unishop\model
- */
- 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);
- }
-
- }
|