MarketLogic.php 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  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. echo 11;die;
  20. dump($orderNo);die;
  21. return ProductTransfer::setTransferOrder($userId, $productId, $areaId, $feeAmount, $orderNo, $params);
  22. }
  23. //取消寄售更新
  24. public static function cancelTransferOrder(int $orderId, int $userId, $orderInfo)
  25. {
  26. //转让
  27. $rows = ProductTransfer::where('order_id', $orderId)->find();
  28. //转让列表取消
  29. $rows->status = ProductTransfer::Stop;
  30. return $rows->save();
  31. }
  32. //判断是否锁定
  33. public static function setTransferLock(object $productTransfer, int $endTime, int $uid, string $transferId)
  34. {
  35. $time = time();
  36. $total = 0;
  37. $lockList = $productTransfer->whereIn('id', $transferId)->select();
  38. foreach ($lockList as &$item) {
  39. if($item->user_id == $uid) throw new Exception(__("不能锁自己的寄售单"));
  40. if($item->lock_uid != $uid && $item->lock_time + $endTime > $time) throw new Exception(__("茶权已被他人锁定,无法操作"));
  41. $total += $item->price;
  42. $item->lock_uid = $uid;
  43. $item->lock_time = $time;
  44. $item->save();
  45. }
  46. //余额足够
  47. if($total > Loader::model('LedgerWalletModel')::getWalletChaBao($uid)) throw new Exception(__("茶宝余额不足"));
  48. return true;
  49. }
  50. }