DistributionOrderGoods.php 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | likeshop100%开源免费商用商城系统
  4. // +----------------------------------------------------------------------
  5. // | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
  6. // | 开源版本可自由商用,可去除界面版权logo
  7. // | 商业版本务必购买商业授权,以免引起法律纠纷
  8. // | 禁止对系统程序代码以任何目的,任何形式的再发布
  9. // | gitee下载:https://gitee.com/likeshop_gitee
  10. // | github下载:https://github.com/likeshop-github
  11. // | 访问官网:https://www.likeshop.cn
  12. // | 访问社区:https://home.likeshop.cn
  13. // | 访问手册:http://doc.likeshop.cn
  14. // | 微信公众号:likeshop技术社区
  15. // | likeshop团队 版权所有 拥有最终解释权
  16. // +----------------------------------------------------------------------
  17. // | author: likeshopTeam
  18. // +----------------------------------------------------------------------
  19. namespace app\common\model;
  20. use app\common\enum\DistributionOrderGoodsEnum;
  21. class DistributionOrderGoods extends BaseModel
  22. {
  23. /**
  24. * @notes 返佣状态获取器
  25. * @param $value
  26. * @return string
  27. * @author Tab
  28. * @date 2021/7/17 18:15
  29. */
  30. public function getStatusDescAttr($value)
  31. {
  32. $desc = [1 => '待返佣', 2 => '已结算', 3 => '已失效'];
  33. return $desc[$value] ?? '';
  34. }
  35. /**
  36. * @notes 结算时间获取器
  37. * @param $value
  38. * @return string|null
  39. * @author Tab
  40. * @date 2021/7/28 9:21
  41. */
  42. public function getSettlementTimeAttr($value)
  43. {
  44. return $value ? date('Y-m-d H:i:s', $value) : '';
  45. }
  46. /**
  47. * @notes 分销层级描述获取器
  48. * @param $value
  49. * @return string
  50. * @author Tab
  51. * @date 2021/8/5 14:12
  52. */
  53. public function getLevelDescAttr($value)
  54. {
  55. $desc = ['自购佣金', '一级分佣', '二级分佣'];
  56. return $desc[$value] ?? '';
  57. }
  58. /**
  59. * @notes 累计已入账佣金
  60. * @param $userId
  61. * @return float
  62. * @author Tab
  63. * @date 2021/7/27 17:18
  64. */
  65. public static function getEarnings($userId)
  66. {
  67. return self::where([
  68. 'user_id' => $userId,
  69. 'status' => DistributionOrderGoodsEnum::RETURNED
  70. ])->sum('earnings');
  71. }
  72. /**
  73. * @notes 累计未返还佣金
  74. * @param $userId
  75. * @return float
  76. * @author Tab
  77. * @date 2021/8/5 15:03
  78. */
  79. public static function getUnReturnedCommission($userId)
  80. {
  81. return self::where([
  82. 'user_id' => $userId,
  83. 'status' => DistributionOrderGoodsEnum::UN_RETURNED
  84. ])->sum('earnings');
  85. }
  86. /**
  87. * @notes 买家信息
  88. * @param $userId
  89. * @return User|array|\think\Model
  90. * @author Tab
  91. * @date 2021/8/5 13:57
  92. */
  93. public static function getBueyer($userId)
  94. {
  95. return User::field('id,sn,nickname,avatar')->findOrEmpty($userId);
  96. }
  97. /**
  98. * @notes 订单用户信息搜索器
  99. * @param $query
  100. * @param $value
  101. * @param $data
  102. * @author Tab
  103. * @date 2021/9/22 16:49
  104. */
  105. public function searchUserIdAttr($query, $value, $data)
  106. {
  107. if (!isset($data['user_info']) || empty($data['user_info'])) {
  108. return $query;
  109. }
  110. $ids = User::where('sn|nickname', 'like', '%' . $data['user_info'] . '%')->column('id');
  111. return $query->where('o.user_id', 'in', $ids);
  112. }
  113. }