BookSpecialChannel.php 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. <?php
  2. namespace App\Modules\Book\Models;
  3. use Illuminate\Database\Eloquent\Model;
  4. class BookSpecialChannel extends Model
  5. {
  6. protected $table = 'channel_special_books';
  7. protected $fillable = ['id', 'bid', 'channel_user_id', 'created_at', 'updated_at'];
  8. /**
  9. * 设置书本的渠道标识
  10. * @param $bid 书本id
  11. * @param $channels 渠道列表
  12. * @return mixed
  13. */
  14. public static function addSpecialChannle($bid, $channels)
  15. {
  16. $data = self::where('bid', $bid)->delete();
  17. foreach ($channels as $channel) {
  18. self::create(['bid' => $bid, 'channel_user_id' => $channel]);
  19. }
  20. return true;
  21. }
  22. /**
  23. * 获取书本设置的渠道标识
  24. * @param $bid
  25. * @return mixed
  26. */
  27. public static function getChannelsByBid($bid)
  28. {
  29. return self::select('channel_user_id')->where('bid', $bid)->get();
  30. }
  31. /**
  32. * 清除书本设置的渠道标识
  33. * @param $bid
  34. * @return mixed
  35. */
  36. public static function clearSpecialChannle($bid)
  37. {
  38. return self::where('bid', $bid)->delete();
  39. }
  40. /**
  41. * 获取渠道下配置的所有的书本id列表
  42. * @param $channel_user_id
  43. * @return array
  44. */
  45. public static function getBids($channel_user_id)
  46. {
  47. $data= self::where('channel_user_id', $channel_user_id)->select('bid')->get();
  48. $bids=[];
  49. foreach ($data as $item){
  50. $bids[]=$item->bid;
  51. }
  52. return $bids;
  53. }
  54. }