Cron.php 3.1 KB

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