BaseCron.php 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  1. <?php
  2. namespace app\crontab\controller;
  3. use app\BaseController;
  4. use think\facade\Log;
  5. /**
  6. * ============================================================================
  7. * DSMall多用户商城
  8. * ============================================================================
  9. * 版权所有 2014-2028 长沙德尚网络科技有限公司,并保留所有权利。
  10. * 网站地址: http://www.csdeshang.com
  11. * ----------------------------------------------------------------------------
  12. * 这不是一个自由软件!您只能在不用于商业目的的前提下对程序代码进行修改和使用 .
  13. * 不允许对程序代码以任何形式任何目的的再发布。
  14. * ============================================================================
  15. * 定时器
  16. */
  17. class BaseCron extends BaseController {
  18. public function shutdown(){
  19. exit("run ".request()->controller()." success at ".date('Y-m-d H:i:s',TIMESTAMP)."\n");
  20. }
  21. public function initialize(){
  22. parent::initialize();
  23. $config_list = rkcache('config', true);
  24. config($config_list,'ds_config');
  25. set_time_limit(600);
  26. error_reporting(E_ALL & ~E_NOTICE);
  27. register_shutdown_function(array($this,"shutdown"));
  28. }
  29. /**
  30. * 记录日志
  31. * @param unknown $content 日志内容
  32. * @param boolean $if_sql 是否记录SQL
  33. */
  34. protected function log($content, $if_sql = true) {
  35. Log::record('queue\\'.$content);
  36. }
  37. /**
  38. * 更新订单中的佣金比例[多个地方调用,写到父类中]
  39. */
  40. protected function _order_commis_rate_update() {
  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('更新实物订单商品佣金值失败'); $_break = true; break;
  66. }
  67. $update = $refundreturn_model->editRefundreturn(array('store_id'=>$v['store_id'],'goods_id'=>$v['goods_id']),array('commis_rate' => $commis_rate));
  68. if (!$update) {
  69. $this->log('更新实物订单退款佣金值失败'); $_break = true; break;
  70. }
  71. }
  72. } else {
  73. break;
  74. }
  75. Db::commit();
  76. }
  77. Db::commit();
  78. //虚拟订单,每次最多处理50W个商品佣金
  79. $_break = false;
  80. $vrorder_model = model('vrorder');
  81. $vrrefund_model = model('vrrefund');
  82. for($i = 0; $i < 5000; $i++) {
  83. if ($_break) {
  84. break;
  85. }
  86. Db::startTrans();
  87. $goods_list = $vrorder_model->getVrorderList(array('commis_rate' => 200),'', 'order_id,store_id,gc_id', '',100);
  88. if (!empty($goods_list)) {
  89. //$commis_rate_list : store_id => array(gc_id => commis_rate)
  90. $commis_rate_list = $storebindclass_model->getStoreGcidCommisRateList($goods_list);
  91. //更新订单商品佣金值
  92. foreach ($goods_list as $v) {
  93. //如果未查到店铺或分类ID,则佣金置0
  94. if (!isset($commis_rate_list[$v['store_id']][$v['gc_id']])) {
  95. $commis_rate = 0;
  96. } else {
  97. $commis_rate = $commis_rate_list[$v['store_id']][$v['gc_id']];
  98. }
  99. $update = $vrorder_model->editVrorder(array('commis_rate' => $commis_rate),array('order_id' => $v['order_id']));
  100. if (!$update) {
  101. $this->log('更新虚拟订单商品佣金值失败'); $_break = true; break;
  102. }
  103. $update = $vrorder_model->editVrorderCode(array('commis_rate' => $commis_rate),array('order_id' => $v['order_id']));
  104. if (!$update) {
  105. $this->log('更新虚拟订单兑换码佣金值失败'); $_break = true; break;
  106. }
  107. $update = $vrrefund_model->editVrrefund(array('order_id' => $v['order_id']),array('commis_rate' => $commis_rate));
  108. if (!$update) {
  109. $this->log('更新虚拟订单商品退款佣金值失败'); $_break = true; break;
  110. }
  111. }
  112. } else {
  113. break;
  114. }
  115. Db::commit();
  116. }
  117. Db::commit();
  118. }
  119. }
  120. ?>