| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104 |
- <?php
- namespace app\extra\service\user;
- use app\extra\basic\Service;
- use app\extra\dao\user\UserBrokerageDao;
- use support\exception\BusinessException;
- class UserBrokerageService extends Service
- {
- /**
- * 用户记录模板
- * @var array[]
- */
- protected $incomeData = [
- 'extract' => [
- 'title' => '佣金提现',
- 'type' => 'extract',
- 'mark' => '{%mark%}',
- 'status' => 1,
- 'pm' => 0
- ],
- 'extract_fail' => [
- 'title' => '提现失败',
- 'type' => 'extract_fail',
- 'mark' => '提现失败,退回佣金{%number%}元',
- 'status' => 1,
- 'pm' => 1
- ],
- 'order_settle' => [
- 'title' => '订单结算',
- 'type' => 'order_settle',
- 'mark' => '订单结算成功,增加佣金{%number%}元',
- 'status' => 1,
- 'pm' => 1
- ],
- ];
- /**
- * 设置模型
- * @return string
- */
- public function __construct()
- {
- $this->dao = new UserBrokerageDao();
- }
- /**
- * 列表
- * @param array $param
- */
- public function getList(array $param = [],string $field = '*', int $page = 0,int $limit = 0,string $order = 'id desc')
- {
- $list = $this->dao->getList($this->searchFilter($param),$field,$page,$limit,$order);
- $count = $this->dao->count($this->searchFilter($param));
- return compact('list','count');
- }
- protected function searchFilter(array $param = []): array
- {
- $filter = [];
- !empty($param['key']) && $filter[] = ["uid", '=', $param['key']];
- !empty($param['pm']) && $filter[] = ["pm", '=', $param['pm']];
- return $filter;
- }
- /**
- * 写入佣金记录
- * @param string $type 写入类型
- * @param int $uid
- * @param int|string|array $number
- * @param int|string $balance
- * @param $linkId
- * @return bool|mixed
- */
- public function income(string $type, int $uid, $number, $balance, $linkId)
- {
- $data = $this->incomeData[$type] ?? null;
- if (!$data) {
- return true;
- }
- $data['uid'] = $uid;
- $data['balance'] = $balance ?? 0;
- $data['link_id'] = $linkId;
- if (is_array($number)) {
- $key = array_keys($number);
- $key = array_map(function ($item) {
- return '{%' . $item . '%}';
- }, $key);
- $value = array_values($number);
- $data['number'] = $number['number'] ?? 0;
- $data['frozen_time'] = $number['frozen_time'] ?? '';
- $data['mark'] = str_replace($key, $value, $data['mark']);
- } else {
- $data['number'] = $number;
- $data['mark'] = str_replace(['{%number%}'], $number, $data['mark']);
- }
- return $this->dao->save($data);
- }
- }
|