Provider.php 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. <?php
  2. declare (strict_types = 1);
  3. namespace app\store\controller;
  4. use app\common\model\Provider as ProviderModel;
  5. /**
  6. * 供应商
  7. * Class Provider
  8. * @package app\store\controller
  9. */
  10. class Provider extends Controller
  11. {
  12. /**
  13. * 列表
  14. * @return array
  15. * @throws \think\db\exception\DataNotFoundException
  16. * @throws \think\db\exception\DbException
  17. * @throws \think\db\exception\ModelNotFoundException
  18. */
  19. public function list()
  20. {
  21. $model = new ProviderModel;
  22. $list = $model->getList($this->request->param());
  23. return $this->renderSuccess(compact('list'));
  24. }
  25. /**
  26. * 获取所有记录
  27. * @return array
  28. * @throws \think\db\exception\DataNotFoundException
  29. * @throws \think\db\exception\DbException
  30. * @throws \think\db\exception\ModelNotFoundException
  31. */
  32. public function all()
  33. {
  34. $model = new ProviderModel;
  35. $list = $model->getAll();
  36. return $this->renderSuccess(compact('list'));
  37. }
  38. /**
  39. * 删除
  40. * @param $providerId
  41. * @return array
  42. * @throws \Exception
  43. */
  44. public function delete(int $providerId)
  45. {
  46. // 详情
  47. $model = ProviderModel::detail($providerId);
  48. if (!$model->delete()) {
  49. return $this->renderError($model->getError() ?: '删除失败');
  50. }
  51. return $this->renderSuccess('删除成功');
  52. }
  53. /**
  54. * 详情记录
  55. * @param int $providerId
  56. * @return array
  57. */
  58. public function detail(int $providerId)
  59. {
  60. $detail = ProviderModel::detail($providerId);
  61. return $this->renderSuccess(compact('detail'));
  62. }
  63. /**
  64. * 添加
  65. * @return array|string
  66. */
  67. public function add()
  68. {
  69. // 新增记录
  70. $model = new ProviderModel;
  71. if ($model->add($this->postForm())) {
  72. return $this->renderSuccess('添加成功');
  73. }
  74. return $this->renderError($model->getError() ?: '添加失败');
  75. }
  76. /**
  77. * 编辑
  78. * @param int $providerId
  79. * @return mixed
  80. */
  81. public function edit(int $providerId)
  82. {
  83. // 详情
  84. $model = ProviderModel::detail($providerId);
  85. // 更新记录
  86. if ($model->edit($this->postForm())) {
  87. return $this->renderSuccess('更新成功');
  88. }
  89. return $this->renderError($model->getError() ?: '更新失败');
  90. }
  91. }