Stat.php 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. <?php
  2. /**
  3. * Niushop商城系统 - 团队十年电商经验汇集巨献!
  4. * =========================================================
  5. * Copy right 2019-2029 杭州牛之云科技有限公司, 保留所有权利。
  6. * ----------------------------------------------
  7. * 官方网址: https://www.niushop.com
  8. * =========================================================
  9. */
  10. namespace addon\store\model;
  11. use app\model\BaseModel;
  12. /**
  13. * 门店订单与结算
  14. */
  15. class Stat extends BaseModel
  16. {
  17. /**
  18. * 统计
  19. * @param $params
  20. */
  21. public function getStoreAccountSum($condition, $field)
  22. {
  23. $sum = model('store')->getSum($condition, $field);
  24. return $this->success($sum);
  25. }
  26. /**
  27. * 门店订单的销售额和销售量排行
  28. * @param $params
  29. */
  30. public function getStoreOrderRank($params)
  31. {
  32. $site_id = $params[ 'site_id' ];
  33. $join = [
  34. [ 'order o', '(o.store_id = s.store_id and o.pay_status = 1 and o.is_delete = 0) || o.store_id is null ', 'left' ]
  35. ];
  36. $group = 's.store_id';
  37. $limit = 5;
  38. $order = $params[ 'order' ] == 'num' ? 'order_num desc' : 'order_money desc';
  39. $field = 'ifnull(count(o.order_id), 0) as order_num, ifnull(sum(o.order_money), 0) as order_money,s.store_name';
  40. $condition = array (
  41. [ 's.site_id', '=', $site_id ],
  42. );
  43. $list = model('store')->getList($condition, $field, $order, 's', $join, $group, $limit);
  44. return $this->success($list);
  45. }
  46. }