Approval.php 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216
  1. <?php
  2. namespace addons\qingdong\controller;
  3. use addons\qingdong\model\Approval as ApprovalModel;
  4. use addons\qingdong\model\ExamineRecord;
  5. use addons\qingdong\model\File;
  6. use addons\qingdong\model\FormApproval;
  7. use addons\qingdong\model\Message;
  8. use addons\qingdong\model\Staff;
  9. use addons\qingdong\model\Form;
  10. use think\Db;
  11. use think\Exception;
  12. /**
  13. * 工作审批
  14. */
  15. class Approval extends StaffApi {
  16. protected $noNeedLogin = [];
  17. protected $noNeedRight = [];
  18. /**
  19. * 审核审核记录
  20. */
  21. public function examineApprovalList(){
  22. $check_status=input('check_status');//1审核中、2审核通过、3审核未通过
  23. $formapproval_id=input('formapproval_id');//
  24. $times=input('times');//
  25. $where=[];
  26. if($formapproval_id){
  27. $where['formapproval_id']=$formapproval_id;
  28. }
  29. if($times){
  30. $times = explode(',', $times);
  31. $where['createtime']=['between',[strtotime($times[0]),strtotime($times[1])+86400-1]];
  32. }
  33. if ($check_status) {
  34. //0待审核、1审核中、2审核通过、3审核未通过、4撤销
  35. if ($check_status == 1) {
  36. $where['check_status'] = ['in', [0, 1]];
  37. } elseif ($check_status == 2) {
  38. $where['check_status'] = 2;
  39. } elseif ($check_status == 3) {
  40. $where['check_status'] = 3;
  41. } elseif ($check_status == 4) {
  42. $where['check_status'] = 4;
  43. } elseif ($check_status == 9) {
  44. $where['check_status'] = 9;
  45. }
  46. }
  47. $type = input('type', 0);// 0 全部 1 我创建 2 下属创建
  48. if ($type == 1) {//我的客户
  49. $where['create_staff_id'] = $this->auth->id;
  50. } elseif ($type == 2) {//下属负责的客户
  51. $where['create_staff_id'] = ['in', Staff::getLowerStaffId()];
  52. }else{
  53. $where['create_staff_id'] = ['in', Staff::getMyStaffIds()];
  54. }
  55. $staff_id=$this->auth->id;
  56. $approvals= ApprovalModel::where($where)->where(function ($query) use ($staff_id){
  57. $query->where('create_staff_id',$staff_id)
  58. ->whereOr('','exp', Db::raw('FIND_IN_SET(' . $staff_id. ',flow_staff_ids)'));
  59. })->with(['createStaff','formapproval'])->order('id desc')->paginate();
  60. $this->success('请求成功',$approvals);
  61. }
  62. /**
  63. * 获取工作列表
  64. */
  65. public function getList() {
  66. $list = FormApproval::where([])->field('id,name,img')->select();
  67. $this->success('请求成功', $list);
  68. }
  69. /**
  70. * 获取form表单
  71. */
  72. public function getFormapproval() {
  73. $id = input('id');
  74. $form = FormApproval::where(['id' => $id])->find();
  75. $staff = Staff::where(['id' => ['in',explode(',', $form['flow_staff_ids'])]])->field('id,name,img')->select();
  76. $forminfo = Form::where(array('id'=>$form['form_id']))->find();
  77. $data=json_decode($forminfo['data'], true)['data']??[];
  78. $this->success('请求成功',['data'=>$data,'staff'=>$staff] );
  79. }
  80. /**
  81. * 添加审批
  82. */
  83. public function addApproval() {
  84. $params = $this->request->post();
  85. if(empty( $params['data'])){
  86. $this->error('数据不能为空');
  87. }
  88. if(empty( $params['formapproval_id'])){
  89. $this->error('表单id不能为空');
  90. }
  91. $result = ApprovalModel::createApproval($params);
  92. $this->success('保存成功');
  93. }
  94. /**
  95. * 获取审批详情
  96. */
  97. public function getDetail(){
  98. $id = input('id');
  99. if(empty($id)){
  100. $this->error('参数不能为空');
  101. }
  102. $approval=ApprovalModel::where(['id'=>$id])->with(['formapproval'])->find()->toArray();
  103. $type = Form::where(array('id'=>$approval['formapproval']['form_id']))->value('type');
  104. $form = Form::getDataValue($type,$approval['content']);
  105. foreach($form as $k=>$v){
  106. if($v['component'] == 'uploadImage' || $v['component'] == 'uploadFile'){
  107. if(key_exists($v['id'],$approval['content'])){
  108. if(isset($approval['content'][$v['id']]) && $approval['content'][$v['id']]){
  109. $whereT['id'] = array('in',$approval['content'][$v['id']]);
  110. $fileinfo = File::where($whereT)->field('id,name,file_path')->select();
  111. if($fileinfo){
  112. $approval['content'][$v['id']] = $fileinfo;
  113. }
  114. }
  115. }
  116. }elseif($v['component'] == 'select'){
  117. if(isset($v['config']['multiple']) && $v['config']['multiple'] == true){
  118. if(key_exists($v['id'],$approval['content'])){
  119. if(is_array($approval['content'][$v['id']]) && $approval['content'][$v['id']]){
  120. $approval['content'][$v['id']] = implode(',',$approval['content'][$v['id']]);
  121. }
  122. }
  123. }
  124. }
  125. }
  126. if ($approval['check_status'] == 0 || $approval['check_status'] == 1) {
  127. $approval['is_examine'] = ExamineRecord::isExaminse(ExamineRecord::APPROVAL_TYPE, $id);
  128. } else {
  129. $approval['is_examine'] = 0;
  130. }
  131. $approval['is_operation']=0;
  132. if($approval['create_staff_id'] == $this->auth->id){
  133. //是否可以操作
  134. $approval['is_operation']=1;
  135. }
  136. Message::setRead(Message::APPROVAL_TYPE,$id,$this->auth->id);
  137. $this->success('请求成功',$approval);
  138. }
  139. /**
  140. * 修改审批
  141. */
  142. public function editApproval(){
  143. $id = input('id');
  144. $params = $this->request->post();
  145. $row = ApprovalModel::where(['id' => $id, 'check_status' => ['in', [3, 4]]])->find();
  146. if (empty($row)) {
  147. $this->error('审批信息不存在');
  148. }
  149. if(empty( $params['data'])){
  150. $this->error('数据不能为空');
  151. }
  152. if(empty( $params['formapproval_id'])){
  153. $this->error('表单id不能为空');
  154. }
  155. if(empty( $params['relation_type'])){
  156. $this->error('关联类型不能为空');
  157. }
  158. Db::startTrans();
  159. try {
  160. $result = ApprovalModel::updateApproval($params);
  161. Db::commit();
  162. } catch (Exception $e) {
  163. Db::rollback();
  164. $this->error($e->getMessage());
  165. }
  166. $this->success('修改信息成功');
  167. }
  168. /**
  169. * 撤回审批
  170. */
  171. public function cancel(){
  172. $id = input('id');
  173. $customer = ApprovalModel::where(['id' => $id, 'check_status' => ['in', [0, 1]]])->find();
  174. if (empty($customer)) {
  175. $this->error('信息不存在');
  176. }
  177. Db::startTrans();
  178. try {
  179. ApprovalModel::where(['id' => $id])->update(['check_status' => 4]);
  180. ExamineRecord::cancelExaminse(ExamineRecord::APPROVAL_TYPE,$id);
  181. Db::commit();
  182. } catch (Exception $e) {
  183. Db::rollback();;
  184. $this->error($e->getMessage());
  185. }
  186. $this->success('撤回成功');
  187. }
  188. }