Coupon.php 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. <?php
  2. namespace app\api\model\service;
  3. use think\Model;
  4. class Coupon extends Model
  5. {
  6. // 表名
  7. protected $name = 'service_coupon';
  8. // 自动写入时间戳字段
  9. protected $autoWriteTimestamp = 'int';
  10. // 定义时间戳字段名
  11. protected $createTime = 'createtime';
  12. protected $updateTime = 'updatetime';
  13. public static function getCouponList($params)
  14. {
  15. extract($params);
  16. if(isset($shop_id) && $shop_id)
  17. {
  18. $where['shop_id'] = $shop_id;
  19. }
  20. if(isset($is_check) && $is_check != '')
  21. {
  22. $where['is_check'] = $is_check;
  23. }
  24. if(isset($timttype) && $timttype != '')
  25. {
  26. switch ($timttype)
  27. {
  28. case 0:
  29. $where['starttime'] = ['>',time()];
  30. break;
  31. case 1:
  32. $where['starttime'] = ['<=',time()];
  33. $where['endtime'] = ['>=',time()];
  34. break;
  35. case 2:
  36. $where['endtime'] = ['<',time()];
  37. break;
  38. }
  39. }
  40. $list = self::where($where)->field('id,type,goods_id,shop_id,achieve,reduce,starttime,endtime,effective_day,is_check,note,createtime')->order('id desc')->page($page)->limit(10)->select();
  41. foreach ($list as $key=>$value)
  42. {
  43. $list[$key]['goodsname'] = $value['goods_id']?Goods::getName($value['goods_id']):'';
  44. }
  45. return $list;
  46. }
  47. }