Coupon.php 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. <?php
  2. namespace app\store\model;
  3. use app\common\model\Coupon as CouponModel;
  4. /**
  5. * 优惠券模型
  6. * Class Coupon
  7. * @package app\store\model
  8. */
  9. class Coupon extends CouponModel
  10. {
  11. /**
  12. * 获取优惠券列表
  13. * @return \think\Paginator
  14. * @throws \think\exception\DbException
  15. */
  16. public function getList()
  17. {
  18. return $this->where('is_delete', '=', 0)
  19. ->order(['sort' => 'asc', 'create_time' => 'desc'])
  20. ->paginate(15, false, [
  21. 'query' => request()->request()
  22. ]);
  23. }
  24. /**
  25. * 添加新记录
  26. * @param $data
  27. * @return false|int
  28. */
  29. public function add($data)
  30. {
  31. $data['wxapp_id'] = self::$wxapp_id;
  32. if ($data['expire_type'] == '20') {
  33. $data['start_time'] = strtotime($data['start_time']);
  34. $data['end_time'] = strtotime($data['end_time']);
  35. }
  36. return $this->allowField(true)->save($data);
  37. }
  38. /**
  39. * 更新记录
  40. * @param $data
  41. * @return bool|int
  42. */
  43. public function edit($data)
  44. {
  45. if ($data['expire_type'] == '20') {
  46. $data['start_time'] = strtotime($data['start_time']);
  47. $data['end_time'] = strtotime($data['end_time']);
  48. }
  49. return $this->allowField(true)->save($data) !== false;
  50. }
  51. /**
  52. * 删除记录 (软删除)
  53. * @return bool|int
  54. */
  55. public function setDelete()
  56. {
  57. return $this->save(['is_delete' => 1]) !== false;
  58. }
  59. }