0
0

ConveyPlan.php 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160
  1. <?php
  2. namespace app\admin\controller;
  3. use think\App;
  4. use think\Db;
  5. class ConveyPlan extends Auth
  6. {
  7. public function __construct(App $app = null) {
  8. parent::__construct($app);
  9. $this->table='convey_plan';
  10. $this->model= new \app\common\model\ConveyPlan();
  11. }
  12. public function index(){
  13. if(request()->isAjax()){
  14. //分页参数
  15. $length = input('rows',10,'intval'); //每页条数
  16. $page = input('page',1,'intval'); //第几页
  17. $start = ($page - 1) * $length; //分页开始位置
  18. //排序
  19. $sortRow = input('sidx','id','trim'); //排序列
  20. $sort = input('sord','desc','trim'); //排序方式
  21. $order = $sortRow.' '.$sort;
  22. $title = input('title','','trim');
  23. if($title){
  24. $map[] = ['name','like','%'.$title.'%'];
  25. }
  26. $enable = input('enable','','trim');
  27. if($enable != ''){
  28. $map[] = ['enable','=',$enable];
  29. }
  30. $map[] = ['del','=',0];
  31. $map[] = ['org_id','=',$this->orgId];
  32. $map= empty($map) ? true: $map;
  33. //数据查询
  34. $lists = db($this->table)->where($map)->limit($start,$length)->order($order)->select();
  35. foreach ($lists as $k=>$v){
  36. $lists[$k]['real_name'] = Db::name('user')
  37. ->where('id',$v['user_id'])
  38. ->value('real_name');
  39. }
  40. //数据返回
  41. $totalCount = db($this->table)->where($map)->count();
  42. $totalPage = ceil($totalCount/$length);
  43. $result['page'] = $page;
  44. $result['total'] = $totalPage;
  45. $result['records'] = $totalCount;
  46. $result['rows'] = $lists;
  47. return json($result);
  48. }else{
  49. return $this->fetch();
  50. }
  51. }
  52. /**
  53. * 新增/编辑
  54. */
  55. public function add($id=0){
  56. if(request()->isPost()){
  57. $res = $this->model->updates();
  58. if($res){
  59. $this->success('操作成功',url('index'));
  60. }else{
  61. $this->error($this->model->getError());
  62. }
  63. }else{
  64. if($id){
  65. $info =db($this->table)->where('id',$id)->find();
  66. $info['weeks'] = explode(',',$info['weeks']);
  67. $this->assign('info',$info);
  68. }
  69. $options= [
  70. [
  71. 'id'=>1,
  72. 'title'=>'星期一'
  73. ],
  74. [
  75. 'id'=>2,
  76. 'title'=>'星期二'
  77. ],
  78. [
  79. 'id'=>3,
  80. 'title'=>'星期三'
  81. ],
  82. [
  83. 'id'=>4,
  84. 'title'=>'星期四'
  85. ],
  86. [
  87. 'id'=>5,
  88. 'title'=>'星期五'
  89. ],
  90. [
  91. 'id'=>6,
  92. 'title'=>'星期六'
  93. ], [
  94. 'id'=>0,
  95. 'title'=>'星期日'
  96. ]
  97. ];
  98. $user = (new \app\common\model\WorkTypeMode())->getRolesUser(3, $this->orgId,1);
  99. $newUser = [];
  100. foreach ($user as $k => $v) {
  101. foreach ($v['user'] as $k1 => $v1) {
  102. $newUser[] = [
  103. 'id'=>$v1['id'],
  104. 'title'=>$v1['real_name'],
  105. ];
  106. }
  107. }
  108. $this->assign('user',$newUser);
  109. $this->assign('option',$options);
  110. return $this->fetch();
  111. }
  112. }
  113. /**
  114. * 删除记录
  115. * @param int $id
  116. */
  117. public function del($id=0){
  118. if(!$id){
  119. $this->error('参数错误');
  120. }
  121. $res = db($this->table)->where('id',$id)->setField('del',1);
  122. if($res){
  123. $this->success('删除成功');
  124. }else{
  125. $this->error('删除失败');
  126. }
  127. }
  128. /**
  129. * 改变字段值
  130. * @param int $fv
  131. * @param string $fn
  132. * @param int $fv
  133. */
  134. public function changeField($id=0,$fn='',$fv=0){
  135. if(!$fn||!$id){
  136. $this->error('参数错误');
  137. }
  138. $res = db($this->table)->where('id',$id)->setField($fn,$fv);
  139. if($res){
  140. $this->success('操作成功');
  141. }else{
  142. $this->error('操作失败');
  143. }
  144. }
  145. }