StoreOrderCartInfoDao.php 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
  4. // +----------------------------------------------------------------------
  5. // | Copyright (c) 2016~2023 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\StoreOrderCartInfo;
  14. /**
  15. * 订单详情
  16. * Class StoreOrderCartInfoDao
  17. * @package app\dao\order
  18. */
  19. class StoreOrderCartInfoDao extends BaseDao
  20. {
  21. /**
  22. * 设置模型
  23. * @return string
  24. */
  25. protected function setModel(): string
  26. {
  27. return StoreOrderCartInfo::class;
  28. }
  29. /**
  30. * 获取购物车详情列表
  31. * @param array $where
  32. * @param array $field
  33. * @return array
  34. * @throws \think\db\exception\DataNotFoundException
  35. * @throws \think\db\exception\DbException
  36. * @throws \think\db\exception\ModelNotFoundException
  37. */
  38. public function getCartInfoList(array $where, array $field)
  39. {
  40. return $this->search($where)->field($field)->select()->toArray();
  41. }
  42. /**
  43. * 获取购物车信息以数组返回
  44. * @param array $where
  45. * @param string $field
  46. * @param string $key
  47. */
  48. public function getCartColunm(array $where, string $field, string $key = '')
  49. {
  50. return $this->search($where)->column($field, $key);
  51. }
  52. public function getSplitCartNum($cart_ids)
  53. {
  54. $res = $this->getModel()->whereIn('old_cart_id', $cart_ids)->field('sum(cart_num) as num,old_cart_id')->group('old_cart_id')->select()->toArray();
  55. $data = [];
  56. foreach ($res as $value) {
  57. $data[$value['old_cart_id']] = $value['num'];
  58. }
  59. return $data;
  60. }
  61. }