UserBillServices.php 44 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244
  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. }