Month.php 4.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. <?php
  2. namespace app\crontab\controller;
  3. use think\facade\Db;
  4. /**
  5. * ============================================================================
  6. *
  7. * ============================================================================
  8. * 版权所有 2014-2028 浙江惠利玛产业互联网有限公司,并保留所有权利。
  9. * 网站地址: https://www.valimart.net/
  10. * ----------------------------------------------------------------------------
  11. *
  12. * ============================================================================
  13. * 定时器
  14. */
  15. class Month extends BaseCron {
  16. /**
  17. * 默认方法
  18. */
  19. public function index(){
  20. //生成平台月账单统计
  21. $this->_create_orderstatis();
  22. }
  23. private function _create_orderstatis(){
  24. $max_time=strtotime(date('Y-m-01 0:0:0', TIMESTAMP))-1;//上个月最后一天
  25. $os_month=Db::name('orderstatis')->order('os_month desc')->value('os_month');
  26. if($os_month){
  27. //有生成过平台账单则查看最新的账单时间到上个月期间是否有结算单
  28. $start_time= strtotime($os_month.'01 0:0:0 + 1 month');
  29. }else{
  30. //没生成过平台账单则生成最旧的结算单时间到上个月期间的平台账单
  31. $ob_createdate=Db::name('orderbill')->order('ob_startdate asc')->value('ob_startdate');
  32. if($ob_createdate){
  33. $start_time= strtotime(date('Y-m-01 0:0:0',$ob_createdate));
  34. }
  35. }
  36. if(isset($start_time)){
  37. for($i=1;$i<=100;$i++){
  38. $end_time=strtotime(date('Y-m-01 0:0:0', $start_time)." +1 month")-1;
  39. if($end_time>$max_time){
  40. break;
  41. }
  42. $orderbill_sum=Db::name('orderbill')->where('ob_enddate','between',[$start_time,$end_time])->field('SUM(ob_order_totals) AS os_order_totals,SUM(ob_shipping_totals) AS os_shipping_totals,SUM(ob_order_return_totals) AS os_order_returntotals,SUM(ob_commis_totals) AS os_commis_totals,SUM(ob_commis_return_totals) AS os_commis_returntotals,SUM(ob_store_cost_totals) AS os_store_costtotals,SUM(ob_vr_order_totals) AS os_vr_order_totals,SUM(ob_vr_commis_totals) AS os_vr_commis_totals,SUM(ob_vr_inviter_totals) AS os_vr_inviter_totals,SUM(ob_result_totals) AS os_result_totals,SUM(ob_inviter_totals) AS os_inviter_totals,SUM(ob_vr_order_return_totals) AS os_vr_order_return_totals,SUM(ob_vr_commis_return_totals) AS os_vr_commis_return_totals')->find();
  43. if($orderbill_sum){
  44. Db::name('orderstatis')->insert(array(
  45. 'os_month'=>date('Ym',$start_time),
  46. 'os_createdate'=>TIMESTAMP,
  47. 'os_order_totals'=>floatval($orderbill_sum['os_order_totals']),
  48. 'os_shipping_totals'=>floatval($orderbill_sum['os_shipping_totals']),
  49. 'os_order_returntotals'=>floatval($orderbill_sum['os_order_returntotals']),
  50. 'os_commis_totals'=>floatval($orderbill_sum['os_commis_totals']),
  51. 'os_commis_returntotals'=>floatval($orderbill_sum['os_commis_returntotals']),
  52. 'os_store_costtotals'=>floatval($orderbill_sum['os_store_costtotals']),
  53. 'os_vr_order_totals'=>floatval($orderbill_sum['os_vr_order_totals']),
  54. 'os_vr_commis_totals'=>floatval($orderbill_sum['os_vr_commis_totals']),
  55. 'os_vr_inviter_totals'=>floatval($orderbill_sum['os_vr_inviter_totals']),
  56. 'os_result_totals'=>floatval($orderbill_sum['os_result_totals']),
  57. 'os_inviter_totals'=>floatval($orderbill_sum['os_inviter_totals']),
  58. 'os_vr_order_return_totals'=>floatval($orderbill_sum['os_vr_order_return_totals']),
  59. 'os_vr_commis_return_totals'=>floatval($orderbill_sum['os_vr_commis_return_totals']),
  60. ));
  61. }else{
  62. Db::name('orderstatis')->insert(array('os_month'=>date('Ym',$start_time),'os_createdate'=>TIMESTAMP));
  63. }
  64. $start_time=$end_time+1;
  65. }
  66. if($end_time<$max_time){
  67. $this->redirect('month/index');
  68. }
  69. }
  70. }
  71. }
  72. ?>