123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | Description: 审批流程
  4. // +----------------------------------------------------------------------
  5. // | Author: zjf
  6. // +----------------------------------------------------------------------
  7. namespace app\admin\model;
  8. use app\admin\controller\ApiCommon;
  9. use think\Db;
  10. use app\admin\model\Common;
  11. use think\Request;
  12. use think\Validate;
  13. class Examine extends Common
  14. {
  15. /**
  16. * 为了数据库的整洁,同时又不影响Model和Controller的名称
  17. * 我们约定每个模块的数据表都加上相同的前缀,比如CRM模块用crm作为数据表前缀
  18. */
  19. protected $name = 'examine';
  20. protected $createTime = 'create_time';
  21. protected $updateTime = 'update_time';
  22. protected $autoWriteTimestamp = true;
  23. protected $typesArr = ['crm_contract', 'crm_receivables', 'crm_invoice', 'oa_examine', 'jxc_purchase', 'jxc_retreat', 'jxc_sale', 'jxc_salereturn', 'jxc_payment', 'jxc_collection', 'jxc_allocation', 'jxc_inventory'];
  24. /**
  25. * [getDataList 审批流程list]
  26. * @author zjf
  27. * @param [string] $map [查询条件]
  28. * @param [number] $page [当前页数]
  29. * @param [number] $limit [每页数量]
  30. * @return [array] [description]
  31. */
  32. public function getDataList($request)
  33. {
  34. $request = $this->fmtRequest( $request );
  35. $map = $request['map'] ? : [];
  36. if (isset($map['search'])) {
  37. //普通筛选
  38. $map['a.examine_name'] = ['like', '%'.$map['search'].'%'];
  39. unset($map['search']);
  40. }
  41. $map['a.status'] = ['neq', 3];
  42. $list = db('examine')
  43. ->alias('a')
  44. // ->join('examine_manager_user b','a.examine_id = b.examine_id', 'left')
  45. ->join('admin_user c','a.update_user_id = c.id', 'left')
  46. ->page($request['page'], $request['limit'])
  47. ->field('a.*, c.realname as update_realname, c.thumb_img as update_thumb_img')
  48. ->where($map)
  49. ->order('a.status desc,a.update_time desc')
  50. ->select();
  51. foreach ($list as $k=>$v) {
  52. $list[$k]['status'] = $v['status']==1 ? '启用' : '停用';
  53. $list[$k]['recheck_type'] = $v['recheck_type']==1 ? '从第一层开始' : '从拒绝的层级开始';
  54. // 1 合同 2 回款 3发票 4薪资 5 采购审核 6采购退货审核 7销售审核 8 销售退货审核 9付款单审核10 回款单审核11盘点审核12调拨审核',
  55. switch ($v['label']) {
  56. case '1' : $label = '合同'; break;
  57. case '2' : $label = '回款'; break;
  58. case '3' : $label = '发票'; break;
  59. case '4' : $label = '薪资'; break;
  60. case '5' : $label = '采购审核'; break;
  61. case '6' : $label = '采购退货审核'; break;
  62. case '7' : $label = '销售审核'; break;
  63. case '8' : $label = '销售退货审核'; break;
  64. case '9' : $label = '付款单审核'; break;
  65. case '10' : $label = '回款单审核1'; break;
  66. case '11' : $label = '盘点审核'; break;
  67. case '12' : $label = '调拨审核'; break;
  68. default : $label = ''; break;
  69. }
  70. // 审批流管理员
  71. $manager_user = db('examine_manager_user')
  72. ->alias('a')
  73. ->join('admin_user b','a.user_id = b.id')
  74. ->field('a.user_id, b.realname')
  75. ->where('examine_id', $v['examine_id'])
  76. ->column('user_id');
  77. $list[$k]['managerList'] = $manager_user;
  78. $list[$k]['label'] = $label;
  79. }
  80. $dataCount = db('examine')
  81. ->alias('a')
  82. ->join('examine_manager_user b','a.examine_id = b.examine_id', 'left')
  83. ->join('admin_user c','a.update_user_id = c.id', 'left')
  84. ->where($map)
  85. ->count('a.examine_id');
  86. $data = [];
  87. $data['list'] = $list;
  88. $data['dataCount'] = $dataCount ? : 0;
  89. return $data;
  90. }
  91. /**
  92. * 审批流程详情
  93. * @author zjf
  94. * @param
  95. * @return
  96. */
  97. public function getDataById($examine_id = '')
  98. {
  99. $userModel = new \app\admin\model\User();
  100. $dataInfo = $this->get($examine_id);
  101. if (!$dataInfo) {
  102. $this->error = '数据不存在或已删除';
  103. return false;
  104. }
  105. //审批步骤
  106. $flowList = db('examine_flow')->where(['examine_id' => $examine_id])->where('condition_id', 0)->select();
  107. foreach ($flowList as $k=>$v) {
  108. if($v['examine_type'] == 0){
  109. $conditionList = db('examine_condition')->where(['flow_id' => $v['flow_id']])->select();
  110. foreach ($conditionList as $key => $value) {
  111. $conditionList[$key]['conditionDataList'] = db('examine_condition_data')->where(['condition_id' => $value['condition_id']])->select();
  112. $examineDataList = $this->recursion($value['condition_id']);
  113. $conditionList[$key]['examineDataList'] = $examineDataList;
  114. }
  115. $flowList[$k]['conditionList'] = $conditionList;
  116. }
  117. }
  118. return $flowList;
  119. }
  120. public function recursion($condition_id = '')
  121. {
  122. //审批步骤
  123. $flowList = db('examine_flow')->where(['condition_id' => $condition_id])->select();
  124. foreach ($flowList as $k=>$v) {
  125. if($v['examine_type'] == 0){
  126. $conditionList = db('examine_condition')->where(['flow_id' => $v['flow_id']])->select();
  127. foreach ($conditionList as $key => $value) {
  128. $conditionList[$key]['conditionDataList'] = db('examine_condition_data')->where(['condition_id' => $value['condition_id']])->select();
  129. $examineDataList = $this->recursion($value['condition_id']);
  130. $conditionList[$key]['examineDataList'] = $examineDataList;
  131. }
  132. $flowList[$k]['conditionList'] = $conditionList;
  133. }
  134. }
  135. return $flowList;
  136. }
  137. }