StoreOrderWriteoffDao.php 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  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\StoreOrderWriteoff;
  14. /**
  15. * 订单核销
  16. * Class StoreOrderWriteoffDao
  17. * @package app\dao\order
  18. * @method saveAll(array $data)
  19. */
  20. class StoreOrderWriteoffDao extends BaseDao
  21. {
  22. /**
  23. * 设置模型
  24. * @return string
  25. */
  26. protected function setModel(): string
  27. {
  28. return StoreOrderWriteoff::class;
  29. }
  30. /**
  31. * @param array $where
  32. * @return \crmeb\basic\BaseModel|mixed|\think\Model
  33. */
  34. public function search(array $where = [])
  35. {
  36. return parent::search($where)
  37. ->when(isset($where['keyword']) && $where['keyword'] , function($query) use ($where) {
  38. $query->where(function ($q) use ($where) {
  39. $q->whereLike('uid|oid|relation_id|staff_id|product_id', '%' . $where['keyword'] . '%')
  40. ->whereOr('uid', 'IN', function ($user) use ($where) {
  41. $user->name('user')->field('id')->whereLike('uid|phone|nickname', '%' . $where['keyword'] . '%');
  42. })->whereOr('product_id', 'IN', function ($product) use ($where) {
  43. $product->name('store_product')->field('id')->whereLike('store_name|keyword', '%' . $where['keyword'] . '%');
  44. })->whereOr('oid', 'IN', function ($order) use ($where) {
  45. $order->name('store_order')->field('id')->whereLike('order_id|uid|user_phone|staff_id', '%' . $where['keyword'] . '%');
  46. });
  47. });
  48. });
  49. }
  50. /**
  51. * 获取核销列表
  52. * @param array $where
  53. * @param string $field
  54. * @param int $page
  55. * @param int $limit
  56. * @param array $with
  57. * @return array
  58. * @throws \think\db\exception\DataNotFoundException
  59. * @throws \think\db\exception\DbException
  60. * @throws \think\db\exception\ModelNotFoundException
  61. */
  62. public function getList(array $where, string $field = '*', int $page = 0, int $limit = 0, array $with = [])
  63. {
  64. return $this->search($where)->field($field)
  65. ->when($with, function ($query) use ($with) {
  66. $query->with($with);
  67. })->when($page != 0 && $limit != 0, function ($query) use ($page, $limit) {
  68. $query->page($page, $limit);
  69. })->order('id desc')->select()->toArray();
  70. }
  71. }