StoreCouponProductDao.php 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. <?php
  2. namespace app\common\dao\store\coupon;
  3. use app\common\dao\BaseDao;
  4. use app\common\model\BaseModel;
  5. use app\common\model\store\coupon\StoreCouponProduct;
  6. use think\Collection;
  7. use think\db\exception\DataNotFoundException;
  8. use think\db\exception\DbException;
  9. use think\db\exception\ModelNotFoundException;
  10. /**
  11. * Class StoreCouponProductDao
  12. * @package app\common\dao\store\coupon
  13. * @author zfy
  14. * @day 2020-05-13
  15. */
  16. class StoreCouponProductDao extends BaseDao
  17. {
  18. /**
  19. * @return BaseModel
  20. * @author zfy
  21. * @day 2020-03-30
  22. */
  23. protected function getModel(): string
  24. {
  25. return StoreCouponProduct::class;
  26. }
  27. /**
  28. * @param array $data
  29. * @return int
  30. * @author zfy
  31. * @day 2020-05-13
  32. */
  33. public function insertAll(array $data)
  34. {
  35. return StoreCouponProduct::getDB()->insertAll($data);
  36. }
  37. /**
  38. * @param $couponId
  39. * @return int
  40. * @throws DbException
  41. * @author zfy
  42. * @day 2020-05-13
  43. */
  44. public function clear($couponId)
  45. {
  46. return StoreCouponProduct::getDB()->where('coupon_id', $couponId)->delete();
  47. }
  48. /**
  49. * @param $productId
  50. * @return array
  51. * @author zfy
  52. * @day 2020/6/1
  53. */
  54. public function productByCouponId($productId)
  55. {
  56. return StoreCouponProduct::getDB()->whereIn('product_id', $productId)->column('coupon_id');
  57. }
  58. public function search(array $where)
  59. {
  60. return StoreCouponProduct::getDB()->when(isset($where['coupon_id']), function ($query) use ($where) {
  61. return $query->where('coupon_id', $where['coupon_id']);
  62. });
  63. }
  64. }