|
|
@@ -12,6 +12,7 @@ use app\common\model\ProductOrder;
|
|
|
use app\common\model\ProductsModel;
|
|
|
use app\common\model\RwaExchangeRecordModel;
|
|
|
use app\common\model\LedgerWalletModel;
|
|
|
+use app\common\model\LedgerTeacChangeModel;
|
|
|
use fast\Action;
|
|
|
use fast\Asset;
|
|
|
use think\Db;
|
|
|
@@ -30,8 +31,7 @@ class Exchange extends Api
|
|
|
$this->lan = $this->request->getLan();
|
|
|
}
|
|
|
|
|
|
- //Ledger/getWelfareRedeConfig Exchange
|
|
|
- //Ledger/submitWelfare
|
|
|
+
|
|
|
//Rwa福利兑换配置
|
|
|
public function getWelfareRedeConfig(){
|
|
|
|
|
|
@@ -186,20 +186,43 @@ class Exchange extends Api
|
|
|
|
|
|
$ids = $this->request->post('product_id/d', 0);
|
|
|
$list = $productLists::where('is_teac', 1)
|
|
|
- ->where('id', $ids)
|
|
|
+ ->where('id', $ids)->where('status', 1)
|
|
|
->field('id,teac_price,thum,'.$this->lan.'_name as name,details')
|
|
|
->find();
|
|
|
$this->success('ok', $list);
|
|
|
}
|
|
|
|
|
|
//Teac兑换购买
|
|
|
- public function getTeacOrder(ProductLists $productLists){
|
|
|
+ public function getTeacOrder(ProductLists $productLists, LedgerWalletModel $ledgerWalletModel){
|
|
|
|
|
|
- $list = $productLists::where('is_teac', 1)
|
|
|
- ->field('id,teac_price,thum,'.$this->lan.'_name as name')
|
|
|
- ->order('weigh desc')
|
|
|
- ->find();
|
|
|
- $this->success('ok', $list);
|
|
|
+ $params = $this->request->post();
|
|
|
+ $validate = \think\Loader::validate('Exchange');
|
|
|
+ if(!$validate->scene('order')->check($params)) $this->error($validate->getError());
|
|
|
+
|
|
|
+ $rows = $productLists::where('id', $params['product_id'])->where('is_teac', 1)->where('status', 1)->find();
|
|
|
+ if(empty($rows)) throw new Exception(__("产品暂未开放"));
|
|
|
+ // 启动事务
|
|
|
+ Db::startTrans();
|
|
|
+ try {
|
|
|
+
|
|
|
+ $teac = $ledgerWalletModel::getWalletTeac($this->auth->id);
|
|
|
+
|
|
|
+ $amount = bcmul($params['stock'], $rows->teac_price, 2);
|
|
|
+ if(bccomp($amount, $teac, 2) > 0) throw new Exception(__("Teac购买金额足"), 15001);
|
|
|
+
|
|
|
+ // 更新USDT和账变
|
|
|
+ $ledgerWalletModel->changeWalletAccount($this->auth->id, Asset::TEAC, -$amount, LedgerTeacChangeModel::Exchange, 0);
|
|
|
+
|
|
|
+
|
|
|
+ // 提交事务
|
|
|
+ Db::commit();
|
|
|
+ } catch (Exception $e) {
|
|
|
+ // 回滚事务
|
|
|
+ Db::rollback();
|
|
|
+ $this->error($e->getMessage(), null, $e->getCode());
|
|
|
+ }
|
|
|
+
|
|
|
+ $this->success('ok');
|
|
|
}
|
|
|
|
|
|
}
|