'sell_serve_fee' , //出售服务费 2 => 'buy_serve_fee' , //求购服务费 ]; /** * 发布求购出售信息 */ public static function setCreateTrade(int $uid, float $price, int $stock, int $typeId, float $frozen)//:object { $rows = ProductTeac::where('user_id', $uid)->where('type_id', $typeId)->where('price', $price)->where('status', ProductTeac::Normal)->find(); $fee = config('teac_trade.'. self::$feeList[$typeId]); if($rows) { $total_price = bcmul($price, $stock, 4); $rows->fee += bcmul($total_price, $fee, 4); $rows->frozen += $frozen; $rows->stock += $stock; return $rows->save(); }else{ //添加订单信息 return ProductTeac::setUserCreateOrder($uid, $typeId, $price, $stock, $fee, $frozen); } } /** * 购买出售 * @$uid 用户人id * @$fromUid 来源订单id */ public static function setCreateSellOrder(int $uid, int $fromUid, float $chabao, int $num, float $fee) { $ledgerWalletModel = Loader::model('LedgerWalletModel'); $total_price = bcmul($chabao, $num, 4); //总价 $fee = bcmul($total_price, $fee, 4); //手续费 //扣除用户茶宝 $ledgerWalletModel->changeWalletAccount($uid, Asset::TOKEN, -$total_price, LedgerTokenChangeModel::BuySellg, $fromUid); //添加用户Teac $ledgerWalletModel->changeWalletAccount($uid, Asset::TEAC, $num, LedgerTeacChangeModel::SellBuy, $fromUid); //添加来源茶宝 $ledgerWalletModel->changeWalletAccount($fromUid, Asset::TOKEN, bcsub($total_price, $fee, 4), LedgerTokenChangeModel::BuySellg, $uid); return true; } /** * 求购出售 * @$uid 用户人id * @$fromUid 来源订单id */ public static function setCreateBuyingOrder(int $uid, int $fromUid, float $chabao, int $num, float $fee) { $ledgerWalletModel = Loader::model('LedgerWalletModel'); $total_price = bcmul($chabao, $num, 4); //总价 $fee = bcmul($total_price, $fee, 4); //手续费 //添加用户茶宝 $ledgerWalletModel->changeWalletAccount($uid, Asset::TOKEN, bcsub($total_price, $fee, 4), LedgerTokenChangeModel::BuySellg, $fromUid); //扣除用户Teac $ledgerWalletModel->changeWalletAccount($uid, Asset::TEAC, -$num, LedgerTeacChangeModel::BuySell, $fromUid); //添加Teac $ledgerWalletModel->changeWalletAccount($fromUid, Asset::TEAC, $num, LedgerTeacChangeModel::Buying, $uid); return true; } /** * 退回相应茶宝/Teac * @param $uid 用户id * @param $typeId 订单类型 * @param $stock 剩余数 * @return void */ public static function setUserReturnOrder(int $uid, int $typeId, float $stock) { if($typeId == ProductTeac::Sell) { $asset = Asset::TEAC ; $action = LedgerTeacChangeModel::SellCancel; }else{ $asset = Asset::TOKEN ; $action = LedgerTokenChangeModel::BuyCancel; } return Loader::model('LedgerWalletModel')->changeWalletAccount($uid, $asset, $stock, $action, $uid); } }