ScoreGoodsCateService.php 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | LARAVEL8.0 框架 [ LARAVEL ][ RXThinkCMF ]
  4. // +----------------------------------------------------------------------
  5. // | 版权所有 2017~2021 LARAVEL研发中心
  6. // +----------------------------------------------------------------------
  7. // | 官方网站: http://www.laravel.cn
  8. // +----------------------------------------------------------------------
  9. // | Author: laravel开发员 <laravel.qq.com>
  10. // +----------------------------------------------------------------------
  11. namespace App\Services\Common;
  12. use App\Models\GoodsModel;
  13. use App\Models\ScoreGoodsCateModel;
  14. use App\Models\ScoreGoodsModel;
  15. use App\Services\BaseService;
  16. /**
  17. * 积分商品分类管理-服务类
  18. * @author laravel开发员
  19. * @since 2020/11/11
  20. * Class ScoreGoodsCateService
  21. * @package App\Services\Common
  22. */
  23. class ScoreGoodsCateService extends BaseService
  24. {
  25. // 静态对象
  26. protected static $instance = null;
  27. /**
  28. * 构造函数
  29. * @author laravel开发员
  30. * @since 2020/11/11
  31. * ScoreGoodsCateService constructor.
  32. */
  33. public function __construct()
  34. {
  35. $this->model = new ScoreGoodsCateModel();
  36. }
  37. /**
  38. * 静态入口
  39. * @return static|null
  40. */
  41. public static function make()
  42. {
  43. if (!self::$instance) {
  44. self::$instance = (new static());
  45. }
  46. return self::$instance;
  47. }
  48. /**
  49. * 列表数据
  50. * @param $params
  51. * @param int $pageSize
  52. * @return array
  53. */
  54. public function getDataList($params, $pageSize = 15)
  55. {
  56. $where = ['a.mark' => 1];
  57. $status = isset($params['status'])? $params['status'] : 0;
  58. if($status>0){
  59. $where['a.status'] = $status;
  60. }
  61. $list = $this->model->from('score_goods_cate as a')
  62. ->where($where)
  63. ->where(function ($query) use($params){
  64. $keyword = isset($params['keyword'])? $params['keyword'] : '';
  65. if($keyword){
  66. $query->where('a.name','like',"%{$keyword}%");
  67. }
  68. })
  69. ->select(['a.*'])
  70. ->orderBy('a.id','desc')
  71. ->paginate($pageSize > 0 ? $pageSize : 9999999);
  72. $list = $list? $list->toArray() :[];
  73. if($list){
  74. foreach($list['data'] as &$item){
  75. $item['create_time'] = $item['create_time']? datetime($item['create_time'],'Y-m-d H.i.s') : '';
  76. $item['icon'] = isset($item['icon']) && $item['icon']? get_image_url($item['icon']) : '';
  77. }
  78. }
  79. return [
  80. 'pageSize'=> $pageSize,
  81. 'total'=>isset($list['total'])? $list['total'] : 0,
  82. 'list'=> isset($list['data'])? $list['data'] : []
  83. ];
  84. }
  85. /**
  86. * 选项
  87. * @return array
  88. */
  89. public function options()
  90. {
  91. // 获取参数
  92. $param = request()->all();
  93. // 用户ID
  94. $keyword = getter($param, "keyword");
  95. $datas = $this->model->where(['mark'=>1])->where(function($query) use($keyword){
  96. if($keyword){
  97. $query->where('name','like',"%{$keyword}%");
  98. }
  99. })
  100. ->select(['id','name','status'])
  101. ->get();
  102. return $datas? $datas->toArray() : [];
  103. }
  104. /**
  105. * 添加编辑
  106. * @return array
  107. * @since 2020/11/11
  108. * @author laravel开发员
  109. */
  110. public function edit()
  111. {
  112. // 请求参数
  113. $data = request()->all();
  114. // thumb处理
  115. $thumb = isset($data['icon'])? trim($data['icon']) : '';
  116. if ($thumb && strpos($thumb, "temp")) {
  117. $data['icon'] = save_image($thumb, 'member');
  118. } else if($thumb){
  119. $data['icon'] = str_replace(IMG_URL, "", $data['icon']);
  120. }
  121. return parent::edit($data); // TODO: Change the autogenerated stub
  122. }
  123. }