dever 6 jaren geleden
bovenliggende
commit
e873553041
2 gewijzigde bestanden met toevoegingen van 400 en 0 verwijderingen
  1. 288 0
      stat/database/seller.php
  2. 112 0
      stat/lib/Seller.php

+ 288 - 0
stat/database/seller.php

@@ -0,0 +1,288 @@
+<?php
+# 获取小刊分类权限
+$auth = Dever::tops();
+
+# 如果用linkage,那么下面这两个用不上了
+$journal = function() use ($auth)
+{
+    $array = array();
+    if ($auth) {
+        $info = Dever::db('journal/info')->getIds(array('cate_id' => $auth, 'buy' => 1));
+    } else {
+        $info = Dever::db('journal/info')->state(array('buy' => 1));
+    }
+    if($info)
+    {
+        $array += $info;
+    }
+    return $array;
+};
+
+$cate = function() use ($auth)
+{
+    $array = array();
+    if ($auth) {
+        $info = Dever::db('journal/cate')->getIds(array('ids' => $auth));
+    } else {
+        $info = Dever::db('journal/cate')->state();
+    }
+    
+    if($info)
+    {
+        $array += $info;
+    }
+    return $array;
+};
+$seller = function()
+{
+    $array = array();
+    $info = Dever::db('code/seller')->state();
+    if($info)
+    {
+        $array += $info;
+    }
+    return $array;
+};
+
+$zhou = Dever::input('search_zhou');
+if ($zhou) {
+    $group = 'seller_id,cate_id';
+} else {
+    $group = 'day_int,seller_id,cate_id';
+}
+
+$list = array
+(
+    # 匹配的正则或函数 选填项
+    'option' => array
+    (
+
+        'start_day_int' => array('yes-day_int', '>='),
+        'end_day_int' => array('yes-day_int', '<='),
+        'seller_id' => 'yes',
+        'cate_id' => 'yes',
+        'journal_id' => 'yes',
+        'state' => 1,
+    ),
+    'type' => 'all',
+    'order' => array('day_int' => 'desc', 'id' => 'desc'),
+    'group' => $group,
+    'page' => array(20, 'list'),
+    'col' => 'id,sum(code_num) as code_num,sum(code_yes_num) as code_yes_num,sum(code_no_num) as code_no_num,sum(code_drop_num) as code_drop_num,cdate,journal_id,seller_id,day_int,day_string,cate_id',
+);
+
+//$search = Dever::input('search_option_journal_id');
+$search = Dever::input('search_linkage_cate_journal');
+if ($search && $search != -1 && isset($search[1]) && $search[1] > 0) {
+    $list['option']['journal_id'] = $search[1];
+    Dever::setInput('search_option_journal_id', $search[1]);
+}
+if (!$zhou) {
+    unset($list['group']);
+    $list['col'] = 'id,code_num,code_yes_num,code_no_num,code_drop_num,cdate,journal_id,seller_id,day_int,day_string,cate_id';
+}
+
+if ($auth) {
+    $list['option']['cate_id'] = array($auth, 'in');
+}
+
+$config = array
+(
+    # 表名
+    'name' => 'seller',
+    # 显示给用户看的名称
+    'lang' => '销售商订单',
+    'order' => '8',
+    # 数据结构
+    'struct' => array
+    (
+    
+        'id'        => array
+        (
+            'type'      => 'int-11',
+            'name'      => 'ID',
+            'default'   => '',
+            'desc'      => '',
+            'match'     => 'is_numeric',
+            //'list'        => true,
+        ),
+
+        'day_string'       => array
+        (
+            'type'      => 'varchar-60',
+            'name'      => '统计日期',
+            'default'   => '',
+            'desc'      => '统计日期',
+            'match'     => 'is_string',
+            'update'    => 'text',
+            //'search'    => 'fulltext',
+            'list'      => $zhou ? false : true,
+        ),
+
+        'day_int'        => array
+        (
+            'type'      => 'int-11',
+            'name'      => '统计日期',
+            'default'   => '',
+            'desc'      => '统计日期',
+            'match'     => 'is_numeric',
+            'update'    => 'text',
+            'search'    => 'time',
+            'order'     => 'desc',
+            //'list'        => true,
+        ),
+
+        'seller_id'      => array
+        (
+            'type'      => 'int-11',
+            'name'      => '销售商',
+            'default'   => '',
+            'desc'      => '销售商',
+            'match'     => 'is_numeric',
+            'update'    => 'select',
+            'search'    => 'select',
+            'option'    => $seller,
+            'list'      => true,
+        ),
+
+        'cate_journal'     => array
+        (
+            'name'      => '小刊',
+            'default'   => '',
+            'desc'      => '小刊',
+            'search'    => 'linkage',
+            'search_col' => 'cate_id,product_id',
+            'option'    => Dever::url('lib/manage.search_cate_journal', 'journal'),
+        ),
+
+        'cate_id'       => array
+        (
+            'type'      => 'int-11',
+            'name'      => '小刊分类',
+            'default'   => '1',
+            'desc'      => '小刊分类',
+            'match'     => 'is_numeric',
+            'update'    => 'select',
+            'option'    => $cate,
+            //'search'    => 'select',
+            'list'      => true,
+        ),
+
+        'journal_id'      => array
+        (
+            'type'      => 'int-11',
+            'name'      => '小刊',
+            'default'   => '',
+            'desc'      => '小刊',
+            'match'     => 'is_numeric',
+            'update'    => 'select',
+            //'search'    => 'select',
+            'option'    => $journal,
+            'list'      => $zhou ? false : 'Dever::load("stat/lib/manage.info", {journal_id})',
+        ),
+
+        'code_num'       => array
+        (
+            'type'      => 'int-11',
+            'name'      => '兑换码总数量',
+            'default'   => '0',
+            'match'     => '兑换码总数量',
+            'match'     => 'is_numeric',
+            'update'    => 'text',
+            //'list'      => true,
+        ),
+
+        'code_yes_num'       => array
+        (
+            'type'      => 'int-11',
+            'name'      => '兑换码已用数',
+            'default'   => '0',
+            'match'     => '兑换码已用数',
+            'match'     => 'is_numeric',
+            'update'    => 'text',
+            'list'      => true,
+        ),
+
+        'code_no_num'       => array
+        (
+            'type'      => 'int-11',
+            'name'      => '兑换码未用数',
+            'default'   => '0',
+            'match'     => '兑换码未用数',
+            'match'     => 'is_numeric',
+            'update'    => 'text',
+            'list'      => true,
+        ),
+
+        'code_drop_num'       => array
+        (
+            'type'      => 'int-11',
+            'name'      => '兑换码作废数',
+            'default'   => '0',
+            'match'     => '兑换码作废数',
+            'match'     => 'is_numeric',
+            'update'    => 'text',
+            'list'      => true,
+        ),
+
+        'state'     => array
+        (
+            'type'      => 'tinyint-1',
+            'name'      => '状态',
+            'default'   => '1',
+            'desc'      => '请选择状态',
+            'match'     => 'is_numeric',
+        ),
+        
+        'cdate'     => array
+        (
+            'type'      => 'int-11',
+            'name'      => '上次统计时间',
+            'match'     => array('is_numeric', time()),
+            'desc'      => '',
+            # 只有insert时才生效
+            'insert'    => true,
+            //'search'    => 'date',
+            'list'      => 'date("Y-m-d H:i", {cdate})',
+        ),
+    ),
+
+    'top' => Dever::config('base')->top,
+
+    'manage' => array
+    (
+        'insert' => false,
+        'edit' => false,
+        'delete' => false,
+        'num' => false,
+        'excel' => true,
+
+        //'page_list' => 'journal',
+    ),
+
+    'request' => array
+    (
+        'list' => $list,
+
+        'getData' => array
+        (
+            # 匹配的正则或函数 选填项
+            'option' => array
+            (
+                'start' => array('yes-day_int', '>='),
+                'end' => array('yes-day_int', '<='),
+                'state' => 1,
+            ),
+            'type' => 'all',
+            'order' => array('day_int' => 'desc'),
+            //'group' => 'day_int',
+            'col' => '*',
+        ),
+    ),
+);
+
+
+if ($search && $search > 0) {
+	
+}
+return $config;

