sum('stock-num'); $holdNum = ProductOrder::where('product_id', $productId)->where('status', ProductOrder::Paid)->sum('num'); return bcadd($popularNum, $holdNum); } //获取产品流通量 public static function getProductCirculation(int $productId): int { return Loader::model('ProductOrder')::where('product_id', $productId)->whereIn('status', [ProductOrder::Paid, ProductOrder::Transferred, ProductOrder::Freeze])->count(); } //获取产品有效的订单 public static function getUserProductOrder(int $uid, int $productId,string $lan): array { return Loader::model('ProductOrder')->alias('a') ->join("product_list b", "a.product_id = b.id", "left") ->field('a.id,'.'b.'.$lan.'_name as name,b.thum as img_url,a.order_no') ->where('a.product_id', $productId) ->where('a.user_id', $uid) ->where('a.status', ProductOrder::Paid) ->order('id desc') ->select(); } //获取转让产品订单列表 public static function getProductTransferOrder(string $orderId, int $uid, int $puid)//: array { $productOrder = Loader::model('ProductOrder'); $productTransfer = Loader::model('ProductTransfer'); $userModel = Loader::model('UserModel'); $ledgerWalletModel = Loader::model('LedgerWalletModel'); $ledgerTokenChangeModel = Loader::model('LedgerTokenChangeModel'); $result = $productTransfer::whereIn('id', $orderId)->where('status', ProductTransfer::Normal)->select(); if (count($result) != count(explode(",", $orderId))) { if(empty($order_info)) throw new Exception(__("订单不存在")); } $totalAmount = 0; //总金额 $time = time(); $endTime = config('market_transfer.lock_time'); foreach ($result as $item) { if($item->user_id == $uid) throw new Exception(__("不能购买自己寄售的商品")); if($item->lock_uid != $uid && $item->lock_time + $endTime > $time) throw new Exception(__("茶权已被他人锁定,无法操作")); $totalAmount = bcadd($totalAmount, $item->price, 2); //抢购订单 $popular_order = $productOrder->where('id', $item->order_id)->find(); // 生成订单 $popularPrice = empty($popular_order->popular_price)? $item->price: $popular_order->popular_price; $productOrder::setCreateOrder($item->order_id, $item, $productOrder::Transfer, $uid, $item->user_id, $popular_order->order_no, $item->fees, $popularPrice); //扣除余额记录 $ledgerWalletModel->changeWalletAccount($uid, Asset::TOKEN, -$item->price, $ledgerTokenChangeModel::Payment, $item->user_id); //增加转让人余额 $amount = bcsub($item->price, $item->fees, 2); $ledgerWalletModel->changeWalletAccount($item->user_id, Asset::TOKEN, $amount, $ledgerTokenChangeModel::Receive, $uid); if($popular_order->popular_price > config('min_rwa_price')) { //扣除转让人Rwa有效 $userModel::updateForRwaNum($item->user_id, $userModel::getByParentId($item->user_id), 1, '-'); //增加购买Rwa有效 $userModel::updateForRwaNum($uid, $puid, 1, '+'); } //修改原订单状态 $popular_order->status=$productOrder::Closure; $popular_order->save(); //修改状态 $item->status = $productTransfer::Stop; $item->save(); } $chabao = $ledgerWalletModel::getWalletChaBao($uid); if(bccomp($totalAmount, $chabao, 2) > 0) throw new Exception(__("余额不足请前往充值"), 15001); return true; } //获取赠送产品订单数量 public static function getWaitPayOrderCount(int $uid, int $endTime): int { return Loader::model('ProductTransfer')::where('lock_uid', $uid)->where('lock_time', '>', time()-$endTime)->where('status', ProductTransfer::Normal)->count(); } //获取赠送产品订单列表 public static function getWaitPayOrderList(int $uid, int $endTime, int $page, string $lan): object { $result =Loader::model('ProductTransfer')::alias('a') ->join("product_list b", "a.product_id = b.id", "left") ->where('a.lock_uid', $uid) ->where('a.lock_time', '>', time()-$endTime) ->where('a.status', ProductTransfer::Normal) ->field('a.id,a.order_id,a.price,a.fees,a.lock_time,b.thum,b.' . $lan . '_name as name') ->order('a.id desc') ->paginate($page); return $result; } //取消赠送产品订单 public static function setCancelWaitPayOrder(int $uid, int $transfer_id): bool { return Loader::model('ProductTransfer')::where('id', $transfer_id)->where('lock_uid', $uid)->update(['lock_uid' => 0, 'lock_time' => 0]); } }