BroadcastGoodsDao.php 4.6 KB

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