截流自动化的商城平台
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

DistributionOrderLogic.php 4.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. <?php
  2. namespace app\admin\logic\distribution;
  3. use app\common\basics\Logic;
  4. use app\common\model\distribution\DistributionLevel;
  5. use app\common\model\distribution\DistributionOrderGoods;
  6. use app\common\model\user\User;
  7. use app\common\server\UrlServer;
  8. class DistributionOrderLogic extends Logic
  9. {
  10. /**
  11. * @notes 分销订单列表
  12. * @param $params
  13. * @return int[]
  14. * @author Tab
  15. * @date 2021/9/3 14:53
  16. */
  17. public static function lists($params)
  18. {
  19. $where= [];
  20. // 订单信息
  21. if (isset($params['order_keyword']) && !empty($params['order_keyword'])) {
  22. $where[] = ['o.order_sn', '=', $params['order_keyword']];
  23. }
  24. // 商品名称
  25. if (isset($params['goods_keyword']) && !empty($params['goods_keyword'])) {
  26. $where[] = ['og.goods_name', 'like', '%'.$params['goods_keyword'].'%'];
  27. }
  28. // 分销会员
  29. if (isset($params['distribution_keyword']) && !empty($params['distribution_keyword'])) {
  30. $where[] = ['u.sn|u.nickname', 'like', '%'.$params['distribution_keyword'].'%'];
  31. }
  32. // 佣金状态
  33. if (isset($params['status']) && !empty($params['status'])) {
  34. $where[] = ['dog.status', '=', $params['status']];
  35. }
  36. $field = [
  37. 'o.id' => 'order_id',
  38. 'o.order_sn',
  39. 'o.create_time' => 'order_create_time',
  40. 'o.user_id' => 'order_user_id',
  41. 'u.id' => 'distribution_user_id',
  42. 'u.avatar' => 'distribution_avatar',
  43. 'u.sn' => 'distribution_sn',
  44. 'u.nickname' => 'distribution_nickname',
  45. 'og.image' => 'goods_image',
  46. 'og.goods_name' => 'goods_name',
  47. 'og.spec_value' => 'spec_value',
  48. 'og.goods_num' => 'goods_num',
  49. 'og.total_pay_price' => 'total_pay_price',
  50. 'dog.level_id',
  51. 'dog.level',
  52. 'dog.ratio',
  53. 'dog.money',
  54. 'dog.status' => 'status_desc',
  55. 'dog.settlement_time',
  56. 's.id' => 'shop_id',
  57. 's.name' => 'shop_name',
  58. 's.logo' => 'shop_logo',
  59. ];
  60. $lists = DistributionOrderGoods::alias('dog')
  61. ->leftJoin('order o', 'o.id = dog.order_id')
  62. ->leftJoin('user u', 'u.id = dog.user_id')
  63. ->leftJoin('order_goods og', 'og.id = dog.order_goods_id')
  64. ->leftJoin('distribution_level dl', 'dl.id = dog.level_id')
  65. ->leftJoin('shop s', 's.id = dog.shop_id')
  66. ->field($field)
  67. ->where($where)
  68. ->order('dog.id', 'desc')
  69. ->page($params['page'], $params['limit'])
  70. ->select()
  71. ->toArray();
  72. $count = DistributionOrderGoods::alias('dog')
  73. ->leftJoin('order o', 'o.id = dog.order_id')
  74. ->leftJoin('user u', 'u.id = dog.user_id')
  75. ->leftJoin('order_goods og', 'og.id = dog.order_goods_id')
  76. ->leftJoin('distribution_level dl', 'dl.id = dog.level_id')
  77. ->leftJoin('shop s', 's.id = dog.shop_id')
  78. ->field($field)
  79. ->where($where)
  80. ->count();
  81. foreach($lists as &$item) {
  82. $item['order_create_time'] = date('Y-m-d H:i:s', $item['order_create_time']);
  83. $item['user_info'] = User::getUserInfo($item['order_user_id']);
  84. if ($item['user_info'] == '系统') {
  85. // 用户不存在(已被删除的情况)
  86. $item['user_info'] = [
  87. 'avatar' => '',
  88. 'nickname' => '-',
  89. 'sn' => '-',
  90. ];
  91. }
  92. $item['distribution_avatar'] = empty($item['distribution_avatar']) ? '' : UrlServer::getFileUrl($item['distribution_avatar']);
  93. $item['user_info']['avatar'] = empty($item['user_info']['avatar']) ? '' : UrlServer::getFileUrl($item['user_info']['avatar']);
  94. $item['level_name'] = DistributionLevel::getLevelName($item['level_id']);
  95. $item['shop_logo'] = empty($item['shop_logo']) ? '' : UrlServer::getFileUrl($item['shop_logo']);
  96. $item['goods_image'] = empty($item['goods_image']) ? '' : UrlServer::getFileUrl($item['goods_image']);
  97. }
  98. return [
  99. 'count' => $count,
  100. 'lists' => $lists
  101. ];
  102. }
  103. }