Coupon.php 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. <?php
  2. namespace app\admin\controller\shop;
  3. use app\common\controller\Backend;
  4. /**
  5. * 优惠券管理
  6. *
  7. * @icon fa fa-circle-o
  8. */
  9. class Coupon extends Backend
  10. {
  11. /**
  12. * Coupon模型对象
  13. * @var \app\admin\model\shop\Coupon
  14. */
  15. protected $model = null;
  16. public function _initialize()
  17. {
  18. parent::_initialize();
  19. $this->model = new \app\admin\model\shop\Coupon;
  20. $this->view->assign("resultList", $this->model->getResultList());
  21. $this->view->assign("isOpenList", $this->model->getIsOpenList());
  22. $this->view->assign("IsPrivateList", $this->model->getIsPrivateList());
  23. $this->view->assign("modeList", $this->model->getModeList());
  24. }
  25. /**
  26. * 默认生成的控制器所继承的父类中有index/add/edit/del/multi五个基础方法、destroy/restore/recyclebin三个回收站方法
  27. * 因此在当前控制器中可不用编写增删改查的代码,除非需要自己控制这部分逻辑
  28. * 需要将application/admin/library/traits/Backend.php中对应的方法复制到当前控制器,然后进行修改
  29. */
  30. /**
  31. * 查看
  32. */
  33. public function index()
  34. {
  35. //设置过滤方法
  36. $this->request->filter(['strip_tags', 'trim']);
  37. if ($this->request->isAjax()) {
  38. //如果发送的来源是Selectpage,则转发到Selectpage
  39. if ($this->request->request('keyField')) {
  40. return $this->selectpage();
  41. }
  42. $this->relationSearch = true;
  43. list($where, $sort, $order, $offset, $limit, $page, $alias, $bind) = $this->buildparams();
  44. $aliasName = reset($alias);
  45. $list = $this->model
  46. ->field($aliasName . '.*,GROUP_CONCAT(n.name) condition_name')
  47. ->alias($aliasName)
  48. ->bind($bind)
  49. ->join('shop_coupon_condition n', 'FIND_IN_SET(n.id,' . $aliasName . '.condition_ids)', 'LEFT')
  50. ->where($where)
  51. ->order($sort, $order)
  52. ->group($aliasName . '.id')
  53. ->paginate($limit);
  54. foreach ($list as $index => $item) {
  55. $item['expired'] = $item['endtime'] < time() ? true : false;
  56. }
  57. $result = array("total" => $list->total(), "rows" => $list->items());
  58. return json($result);
  59. }
  60. $config = get_addon_config('shop');
  61. $this->assignconfig('mobileurl', '');
  62. return $this->view->fetch();
  63. }
  64. /**
  65. * 查看
  66. */
  67. public function select()
  68. {
  69. $this->request->filter(['strip_tags', 'trim']);
  70. if ($this->request->isAjax()) {
  71. //如果发送的来源是Selectpage,则转发到Selectpage
  72. if ($this->request->request('keyField')) {
  73. return $this->selectpage();
  74. }
  75. $this->relationSearch = true;
  76. list($where, $sort, $order, $offset, $limit, $page, $alias, $bind) = $this->buildparams();
  77. $aliasName = reset($alias);
  78. $list = $this->model
  79. ->field($aliasName . '.*,GROUP_CONCAT(n.name) condition_name')
  80. ->alias($aliasName)
  81. ->bind($bind)
  82. ->join('shop_coupon_condition n', 'FIND_IN_SET(n.id,' . $aliasName . '.condition_ids)', 'LEFT')
  83. ->where($where)
  84. ->order($sort, $order)
  85. ->group($aliasName . '.id')
  86. ->paginate($limit);
  87. foreach ($list as $index => $item) {
  88. $item['expired'] = $item['endtime'] < time() ? true : false;
  89. }
  90. $result = array("total" => $list->total(), "rows" => $list->items());
  91. return json($result);
  92. }
  93. $config = get_addon_config('shop');
  94. $this->assignconfig('mobileurl', '');
  95. return $this->view->fetch();
  96. }
  97. }