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