123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | Description: 审批意见
  4. // +----------------------------------------------------------------------
  5. // | Author: Michael_xu | gengxiaoxu@5kcrm.com
  6. // +----------------------------------------------------------------------
  7. namespace app\admin\model;
  8. use think\Db;
  9. use app\admin\model\Common;
  10. use think\Request;
  11. use think\Validate;
  12. class ExamineRecord extends Common
  13. {
  14. /**
  15. * 为了数据库的整洁,同时又不影响Model和Controller的名称
  16. * 我们约定每个模块的数据表都加上相同的前缀,比如CRM模块用crm作为数据表前缀
  17. */
  18. protected $name = 'admin_examine_record';
  19. /**
  20. * 审批意见(创建)
  21. * @param types 关联对象
  22. * @param types_id 联对象ID
  23. * @param flow_id 审批流程ID
  24. * @param step_id 审批步骤ID
  25. * @param user_id 审批人ID
  26. * @param status 1通过0驳回
  27. * @return
  28. */
  29. public function createData($param)
  30. {
  31. if ($this->data($param)->allowField(true)->save()) {
  32. $data = [];
  33. $data['record_id'] = $this->record_id;
  34. return $data;
  35. } else {
  36. $this->error = '添加失败';
  37. return false;
  38. }
  39. }
  40. /**
  41. * 审批意见(列表)
  42. * @param types 关联对象
  43. * @param types_id 联对象ID
  44. * @return
  45. */
  46. public function getDataList($param)
  47. {
  48. $userModel = new \app\admin\model\User();
  49. if (empty($param['types']) || empty($param['types_id'])) {
  50. return [];
  51. }
  52. $result = [];
  53. # 获取创建者信息(业务审批)
  54. if (in_array($param['types'], ['crm_contract', 'crm_receivables', 'crm_invoice', 'jxc_purchase', 'jxc_retreat', 'jxc_sale', 'jxc_salereturn', 'jxc_payment', 'jxc_collection', 'jxc_allocation', 'jxc_inventory'])) {
  55. $model = db($param['types']);
  56. $primaryKey = null;
  57. if ($param['types'] == 'crm_contract') $primaryKey = 'contract_id';
  58. if ($param['types'] == 'crm_receivables') $primaryKey = 'receivables_id';
  59. if ($param['types'] == 'crm_invoice') $primaryKey = 'invoice_id';
  60. if ($param['types'] == 'jxc_purchase') $primaryKey = 'purchase_id';
  61. if ($param['types'] == 'jxc_retreat') $primaryKey = 'retreat_id';
  62. if ($param['types'] == 'jxc_sale') $primaryKey = 'sale_id';
  63. if ($param['types'] == 'jxc_salereturn') $primaryKey = 'salereturn_id';
  64. if ($param['types'] == 'jxc_payment') $primaryKey = 'payment_note_id';
  65. if ($param['types'] == 'jxc_collection') $primaryKey = 'collection_note_id';
  66. if ($param['types'] == 'jxc_allocation') $primaryKey = 'allocation_id';
  67. if ($param['types'] == 'jxc_inventory') $primaryKey = 'inventory_id';
  68. $info = $model->field(['create_time', 'owner_user_id'])->where($primaryKey, $param['types_id'])->find();
  69. $userInfo = $userModel->getUserById($info['owner_user_id']);
  70. $result[] = [
  71. 'check_date' => date('Y-m-d H:i:s', $info['create_time']),
  72. 'check_time' => $info['create_time'],
  73. 'check_user_id' => $info['owner_user_id'],
  74. 'check_user_id_info' => $userInfo,
  75. 'content' => '',
  76. 'flow_id' => 0,
  77. 'is_end' => 0,
  78. 'order_id' => 1,
  79. 'record_id' => 0,
  80. 'status' => 3,
  81. 'types' => $param['types'],
  82. 'types_id' => $param['types_id']
  83. ];
  84. }else{
  85. unset($param['action']);
  86. # 获取创建者信息(办公审批)
  87. $info = db('oa_examine')->field(['create_time', 'create_user_id','update_time,check_status'])->where('examine_id', $param['types_id'])->find();
  88. $userInfo = $userModel->getUserById($info['create_user_id']);
  89. #撤销之后修改再次审批 审批流程过滤之前的审批记录
  90. if($info['check_status']<2){
  91. $param['check_time']=['>',$info['update_time']?:$info['create_time']];
  92. }
  93. $result[] = [
  94. 'check_date' => date('Y-m-d H:i:s', $info['create_time']),
  95. 'check_time' => $info['create_time'],
  96. 'check_user_id' => $info['create_user_id'],
  97. 'check_user_id_info' => $userInfo,
  98. 'content' => '',
  99. 'flow_id' => 0,
  100. 'is_end' => 0,
  101. 'order_id' => 1,
  102. 'record_id' => 0,
  103. 'status' => 3,
  104. 'types' => $param['types'],
  105. 'types_id' => $param['types_id']
  106. ];
  107. }
  108. unset($param['is_record']);
  109. # 多次撤销使用 只显示最后一次撤销数据条件 is_end 0
  110. $param['is_end']=0;
  111. $list = db('admin_examine_record')->where($param)->order('check_time asc')->select();
  112. foreach ($list as $k=>$v) {
  113. $list[$k]['check_user_id_info'] = $userModel->getUserById($v['check_user_id']);
  114. $list[$k]['check_date'] = date('Y-m-d H:i:s', $v['check_time']);
  115. $list[$k]['order_id'] = $k + 2;
  116. $result[] = $list[$k];
  117. }
  118. return !empty($result) ? $result : [];
  119. }
  120. /**
  121. * 审批意见(标记无效,撤销审批时使用)
  122. * @param types 关联对象
  123. * @param types_id 关联对象ID
  124. * @return
  125. */
  126. public function setEnd($param)
  127. {
  128. if (empty($param['types']) || empty($param['types_id'])) {
  129. $this->error = '参数错误';
  130. return false;
  131. }
  132. $res = $this->where(['types' => $param['types'],'types_id' => $param['types_id']])->update(['is_end' => 1]);
  133. return true;
  134. }
  135. }