Store.php 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. <?php
  2. /**
  3. *
  4. * @copyright ©2020 点小铺
  5. * @author hanj
  6. * @link: https://dyuit.com
  7. * Created by VSCode
  8. */
  9. namespace app\admin\controller;
  10. use app\admin\model\Wxapp as WxappModel;
  11. use app\admin\model\store\User as StoreUser;
  12. /**
  13. * 小程序商城管理
  14. * Class Store
  15. * @package app\admin\controller
  16. */
  17. class Store extends Controller
  18. {
  19. /**
  20. * 小程序列表
  21. * @return mixed
  22. * @throws \think\exception\DbException
  23. */
  24. public function index()
  25. {
  26. $model = new WxappModel;
  27. return $this->fetch('index', [
  28. 'list' => $list = $model->getList(),
  29. 'names' => $model->getStoreName($list)
  30. ]);
  31. }
  32. /**
  33. * 进入商城
  34. * @param $wxapp_id
  35. * @throws \think\Exception
  36. * @throws \think\exception\DbException
  37. */
  38. public function enter($wxapp_id)
  39. {
  40. $model = new StoreUser;
  41. $model->login($wxapp_id);
  42. $this->redirect('store/index/index');
  43. }
  44. /**
  45. * 回收站列表
  46. * @return mixed
  47. * @throws \think\exception\DbException
  48. */
  49. public function recycle()
  50. {
  51. $model = new WxappModel;
  52. return $this->fetch('recycle', [
  53. 'list' => $list = $model->getList(true),
  54. 'names' => $model->getStoreName($list)
  55. ]);
  56. }
  57. /**
  58. * 添加小程序
  59. * @return array|mixed
  60. * @throws \think\exception\PDOException
  61. */
  62. public function add()
  63. {
  64. $model = new WxappModel;
  65. if (!$this->request->isAjax()) {
  66. return $this->fetch('add');
  67. }
  68. // 新增记录
  69. if ($model->add($this->postData('store'))) {
  70. return $this->renderSuccess('添加成功', url('store/index'));
  71. }
  72. return $this->renderError($model->getError() ?: '添加失败');
  73. }
  74. /**
  75. * 回收小程序
  76. * @param $wxapp_id
  77. * @return array
  78. * @throws \think\exception\DbException
  79. */
  80. public function recovery($wxapp_id)
  81. {
  82. // 小程序详情
  83. $model = WxappModel::detail($wxapp_id);
  84. if (!$model->recycle()) {
  85. return $this->renderError('操作失败');
  86. }
  87. return $this->renderSuccess('操作成功');
  88. }
  89. /**
  90. * 移出回收站
  91. * @param $wxapp_id
  92. * @return array
  93. * @throws \think\exception\DbException
  94. */
  95. public function move($wxapp_id)
  96. {
  97. // 小程序详情
  98. $model = WxappModel::detail($wxapp_id);
  99. if (!$model->recycle(false)) {
  100. return $this->renderError('操作失败');
  101. }
  102. return $this->renderSuccess('操作成功');
  103. }
  104. /**
  105. * 删除小程序
  106. * @param $wxapp_id
  107. * @return array
  108. * @throws \think\exception\DbException
  109. */
  110. public function delete($wxapp_id)
  111. {
  112. // 小程序详情
  113. $model = WxappModel::detail($wxapp_id);
  114. if (!$model->setDelete()) {
  115. return $this->renderError('操作失败');
  116. }
  117. return $this->renderSuccess('操作成功');
  118. }
  119. }