PopScreen.php 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. <?php
  2. namespace app\models\store;
  3. use crmeb\services\UtilService;
  4. use crmeb\traits\ModelTrait;
  5. use crmeb\basic\BaseModel;
  6. /**
  7. * TODO 弹屏广告Model
  8. * Class PopScreen
  9. * @package app\models\store
  10. */
  11. class PopScreen extends BaseModel
  12. {
  13. /**
  14. * 数据表主键
  15. * @var string
  16. */
  17. protected $pk = 'id';
  18. /**
  19. * 模型名称
  20. * @var string
  21. */
  22. protected $name = 'pop_screen';
  23. use ModelTrait;
  24. public static function merSet($mer_id, $alias = '')
  25. {
  26. return $mer_id ? self::where($alias ? $alias . '.mer_id' : 'mer_id', $mer_id) : new self;
  27. }
  28. /**
  29. * 弹屏广告列表
  30. * @param $where
  31. * @return array
  32. */
  33. public static function systemPage($where)
  34. {
  35. $model = self::setWhere($where);
  36. $count = $model->count();
  37. $list = $model->page((int)$where['page'], (int)$where['limit'])
  38. ->select()
  39. ->each(function ($item) {
  40. if($item['template_id']==0){
  41. $item['bg_img'] = image_to_base64("http://img.boofly.cn/pop_bg1.jpg");
  42. }
  43. if($item['template_id']==1){
  44. $item['bg_img'] = image_to_base64("http://img.boofly.cn/pop_bg2.jpg");
  45. }
  46. if($item['template_id']==2){
  47. $item['bg_img'] = image_to_base64("http://img.boofly.cn/pop_bg3.jpg");
  48. }
  49. if($item['template_id']==3){
  50. $item['bg_img'] = image_to_base64("http://img.boofly.cn/pop_bg4.jpg");
  51. }
  52. if($item['template_id']==4){
  53. $item['bg_img'] = image_to_base64($item['bg_image']);
  54. }
  55. });
  56. return compact('count', 'list');
  57. }
  58. /**
  59. * 设置弹屏广告 where 条件
  60. * @param $where
  61. * @param null $model
  62. * @return mixed
  63. */
  64. public static function setWhere($where, $model = null)
  65. {
  66. $model = $model === null ? new self() : $model;
  67. $model = $model->alias('c');
  68. $model = $model->field('c.*');
  69. $model = $model->where('c.mer_id', $where['mer_id']);
  70. if (isset($where['store_name']) && $where['store_name'] != '') $model = $model->where('c.id|c.title', 'LIKE', "%$where[store_name]%");
  71. return $model->order('c.id desc')->where('c.is_del', 0);
  72. }
  73. /**
  74. * 详情
  75. */
  76. public static function getOne($id)
  77. {
  78. $info = self::get($id);
  79. return $info;
  80. }
  81. }