ShopCartLists.php 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  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. ])
  49. ->where($this->searchWhere)
  50. ->where($this->querySearch())
  51. ->field(['id', 'shop_goods_id' ,'goods_specs_inventory_id', 'number'])
  52. ->select()
  53. ->toArray();
  54. return $lists;
  55. }
  56. /**
  57. * @notes 获取数量
  58. * @return int
  59. * @author whitef
  60. * @date 2024/07/07 18:23
  61. */
  62. public function count(): int
  63. {
  64. return ShopCart::where($this->searchWhere) ->where($this->querySearch())->count();
  65. }
  66. }