StoreAttrTemplateDao.php 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
  4. // +----------------------------------------------------------------------
  5. // | Copyright (c) 2016~2020 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\dao\store;
  12. use app\common\dao\BaseDao;
  13. use app\common\model\BaseModel;
  14. use app\common\model\store\StoreAttrTemplate;
  15. use think\db\BaseQuery;
  16. use think\db\exception\DataNotFoundException;
  17. use think\db\exception\DbException;
  18. use think\db\exception\ModelNotFoundException;
  19. use think\Model;
  20. /**
  21. * Class StoreAttrTemplateDao
  22. * @package app\common\dao\store
  23. * @author xaboy
  24. * @day 2020-05-06
  25. */
  26. class StoreAttrTemplateDao extends BaseDao
  27. {
  28. /**
  29. * @return BaseModel
  30. * @author xaboy
  31. * @day 2020-03-30
  32. */
  33. protected function getModel(): string
  34. {
  35. return StoreAttrTemplate::class;
  36. }
  37. /**
  38. * @param $merId
  39. * @param array $where
  40. * @return BaseQuery
  41. * @author xaboy
  42. * @day 2020-05-06
  43. */
  44. public function search($merId, array $where = [])
  45. {
  46. return StoreAttrTemplate::getDB()->where('mer_id', $merId)->order('attr_template_id DESC');
  47. }
  48. /**
  49. * @param int $merId
  50. * @param int $id
  51. * @param null $except
  52. * @return bool
  53. * @author xaboy
  54. * @day 2020-04-15
  55. */
  56. public function merExists(int $merId, int $id, $except = null)
  57. {
  58. return $this->merFieldExists($merId, $this->getPk(), $id, $except);
  59. }
  60. /**
  61. * @param int $merId
  62. * @param $field
  63. * @param $value
  64. * @param null $except
  65. * @return bool
  66. * @author xaboy
  67. * @day 2020-04-15
  68. */
  69. public function merFieldExists(int $merId, $field, $value, $except = null)
  70. {
  71. return ($this->getModel())::getDB()->when($except, function ($query, $except) use ($field) {
  72. $query->where($field, '<>', $except);
  73. })->where('mer_id', $merId)->where($field, $value)->count() > 0;
  74. }
  75. /**
  76. * @param int $id
  77. * @param int $merId
  78. * @return array|Model|null
  79. * @throws DataNotFoundException
  80. * @throws DbException
  81. * @throws ModelNotFoundException
  82. * @author xaboy
  83. * @day 2020-04-15
  84. */
  85. public function get( $id, $merId = 0)
  86. {
  87. return ($this->getModel())::getDB()->where('mer_id', $merId)->find($id);
  88. }
  89. /**
  90. * @param int $id
  91. * @param int $merId
  92. * @return int
  93. * @throws DbException
  94. * @author xaboy
  95. * @day 2020-04-15
  96. */
  97. public function delete(int $id, $merId = 0)
  98. {
  99. return ($this->getModel())::getDB()->where($this->getPk(), $id)->where('mer_id', $merId)->delete();
  100. }
  101. public function getList($merId)
  102. {
  103. return ($this->getModel())::getDB()->where('mer_id',$merId)->field('attr_template_id,template_name,template_value')->select();
  104. }
  105. }