init
- 框架初始化 - 安装插件 - 修复PHP8.4报错
This commit is contained in:
23
application/admin/model/shopro/chat/CommonWord.php
Normal file
23
application/admin/model/shopro/chat/CommonWord.php
Normal file
@@ -0,0 +1,23 @@
|
||||
<?php
|
||||
|
||||
namespace app\admin\model\shopro\chat;
|
||||
|
||||
use app\admin\model\shopro\Common;
|
||||
use app\admin\model\shopro\chat\traits\ChatCommon;
|
||||
|
||||
class CommonWord extends Common
|
||||
{
|
||||
use ChatCommon;
|
||||
|
||||
protected $name = 'shopro_chat_common_word';
|
||||
|
||||
protected $append = [
|
||||
'status_text',
|
||||
'room_name'
|
||||
];
|
||||
|
||||
public function scopeRoomId($query, $room_id)
|
||||
{
|
||||
return $query->where('room_id', $room_id);
|
||||
}
|
||||
}
|
||||
57
application/admin/model/shopro/chat/CustomerService.php
Normal file
57
application/admin/model/shopro/chat/CustomerService.php
Normal file
@@ -0,0 +1,57 @@
|
||||
<?php
|
||||
|
||||
namespace app\admin\model\shopro\chat;
|
||||
|
||||
use app\admin\model\shopro\Common;
|
||||
use app\admin\model\shopro\chat\Record;
|
||||
use app\admin\model\shopro\chat\CustomerServiceUser;
|
||||
use app\admin\model\shopro\chat\traits\ChatCommon;
|
||||
|
||||
class CustomerService extends Common
|
||||
{
|
||||
use ChatCommon;
|
||||
|
||||
protected $name = 'shopro_chat_customer_service';
|
||||
|
||||
protected $append = [
|
||||
'auth_model',
|
||||
'auth_text',
|
||||
'status_text',
|
||||
'room_name'
|
||||
];
|
||||
|
||||
// 自动数据类型转换
|
||||
protected $type = [
|
||||
'last_time' => 'timestamp',
|
||||
];
|
||||
|
||||
|
||||
public function statusList()
|
||||
{
|
||||
return ['offline' => '离线', 'online' => '在线', 'busy' => '忙碌'];
|
||||
}
|
||||
|
||||
|
||||
public function getAuthModelAttr($value, $data)
|
||||
{
|
||||
return $this->customer_service_user['auth_model'] ?? null;
|
||||
}
|
||||
|
||||
public function getAuthTextAttr($value, $data)
|
||||
{
|
||||
return $this->customer_service_user['auth_text'] ?? null;
|
||||
}
|
||||
|
||||
|
||||
public function customerService()
|
||||
{
|
||||
return $this->morphMany(Record::class, ['sender_identify', 'sender_id'], 'customer_service');
|
||||
}
|
||||
|
||||
public function customerServiceUser()
|
||||
{
|
||||
return $this->HasOne(CustomerServiceUser::class, 'customer_service_id');
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
62
application/admin/model/shopro/chat/CustomerServiceUser.php
Normal file
62
application/admin/model/shopro/chat/CustomerServiceUser.php
Normal file
@@ -0,0 +1,62 @@
|
||||
<?php
|
||||
|
||||
namespace app\admin\model\shopro\chat;
|
||||
|
||||
use app\admin\model\Admin;
|
||||
use app\admin\model\shopro\Common;
|
||||
use app\admin\model\shopro\chat\CustomerService;
|
||||
use app\admin\model\shopro\user\User as ShopUser;
|
||||
|
||||
class CustomerServiceUser extends Common
|
||||
{
|
||||
protected $name = 'shopro_chat_customer_service_user';
|
||||
|
||||
|
||||
protected $append = [
|
||||
'auth_model',
|
||||
'auth_text'
|
||||
];
|
||||
|
||||
public static $authType = [
|
||||
'admin' => ['name' => '管理员', 'value' => 'admin'],
|
||||
'user' => ['name' => '用户', 'value' => 'user'],
|
||||
];
|
||||
|
||||
public function scopeAuthAdmin($query, $admin_id)
|
||||
{
|
||||
return $query->where('auth', 'admin')->where('auth_id', $admin_id);
|
||||
}
|
||||
|
||||
|
||||
public function scopeAuthUser($query, $user_id)
|
||||
{
|
||||
return $query->where('auth', 'user')->where('auth_id', $user_id);
|
||||
}
|
||||
|
||||
|
||||
public function getAuthModelAttr($value, $data)
|
||||
{
|
||||
return $this->{$data['auth']};
|
||||
}
|
||||
|
||||
public function getAuthTextAttr($value, $data)
|
||||
{
|
||||
return self::$authType[$data['auth']]['name'] ?? '';
|
||||
}
|
||||
|
||||
|
||||
public function admin()
|
||||
{
|
||||
return $this->belongsTo(Admin::class, 'auth_id');
|
||||
}
|
||||
|
||||
public function customerService()
|
||||
{
|
||||
return $this->belongsTo(CustomerService::class, 'customer_service_id');
|
||||
}
|
||||
|
||||
public function user()
|
||||
{
|
||||
return $this->belongsTo(ShopUser::class, 'auth_id');
|
||||
}
|
||||
}
|
||||
23
application/admin/model/shopro/chat/Question.php
Normal file
23
application/admin/model/shopro/chat/Question.php
Normal file
@@ -0,0 +1,23 @@
|
||||
<?php
|
||||
|
||||
namespace app\admin\model\shopro\chat;
|
||||
|
||||
use app\admin\model\shopro\Common;
|
||||
use app\admin\model\shopro\chat\traits\ChatCommon;
|
||||
|
||||
class Question extends Common
|
||||
{
|
||||
use ChatCommon;
|
||||
|
||||
protected $name = 'shopro_chat_question';
|
||||
|
||||
protected $append = [
|
||||
'status_text',
|
||||
'room_name'
|
||||
];
|
||||
|
||||
public function scopeRoomId($query, $room_id)
|
||||
{
|
||||
return $query->where('room_id', $room_id);
|
||||
}
|
||||
}
|
||||
94
application/admin/model/shopro/chat/Record.php
Normal file
94
application/admin/model/shopro/chat/Record.php
Normal file
@@ -0,0 +1,94 @@
|
||||
<?php
|
||||
|
||||
namespace app\admin\model\shopro\chat;
|
||||
|
||||
use app\admin\model\shopro\Common;
|
||||
use app\admin\model\shopro\chat\traits\ChatCommon;
|
||||
|
||||
class Record extends Common
|
||||
{
|
||||
use ChatCommon;
|
||||
|
||||
protected $name = 'shopro_chat_record';
|
||||
|
||||
protected $append = [
|
||||
'room_name'
|
||||
];
|
||||
|
||||
// 不格式化创建更新时间
|
||||
protected $dateFormat = false;
|
||||
|
||||
public function scopeCustomer($query)
|
||||
{
|
||||
return $query->where('sender_identify', 'customer');
|
||||
}
|
||||
|
||||
|
||||
public function scopeCustomerService($query)
|
||||
{
|
||||
return $query->where('sender_identify', 'customer_service');
|
||||
}
|
||||
|
||||
public function scopeNoRead($query)
|
||||
{
|
||||
return $query->whereNull('read_time');
|
||||
}
|
||||
|
||||
|
||||
public function setMessageAttr($value, $data)
|
||||
{
|
||||
switch ($data['message_type']) {
|
||||
case 'order':
|
||||
case 'goods':
|
||||
$value = is_array($value) ? json_encode($value) : $value;
|
||||
break;
|
||||
default :
|
||||
$value = $value;
|
||||
}
|
||||
|
||||
return $value;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 处理消息
|
||||
*
|
||||
* @param string $value
|
||||
* @param array $data
|
||||
* @return string
|
||||
*/
|
||||
public function getMessageAttr($value, $data)
|
||||
{
|
||||
switch($data['message_type']) {
|
||||
case 'order':
|
||||
case 'goods':
|
||||
$message = json_decode($value, true);
|
||||
|
||||
break;
|
||||
default :
|
||||
$message = $value;
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
// if ($data['message_type'] == 'image') {
|
||||
// $message = Online::cdnurl($value);
|
||||
// } else if (in_array($data['message_type'], ['order', 'goods'])) {
|
||||
// $messageArr = json_decode($value, true);
|
||||
// if (isset($messageArr['image']) && $messageArr['image']) {
|
||||
// $messageArr['image'] = Online::cdnurl($messageArr['image']);
|
||||
// }
|
||||
|
||||
// $message = json_encode($messageArr);
|
||||
// } else if ($data['message_type'] == 'text') {
|
||||
// // 全文匹配图片拼接 cdnurl
|
||||
// $url = Online::cdnurl('/uploads');
|
||||
// $message = str_replace("<img src=\"/uploads", "<img style=\"width: 100%;!important\" src=\"" . $url, $value);
|
||||
// } else {
|
||||
// $message = $value;
|
||||
// }
|
||||
|
||||
return $message;
|
||||
}
|
||||
|
||||
}
|
||||
22
application/admin/model/shopro/chat/ServiceLog.php
Normal file
22
application/admin/model/shopro/chat/ServiceLog.php
Normal file
@@ -0,0 +1,22 @@
|
||||
<?php
|
||||
|
||||
namespace app\admin\model\shopro\chat;
|
||||
|
||||
use app\admin\model\shopro\Common;
|
||||
use app\admin\model\shopro\chat\traits\ChatCommon;
|
||||
|
||||
class ServiceLog extends Common
|
||||
{
|
||||
use ChatCommon;
|
||||
|
||||
protected $name = 'shopro_chat_service_log';
|
||||
|
||||
protected $append = [
|
||||
'room_name'
|
||||
];
|
||||
|
||||
public function chatUser()
|
||||
{
|
||||
return $this->belongsTo(User::class, 'chat_user_id');
|
||||
}
|
||||
}
|
||||
33
application/admin/model/shopro/chat/User.php
Normal file
33
application/admin/model/shopro/chat/User.php
Normal file
@@ -0,0 +1,33 @@
|
||||
<?php
|
||||
|
||||
namespace app\admin\model\shopro\chat;
|
||||
|
||||
use app\admin\model\shopro\Common;
|
||||
use app\admin\model\shopro\user\User as ShopUser;
|
||||
|
||||
|
||||
class User extends Common
|
||||
{
|
||||
protected $name = 'shopro_chat_user';
|
||||
|
||||
// 自动数据类型转换
|
||||
protected $type = [
|
||||
'last_time' => 'timestamp',
|
||||
];
|
||||
|
||||
public function customer()
|
||||
{
|
||||
return $this->morphMany(Record::class, ['sender_identify', 'sender_id'], 'customer');
|
||||
}
|
||||
|
||||
public function user()
|
||||
{
|
||||
return $this->belongsTo(ShopUser::class, 'auth_id');
|
||||
}
|
||||
|
||||
|
||||
public function customerService()
|
||||
{
|
||||
return $this->belongsTo(CustomerService::class, 'customer_service_id');
|
||||
}
|
||||
}
|
||||
31
application/admin/model/shopro/chat/traits/ChatCommon.php
Normal file
31
application/admin/model/shopro/chat/traits/ChatCommon.php
Normal file
@@ -0,0 +1,31 @@
|
||||
<?php
|
||||
|
||||
namespace app\admin\model\shopro\chat\traits;
|
||||
|
||||
trait ChatCommon
|
||||
{
|
||||
|
||||
/**
|
||||
* 默认房间
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
public static function defaultRooms()
|
||||
{
|
||||
return [
|
||||
['name' => '总后台', 'value' => 'admin'],
|
||||
// ['name' => '官网', 'value' => 'official'],
|
||||
// ['name' => '商城', 'value' => 'shop']
|
||||
];
|
||||
}
|
||||
|
||||
|
||||
public function getRoomNameAttr($value, $data)
|
||||
{
|
||||
$value = $value ?: ($data['room_id'] ?? null);
|
||||
|
||||
$list = array_column(self::defaultRooms(), null, 'value');
|
||||
return isset($list[$value]) ? $list[$value]['name'] : $value;
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user