ShopGoodsLists.php 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | likeadmin快速开发前后端分离管理后台(PHP版)
  4. // +----------------------------------------------------------------------
  5. // | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
  6. // | 开源版本可自由商用,可去除界面版权logo
  7. // | gitee下载:https://gitee.com/likeshop_gitee/likeadmin
  8. // | github下载:https://github.com/likeshop-github/likeadmin
  9. // | 访问官网:https://www.likeadmin.cn
  10. // | likeadmin团队 版权所有 拥有最终解释权
  11. // +----------------------------------------------------------------------
  12. // | author: likeadminTeam
  13. // +----------------------------------------------------------------------
  14. namespace app\adminapi\lists\shops;
  15. use app\adminapi\lists\BaseAdminDataLists;
  16. use app\common\model\shops\ShopCategory;
  17. use app\common\model\shops\ShopGoods;
  18. use app\common\lists\ListsSearchInterface;
  19. use think\db\Query;
  20. /**
  21. * ShopGoods列表
  22. * Class ShopGoodsLists
  23. * @package app\adminapi\listsshops
  24. */
  25. class ShopGoodsLists extends BaseAdminDataLists implements ListsSearchInterface
  26. {
  27. /**
  28. * @notes 设置搜索条件
  29. * @return \string[][]
  30. * @author likeadmin
  31. * @date 2024/08/04 11:07
  32. */
  33. public function setSearch(): array
  34. {
  35. return [
  36. '=' => ['delivery_type', 'shop_goods_type', 'goods_name', 'company_name', 'goods_status', 'is_recommend'],
  37. ];
  38. }
  39. public function queryWhere()
  40. {
  41. $where = [];
  42. if (!empty($this->params['goods_category_id'])) {
  43. $goodsCategoryId = end($this->params['goods_category_id']);
  44. $goodsCategoryData = ShopCategory::where(['status'=>1])->order(['pid' => 'asc','weigh' => 'desc', 'id' => 'desc'])
  45. ->select()->toArray();
  46. $ids =get_tree_ids($goodsCategoryData,$goodsCategoryId);
  47. $ids[] = $goodsCategoryId;
  48. $where[] = ['goods_category_id','in' ,$ids];
  49. }
  50. return $where;
  51. }
  52. /**
  53. * @notes 获取列表
  54. * @return array
  55. * @throws \think\db\exception\DataNotFoundException
  56. * @throws \think\db\exception\DbException
  57. * @throws \think\db\exception\ModelNotFoundException
  58. * @author likeadmin
  59. * @date 2024/08/04 11:07
  60. */
  61. public function lists(): array
  62. {
  63. $lists = ShopGoods::with(['goodsCategory','goodSpecsInventory'=>function (Query $query) {
  64. $query->field(['specs', 'inventory','shop_goods_id','remaining_inventory','service_fee','service_total']);
  65. }])
  66. ->where($this->searchWhere)
  67. ->where($this->queryWhere())
  68. ->field(['id', 'delivery_type', 'shop_goods_type', 'goods_category_ids', 'goods_category_id', 'goods_name', 'company_name', 'goods_image', 'goods_banners', 'description', 'goods_status', 'is_recommend', 'recommend_weight','specs_type','custom_attribute_items'])
  69. ->limit($this->limitOffset, $this->limitLength)
  70. ->order(['id' => 'desc'])
  71. ->select()
  72. ->toArray();
  73. foreach ($lists as &$item) {
  74. $item['goods_category_ids'] = array_map("intval",$item['goods_category_ids']);
  75. }
  76. return $lists;
  77. }
  78. /**
  79. * @notes 获取数量
  80. * @return int
  81. * @author likeadmin
  82. * @date 2024/08/04 11:07
  83. */
  84. public function count(): int
  85. {
  86. return ShopGoods::where($this->searchWhere)->where($this->queryWhere())->count();
  87. }
  88. }