BroadcastGoodsDao.php 3.1 KB

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