UserStoreOrderDao.php 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  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. declare (strict_types=1);
  12. namespace app\dao\user;
  13. use app\dao\BaseDao;
  14. use app\model\order\StoreOrder;
  15. use app\model\user\User;
  16. /**
  17. *
  18. * Class UserStoreOrderDao
  19. * @package app\dao\user
  20. */
  21. class UserStoreOrderDao extends BaseDao
  22. {
  23. /**
  24. * @var string
  25. */
  26. protected $alias = '';
  27. /**
  28. * @var string
  29. */
  30. protected $join_alis = '';
  31. /**
  32. * 设置模型
  33. * @return string
  34. */
  35. protected function setModel(): string
  36. {
  37. return User::class;
  38. }
  39. public function joinModel(): string
  40. {
  41. return StoreOrder::class;
  42. }
  43. /**
  44. * 关联模型
  45. * @param string $alias
  46. * @param string $join_alias
  47. * @return \crmeb\basic\BaseModel
  48. */
  49. public function getModel(string $table = '', string $alias = 'u', string $join_alias = 'p', $join = 'left')
  50. {
  51. $this->alias = $alias;
  52. $this->join_alis = $join_alias;
  53. if (!$table) {
  54. /** @var StoreOrder $storeOrder */
  55. $storeOrder = app()->make($this->joinModel());
  56. $table = $storeOrder->getName();
  57. }
  58. return parent::getModel()->join($table . ' ' . $join_alias, $alias . '.uid = ' . $join_alias . '.uid', $join)->alias($alias);
  59. }
  60. /**
  61. * 推广团队列表
  62. * @param array $where
  63. * @param string $field
  64. * @param string $order_by
  65. * @param $page
  66. * @param $limit
  67. * @return array
  68. * @throws \think\db\exception\DataNotFoundException
  69. * @throws \think\db\exception\DbException
  70. * @throws \think\db\exception\ModelNotFoundException
  71. */
  72. public function getUserSpreadCountList(array $where, string $field, string $order_by, int $page, int $limit)
  73. {
  74. $table = app()->make($this->joinModel())->getModel()->where('o.pid', 'IN', [0, -1])->group('o.uid')->field(['SUM(o.pay_price) as numberCount', 'count(o.id) as orderCount', 'o.uid', 'o.order_id'])
  75. ->where('o.is_del', 0)->where('o.is_system_del', 0)->where('o.paid', 1)->where('o.refund_status', 'IN', [0, 3])->alias('o')->fetchSql(true)->select();
  76. return $this->getModel('(' . $table . ')')->where($where)->field($field)->order($order_by)->page($page, $limit)->select()->toArray();
  77. }
  78. }