|
@@ -0,0 +1,114 @@
|
|
|
+<?php
|
|
|
+
|
|
|
+namespace Stat\Lib;
|
|
|
+
|
|
|
+use Dever;
|
|
|
+
|
|
|
+class Journal
|
|
|
+{
|
|
|
+ const NUM = 1;
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 获取数据-可以放到cron里
|
|
|
+ *
|
|
|
+ * @return mixed
|
|
|
+ */
|
|
|
+ public function data()
|
|
|
+ {
|
|
|
+ # 获取最近self::NUM天的数据
|
|
|
+ $num = Dever::input('num', self::NUM);
|
|
|
+
|
|
|
+ $day = Dever::input('day');
|
|
|
+ if ($day) {
|
|
|
+ $day = Dever::maketime($day);
|
|
|
+ } else {
|
|
|
+ $day = time();
|
|
|
+ }
|
|
|
+ $start = date('Y-m-d 00:00:00', $day);
|
|
|
+ $option = array
|
|
|
+ (
|
|
|
+ 'state' => 1,
|
|
|
+ 'start' => array('yes-cdate', '>'),
|
|
|
+ 'end' => array('yes-cdate', '<'),
|
|
|
+ );
|
|
|
+ $where['option'] = $option;
|
|
|
+
|
|
|
+ $journal = Dever::db('journal/info')->state(array('buy' => 1));
|
|
|
+ print_r($journal);
|
|
|
+
|
|
|
+ if ($journal) {
|
|
|
+ foreach ($journal as $k => $v) {
|
|
|
+ for ($i = 0; $i < $num; $i++) {
|
|
|
+ $where['start'] = strtotime("$start -$i day");
|
|
|
+ $where['end'] = $where['start'] + 86399;
|
|
|
+ $this->total($v, $where, $day);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+
|
|
|
+ private function total($info, $where, $day)
|
|
|
+ {
|
|
|
+ # 这里就是为了做下sql的实现方式,其实用dever自带的功能完全可以实现。
|
|
|
+ $day = date('Y-m-d', $where['start']);
|
|
|
+ $sql = 'select * from applet_passport_wechat where type = 1 and product_id = '.$info['id'].' and state = 1 and cdate >= '.$where['start'].' and cdate <= '.$where['end'];
|
|
|
+ echo $sql;
|
|
|
+ $order = Dever::db('journal/order')->fetchAll($sql);
|
|
|
+ print_r($order);
|
|
|
+
|
|
|
+ if ($order) {
|
|
|
+ $order_num = $order_yes_num = $order_no_num = $buy_num = $buy_cash = 0;
|
|
|
+ foreach ($order as $k => $v) {
|
|
|
+ $order_num++;
|
|
|
+ if ($v['status'] == 1) {
|
|
|
+ # 待支付
|
|
|
+ $order_no_num++;
|
|
|
+ } elseif ($v['status'] == 2) {
|
|
|
+ # 已支付
|
|
|
+ $order_yes_num++;
|
|
|
+ }
|
|
|
+ if ($v['buy_id']) {
|
|
|
+ $buy = Dever::db('journal/buy_num')->one($v['buy_id']);
|
|
|
+ if ($buy['num']) {
|
|
|
+ $buy_num += $buy['num'];
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ if ($v['cash']) {
|
|
|
+ $buy_cash += $v['cash'];
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ $this->update($info['id'], $day, $order_num, $order_yes_num, $order_no_num, $buy_num, $buy_cash);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ public function update($info_id, $day, $order_num, $order_yes_num, $order_no_num, $buy_num, $buy_cash)
|
|
|
+ {
|
|
|
+ $update = array();
|
|
|
+ $update['day_string'] = $day;
|
|
|
+ $update['day_int'] = Dever::maketime($day);
|
|
|
+ $update['order_num'] = $order_num;
|
|
|
+ $update['order_yes_num'] = $order_yes_num;
|
|
|
+ $update['order_no_num'] = $order_no_num;
|
|
|
+ $update['buy_num'] = $buy_num;
|
|
|
+ $update['buy_cash'] = $buy_cash;
|
|
|
+ $update['journal_id'] = $info_id;
|
|
|
+
|
|
|
+ print_r($update);die;
|
|
|
+
|
|
|
+ $where = array();
|
|
|
+ $where['day_int'] = $update['day_int'];
|
|
|
+ $where['journal_id'] = $update['journal_id'];
|
|
|
+
|
|
|
+ $info = Dever::db('stat/journal')->one($where);
|
|
|
+ if (!$info) {
|
|
|
+ $id = Dever::db('stat/journal')->insert($update);
|
|
|
+ } else {
|
|
|
+ $id = $info['id'];
|
|
|
+ $update['where_id'] = $id;
|
|
|
+ Dever::db('stat/journal')->update($update);
|
|
|
+ }
|
|
|
+ }
|
|
|
+}
|