Process.php 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. <?php
  2. namespace app\admin\controller;
  3. use app\BaseController;
  4. use think\App;
  5. use think\facade\Db;
  6. //流程单
  7. class Process extends BaseController
  8. {
  9. public $post="";
  10. public function __construct(App $app)
  11. {
  12. parent::__construct($app);
  13. $this->post = $this->request->post();
  14. }
  15. /**
  16. * @return \think\response\Json|void
  17. * @throws \think\db\exception\DataNotFoundException
  18. * @throws \think\db\exception\DbException
  19. * @throws \think\db\exception\ModelNotFoundException
  20. */
  21. public function list(){
  22. $page =isset($this->post['page']) &&$this->post['page']!="" ? intval($this->post['page']) : 1;
  23. $size =isset($this->post['size']) &&$this->post['size']!="" ? intval($this->post['size']) : 10;
  24. $count = Db::name("process")->where('is_del',0)->count();
  25. $total = ceil($count/$size);
  26. $page = $page>$total ? $total:$page;
  27. $list = Db::name("process")->where('is_del', 0)->page($page, $size)->select();
  28. return app_show(0,"获取成功",["list"=>$list,"count"=>$count]);
  29. }
  30. /**
  31. * @return \think\response\Json|void
  32. * @throws \think\db\exception\DataNotFoundException
  33. * @throws \think\db\exception\DbException
  34. * @throws \think\db\exception\ModelNotFoundException
  35. */
  36. public function info(){
  37. $id =isset($this->post['id']) &&$this->post['id']!="" ? intval($this->post['id']) : "";
  38. if($id==""){
  39. return error_show(1004,"参数id 不能为空");
  40. }
  41. $info = Db::name("process")->where(['id'=>$id,"is_del"=>0])->find();
  42. if(empty($info)){
  43. return error_show(1004,"流程信息未找到");
  44. }
  45. $list=Db::name("action_process")->where(["pid"=>$id,"is_del"=>0])->order("weight,id")->select();
  46. $info['item'] = empty($list) ? []:$list;
  47. return app_show(0,"获取成功",$info);
  48. }
  49. /**
  50. * @return \think\response\Json|void
  51. * @throws \think\db\exception\DataNotFoundException
  52. * @throws \think\db\exception\DbException
  53. * @throws \think\db\exception\ModelNotFoundException
  54. */
  55. public function process(){
  56. $process_type = isset($this->post['type'])&&$this->post['type']!="" ? $this->post['type']:"";
  57. if($process_type==""){
  58. return error_show(1004,"参数type 不能为空");
  59. }
  60. $orderCode = isset($this->post['orderCode'])&&$this->post['orderCode']!="" ? $this->post['orderCode']:"";
  61. if($orderCode==""){
  62. return error_show(1004,"参数orderCode不能为空");
  63. }
  64. $list = Db::name("action_process")
  65. ->withoutField('updatetime')//排除更新时间
  66. ->where(['order_type'=>$process_type,"is_del"=>0,"status"=>1])
  67. ->order("weight desc,id desc")
  68. ->select()
  69. ->toArray();
  70. //根据所有的状态,查询对应的操作
  71. $order_process_s = array_column($list,'order_process');
  72. $node= Db::name("process_order")
  73. ->where(["order_type"=>$process_type,"order_code"=>$orderCode])
  74. ->whereIn('action_process',$order_process_s)
  75. ->column('id,action_uid,action_name,addtime','action_process');
  76. $data=[];
  77. foreach ($list as $value){
  78. // $node = Db::name("process_order")
  79. // ->where([
  80. // "order_type"=>$value['order_type'],
  81. // "action_process"=>$value['order_process'],
  82. // "order_code"=>$orderCode])
  83. // ->find();
  84. $value['action_uid']= isset($node[$value['order_process']]['action_uid']) ? $node[$value['order_process']]['action_uid']:'';
  85. $value['action_name']= isset($node[$value['order_process']]['action_name']) ? $node[$value['order_process']]['action_name']:'';
  86. $value['addtime']= isset($node[$value['order_process']]['addtime']) ? $node[$value['order_process']]['addtime']:'';
  87. $data[]=$value;
  88. }
  89. return app_show(0,"获取成功",$data);
  90. }
  91. }