GoodsService.php 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  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\AcceptorModel;
  13. use App\Models\GoodsCategoryModel;
  14. use App\Models\GoodsModel;
  15. use App\Models\TradeModel;
  16. use App\Services\BaseService;
  17. use Illuminate\Support\Facades\DB;
  18. /**
  19. * 承兑商管理-服务类
  20. * @author laravel开发员
  21. * @since 2020/11/11
  22. * @package App\Services\Common
  23. */
  24. class GoodsService extends BaseService
  25. {
  26. /**
  27. * 构造函数
  28. * @author laravel开发员
  29. * @since 2020/11/11
  30. */
  31. public function __construct()
  32. {
  33. $this->model = new GoodsModel();
  34. }
  35. /**
  36. * 获取列表_de
  37. * @param $params 参数
  38. * @param int $pageSize 分页大小:默认 15
  39. * @return array
  40. */
  41. public function getDataList($params, $pageSize = 10, $field = [])
  42. {
  43. $where = ['a.mark' => 1];
  44. $query = $this->model->with(['category'])
  45. ->from('goods as a')
  46. ->where($where)
  47. ->select($field ? $field : ['a.*']);
  48. if (isset($params['goods_name']) && $params['goods_name'] != '') {
  49. $query->where('a.goods_name','like',"%{$params['goods_name']}%");
  50. }
  51. if (isset($params['spu_name']) && $params['spu_name'] != '') {
  52. $query->where('a.spu_name','like',"%{$params['spu_name']}%");
  53. }
  54. if (isset($params['spu_sn']) && $params['spu_sn'] != '') {
  55. $query->where('a.spu_sn','like',"%{$params['spu_sn']}%");
  56. }
  57. if (isset($params['brand_name']) && $params['brand_name'] != '') {
  58. $query->where('a.brand_name','like',"%{$params['brand_name']}%");
  59. }
  60. if (isset($params['supply_type'])) {
  61. if(is_array($params['supply_type'])){
  62. $query->whereIn('a.supply_type',$params['supply_type']);
  63. }else{
  64. if($params['supply_type'] != ''){
  65. $query->where('a.supply_type',$params['supply_type']);
  66. }
  67. }
  68. }
  69. if (isset($params['is_recommend'])) {
  70. if(is_array($params['is_recommend'])){
  71. $query->whereIn('a.is_recommend',$params['is_recommend']);
  72. }else{
  73. if($params['is_recommend'] != ''){
  74. $query->where('a.is_recommend',$params['is_recommend']);
  75. }
  76. }
  77. }
  78. if (isset($params['status'])) {
  79. if(is_array($params['status'])){
  80. $query->whereIn('a.status',$params['status']);
  81. }else{
  82. if($params['status'] != ''){
  83. $query->where('a.status',$params['status']);
  84. }
  85. }
  86. }
  87. $list = $query->paginate($pageSize > 0 ? $pageSize : 9999999);
  88. $list = $list ? $list->toArray() : [];
  89. if ($list) {
  90. foreach ($list['data'] as &$item) {
  91. $item['detail_img'] = !empty($item['detail_img']) ? json_decode($item['detail_img']) : '';
  92. }
  93. }
  94. return [
  95. 'pageSize' => $pageSize,
  96. 'total' => isset($list['total']) ? $list['total'] : 0,
  97. 'list' => isset($list['data']) ? $list['data'] : []
  98. ];
  99. }
  100. /**
  101. * 添加会编辑会员
  102. * @return array
  103. * @since 2020/11/11
  104. * @author laravel开发员
  105. */
  106. public function edit()
  107. {
  108. // 请求参数
  109. $data = request()->all();
  110. if(isset($data['detail_img']) && is_array($data['detail_img'])){
  111. $data['detail_img'] = json_encode($data['detail_img']);
  112. }
  113. return parent::edit($data); // TODO: Change the autogenerated stub
  114. }
  115. }