StoreOrderCartInfoDao.php 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  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\StoreOrderCartInfo;
  14. /**
  15. * 订单详情
  16. * Class StoreOrderCartInfoDao
  17. * @package app\dao\order
  18. * @method saveAll(array $data)
  19. */
  20. class StoreOrderCartInfoDao extends BaseDao
  21. {
  22. /**
  23. * 设置模型
  24. * @return string
  25. */
  26. protected function setModel(): string
  27. {
  28. return StoreOrderCartInfo::class;
  29. }
  30. /**
  31. * 获取购物车详情列表
  32. * @param array $where
  33. * @param array $field
  34. * @return array
  35. * @throws \think\db\exception\DataNotFoundException
  36. * @throws \think\db\exception\DbException
  37. * @throws \think\db\exception\ModelNotFoundException
  38. */
  39. public function getCartInfoList(array $where, array $field = ['*'])
  40. {
  41. return $this->search($where)->field($field)->select()->toArray();
  42. }
  43. /**
  44. * 获取购物车信息以数组返回
  45. * @param array $where
  46. * @param string $field
  47. * @param string $key
  48. */
  49. public function getCartColunm(array $where, string $field, string $key = '')
  50. {
  51. return $this->search($where)->order('id asc')->column($field, $key);
  52. }
  53. /**
  54. * @param $cart_ids
  55. * @return array
  56. */
  57. public function getSplitCartNum($cart_ids)
  58. {
  59. $res = $this->getModel()->whereIn('old_cart_id', $cart_ids)->field('sum(cart_num) as num,old_cart_id')->group('old_cart_id')->select()->toArray();
  60. $data = [];
  61. foreach ($res as $value) {
  62. $data[$value['old_cart_id']] = $value['num'];
  63. }
  64. return $data;
  65. }
  66. /**临期 卡次
  67. * @param int $writeEndTime
  68. * @param int $writeTime
  69. * @return array
  70. * @throws \think\db\exception\DataNotFoundException
  71. * @throws \think\db\exception\DbException
  72. * @throws \think\db\exception\ModelNotFoundException
  73. */
  74. public function getAdventCartInfoList(int $time = 0, int $writeTime = 0)
  75. {
  76. $list = $this->getModel()->where(['is_writeoff' => 0, 'is_advent_sms' => 0])->where('write_start', '>', 0)->where('write_end', '>', 0)
  77. ->where('write_end', '>', $time)->where('write_end', '<=', $writeTime)
  78. ->field('id,oid,product_id,write_times,write_surplus_times,write_start,write_end,cart_info')->select();
  79. $list = count($list) > 0 ? $list->toArray() : [];
  80. return $list;
  81. }
  82. /**过期 卡次
  83. * @param int $writeTime
  84. * @return array
  85. * @throws \think\db\exception\DataNotFoundException
  86. * @throws \think\db\exception\DbException
  87. * @throws \think\db\exception\ModelNotFoundException
  88. */
  89. public function getExpireCartInfoList(int $writeTime = 0)
  90. {
  91. $list = $this->getModel()->where(['is_writeoff' => 0, 'is_expire_sms' => 0])->where('write_start', '>', 0)->where('write_end', '>', 0)
  92. ->where('write_end', '<', $writeTime)
  93. ->field('id,oid,product_id,write_times,write_surplus_times,write_start,write_end,cart_info')->select();
  94. $list = count($list) > 0 ? $list->toArray() : [];
  95. return $list;
  96. }
  97. }