ProductPlateModel.php 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. <?php
  2. namespace App\Web\Models;
  3. use App\Models\BaseModel;
  4. class ProductPlateModel extends BaseModel
  5. {
  6. /**
  7. * 状态字段
  8. */
  9. const DELETED_AT = 'status';
  10. /**
  11. * @var string
  12. */
  13. protected $table = 'product_plate';
  14. /**
  15. * 获取产品板块
  16. * */
  17. public function getProductPlateList($params,$fields=''){
  18. list($pageSize, $page, $skip) = $this->getPaginatorParams($params);
  19. $where=[];
  20. if(isset($params['status'])){
  21. $where[]=['a.status','=',$params['status']];
  22. }else{
  23. $where[]=['a.status','<',2];
  24. }
  25. if(empty($fields)){
  26. $fields='a.*,b.urla,b.seo_title,b.seo_keyword,b.seo_describe';
  27. }
  28. $query= $this->newInstance()->alias('a')
  29. ->leftJoin('web_seo as b', 'a.seo_id', '=', 'b.id')
  30. ->where($where);
  31. if (!empty($params['keyword'])) {
  32. $keyword = $params['keyword'];
  33. $query->where('a.plate_name', 'like', "%" . $keyword . "%");
  34. }
  35. $totalCount = $query->count();
  36. $list= $query->skip($skip)
  37. ->limit($pageSize)
  38. ->selectRaw($fields)
  39. ->orderBy('sort')
  40. ->get();
  41. if(!empty($list)){
  42. $list=$list->toArray();
  43. }else{
  44. $list=[];
  45. }
  46. $result = $this->buildPaginator($list, $skip, $page, $pageSize, $totalCount);
  47. return $result;
  48. }
  49. /**
  50. * 产品类型保存
  51. * @param array $data
  52. * */
  53. public function savePlateData($data){
  54. if (!empty($data['id'])) {
  55. $id = $data['id'];
  56. $this->newInstance()->where('id', $data['id'])->update($data);
  57. } else {
  58. $id = $this->newInstance()->insertGetId($data);
  59. }
  60. return $id;
  61. }
  62. /**
  63. * 检查 名称是否唯一
  64. * */
  65. public function checkPlateNameUnique($name,$id=0){
  66. $where=[];
  67. if(!empty($id)){
  68. $where[]=['id', '<>', $id];
  69. }
  70. $where[]=['status', '<', 2];
  71. $where[]=['plate_name', '=', trim($name)];
  72. return $this->checkFieldUnique('plate_name',$where);
  73. }
  74. /**
  75. * 获取板块详情
  76. * @param array $params
  77. * */
  78. public function getProductPlateInfo($params=[]){
  79. if(empty($params)){
  80. return [];
  81. }
  82. $where=[];
  83. $where[]=['status','<',2];
  84. if(!empty($params['id'])){
  85. $where['id']=$params['id'];
  86. }
  87. $info= $this->newInstance()->where($where)->first();
  88. if(!empty($info)){
  89. return $info->toArray();
  90. }else{
  91. return [];
  92. }
  93. }
  94. }