MarketLogic.php 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. <?php
  2. namespace app\api\logic;
  3. use Exception;
  4. use think\Env;
  5. use think\Cache;
  6. use think\Loader;
  7. use app\common\model\ProductOrder;
  8. use app\common\model\ProductLists;
  9. use app\common\model\ProductTransfer;
  10. //自由市场
  11. class MarketLogic
  12. {
  13. // 添加市场寄售订单
  14. public static function createTransferOrder(float $price, int $productId, int $areaId, string $orderNo, int $userId, array $params)
  15. {
  16. //添加寄售订单
  17. $fee = getConfig('transfer_fee');
  18. $feeAmount = bcmul($price, $fee, 2) ;
  19. return ProductTransfer::setTransferOrder($userId, $productId, $areaId, $feeAmount, $orderNo, $params);
  20. }
  21. //取消寄售更新
  22. public static function cancelTransferOrder(int $orderId, int $userId, $orderInfo)
  23. {
  24. //转让
  25. $rows = ProductTransfer::where('order_id', $orderId)->find();
  26. //转让列表取消
  27. $rows->status = ProductTransfer::Stop;
  28. return $rows->save();
  29. }
  30. //判断是否锁定
  31. public static function setTransferLock(object $productTransfer, int $endTime, int $uid, string $transferId)
  32. {
  33. $time = time();
  34. $total = 0;
  35. $lockList = $productTransfer->whereIn('id', $transferId)->select();
  36. foreach ($lockList as &$item) {
  37. if($item->user_id == $uid) throw new Exception(__("不能锁自己的寄售单"));
  38. if($item->lock_uid != $uid && $item->lock_time + $endTime > $time) throw new Exception(__("茶权已被他人锁定,无法操作"));
  39. $total += $item->price;
  40. $item->lock_uid = $uid;
  41. $item->lock_time = $time;
  42. $item->save();
  43. }
  44. //余额足够
  45. if($total > Loader::model('LedgerWalletModel')::getWalletChaBao($uid)) throw new Exception(__("茶宝余额不足"));
  46. return true;
  47. }
  48. }