UpdateProcessWaitFinallyActionData.php 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  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. //判断是否在执行中
  22. Db::startTrans();
  23. try {
  24. //设置标识,执行中
  25. Db::name('process_wait')
  26. ->where('action_uid_finally','<>',0)
  27. ->update(['action_uid_finally'=>0,'action_name_finally'=>'']);
  28. $data = Db::name('process_wait')
  29. ->field('order_code,order_type,order_id')
  30. ->group('order_code,order_type,order_id')
  31. ->whereIn('status', [1, 2])
  32. ->cursor();
  33. foreach ($data as $value) {
  34. if($value['order_type'] == 'LZJJ') $order_code = $value['order_id'];//离职交接单,取id
  35. else $order_code = $value['order_code'];
  36. $action = Db::name('action_log')
  37. ->field('id,action_id,action_name')
  38. ->where([
  39. 'order_code'=>$order_code,
  40. 'order_type'=>$value['order_type']
  41. ])
  42. ->order('id','desc')
  43. ->findOrEmpty();
  44. if ($action) Db::name('process_wait')
  45. ->where('order_code', $value['order_code'])
  46. ->where('order_type', $value['order_type'])
  47. ->update(['action_uid_finally' => $action['action_id'],'action_name_finally' => $action['action_name']]);
  48. }
  49. Db::commit();
  50. $output->writeln('update success');
  51. //解除标识,执行完毕
  52. } catch (Exception $exception) {
  53. Db::rollback();
  54. $output->writeln('update fail,' . $exception->getMessage());
  55. //解除标识,执行完毕
  56. }
  57. }
  58. }