Wlps.php 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. <?php
  2. namespace app\cron;
  3. use think\Db;
  4. use yunwuxin\cron\Task;
  5. class Wlps extends Task
  6. {
  7. public function configure()
  8. {
  9. $this->everyMinute(); //每分钟执行一次
  10. }
  11. /**
  12. * 执行任务
  13. * @return mixed
  14. */
  15. protected function execute()
  16. {
  17. try{
  18. $this->ypconvey();
  19. $this->cancelypconvey();
  20. }catch (\Exception $e){
  21. trace($e->getMessage());
  22. }
  23. }
  24. public function ypconvey(){
  25. $lists = Db::connect('db_config_jili')->name('wlps')->where('is_deal',0)->where('is_qx','N')->select();
  26. $lists = $lists?$lists:[];
  27. foreach ($lists as $k=>$v){
  28. $v['s_bmid'] = trim($v['s_bmid']);
  29. $v['department_no'] = trim($v['department_no']);
  30. (new \app\common\model\Wlps())->deal_wlps($v);
  31. }
  32. }
  33. // 药品运送取消,每分钟查询一次
  34. public function cancelypconvey(){
  35. $lists=Db::connect('db_config_jili')
  36. ->name('wlps')
  37. ->alias('a')
  38. ->join('orders as b','a.order_id = b.order_id')
  39. ->field('b.*')
  40. ->whereIn('b.order_mode',[1,5])
  41. ->where('b.del_ref',0)
  42. ->where('a.order_id', '>',0)
  43. ->where('a.is_qx','<>','N')
  44. ->select();
  45. $lists = $lists?$lists:[];
  46. foreach ($lists as $k=>$v){
  47. $this->startTrans();
  48. try{
  49. $ret = Db::name('orders')->where('order_id',$v['order_id'])->update(['order_mode'=>2,'cancel_time'=>date('Y-m-d H:i:s')]);
  50. if (!$ret) {
  51. exception('保存失败');
  52. }
  53. if($v['order_mode'] == 5){
  54. $res = Db::name('todo')->where('order_id',$v['order_id'])->whereIn('todo_mode',[1,2,3])->update(['todo_mode'=>6]);
  55. if (!$res) {
  56. exception('保存失败');
  57. }
  58. }
  59. $this->commit();
  60. }catch (\Exception $e){
  61. trace('error',$e->getMessage());
  62. $this->rollback();
  63. }
  64. }
  65. }
  66. }