|
|
@@ -7,6 +7,7 @@ use think\Env;
|
|
|
use think\Cache;
|
|
|
use think\Loader ;
|
|
|
use fast\Asset;
|
|
|
+use app\common\model\LedgerFrozenChangeModel;
|
|
|
use app\common\model\LedgerTokenChangeModel;
|
|
|
use app\common\model\ProductLists;
|
|
|
use app\common\model\ProductOrder;
|
|
|
@@ -16,8 +17,6 @@ use app\common\model\ProductPledges;
|
|
|
//质押抵扣
|
|
|
class PledgeLogic
|
|
|
{
|
|
|
-
|
|
|
-
|
|
|
//获取产品信息
|
|
|
public static function getByProductIdList(object $list, string $lan = 'zh')
|
|
|
{
|
|
|
@@ -53,18 +52,16 @@ class PledgeLogic
|
|
|
$product= self::getOrderProductList($user_id, $order_id, $count);
|
|
|
|
|
|
if(empty($product) || count($product) < $count) throw new Exception('订单不存在');
|
|
|
- $pledge_num = 1;
|
|
|
- if($pledge->type_id == ProductPledges::Single) $pledge_num = $count;
|
|
|
+ //数量
|
|
|
+ $pledge_num = ($pledge->type_id == ProductPledges::Single)? $count: 1;
|
|
|
|
|
|
//添加订单
|
|
|
Loader::model('UserPledge')::setPledgeData($user_id, $pledge->id, $pledge->product_id,
|
|
|
$product, //订单信息
|
|
|
$pledge->day_num, $pledge_num);
|
|
|
|
|
|
- //扣除支付金额
|
|
|
- $action = ($pay_type == Asset::TEAC)? LedgerTeacChangeModel::PledgeFee: LedgerTokenChangeModel::Pledge; //类型
|
|
|
- if($price >0) Loader::model('LedgerWalletModel')->changeWalletAccount($user_id, $pay_type, -$price, $action, 0);
|
|
|
-
|
|
|
+ self::setPledgeFee($user_id, $pay_type, $price);
|
|
|
+
|
|
|
//修改状态
|
|
|
return Loader::model('ProductOrder')->whereIn('id', $order_id)->setField('status', ProductOrder::Freeze);
|
|
|
}
|
|
|
@@ -142,7 +139,7 @@ class PledgeLogic
|
|
|
//修改状态
|
|
|
Loader::model('ProductOrder')::where('user_id', $user_id)->whereIn('id', $orderId)->setField('status', ProductOrder::Paid);
|
|
|
|
|
|
- //
|
|
|
+ //等级
|
|
|
if($rows->type_id == 2) CommonLogic::setIsOuLevelSave($user_id, $team_level_id, $address_level);
|
|
|
//更新领取状态
|
|
|
$rows->last_time = $time;
|
|
|
@@ -152,7 +149,6 @@ class PledgeLogic
|
|
|
|
|
|
//收取质抵押订单列表:(60*60*24)*(当前时间-最后一次收取时间)
|
|
|
public static function getPledgeCollect(int $user_id)
|
|
|
-
|
|
|
{
|
|
|
$model = Loader::model('UserPledge');
|
|
|
$time = time();
|
|
|
@@ -195,9 +191,8 @@ class PledgeLogic
|
|
|
public static function setPledgeOrderRenew(object $pledge, int $user_id, string $pay_type)
|
|
|
{
|
|
|
//扣除支付金额
|
|
|
- $action = ($pay_type == Asset::TEAC)? LedgerTeacChangeModel::PledgeFee: LedgerTokenChangeModel::Pledge; //类型
|
|
|
- if($pledge[$pay_type] > 0) Loader::model('LedgerWalletModel')->changeWalletAccount($user_id, $pay_type, -$pledge[$pay_type], $action, 0);
|
|
|
-
|
|
|
+ self::setPledgeFee($user_id, $pay_type, $pledge[$pay_type]);
|
|
|
+
|
|
|
$pledge->end_time = $pledge->end_time + config('pledge_end_time');
|
|
|
return $pledge->save();
|
|
|
}
|
|
|
@@ -219,6 +214,28 @@ class PledgeLogic
|
|
|
return $pledge->save();
|
|
|
}
|
|
|
|
|
|
+ //判断用户余额
|
|
|
+ public static function isUserBalance(object $user, int $pay_type, string $pay)
|
|
|
+ {
|
|
|
+ $result = true;
|
|
|
+ if ($pay_type == 1 && bcadd($user['token'], $user['frozen']) < $pay) $result = false;
|
|
|
+ if ($pay_type == 2 && $user['teac'] < $pay) $result = false;
|
|
|
+ return $result;
|
|
|
+ }
|
|
|
+
|
|
|
+ //扣除存储手续费
|
|
|
+ private static function setPledgeFee(int $user_id, int $pay_type, float $price)
|
|
|
+ {
|
|
|
+ if( empty($price)) return true;
|
|
|
+ //扣除支付金额
|
|
|
+ if ($pay_type == Asset::TEAC) {
|
|
|
+ Loader::model('LedgerWalletModel')->changeWalletAccount($user_id, $pay_type, -$price, LedgerTeacChangeModel::PledgeFee, 0);
|
|
|
+ }else{
|
|
|
+ Loader::model('LedgerWalletModel')->setChangeFrozen($user_id, $price, LedgerFrozenChangeModel::Pledge, LedgerTokenChangeModel::Pledge, '-');
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
|
|
|
//获取订单产品
|
|
|
private static function getOrderProductList(int $user_id, array $order_id, int $count)
|