UpdateProcessWaitFinallyActionData.php 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. <?php
  2. declare (strict_types=1);
  3. namespace app\command;
  4. use think\console\Command;
  5. use think\console\Input;
  6. use think\console\input\Argument;
  7. use think\console\input\Option;
  8. use think\console\Output;
  9. use think\Exception;
  10. use think\facade\Db;
  11. class UpdateProcessWaitFinallyActionData extends Command
  12. {
  13. protected function configure()
  14. {
  15. // 指令配置
  16. $this->setName('UpdateProcessWaitFinallyActionData')
  17. ->setDescription('更新待办数据表中的字段:最终操作人');
  18. }
  19. protected function execute(Input $input, Output $output)
  20. {
  21. Db::startTrans();
  22. try {
  23. Db::name('process_wait')
  24. ->where('action_uid_finally','<>',0)
  25. ->update(['action_uid_finally'=>0,'action_name_finally'=>'']);
  26. $data = Db::name('process_wait')
  27. ->field('order_code,order_type,order_id')
  28. ->group('order_code,order_type,order_id')
  29. ->whereIn('status', [1, 2])
  30. ->cursor();
  31. foreach ($data as $value) {
  32. if($value['order_type'] == 'LZJJ') $order_code = $value['order_id'];//离职交接单,取id
  33. else $order_code = $value['order_code'];
  34. $action = Db::name('action_log')
  35. ->field('id,action_id,action_name')
  36. ->where([
  37. 'order_code'=>$order_code,
  38. 'order_type'=>$value['order_type']
  39. ])
  40. ->order('id','desc')
  41. ->findOrEmpty();
  42. if ($action) Db::name('process_wait')
  43. ->where('order_code', $value['order_code'])
  44. ->where('order_type', $value['order_type'])
  45. ->update(['action_uid_finally' => $action['action_id'],'action_name_finally' => $action['action_name']]);
  46. }
  47. Db::commit();
  48. $output->writeln('update success');
  49. } catch (Exception $exception) {
  50. Db::rollback();
  51. $output->writeln('update fail,' . $exception->getMessage());
  52. }
  53. }
  54. }