EffectiveRules.php 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | likeadmin快速开发前后端分离管理后台(PHP版)
  4. // +----------------------------------------------------------------------
  5. // | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
  6. // | 开源版本可自由商用,可去除界面版权logo
  7. // | gitee下载:https://gitee.com/likeshop_gitee/likeadmin
  8. // | github下载:https://github.com/likeshop-github/likeadmin
  9. // | 访问官网:https://www.likeadmin.cn
  10. // | likeadmin团队 版权所有 拥有最终解释权
  11. // +----------------------------------------------------------------------
  12. // | author: likeadminTeam
  13. // +----------------------------------------------------------------------
  14. namespace app\common\model\effective;
  15. use app\common\model\BaseModel;
  16. use app\common\model\goods_category\GoodsCategory;
  17. /**
  18. * EffectiveRules模型
  19. * Class EffectiveRules
  20. * @package app\common\model\effective
  21. */
  22. class EffectiveRules extends BaseModel
  23. {
  24. protected $name = 'effective_rules';
  25. public function effectiveWithCategory()
  26. {
  27. return $this->belongsToMany(GoodsCategory::class,EffectiveCategory::class,'goods_category_id','effective_id');
  28. }
  29. public static function formatEndEffectiveTime( $time,$num,$unit)
  30. {
  31. if(is_numeric($time)){
  32. $time = date('Y-m-d H:i:s',$time);
  33. }
  34. $effectiveUnit = 'day';
  35. switch ($unit){
  36. case 1:
  37. $effectiveUnit = 'day';
  38. break;
  39. case 2:
  40. $effectiveUnit = 'hour';
  41. break;
  42. }
  43. return strtotime("$time +". $num.$effectiveUnit);
  44. }
  45. }