| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081 |
- <?php
- // +----------------------------------------------------------------------
- // | ThinkCMF [ WE CAN DO IT MORE SIMPLE ]
- // +----------------------------------------------------------------------
- // | Copyright (c) 2013-2019 http://www.thinkcmf.com All rights reserved.
- // +----------------------------------------------------------------------
- // | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
- // +----------------------------------------------------------------------
- // | Author: 老猫 <thinkcmf@126.com>
- // +----------------------------------------------------------------------
- namespace app\rob\model;
- use think\Model;
- use think\model\concern\SoftDelete;
- class ProductModel extends Model
- {
- use SoftDelete;
- // 开启自动写入时间戳字段
- protected $autoWriteTimestamp = true;
- protected $json = ['image_list'];
- protected $jsonAssoc = true;
- /**
- * 销售状态
- */
- public function getOnSaleTextAttr($value, $data)
- {
- $status = ['', '上架', '下架'];
- return $status[$data['on_sale']];
- }
- /**
- * 状态
- */
- public function getStatusAttr($value, $data)
- {
- $start_time = strtotime($data['start_time']);
- $end_time = strtotime($data['end_time']);
- $now = time();
- if ($start_time < $now && $end_time > $now) {
- return 2;
- }
- if ($start_time > $now) {
- return 1;
- }
- return 3;
- }
- public function getStatusTextAttr($value, $data)
- {
- $start_time = strtotime($data['start_time']);
- $end_time = strtotime($data['end_time']);
- $now = time();
- if ($start_time < $now && $end_time > $now) {
- return '进行中';
- }
- if ($start_time > $now) {
- return '未开始';
- }
- return '已结束';
- }
- /**
- * 类型
- */
- public function getTypeTextAttr($value, $data)
- {
- $status = ['', '实体券', '虚拟券'];
- return $status[$data['type']];
- }
- public function productCode()
- {
- return $this->hasMany(ProductCodeModel::class, 'product_id', 'id');
- }
- }
|