AddonsOperatingNoteStatistics.php 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  1. <?php
  2. namespace addons\OperatingNote\common\models;
  3. use Yii;
  4. /**
  5. * This is the model class for table "{{%addons_operating_note_statistics}}".
  6. *
  7. * @property int $id
  8. * @property int $mall_id 商城ID
  9. * @property int $push_count 发布量
  10. * @property int $views_count 浏览量
  11. * @property int $stars_count 点赞量
  12. * @property int $shares_count 分享量
  13. * @property int $discuss_count 评论量
  14. * @property int $goods_views_count 商品访问统计
  15. * @property int $order_count 订单统计
  16. * @property int $goods_amount 成交金额
  17. * @property int $created_at 创建时间
  18. * @property int $updated_at 更新时间
  19. */
  20. class AddonsOperatingNoteStatistics extends \common\models\base\BaseActiveRecord
  21. {
  22. /**
  23. * {@inheritdoc}
  24. */
  25. public static function tableName()
  26. {
  27. return '{{%addons_operating_note_statistics}}';
  28. }
  29. /**
  30. * {@inheritdoc}
  31. */
  32. public function rules()
  33. {
  34. return [
  35. [['mall_id', 'push_count', 'views_count', 'stars_count', 'shares_count', 'discuss_count', 'goods_views_count', 'order_count', 'goods_amount', 'created_at', 'updated_at'], 'required'],
  36. [['mall_id', 'push_count', 'views_count', 'stars_count', 'shares_count', 'discuss_count', 'goods_views_count', 'order_count', 'goods_amount', 'created_at', 'updated_at'], 'integer'],
  37. ];
  38. }
  39. /**
  40. * {@inheritdoc}
  41. */
  42. public function attributeLabels()
  43. {
  44. return [
  45. 'id' => 'ID',
  46. 'mall_id' => '商城ID',
  47. 'push_count' => '发布量',
  48. 'views_count' => '浏览量',
  49. 'stars_count' => '点赞量',
  50. 'shares_count' => '分享量',
  51. 'discuss_count' => '评论量',
  52. 'goods_views_count' => '商品访问统计',
  53. 'order_count' => '订单统计',
  54. 'goods_amount' => '成交金额',
  55. 'created_at' => '创建时间',
  56. 'updated_at' => '更新时间',
  57. ];
  58. }
  59. /**
  60. * 保存数据
  61. * @Author: ltm
  62. * @DateTime: 2021/01/05 0022 17:13
  63. * @Copyright: copyright (c) 2021 广东七件事集团
  64. * @param array $params
  65. * @return AddonsMaterial|bool
  66. */
  67. public static function statistics($mall_id, $start_time, $end_time)
  68. {
  69. if ($start_time) $beginThismonth = $start_time; else $beginThismonth = mktime(0, 0, 0, date('m'), 1, date('Y'));
  70. if ($start_time) $endThismonth = $end_time; else $endThismonth = mktime(23, 59, 59, date('m'), date('t'), date('Y'));
  71. $params['where'][] = ['=', 'mall_id', $mall_id];
  72. $params['where'][] = ['between', 'created_at', $beginThismonth, $endThismonth];
  73. $params['order'] = 'created_at';
  74. $yesterday_data = AddonsOperatingNoteStatistics::lists($params, true);
  75. $data['items'] = ['发布量', '分享量', '点赞量', '浏览量', '评论量', '引导下单转化率'];
  76. if ($yesterday_data) foreach (array_column($yesterday_data, 'created_at') as $k => $v) $data['dates'][] = date("Y-m-d", $v);
  77. $data['series'][0]['type'] = "line";
  78. $data['series'][0]['name'] = "发布量";
  79. if ($yesterday_data) $data['series'][0]['data'] = array_column($yesterday_data, 'push_count');
  80. $data['series'][1]['type'] = "line";
  81. $data['series'][1]['name'] = "分享量";
  82. if ($yesterday_data) $data['series'][1]['data'] = array_column($yesterday_data, 'shares_count');
  83. $data['series'][2]['type'] = "line";
  84. $data['series'][2]['name'] = "点赞量";
  85. if ($yesterday_data) $data['series'][2]['data'] = array_column($yesterday_data, 'stars_count');
  86. $data['series'][3]['type'] = "line";
  87. $data['series'][3]['name'] = "浏览量";
  88. if ($yesterday_data) $data['series'][3]['data'] = array_column($yesterday_data, 'views_count');
  89. $data['series'][4]['type'] = "line";
  90. $data['series'][4]['name'] = "评论量";
  91. if ($yesterday_data) $data['series'][4]['data'] = array_column($yesterday_data, 'discuss_count');
  92. $data['series'][5]['type'] = "line";
  93. $data['series'][5]['name'] = "引导下单转化率";
  94. if ($yesterday_data) $data['series'][5]['data'] = array_column($yesterday_data, 'goods_views_count');
  95. return $data;
  96. }
  97. /**
  98. * @Author: ltm
  99. * @DateTime: 2022/1/17 0017 14:29
  100. * @Copyright: copyright (c) 2021 广东七件事集团
  101. * @param $data
  102. * @return string
  103. */
  104. public static function format($data)
  105. {
  106. $list = [];
  107. if ($data) {
  108. $list = array_map(function ($v) {
  109. if (is_numeric($v)) {
  110. if ($v > 10000) $v = ($v / 10000) . "万";
  111. }
  112. return $v;
  113. }, $data);
  114. }
  115. return $list;
  116. }
  117. }