|
@@ -4,6 +4,7 @@ namespace app\common\model;
|
|
|
|
|
|
use think\db\Query;
|
|
|
use think\Model;
|
|
|
+use Yansongda\Supports\Arr;
|
|
|
|
|
|
/**
|
|
|
* @method static Query|static hot($hot=1)
|
|
@@ -21,6 +22,9 @@ class SiteMsg extends Model
|
|
|
public function read(){
|
|
|
return $this->hasMany(SiteMsgRead::class);
|
|
|
}
|
|
|
+ protected $type=[
|
|
|
+ 'data'=>'json',
|
|
|
+ ];
|
|
|
protected static function init()
|
|
|
{
|
|
|
self::afterDelete(function (self $msg){
|
|
@@ -29,19 +33,20 @@ class SiteMsg extends Model
|
|
|
}
|
|
|
|
|
|
public static function sendMsg($msgType,$user,$extend=[]){
|
|
|
- list($title,$content)=self::getTitleByType($msgType,$extend);
|
|
|
+ list($title,$content,$data)=self::getTitleByType($msgType,$extend);
|
|
|
if($title && $content){
|
|
|
return self::create([
|
|
|
'msg_type'=>$msgType,
|
|
|
'user_id'=>$user instanceof User?$user['id']:$user,
|
|
|
'title'=>$title,
|
|
|
'content'=>$content,
|
|
|
+ 'data'=>$data,
|
|
|
]);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
public static function getTitleByType($type,$extend=[]){
|
|
|
- $arr=['',''];
|
|
|
+ $arr=['','',null];
|
|
|
switch ($type){
|
|
|
case self::TYPE_COUPON:
|
|
|
$arr[0]='您获得了新的优惠券';
|
|
@@ -64,8 +69,12 @@ class SiteMsg extends Model
|
|
|
$arr[1]='您申请的退货退款未通过,请注意查看';
|
|
|
break;
|
|
|
case self::TYPE_NEW_GOODS:
|
|
|
- $arr[0]='有新产品上新啦';
|
|
|
- $arr[1]='有新产品上新啦,请注意查看';
|
|
|
+ $goods=$extend['goods'];
|
|
|
+ $arr[0]="新产品【{$goods['name']}】全新上市";
|
|
|
+ $arr[1]="有新产品上新啦,请注意查看";
|
|
|
+ $arr[2]=[
|
|
|
+ 'id'=>$goods['id'],
|
|
|
+ ];
|
|
|
break;
|
|
|
}
|
|
|
return $arr;
|