链街Dcat后台
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

60 lines
1.7 KiB

  1. <?php
  2. namespace App\Admin\Repositories\v3;
  3. use App\Models\v3\Coupon as Model;
  4. use Dcat\Admin\Grid\Model as GridModel;
  5. use Dcat\Admin\Repositories\EloquentRepository;
  6. use App\Models\v3\CouponUse as CouponUseModel;
  7. use Illuminate\Support\Facades\DB;
  8. class Coupon extends EloquentRepository
  9. {
  10. /**
  11. * Model.
  12. *
  13. * @var string
  14. */
  15. protected $eloquentClass = Model::class;
  16. /**
  17. * 查询Grid表格数据.
  18. *
  19. * @param Grid\Model $model
  20. *
  21. * @return \Illuminate\Contracts\Pagination\LengthAwarePaginator|Collection|array
  22. */
  23. public function get(GridModel $model)
  24. {
  25. $this->setSort($model);
  26. $this->setPaginate($model);
  27. $query = $this->newQuery();
  28. if ($this->relations) {
  29. $query->with($this->relations);
  30. }
  31. $model->getQueries()->unique()->each(function ($value) use (&$query) {
  32. if ($value['method'] == 'paginate') {
  33. $value['arguments'][1] = $this->getGridColumns();
  34. } elseif ($value['method'] == 'get') {
  35. $value['arguments'] = [$this->getGridColumns()];
  36. }
  37. $query = call_user_func_array([$query, $value['method']], $value['arguments'] ?? []);
  38. });
  39. // dd(CouponUseModel::where('system_coupon_id',16)->sum('number'));
  40. // $u = DB::table('ims_system_coupon_user_use')->where('system_coupon_id',16)->count('number');
  41. // dd($u);
  42. // $list = $query->toArray();
  43. // foreach($list as &$value){
  44. // // 查询使用数量
  45. // $value['use_total'] = CouponUseModel::where('system_coupon_id',16)->count('number');
  46. // dd( $value['use_total'] );
  47. // }
  48. return $query;
  49. }
  50. }