ShopCartLists.php 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  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. ->limit($this->limitOffset, $this->limitLength)
  53. ->select()
  54. ->toArray();
  55. return $lists;
  56. }
  57. /**
  58. * @notes 获取数量
  59. * @return int
  60. * @author whitef
  61. * @date 2024/07/07 18:23
  62. */
  63. public function count(): int
  64. {
  65. return ShopCart::where($this->searchWhere) ->where($this->querySearch())->count();
  66. }
  67. }