|
|
@@ -6,7 +6,7 @@ namespace app\api\controller;
|
|
|
use app\common\controller\Api;
|
|
|
use app\api\logic\TeacLogin;
|
|
|
use app\common\model\ParametersModel;
|
|
|
-use app\common\model\ProductOrder;
|
|
|
+use app\common\model\LedgerTokenChangeModel;
|
|
|
use app\common\model\UserModel;
|
|
|
use app\common\model\LedgerWalletModel;
|
|
|
use fast\Action;
|
|
|
@@ -54,24 +54,26 @@ class Teac extends Api
|
|
|
/*
|
|
|
* 发布求购
|
|
|
*/
|
|
|
- public function setBuying(TeacLogin $teacLogin)
|
|
|
+ public function setBuying(LedgerWalletModel $ledgerWalletModel, TeacLogin $teacLogin)
|
|
|
{
|
|
|
$params = $this->request->post();
|
|
|
$validate = \think\Loader::validate('Teac');
|
|
|
if(!$validate->scene('buying')->check($params)) $this->error($validate->getError());
|
|
|
|
|
|
if(config('teac_trade.sell_min_price') > $params['price']) $this->error('价格不能低于'.config('teac_trade.sell_min_price'));
|
|
|
+
|
|
|
+ $chabao = $ledgerWalletModel->getWalletChaBao($this->auth->id);
|
|
|
+ if($chabao < bcmul($params['price'], $params['stock'], 2)) $this->error('您的钱包茶宝余额不足');
|
|
|
|
|
|
Db::startTrans();
|
|
|
try{
|
|
|
|
|
|
//新增求购信息
|
|
|
- $order_info = $teacLogin::setCreateOrder($this->auth->id, $params['price'], $params['user_id'], $params['from_user'], $params['order_no'], $params['fees'], $params['price']);
|
|
|
+ $order_price = $teacLogin::setCreateOrder($this->auth->id, $params['price'], $params['stock']);
|
|
|
+
|
|
|
+ //冻结资产
|
|
|
+ $ledgerWalletModel->changeWalletAccount($this->auth->id, Asset::TOKEN, -$order_price, LedgerTokenChangeModel::Buying, $this->auth->id);
|
|
|
|
|
|
- $order_id = (new ProductOrder)->insertGetId($order_info);
|
|
|
- if(!$order_id){
|
|
|
- throw new Exception('订单创建失败');
|
|
|
- }
|
|
|
Db::commit();
|
|
|
$this->success('订单创建成功');
|
|
|
}catch(Exception $e){
|
|
|
@@ -82,17 +84,32 @@ class Teac extends Api
|
|
|
}
|
|
|
|
|
|
|
|
|
-
|
|
|
+ //发布出售
|
|
|
+ public function setSell()
|
|
|
+ {
|
|
|
+ $validate = \think\Loader::validate('Teac');
|
|
|
+ if(!$validate->scene('sell')->check($params)) $this->error($validate->getError());
|
|
|
+
|
|
|
+ if(config('teac_trade.sell_min_price') > $params['price']) $this->error('价格不能低于'.config('teac_trade.sell_min_price'));
|
|
|
|
|
|
+ $chabao = $ledgerWalletModel->getWalletChaBao($this->auth->id);
|
|
|
+ if($chabao < bcmul($params['price'], $params['stock'], 2)) $this->error('您的钱包茶宝余额不足');
|
|
|
+
|
|
|
+ Db::startTrans();
|
|
|
+ try{
|
|
|
+
|
|
|
+ //新增求购信息
|
|
|
+ $order_price = $teacLogin::setCreateOrder($this->auth->id, $params['price'], $params['stock']);
|
|
|
|
|
|
- //
|
|
|
- public function updaetWallet()
|
|
|
- {
|
|
|
- $daoru_list = Db::table('ledger_wallet_1')
|
|
|
- ->whereNotNull('address')
|
|
|
- ->select();
|
|
|
- $i = 0;
|
|
|
- dump($i);
|
|
|
+ //冻结资产
|
|
|
+ $ledgerWalletModel->changeWalletAccount($this->auth->id, Asset::TOKEN, -$order_price, LedgerTokenChangeModel::Buying, $this->auth->id);
|
|
|
+
|
|
|
+ Db::commit();
|
|
|
+ $this->success('订单创建成功');
|
|
|
+ }catch(Exception $e){
|
|
|
+ Db::rollback();
|
|
|
+ $this->error($e->getMessage());
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
|