| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153 | <?phpnamespace Cash\Lib;use Dever;class Cron{    private function check($info)    {        if (!$info['stat_day']) {            $info['stat_day'] = 1;        }        if ($info['stat_type'] == 1) {            $day = intval(date('d'));            if ($day != $info['stat_day']) {                return false;            }        } elseif ($info['stat_type'] == 2) {            $day = intval(date('w'));            if (!$day || $day == 0) {                $day = 7;            }            if ($day != $info['stat_day']) {                return false;            }        }        return true;    }    # 处理门店对账单    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'] = $w['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, 1);        }    }    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, $k = 1)    {        $state = $this->check($info);        if (!$state) {            return;        }        if ($info['stat_type'] == 1) {    		$method = 'month';    	} elseif ($info['stat_type'] == 2) {    		$method = 'week';    	} else {            $method = 'day';        }    	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;        $data['t'] = $k;        $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 ($id > 0 && $type == 'store') {            $where['source_type'] = $where['type'];            $where['source_id'] = $where['type_id'];            unset($where['type']);            unset($where['type_id']);            $cash = Dever::db('cash/order')->getCash($where);            $up['cash'] = $cash['total'] ? $cash['total'] : 0;            $num = Dever::db('cash/order')->getNum($where);            $up['num'] = $num['total'] ? $num['total'] : 0;            $data['cash'] += $up['cash'];            $data['num'] += $up['num'];            $data['where_id'] = $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);        }        return $id;    }}
 |