UserServices.php 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  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\pc;
  13. use app\services\BaseServices;
  14. use app\services\user\UserRelationServices;
  15. use app\services\user\UserBillServices;
  16. class UserServices extends BaseServices
  17. {
  18. /**
  19. * PC端用户记录明细
  20. * @param int $uid
  21. * @param int $type
  22. * @return array
  23. */
  24. public function getBalanceRecord(int $uid, int $type)
  25. {
  26. /** @var UserBillServices $userBill */
  27. $userBill = app()->make(UserBillServices::class);
  28. $where = [];
  29. $where['uid'] = $uid;
  30. $where['category'] = 'now_money';
  31. switch ((int)$type) {
  32. case 0:
  33. $where['type'] = ['recharge', 'pay_money', 'system_add', 'pay_product_refund', 'system_sub'];
  34. break;
  35. case 1:
  36. $where['type'] = ['pay_money'];
  37. break;
  38. case 2:
  39. $where['type'] = ['recharge', 'system_add'];
  40. break;
  41. case 3:
  42. $where['type'] = ['brokerage', 'brokerage_user'];
  43. break;
  44. case 4:
  45. $where['type'] = ['extract'];
  46. break;
  47. }
  48. [$page, $limit] = $this->getPageValue();
  49. $list = $userBill->getBalanceRecord($where, $page, $limit);
  50. foreach ($list as &$item) {
  51. $item['time'] = date('Y-m', strtotime($item['add_time']));
  52. }
  53. $count = $userBill->count($where);
  54. return ['list' => $list, 'count' => $count];
  55. }
  56. /**
  57. * 获取收藏商品
  58. * @param int $uid
  59. * @return array
  60. */
  61. public function getCollectList(int $uid)
  62. {
  63. /** @var UserRelationServices $relation */
  64. $relation = app()->make(UserRelationServices::class);
  65. $where['uid'] = $uid;
  66. $where['type'] = 'collect';
  67. $where['category'] = 'product';
  68. [$page, $limit] = $this->getPageValue();
  69. $count = $relation->count($where);
  70. $list = $relation->getList($where, 'relation_id,category', $page, $limit);
  71. foreach ($list as $k => $product) {
  72. if ($product['product'] && isset($product['product']['id'])) {
  73. $list[$k]['pid'] = $product['product']['id'] ?? 0;
  74. $list[$k]['store_name'] = $product['product']['store_name'] ?? 0;
  75. $list[$k]['price'] = $product['product']['price'] ?? 0;
  76. $list[$k]['ot_price'] = $product['product']['ot_price'] ?? 0;
  77. $list[$k]['sales'] = $product['product']['sales'] ?? 0;
  78. $list[$k]['image'] = get_thumb_water($product['product']['image'] ?? 0);
  79. $list[$k]['is_del'] = $product['product']['is_del'] ?? 0;
  80. $list[$k]['is_show'] = $product['product']['is_show'] ?? 0;
  81. $list[$k]['is_fail'] = $product['product']['is_del'] && $product['product']['is_show'];
  82. } else {
  83. unset($list[$k]);
  84. }
  85. }
  86. return compact('list', 'count');
  87. }
  88. }