UserServices.php 3.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
  4. // +----------------------------------------------------------------------
  5. // | Copyright (c) 2016~2023 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\product\product\StoreProductRelationServices;
  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 StoreProductRelationServices $relation */
  64. $relation = app()->make(StoreProductRelationServices::class);
  65. $where['uid'] = $uid;
  66. $where['type'] = 'collect';
  67. [$page, $limit] = $this->getPageValue();
  68. $count = $relation->count($where);
  69. $list = $relation->getList($where, 'product_id,category', $page, $limit);
  70. foreach ($list as $k => $product) {
  71. if ($product['product'] && isset($product['product']['id'])) {
  72. $list[$k]['pid'] = $product['product']['id'] ?? 0;
  73. $list[$k]['store_name'] = $product['product']['store_name'] ?? 0;
  74. $list[$k]['price'] = $product['product']['price'] ?? 0;
  75. $list[$k]['ot_price'] = $product['product']['ot_price'] ?? 0;
  76. $list[$k]['sales'] = $product['product']['sales'] ?? 0;
  77. $list[$k]['image'] = get_thumb_water($product['product']['image'] ?? 0, 'mid');
  78. $list[$k]['is_del'] = $product['product']['is_del'] ?? 0;
  79. $list[$k]['is_show'] = $product['product']['is_show'] ?? 0;
  80. $list[$k]['is_fail'] = $product['product']['is_del'] && $product['product']['is_show'];
  81. } else {
  82. unset($list[$k]);
  83. }
  84. }
  85. return compact('list', 'count');
  86. }
  87. }