| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107 | 
							- <?php
 
- namespace Cash\Lib;
 
- use Dever;
 
- class Cron
 
- {
 
-     # 处理门店对账单
 
-     public function shop_api(){}
 
-     public function shop()
 
-     {
 
-         $num = Dever::input('num', -1);
 
-         $where['status'] = 2;
 
-        
 
-         $shop = Dever::db('shop/info')->select();
 
-         foreach ($shop as $k => $v) {
 
-         	$where['type'] = 1;
 
-             $where['type_id'] = $v['id'];
 
-         	$this->up($where, $v, 'shop', $num);
 
-         }
 
-     }
 
-     public function store_api(){}
 
-     public function store()
 
-     {
 
-         $num = Dever::input('num', -1);
 
-         $where['status'] = 2;
 
-        
 
-         $store = Dever::db('store/info')->select();
 
-         foreach ($store as $k => $v) {
 
-             $where['type'] = 2;
 
-             $where['type_id'] = $v['id'];
 
-             $this->up($where, $v, 'store', $num);
 
-         }
 
-     }
 
-     public function factory_api(){}
 
-     public function factory()
 
-     {
 
-         $num = Dever::input('num', -1);
 
-         $where['status'] = 2;
 
-        
 
-         $store = Dever::db('factory/info')->select();
 
-         foreach ($store as $k => $v) {
 
-             $where['source_type'] = 3;
 
-             $where['source_id'] = $v['id'];
 
-             $this->up($where, $v, 'factory', $num);
 
-         }
 
-     }
 
-     private function up($where, $info, $type, $num)
 
-     {
 
-         if ($info['stat_type'] == 2) {
 
-     		$method = 'week';
 
-     	} else {
 
-     		$method = 'month';
 
-     	}
 
-     	list($start, $end) = Dever::$method($num);
 
-     	$where['start'] = $start;
 
-         $where['end'] = $end;
 
-         $data = array();
 
-         $data[$type . '_id'] = $info['id'];
 
-         $data['type'] = $info['stat_type'];
 
-         $data['day'] = $start;
 
-         $find = Dever::db('cash/' . $type)->find($data);
 
-         if ($type == 'factory') {
 
-             $msg_type = 4;
 
-             $cash = Dever::db('cash/order')->getPCash($where);
 
-             $data['cash'] = $cash['total'] ? $cash['total'] : 0;
 
-         } else {
 
-             $msg_type = 3;
 
-             $cash = Dever::db('cash/order')->getCash($where);
 
-             $data['cash'] = $cash['total'] ? $cash['total'] : 0;
 
-         }
 
-         
 
-         $num = Dever::db('cash/order')->getNum($where);
 
-         $data['num'] = $num['total'] ? $num['total'] : 0;
 
-         $data['start'] = $start;
 
-         $data['end'] = $end;
 
-         if (!$find) {
 
-             $id = Dever::db('cash/' . $type)->insert($data);
 
-         } else {
 
-             $id = $data['where_id'] = $find['id'];
 
-             Dever::db('cash/' . $type)->update($data);
 
-         }
 
-         if (($type == 'factory' || $type == 'store') && Dever::project('message') && $id) {
 
-             $msg_param['type'] = 2;//消息头类型2是对账单消息
 
-             $msg_param['id'] = $id;
 
-             $msg_param = Dever::json_encode($msg_param);
 
-             $msg = '您的'.Dever::load('cash/lib/set')->statDate($data['type'], $data['day']).'对账单已经生成,请您及时确认,确认之后方可结算';
 
-             Dever::load('message/lib/data')->push(-1, $info['id'], '对账通知', $msg, 6, $msg_type, false, $msg_param);
 
-         }
 
-     }
 
- }
 
 
  |