control.php 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. <?php
  2. /**
  3. * 父类
  4. *
  5. *
  6. *
  7. *
  8. */
  9. defined('InShopNC') or exit('Access Invalid!');
  10. class BaseCronControl {
  11. public function shutdown(){
  12. exit("success at ".date('Y-m-d H:i:s',TIMESTAMP)."\n");
  13. }
  14. public function __construct(){
  15. register_shutdown_function(array($this,"shutdown"));
  16. }
  17. /**
  18. * 记录日志
  19. * @param unknown $content 日志内容
  20. * @param boolean $if_sql 是否记录SQL
  21. */
  22. protected function log($content, $if_sql = true) {
  23. if ($if_sql) {
  24. $log = Log::read();
  25. if (!empty($log) && is_array($log)){
  26. $content .= end($log);
  27. }
  28. }
  29. Log::record('queue\\'.$content,Log::RUN);
  30. }
  31. /**
  32. * 更新订单中的佣金比例[多个地方调用,写到父类中]
  33. */
  34. protected function _order_commis_rate_update() {
  35. //实物订单,每次最多处理50W个商品佣金
  36. $_break = false;
  37. $model_order = Model('order');
  38. $store_bind_class = Model('store_bind_class');
  39. $model_refund_return = Model('refund_return');
  40. for($i = 0; $i < 5000; $i++) {
  41. if ($_break) {
  42. break;
  43. }
  44. $model_order->beginTransaction();
  45. $goods_list = $model_order->getOrderGoodsList(array('commis_rate' => 200), 'rec_id,goods_id,store_id,gc_id', 100, null, '');
  46. if (!empty($goods_list)) {
  47. //$commis_rate_list : store_id => array(gc_id => commis_rate)
  48. $commis_rate_list = $store_bind_class->getStoreGcidCommisRateList($goods_list);
  49. //更新订单商品佣金值
  50. foreach ($goods_list as $v) {
  51. //如果未查到店铺或分类ID,则佣金置0
  52. if (!isset($commis_rate_list[$v['store_id']][$v['gc_id']])) {
  53. $commis_rate = 0;
  54. } else {
  55. $commis_rate = $commis_rate_list[$v['store_id']][$v['gc_id']];
  56. }
  57. $update = $model_order->editOrderGoods(array('commis_rate' => $commis_rate),array('rec_id' => $v['rec_id']));
  58. if (!$update) {
  59. $this->log('更新实物订单商品佣金值失败'); $_break = true; break;
  60. }
  61. $update = $model_refund_return->editRefundReturn(array('store_id'=>$v['store_id'],'goods_id'=>$v['goods_id']),array('commis_rate' => $commis_rate));
  62. if (!$update) {
  63. $this->log('更新实物订单退款佣金值失败'); $_break = true; break;
  64. }
  65. }
  66. } else {
  67. break;
  68. }
  69. $model_order->commit();
  70. }
  71. $model_order->commit();
  72. //虚拟订单,每次最多处理50W个商品佣金
  73. $_break = false;
  74. $model_order = Model('vr_order');
  75. $model_vr_refund = Model('vr_refund');
  76. for($i = 0; $i < 5000; $i++) {
  77. if ($_break) {
  78. break;
  79. }
  80. $model_order->beginTransaction();
  81. $goods_list = $model_order->getOrderList(array('commis_rate' => 200),'', 'order_id,store_id,gc_id', '',100);
  82. if (!empty($goods_list)) {
  83. //$commis_rate_list : store_id => array(gc_id => commis_rate)
  84. $commis_rate_list = $store_bind_class->getStoreGcidCommisRateList($goods_list);
  85. //更新订单商品佣金值
  86. foreach ($goods_list as $v) {
  87. //如果未查到店铺或分类ID,则佣金置0
  88. if (!isset($commis_rate_list[$v['store_id']][$v['gc_id']])) {
  89. $commis_rate = 0;
  90. } else {
  91. $commis_rate = $commis_rate_list[$v['store_id']][$v['gc_id']];
  92. }
  93. $update = $model_order->editOrder(array('commis_rate' => $commis_rate),array('order_id' => $v['order_id']));
  94. if (!$update) {
  95. $this->log('更新虚拟订单商品佣金值失败'); $_break = true; break;
  96. }
  97. $update = $model_order->editOrderCode(array('commis_rate' => $commis_rate),array('order_id' => $v['order_id']));
  98. if (!$update) {
  99. $this->log('更新虚拟订单兑换码佣金值失败'); $_break = true; break;
  100. }
  101. $update = $model_vr_refund->editRefund(array('order_id' => $v['order_id']),array('commis_rate' => $commis_rate));
  102. if (!$update) {
  103. $this->log('更新虚拟订单商品退款佣金值失败'); $_break = true; break;
  104. }
  105. }
  106. } else {
  107. break;
  108. }
  109. $model_order->commit();
  110. }
  111. $model_order->commit();
  112. }
  113. }