ProductModel.php 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | ThinkCMF [ WE CAN DO IT MORE SIMPLE ]
  4. // +----------------------------------------------------------------------
  5. // | Copyright (c) 2013-2019 http://www.thinkcmf.com All rights reserved.
  6. // +----------------------------------------------------------------------
  7. // | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
  8. // +----------------------------------------------------------------------
  9. // | Author: 老猫 <thinkcmf@126.com>
  10. // +----------------------------------------------------------------------
  11. namespace app\rob\model;
  12. use think\Model;
  13. use think\model\concern\SoftDelete;
  14. class ProductModel extends Model
  15. {
  16. use SoftDelete;
  17. // 开启自动写入时间戳字段
  18. protected $autoWriteTimestamp = true;
  19. protected $json = ['image_list'];
  20. protected $jsonAssoc = true;
  21. /**
  22. * 销售状态
  23. */
  24. public function getOnSaleTextAttr($value, $data)
  25. {
  26. $status = ['', '上架', '下架'];
  27. return $status[$data['on_sale']];
  28. }
  29. /**
  30. * 状态
  31. */
  32. public function getStatusAttr($value, $data)
  33. {
  34. $start_time = strtotime($data['start_time']);
  35. $end_time = strtotime($data['end_time']);
  36. $now = time();
  37. if ($start_time < $now && $end_time > $now) {
  38. return 2;
  39. }
  40. if ($start_time > $now) {
  41. return 1;
  42. }
  43. return 3;
  44. }
  45. public function getStatusTextAttr($value, $data)
  46. {
  47. $start_time = strtotime($data['start_time']);
  48. $end_time = strtotime($data['end_time']);
  49. $now = time();
  50. if ($start_time < $now && $end_time > $now) {
  51. return '进行中';
  52. }
  53. if ($start_time > $now) {
  54. return '未开始';
  55. }
  56. return '已结束';
  57. }
  58. /**
  59. * 类型
  60. */
  61. public function getTypeTextAttr($value, $data)
  62. {
  63. $status = ['', '实体券', '虚拟券'];
  64. return $status[$data['type']];
  65. }
  66. public function productCode()
  67. {
  68. return $this->hasMany(ProductCodeModel::class, 'product_id', 'id');
  69. }
  70. }