123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122 |
- <?php
- namespace addons\unishop\model;
- use addons\unishop\extend\Hashids;
- use think\Model;
- use traits\model\SoftDelete;
- class FlashSale extends Model
- {
- use SoftDelete;
-
- protected $name = 'unishop_flash_sale';
-
- protected $autoWriteTimestamp = 'int';
-
- protected $createTime = 'createtime';
- protected $updateTime = 'updatetime';
- protected $deleteTime = 'deletetime';
-
- const STATUS_YES = 1;
- const STATUS_NO = 0;
-
- const SWITCH_YES = 1;
- const SWITCH_NO = 0;
-
- protected $hidden = [
- 'id'
- ];
-
- protected $append = [
- 'flash_id',
- 'starttime_hour',
- 'state',
- 'current',
- ];
-
- public function getFlashIdAttr($value, $data) {
- return Hashids::encodeHex($data['id']);
- }
-
- public function getStarttimeHourAttr($value, $data) {
- return date('H:i', $data['starttime']);
- }
-
- public function getCurrentAttr($value, $data) {
- if (date('Y-m-d H:00:00', time()) == date('Y-m-d H:00:00', $data['starttime'])) {
- return true;
- } else {
- return false;
- }
- }
-
- public function getStateAttr($value, $data) {
- $time = time();
- if (date('Y-m-d H:00:00', $time) == date('Y-m-d H:00:00', $data['starttime'])) {
- return 2;
- } else if ($data['starttime'] < $time) {
- return 1;
- } else {
- return 0;
- }
- }
-
- public function product()
- {
- return $this->hasMany('flashProduct', 'flash_id', 'id');
- }
-
- public static function countdown($targetTime)
- {
- $time = $targetTime - time();
- if ($time > 0) {
-
- $countdown['day'] = intval(date('d', $time) - 1);
- $countdown['hour'] = intval(date('H', $time) - 8);
- $countdown['minute'] = intval(date('i', $time));
- $countdown['second'] = intval(date('s', $time));
- foreach ($countdown as &$item) {
- if ($item < 0) $item = 0;
- }
- return $countdown;
- }
- return false;
- }
- }
|