UserBillServices.php 44 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
  4. // +----------------------------------------------------------------------
  5. // | Copyright (c) 2016~2020 https://www.crmeb.com All rights reserved.
  6. // +----------------------------------------------------------------------
  7. // | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
  8. // +----------------------------------------------------------------------
  9. // | Author: CRMEB Team <admin@crmeb.com>
  10. // +----------------------------------------------------------------------
  11. declare (strict_types=1);
  12. namespace app\services\user;
  13. use app\services\BaseServices;
  14. use app\dao\user\UserBillDao;
  15. use app\services\order\StoreOrderServices;
  16. use think\Exception;
  17. use think\exception\ValidateException;
  18. use think\facade\Cache;
  19. use crmeb\services\CacheService;
  20. use think\facade\Log;
  21. /**
  22. *
  23. * Class UserBillServices
  24. * @package app\services\user
  25. * @method takeUpdate(int $uid, int $id) 修改收货状态
  26. * @method sum(array $where, string $field) 求和
  27. * @method count(array $where) 求条数
  28. * @method getTotalSum(array $where) 计算某个条件下订单内商品总数
  29. * @method getBillSum(array $where) 获取某个条件总数
  30. * @method getList(array $where, string $field, int $page, int $limit, $typeWhere = [], $order = 'id desc') 获取某个条件总数
  31. * @method getUserRefundPriceList(array $time, string $timeType, string $str, string $field = 'add_time', array $with = []) 获取退款金额按照时间分组
  32. */
  33. class UserBillServices extends BaseServices
  34. {
  35. /**
  36. * 用户记录模板
  37. * @var array[]
  38. */
  39. protected $incomeData = [
  40. 'pay_give_integral' => [
  41. 'title' => '购买商品赠送积分',
  42. 'category' => 'integral',
  43. 'type' => 'product_gain',
  44. 'mark' => '购买商品赠送{%num%}积分',
  45. 'status' => 1,
  46. 'pm' => 1
  47. ],
  48. 'order_give_integral' => [
  49. 'title' => '下单赠送积分',
  50. 'category' => 'integral',
  51. 'type' => 'gain',
  52. 'mark' => '下单赠送{%num%}积分',
  53. 'status' => 1,
  54. 'pm' => 1
  55. ],
  56. 'order_give_exp' => [
  57. 'title' => '下单赠送经验',
  58. 'category' => 'exp',
  59. 'type' => 'gain',
  60. 'mark' => '下单赠送{%num%}经验',
  61. 'status' => 1,
  62. 'pm' => 1
  63. ],
  64. 'get_brokerage' => [
  65. 'title' => '获得推广佣金',
  66. 'category' => 'now_money',
  67. 'type' => 'brokerage',
  68. 'mark' => '{%nickname%}成功消费{%pay_price%}元,奖励推广佣金{%number%}',
  69. 'status' => 1,
  70. 'pm' => 1
  71. ],
  72. 'get_two_brokerage' => [
  73. 'title' => '获得推广佣金',
  74. 'category' => 'now_money',
  75. 'type' => 'brokerage',
  76. 'mark' => '二级推广人{%nickname%}成功消费{%pay_price%}元,奖励推广佣金{%number%}',
  77. 'status' => 1,
  78. 'pm' => 1
  79. ],
  80. 'get_user_brokerage' => [
  81. 'title' => '获得推广用户佣金',
  82. 'category' => 'now_money',
  83. 'type' => 'brokerage_user',
  84. 'mark' => '成功推广用户:{%nickname%},奖励推广佣金{%number%}',
  85. 'status' => 1,
  86. 'pm' => 1
  87. ],
  88. 'pay_product_refund' => [
  89. 'title' => '商品退款',
  90. 'category' => 'now_money',
  91. 'type' => 'pay_product_refund',
  92. 'mark' => '订单退款{%payType%}{%number%}元',
  93. 'status' => 1,
  94. 'pm' => 1
  95. ],
  96. 'integral_refund' => [
  97. 'title' => '扣除订单下单赠送积分',
  98. 'category' => 'integral',
  99. 'type' => 'order_deduction',
  100. 'mark' => '购买商品失败,回退赠送积分{%num%}',
  101. 'status' => 1,
  102. 'pm' => 0
  103. ],
  104. 'order_integral_refund' => [
  105. 'title' => '返还下单使用积分',
  106. 'category' => 'integral',
  107. 'type' => 'integral_refund',
  108. 'mark' => '购买商品失败,回退积分{%num%}',
  109. 'status' => 1,
  110. 'pm' => 1
  111. ],
  112. 'pay_product_integral_back' => [
  113. 'title' => '商品退积分',
  114. 'category' => 'integral',
  115. 'type' => 'pay_product_integral_back',
  116. 'mark' => '订单退积分{%num%}积分到用户积分',
  117. 'status' => 1,
  118. 'pm' => 1
  119. ],
  120. 'deduction' => [
  121. 'title' => '积分抵扣',
  122. 'category' => 'integral',
  123. 'type' => 'deduction',
  124. 'mark' => '购买商品使用{%number%}积分抵扣{%deductionPrice%}元',
  125. 'status' => 1,
  126. 'pm' => 0
  127. ],
  128. 'pay_product' => [
  129. 'title' => '余额支付购买商品',
  130. 'category' => 'now_money',
  131. 'type' => 'pay_product',
  132. 'mark' => '余额支付{%num%}元购买商品',
  133. 'status' => 1,
  134. 'pm' => 0
  135. ],
  136. 'pay_money' => [
  137. 'title' => '购买商品',
  138. 'category' => 'now_money',
  139. 'type' => 'pay_money',
  140. 'mark' => '支付{%num%}元购买商品',
  141. 'status' => 1,
  142. 'pm' => 0
  143. ],
  144. 'system_add' => [
  145. 'title' => '系统增加余额',
  146. 'category' => 'now_money',
  147. 'type' => 'system_add',
  148. 'mark' => '系统增加{%num%}元',
  149. 'status' => 1,
  150. 'pm' => 1
  151. ],
  152. 'brokerage_to_nowMoney' => [
  153. 'title' => '佣金提现到余额',
  154. 'category' => 'now_money',
  155. 'type' => 'extract',
  156. 'mark' => '佣金提现到余额{%num%}元',
  157. 'status' => 1,
  158. 'pm' => 0
  159. ],
  160. 'pay_member' => [
  161. 'title' => '购买会员',
  162. 'category' => 'now_money',
  163. 'type' => 'pay_member',
  164. 'mark' => '支付{%num%}元购买会员',
  165. 'status' => 1,
  166. 'pm' => 0
  167. ],
  168. 'offline_scan' => [
  169. 'title' => '线下收银',
  170. 'category' => 'now_money',
  171. 'type' => 'offline_scan',
  172. 'mark' => '线下收银支付{%num%}元',
  173. 'status' => 1,
  174. 'pm' => 0
  175. ],
  176. 'lottery_use_integral' => [
  177. 'title' => '参与抽奖使用积分',
  178. 'category' => 'integral',
  179. 'type' => 'lottery_use',
  180. 'mark' => '参与抽奖使用{%num%}积分',
  181. 'status' => 1,
  182. 'pm' => 0
  183. ],
  184. 'lottery_give_integral' => [
  185. 'title' => '抽奖中奖赠送积分',
  186. 'category' => 'integral',
  187. 'type' => 'lottery_add',
  188. 'mark' => '抽奖中奖赠送{%num%}积分',
  189. 'status' => 1,
  190. 'pm' => 1
  191. ],
  192. 'lottery_use_money' => [
  193. 'title' => '参与抽奖使用余额',
  194. 'category' => 'now_money',
  195. 'type' => 'lottery_use',
  196. 'mark' => '参与抽奖使用{%num%}余额',
  197. 'status' => 1,
  198. 'pm' => 0
  199. ],
  200. 'lottery_give_money' => [
  201. 'title' => '抽奖中奖赠送余额',
  202. 'category' => 'now_money',
  203. 'type' => 'lottery_add',
  204. 'mark' => '抽奖中奖赠送{%num%}余额',
  205. 'status' => 1,
  206. 'pm' => 1
  207. ],
  208. 'storeIntegral_use_integral' => [
  209. 'title' => '积分兑换商品',
  210. 'category' => 'integral',
  211. 'type' => 'storeIntegral_use',
  212. 'mark' => '积分商城兑换商品使用{%num%}积分',
  213. 'status' => 1,
  214. 'pm' => 0
  215. ],
  216. ];
  217. /**
  218. * UserBillServices constructor.
  219. * @param UserBillDao $dao
  220. */
  221. public function __construct(UserBillDao $dao)
  222. {
  223. $this->dao = $dao;
  224. }
  225. /**
  226. * TODO 获取用户记录总和
  227. * @param $uid
  228. * @param string $category
  229. * @param array $type
  230. * @return mixed
  231. */
  232. public function getRecordCount(int $uid, $category = 'now_money', $type = [], $time = '', $pm = false)
  233. {
  234. $where = [];
  235. $where['uid'] = $uid;
  236. $where['category'] = $category;
  237. $where['status'] = 1;
  238. if (is_string($type) && strlen(trim($type))) {
  239. $where['type'] = explode(',', $type);
  240. }
  241. if ($time) {
  242. $where['time'] = $time;
  243. }
  244. if ($pm) {
  245. $where['pm'] = 0;
  246. }
  247. return $this->dao->getBillSumColumn($where);
  248. }
  249. public function getUsersBokerageSum(array $where, $time = 0)
  250. {
  251. $where_data = [
  252. 'type' => ['brokerage', 'brokerage_user'],
  253. 'category' => 'now_money',
  254. 'status' => 1,
  255. 'pm' => $where['pm'] ?? '',
  256. 'uid' => $where['uid'] ?? '',
  257. 'time' => $where['time'] ?? 0
  258. ];
  259. if ($time) $where_data['time'] = $time;
  260. return $this->dao->getBillSumColumn($where_data);
  261. }
  262. /**
  263. * 某个用户佣金总和
  264. * @param int $uid
  265. * @return float
  266. */
  267. public function getUserBillBrokerageSum(int $uid, array $type = ['brokerage', 'brokerage_user'], $time = '')
  268. {
  269. $where = ['uid' => $uid, 'category' => 'now_money'];
  270. if ($type) $where['type'] = $type;
  271. if ($time) $where['time'] = $time;
  272. return $this->dao->getBillSum($where);
  273. }
  274. /**
  275. * 获取用户|所有佣金总数
  276. * @param int $uid
  277. * @param array $where_time
  278. * @return float
  279. */
  280. public function getBrokerageSum(int $uid = 0, $where_time = [])
  281. {
  282. $where = ['category' => 'now_money', 'type' => ['system_add', 'pay_product', 'extract', 'pay_product_refund', 'system_sub'], 'pm' => 1, 'status' => 1];
  283. if ($uid) $where['uid'] = $uid;
  284. if ($where_time) $where['add_time'] = $where_time;
  285. return $this->dao->getBillSum($where);
  286. }
  287. public function getBrokerageNumSum($link_ids = [])
  288. {
  289. $where = ['category' => 'now_money', 'type' => ['brokerage', 'brokerage_user']];
  290. if ($link_ids) $where['link_id'] = $link_ids;
  291. return $this->dao->getBillSum($where);
  292. }
  293. /**
  294. * 获取用户|所有佣金总数
  295. * @param int $uid
  296. * @param array $where_time
  297. * @return float
  298. */
  299. public function getBrokerageCount(int $uid = 0, $where_time = [])
  300. {
  301. $where = ['category' => 'now_money', 'type' => ['system_add', 'pay_product', 'extract', 'pay_product_refund', 'system_sub'], 'pm' => 1, 'status' => 1];
  302. if ($uid) $where['uid'] = $uid;
  303. if ($where_time) $where['add_time'] = $where_time;
  304. return $this->dao->getBillCount($where);
  305. }
  306. /**
  307. * 用户|所有资金变动列表
  308. * @param int $uid
  309. * @param string $field
  310. * @return array
  311. */
  312. public function getBrokerageList(int $uid = 0, $where_time = [], string $field = '*')
  313. {
  314. [$page, $limit] = $this->getPageValue();
  315. $where = ['category' => 'now_money', 'type' => ['pay_money', 'system_add', 'pay_product_refund', 'pay_member', 'offline_scan', 'lottery_add', 'system_sub']];
  316. if ($uid) $where['uid'] = $uid;
  317. if ($where_time) $where['add_time'] = $where_time;
  318. $list = $this->dao->getList($where, $field, $page, $limit);
  319. $count = $this->dao->count($where);
  320. foreach ($list as &$item) {
  321. $value = array_filter($this->incomeData, function ($value) use ($item) {
  322. if ($item['type'] == $value['type']) {
  323. return $item['title'];
  324. }
  325. });
  326. $item['type_title'] = $value[$item['type']]['title'] ?? '未知类型';
  327. }
  328. return compact('list', 'count');
  329. }
  330. /**
  331. * 获取用户的充值总数
  332. * @param int $uid
  333. * @return float
  334. */
  335. public function getRechargeSum(int $uid = 0, $where_time = [])
  336. {
  337. $where = ['category' => 'now_money', 'type' => 'recharge', 'pm' => 1, 'status' => 1];//用户充值余额
  338. $where_system = ['category' => 'now_money', 'type' => 'system_add', 'pm' => 1, 'status' => 1];//系统赠送余额
  339. if ($uid) $where['uid'] = $where_system['uid'] = $uid;
  340. if ($where_time) $where['add_time'] = $where_system['add_time'] = $where_time;
  341. $sum1 = $this->dao->getBillSum($where);
  342. $sum2 = $this->dao->getBillSum($where_system);
  343. return bcadd((string)$sum1, (string)$sum2, 2);
  344. }
  345. /**
  346. * 用户|所有充值列表
  347. * @param int $uid
  348. * @param string $field
  349. * @return array
  350. */
  351. public function getRechargeList(int $uid = 0, $where_time = [], string $field = '*')
  352. {
  353. [$page, $limit] = $this->getPageValue();
  354. $where = ['category' => 'now_money', 'type' => 'recharge'];
  355. if ($uid) $where['uid'] = $uid;
  356. if ($where_time) $where['add_time'] = $where_time;
  357. $list = $this->dao->getList($where, $field, $page, $limit);
  358. $count = $this->dao->count($where);
  359. return compact('list', 'count');
  360. }
  361. /**
  362. * 获取用户的积分总数
  363. * @param int $uid
  364. * @return float
  365. */
  366. public function getIntegralSum(int $uid = 0, $where_time = [])
  367. {
  368. $where = ['category' => 'integral', 'type' => ['sign', 'system_add'], 'pm' => 1, 'status' => 1];
  369. if ($uid) $where['uid'] = $uid;
  370. if ($where_time) $where['add_time'] = $where_time;
  371. return $this->dao->getBillSum($where);
  372. }
  373. /**
  374. * 获取用户的获取积分总次数
  375. * @param int $uid
  376. * @return float
  377. */
  378. public function getIntegralCount(int $uid = 0, $where_time = [])
  379. {
  380. $where = ['category' => 'integral', 'type' => ['sign', 'system_add'], 'pm' => 1, 'status' => 1];
  381. if ($uid) $where['uid'] = $uid;
  382. if ($where_time) $where['add_time'] = $where_time;
  383. return $this->dao->getBillCount($where);
  384. }
  385. /**
  386. * 获取积分列表
  387. * @param int $uid
  388. * @param array $where_time
  389. * @param string $field
  390. * @return array
  391. */
  392. public function getIntegralList(int $uid = 0, $where_time = [], string $field = '*')
  393. {
  394. [$page, $limit] = $this->getPageValue();
  395. $where = ['category' => 'integral'];
  396. if ($uid) $where['uid'] = $uid;
  397. if ($where_time) $where['add_time'] = $where_time;
  398. $list = $this->dao->getList($where, $field, $page, $limit);
  399. foreach ($list as &$item) {
  400. $item['number'] = intval($item['number']);
  401. $item['is_frozen'] = $item['frozen_time'] > time() ? 1 : 0;
  402. }
  403. $count = $this->dao->count($where);
  404. return compact('list', 'count');
  405. }
  406. /**
  407. * 获取用户签到总数
  408. * @param int $uid
  409. * @return float
  410. */
  411. public function getSignlSum(int $uid = 0, $where_time = [])
  412. {
  413. $where = ['category' => 'integral', 'type' => 'sign', 'pm' => 1, 'status' => 1];
  414. if ($uid) $where['uid'] = $uid;
  415. if ($where_time) $where['add_time'] = $where_time;
  416. return $this->dao->getBillSum($where);
  417. }
  418. /**
  419. * 获取用户的签到总次数
  420. * @param int $uid
  421. * @return float
  422. */
  423. public function getSignCount(int $uid = 0, $where_time = [])
  424. {
  425. $where = ['category' => 'integral', 'type' => 'sign', 'pm' => 1, 'status' => 1];
  426. if ($uid) $where['uid'] = $uid;
  427. if ($where_time) $where['add_time'] = $where_time;
  428. return $this->dao->getBillCount($where);
  429. }
  430. /**
  431. * 获取签到列表
  432. * @param int $uid
  433. * @param array $where_time
  434. * @param string $field
  435. * @return array
  436. */
  437. public function getSignList(int $uid = 0, $where_time = [], string $field = '*')
  438. {
  439. [$page, $limit] = $this->getPageValue();
  440. $where = ['category' => 'integral', 'type' => 'sign'];
  441. if ($uid) $where['uid'] = $uid;
  442. if ($where_time) $where['add_time'] = $where_time;
  443. $list = $this->dao->getList($where, $field, $page, $limit);
  444. $count = $this->dao->count($where);
  445. return compact('list', 'count');
  446. }
  447. /**
  448. * 经验总数
  449. * @param int $uid
  450. * @param array $where_time
  451. * @return float
  452. */
  453. public function getExpSum(int $uid = 0, $where_time = [])
  454. {
  455. $where = ['category' => ['exp'], 'pm' => 1, 'status' => 1];
  456. if ($uid) $where['uid'] = $uid;
  457. if ($where_time) $where['time'] = $where_time;
  458. return $this->dao->getBillSum($where);
  459. }
  460. /**
  461. * 获取所有经验列表
  462. * @param int $uid
  463. * @param array $where_time
  464. * @param string $field
  465. * @return array
  466. */
  467. public function getExpList(int $uid = 0, $where_time = [], string $field = '*')
  468. {
  469. [$page, $limit] = $this->getPageValue();
  470. $where = ['category' => ['exp']];
  471. $where['status'] = 1;
  472. if ($uid) $where['uid'] = $uid;
  473. if ($where_time) $where['time'] = $where_time;
  474. $list = $this->dao->getList($where, $field, $page, $limit);
  475. $count = $this->dao->count($where);
  476. return compact('list', 'count');
  477. }
  478. /**
  479. * 增加佣金
  480. * @param int $uid
  481. * @param string $type
  482. * @param array $data
  483. * @return bool
  484. * @throws Exception
  485. */
  486. public function incomeNowMoney(int $uid, string $type, array $data)
  487. {
  488. $data['uid'] = $uid;
  489. $data['category'] = 'now_money';
  490. $data['type'] = $type;
  491. $data['pm'] = 1;
  492. $data['status'] = 1;
  493. $data['add_time'] = time();
  494. if (!$this->dao->save($data))
  495. throw new Exception('增加记录失败');
  496. return true;
  497. }
  498. /**
  499. * 扣除佣金
  500. * @param int $uid
  501. * @param string $type
  502. * @param array $data
  503. * @return bool
  504. * @throws Exception
  505. */
  506. public function expendNowMoney(int $uid, string $type, array $data)
  507. {
  508. $data['uid'] = $uid;
  509. $data['category'] = 'now_money';
  510. $data['type'] = $type;
  511. $data['pm'] = 0;
  512. $data['status'] = 1;
  513. $data['add_time'] = time();
  514. if (!$this->dao->save($data))
  515. throw new Exception('增加记录失败');
  516. return true;
  517. }
  518. /**
  519. * 增加积分
  520. * @param int $uid
  521. * @param string $type
  522. * @param array $data
  523. * @return bool
  524. * @throws Exception
  525. */
  526. public function incomeIntegral(int $uid, string $type, array $data)
  527. {
  528. $data['uid'] = $uid;
  529. $data['category'] = 'integral';
  530. $data['type'] = $type;
  531. $data['pm'] = 1;
  532. $data['status'] = 1;
  533. $data['add_time'] = time();
  534. if (!$this->dao->save($data))
  535. throw new Exception('增加记录失败');
  536. return true;
  537. }
  538. /**
  539. * 扣除积分
  540. * @param int $uid
  541. * @param string $type
  542. * @param array $data
  543. * @return bool
  544. * @throws Exception
  545. */
  546. public function expendIntegral(int $uid, string $type, array $data)
  547. {
  548. $data['uid'] = $uid;
  549. $data['category'] = 'integral';
  550. $data['type'] = $type;
  551. $data['pm'] = 0;
  552. $data['status'] = 1;
  553. $data['add_time'] = time();
  554. if (!$this->dao->save($data))
  555. throw new Exception('增加记录失败');
  556. return true;
  557. }
  558. /**
  559. * 写入用户记录
  560. * @param string $type 写入类型
  561. * @param int $uid
  562. * @param int|string|array $number
  563. * @param int|string $balance
  564. * @param int $link_id
  565. * @return bool|mixed
  566. */
  567. public function income(string $type, int $uid, $number, $balance, $link_id)
  568. {
  569. $data = $this->incomeData[$type] ?? null;
  570. if (!$data) {
  571. return true;
  572. }
  573. $data['uid'] = $uid;
  574. $data['balance'] = $balance ?? 0;
  575. $data['link_id'] = $link_id;
  576. if (is_array($number)) {
  577. $key = array_keys($number);
  578. $key = array_map(function ($item) {
  579. return '{%' . $item . '%}';
  580. }, $key);
  581. $value = array_values($number);
  582. $data['number'] = $number['number'] ?? 0;
  583. $data['mark'] = str_replace($key, $value, $data['mark']);
  584. } else {
  585. $data['number'] = $number;
  586. $data['mark'] = str_replace(['{%num%}'], $number, $data['mark']);
  587. }
  588. $data['add_time'] = time();
  589. if ($type == 'pay_give_integral' || $type == 'order_give_integral') {
  590. $integral_frozen = sys_config('integral_frozen');
  591. if ($integral_frozen) {
  592. $data['frozen_time'] = $data['add_time'] + ($integral_frozen * 86400);
  593. }
  594. }
  595. return $this->dao->save($data);
  596. }
  597. /**
  598. * 邀请新用户增加经验
  599. * @param int $spreadUid
  600. */
  601. public function inviteUserIncExp(int $spreadUid)
  602. {
  603. if (!$spreadUid) {
  604. return false;
  605. }
  606. //用户等级是否开启
  607. if (!sys_config('member_func_status', 1)) {
  608. return false;
  609. }
  610. /** @var UserServices $userService */
  611. $userService = app()->make(UserServices::class);
  612. $spread_user = $userService->getUserInfo($spreadUid);
  613. if (!$spread_user) {
  614. return false;
  615. }
  616. $exp_num = sys_config('invite_user_exp', 0);
  617. if ($exp_num) {
  618. $userService->incField($spreadUid, 'exp', (int)$exp_num);
  619. $data = [];
  620. $data['uid'] = $spreadUid;
  621. $data['number'] = $exp_num;
  622. $data['category'] = 'exp';
  623. $data['type'] = 'invite_user';
  624. $data['title'] = $data['mark'] = '邀新奖励';
  625. $data['balance'] = (int)$spread_user['exp'] + (int)$exp_num;
  626. $data['pm'] = 1;
  627. $data['status'] = 1;
  628. $this->dao->save($data);
  629. }
  630. //检测会员等级
  631. try {
  632. //用户升级事件
  633. event('user.userLevel', [$spreadUid]);
  634. } catch (\Throwable $e) {
  635. Log::error('会员等级升级失败,失败原因:' . $e->getMessage());
  636. }
  637. return true;
  638. }
  639. /**
  640. * 获取type
  641. * @param array $where
  642. * @param string $filed
  643. */
  644. public function getBillType(array $where)
  645. {
  646. return $this->dao->getType($where);
  647. }
  648. /**
  649. * 资金类型
  650. */
  651. public function bill_type()
  652. {
  653. $where = [];
  654. $where['not_type'] = ['gain', 'system_sub', 'deduction', 'sign'];
  655. $where['not_category'] = ['exp', 'integral'];
  656. return Cache::remember('user_type_list', function () use ($where) {
  657. return ['list' => $this->getBillType($where)];
  658. }, 600);
  659. }
  660. /**
  661. * 获取资金列表
  662. * @param array $where
  663. * @param string $field
  664. * @return array
  665. */
  666. public function getBillList(array $where, string $field = '*', $is_page = true)
  667. {
  668. $where_data = [];
  669. if (isset($where['uid']) && $where['uid'] != '') {
  670. $where_data['uid'] = $where['uid'];
  671. }
  672. if ($where['start_time'] != '' && $where['end_time'] != '') {
  673. $where_data['time'] = str_replace('-', '/', $where['start_time']) . ' - ' . str_replace('-', '/', $where['end_time']);
  674. }
  675. if (isset($where['category']) && $where['category'] != '') {
  676. $where_data['category'] = $where['category'];
  677. }
  678. if (isset($where['type']) && $where['type'] != '') {
  679. $where_data['type'] = $where['type'];
  680. if ($where['type'] == 'brokerage') $where_data['pm'] = 1;
  681. }
  682. $where_data['not_category'] = ['integral', 'exp', 'share'];
  683. $where_data['not_type'] = $where['type'] == 'pay_product' ? ['gain', 'system_sub', 'deduction', 'sign'] : ['gain', 'system_sub', 'deduction', 'sign', 'pay_product'];
  684. if (isset($where['nickname']) && $where['nickname'] != '') {
  685. $where_data['like'] = $where['nickname'];
  686. }
  687. if (isset($where['excel']) && $where['excel'] != '') {
  688. $where_data['excel'] = $where['excel'];
  689. } else {
  690. $where_data['excel'] = 0;
  691. }
  692. [$page, $limit] = $this->getPageValue($is_page);
  693. $data = $this->dao->getBillList($where_data, $field, $page, $limit);
  694. foreach ($data as &$item) {
  695. $item['nickname'] = $item['user']['nickname'] ?? '';
  696. unset($item['user']);
  697. }
  698. $count = $this->dao->count($where_data);
  699. return compact('data', 'count');
  700. }
  701. /**
  702. * 获取佣金列表
  703. * @param array $where
  704. * @param int $limit
  705. * @return array
  706. */
  707. public function getCommissionList(array $where, int $limit = 0)
  708. {
  709. $where_data = [];
  710. $where_data['time'] = $where['time'];
  711. if (isset($where['nickname']) && $where['nickname']) {
  712. $where_data[] = ['u.account|u.nickname|u.uid|u.phone', 'LIKE', "%$where[nickname]%"];
  713. }
  714. if (isset($where['price_max']) && isset($where['price_min'])) {
  715. if ($where['price_max'] != '' && $where['price_min'] != '') {
  716. $where_data[] = ['u.brokerage_price', 'between', [$where['price_min'], $where['price_max']]];
  717. } elseif ($where['price_min'] != '' && $where['price_max'] == '') {
  718. $where_data[] = ['u.brokerage_price', '>=', $where['price_min']];
  719. } elseif ($where['price_min'] == '' && $where['price_max'] != '') {
  720. $where_data[] = ['u.brokerage_price', '<=', $where['price_max']];
  721. }
  722. }
  723. $order_string = '';
  724. $order_arr = ['asc', 'desc'];
  725. if (isset($where['sum_number']) && in_array($where['sum_number'], $order_arr)) {
  726. $order_string .= ',income ' . $where['sum_number'];
  727. }
  728. if (isset($where['brokerage_price']) && in_array($where['brokerage_price'], $order_arr)) {
  729. $order_string .= ',u.brokerage_price ' . $where['brokerage_price'];
  730. }
  731. if ($order_string) {
  732. $order_string = trim($order_string, ',');
  733. }
  734. /** @var UserUserBrokerageServices $userUserBrokerage */
  735. $userUserBrokerage = app()->make(UserUserBrokerageServices::class);
  736. [$count, $list] = $userUserBrokerage->getBrokerageList($where_data, 'b.type,b.pm,sum(IF(b.pm = 1, b.number, 0)) as income,sum(IF(b.pm = 0, b.number, 0)) as pay,u.nickname,u.phone,u.uid,u.now_money,u.brokerage_price,b.add_time as time', $order_string, $limit);
  737. $uids = array_unique(array_column($list, 'uid'));
  738. /** @var UserExtractServices $userExtract */
  739. $userExtract = app()->make(UserExtractServices::class);
  740. $extractSumList = $userExtract->getUsersSumList($uids);
  741. foreach ($list as &$item) {
  742. $item['sum_number'] = $item['income'] > $item['pay'] ? bcsub($item['income'], $item['pay'], 2) : 0;
  743. $item['nickname'] = $item['nickname'] . "|" . ($item['phone'] ? $item['phone'] . "|" : '') . $item['uid'];
  744. $item['extract_price'] = $extractSumList[$item['uid']] ?? 0;
  745. $item['time'] = $item['time'] ? date('Y-m-d H:i:s', $item['time']) : '';
  746. }
  747. return compact('count', 'list');
  748. }
  749. public function user_info(int $uid)
  750. {
  751. /** @var UserServices $user */
  752. $user = app()->make(UserServices::class);
  753. $user_info = $user->getUserInfo($uid, 'nickname,spread_uid,now_money,add_time,brokerage_price');
  754. if (!$user_info) {
  755. throw new ValidateException('您查看的用户信息不存在!');
  756. }
  757. $user_info = $user_info->toArray();
  758. $user_info['number'] = $user_info['brokerage_price'];
  759. $user_info['add_time'] = date('Y-m-d H:i:s', $user_info['add_time']);
  760. $user_info['spread_name'] = $user_info['spread_uid'] ? $user->getUserInfo((int)$user_info['spread_uid'], 'nickname', true)['nickname'] ?? '' : '';
  761. return compact('user_info');
  762. }
  763. /**
  764. * 记录分享次数
  765. * @param int $uid 用户uid
  766. * @param int $cd 冷却时间
  767. * @return Boolean
  768. * */
  769. public function setUserShare(int $uid, $cd = 300)
  770. {
  771. /** @var UserServices $userServices */
  772. $userServices = app()->make(UserServices::class);
  773. $user = $userServices->getUserInfo($uid);
  774. if (!$user) {
  775. throw new ValidateException('用户不存在!');
  776. }
  777. $cachename = 'Share_' . $uid;
  778. if (CacheService::get($cachename)) {
  779. return false;
  780. }
  781. $data = ['title' => '用户分享记录', 'uid' => $uid, 'category' => 'share', 'type' => 'share', 'number' => 0, 'link_id' => 0, 'balance' => 0, 'mark' => date('Y-m-d H:i:s', time()) . ':用户分享'];
  782. if (!$this->dao->save($data)) {
  783. throw new ValidateException('记录分享记录失败');
  784. }
  785. CacheService::set($cachename, 1, $cd);
  786. return true;
  787. }
  788. /**
  789. * 获取佣金提现列表
  790. * @param int $uid
  791. * @param array $where
  792. * @return array
  793. * @throws \think\db\exception\DataNotFoundException
  794. * @throws \think\db\exception\DbException
  795. * @throws \think\db\exception\ModelNotFoundException
  796. */
  797. public function getBillOneList(int $uid, array $where)
  798. {
  799. $where['uid'] = $uid;
  800. $data = $this->getBillList($where);
  801. foreach ($data['data'] as &$item) {
  802. $item['_add_time'] = $item['add_time'] ?? '';
  803. }
  804. return $data;
  805. }
  806. /**
  807. * 获取积分列表
  808. * @param array $where
  809. * @param string $field
  810. * @return array
  811. */
  812. public function getPointList(array $where, string $field = '*', $is_page = true)
  813. {
  814. $where_data = [];
  815. $where_data['category'] = 'integral';
  816. if (isset($where['uid']) && $where['uid'] != '') {
  817. $where_data['uid'] = $where['uid'];
  818. }
  819. if ($where['start_time'] != '' && $where['end_time'] != '') {
  820. $where_data['time'] = $where['start_time'] . ' - ' . $where['end_time'];
  821. }
  822. if (isset($where['type']) && $where['type'] != '') {
  823. $where_data['type'] = $where['type'];
  824. }
  825. if (isset($where['nickname']) && $where['nickname'] != '') {
  826. $where_data['like'] = $where['nickname'];
  827. }
  828. if (isset($where['excel']) && $where['excel'] != '') {
  829. $where_data['excel'] = $where['excel'];
  830. } else {
  831. $where_data['excel'] = 0;
  832. }
  833. [$page, $limit] = $this->getPageValue($is_page);
  834. $list = $this->dao->getBillList($where_data, $field, $page, $limit);
  835. foreach ($list as &$item) {
  836. $item['nickname'] = $item['user']['nickname'] ?? '';
  837. $item['number'] = intval($item['number']);
  838. $item['balance'] = intval($item['balance']);
  839. unset($item['user']);
  840. }
  841. $count = $this->dao->count($where_data);
  842. return compact('list', 'count');
  843. }
  844. /**
  845. * 积分头部信息
  846. * @param array $where
  847. * @return array[]
  848. */
  849. public function getUserPointBadgelist(array $where)
  850. {
  851. $data = [];
  852. $where_data = [];
  853. $where_data['category'] = 'integral';
  854. if ($where['start_time'] != '' && $where['end_time'] != '') {
  855. $where_data['time'] = $where['start_time'] . ' - ' . $where['end_time'];
  856. }
  857. if (isset($where['nickname']) && $where['nickname'] != '') {
  858. $where_data['like'] = $where['nickname'];
  859. }
  860. $data['SumIntegral'] = intval($this->dao->getBillSumColumn($where_data + ['pm' => 1, 'integral_type' => 'get']));
  861. $where_data['type'] = 'sign';
  862. $data['CountSign'] = $this->dao->getUserSignPoint($where_data);
  863. $data['SumSign'] = intval($this->dao->getBillSumColumn($where_data));
  864. $where_data['type'] = ['deduction', 'system_sub'];
  865. $data['SumDeductionIntegral'] = intval($this->dao->getBillSumColumn($where_data));
  866. return [
  867. [
  868. 'col' => 6,
  869. 'count' => $data['SumIntegral'],
  870. 'name' => '总积分(个)',
  871. ],
  872. [
  873. 'col' => 6,
  874. 'count' => $data['CountSign'],
  875. 'name' => '客户签到次数(次)',
  876. ],
  877. [
  878. 'col' => 6,
  879. 'count' => $data['SumSign'],
  880. 'name' => '签到送出积分(个)',
  881. ],
  882. [
  883. 'col' => 6,
  884. 'count' => $data['SumDeductionIntegral'],
  885. 'name' => '使用积分(个)',
  886. ],
  887. ];
  888. }
  889. /**
  890. * 退佣金
  891. * @param int $id
  892. * @throws \think\db\exception\DataNotFoundException
  893. * @throws \think\db\exception\DbException
  894. * @throws \think\db\exception\ModelNotFoundException
  895. */
  896. public function orderRefundBrokerageBack(int $id, string $orderId)
  897. {
  898. $brokerageList = $this->dao->getUserBillList([
  899. 'category' => 'now_money',
  900. 'type' => 'brokerage',
  901. 'link_id' => $id,
  902. 'pm' => 1
  903. ]);
  904. /** @var UserServices $userServices */
  905. $userServices = app()->make(UserServices::class);
  906. $brokerages = $userServices->getColumn([['uid', 'in', array_column($brokerageList, 'uid')]], 'brokerage_price', 'uid');
  907. $userBillData = [];
  908. $res = true;
  909. foreach ($brokerageList as $item) {
  910. $usermoney = $brokerages[$item['uid']] ?? 0;
  911. if ($item['number'] > $usermoney) {
  912. $item['number'] = $usermoney;
  913. }
  914. $res = $res && $userServices->bcDec($item['uid'], 'brokerage_price', (string)$item['number'], 'uid');
  915. $userBillData[] = [
  916. 'title' => '退款退佣金',
  917. 'uid' => $item['uid'],
  918. 'pm' => 0,
  919. 'add_time' => time(),
  920. 'category' => 'now_money',
  921. 'type' => 'brokerage',
  922. 'number' => $item['number'],
  923. 'link_id' => $id,
  924. 'balance' => bcsub((string)$usermoney, (string)$item['number'], 2),
  925. 'mark' => '订单退款扣除佣金' . floatval($item['number']) . '元'
  926. ];
  927. }
  928. if ($userBillData) {
  929. $res = $res && $this->dao->saveAll($userBillData);
  930. }
  931. /** @var UserBrokerageFrozenServices $services */
  932. $services = app()->make(UserBrokerageFrozenServices::class);
  933. $services->updateFrozen($orderId);
  934. return $res;
  935. }
  936. /**
  937. * 佣金排行
  938. * @param string $time
  939. * @return array
  940. * @throws \think\db\exception\DataNotFoundException
  941. * @throws \think\db\exception\DbException
  942. * @throws \think\db\exception\ModelNotFoundException
  943. */
  944. public function brokerageRankList(string $time = 'week')
  945. {
  946. $where = [];
  947. $where['category'] = 'now_money';
  948. $where['type'] = ['brokerage', 'brokerage_user'];
  949. if ($time) {
  950. $where['time'] = $time;
  951. }
  952. [$page, $limit] = $this->getPageValue();
  953. $list = $this->dao->brokerageRankList($where, $page, $limit);
  954. foreach ($list as $key => &$item) {
  955. if (!isset($item['user']) || !$item['user']) {
  956. unset($list['$key']);
  957. continue;
  958. }
  959. $item['nickname'] = $item['user']['nickname'] ?? '';
  960. $item['avatar'] = $item['user']['avatar'] ?? '';
  961. if ($item['brokerage_price'] == '0.00' || $item['brokerage_price'] == 0 || !$item['brokerage_price']) {
  962. unset($list[$key]);
  963. }
  964. unset($item['user']);
  965. }
  966. return $list;
  967. }
  968. /**
  969. * 获取用户排名
  970. * @param int $uid
  971. * @param string $time
  972. */
  973. public function getUserBrokerageRank(int $uid, string $time = 'week')
  974. {
  975. $where = [];
  976. $where['category'] = 'now_money';
  977. $where['type'] = ['brokerage', 'brokerage_user'];
  978. if ($time) {
  979. $where['time'] = $time;
  980. }
  981. $list = $this->dao->brokerageRankList($where, 0, 0);
  982. $position_tmp_one = array_column($list, 'uid');
  983. $position_tmp_two = array_column($list, 'brokerage_price', 'uid');
  984. if (!in_array($uid, $position_tmp_one)) {
  985. $position = 0;
  986. } else {
  987. if ($position_tmp_two[$uid] == 0.00) {
  988. $position = 0;
  989. } else {
  990. $position = array_search($uid, $position_tmp_one) + 1;
  991. }
  992. }
  993. return $position;
  994. }
  995. /**
  996. * 推广数据 昨天的佣金 累计提现金额 当前佣金
  997. * @param int $uid
  998. * @return mixed
  999. */
  1000. public function commission(int $uid)
  1001. {
  1002. /** @var UserServices $userServices */
  1003. $userServices = app()->make(UserServices::class);
  1004. if (!$userServices->getUserInfo($uid)) {
  1005. throw new ValidateException('数据不存在');
  1006. }
  1007. /** @var UserExtractServices $userExtract */
  1008. $userExtract = app()->make(UserExtractServices::class);
  1009. $data = [];
  1010. $data['uid'] = $uid;
  1011. $data['pm'] = 1;
  1012. $data['commissionSum'] = $this->getUsersBokerageSum($data);
  1013. $data['pm'] = 0;
  1014. $data['commissionRefund'] = $this->getUsersBokerageSum($data);
  1015. $data['commissionCount'] = $data['commissionSum'] > $data['commissionRefund'] ? bcsub((string)$data['commissionSum'], (string)$data['commissionRefund'], 2) : 0.00;
  1016. $data['lastDayCount'] = $this->getUsersBokerageSum($data, 'yesterday');//昨天的佣金
  1017. $data['extractCount'] = $userExtract->getUserExtract($uid);//累计提现金额
  1018. return $data;
  1019. }
  1020. /**
  1021. * 前端佣金排行页面数据
  1022. * @param int $uid
  1023. * @param $type
  1024. * @return array
  1025. * @throws \think\db\exception\DataNotFoundException
  1026. * @throws \think\db\exception\DbException
  1027. * @throws \think\db\exception\ModelNotFoundException
  1028. */
  1029. public function brokerage_rank(int $uid, $type)
  1030. {
  1031. /** @var UserServices $userService */
  1032. $userService = app()->make(UserServices::class);
  1033. if (!$userService->getUserInfo($uid)) {
  1034. throw new ValidateException('数据不存在');
  1035. }
  1036. return [
  1037. 'rank' => $this->brokerageRankList($type),
  1038. 'position' => $this->getUserBrokerageRank($uid, $type)
  1039. ];
  1040. }
  1041. /**
  1042. * @param $uid
  1043. * @param $type
  1044. * @return array
  1045. */
  1046. public function getUserBillList(int $uid, int $type)
  1047. {
  1048. $where = [];
  1049. $where['uid'] = $uid;
  1050. $where['category'] = 'now_money';
  1051. switch ((int)$type) {
  1052. case 0:
  1053. $where['type'] = ['recharge', 'pay_money', 'system_add', 'pay_product_refund', 'system_sub', 'pay_member', 'offline_scan', 'lottery_add'];
  1054. break;
  1055. case 1:
  1056. $where['type'] = ['pay_money', 'pay_member', 'offline_scan', 'user_recharge_refund'];
  1057. break;
  1058. case 2:
  1059. $where['type'] = ['recharge', 'system_add', 'lottery_add'];
  1060. break;
  1061. case 3:
  1062. $where['type'] = ['brokerage', 'brokerage_user'];
  1063. break;
  1064. case 4:
  1065. $where['type'] = ['extract'];
  1066. /** @var UserExtractServices $userExtractService */
  1067. $userExtractService = app()->make(UserExtractServices::class);
  1068. $userExtract = $userExtractService->getColumn(['uid' => $uid], 'fail_msg', 'id');
  1069. break;
  1070. }
  1071. $field = 'FROM_UNIXTIME(add_time,"%Y-%m") as time,group_concat(id SEPARATOR ",") ids';
  1072. [$page, $limit] = $this->getPageValue();
  1073. $list = $this->dao->getUserBillListByGroup($where, $field, 'time', $page, $limit);
  1074. $data = [];
  1075. if ($list) {
  1076. $listIds = array_column($list, 'ids');
  1077. $ids = [];
  1078. foreach ($listIds as $id) {
  1079. $ids = array_merge($ids, explode(',', $id));
  1080. }
  1081. $info = $this->dao->getColumn([['id', 'in', $ids]], 'FROM_UNIXTIME(add_time,"%Y-%m-%d %H:%i") as add_time,title,number,pm,link_id', 'id');
  1082. foreach ($list as $item) {
  1083. $value['time'] = $item['time'];
  1084. $id = explode(',', $item['ids']);
  1085. array_multisort($id, SORT_DESC);
  1086. $value['list'] = [];
  1087. foreach ($id as $v) {
  1088. if (isset($info[$v])) {
  1089. if ($info[$v]['pm'] == 1 && $type == 4) $info[$v]['fail_msg'] = $userExtract[$info[$v]['link_id']];
  1090. $value['list'][] = $info[$v];
  1091. }
  1092. }
  1093. array_push($data, $value);
  1094. }
  1095. }
  1096. return $data;
  1097. }
  1098. /**
  1099. * 推广 佣金/提现 总和
  1100. * @param int $uid
  1101. * @param $type 3 佣金 4 提现
  1102. * @return mixed
  1103. */
  1104. public function spread_count(int $uid, $type)
  1105. {
  1106. /** @var UserServices $userService */
  1107. $userService = app()->make(UserServices::class);
  1108. if (!$userService->getUserInfo($uid)) {
  1109. throw new ValidateException('数据不存在');
  1110. }
  1111. $count = 0;
  1112. if ($type == 3) {
  1113. $count1 = $this->getRecordCount($uid, 'now_money', ['brokerage', 'brokerage_user']);
  1114. $count2 = $this->getRecordCount($uid, 'now_money', ['brokerage', 'brokerage_user'], '', true);
  1115. $count = $count1 - $count2;
  1116. } else if ($type == 4) {
  1117. /** @var UserExtractServices $userExtract */
  1118. $userExtract = app()->make(UserExtractServices::class);
  1119. $count = $userExtract->getUserExtract($uid);//累计提现
  1120. }
  1121. return $count ?: 0;
  1122. }
  1123. /**
  1124. * 推广订单
  1125. * @param Request $request
  1126. * @return mixed
  1127. */
  1128. public function spread_order(int $uid, array $data)
  1129. {
  1130. /** @var UserServices $userService */
  1131. $userService = app()->make(UserServices::class);
  1132. if (!$userService->getUserInfo($uid)) {
  1133. throw new ValidateException('数据不存在');
  1134. }
  1135. $result = ['list' => [], 'time' => [], 'count' => 0];
  1136. /** @var StoreOrderServices $storeOrderServices */
  1137. $storeOrderServices = app()->make(StoreOrderServices::class);
  1138. [$page, $limit] = $this->getPageValue();
  1139. $time = [];
  1140. $where = ['paid' => 1, 'type' => 1, 'spread_or_uid' => $uid, 'pid' => 0];
  1141. $list = $storeOrderServices->getlist($where, ['id,order_id,uid,add_time,spread_uid,status,spread_two_uid,one_brokerage,two_brokerage,pay_price,pid'], $page, $limit, ['split']);
  1142. $result['count'] = $storeOrderServices->count($where + ['pid' => 0]);
  1143. $time_data = [];
  1144. if ($list) {
  1145. $uids = array_unique(array_column($list, 'uid'));
  1146. $userInfos = $userService->getColumn([['uid', 'in', $uids]], 'uid,avatar,nickname', 'uid');
  1147. foreach ($list as &$item) {
  1148. $item['avatar'] = $userInfos[$item['uid']]['avatar'] ?? '';
  1149. $item['nickname'] = $userInfos[$item['uid']]['nickname'] ?? '';
  1150. $item['number'] = $item['spread_uid'] == $uid ? $item['one_brokerage'] : $item['two_brokerage'];
  1151. $item['time'] = $item['add_time'] ? date('Y-m-d H:i', $item['add_time']) : '';
  1152. $item['time_key'] = $item['add_time'] ? date('Y-m', $item['add_time']) : '';
  1153. $item['type'] = in_array($item['status'], [2, 3]) ? 'brokerage' : 'number';
  1154. foreach ($item['split'] as $key => $items) {
  1155. $item['children'][] = [
  1156. 'order_id' => $items['order_id'],
  1157. 'number' => $item['spread_uid'] == $uid ? $items['one_brokerage'] : $items['two_brokerage'],
  1158. 'type' => in_array($item['status'], [2, 3]) ? 'brokerage' : 'number',
  1159. ];
  1160. unset($item['split'][$key]);
  1161. }
  1162. }
  1163. $times = array_unique(array_column($list, 'time_key'));
  1164. $time_data = [];
  1165. $i = 0;
  1166. foreach ($times as $time) {
  1167. $time_data[$i]['time'] = $time;
  1168. $time_data[$i]['count'] = $storeOrderServices->getMonthCount($where + ['pid' => 0], $time);
  1169. $i++;
  1170. }
  1171. }
  1172. $result['list'] = $list;
  1173. $result['time'] = $time_data;
  1174. return $result;
  1175. }
  1176. /**根据查询用户充值金额
  1177. * @param array $where
  1178. * @return float|int
  1179. */
  1180. public function getRechargeMoneyByWhere(array $where, string $rechargeSumField, string $selectType, string $group = "")
  1181. {
  1182. switch ($selectType) {
  1183. case "sum" :
  1184. return $this->dao->getWhereSumField($where, $rechargeSumField);
  1185. case "group" :
  1186. return $this->dao->getGroupField($where, $rechargeSumField, $group);
  1187. }
  1188. }
  1189. }