BaseCron.php 5.5 KB

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