RepeatOrder.php 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. <?php
  2. /**
  3. * RepeatOrder.php UTF-8
  4. * 补单
  5. *
  6. * @date : 2020/7/29 16:11
  7. *
  8. * @license 这不是一个自由软件,未经授权不许任何使用和传播。
  9. * @author : chenbingling <cbl@huosdk.com>
  10. * @version : HUOSDK 8.0
  11. */
  12. namespace console\index\controller;
  13. use huo\model\order\OrderModel;
  14. use huolib\constant\OrderConst;
  15. use huolib\tool\Time;
  16. use huoOrderRepeat\controller\OrderRepeat;
  17. use think\console\Command;
  18. use think\console\Input;
  19. use think\console\input\Option;
  20. use think\console\Output;
  21. class RepeatOrder extends Command {
  22. protected function configure() {
  23. $this->setName('repeat_order')->setDescription('所有掉单补单');
  24. $this->addOption('date', 'd', Option::VALUE_REQUIRED, 'choose date to do', '');
  25. }
  26. protected function execute(Input $input, Output $output) {
  27. $_date = $input->getOption('date');
  28. $_log_date = date('Y-m-d H:i:s');
  29. \think\Log::write("ETL RepeatOrder at $_log_date and date = $_date", 'etl', true);
  30. $this->repeatByDate($_date);
  31. exit;
  32. }
  33. /**
  34. * 执行每日补单操作
  35. *
  36. * @param $date
  37. */
  38. private function repeatByDate($date) {
  39. $_map = [
  40. 'cp_status' => ['neq', OrderConst::CP_STATUS_SUC],
  41. 'status' => OrderConst::PAY_STATUS_SUC,
  42. ];
  43. if (!empty($date)) {
  44. list($_start_time, $_end_time) = Time::day($date);
  45. $_map['create_time'] = ['between', [$_start_time, $_end_time]];
  46. }
  47. $_order_repeat = new OrderRepeat();
  48. $_order_model = new OrderModel();
  49. $_field = ['id', 'order_id'];
  50. $_order_model->where($_map)->field($_field)->chunk(
  51. 10, function ($_orders) use ($_order_repeat) {
  52. foreach ($_orders as $_order) {
  53. if (is_object($_order)) {
  54. $_order = $_order->toArray();
  55. }
  56. if (!empty($_order['order_id'])) {
  57. $_order_repeat->cpNotifyQueue($_order['order_id'], 1);
  58. }
  59. }
  60. }
  61. );
  62. }
  63. }