Chart.php 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. <?php
  2. namespace app\admin\model\customcharts;
  3. use think\Model;
  4. class Chart extends Model
  5. {
  6. // 表名
  7. protected $name = 'customcharts_chart';
  8. // 自动写入时间戳字段
  9. protected $autoWriteTimestamp = false;
  10. // 定义时间戳字段名
  11. protected $createTime = false;
  12. protected $updateTime = false;
  13. protected $deleteTime = false;
  14. // 追加属性
  15. protected $append = [
  16. 'type_total_text',
  17. 'chart_type_text'
  18. ];
  19. protected static function init()
  20. {
  21. self::afterInsert(function ($row) {
  22. $pk = $row->getPk();
  23. $row->getQuery()->where($pk, $row[$pk])->update(['weigh' => $row[$pk]]);
  24. });
  25. }
  26. public function getTypeTotalList()
  27. {
  28. return ['sum' => __('Sum'), 'count' => __('Count')];
  29. }
  30. public function getChartTypeList()
  31. {
  32. return ['pie' => __('Pie'), 'graph' => __('Graph'), 'histogram' => __('Histogram')];
  33. }
  34. public function getTypeTotalTextAttr($value, $data)
  35. {
  36. $value = $value ? $value : (isset($data['type_total']) ? $data['type_total'] : '');
  37. $list = $this->getTypeTotalList();
  38. return isset($list[$value]) ? $list[$value] : '';
  39. }
  40. public function getChartTypeTextAttr($value, $data)
  41. {
  42. $value = $value ? $value : (isset($data['chart_type']) ? $data['chart_type'] : '');
  43. $list = $this->getChartTypeList();
  44. return isset($list[$value]) ? $list[$value] : '';
  45. }
  46. }