ShippingTemplateRegionDao.php 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. <?php
  2. /**
  3. * @package merchant
  4. * Author: Qinii
  5. * Date: 2020/5/6
  6. * Time: 14:21
  7. */
  8. namespace app\common\dao\store\shipping;
  9. use app\entity\data\shipping\ShippingTemplateRegionEntity;
  10. use think\facade\Db;
  11. use app\common\dao\BaseDao;
  12. use app\common\model\store\shipping\ShippingTemplateRegion as model;
  13. class ShippingTemplateRegionDao extends BaseDao
  14. {
  15. /**
  16. * @Author:Qinii
  17. * @Date: 2020/5/8
  18. * @return string
  19. */
  20. protected function getModel(): string
  21. {
  22. return model::class;
  23. }
  24. /**
  25. * @Author:Qinii
  26. * @Date: 2020/5/8
  27. * @param $field
  28. * @param $value
  29. * @param null $except
  30. * @return bool
  31. */
  32. public function merFieldExists($field, $value, $except = null)
  33. {
  34. return ($this->getModel())::getDB()->when($except, function ($query, $except) use ($field) {
  35. $query->where($field, '<>', $except);
  36. })->where($field, $value)->count() > 0;
  37. }
  38. /**
  39. * 批量删除
  40. * @Author:Qinii
  41. * @Date: 2020/5/8
  42. * @param array $id
  43. * @param array $temp_id
  44. */
  45. public function batchRemove(array $id,array $temp_id)
  46. {
  47. if($id)
  48. ($this->getModel())::getDB()->where($this->getPk(),'in',$id)->delete();
  49. if($temp_id)
  50. ($this->getModel())::getDB()->where('temp_id','in',$temp_id)->delete();
  51. }
  52. /**
  53. * @Author:Qinii
  54. * @Date: 2020/5/13
  55. * @param array $data
  56. * @return mixed
  57. */
  58. public function insertAll(array $data)
  59. {
  60. return ($this->getModel()::getDB())->insertAll($data);
  61. }
  62. /**
  63. * @param int $tempId
  64. * @return ShippingTemplateRegionEntity[]
  65. */
  66. public function getShippingTemplateRegionEntityListByTempId(int $tempId): array
  67. {
  68. $entityList = [];
  69. try {
  70. /** @var model $model */
  71. $model = $this->getModel();
  72. $dataListRes = $model::getDB()
  73. ->where('temp_id', '=', $tempId)
  74. ->order('shipping_template_region_id DESC')
  75. ->select()
  76. ->toArray();
  77. if (!empty($dataListRes)) {
  78. foreach ($dataListRes as $data) {
  79. $entityList[] = ShippingTemplateRegionEntity::newInstance($data);
  80. }
  81. }
  82. } catch (\Exception $e) {
  83. }
  84. return $entityList;
  85. }
  86. }