Store.php 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  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. */
  54. public function add()
  55. {
  56. $model = new WxappModel;
  57. if (!$this->request->isAjax()) {
  58. return $this->fetch('add');
  59. }
  60. // 新增记录
  61. if ($model->add($this->postData('store'))) {
  62. return $this->renderSuccess('添加成功', url('store/index'));
  63. }
  64. return $this->renderError($model->getError() ?: '添加失败');
  65. }
  66. /**
  67. * 回收小程序
  68. * @param $wxapp_id
  69. * @return array
  70. * @throws \think\exception\DbException
  71. */
  72. public function recovery($wxapp_id)
  73. {
  74. // 小程序详情
  75. $model = WxappModel::detail($wxapp_id);
  76. if (!$model->recycle()) {
  77. return $this->renderError('操作失败');
  78. }
  79. return $this->renderSuccess('操作成功');
  80. }
  81. /**
  82. * 移出回收站
  83. * @param $wxapp_id
  84. * @return array
  85. * @throws \think\exception\DbException
  86. */
  87. public function move($wxapp_id)
  88. {
  89. // 小程序详情
  90. $model = WxappModel::detail($wxapp_id);
  91. if (!$model->recycle(false)) {
  92. return $this->renderError('操作失败');
  93. }
  94. return $this->renderSuccess('操作成功');
  95. }
  96. /**
  97. * 删除小程序
  98. * @param $wxapp_id
  99. * @return array
  100. * @throws \think\exception\DbException
  101. */
  102. public function delete($wxapp_id)
  103. {
  104. // 小程序详情
  105. $model = WxappModel::detail($wxapp_id);
  106. if (!$model->setDelete()) {
  107. return $this->renderError('操作失败');
  108. }
  109. return $this->renderSuccess('操作成功');
  110. }
  111. }