UserBrokerageService.php 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. <?php
  2. namespace app\extra\service\user;
  3. use app\extra\basic\Service;
  4. use app\extra\dao\user\UserBrokerageDao;
  5. use support\exception\BusinessException;
  6. class UserBrokerageService extends Service
  7. {
  8. /**
  9. * 用户记录模板
  10. * @var array[]
  11. */
  12. protected $incomeData = [
  13. 'extract' => [
  14. 'title' => '佣金提现',
  15. 'type' => 'extract',
  16. 'mark' => '{%mark%}',
  17. 'status' => 1,
  18. 'pm' => 0
  19. ],
  20. 'extract_fail' => [
  21. 'title' => '提现失败',
  22. 'type' => 'extract_fail',
  23. 'mark' => '提现失败,退回佣金{%number%}元',
  24. 'status' => 1,
  25. 'pm' => 1
  26. ],
  27. 'order_settle' => [
  28. 'title' => '订单结算',
  29. 'type' => 'order_settle',
  30. 'mark' => '订单结算成功,增加佣金{%number%}元',
  31. 'status' => 1,
  32. 'pm' => 1
  33. ],
  34. ];
  35. /**
  36. * 设置模型
  37. * @return string
  38. */
  39. public function __construct()
  40. {
  41. $this->dao = new UserBrokerageDao();
  42. }
  43. /**
  44. * 列表
  45. * @param array $param
  46. */
  47. public function getList(array $param = [],string $field = '*', int $page = 0,int $limit = 0,string $order = 'id desc')
  48. {
  49. $list = $this->dao->getList($this->searchFilter($param),$field,$page,$limit,$order);
  50. $count = $this->dao->count($this->searchFilter($param));
  51. return compact('list','count');
  52. }
  53. protected function searchFilter(array $param = []): array
  54. {
  55. $filter = [];
  56. !empty($param['key']) && $filter[] = ["uid", '=', $param['key']];
  57. !empty($param['pm']) && $filter[] = ["pm", '=', $param['pm']];
  58. return $filter;
  59. }
  60. /**
  61. * 写入佣金记录
  62. * @param string $type 写入类型
  63. * @param int $uid
  64. * @param int|string|array $number
  65. * @param int|string $balance
  66. * @param $linkId
  67. * @return bool|mixed
  68. */
  69. public function income(string $type, int $uid, $number, $balance, $linkId)
  70. {
  71. $data = $this->incomeData[$type] ?? null;
  72. if (!$data) {
  73. return true;
  74. }
  75. $data['uid'] = $uid;
  76. $data['balance'] = $balance ?? 0;
  77. $data['link_id'] = $linkId;
  78. if (is_array($number)) {
  79. $key = array_keys($number);
  80. $key = array_map(function ($item) {
  81. return '{%' . $item . '%}';
  82. }, $key);
  83. $value = array_values($number);
  84. $data['number'] = $number['number'] ?? 0;
  85. $data['frozen_time'] = $number['frozen_time'] ?? '';
  86. $data['mark'] = str_replace($key, $value, $data['mark']);
  87. } else {
  88. $data['number'] = $number;
  89. $data['mark'] = str_replace(['{%number%}'], $number, $data['mark']);
  90. }
  91. return $this->dao->save($data);
  92. }
  93. }