Express.php 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
  4. // +----------------------------------------------------------------------
  5. // | Copyright (c) 2016~2020 https://www.crmeb.com All rights reserved.
  6. // +----------------------------------------------------------------------
  7. // | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
  8. // +----------------------------------------------------------------------
  9. // | Author: CRMEB Team <admin@crmeb.com>
  10. // +----------------------------------------------------------------------
  11. namespace app\admin\controller\system;
  12. use service\FormBuilder as Form;
  13. use service\JsonService as Json;
  14. use think\Request;
  15. use think\Url;
  16. use app\admin\model\system\Express as ExpressModel;
  17. use app\admin\controller\AuthController;
  18. /**
  19. * 物流公司管理控制器
  20. * Class SystemMenus
  21. * @package app\admin\controller\system
  22. */
  23. class Express extends AuthController
  24. {
  25. /**
  26. * 显示资源列表
  27. *
  28. * @return \think\Response
  29. */
  30. public function index()
  31. {
  32. $params = parent::getMore([
  33. ['keyword', '']
  34. ], $this->request);
  35. $this->assign(ExpressModel::systemPage($params));
  36. $this->assign(compact('params'));
  37. return $this->fetch();
  38. }
  39. /**
  40. * 显示创建资源表单页.
  41. *
  42. * @return \think\Response
  43. */
  44. public function create($cid = 0)
  45. {
  46. $formbuider = [
  47. Form::input('name', '公司名称')->required('公司名称名称必填'),
  48. Form::input('code', '编码'),
  49. Form::number('sort', '排序', 0),
  50. Form::radio('is_show', '是否启用', 1)->options([['value' => 0, 'label' => '隐藏'], ['value' => 1, 'label' => '启用']]),
  51. ];
  52. $form = Form::make_post_form('添加物流公司', $formbuider, Url::build('save'), 2);
  53. $this->assign(compact('form'));
  54. return $this->fetch('public/form-builder');
  55. }
  56. /**
  57. * 保存新建的资源
  58. *
  59. * @param \think\Request $request
  60. * @return \think\Response
  61. */
  62. public function save(Request $request)
  63. {
  64. $data = parent::postMore([
  65. 'name',
  66. 'code',
  67. ['sort', 0],
  68. ['is_show', 0]], $request);
  69. if (!$data['name']) return Json::fail('请输入公司名称');
  70. ExpressModel::set($data);
  71. return Json::successful('添加公司成功!');
  72. }
  73. /**
  74. * 显示编辑资源表单页.
  75. *
  76. * @param int $id
  77. * @return \think\Response
  78. */
  79. public function edit($id)
  80. {
  81. $menu = ExpressModel::get($id);
  82. if (!$menu) return Json::fail('数据不存在!');
  83. $formbuider = [
  84. Form::input('name', '公司名称', $menu['name']),
  85. Form::input('code', '编码', $menu['code']),
  86. Form::number('sort', '排序', $menu['sort']),
  87. Form::radio('is_show', '是否启用', $menu['is_show'])->options([['value' => 0, 'label' => '隐藏'], ['value' => 1, 'label' => '启用']])
  88. ];
  89. $form = Form::make_post_form('添加物流公司', $formbuider, Url::build('update', array('id' => $id)), 2);
  90. $this->assign(compact('form'));
  91. return $this->fetch('public/form-builder');
  92. }
  93. /**
  94. * 保存更新的资源
  95. *
  96. * @param \think\Request $request
  97. * @param int $id
  98. * @return \think\Response
  99. */
  100. public function update(Request $request, $id)
  101. {
  102. $data = parent::postMore([
  103. 'name',
  104. 'code',
  105. ['sort', 0],
  106. ['is_show', 0]], $request);
  107. if (!$data['name']) return Json::fail('请输入公司名称');
  108. if (!ExpressModel::get($id)) return Json::fail('编辑的记录不存在!');
  109. ExpressModel::edit($data, $id);
  110. return Json::successful('修改成功!');
  111. }
  112. /**
  113. * 删除指定资源
  114. *
  115. * @param int $id
  116. * @return \think\Response
  117. */
  118. public function delete($id)
  119. {
  120. if (!$id) return $this->failed('参数错误,请重新打开');
  121. $res = ExpressModel::destroy($id);
  122. if (!$res)
  123. return Json::fail(ExpressModel::getErrorInfo('删除失败,请稍候再试!'));
  124. else
  125. return Json::successful('删除成功!');
  126. }
  127. }