MinAppTemplateMessage.php 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. <?php
  2. /**
  3. * Author: 芸众商城 www.yunzshop.com
  4. * Date: 2017/11/9
  5. * Time: 下午3:09
  6. */
  7. namespace app\common\models\notice;
  8. use app\common\models\BaseModel;
  9. use app\common\scopes\UniacidScope;
  10. use Illuminate\Database\Eloquent\Builder;
  11. use app\backend\models\BackendModel;
  12. class MinAppTemplateMessage extends BackendModel
  13. {
  14. public $table = 'yz_mini_app_template_message';
  15. protected $guarded = [''];
  16. public static function boot()
  17. {
  18. parent::boot();
  19. static::addGlobalScope(new UniacidScope);
  20. }
  21. public static function getList()
  22. {
  23. return self::select('*')->get();
  24. }
  25. public static function getSmallType()
  26. {
  27. return self::uniacid()->select('*')->where("small_type",1)->get();
  28. }
  29. public static function getAllTemp()
  30. {
  31. return self::select('id','title')->get();
  32. }
  33. public static function getTemp($id)
  34. {
  35. return self::select()->where('template_id',$id)->first();
  36. }
  37. public static function getTitle($title)
  38. {
  39. return self::select('template_id','is_open')->where('title',$title)->where('is_default',1)->first();
  40. }
  41. public static function getOpenTemp($id)
  42. {
  43. return self::select()->where('id',$id)->where('is_default',1)->first();
  44. }
  45. public static function delTempDataByTempId($id)
  46. {
  47. return self::where('id',$id)->delete();
  48. }
  49. public static function isOpen($id,$open)
  50. {
  51. return self::where('id',$id)->update(['is_open' => $open]);
  52. }
  53. public static function getTempById($temp_id)
  54. {
  55. return self::select('template_id')->whereId($temp_id);
  56. }
  57. public static function getTemplate($id)
  58. {
  59. return self::select('template_id')->where('id',$id)->first();
  60. }
  61. public static function fetchTempList($kwd)
  62. {
  63. return self::select()->where('is_default',0)->likeTitle($kwd);
  64. }
  65. public function scopeGetTempList($query)
  66. {
  67. $data = $this->getTempListTitle();
  68. return $query->whereIn('title', $data)->where("small_type",1)->groupBy('title')->get();
  69. }
  70. private function getTempListTitle()
  71. {
  72. return [
  73. '新订单提醒','订单支付成功通知','订单发货通知','确认收货通知','订单退款通知','佣金到账提醒','粉丝下单通知','审核结果通知','提现状态通知','提现成功通知'
  74. ];
  75. }
  76. // public function scopeLikeTitle($query, $kwd)
  77. // {
  78. // return $query->where('title', 'like', '%' . $kwd . '%');
  79. // }
  80. }