UserLogic.php 7.0 KB

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