KeFuCsrKpi.php 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. <?php
  2. namespace app\admin\model;
  3. use think\Model;
  4. class KeFuCsrKpi extends Model
  5. {
  6. // 表名
  7. protected $name = 'kefu_csr_config';
  8. // 自动写入时间戳字段
  9. protected $autoWriteTimestamp = false;
  10. // 定义时间戳字段名
  11. protected $createTime = false;
  12. protected $updateTime = false;
  13. protected $deleteTime = false;
  14. // 追加属性
  15. protected $append = [
  16. 'last_reception_time_text',
  17. 'status_text',
  18. 'sum_reception_count',
  19. 'sum_message_count'
  20. ];
  21. public function getStatusList()
  22. {
  23. return ['0' => __('Status 0'), '1' => __('Status 1'), '2' => __('Status 2'), '3' => __('Status 3')];
  24. }
  25. public function getSumReceptionCountAttr($value, $data)
  26. {
  27. return \think\Db::name('kefu_reception_log')->where('csr_id', $data['admin_id'])->count('id');
  28. }
  29. public function getSumMessageCountAttr($value, $data)
  30. {
  31. return \think\Db::name('kefu_record')
  32. ->where('sender_identity', 0)
  33. ->where('sender_id', $data['admin_id'])
  34. ->count('id');
  35. }
  36. public function getLastReceptionTimeTextAttr($value, $data)
  37. {
  38. $value = $value ? $value : (isset($data['last_reception_time']) ? $data['last_reception_time'] : '');
  39. return is_numeric($value) ? date("Y-m-d H:i:s", $value) : $value;
  40. }
  41. public function getStatusTextAttr($value, $data)
  42. {
  43. $value = $value ? $value : (isset($data['status']) ? $data['status'] : '');
  44. $list = $this->getStatusList();
  45. return isset($list[$value]) ? $list[$value] : '';
  46. }
  47. protected function setLastReceptionTimeAttr($value)
  48. {
  49. return $value === '' ? null : ($value && !is_numeric($value) ? strtotime($value) : $value);
  50. }
  51. public function admin()
  52. {
  53. return $this->belongsTo('Admin', 'admin_id', 'id', [], 'LEFT')->setEagerlyType(0);
  54. }
  55. }