| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364 |
- <?php
- namespace app\api\logic;
- use Exception;
- use think\Env;
- use think\Cache;
- use think\Loader;
- use app\common\model\ProductOrder;
- use app\common\model\ProductLists;
- use app\common\model\ProductTransfer;
- //自由市场
- class MarketLogic
- {
- // 添加市场寄售订单
- public static function createTransferOrder(float $price, int $productId, int $areaId, string $orderNo, int $userId, array $params)
- {
-
- //添加寄售订单
- $fee = getConfig('transfer_fee');
- $feeAmount = bcmul($price, $fee, 2) ;
- return ProductTransfer::setTransferOrder($userId, $productId, $areaId, $feeAmount, $orderNo, $params);
- }
- //取消寄售更新
- public static function cancelTransferOrder(int $orderId, int $userId, $orderInfo)
- {
- //转让
- $rows = ProductTransfer::where('order_id', $orderId)->find();
-
- //转让列表取消
- $rows->status = ProductTransfer::Stop;
- $rows->save();
- //新增记录
- return ProductOrder::setCreateOrder($orderInfo['order_id'], $orderInfo, ProductOrder::Popular, $userId, $orderInfo['from_user'], getOrderSN('R'.$orderInfo['order_id']), 0, $orderInfo->popular_price);
- }
- //判断是否锁定
- public static function setTransferLock(object $productTransfer, int $endTime, int $uid, string $transferId)
- {
- $time = time();
- $total = 0;
- $lockList = $productTransfer->whereIn('id', $transferId)->select();
- foreach ($lockList as &$item) {
- if($item->user_id == $uid) throw new Exception(__("不能锁自己的寄售单"));
- if($item->lock_uid != $uid && $item->lock_time + $endTime > $time) throw new Exception(__("茶权已被他人锁定,无法操作"));
- $total += $item->price;
- $item->lock_uid = $uid;
- $item->lock_time = $time;
- $item->save();
- }
- //余额足够
- if($total > Loader::model('LedgerWalletModel')::getWalletChaBao($uid)) throw new Exception(__("茶宝余额不足"));
- return true;
- }
- }
|