Coupon.php 1.6 KB

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