UserLogic.php 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165
  1. <?php
  2. namespace app\api\logic;
  3. use Exception;
  4. use think\Env;
  5. use think\Cache;
  6. use think\Loader ;
  7. use fast\Asset;
  8. use app\common\model\ProductOrder;
  9. use app\common\model\LedgerTeacChangeModel;
  10. use app\common\model\ProductPopular;
  11. use app\common\model\ProductTransfer;
  12. //用户逻辑
  13. class UserLogic
  14. {
  15. //获取用户分享余额记录信息
  16. public static function getUserBalanceLog(object $ledgerTokenChangeModel, int $uid, int $pageSize): array
  17. {
  18. //总收益
  19. $list['total'] = $ledgerTokenChangeModel::where('user_id', $uid)->where('action', $ledgerTokenChangeModel::Share)->sum("change_amount");
  20. $list['data'] = $ledgerTokenChangeModel::where('user_id', $uid)
  21. ->where('action', $ledgerTokenChangeModel::Share)
  22. ->order('id desc')
  23. ->paginate($pageSize);
  24. $list['statusList'] = $ledgerTokenChangeModel::getStatusList();
  25. return $list;
  26. }
  27. //获取用户发行Nft列表
  28. public static function getUserNftList(object $productOrder, object $productTransfer, string $lan, int $uid, int $pageSize, array $where): object
  29. {
  30. $list = $productOrder->alias('a')
  31. ->join("product_list b", "b.id = a.product_id", "left")
  32. ->join("products c", "c.id = b.type_id", "left")
  33. ->join("product_transfer z", "a.id = z.order_id AND a.status=2", "left") //转让
  34. ->join("product_area d", "d.id = a.area_id", "left") //地区
  35. ->field('a.id as order_id,a.product_id,'.'b.'.$lan.'_name as name,b.thum as img_url,a.price,a.status,a.order_no,a.type_id,c.'.$lan.'_title as title,
  36. z.price as transfer_price,d.address,b.min_transfer_fee,b.max_transfer_fee,b.gift_fee,b.freight,b.is_transfer,b.is_gift,b.is_freight,b.is_storage,b.is_buying')
  37. ->where('a.user_id', $uid)
  38. ->where($where)
  39. ->order('a.id DESC')
  40. ->paginate($pageSize);
  41. //地板价格
  42. foreach ($list as &$item) {
  43. if($item->price == 0) $item->floor_price = $productTransfer::getTransferMinPrice($item->product_id);
  44. }
  45. return $list;
  46. }
  47. //获取自己发行的Nft列表
  48. public static function getMyUserNftList(object $productOrder, int $uid, string $lan, array $where, int $pageSize): object
  49. {
  50. return $productOrder->alias('a')
  51. ->join("product_list b", "b.id = a.product_id", "left")
  52. ->field('a.id as order_id,a.product_id,'.'b.'.$lan.'_name as name,b.thum as img_url,a.price,a.status,a.type_id, count(a.num) as hold_num')
  53. ->where('a.user_id', $uid)
  54. ->group('a.product_id')
  55. ->where($where)
  56. ->order('a.id DESC')
  57. ->paginate($pageSize);
  58. }
  59. //获取我的茶友好列表
  60. public static function getUserChaList(object $userModel, int $uid, int $pageSize): array
  61. {
  62. // 总推荐数
  63. $list['total'] = $userModel::where('parent_id', $uid)->count();
  64. // 直推列表
  65. $list['data'] = $userModel::where('parent_id', $uid)
  66. ->field("address,address_level,create_time,nickname,direct_super,REPLACE(phone, SUBSTRING(phone, 4, 4), '****') as phone")
  67. ->order('id desc')
  68. ->paginate($pageSize);
  69. return $list;
  70. }
  71. public static function getUserOperateLog(object $productOrder, string $lan, int $uid, int $pageSize, array $where): array
  72. {
  73. $list['data'] = $productOrder->alias('a')
  74. ->join("product_list b", "b.id = a.product_id", "left")
  75. ->join("product_area d", "d.id = a.area_id", "left") //地区
  76. ->field('a.id as order_id,a.product_id,'.'b.'.$lan.'_name as name,b.thum as img_url,a.price,a.status,a.type_id,a.create_time,d.province,d.city,d.area,d.county')
  77. ->where('a.user_id', $uid)
  78. ->where($where)
  79. ->order('a.id DESC')
  80. ->paginate($pageSize);
  81. foreach ($list['data'] as &$item) {
  82. $item->address_id = '';
  83. if($item->province > 0) $item->address_id .= $item->province.'-';
  84. if($item->city > 0) $item->address_id .= $item->city.'-';
  85. if($item->area > 0) $item->address_id .= $item->area.'-';
  86. if($item->county > 0) $item->address_id .= $item->county.'-';
  87. $item->address_id = rtrim($item->address_id, '-');
  88. }
  89. $list['statusList'] = $productOrder::getStatusAll();
  90. return $list;
  91. }
  92. /**
  93. * Nft搜索条件
  94. * @return array
  95. */
  96. public static function getNftWhere(int $typeId, int $productId , object $productOrder): array
  97. {
  98. $where = [];
  99. switch ($typeId) {
  100. case 0:
  101. $where['a.status'] = ['=' , $productOrder::Paid];
  102. break;
  103. case 1:
  104. $where = ['a.type_id' => $productOrder::Transfer, 'a.status' => $productOrder::Transferred];
  105. break;
  106. case 2:
  107. $where = ['a.type_id' => $productOrder::Transfer, 'a.status' => $productOrder::Closure];
  108. break;
  109. case 3:
  110. $where = ['a.type_id' => $productOrder::Popular, 'a.status' => $productOrder::Closure];
  111. break;
  112. case 4:
  113. $where = ['a.type_id' => $productOrder::Giveaway, 'a.status' => $productOrder::Closure];
  114. break;
  115. case 5:
  116. $where = ['a.type_id' => $productOrder::Popular, 'a.status' => $productOrder::Shipped];
  117. break;
  118. }
  119. if($productId > 0) $where['a.product_id'] = ['=' , $productId];
  120. return $where;
  121. }
  122. /**
  123. * 操作记录搜索条件
  124. * @return array
  125. */
  126. public static function getOperateWhere(int $typeId, int $status, string $areaId)
  127. {
  128. $where = [];
  129. //类型
  130. if($typeId > 0 || $status > 0) $where = ['a.type_id' => $typeId, 'a.status' => $status];
  131. //编号Id
  132. if(!empty($areaId)){
  133. $arr = explode('-', $areaId);
  134. if(count($arr) > 0) {
  135. if(isset($arr[0])) $where['d.province'] = ['=', $arr[0]];
  136. if(isset($arr[1])) $where['d.city'] = ['=', $arr[1]];
  137. if(isset($arr[2])) $where['d.area'] = ['=', $arr[2]];
  138. if(isset($arr[3])) $where['d.county'] = ['=', $arr[3]];
  139. }
  140. }
  141. return $where;
  142. }
  143. }