StoreOrderStoreOrderCartInfoDao.php 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  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\dao\order;
  12. use app\dao\BaseDao;
  13. use app\model\order\StoreOrder;
  14. use app\model\order\StoreOrderCartInfo;
  15. /**
  16. *
  17. * Class StoreOrderStoreOrderCartInfoDao
  18. * @package app\dao\order
  19. */
  20. class StoreOrderStoreOrderCartInfoDao extends BaseDao
  21. {
  22. protected $alias = 'a';
  23. protected $joinAlis = 'c';
  24. /**
  25. * 设置主表模型
  26. * @return string
  27. */
  28. protected function setModel(): string
  29. {
  30. return StoreOrder::class;
  31. }
  32. /**
  33. * 设置链表模型
  34. * @return string
  35. */
  36. protected function setJoinModel(): string
  37. {
  38. return StoreOrderCartInfo::class;
  39. }
  40. /**
  41. * 设置模型
  42. * @return \crmeb\basic\BaseModel
  43. */
  44. public function getModel()
  45. {
  46. $name = app()->make($this->setJoinModel())->getName();
  47. return parent::getModel()->alias($this->alias)->join($name . ' ' . $this->joinAlis, $this->alias . '.id =' . $this->joinAlis . '.oid');
  48. }
  49. /**
  50. * 获取用户购买过的商品id
  51. * @param array $where
  52. * @return array
  53. */
  54. public function getUserCartProductIds(array $where)
  55. {
  56. return $this->getModel()->when(isset($where['uid']), function ($query) use ($where) {
  57. $query->where($this->alias . '.uid', $where['uid']);
  58. })->column($this->joinAlis . '.product_id');
  59. }
  60. }