StoreService.php 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  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\StoreModel;
  14. use App\Services\BaseService;
  15. use App\Services\RedisService;
  16. /**
  17. * 商家店铺管理-服务类
  18. * @author laravel开发员
  19. * @since 2020/11/11
  20. * @package App\Services\Common
  21. */
  22. class StoreService extends BaseService
  23. {
  24. /**
  25. * 构造函数
  26. * @author laravel开发员
  27. * @since 2020/11/11
  28. * AdService constructor.
  29. */
  30. public function __construct()
  31. {
  32. $this->model = new StoreModel();
  33. }
  34. /**
  35. * 列表
  36. * @param $params
  37. * @param int $pageSize
  38. * @return array
  39. */
  40. public function getDataList($params, $pageSize = 15)
  41. {
  42. $query = $this->getQuery($params);
  43. $list = $query->select(['a.*'])
  44. ->orderBy('a.create_time','desc')
  45. ->orderBy('a.id','desc')
  46. ->paginate($pageSize > 0 ? $pageSize : 9999999);
  47. $list = $list? $list->toArray() :[];
  48. if($list){
  49. foreach($list['data'] as &$item){
  50. $item['create_time'] = $item['create_time']? datetime($item['create_time'],'Y-m-d H.i.s') : '';
  51. }
  52. }
  53. return [
  54. 'pageSize'=> $pageSize,
  55. 'total'=>isset($list['total'])? $list['total'] : 0,
  56. 'list'=> isset($list['data'])? $list['data'] : []
  57. ];
  58. }
  59. /**
  60. * 查询
  61. * @param $params
  62. * @return \Illuminate\Database\Eloquent\Builder
  63. */
  64. public function getQuery($params)
  65. {
  66. $where = ['a.mark' => 1];
  67. $status = isset($params['status'])? $params['status'] : 1;
  68. if($status>0){
  69. $where['a.status'] = $status;
  70. }else{
  71. unset($where['a.status']);
  72. }
  73. $model = $this->model->with(['member'])
  74. ->from('stores as a')
  75. ->where($where)
  76. ->where(function ($query) use($params){
  77. $name = isset($params['name'])? $params['name'] : '';
  78. if($name){
  79. $query->where(function ($query) use ($name){
  80. $query->where('a.name','like',"%{$name}%");
  81. });
  82. }
  83. $phone = isset($params['phone'])? $params['phone'] : '';
  84. if($phone){
  85. $query->where(function ($query) use ($phone){
  86. $query->where('a.phone',$phone);
  87. });
  88. }
  89. });
  90. return $model;
  91. }
  92. /**
  93. * 添加或编辑
  94. * @return array
  95. * @since 2020/11/11
  96. * @author laravel开发员
  97. */
  98. public function edit()
  99. {
  100. $data = request()->all();
  101. // 图片处理
  102. if(isset($data['logo'])){
  103. $data['logo'] = get_image_path($data['logo']);
  104. }
  105. if(empty($data['name'])){
  106. return message('请填写店铺名称',false);
  107. }
  108. return parent::edit($data);
  109. }
  110. }