Coupon.php 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. <?php
  2. /**
  3. * Niushop商城系统 - 团队十年电商经验汇集巨献!
  4. * =========================================================
  5. * Copy right 2019-2029 上海牛之云网络科技有限公司, 保留所有权利。
  6. * ----------------------------------------------
  7. * 官方网址: https://www.niushop.com
  8. * 这不是一个自由软件!您只能在不用于商业目的的前提下对程序代码进行修改和使用。
  9. * 任何企业和个人不允许对程序代码以任何形式任何目的再发布。
  10. * =========================================================
  11. */
  12. namespace addon\cashier\storeapi\controller;
  13. use addon\coupon\model\Coupon as CouponModel;
  14. use app\storeapi\controller\BaseStoreApi;
  15. class Coupon extends BaseStoreApi
  16. {
  17. /**
  18. * 列表
  19. */
  20. public function lists()
  21. {
  22. $page = $this->params[ 'page' ] ?? 1;
  23. $page_size = $this->params[ 'page_size' ] ?? PAGE_LIST_ROWS;
  24. $name = $this->params[ 'name' ] ?? '';
  25. $start_time = $this->params[ 'fetch_time_start' ] ?? '';
  26. $end_time = $this->params[ 'fetch_time_end' ] ?? '';
  27. $type = $this->params[ 'type' ] ?? '';
  28. $use_type = $this->params[ 'use_type' ] ?? '';
  29. $coupon_model = new CouponModel();
  30. $condition = [
  31. [ 'site_id', "=", $this->site_id ],
  32. ];
  33. if (!empty($type)) {
  34. $condition[] = [ "type", '=', $type ];
  35. }
  36. if (!empty($use_type)) {
  37. $condition[] = [ "use_type", '=', $use_type ];
  38. }
  39. if ($name !== '') {
  40. $condition[] = [ "name", 'like', '%' . $name . '%' ];
  41. }
  42. if (!empty($start_time) && empty($end_time)) {
  43. $condition[] = [ 'create_time', '>=', date_to_time($start_time) ];
  44. } elseif (empty($start_time) && !empty($end_time)) {
  45. $condition[] = [ "create_time", "<=", date_to_time($end_time) ];
  46. } elseif (!empty($start_time) && !empty($end_time)) {
  47. $condition[] = [ 'create_time', 'between', [ date_to_time($start_time), date_to_time($end_time) ] ];
  48. }
  49. $list = $coupon_model->getCouponPageList($condition, $page, $page_size, 'coupon_id desc');
  50. return $this->response($list);
  51. }
  52. /**
  53. * 优惠券详情
  54. */
  55. public function detail()
  56. {
  57. $coupon_id = $this->params[ 'coupon_id' ] ?? 0;
  58. $coupon_model = new CouponModel();
  59. $condition = array(
  60. ['site_id', '=', $this->site_id],
  61. ['coupon_id', '=', $coupon_id]
  62. );
  63. $info = $coupon_model->getCouponInfo($condition,'*');
  64. return $this->response($info);
  65. }
  66. /**
  67. * 查询优惠券
  68. * @return false|string
  69. */
  70. public function couponTypeList()
  71. {
  72. $page = $this->params[ 'page' ] ?? 1;
  73. $page_size = $this->params[ 'page_size' ] ?? PAGE_LIST_ROWS;
  74. $name = $this->params[ 'name' ] ?? '';
  75. $coupon_model = new CouponModel();
  76. $condition = [
  77. [ 'site_id', "=", $this->site_id ],
  78. [ 'status', '=', 1]
  79. ];
  80. if ($name !== '') {
  81. $condition[] = [ "coupon_name", 'like', '%' . $name . '%' ];
  82. }
  83. $field = 'coupon_type_id,type,coupon_name,count,lead_count,used_count,goods_type,is_limit,at_least,money,discount,discount_limit,validity_type,end_time,fixed_term';
  84. $list = $coupon_model->getCouponTypePageList($condition, $page, $page_size, 'coupon_type_id desc', $field);
  85. return $this->response($list);
  86. }
  87. }