ShippingTemplateRegionRepository.php 3.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
  4. // +----------------------------------------------------------------------
  5. // | Copyright (c) 2016~2024 https://www.crmeb.com All rights reserved.
  6. // +----------------------------------------------------------------------
  7. // | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
  8. // +----------------------------------------------------------------------
  9. // | Author: CRMEB Team <admin@crmeb.com>
  10. // +----------------------------------------------------------------------
  11. namespace app\common\repositories\store\shipping;
  12. use app\common\repositories\BaseRepository;
  13. use app\common\dao\store\shipping\ShippingTemplateRegionDao as dao;
  14. class ShippingTemplateRegionRepository extends BaseRepository
  15. {
  16. /**
  17. * ShippingTemplateRegionRepository constructor.
  18. * @param dao $dao
  19. */
  20. public function __construct(dao $dao)
  21. {
  22. $this->dao = $dao;
  23. }
  24. /**
  25. * 检查商家是否存在指定的运输模板。
  26. *
  27. * 本函数用于确认一个商家是否拥有特定ID的运输模板。它首先通过ID从数据访问对象(DAO)获取模板信息,
  28. * 然后利用依赖注入获取ShippingTemplateRepository实例,通过这个实例来检查商家是否存在指定的模板ID。
  29. * 这种设计模式使得代码更加灵活,易于维护和测试。
  30. *
  31. * @param int $merId 商家ID,用于确认商家身份。
  32. * @param int $id 指定的运输模板ID,需要确认商家是否拥有这个模板。
  33. * @return bool 如果商家存在指定的运输模板,则返回true,否则返回false。
  34. */
  35. public function merExists($merId , $id)
  36. {
  37. // 通过ID从DAO获取模板信息
  38. $result = $this->dao->get($id);
  39. // 通过依赖注入创建ShippingTemplateRepository实例
  40. $make = app()->make(ShippingTemplateRepository::class);
  41. // 如果模板信息存在,则检查商家是否存在指定的模板ID
  42. if ($result)
  43. return $make->merExists($merId,$result['temp_id']);
  44. // 如果模板信息不存在,则直接返回false
  45. return false;
  46. }
  47. /**
  48. * 暂未使用
  49. * @Author:Qinii
  50. * @Date: 2020/5/8
  51. * @param $id
  52. * @param $data
  53. */
  54. public function update($id,$data)
  55. {
  56. foreach ($data as $item) {
  57. if(isset($item['shipping_template_region_id']) && $item['shipping_template_region_id']){
  58. $item['city_id'] = implode('/',$item['city_id']);
  59. $this->dao->update($item['shipping_template_region_id'],$item);
  60. }else{
  61. $item['temp_id'] = $id;
  62. $this->dao->create($item);
  63. }
  64. }
  65. }
  66. /**
  67. * 批量插入数据。
  68. *
  69. * 本方法用于一次性插入多条数据记录。它通过调用DAO层的insertAll方法来实现,
  70. * 提高了数据插入的效率,减少了数据库操作的次数。此方法适用于需要批量导入或添加数据的场景。
  71. *
  72. * @param array $data 包含多条数据记录的数组,每条记录应为一个数组。
  73. * 数组的每个元素代表一条数据,元素的键应与数据库表的字段名对应。
  74. * @return bool 插入操作的结果。成功返回true,失败返回false。
  75. */
  76. public function insertAll(array $data)
  77. {
  78. return $this->dao->insertAll($data);
  79. }
  80. }