1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798 |
- <?php
- namespace app\admin\model;
- use think\Model;
- use traits\model\SoftDelete;
- use app\common\library\Tenim;
- class Worker extends Model
- {
- use SoftDelete;
-
- // 表名
- protected $table = 'worker';
-
- // 自动写入时间戳字段
- protected $autoWriteTimestamp = false;
- // 定义时间戳字段名
- protected $createTime = false;
- protected $updateTime = false;
- protected $deleteTime = 'deletetime';
- // 追加属性
- protected $append = [
- 'status_text',
- 'prevtime_text',
- 'logintime_text'
- ];
-
- protected static function init()
- {
- self::afterInsert(function($row){
- $worker_id = $row['id'];
- //注册到im
- //user_用户端小程序,master_师傅,kefu_客服
- $tenim = new Tenim();
- $rs = $tenim->register('master_'. $worker_id, $row['truename'], localpath_to_netpath($row['avatar']));
- });
- self::afterUpdate(function ($row) {
- $changed = $row->getChangedData();
- //如果有修改头像或昵称,同步到im
- if (isset($changed['truename']) || isset($changed['avatar'])) {
- //user_用户端小程序,master_师傅,kefu_客服
- $tenim = new Tenim();
- $rs = $tenim->useredit('master_'. $row['id'], $row['truename'], localpath_to_netpath($row['avatar']));
- }
- });
- }
-
- public function getStatusList()
- {
- return ['1' => __('Status 1'), '0' => __('Status 0'), '-1' => __('Status -1')];
- }
- public function getStatusTextAttr($value, $data)
- {
- $value = $value ? $value : (isset($data['status']) ? $data['status'] : '');
- $list = $this->getStatusList();
- return isset($list[$value]) ? $list[$value] : '';
- }
- public function getPrevtimeTextAttr($value, $data)
- {
- $value = $value ? $value : (isset($data['prevtime']) ? $data['prevtime'] : '');
- return is_numeric($value) ? date("Y-m-d H:i:s", $value) : $value;
- }
- public function getLogintimeTextAttr($value, $data)
- {
- $value = $value ? $value : (isset($data['logintime']) ? $data['logintime'] : '');
- return is_numeric($value) ? date("Y-m-d H:i:s", $value) : $value;
- }
- protected function setPrevtimeAttr($value)
- {
- return $value === '' ? null : ($value && !is_numeric($value) ? strtotime($value) : $value);
- }
- protected function setLogintimeAttr($value)
- {
- return $value === '' ? null : ($value && !is_numeric($value) ? strtotime($value) : $value);
- }
- public function company()
- {
- return $this->belongsTo('Company', 'company_id', 'id', [], 'LEFT')->setEagerlyType(0);
- }
- }
|