MarketLogic.php 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  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. $rows->save();
  29. //新增记录
  30. return ProductOrder::setCreateOrder($orderInfo['order_id'], $orderInfo, ProductOrder::Popular, $userId, $orderInfo['from_user'], getOrderSN('R'.$orderInfo['order_id']), 0, $orderInfo->popular_price);
  31. }
  32. //判断是否锁定
  33. public static function setTransferLock(object $productTransfer, int $endTime, int $uid, string $transferId)
  34. {
  35. $time = time();
  36. $lockList = $productTransfer->whereIn('id', $transferId)->select();
  37. foreach ($lockList as &$item) {
  38. if($item->user_id == $uid) throw new Exception(__("不能锁自己的寄售单"));
  39. if($item->lock_uid != $uid && $item->lock_time + $endTime > $time) throw new Exception(__("茶权已被他人锁定,无法操作"));
  40. $item->lock_uid = $uid;
  41. $item->lock_time = $time;
  42. $item->save();
  43. }
  44. return true;
  45. }
  46. }