Coupon.php 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  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. $data['apply_range_config'] = isset($data['apply_range_config']) ? $data['apply_range_config'] : [];
  37. return $this->allowField(true)->save($data);
  38. }
  39. /**
  40. * 更新记录
  41. * @param $data
  42. * @return bool|int
  43. */
  44. public function edit($data)
  45. {
  46. if ($data['expire_type'] == '20') {
  47. $data['start_time'] = strtotime($data['start_time']);
  48. $data['end_time'] = strtotime($data['end_time']);
  49. }
  50. return $this->allowField(true)->save($data) !== false;
  51. }
  52. /**
  53. * 删除记录 (软删除)
  54. * @return bool|int
  55. */
  56. public function setDelete()
  57. {
  58. return $this->save(['is_delete' => 1]) !== false;
  59. }
  60. }