StoreProductAttrResultServices.php 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
  4. // +----------------------------------------------------------------------
  5. // | Copyright (c) 2016~2023 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\sku;
  12. use app\dao\product\sku\StoreProductAttrResultDao;
  13. use app\services\BaseServices;
  14. use crmeb\exceptions\AdminException;
  15. /**
  16. * Class StoreProductAttrResultService
  17. * @package app\services\product\sku
  18. * @method value(array $where, string $field)
  19. */
  20. class StoreProductAttrResultServices extends BaseServices
  21. {
  22. /**
  23. * StoreProductAttrResultServices constructor.
  24. * @param StoreProductAttrResultDao $dao
  25. */
  26. public function __construct(StoreProductAttrResultDao $dao)
  27. {
  28. $this->dao = $dao;
  29. }
  30. /**
  31. * 获取属性规格
  32. * @param array $where
  33. * @return mixed
  34. */
  35. public function getResult(array $where)
  36. {
  37. return json_decode($this->dao->value($where, 'result'), true);
  38. }
  39. /**
  40. * 删除属性
  41. * @param int $id
  42. * @param int $type
  43. * @return bool
  44. */
  45. public function del(int $id, int $type)
  46. {
  47. return $this->dao->del($id, $type);
  48. }
  49. /**
  50. * 修改属性
  51. * @param array $data
  52. * @param int $id
  53. * @param int $type
  54. */
  55. public function setResult(array $data, int $id, int $type)
  56. {
  57. $res = $this->dao->save(['product_id' => $id, 'result' => json_encode($data), 'change_time' => time(), 'type' => $type]);
  58. if (!$res) throw new AdminException(100006);
  59. }
  60. }