| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157 |
- <?php
- /**
- * Created by PhpStorm.
- * Name: 芸众商城系统
- * Author: 广州市芸众信息科技有限公司
- * Profile: 广州市芸众信息科技有限公司位于国际商贸中心的广州,专注于移动电子商务生态系统打造,拥有芸众社交电商系统、区块链数字资产管理系统、供应链管理系统、电子合同等产品/服务。官网 :www.yunzmall.com www.yunzshop.com
- * Date: 2022/8/3
- * Time: 16:59
- */
- namespace business\common\models;
- use app\common\models\Member;
- use app\common\models\BaseModel;
- use Illuminate\Database\Eloquent\Builder;
- use Illuminate\Database\Eloquent\SoftDeletes;
- use business\common\notice\BusinessNoticeFactory;
- use business\common\services\SettingService;
- /**
- * Class MessageNotice
- * @method static self businessId($business_id = null)
- * @package business\common\models
- */
- class MessageNotice extends BaseModel
- {
- use SoftDeletes;
- public $table = 'yz_business_message_notice';
- protected $guarded = [];
- protected $hidden = ['param','html','deleted_at','updated_at'];
- protected $appends = ['message_body', 'send_staff'];
- protected $casts = [
- 'param' => 'json',
- ];
- public static function getList($search = [])
- {
- $model = self::uniacid();
- $model->businessId();
- if (isset($search['status']) && is_numeric($search['status'])) {
- $model->where('status', $search['status']);
- }
- if (isset($search['handle_status']) && is_numeric($search['handle_status'])) {
- $model->where('handle_status', $search['handle_status']);
- }
- if (isset($search['plugin']) && $search['plugin'] != '') {
- $model->where('plugin', $search['plugin']);
- }
- if (isset($search['notice_type']) && $search['notice_type'] != '') {
- $model->where('notice_type', $search['notice_type']);
- }
- if (isset($search['recipient_id'])) {
- $model->where('recipient_id', $search['recipient_id']);
- }
- if (isset($search['operate_id'])) {
- $model->where('operate_id', $search['operate_id']);
- }
- if ($search['end_time'] && $search['start_time']) {
- $range = [strtotime($search['start_time']), strtotime($search['end_time'])];
- } else {
- //默认只查询一年以内的通知
- $range = [strtotime("-1 year") , time() + 10];
- }
- $model->whereBetween('created_at', $range);
- // $model->with(['hasOneRecipient']);
- $model->orderBy('id', 'desc');
- return $model;
- }
- public static function getByPlugin($plugin)
- {
- return self::uniacid()->businessId()->where('plugin', $plugin)->get();
- }
- public function getSendStaff()
- {
- return $this->getProductModule()->sendStaff();
- }
- public function getSendStaffAttribute()
- {
- return $this->getSendStaff();
- }
- public function getMessageBodyAttribute()
- {
- return $this->getProductModule()->showBody();
- }
- protected $pluginProductModule;
- public function getProductModule()
- {
- if (!isset($this->pluginProductModule)) {
- $this->pluginProductModule = BusinessNoticeFactory::selectInstance($this);
- }
- return $this->pluginProductModule;
- }
- /**
- * @param Builder $query
- * @param null $business_id
- * @return Builder
- */
- public function scopeBusinessId(Builder $query, $business_id = null)
- {
- is_null($business_id) && $business_id = SettingService::getBusinessId();
- $query = $query->where('business_id',$business_id);
- return $query;
- }
- //消息发送人
- public function hasOneCreator()
- {
- return $this->hasOne(Staff::class,'id','operate_id');
- }
- //消息通知人
- public function hasOneRecipient()
- {
- return $this->hasOne(Staff::class, 'id', 'recipient_id');
- }
- public function hasOneBusiness()
- {
- return $this->hasOne(Business::class, 'id', 'business_id');
- }
- }
|