DocumentCovers.php 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. <?php
  2. /**
  3. * Created by PhpStorm.
  4. * User: hp
  5. * Date: 2017/11/21
  6. * Time: 11:14
  7. */
  8. namespace App\Modules\Promotion\Models;
  9. use Illuminate\Database\Eloquent\Model;
  10. class DocumentCovers extends Model
  11. {
  12. protected $table = 'document_covers';
  13. protected $fillable = ['id', 'link', 'type', 'sequence'];
  14. /**
  15. * @return mixed 获取所有的文案封面
  16. */
  17. static function getAllDocumentCovers($distribution_channel_id)
  18. {
  19. $type = (123 == $distribution_channel_id) ? 4 : 1;
  20. return $documentCoversResult = self::select('id', 'link')->where('type', $type)->orderBy('updated_at', 'desc')->get();
  21. }
  22. /**
  23. * @return mixed 获取所有的文案封面
  24. */
  25. static function getAllMessageDocumentCovers($distribution_channel_id)
  26. {
  27. $link1 = 'https://cdn-novel.iycdm.com/distribution/message_document_cover/68.jpg';
  28. $link2 = 'https://cdn-novel.iycdm.com/distribution/message_document_cover/9.9.jpg';
  29. $link3 = 'https://cdn-novel.iycdm.com/distribution/message_document_cover/201811091716.jpg';
  30. $array = self::select('id', 'link')->where('type', 1)->orderBy('updated_at', 'desc')->get()->toArray();
  31. array_splice($array, 0, 0, [['id' => 10001, 'link' => $link1]]);
  32. array_splice($array, 0, 0, [['id' => 10002, 'link' => $link2]]);
  33. array_splice($array, 0, 0, [['id' => 10003, 'link' => $link3]]);
  34. $array = json_decode(json_encode($array));
  35. return $array;
  36. }
  37. /**
  38. *
  39. * @return mixed 随机获取模板消息的文案封面
  40. * $type: 类型(2: 带黄的, 3: 不带黄的)
  41. * $count:条数(默认为 1 条)
  42. */
  43. static function getMessageRandomDocumentCovers($type, $count = 1)
  44. {
  45. return self::select('id', 'link')->where('type', $type)->inRandomOrder()->take($count)->orderBy('updated_at', 'desc')->get()->toArray();
  46. }
  47. static function getFullMessageRandomDocumentCovers($type=3)
  48. {
  49. return self::select('id', 'link')->where('type', $type)->orderBy('updated_at', 'desc')->get();
  50. }
  51. static function search($params = [])
  52. {
  53. $obj = self::orderBy('id', 'desc');
  54. if (isset($params['type']) && $params['type']) $obj->where('type', $params['type']);
  55. return $obj->paginate(50);
  56. }
  57. static function delCover($ids = [])
  58. {
  59. return $ids && self::whereIn('id', $ids)->delete();
  60. }
  61. }