BroadcastGoodsDao.php 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
  4. // +----------------------------------------------------------------------
  5. // | Copyright (c) 2016~2024 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. * 删除商品
  36. * @param int $id
  37. * @return int
  38. * @throws DbException
  39. * @author xaboy
  40. * @day 2020/7/30
  41. */
  42. public function delete(int $id)
  43. {
  44. return $this->update($id, ['is_del' => 1]);
  45. }
  46. /**
  47. * 查询商品是否存在
  48. * @param int $id
  49. * @return bool
  50. * @author xaboy
  51. * @day 2020/7/30
  52. */
  53. public function exists(int $id)
  54. {
  55. return $this->existsWhere(['broadcast_goods_id' => $id, 'is_del' => 0]);
  56. }
  57. /**
  58. * 查询商户的商品是否存在
  59. * @param int $id
  60. * @param int $merId
  61. * @return bool
  62. * @author xaboy
  63. * @day 2020/7/30
  64. */
  65. public function merExists(int $id, int $merId)
  66. {
  67. return $this->existsWhere(['broadcast_goods_id' => $id, 'is_del' => 0, 'is_mer_del' => 0, 'mer_id' => $merId]);
  68. }
  69. /**
  70. * 商品查询
  71. * @param array $where
  72. * @return BaseQuery
  73. * @author xaboy
  74. * @day 2020/7/30
  75. */
  76. public function search(array $where)
  77. {
  78. if (isset($where['is_trader']) && $where['is_trader'] !== '') {
  79. $query = BroadcastGoods::hasWhere('merchant', function ($query) use ($where) {
  80. $query->where('is_trader', $where['is_trader']);
  81. });
  82. } else {
  83. $query = BroadcastGoods::getDB()->alias('BroadcastGoods');
  84. }
  85. $query->when(isset($where['mer_id']), function ($query) use ($where) {
  86. $query->where('BroadcastGoods.mer_id', $where['mer_id']);
  87. })->when(isset($where['keyword']) && $where['keyword'] !== '', function ($query) use ($where) {
  88. $query->whereLike('BroadcastGoods.goods_id|BroadcastGoods.mark|BroadcastGoods.name|BroadcastGoods.broadcast_goods_id', "%{$where['keyword']}%");
  89. })->when(isset($where['valid']) && $where['valid'] !== '', function ($query) use ($where) {
  90. $query->where('BroadcastGoods.is_show', 1);
  91. })->when(isset($where['mer_valid']) && $where['mer_valid'] !== '', function ($query) use ($where) {
  92. $query->where('BroadcastGoods.is_show', 1)->where('BroadcastGoods.is_mer_show', 1);
  93. })->when(isset($where['broadcast_goods_id']) && $where['broadcast_goods_id'] !== '', function ($query) use ($where) {
  94. $query->where('BroadcastGoods.broadcast_goods_id', $where['broadcast_goods_id']);
  95. })->when(isset($where['status_tag']) && $where['status_tag'] !== '', function ($query) use ($where) {
  96. if ($where['status_tag'] == 1) {
  97. $query->where('BroadcastGoods.status', 2);
  98. } else if ($where['status_tag'] == -1) {
  99. $query->where('BroadcastGoods.status', -1);
  100. } else if ($where['status_tag'] == 0) {
  101. $query->whereIn('BroadcastGoods.status', [0, 1]);
  102. }
  103. })->where('BroadcastGoods.is_del', 0)->where('BroadcastGoods.is_mer_del', 0);
  104. return $query;
  105. }
  106. /**
  107. * 获取所有的商品状态
  108. * @return array
  109. * @author wuhaotian
  110. * @email 442384644@qq.com
  111. * @date 2024/7/13
  112. */
  113. public function goodsStatusAll()
  114. {
  115. return BroadcastGoods::getDB()->where('goods_id', '>', 0)->whereIn('audit_status', [0, 1])->column('audit_status', 'goods_id');
  116. }
  117. /**
  118. * 更新商品信息
  119. * @param $goods_id
  120. * @param $data
  121. * @return int
  122. * @throws DbException
  123. * @author wuhaotian
  124. * @email 442384644@qq.com
  125. * @date 2024/7/13
  126. */
  127. public function updateGoods($goods_id, $data)
  128. {
  129. return BroadcastGoods::getDB()->where('goods_id', $goods_id)->update($data);
  130. }
  131. /**
  132. * 商品列表
  133. * @param $merId
  134. * @param array $ids
  135. * @return array|\think\Collection|BaseQuery[]
  136. * @throws DbException
  137. * @throws \think\db\exception\DataNotFoundException
  138. * @throws \think\db\exception\ModelNotFoundException
  139. * @author wuhaotian
  140. * @email 442384644@qq.com
  141. * @date 2024/7/13
  142. */
  143. public function goodsList($merId, array $ids)
  144. {
  145. 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();
  146. }
  147. /**
  148. * 删除商品
  149. * @param int $id
  150. * @return int
  151. * @throws DbException
  152. * @author wuhaotian
  153. * @email 442384644@qq.com
  154. * @date 2024/7/13
  155. */
  156. public function merDelete(int $id)
  157. {
  158. return $this->update($id, ['is_mer_del' => 1]);
  159. }
  160. }