ShopCartLists.php 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. <?php
  2. namespace app\workerapi\lists\shops;
  3. use app\common\lists\ListsSearchInterface;
  4. use app\common\model\shops\ShopCart;
  5. use app\workerapi\lists\BaseWorkerDataLists;
  6. use think\db\Query;
  7. /**
  8. * ShopCartLists列表
  9. * Class ShopCartLists
  10. * @package app\api\lists\goods_category
  11. */
  12. class ShopCartLists extends BaseWorkerDataLists implements ListsSearchInterface
  13. {
  14. /**
  15. *
  16. * @return array[]
  17. */
  18. public function setSearch(): array
  19. {
  20. return [
  21. '=' => ['shop_goods_id', 'goods_specs_inventory_id'],
  22. ];
  23. }
  24. public function querySearch(): array
  25. {
  26. $where = [];
  27. $where[] = ['worker_id', '=', $this->userId];
  28. return $where;
  29. }
  30. /**
  31. * @notes 获取列表
  32. * @return array
  33. * @throws \think\db\exception\DataNotFoundException
  34. * @throws \think\db\exception\DbException
  35. * @throws \think\db\exception\ModelNotFoundException
  36. * @author whitef
  37. * @date 2024/07/07 18:23
  38. */
  39. public function lists(): array
  40. {
  41. $lists = ShopCart::with([
  42. 'goods' => function (Query $query) {
  43. $query->field(['id', 'goods_name', 'delivery_type', 'shop_goods_type', 'goods_image', 'goods_status', 'specs_type', 'custom_attribute_items', 'company_name',])->append(['delivery_type_text', 'shop_goods_type_text']);
  44. },
  45. 'goodSpecsInventory' => function (Query $query) {
  46. $query->field(['id', 'remaining_inventory', 'specs', 'service_fee', 'service_total']);
  47. }
  48. ])->when(!empty($this->params['goods_name']), function ($query) {
  49. $query->hasWhere('goods', function (Query $query) {
  50. $query->where('goods_name', 'like', '%' . $this->params['goods_name'] . '%');
  51. });
  52. })
  53. ->where($this->searchWhere)
  54. ->where($this->querySearch())
  55. ->visible(['id', 'shop_goods_id', 'goods_specs_inventory_id', 'number'])
  56. ->limit($this->limitOffset, $this->limitLength)
  57. ->select()
  58. ->toArray();
  59. return $lists;
  60. }
  61. /**
  62. * @notes 获取数量
  63. * @return int
  64. * @author whitef
  65. * @date 2024/07/07 18:23
  66. */
  67. public function count(): int
  68. {
  69. return ShopCart::where($this->searchWhere)->where($this->querySearch())
  70. ->when(!empty($this->params['goods_name']), function (Query $query) {
  71. $query->hasWhere('goods', function (Query $query) {
  72. $query->where('goods_name', 'like', '%' . $this->params['goods_name'] . '%');
  73. });
  74. })->count();
  75. }
  76. }