123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228 |
- <?php
- namespace Cash\Lib;
- use Dever;
- class Cron
- {
- private function check($info)
- {
- $type = Dever::input('type');
- if ($type && $type == 1) {
- return true;
- }
- 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'];
- $where['pay_type'] = 1;
- $this->up($where, $v, 'shop', $num);
- }
- return 'ok';
- }
- # 处理门店零售对账单
- public function shop_sell_api(){}
- public function shop_sell()
- {
- $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'];
- $where['pay_type'] = '2,3';
- $this->up($where, $v, 'shop_sell', $num);
- }
- return 'ok';
- }
- 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';
- }
- $table = 'cash/' . $type;
- if ($type == 'shop_sell') {
- $type = 'shop';
- }
- 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($table)->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($table)->insert($data);
- } else {
- $id = $data['where_id'] = $find['id'];
- Dever::db($table)->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($table)->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;
- }
- # 修正礼品卡结算单金额,之前是九折,现在不是了
- public function up_cash_api()
- {
- $order = Dever::db('shop/sell_order')->select();
- if ($order) {
- foreach ($order as $k => $v) {
- if ($v['card_code_cash'] > 0) {
- # 礼品卡订单
- $info = Dever::db('cash/order')->select(array('pay_type' => 2, 'source_order_num' => $v['order_num']));
- $order_data = $v;
- $order_data['type'] = 1;
- $order_data['type_id'] = $order_data['shop_id'];
- $order_data['source_type'] = 4;
- $order_data['source_id'] = -1;
- $order_data['price'] = $v['card_code_cash'];
- $order_data['p_price'] = $v['card_code_cash'];
- if (!$info) {
- if ($v['status'] == 5 || $v['status'] == 6) {
- # 完成
- Dever::load('cash/lib/order')->up($order_data, 3, 2, false, 2, $v['fdate']);
- } elseif ($v['status'] == 8) {
- # 退款
- # 获取退款信息
-
- Dever::load('cash/lib/order')->up($order_data, 2, 2, false, 2, $v['operdate']);
- } elseif ($v['status'] == 7) {
- # 取消
- Dever::load('cash/lib/order')->up($order_data, 3, 3, false, 2, $v['operdate']);
- } else {
- # 处理中
- Dever::load('cash/lib/order')->up($order_data, 3, 1, false, 2, $v['cdate']);
- }
- } elseif ($info) {
- if ($v['status'] == 7 && $info['status'] == 2) {
- Dever::db('cash/order')->update(array('where_id' => $info['id'], 'status' => 1));
- }
- }
- }
- }
- }
- return 'ok';
- }
- }
|