DocumentCovers.php 2.4 KB

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