ProcessWait.php 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170
  1. <?php
  2. namespace app\admin\model;
  3. use app\abutment\model\SupplierRelationUser as SupplierRelationUserModel;
  4. use app\abutment\model\SupplierUser as SupplierUserModel;
  5. use think\facade\Db;
  6. use think\Model;
  7. //待办已办
  8. class ProcessWait extends Model
  9. {
  10. protected $table = 'wsm_process_wait';
  11. protected $pk = 'id';
  12. protected $autoWriteTimestamp = false;
  13. public static $status_wait = 1;//状态,1待处理
  14. public static $status_finish = 2;//状态,2已处理
  15. public static $status_interrupt = 3;//状态,3中断
  16. //添加待办记录
  17. public static function add(array $data = [], int $wait_id = 0, string $wait_name = '', string $handle_user_list = '')
  18. {
  19. // $data数据格式实例
  20. // $data=[
  21. // "order_type"=>'',
  22. // "order_code"=>'',
  23. // "order_id"=>'',
  24. // "order_status"=>'',
  25. // "action_process"=>'',
  26. // "action_status"=>'',
  27. // "action_uid"=>'',
  28. // "action_name"=>'',
  29. // "addtime"=>'',
  30. // ];
  31. //修改各个节点的最终节点
  32. Db::name('process_wait')
  33. ->where(['order_type' => $data['order_type'], 'order_code' => $data['order_code'], 'order_id' => $data['order_id']])
  34. ->update(['order_process_finally' => $data['action_process'], 'action_uid_finally' => $data['action_uid'], 'action_name_finally' => $data['action_name']]);
  35. //把上一个节点改成已完成
  36. Db::name('process_wait')
  37. ->where(['order_type' => $data['order_type'], 'order_process' => $data['action_status'], 'order_code' => $data['order_code'], 'order_id' => $data['order_id'], 'status' => self::$status_wait])
  38. ->update(['status' => self::$status_finish, 'updatetime' => date('Y-m-d H:i:s')]);
  39. //查询流程下该节点值的id
  40. $info = Db::name('process')
  41. ->alias('a')
  42. ->field('p.id,p.action_type,p.operation_type,a.api_url')
  43. ->join('action_process p', 'p.process_id=a.id AND p.order_process=' . $data['action_process'])
  44. ->where(['a.process_type' => $data['order_type'], 'a.status' => Process::$status_normal, 'a.is_del' => Process::$is_del_normal])
  45. ->findOrEmpty();
  46. if ($info) {
  47. //如果下一个节点是中断节点,则将相关记录删除,不再新增(只删除待办数据,221010145800@戴确认)
  48. if ($info['action_type'] == ActionProcess::$action_type_interrupt) {
  49. self::where(['order_type' => $data['order_type'], 'order_code' => $data['order_code'], 'order_id' => $data['order_id'], 'status' => self::$status_wait])
  50. ->update(['status' => self::$status_interrupt, 'updatetime' => date('Y-m-d H:i:s')]);
  51. return true;
  52. }
  53. //如果是系统节点,不写入待办已办数据
  54. if ($info['operation_type'] == ActionProcess::$operation_type_system) return true;
  55. //如果是以下4个流程,还需要判断对应供应商是否开通账号,如果开通的话就不推送待办已办数据
  56. if (in_array($data['order_type'], ['CKD', 'RKD', 'CGD'])) {
  57. switch ($data['order_type']) {
  58. //发货申请单流程
  59. case 'CKD':
  60. $supplierNo = Db::name('order_out')
  61. ->alias('a')
  62. ->leftJoin('order_num b', 'b.orderCode=a.orderCode')
  63. ->leftJoin('purchease_order c', 'c.cgdNo=b.cgdNo')
  64. ->where(['a.is_del' => 0, 'a.outCode' => $data['order_code']])
  65. ->value('c.supplierNo');
  66. break;
  67. //采购单入库流程
  68. case 'RKD':
  69. $supplierNo = Db::name('purchease_in')
  70. ->alias('a')
  71. ->leftJoin('purchease_order b', 'b.cgdNo=a.cgdNo')
  72. ->where(['a.is_del' => 0, 'a.wsm_in_code' => $data['order_code']])
  73. ->value('b.supplierNo');
  74. break;
  75. //采购单流程
  76. case 'CGD':
  77. $supplierNo = Db::name('purchease_order')
  78. ->where(['cgdNo' => $data['order_code'], 'is_del' => 0])
  79. ->value('supplierNo');
  80. break;
  81. // //商品成本流程--要根据节点的值来判断是否推送待办数据
  82. // case 'SPCB':
  83. // $supplierNo = Db::name('good_basic')
  84. // ->where(['is_del' => 0, 'spuCode' => $data['order_code'],])
  85. // ->value('supplierNo');
  86. // break;
  87. default:
  88. $supplierNo = '';
  89. break;
  90. }
  91. if ($supplierNo) {
  92. //查询该供应商是否开通账号
  93. $res = SupplierRelationUserModel::field('id')
  94. ->where([
  95. 'is_del' => SupplierUserModel::$is_del_normal,
  96. 'supplierNo' => $supplierNo,
  97. 'status' => SupplierUserModel::$status_normal
  98. ])
  99. ->findOrEmpty()
  100. ->isEmpty();
  101. if (!$res) return true;
  102. }
  103. }
  104. //如果是SPCB的话,以下节点值推送待办数据(0新建待审核,2基础修改待审核,3成本修改待审核)
  105. if ($data['order_type'] == 'SPCB' && !in_array($data['action_process'], [0, 2, 3])) return true;
  106. $insert_data = [
  107. 'order_type' => $data['order_type'],
  108. 'order_code' => $data['order_code'],
  109. 'order_id' => $data['order_id'],
  110. 'action_uid' => $data['action_uid'],
  111. 'action_name' => $data['action_name'],
  112. 'status' => self::$status_wait,
  113. 'order_process' => $data['action_process'],
  114. 'order_process_finally' => $data['action_process'],
  115. 'action_uid_finally' => $data['action_uid'],
  116. 'action_name_finally' => $data['action_name'],
  117. 'addtime' => date('Y-m-d H:i:s'),
  118. 'updatetime' => date('Y-m-d H:i:s'),
  119. ];
  120. if ($wait_id) {
  121. $insert_data['handle_user_list'] = $wait_id;//handle_user_list当前待处理人的uid集合
  122. $insert_data['wait_id'] = $wait_id;
  123. $insert_data['wait_name'] = $wait_name;
  124. } else {
  125. //查询该节点值对应的角色id
  126. $roleid = Db::name('role_process')
  127. ->whereFindInSet('action_data', $info['id'])
  128. ->where('is_del', 0)
  129. ->column('role_id');
  130. $insert_data['roleid'] = implode(',', $roleid);
  131. //针对议价单流程,待boss审核节点,做特殊处理
  132. if ($data['order_type'] == 'YJD' && $data['action_process'] == 7) $insert_data['handle_user_list'] = implode(',', Db::name('user_role')->whereIn('roleid', $roleid)->where(['is_del' => 0, 'status' => 1])->where('roleid', '<>', 1)->column('uid'));
  133. else $insert_data['handle_user_list'] = $handle_user_list ? $handle_user_list : implode(',', get_handle_user_list($info['id'], $data['holder_id'] ?? 0, $info['api_url'], $data['person_id'] ?? 0));//handle_user_list当前待处理人的uid集合
  134. }
  135. //增加新的节点
  136. return self::create($insert_data)->save();
  137. }
  138. return true;
  139. }
  140. }