ShippingTemplateUndeliveryDao.php 2.0 KB

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