StoreCouponProductDao.php 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
  4. // +----------------------------------------------------------------------
  5. // | Copyright (c) 2016~2022 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\coupon;
  12. use app\common\dao\BaseDao;
  13. use app\common\model\BaseModel;
  14. use app\common\model\store\coupon\StoreCouponProduct;
  15. use think\Collection;
  16. use think\db\exception\DataNotFoundException;
  17. use think\db\exception\DbException;
  18. use think\db\exception\ModelNotFoundException;
  19. /**
  20. * Class StoreCouponProductDao
  21. * @package app\common\dao\store\coupon
  22. * @author xaboy
  23. * @day 2020-05-13
  24. */
  25. class StoreCouponProductDao extends BaseDao
  26. {
  27. /**
  28. * @return BaseModel
  29. * @author xaboy
  30. * @day 2020-03-30
  31. */
  32. protected function getModel(): string
  33. {
  34. return StoreCouponProduct::class;
  35. }
  36. /**
  37. * @param array $data
  38. * @return int
  39. * @author xaboy
  40. * @day 2020-05-13
  41. */
  42. public function insertAll(array $data)
  43. {
  44. return StoreCouponProduct::getDB()->insertAll($data);
  45. }
  46. /**
  47. * @param $couponId
  48. * @return int
  49. * @throws DbException
  50. * @author xaboy
  51. * @day 2020-05-13
  52. */
  53. public function clear($couponId)
  54. {
  55. return StoreCouponProduct::getDB()->where('coupon_id', $couponId)->delete();
  56. }
  57. /**
  58. * @param $productId
  59. * @return array
  60. * @author xaboy
  61. * @day 2020/6/1
  62. */
  63. public function productByCouponId($productId)
  64. {
  65. return StoreCouponProduct::getDB()->whereIn('product_id', $productId)->column('coupon_id');
  66. }
  67. public function search(array $where)
  68. {
  69. return StoreCouponProduct::getDB()
  70. ->when(isset($where['coupon_id']) && $where['coupon_id'] !== '', function ($query) use ($where) {
  71. return $query->where('coupon_id', $where['coupon_id']);
  72. })
  73. ->when(isset($where['type']) && $where['type'] !== '', function ($query) use ($where) {
  74. return $query->where('type', $where['type']);
  75. });
  76. }
  77. }