UserCollagePartakeDao.php 3.7 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\activity\collage;
  12. use app\dao\BaseDao;
  13. use app\model\activity\collage\UserCollageCodePartake;
  14. /**
  15. * 用户参与拼单
  16. * Class UserCollagePartakeDao
  17. * @package app\dao\collage
  18. */
  19. class UserCollagePartakeDao extends BaseDao
  20. {
  21. /**
  22. * 设置模型
  23. * @return string
  24. */
  25. protected function setModel(): string
  26. {
  27. return UserCollageCodePartake::class;
  28. }
  29. /**
  30. * @param array $where
  31. * @return \crmeb\basic\BaseModel|mixed|\think\Model
  32. */
  33. public function search(array $where = [])
  34. {
  35. return parent::search($where)->when(isset($where['uid']) && $where['uid'], function ($query) use ($where) {
  36. $query->where('uid', $where['uid']);
  37. })->when(isset($where['collate_code_id']) && $where['collate_code_id'], function ($query) use ($where) {
  38. $query->where('collate_code_id', $where['collate_code_id']);
  39. })->when(isset($where['store_id']) && $where['store_id'], function ($query) use ($where) {
  40. $query->where('store_id', $where['store_id']);
  41. })->when(isset($where['status']) && $where['status'], function ($query) use ($where) {
  42. $query->where('status', 1);
  43. });
  44. }
  45. /**
  46. * 用户拼单商品统计数据
  47. * @param int $uid
  48. * @param string $field
  49. * @param array $with
  50. * @return array
  51. * @throws \think\db\exception\DataNotFoundException
  52. * @throws \think\db\exception\DbException
  53. * @throws \think\db\exception\ModelNotFoundException
  54. */
  55. public function getUserPartakeList(array $where, string $field = '*', array $with = [])
  56. {
  57. return $this->getModel()->where($where)->when(count($with), function ($query) use ($with) {
  58. $query->with($with);
  59. })->order('add_time DESC')->field($field)->select()->toArray();
  60. }
  61. /**
  62. * 获取拼单信息
  63. * @param array $where
  64. * @param string $field
  65. * @param array $with
  66. * @return array
  67. * @throws \think\db\exception\DataNotFoundException
  68. * @throws \think\db\exception\DbException
  69. * @throws \think\db\exception\ModelNotFoundException
  70. */
  71. public function getUserPartakeProductList(array $where, string $field = '*', array $with = [])
  72. {
  73. return $this->getModel()->where($where)->when(count($with), function ($query) use ($with) {
  74. $query->with($with);
  75. })->order('add_time DESC')->field($field)->select()->toArray();
  76. }
  77. /**
  78. * 用户删除拼单、桌码商品
  79. * @param array $where
  80. * @return bool
  81. */
  82. public function del(array $where)
  83. {
  84. return $this->getModel()->where($where)->delete();
  85. }
  86. /**最后加入的记录
  87. * @param $where
  88. * @return array|\crmeb\basic\BaseModel|mixed|\think\Model|null
  89. * @throws \think\db\exception\DataNotFoundException
  90. * @throws \think\db\exception\DbException
  91. * @throws \think\db\exception\ModelNotFoundException
  92. */
  93. public function getUserPartake(array $where)
  94. {
  95. return $this->getModel()->where($where)->order('add_time DESC')->find();
  96. }
  97. }