Cron.php 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  1. <?php
  2. namespace Cash\Lib;
  3. use Dever;
  4. class Cron
  5. {
  6. private function check($info)
  7. {
  8. if (!$info['stat_day']) {
  9. $info['stat_day'] = 1;
  10. }
  11. if ($info['stat_type'] == 1) {
  12. $day = intval(date('d'));
  13. if ($day != $info['stat_day']) {
  14. return false;
  15. }
  16. } elseif ($info['stat_type'] == 2) {
  17. $day = intval(date('w'));
  18. if (!$day || $day == 0) {
  19. $day = 7;
  20. }
  21. if ($day != $info['stat_day']) {
  22. return false;
  23. }
  24. }
  25. return true;
  26. }
  27. # 处理门店对账单
  28. public function shop_api(){}
  29. public function shop()
  30. {
  31. $num = Dever::input('num', 1);
  32. $where['status'] = 2;
  33. $shop = Dever::db('shop/info')->select();
  34. foreach ($shop as $k => $v) {
  35. $where['type'] = 1;
  36. $where['type_id'] = $v['id'];
  37. $this->up($where, $v, 'shop', $num);
  38. }
  39. }
  40. public function store_api(){}
  41. public function store()
  42. {
  43. $num = Dever::input('num', 1);
  44. $where['status'] = 2;
  45. $store = Dever::db('store/info')->select();
  46. foreach ($store as $k => $v) {
  47. $where['type'] = 2;
  48. $where['type_id'] = $v['id'];
  49. $this->up($where, $v, 'store', $num);
  50. //$where['source_type'] = 2;
  51. //$where['source_id'] = $v['id'];
  52. //$this->up($where, $v, 'store', $num);
  53. }
  54. }
  55. public function factory_api(){}
  56. public function factory()
  57. {
  58. $num = Dever::input('num', 1);
  59. $where['status'] = 2;
  60. $store = Dever::db('factory/info')->select();
  61. foreach ($store as $k => $v) {
  62. $where['source_type'] = 3;
  63. $where['source_id'] = $v['id'];
  64. $this->up($where, $v, 'factory', $num);
  65. }
  66. }
  67. private function up($where, $info, $type, $num)
  68. {
  69. $state = $this->check($info);
  70. if (!$state) {
  71. return;
  72. }
  73. if ($info['stat_type'] == 1) {
  74. $method = 'month';
  75. } elseif ($info['stat_type'] == 2) {
  76. $method = 'week';
  77. } else {
  78. $method = 'day';
  79. }
  80. list($start, $end) = Dever::$method($num);
  81. $where['start'] = $start;
  82. $where['end'] = $end;
  83. $data = array();
  84. $data[$type . '_id'] = $info['id'];
  85. $data['type'] = $info['stat_type'];
  86. $data['day'] = $start;
  87. $find = Dever::db('cash/' . $type)->find($data);
  88. if ($type == 'factory') {
  89. $msg_type = 4;
  90. $cash = Dever::db('cash/order')->getPCash($where);
  91. $data['cash'] = $cash['total'] ? $cash['total'] : 0;
  92. } else {
  93. $msg_type = 3;
  94. $cash = Dever::db('cash/order')->getCash($where);
  95. $data['cash'] = $cash['total'] ? $cash['total'] : 0;
  96. }
  97. $num = Dever::db('cash/order')->getNum($where);
  98. $data['num'] = $num['total'] ? $num['total'] : 0;
  99. $data['start'] = $start;
  100. $data['end'] = $end;
  101. if (!$find) {
  102. $id = Dever::db('cash/' . $type)->insert($data);
  103. } else {
  104. $id = $data['where_id'] = $find['id'];
  105. Dever::db('cash/' . $type)->update($data);
  106. }
  107. if (($type == 'factory' || $type == 'store') && Dever::project('message') && $id) {
  108. $msg_param['type'] = 2;//消息头类型2是对账单消息
  109. $msg_param['id'] = $id;
  110. $msg_param = Dever::json_encode($msg_param);
  111. $msg = '您的'.Dever::load('cash/lib/set')->statDate($data['type'], $data['day']).'对账单已经生成,请您及时确认,确认之后方可结算';
  112. Dever::load('message/lib/data')->push(-1, $info['id'], '对账通知', $msg, 6, $msg_type, false, $msg_param);
  113. }
  114. }
  115. }