Store.php 2.9 KB

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