StoreProductSpecsTemplateServices.php 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
  4. // +----------------------------------------------------------------------
  5. // | Copyright (c) 2016~2021 https://www.crmeb.com All rights reserved.
  6. // +----------------------------------------------------------------------
  7. // | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
  8. // +----------------------------------------------------------------------
  9. // | Author: CRMEB Team <admin@crmeb.com>
  10. // +----------------------------------------------------------------------
  11. namespace app\services\product\specs;
  12. use app\dao\other\CategoryDao;
  13. use app\services\BaseServices;
  14. /**
  15. * 商品参数模版
  16. * Class StoreProductSpecsTemplateServices
  17. * @package app\services\product\specs
  18. * @mixin CategoryDao
  19. */
  20. class StoreProductSpecsTemplateServices extends BaseServices
  21. {
  22. /**
  23. * 在分类库中3
  24. */
  25. const GROUP = 3;
  26. /**
  27. * UserLabelCateServices constructor.
  28. * @param CategoryDao $dao
  29. */
  30. public function __construct(CategoryDao $dao)
  31. {
  32. $this->dao = $dao;
  33. }
  34. /**
  35. * 获取所有参数模版
  36. * @param array $where
  37. * @param int $type
  38. * @param int $relation_id
  39. * @return array
  40. * @throws \think\db\exception\DataNotFoundException
  41. * @throws \think\db\exception\DbException
  42. * @throws \think\db\exception\ModelNotFoundException
  43. */
  44. public function getProductSpecsTemplateList(array $where, int $type = 0, int $relation_id = 0)
  45. {
  46. [$page, $limit] = $this->getPageValue();
  47. $where = array_merge($where, ['type' => $type, 'relation_id' => $relation_id, 'group' => 3]);
  48. $count = $this->dao->count($where);
  49. $list = $this->dao->getCateList($where, $page, $limit, ['*']);
  50. if ($list) {
  51. foreach ($list as &$item) {
  52. $item['add_time'] = $item['add_time'] ? date('Y-m-d H:i:s', $item['add_time']) : '';
  53. }
  54. }
  55. return compact('list', 'count');
  56. }
  57. /**
  58. * 获取所有商品参数
  59. * @param int $type
  60. * @param int $relation_id
  61. * @return array
  62. * @throws \think\db\exception\DataNotFoundException
  63. * @throws \think\db\exception\DbException
  64. * @throws \think\db\exception\ModelNotFoundException
  65. */
  66. public function getAllSpecs(int $type = 0, int $relation_id = 0)
  67. {
  68. $where = [];
  69. // $where['relation_id'] = $relation_id;
  70. // $where['type'] = $type;
  71. $where['group'] = 3;
  72. return $this->dao->getCateList($where, 0, 0, ['id', 'name'], ['specs' => function($query) {
  73. $query->where('status', 1);
  74. }]);
  75. }
  76. }