RiceCard.php 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  1. <?php
  2. declare (strict_types = 1);
  3. namespace app\store\controller\card;
  4. use app\store\controller\Controller;
  5. use app\store\model\card\RiceCard as RiceCardModel;
  6. /**
  7. * 米卡管理控制器
  8. * Class RiceCard
  9. * @package app\store\controller\card
  10. */
  11. class RiceCard extends Controller
  12. {
  13. public function list()
  14. {
  15. $model = new RiceCardModel;
  16. $list = $model->getList($this->request->param());
  17. return $this->renderSuccess(compact('list'));
  18. }
  19. /**
  20. * 米卡下拉列表
  21. * @return array
  22. */
  23. public function selectList(){
  24. $param = $this->request->get();
  25. $model = new RiceCardModel;
  26. $list = $model->getListAll($param);
  27. return $this->renderSuccess(compact('list'));
  28. }
  29. /**
  30. * 米卡-现金卡详情记录
  31. * @param int $id
  32. * @return array
  33. */
  34. public function cashDetail(int $id)
  35. {
  36. $model = new RiceCardModel;
  37. $detail = $model->getDetail($id);
  38. return $this->renderSuccess(compact('detail'));
  39. }
  40. /**
  41. * 添加现金卡
  42. * @return array|string
  43. */
  44. public function addCash()
  45. {
  46. // 新增记录
  47. $model = new RiceCardModel;
  48. $post = $this->postForm();
  49. $post['type'] = RiceCardModel::CASH_CARD;
  50. if ($model->add($post)) {
  51. return $this->renderSuccess('添加成功');
  52. }
  53. return $this->renderError($model->getError() ?: '添加失败');
  54. }
  55. //添加兑换卡EXCHANGE_CARD
  56. public function addExchange(){
  57. $model = new RiceCardModel;
  58. $post = $this->postForm();
  59. $post['type'] = RiceCardModel::EXCHANGE_CARD;
  60. $post['status'] = 1;
  61. if ($model->add($post)) {
  62. return $this->renderSuccess('添加成功');
  63. }
  64. return $this->renderError($model->getError() ?: '添加失败');
  65. }
  66. /**
  67. * 添加实体现金卡
  68. * @return array
  69. * @author: zjwhust
  70. * @Time: 2022/3/9 10:59
  71. */
  72. public function addEntityCash()
  73. {
  74. // 新增记录
  75. $model = new RiceCardModel;
  76. $post = $this->postForm();
  77. $post['type'] = RiceCardModel::CASH_CARD_ENTITY;
  78. $post['status'] = 1;
  79. if ($model->add($post)) {
  80. return $this->renderSuccess('添加成功');
  81. }
  82. return $this->renderError($model->getError() ?: '添加失败');
  83. }
  84. /**
  85. * 编辑兑换卡
  86. * @param int $id
  87. * @return mixed
  88. */
  89. public function editExchange(int $id)
  90. {
  91. // 详情
  92. $model = RiceCardModel::detail($id);
  93. // 更新记录
  94. if ($model->edit($this->postForm())) {
  95. return $this->renderSuccess('更新成功');
  96. }
  97. return $this->renderError($model->getError() ?: '更新失败');
  98. }
  99. /**
  100. * 编辑现金卡
  101. * @param int $id
  102. * @return mixed
  103. */
  104. public function editCash(int $id)
  105. {
  106. // 详情
  107. $model = RiceCardModel::detail($id);
  108. // 更新记录
  109. if ($model->edit($this->postForm())) {
  110. return $this->renderSuccess('更新成功');
  111. }
  112. return $this->renderError($model->getError() ?: '更新失败');
  113. }
  114. /**
  115. * 修改状态(上下架)
  116. * @param array $ids id集
  117. * @param bool $state 为true表示上架
  118. * @return array
  119. */
  120. public function state(array $ids, bool $state)
  121. {
  122. $model = new RiceCardModel;
  123. if (!$model->setStatus($ids, $state)) {
  124. return $this->renderError($model->getError() ?: '操作失败');
  125. }
  126. return $this->renderSuccess('操作成功');
  127. }
  128. public function simpleList(){
  129. $list = RiceCardModel::getSimpleList();
  130. return $this->renderSuccess(compact('list'));
  131. }
  132. }