MessageNotice.php 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  1. <?php
  2. /**
  3. * Created by PhpStorm.
  4. * Name: 芸众商城系统
  5. * Author: 广州市芸众信息科技有限公司
  6. * Profile: 广州市芸众信息科技有限公司位于国际商贸中心的广州,专注于移动电子商务生态系统打造,拥有芸众社交电商系统、区块链数字资产管理系统、供应链管理系统、电子合同等产品/服务。官网 :www.yunzmall.com www.yunzshop.com
  7. * Date: 2022/8/3
  8. * Time: 16:59
  9. */
  10. namespace business\common\models;
  11. use app\common\models\Member;
  12. use app\common\models\BaseModel;
  13. use Illuminate\Database\Eloquent\Builder;
  14. use Illuminate\Database\Eloquent\SoftDeletes;
  15. use business\common\notice\BusinessNoticeFactory;
  16. use business\common\services\SettingService;
  17. /**
  18. * Class MessageNotice
  19. * @method static self businessId($business_id = null)
  20. * @package business\common\models
  21. */
  22. class MessageNotice extends BaseModel
  23. {
  24. use SoftDeletes;
  25. public $table = 'yz_business_message_notice';
  26. protected $guarded = [];
  27. protected $hidden = ['param','html','deleted_at','updated_at'];
  28. protected $appends = ['message_body', 'send_staff'];
  29. protected $casts = [
  30. 'param' => 'json',
  31. ];
  32. public static function getList($search = [])
  33. {
  34. $model = self::uniacid();
  35. $model->businessId();
  36. if (isset($search['status']) && is_numeric($search['status'])) {
  37. $model->where('status', $search['status']);
  38. }
  39. if (isset($search['handle_status']) && is_numeric($search['handle_status'])) {
  40. $model->where('handle_status', $search['handle_status']);
  41. }
  42. if (isset($search['plugin']) && $search['plugin'] != '') {
  43. $model->where('plugin', $search['plugin']);
  44. }
  45. if (isset($search['notice_type']) && $search['notice_type'] != '') {
  46. $model->where('notice_type', $search['notice_type']);
  47. }
  48. if (isset($search['recipient_id'])) {
  49. $model->where('recipient_id', $search['recipient_id']);
  50. }
  51. if (isset($search['operate_id'])) {
  52. $model->where('operate_id', $search['operate_id']);
  53. }
  54. if ($search['end_time'] && $search['start_time']) {
  55. $range = [strtotime($search['start_time']), strtotime($search['end_time'])];
  56. } else {
  57. //默认只查询一年以内的通知
  58. $range = [strtotime("-1 year") , time() + 10];
  59. }
  60. $model->whereBetween('created_at', $range);
  61. // $model->with(['hasOneRecipient']);
  62. $model->orderBy('id', 'desc');
  63. return $model;
  64. }
  65. public static function getByPlugin($plugin)
  66. {
  67. return self::uniacid()->businessId()->where('plugin', $plugin)->get();
  68. }
  69. public function getSendStaff()
  70. {
  71. return $this->getProductModule()->sendStaff();
  72. }
  73. public function getSendStaffAttribute()
  74. {
  75. return $this->getSendStaff();
  76. }
  77. public function getMessageBodyAttribute()
  78. {
  79. return $this->getProductModule()->showBody();
  80. }
  81. protected $pluginProductModule;
  82. public function getProductModule()
  83. {
  84. if (!isset($this->pluginProductModule)) {
  85. $this->pluginProductModule = BusinessNoticeFactory::selectInstance($this);
  86. }
  87. return $this->pluginProductModule;
  88. }
  89. /**
  90. * @param Builder $query
  91. * @param null $business_id
  92. * @return Builder
  93. */
  94. public function scopeBusinessId(Builder $query, $business_id = null)
  95. {
  96. is_null($business_id) && $business_id = SettingService::getBusinessId();
  97. $query = $query->where('business_id',$business_id);
  98. return $query;
  99. }
  100. //消息发送人
  101. public function hasOneCreator()
  102. {
  103. return $this->hasOne(Staff::class,'id','operate_id');
  104. }
  105. //消息通知人
  106. public function hasOneRecipient()
  107. {
  108. return $this->hasOne(Staff::class, 'id', 'recipient_id');
  109. }
  110. public function hasOneBusiness()
  111. {
  112. return $this->hasOne(Business::class, 'id', 'business_id');
  113. }
  114. }