Company.php 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. <?php
  2. namespace app\admin\model;
  3. use think\Model;
  4. use traits\model\SoftDelete;
  5. use app\common\library\Tenim;
  6. class Company extends Model
  7. {
  8. use SoftDelete;
  9. // 表名
  10. protected $table = 'company';
  11. // 自动写入时间戳字段
  12. protected $autoWriteTimestamp = false;
  13. // 定义时间戳字段名
  14. protected $createTime = false;
  15. protected $updateTime = false;
  16. protected $deleteTime = 'deletetime';
  17. // 追加属性
  18. protected $append = [
  19. 'status_text'
  20. ];
  21. protected static function init()
  22. {
  23. self::afterUpdate(function ($row) {
  24. $changed = $row->getChangedData();
  25. //如果有修改头像或昵称,同步到im
  26. if (isset($changed['companyname']) || isset($changed['avatar'])) {
  27. //user_用户端小程序,master_师傅,kefu_客服
  28. $tenim = new Tenim();
  29. $rs = $tenim->useredit('kefu_'. $row['id'], $row['companyname'], localpath_to_netpath($row['avatar']));
  30. }
  31. });
  32. }
  33. public function getStatusList()
  34. {
  35. return ['1' => __('Status 1'), '0' => __('Status 0')];
  36. }
  37. public function getStatusTextAttr($value, $data)
  38. {
  39. $value = $value ? $value : (isset($data['status']) ? $data['status'] : '');
  40. $list = $this->getStatusList();
  41. return isset($list[$value]) ? $list[$value] : '';
  42. }
  43. }