| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125 |
- <?php
- namespace app\api\logic;
- use app\common\model\ProductTeac;
- use fast\Http;
- use think\Loader;
- use Exception;
- use finfo;
- use think\Cache;
- use fast\Asset;
- use think\Log;
- use think\Lang;
- use app\common\model\LedgerTeacChangeModel;
- use app\common\model\LedgerTokenChangeModel;
- /**
- * Teac交易
- */
- class TeacLogin
- {
- protected static $feeList = [
- 1 => '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 $team_level_id, 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);
- //添加分润等级
- if($team_level_id > 0) CommonLogic::setTeamLevelIncome($uid, $fee, $team_level_id, Asset::TOKEN, LedgerTokenChangeModel::TeamLevel);
- 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);
- }
-
- }
|