| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134 |
- <?php
- namespace addons\OperatingNote\common\models;
- use Yii;
- /**
- * This is the model class for table "{{%addons_operating_note_statistics}}".
- *
- * @property int $id
- * @property int $mall_id 商城ID
- * @property int $push_count 发布量
- * @property int $views_count 浏览量
- * @property int $stars_count 点赞量
- * @property int $shares_count 分享量
- * @property int $discuss_count 评论量
- * @property int $goods_views_count 商品访问统计
- * @property int $order_count 订单统计
- * @property int $goods_amount 成交金额
- * @property int $created_at 创建时间
- * @property int $updated_at 更新时间
- */
- class AddonsOperatingNoteStatistics extends \common\models\base\BaseActiveRecord
- {
- /**
- * {@inheritdoc}
- */
- public static function tableName()
- {
- return '{{%addons_operating_note_statistics}}';
- }
- /**
- * {@inheritdoc}
- */
- public function rules()
- {
- return [
- [['mall_id', 'push_count', 'views_count', 'stars_count', 'shares_count', 'discuss_count', 'goods_views_count', 'order_count', 'goods_amount', 'created_at', 'updated_at'], 'required'],
- [['mall_id', 'push_count', 'views_count', 'stars_count', 'shares_count', 'discuss_count', 'goods_views_count', 'order_count', 'goods_amount', 'created_at', 'updated_at'], 'integer'],
- ];
- }
- /**
- * {@inheritdoc}
- */
- public function attributeLabels()
- {
- return [
- 'id' => 'ID',
- 'mall_id' => '商城ID',
- 'push_count' => '发布量',
- 'views_count' => '浏览量',
- 'stars_count' => '点赞量',
- 'shares_count' => '分享量',
- 'discuss_count' => '评论量',
- 'goods_views_count' => '商品访问统计',
- 'order_count' => '订单统计',
- 'goods_amount' => '成交金额',
- 'created_at' => '创建时间',
- 'updated_at' => '更新时间',
- ];
- }
- /**
- * 保存数据
- * @Author: ltm
- * @DateTime: 2021/01/05 0022 17:13
- * @Copyright: copyright (c) 2021 广东七件事集团
- * @param array $params
- * @return AddonsMaterial|bool
- */
- public static function statistics($mall_id, $start_time, $end_time)
- {
- if ($start_time) $beginThismonth = $start_time; else $beginThismonth = mktime(0, 0, 0, date('m'), 1, date('Y'));
- if ($start_time) $endThismonth = $end_time; else $endThismonth = mktime(23, 59, 59, date('m'), date('t'), date('Y'));
- $params['where'][] = ['=', 'mall_id', $mall_id];
- $params['where'][] = ['between', 'created_at', $beginThismonth, $endThismonth];
- $params['order'] = 'created_at';
- $yesterday_data = AddonsOperatingNoteStatistics::lists($params, true);
- $data['items'] = ['发布量', '分享量', '点赞量', '浏览量', '评论量', '引导下单转化率'];
- if ($yesterday_data) foreach (array_column($yesterday_data, 'created_at') as $k => $v) $data['dates'][] = date("Y-m-d", $v);
- $data['series'][0]['type'] = "line";
- $data['series'][0]['name'] = "发布量";
- if ($yesterday_data) $data['series'][0]['data'] = array_column($yesterday_data, 'push_count');
- $data['series'][1]['type'] = "line";
- $data['series'][1]['name'] = "分享量";
- if ($yesterday_data) $data['series'][1]['data'] = array_column($yesterday_data, 'shares_count');
- $data['series'][2]['type'] = "line";
- $data['series'][2]['name'] = "点赞量";
- if ($yesterday_data) $data['series'][2]['data'] = array_column($yesterday_data, 'stars_count');
- $data['series'][3]['type'] = "line";
- $data['series'][3]['name'] = "浏览量";
- if ($yesterday_data) $data['series'][3]['data'] = array_column($yesterday_data, 'views_count');
- $data['series'][4]['type'] = "line";
- $data['series'][4]['name'] = "评论量";
- if ($yesterday_data) $data['series'][4]['data'] = array_column($yesterday_data, 'discuss_count');
- $data['series'][5]['type'] = "line";
- $data['series'][5]['name'] = "引导下单转化率";
- if ($yesterday_data) $data['series'][5]['data'] = array_column($yesterday_data, 'goods_views_count');
- return $data;
- }
- /**
- * @Author: ltm
- * @DateTime: 2022/1/17 0017 14:29
- * @Copyright: copyright (c) 2021 广东七件事集团
- * @param $data
- * @return string
- */
- public static function format($data)
- {
- $list = [];
- if ($data) {
- $list = array_map(function ($v) {
- if (is_numeric($v)) {
- if ($v > 10000) $v = ($v / 10000) . "万";
- }
- return $v;
- }, $data);
- }
- return $list;
- }
- }
|