+ 112 - 0
stat/lib/Seller.php

@@ -0,0 +1,112 @@
+<?php
+
+namespace Stat\Lib;
+
+use Dever;
+
+class Seller
+{
+    const NUM = 2;
+
+    public function data_api()
+    {
+
+    }
+    /**
+     * 获取数据-可以放到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;
+
+        $seller = Dever::db('code/seller')->state();
+        $journal = Dever::db('journal/info')->state(array('buy' => 1));
+
+        if ($seller && $journal) {
+        	foreach ($seller as $sk => $sv) {
+        		for ($i = 0; $i < $num; $i++) {
+        			$where['start'] = strtotime("$start -$i day");
+	                $where['end'] = $where['start'] + 86399;
+        			foreach ($journal as $k => $v) {
+	                    $this->total($sv, $v, $where);
+		            }
+                }
+            }
+        }
+        return true;
+    }
+
+    private function total($seller, $info, $where)
+    {
+    	$day = date('Y-m-d', $where['start']);
+        $sql = 'select * from wonderful_code_info where seller_id = '.$seller['id'].' and product_id = '.$info['id'].' and state = 1 and cdate >= '.$where['start'].' and cdate <= '.$where['end'];
+        $code = Dever::db('code/info')->fetchAll($sql);
+
+        $code_num = $code_yes_num = $code_no_num = $code_drop_num = 0;
+
+        if ($code) {
+            foreach ($code as $k => $v) {
+                $code_num++;
+                if ($v['type'] <= 2) {
+                    # 未使用
+                    $code_no_num++;
+                } elseif ($v['type'] == 3) {
+                    # 已使用
+                    $code_yes_num++;
+                } elseif ($v['type'] == 4) {
+                    # 已作废
+                    $code_drop_num++;
+                }
+            }
+        }
+
+        $this->update($seller['id'], $info['cate_id'], $info['id'], $day, $code_num, $code_yes_num, $code_no_num, $code_drop_num);
+    }
+
+    public function update($seller_id, $cate_id, $info_id, $day, $code_num, $code_yes_num, $code_no_num, $code_drop_num)
+    {
+        $update = array();
+        $update['day_string'] = $day;
+        
+        $update['code_num'] = $code_num;
+        $update['code_yes_num'] = $code_yes_num;
+        $update['code_no_num'] = $code_no_num;
+        $update['code_drop_num'] = $code_drop_num;
+        $update['seller_id'] = $seller_id;
+        $update['cate_id'] = $cate_id;
+        $update['journal_id'] = $info_id;
+        $update['cdate'] = time();
+
+        $where = array();
+        $where['day_int'] = $update['day_int'];
+        $where['seller_id'] = $update['seller_id'];
+        $where['journal_id'] = $update['journal_id'];
+
+        $info = Dever::db('stat/seller')->one($where);
+        if (!$info) {
+            $id = Dever::db('stat/seller')->insert($update);
+        } else {
+            $id = $info['id'];
+            $update['where_id'] = $id;
+            Dever::db('stat/seller')->update($update);
+        }
+    }
+}