BaseCron.php 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  1. <?php
  2. namespace app\crontab\controller;
  3. use app\BaseController;
  4. use think\facade\Log;
  5. /**
  6. *
  7. *
  8. * ----------------------------------------------------------------------------
  9. *
  10. * 定时器
  11. */
  12. class BaseCron extends BaseController
  13. {
  14. public function shutdown()
  15. {
  16. exit("run " . request()->controller() . " success at " . date('Y-m-d H:i:s', TIMESTAMP) . "\n");
  17. }
  18. public function initialize()
  19. {
  20. parent::initialize();
  21. $config_list = rkcache('config', true);
  22. config($config_list, 'ds_config');
  23. set_time_limit(600);
  24. error_reporting(E_ALL & ~E_NOTICE);
  25. register_shutdown_function(array($this, "shutdown"));
  26. }
  27. /**
  28. * 记录日志
  29. * @param unknown $content 日志内容
  30. * @param boolean $if_sql 是否记录SQL
  31. */
  32. protected function log($content, $if_sql = true)
  33. {
  34. Log::record('queue\\' . $content);
  35. }
  36. /**
  37. * 更新订单中的佣金比例[多个地方调用,写到父类中]
  38. */
  39. protected function _order_commis_rate_update()
  40. {
  41. //实物订单,每次最多处理50W个商品佣金
  42. $_break = false;
  43. $order_model = model('order');
  44. $storebindclass_model = model('storebindclass');
  45. $refundreturn_model = model('refundreturn');
  46. for ($i = 0; $i < 5000; $i++) {
  47. if ($_break) {
  48. break;
  49. }
  50. Db::startTrans();
  51. $goods_list = $order_model->getOrdergoodsList(array('commis_rate' => 200), 'rec_id,goods_id,store_id,gc_id', 100, null, '');
  52. if (!empty($goods_list)) {
  53. //$commis_rate_list : store_id => array(gc_id => commis_rate)
  54. $commis_rate_list = $storebindclass_model->getStoreGcidCommisRateList($goods_list);
  55. //更新订单商品佣金值
  56. foreach ($goods_list as $v) {
  57. //如果未查到店铺或分类ID,则佣金置0
  58. if (!isset($commis_rate_list[$v['store_id']][$v['gc_id']])) {
  59. $commis_rate = 0;
  60. } else {
  61. $commis_rate = $commis_rate_list[$v['store_id']][$v['gc_id']];
  62. }
  63. $update = $order_model->editOrdergoods(array('commis_rate' => $commis_rate), array('rec_id' => $v['rec_id']));
  64. if (!$update) {
  65. $this->log('更新实物订单商品佣金值失败');
  66. $_break = true;
  67. break;
  68. }
  69. $update = $refundreturn_model->editRefundreturn(array('store_id' => $v['store_id'], 'goods_id' => $v['goods_id']), array('commis_rate' => $commis_rate));
  70. if (!$update) {
  71. $this->log('更新实物订单退款佣金值失败');
  72. $_break = true;
  73. break;
  74. }
  75. }
  76. } else {
  77. break;
  78. }
  79. Db::commit();
  80. }
  81. Db::commit();
  82. //虚拟订单,每次最多处理50W个商品佣金
  83. $_break = false;
  84. $vrorder_model = model('vrorder');
  85. $vrrefund_model = model('vrrefund');
  86. for ($i = 0; $i < 5000; $i++) {
  87. if ($_break) {
  88. break;
  89. }
  90. Db::startTrans();
  91. $goods_list = $vrorder_model->getVrorderList(array('commis_rate' => 200), '', 'order_id,store_id,gc_id', '', 100);
  92. if (!empty($goods_list)) {
  93. //$commis_rate_list : store_id => array(gc_id => commis_rate)
  94. $commis_rate_list = $storebindclass_model->getStoreGcidCommisRateList($goods_list);
  95. //更新订单商品佣金值
  96. foreach ($goods_list as $v) {
  97. //如果未查到店铺或分类ID,则佣金置0
  98. if (!isset($commis_rate_list[$v['store_id']][$v['gc_id']])) {
  99. $commis_rate = 0;
  100. } else {
  101. $commis_rate = $commis_rate_list[$v['store_id']][$v['gc_id']];
  102. }
  103. $update = $vrorder_model->editVrorder(array('commis_rate' => $commis_rate), array('order_id' => $v['order_id']));
  104. if (!$update) {
  105. $this->log('更新虚拟订单商品佣金值失败');
  106. $_break = true;
  107. break;
  108. }
  109. $update = $vrorder_model->editVrorderCode(array('commis_rate' => $commis_rate), array('order_id' => $v['order_id']));
  110. if (!$update) {
  111. $this->log('更新虚拟订单兑换码佣金值失败');
  112. $_break = true;
  113. break;
  114. }
  115. $update = $vrrefund_model->editVrrefund(array('order_id' => $v['order_id']), array('commis_rate' => $commis_rate));
  116. if (!$update) {
  117. $this->log('更新虚拟订单商品退款佣金值失败');
  118. $_break = true;
  119. break;
  120. }
  121. }
  122. } else {
  123. break;
  124. }
  125. Db::commit();
  126. }
  127. Db::commit();
  128. }
  129. }