芝麻web文件管理V1.00
编辑当前文件:/home/digitalh/yeahea.digitalhubbd.com/app/Models/Message.php
belongsTo(Shop::class); } /** * Get the user associated with the model. */ public function user() { return $this->belongsTo(User::class)->withDefault([ 'name' => trans('theme.user'), ]); } /** * Get the customer associated with the model. */ public function customer() { return $this->belongsTo(Customer::class) ->withDefault([ 'name' => trans('app.guest_customer'), ]) ->withoutGlobalScope('MineScope'); } /** * Get the order associated with the model. */ public function order() { return $this->belongsTo(Order::class); } /** * Get the shop associated with the model. */ public function item() { return $this->belongsTo(Inventory::class, 'product_id'); } /** * Scope a query to only include records that have the given status. * * @return \Illuminate\Database\Eloquent\Builder */ public function scopeStatusOf($query, $status) { return $query->where('status', $status); } /** * Scope a query to only include records that have the given label. * * @return \Illuminate\Database\Eloquent\Builder */ public function scopeLabelOf($query, $label) { return $query->where('label', $label); } /** * Scope a query to only include records from the user. * * @return \Illuminate\Database\Eloquent\Builder */ public function scopeMyMessages($query) { return $query->where('customer_id', Auth::id()); } /** * Scope a query to only include unread messages. * * @return \Illuminate\Database\Eloquent\Builder */ public function scopeUnread($query) { $status = $this->getStatusCell(); return $query->where($status, '<', self::STATUS_READ); } /** * Scope a query to only include spam messages. * * @return \Illuminate\Database\Eloquent\Builder */ public function scopeSpam($query) { return $query->where('status', self::STATUS_SPAM); } /** * Scope a query to only include non archived messages. * * @return \Illuminate\Database\Eloquent\Builder */ public function scopeNotArchived($query) { return $query->where([ ['customer_status', '!=', self::LABEL_TRASH], ['label', '!=', self::LABEL_TRASH], ]); } /** * Set the subject with replaced placeholder. */ public function setSubjectAttribute($value) { $this->attributes['subject'] = get_shortcode_replaced($value); } /** * Set the message with replaced placeholder. */ public function setMessageAttribute($value) { $this->attributes['message'] = get_shortcode_replaced($value); } public function about() { if ($this->order) { $str = trans('app.order') . ': ' . $this->order->order_number; } elseif ($this->item) { $str = trans('app.product') . ': ' . $this->item->sku; } return isset($str) ? '
' . $str . '
' : ''; } /** * Check if the message is unread * @return bool */ public function isUnread() { $status = $this->getStatusCell(); return $this->$status < static::STATUS_READ; } /** * mark the message as unread */ public function markAsUnread() { $this->forceFill([$this->getStatusCell() => static::STATUS_UNREAD])->save(); } /** * mark the message as read */ public function markAsRead() { $this->forceFill([$this->getStatusCell() => static::STATUS_READ])->save(); } /** * Archive the message */ public function archive() { $this->forceFill(['customer_status' => static::LABEL_TRASH])->save(); } /** * Mark the message as unread when replied */ public function hasNewReply() { $status = $this->getStatusCell(); if ($status == 'customer_status') { $data = [ 'status' => static::STATUS_NEW, 'label' => static::LABEL_INBOX, ]; } else { $data = [ 'customer_status' => static::STATUS_UNREAD, ]; } $this->forceFill($data)->save(); } /** * get the message level * * @return html */ public function labelName() { switch ($this->label) { case static::LABEL_INBOX: return '
' . trans('app.message_labels.inbox') . '
'; case static::LABEL_SENT: return '
' . trans('app.message_labels.sent') . '
'; case static::LABEL_DRAFT: return '
' . trans('app.message_labels.draft') . '
'; case static::LABEL_SPAM: return '
' . trans('app.message_labels.spam') . '
'; case static::LABEL_TRASH: return '
' . trans('app.message_labels.trash') . '
'; } } /** * get the status lebel of the message * * @return html */ public function statusName() { $status = $this->getStatusCell(); switch ($this->$status) { case static::STATUS_NEW: return '
' . trans('app.statuses.new') . '
'; case static::STATUS_UNREAD: return '
' . trans('app.statuses.unread') . '
'; case static::STATUS_READ: return '
' . trans('app.statuses.read') . '
'; } } /** * get the status colum name based on message author * * @return str */ public function getStatusCell() { return Auth::user() instanceof Customer ? 'customer_status' : 'status'; } /** * Get sender's name * * @return str */ public function getSenderName() { // Message from customer if ($this->customer_id) { return $this->customer->getName(); } // Message from guest user return $this->name ?? trans('app.guest_customer'); } /** * Get sender's email address * * @return str */ public function getSenderEmail() { return $this->email ?? optional($this->customer)->email; } }