BroadcastGoodsDao.php 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. <?php
  2. namespace app\common\dao\store\broadcast;
  3. use app\common\dao\BaseDao;
  4. use app\common\model\store\broadcast\BroadcastGoods;
  5. use app\common\repositories\system\merchant\MerchantRepository;
  6. use think\db\BaseQuery;
  7. use think\db\exception\DbException;
  8. /**
  9. * Class BroadcastGoodsDao
  10. * @package app\common\dao\store\broadcast
  11. * @author xaboy
  12. * @day 2020/7/29
  13. */
  14. class BroadcastGoodsDao extends BaseDao
  15. {
  16. /**
  17. * @return string
  18. * @author xaboy
  19. * @day 2020/7/29
  20. */
  21. protected function getModel(): string
  22. {
  23. return BroadcastGoods::class;
  24. }
  25. /**
  26. * @param int $id
  27. * @return int
  28. * @throws DbException
  29. * @author xaboy
  30. * @day 2020/7/30
  31. */
  32. public function delete(int $id)
  33. {
  34. return $this->update($id, ['is_del' => 1]);
  35. }
  36. /**
  37. * @param int $id
  38. * @return bool
  39. * @author xaboy
  40. * @day 2020/7/30
  41. */
  42. public function exists(int $id)
  43. {
  44. return $this->existsWhere(['broadcast_goods_id' => $id, 'is_del' => 0]);
  45. }
  46. /**
  47. * @param int $id
  48. * @param int $merId
  49. * @return bool
  50. * @author xaboy
  51. * @day 2020/7/30
  52. */
  53. public function merExists(int $id, int $merId)
  54. {
  55. return $this->existsWhere(['broadcast_goods_id' => $id, 'is_del' => 0, 'is_mer_del' => 0, 'mer_id' => $merId]);
  56. }
  57. /**
  58. * @param array $where
  59. * @return BaseQuery
  60. * @author xaboy
  61. * @day 2020/7/30
  62. */
  63. public function search(array $where)
  64. {
  65. if (isset($where['is_trader']) && $where['is_trader'] !== '') {
  66. $query = BroadcastGoods::hasWhere('merchant', function ($query) use ($where) {
  67. $query->where('is_trader', $where['is_trader']);
  68. });
  69. } else {
  70. $query = BroadcastGoods::getDB()->alias('BroadcastGoods');
  71. }
  72. $query->when(isset($where['mer_id']), function ($query) use ($where) {
  73. $query->where('BroadcastGoods.mer_id', $where['mer_id']);
  74. })->when(isset($where['keyword']) && $where['keyword'] !== '', function ($query) use ($where) {
  75. $query->whereLike('goods_id|mark|name|broadcast_goods_id', "%{$where['keyword']}%");
  76. })->when(isset($where['valid']) && $where['valid'] !== '', function ($query) use ($where) {
  77. $query->where('BroadcastGoods.is_show', 1);
  78. })->when(isset($where['mer_valid']) && $where['mer_valid'] !== '', function ($query) use ($where) {
  79. $query->where('BroadcastGoods.is_show', 1)->where('BroadcastGoods.is_mer_show', 1);
  80. })->when(isset($where['broadcast_goods_id']) && $where['broadcast_goods_id'] !== '', function ($query) use ($where) {
  81. $query->where('BroadcastGoods.broadcast_goods_id', $where['broadcast_goods_id']);
  82. })->when(isset($where['status_tag']) && $where['status_tag'] !== '', function ($query) use ($where) {
  83. if ($where['status_tag'] == 1) {
  84. $query->where('BroadcastGoods.status', 2);
  85. } else if ($where['status_tag'] == -1) {
  86. $query->where('BroadcastGoods.status', -1);
  87. } else if ($where['status_tag'] == 0) {
  88. $query->whereIn('BroadcastGoods.status', [0, 1]);
  89. }
  90. })->where('BroadcastGoods.is_del', 0)->where('BroadcastGoods.is_mer_del', 0);
  91. return $query;
  92. }
  93. public function goodsStatusAll()
  94. {
  95. return BroadcastGoods::getDB()->where('goods_id', '>', 0)->whereIn('audit_status', [0, 1])->column('audit_status', 'goods_id');
  96. }
  97. public function updateGoods($goods_id, $data)
  98. {
  99. return BroadcastGoods::getDB()->where('goods_id', $goods_id)->update($data);
  100. }
  101. public function goodsList($merId, array $ids)
  102. {
  103. return BroadcastGoods::getDB()->whereIn('broadcast_goods_id', $ids)->where('mer_id', $merId)->where('is_show', 1)->where('is_mer_show', 1)->where('is_del', 0)->where('status', 2)->select();
  104. }
  105. public function merDelete(int $id)
  106. {
  107. return $this->update($id, ['is_mer_del' => 1]);
  108. }
  109. }