ConveyPlanAddr.php 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  1. <?php
  2. namespace app\admin\controller;
  3. use think\App;
  4. use think\Db;
  5. class ConveyPlanAddr extends Auth
  6. {
  7. public function __construct(App $app = null) {
  8. parent::__construct($app);
  9. $this->table='convey_plan_addr';
  10. $this->model= new \app\common\model\ConveyPlanAddr();
  11. }
  12. public function index($id){
  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. $map1[] = ['org_id','=',$this->orgId];
  25. $map1[] = ['del','=',0];
  26. $map1[] = ['enable','=',1];
  27. $map1[] = ['title','like','%'.$title.'%'];
  28. $map1[]=['','exp',Db::raw("FIND_IN_SET(2,types)")];
  29. $address = Db::name('address')
  30. ->where($map1)
  31. ->column('id');
  32. if(empty($address)){
  33. $map[] = ['addr_id','=',0];
  34. }else{
  35. $map[] = ['addr_id','in',$address];
  36. }
  37. }
  38. $enable = input('enable','','trim');
  39. if($enable != ''){
  40. $map[] = ['enable','=',$enable];
  41. }
  42. $map[] = ['del','=',0];
  43. $map[] = ['org_id','=',$this->orgId];
  44. $map[] = ['plan_id','=',$id];
  45. $map= empty($map) ? true: $map;
  46. //数据查询
  47. $lists = db($this->table)->where($map)
  48. ->limit($start,$length)->order($order)->select();
  49. foreach ($lists as $k=>$v){
  50. $lists[$k]['address_title'] = Db::name('address')
  51. ->where('id',$v['addr_id'])
  52. ->value('title');
  53. $count = Db::name('convey_plan_record')
  54. ->where('addr_id',$v['addr_id'])
  55. ->where('CREATE_YYYYMMDD',date('Ymd'))
  56. ->count();
  57. $lists[$k]['count'] = $count;
  58. }
  59. //数据返回
  60. $totalCount = db($this->table)->where($map)->count();
  61. $totalPage = ceil($totalCount/$length);
  62. $result['page'] = $page;
  63. $result['total'] = $totalPage;
  64. $result['records'] = $totalCount;
  65. $result['rows'] = $lists;
  66. return json($result);
  67. }else{
  68. $info = Db::name('convey_plan')
  69. ->where('id',$id)
  70. ->find();
  71. $this->assign('info',$info);
  72. $this->assign('id',$id);
  73. return $this->fetch();
  74. }
  75. }
  76. /**
  77. * 新增/编辑
  78. */
  79. public function add($id=0){
  80. $pid = input('pid','');
  81. if(request()->isPost()){
  82. $res = $this->model->updates();
  83. if($res){
  84. $this->success('操作成功',url('index'));
  85. }else{
  86. $this->error($this->model->getError());
  87. }
  88. }else{
  89. if($id){
  90. $info =db($this->table)->where('id',$id)->find();
  91. if($info){
  92. $pid = $info['plan_id'];
  93. }
  94. $this->assign('info',$info);
  95. }
  96. $address = (new \app\common\model\Address())->getListByType(2,$this->orgId);
  97. $this->assign('address',$address);
  98. $this->assign('pid',$pid);
  99. return $this->fetch();
  100. }
  101. }
  102. /**
  103. * 删除记录
  104. * @param int $id
  105. */
  106. public function del($id=0){
  107. if(!$id){
  108. $this->error('参数错误');
  109. }
  110. $res = db($this->table)->where('id',$id)->setField('del',1);
  111. if($res){
  112. $this->success('删除成功');
  113. }else{
  114. $this->error('删除失败');
  115. }
  116. }
  117. /**
  118. * 改变字段值
  119. * @param int $fv
  120. * @param string $fn
  121. * @param int $fv
  122. */
  123. public function changeField($id=0,$fn='',$fv=0){
  124. if(!$fn||!$id){
  125. $this->error('参数错误');
  126. }
  127. $res = db($this->table)->where('id',$id)->setField($fn,$fv);
  128. if($res){
  129. $this->success('操作成功');
  130. }else{
  131. $this->error('操作失败');
  132. }
  133. }
  134. }