Month.php 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. <?php
  2. namespace app\crontab\controller;
  3. use think\facade\Db;
  4. /**
  5. * ============================================================================
  6. * DSMall多用户商城
  7. * ============================================================================
  8. * 版权所有 2014-2028 长沙德尚网络科技有限公司,并保留所有权利。
  9. * 网站地址: http://www.csdeshang.com
  10. * ----------------------------------------------------------------------------
  11. * 这不是一个自由软件!您只能在不用于商业目的的前提下对程序代码进行修改和使用 .
  12. * 不允许对程序代码以任何形式任何目的的再发布。
  13. * ============================================================================
  14. * 定时器
  15. */
  16. class Month extends BaseCron {
  17. /**
  18. * 默认方法
  19. */
  20. public function index(){
  21. //生成平台月账单统计
  22. $this->_create_orderstatis();
  23. }
  24. private function _create_orderstatis(){
  25. $max_time=strtotime(date('Y-m-01 0:0:0', TIMESTAMP))-1;//上个月最后一天
  26. $os_month=Db::name('orderstatis')->order('os_month desc')->value('os_month');
  27. if($os_month){
  28. //有生成过平台账单则查看最新的账单时间到上个月期间是否有结算单
  29. $start_time= strtotime($os_month.'01 0:0:0 + 1 month');
  30. }else{
  31. //没生成过平台账单则生成最旧的结算单时间到上个月期间的平台账单
  32. $ob_createdate=Db::name('orderbill')->order('ob_startdate asc')->value('ob_startdate');
  33. if($ob_createdate){
  34. $start_time= strtotime(date('Y-m-01 0:0:0',$ob_createdate));
  35. }
  36. }
  37. if(isset($start_time)){
  38. for($i=1;$i<=100;$i++){
  39. $end_time=strtotime(date('Y-m-01 0:0:0', $start_time)." +1 month")-1;
  40. if($end_time>$max_time){
  41. break;
  42. }
  43. $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();
  44. if($orderbill_sum){
  45. Db::name('orderstatis')->insert(array(
  46. 'os_month'=>date('Ym',$start_time),
  47. 'os_createdate'=>TIMESTAMP,
  48. 'os_order_totals'=>floatval($orderbill_sum['os_order_totals']),
  49. 'os_shipping_totals'=>floatval($orderbill_sum['os_shipping_totals']),
  50. 'os_order_returntotals'=>floatval($orderbill_sum['os_order_returntotals']),
  51. 'os_commis_totals'=>floatval($orderbill_sum['os_commis_totals']),
  52. 'os_commis_returntotals'=>floatval($orderbill_sum['os_commis_returntotals']),
  53. 'os_store_costtotals'=>floatval($orderbill_sum['os_store_costtotals']),
  54. 'os_vr_order_totals'=>floatval($orderbill_sum['os_vr_order_totals']),
  55. 'os_vr_commis_totals'=>floatval($orderbill_sum['os_vr_commis_totals']),
  56. 'os_vr_inviter_totals'=>floatval($orderbill_sum['os_vr_inviter_totals']),
  57. 'os_result_totals'=>floatval($orderbill_sum['os_result_totals']),
  58. 'os_inviter_totals'=>floatval($orderbill_sum['os_inviter_totals']),
  59. 'os_vr_order_return_totals'=>floatval($orderbill_sum['os_vr_order_return_totals']),
  60. 'os_vr_commis_return_totals'=>floatval($orderbill_sum['os_vr_commis_return_totals']),
  61. ));
  62. }else{
  63. Db::name('orderstatis')->insert(array('os_month'=>date('Ym',$start_time),'os_createdate'=>TIMESTAMP));
  64. }
  65. $start_time=$end_time+1;
  66. }
  67. if($end_time<$max_time){
  68. $this->redirect('month/index');
  69. }
  70. }
  71. }
  72. }
  73. ?>