123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306 |
- <?php
- namespace Shop\Lib;
- use Dever;
- class Cron
- {
- /**
- * 处理优惠券到期时间
- *
- * @return mixed
- */
- public function coupon_api()
- {
- $coupon = Dever::db('shop/user_coupon')->getAll(array('status' => 1, 'edate' => time() - 86400));
- if ($coupon && Dever::project('message')) {
- foreach ($coupon as $k => $v) {
- $coupon_info = Dever::db('goods/coupon')->find($v['coupon_id']);
- $msg = $coupon_info['name'] . ",要到期啦!";
- $msg_param['type'] = 2;//消息类型2是优惠券
- $msg_param['id'] = $v['id'];
- $msg_param['coupon_id'] = $v['coupon_id'];
- $msg_param = Dever::json_encode($msg_param);
- Dever::load('message/lib/data')->push(-1, $v['uid'], '优惠劵到期提醒', $msg, 2, 1, false, $msg_param);
- }
- }
- }
- /**
- * 处理待支付订单提醒
- *
- * @return mixed
- */
- public function order_api()
- {
- # 获取超过5分钟未支付的订单
- $time = time();
- $where['status'] = 1;
- $where['cdate'] = $time + 300;
- $order = Dever::db('shop/sell_order')->getDataByTime($where);
- if ($order && Dever::project('message')) {
- foreach ($order as $k => $v) {
- if ($time - $v['cdate'] >= 900) {
- Dever::db('shop/sell_order')->update(array('where_id' => $v['id'], 'status' => 11));
- } else {
- $msg = "您有一笔待付款订单,请及时付款。\r\n订单15分钟内未付款自动取消~";
- $shop = Dever::db('shop/info')->one($v['shop_id']);
- $msg_param['type'] = 1;//消息类型1是订单消息
- $msg_param['id'] = $v['id'];
- $msg_param['name'] = $shop['name'];
- $msg_param = Dever::json_encode($msg_param);
- Dever::load('message/lib/data')->push(-1, $v['uid'], '订单待支付提醒', $msg, 2, 1, false, $msg_param);
- }
- }
- }
- }
- /**
- * 处理销售数据 生成每天的销量统计
- *
- * @return mixed
- */
- public function sell_api()
- {
- $num = Dever::input('num', 1);
- $start = Dever::input('start', date('Y-m-d', strtotime('-'.$num.' day')));
- $end = Dever::input('end', date('Y-m-d'));
- $where['status'] = '1,2,3,4,5,6';
- $start = Dever::maketime($start . ' 00:00:00');
- $end = Dever::maketime($end . ' 23:59:59');
- $day = intval(($end - $start)/86400);
- $shop = Dever::db('shop/info')->select();
- foreach ($shop as $k => $v) {
- $where['shop_id'] = $v['id'];
- for($i=0; $i<=$day; $i++) {
- $where['start'] = $start + 86400*$i;
- $where['end'] = $start + 86400*$i + 86399;
- $data = array();
- $data['shop_id'] = $v['id'];
- $data['day'] = $where['start'];
- $info = Dever::db('shop/sell_stat')->find($data);
- $cash = Dever::db('shop/sell_order')->getCashNum($where);
- $data['cash'] = $cash['total'];
- $data['order'] = Dever::db('shop/sell_order')->getOrderNum($where);
- $goods = Dever::db('shop/sell_order')->getGoodsNum($where);
- $data['goods'] = $goods['total'];
- $data['area'] = $v['area'];
- $data['province'] = $v['province'];
- $data['city'] = $v['city'];
- $data['county'] = $v['county'];
- $data['town'] = $v['town'];
- if (!$info) {
- Dever::db('shop/sell_stat')->insert($data);
- } else {
- $data['where_id'] = $info['id'];
- Dever::db('shop/sell_stat')->update($data);
- }
- }
- }
- }
- public function buy_api()
- {
- $num = Dever::input('num', 1);
- $start = Dever::input('start', date('Y-m-d', strtotime('-'.$num.' day')));
- $end = Dever::input('end', date('Y-m-d'));
- $where['status'] = '1,2,3,4,5,6';
- $start = Dever::maketime($start . ' 00:00:00');
- $end = Dever::maketime($end . ' 23:59:59');
- $day = intval(($end - $start)/86400);
- $shop = Dever::db('shop/info')->select();
- foreach ($shop as $k => $v) {
- $where['shop_id'] = $v['id'];
- for($i=0; $i<=$day; $i++) {
- $where['start'] = $start + 86400*$i;
- //$where['end'] = $start + 86400*$i + 86399;
- $data = array();
- $data['type'] = 1;
- $data['type_id'] = $v['id'];
- $data['day'] = $where['start'];
- $info = Dever::db('shop/buy_stat')->find($data);
- $cash = Dever::db('shop/buy_order')->getCashNum($where);
- $data['cash'] = $cash['total'];
- $cash = Dever::db('shop/buy_order')->getPCashNum($where);
- $data['p_cash'] = $cash['total'];
- $data['order'] = Dever::db('shop/buy_order')->getOrderNum($where);
- $goods = Dever::db('shop/buy_order')->getGoodsNum($where);
- $data['goods'] = $goods['total'];
- $data['area'] = $v['area'];
- $data['province'] = $v['province'];
- $data['city'] = $v['city'];
- $data['county'] = $v['county'];
- $data['town'] = $v['town'];
- if (!$info) {
- Dever::db('shop/buy_stat')->insert($data);
- } else {
- $data['where_id'] = $info['id'];
- Dever::db('shop/buy_stat')->update($data);
- }
- }
- }
- }
- # 处理月度对账数据 废弃,直接用结算单处理
- public function sell_month_api()
- {
- return;
- $num = Dever::input('num', -1);
- if ($num > 0) {
- $month = Dever::input('start', date('Y-m', strtotime('-'.$num.' month')));
- } else {
- $month = Dever::input('start', date('Y-m'));
- }
- $where['status'] = 2;
- $start = Dever::maketime($month . '-01 00:00:00');
- $end = Dever::maketime($month . '-31 23:59:59');
- $shop = Dever::db('shop/info')->select();
- foreach ($shop as $k => $v) {
- $where['shop_id'] = $v['id'];
- $where['start'] = $start;
- $where['end'] = $end;
- $data = array();
- $data['shop_id'] = $v['id'];
- $data['month'] = $start;
- $info = Dever::db('shop/sell_stat_month')->find($data);
- $data['cash'] = Dever::db('shop/sell_order')->getCashNum($where);
- $data['order'] = Dever::db('shop/sell_order')->getOrderNum($where);
- $data['goods'] = Dever::db('shop/sell_order')->getGoodsNum($where);
- if (!$info) {
- Dever::db('shop/sell_stat_month')->insert($data);
- } else {
- $data['where_id'] = $info['id'];
- Dever::db('shop/sell_stat_month')->update($data);
- }
- }
- }
- # 处理月度对账数据:门店采购 废弃,直接用结算单处理
- public function buy_month_api()
- {
- return;
- $num = Dever::input('num', -1);
- if ($num > 0) {
- $month = Dever::input('start', date('Y-m', strtotime('-'.$num.' month')));
- } else {
- $month = Dever::input('start', date('Y-m'));
- }
- $where['status'] = '5,6';
- $start = Dever::maketime($month . '-01 00:00:00');
- $end = Dever::maketime($month . '-31 23:59:59');
- $shop = Dever::db('shop/info')->select();
- foreach ($shop as $k => $v) {
- $where['type'] = 1;
- $where['type_id'] = $v['id'];
- $where['start'] = $start;
- $where['end'] = $end;
- $data = array();
- $data['shop_id'] = $v['id'];
- $data['month'] = $start;
- $info = Dever::db('shop/buy_stat_month')->find($data);
- $data['cash'] = Dever::db('shop/buy_order')->getCashNum($where);
- $data['order'] = Dever::db('shop/buy_order')->getOrderNum($where);
- $data['goods'] = Dever::db('shop/buy_order')->getGoodsNum($where);
- if (!$info) {
- Dever::db('shop/buy_stat_month')->insert($data);
- } else {
- $data['where_id'] = $info['id'];
- Dever::db('shop/buy_stat_month')->update($data);
- }
- }
- }
- # 处理月度对账数据:仓库对账 废弃,直接用结算单处理
- public function store_month_api()
- {
- return;
- $num = Dever::input('num', -1);
- if ($num > 0) {
- $month = Dever::input('start', date('Y-m', strtotime('-'.$num.' month')));
- } else {
- $month = Dever::input('start', date('Y-m'));
- }
- $where['status'] = '5,6';
- $start = Dever::maketime($month . '-01 00:00:00');
- $end = Dever::maketime($month . '-31 23:59:59');
- $store = Dever::db('store/info')->select();
- foreach ($store as $k => $v) {
- $where['type'] = 2;
- $where['type_id'] = $v['id'];
- $where['start'] = $start;
- $where['end'] = $end;
- $data = array();
- $data['store_id'] = $v['id'];
- $data['month'] = $start;
- $info = Dever::db('shop/store_stat_month')->find($data);
- $data['cash'] = Dever::db('shop/buy_order')->getCashNum($where);
- $data['order'] = Dever::db('shop/buy_order')->getOrderNum($where);
- $data['goods'] = Dever::db('shop/buy_order')->getGoodsNum($where);
- if (!$info) {
- Dever::db('shop/store_stat_month')->insert($data);
- } else {
- $data['where_id'] = $info['id'];
- Dever::db('shop/store_stat_month')->update($data);
- }
- }
- }
- # 处理月度对账数据:工厂对账 废弃,直接用结算单处理
- public function factory_month_api()
- {
- return;
- $num = Dever::input('num', -1);
- if ($num > 0) {
- $month = Dever::input('start', date('Y-m', strtotime('-'.$num.' month')));
- } else {
- $month = Dever::input('start', date('Y-m'));
- }
- $where['status'] = '5,6';
- $start = Dever::maketime($month . '-01 00:00:00');
- $end = Dever::maketime($month . '-31 23:59:59');
- $factory = Dever::db('factory/info')->select();
- foreach ($factory as $k => $v) {
- $where['source_type'] = 3;
- $where['source_id'] = $v['id'];
- $where['start'] = $start;
- $where['end'] = $end;
- $data = array();
- $data['factory_id'] = $v['id'];
- $data['month'] = $start;
- $info = Dever::db('shop/factory_stat_month')->find($data);
- $data['cash'] = Dever::db('shop/buy_order')->getCashNum($where);
- $data['order'] = Dever::db('shop/buy_order')->getOrderNum($where);
- $data['goods'] = Dever::db('shop/buy_order')->getGoodsNum($where);
- if (!$info) {
- Dever::db('shop/factory_stat_month')->insert($data);
- } else {
- $data['where_id'] = $info['id'];
- Dever::db('shop/factory_stat_month')->update($data);
- }
- }
- }
- }
|