UserCollageDao.php 3.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  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\UserCollageCode;
  14. /**
  15. * 拼单
  16. * Class UserCollageDao
  17. * @package app\dao\collage
  18. */
  19. class UserCollageDao extends BaseDao
  20. {
  21. /**
  22. * 设置模型
  23. * @return string
  24. */
  25. protected function setModel(): string
  26. {
  27. return UserCollageCode::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['serial_number']) && $where['serial_number'] != '', function ($query) use ($where) {
  36. if (substr($where['serial_number'], 0, 2) == 'wx') {
  37. $query->where(function ($que) use ($where) {
  38. $que->where('oid', 'in', function ($q) use ($where) {
  39. $q->name('store_order')->where('order_id', 'LIKE', '%' . $where['serial_number'] . '%')->where('type', 10)->field(['id'])->select();
  40. });
  41. });
  42. } else {
  43. $query->where('serial_number', 'LIKE', '%' . $where['serial_number'] . '%');
  44. }
  45. })->when(isset($where['status']) && $where['status'], function ($query) use ($where) {
  46. if (is_array($where['status'])) {
  47. $query->whereIn('status', $where['status']);
  48. } else {
  49. $query->where('status', $where['status']);
  50. }
  51. })->when(isset($where['type']) && $where['type'], function ($query) use ($where) {
  52. $query->where('type', $where['type']);
  53. })->when(isset($where['store_id']) && $where['store_id'], function ($query) use ($where) {
  54. $query->where('store_id', $where['store_id']);
  55. })->when(isset($where['staff_id']) && $where['staff_id'] > 0, function ($query) use ($where) {
  56. $query->where(function ($que) use ($where) {
  57. $que->where('oid', 'in', function ($q) use ($where) {
  58. $q->name('store_order')->where('staff_id', $where['staff_id'])->where('type', 10)->field(['id'])->select();
  59. });
  60. });
  61. });
  62. }
  63. /**获取当天最大流水号
  64. * @param $where
  65. * @return mixed
  66. */
  67. public function getMaxSerialNumber($where)
  68. {
  69. $now_day = strtotime(date('Y-m-d'));
  70. return $this->search($where)->where('add_time', '>', $now_day)->order('add_time desc')->value('serial_number');
  71. }
  72. /**桌码订单
  73. * @param array $where
  74. * @param int $store_id
  75. * @param array $with
  76. * @return array
  77. * @throws \think\db\exception\DataNotFoundException
  78. * @throws \think\db\exception\DbException
  79. * @throws \think\db\exception\ModelNotFoundException
  80. */
  81. public function searchTableCodeList(array $where, array $field = ['*'], int $page = 0, int $limit = 0, array $with = [])
  82. {
  83. return $this->search($where)->field($field)->when(count($with), function ($query) use ($with) {
  84. $query->with($with);
  85. })->when($page && $limit, function ($query) use ($page, $limit) {
  86. $query->page($page, $limit);
  87. })->when(!$page && $limit, function ($query) use ($limit) {
  88. $query->limit($limit);
  89. })->order('add_time desc')->select()->toArray();
  90. }
  91. }