Express.php 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  1. <?php
  2. namespace app\adminapi\controller\v1\freight;
  3. use app\models\system\Express as ExpressModel;
  4. use app\adminapi\controller\AuthController;
  5. use crmeb\services\FormBuilder as Form;
  6. use crmeb\services\UtilService as Util;
  7. use think\facade\Route as Url;
  8. use think\Request;
  9. class Express extends AuthController
  10. {
  11. /**
  12. * 显示资源列表
  13. *
  14. * @return \think\Response
  15. */
  16. public function index()
  17. {
  18. $params = Util::getMore([
  19. ['page', 1],
  20. ['limit', 20],
  21. ['keyword', '']
  22. ], $this->request);
  23. $list = ExpressModel::systemPage($params);
  24. return $this->success($list);
  25. }
  26. /**
  27. * 显示创建资源表单页.
  28. *
  29. * @return \think\Response
  30. */
  31. public function create()
  32. {
  33. $formbuider = [
  34. Form::input('name', '公司名称')->required('公司名称名称必填'),
  35. Form::input('code', '编码'),
  36. Form::number('sort', '排序', 0),
  37. Form::radio('is_show', '是否启用', 1)->options([['value' => 0, 'label' => '隐藏'], ['value' => 1, 'label' => '启用']]),
  38. ];
  39. return $this->makePostForm('添加物流公司', $formbuider, Url::buildUrl('/freight/express'), 'POST');
  40. }
  41. /**
  42. * 保存新建的资源
  43. *
  44. * @param \think\Request $request
  45. * @return \think\Response
  46. */
  47. public function save(Request $request)
  48. {
  49. $data = Util::postMore([
  50. 'name',
  51. 'code',
  52. ['sort', 0],
  53. ['is_show', 0]]);
  54. if (!$data['name']) return $this->fail('请输入公司名称');
  55. ExpressModel::create($data);
  56. return $this->success('添加公司成功!');
  57. }
  58. /**
  59. * 显示指定的资源
  60. *
  61. * @param int $id
  62. * @return \think\Response
  63. */
  64. public function read($id)
  65. {
  66. //
  67. }
  68. /**
  69. * 显示编辑资源表单页.
  70. *
  71. * @param int $id
  72. * @return \think\Response
  73. */
  74. public function edit($id)
  75. {
  76. $menu = ExpressModel::get($id);
  77. if (!$menu) return $this->fail('数据不存在!');
  78. $formbuider = [
  79. Form::input('name', '公司名称', $menu['name']),
  80. Form::input('code', '编码', $menu['code']),
  81. Form::number('sort', '排序', $menu['sort']),
  82. Form::radio('is_show', '是否启用', $menu['is_show'])->options([['value' => 0, 'label' => '隐藏'], ['value' => 1, 'label' => '启用']])
  83. ];
  84. return $this->makePostForm('编辑物流公司', $formbuider, Url::buildUrl('/freight/express/' . $id), 'PUT');
  85. }
  86. /**
  87. * 保存更新的资源
  88. *
  89. * @param \think\Request $request
  90. * @param int $id
  91. * @return \think\Response
  92. */
  93. public function update(Request $request, $id)
  94. {
  95. $data = Util::postMore([
  96. 'name',
  97. 'code',
  98. ['sort', 0],
  99. ['is_show', 0]]);
  100. if (!$data['name']) return $this->fail('请输入公司名称');
  101. if (!ExpressModel::get($id)) return $this->fail('编辑的记录不存在!');
  102. ExpressModel::edit($data, $id);
  103. return $this->success('修改成功!');
  104. }
  105. /**
  106. * 删除指定资源
  107. *
  108. * @param int $id
  109. * @return \think\Response
  110. */
  111. public function delete($id)
  112. {
  113. if (!$id) return $this->fail('参数错误,请重新打开');
  114. $res = ExpressModel::destroy($id);
  115. if (!$res)
  116. return $this->fail(ExpressModel::getErrorInfo('删除失败,请稍候再试!'));
  117. else
  118. return $this->success('删除成功!');
  119. }
  120. /**
  121. * 修改状态
  122. * @param int $id
  123. * @param string $status
  124. * @return mixed
  125. */
  126. public function set_status($id = 0, $status = '')
  127. {
  128. if ($status == '' || $id == 0) return $this->fail('参数错误');
  129. ExpressModel::where(['id' => $id])->update(['is_show' => $status]);
  130. return $this->success($status == 0 ? '隐藏成功' : '显示成功');
  131. }
  132. }