Staff.php 2.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. <?php
  2. /**
  3. * @copyright Copyright (c) 2017 https://www.sapixx.com All rights reserved.
  4. * @license Licensed (http://www.apache.org/licenses/LICENSE-2.0).
  5. * @author pillar<ltmn@qq.com>
  6. * 回收人员
  7. */
  8. namespace app\green\controller;
  9. use app\green\model\GreenStaff;
  10. class Staff extends Common{
  11. public function initialize(){
  12. parent::initialize();
  13. $this->assign('pathMaps',[['name'=>'回收人员','url'=>url("staff/index")]]);
  14. }
  15. /**
  16. * 列表
  17. */
  18. public function index(){
  19. $view['lists'] = GreenStaff::where(['member_miniapp_id' => $this->member_miniapp_id])->order('sort desc,id desc')->paginate(20);
  20. return view()->assign($view);
  21. }
  22. /**
  23. * 编辑或添加
  24. * @return void
  25. */
  26. public function edit(){
  27. if(request()->isAjax()){
  28. $id = $this->request->param('id/d');
  29. $data = [
  30. 'uid' => $this->request->param('uid/d'),
  31. 'title' => $this->request->param('title/s'),
  32. 'about' => $this->request->param('about/s'),
  33. 'operate_id' => $this->founder ? $this->request->param('operate_id/d') : $this->operate_id,
  34. 'member_miniapp_id' => $this->member_miniapp_id,
  35. 'update_time' => time(),
  36. ];
  37. $validate = $this->validate($data,'Staff.edit');
  38. if(true !== $validate){
  39. return enjson(0,$validate);
  40. }
  41. if($id > 0){
  42. $data['id'] = $id;
  43. $result = GreenStaff::update($data);
  44. }else{
  45. $data['create_time'] = time();
  46. $result = GreenStaff::create($data);
  47. }
  48. if($result){
  49. return enjson(200,'操作成功');
  50. }else{
  51. return enjson(0);
  52. }
  53. }else{
  54. $view['info'] = GreenStaff::where(['id' => $this->request->param('id/d',0),'member_miniapp_id' => $this->member_miniapp_id])->find();
  55. return view()->assign($view);
  56. }
  57. }
  58. /**
  59. * 排序
  60. */
  61. public function sort(){
  62. if(request()->isAjax()){
  63. $data = [
  64. 'sort' => $this->request->param('sort/d'),
  65. 'id' => $this->request->param('id/d'),
  66. ];
  67. $validate = $this->validate($data,'Staff.sort');
  68. if(true !== $validate){
  69. return enjson(0,$validate);
  70. }
  71. $result = GreenStaff::update(['sort'=>$data['sort']],['id' => $data['id']]);
  72. if($result){
  73. return enjson(200);
  74. }else{
  75. return enjson(0);
  76. }
  77. }
  78. }
  79. //删除
  80. public function delete(int $id){
  81. $result = GreenStaff::destroy($id);
  82. if($result){
  83. return enjson(200);
  84. }else{
  85. return enjson(403,'删除失败');
  86. }
  87. }
  88. }