|
@@ -27,12 +27,10 @@ class Teac extends Api
|
|
|
{
|
|
{
|
|
|
$type_id = $this->request->post('type_id/d', 0);
|
|
$type_id = $this->request->post('type_id/d', 0);
|
|
|
if(!in_array($type_id, [ProductTeac::Buying, ProductTeac::Sell])) $this->error('类型错误');
|
|
if(!in_array($type_id, [ProductTeac::Buying, ProductTeac::Sell])) $this->error('类型错误');
|
|
|
-
|
|
|
|
|
$list = $productTeac->with('users')
|
|
$list = $productTeac->with('users')
|
|
|
->where('product_teac.status', ProductTeac::Normal)->where('type_id', $type_id)
|
|
->where('product_teac.status', ProductTeac::Normal)->where('type_id', $type_id)
|
|
|
->order('create_time desc')
|
|
->order('create_time desc')
|
|
|
->paginate($this->pageSize);
|
|
->paginate($this->pageSize);
|
|
|
-
|
|
|
|
|
$this->success('ok', $list);
|
|
$this->success('ok', $list);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -142,10 +140,8 @@ class Teac extends Api
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
- /**
|
|
|
|
|
- * 求购出售
|
|
|
|
|
- */
|
|
|
|
|
- public function getBuyOrder(ProductTeac $productTeac, LedgerWalletModel $ledgerWalletModel, TeacLogin $teacLogin, UserTeac $userTeac)
|
|
|
|
|
|
|
+ // 求购出售
|
|
|
|
|
+ public function setBuyOrder(ProductTeac $productTeac, LedgerWalletModel $ledgerWalletModel, TeacLogin $teacLogin, UserTeac $userTeac)
|
|
|
{
|
|
{
|
|
|
$params = $this->request->post();
|
|
$params = $this->request->post();
|
|
|
$validate = \think\Loader::validate('Teac');
|
|
$validate = \think\Loader::validate('Teac');
|
|
@@ -154,10 +150,9 @@ class Teac extends Api
|
|
|
if(empty($row) || $row['status'] != ProductTeac::Normal) $this->error('订单不存在');
|
|
if(empty($row) || $row['status'] != ProductTeac::Normal) $this->error('订单不存在');
|
|
|
if($this->auth->id == $row['user_id']) $this->error('不能购买自己的订单');
|
|
if($this->auth->id == $row['user_id']) $this->error('不能购买自己的订单');
|
|
|
if($params['num'] > $row['stock'] - $row['num']) $this->error('库存不足');
|
|
if($params['num'] > $row['stock'] - $row['num']) $this->error('库存不足');
|
|
|
- $chabao = $ledgerWalletModel->getWalletChaBao($this->auth->id);
|
|
|
|
|
|
|
+ $chabao = $ledgerWalletModel->getWalletChaBao(1044);
|
|
|
$tatal = bcmul($row['price'], $params['num'], 2);
|
|
$tatal = bcmul($row['price'], $params['num'], 2);
|
|
|
if($chabao < $tatal) $this->error('您的钱包茶宝余额不足');
|
|
if($chabao < $tatal) $this->error('您的钱包茶宝余额不足');
|
|
|
-
|
|
|
|
|
// 启动事务
|
|
// 启动事务
|
|
|
Db::startTrans();
|
|
Db::startTrans();
|
|
|
try {
|
|
try {
|
|
@@ -169,7 +164,7 @@ class Teac extends Api
|
|
|
|
|
|
|
|
//添加扣除相应茶宝Teac
|
|
//添加扣除相应茶宝Teac
|
|
|
$teacLogin::setCreateBuyingOrder($this->auth->id, $row['user_id'], $row['price'], $params['num'], $fee);
|
|
$teacLogin::setCreateBuyingOrder($this->auth->id, $row['user_id'], $row['price'], $params['num'], $fee);
|
|
|
-
|
|
|
|
|
|
|
+
|
|
|
//修改状态
|
|
//修改状态
|
|
|
if($row->stock - $row->num == $params['num']) $row->status = ProductTeac::Complete;
|
|
if($row->stock - $row->num == $params['num']) $row->status = ProductTeac::Complete;
|
|
|
$row->frozen -= $chabao;
|
|
$row->frozen -= $chabao;
|
|
@@ -186,6 +181,50 @@ class Teac extends Api
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
+ // 我的交易列表
|
|
|
|
|
+ public function getUserTeacList(ProductTeac $productTeac)
|
|
|
|
|
+ {
|
|
|
|
|
+ $type_id = $this->request->post('type_id/d', 0);
|
|
|
|
|
+ if(!in_array($type_id, [ProductTeac::Buying, ProductTeac::Sell])) $this->error('类型错误');
|
|
|
|
|
+ $list = $productTeac::where('user_id', $this->auth->id)
|
|
|
|
|
+ ->where('status', ProductTeac::Normal)->where('type_id', $type_id)
|
|
|
|
|
+ ->order('create_time desc')
|
|
|
|
|
+ ->paginate($this->pageSize);
|
|
|
|
|
+ $this->success('ok', $list);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ //取消交易
|
|
|
|
|
+ public function cancelTrade(ProductTeac $productTeac, UserTeac $userTeac)
|
|
|
|
|
+ {
|
|
|
|
|
+ $id = $this->request->post('id/d', 0);
|
|
|
|
|
+ $row = $productTeac::where(['id' => $id, 'user_id' => $this->auth->id])->find();
|
|
|
|
|
+ if(empty($row)) $this->error('订单不存在');
|
|
|
|
|
+ if($row['status'] != ProductTeac::Normal) $this->error('订单已完成');
|
|
|
|
|
+ Db::startTrans();
|
|
|
|
|
+ try {
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+ // 出售购买
|
|
|
|
|
+ $userTeac::setUserCreateOrder($this->auth->id, $row['id'], ProductTeac::Buying, $params['num'], $row['price'], $fee);
|
|
|
|
|
+
|
|
|
|
|
+ //添加扣除相应茶宝Teac
|
|
|
|
|
+ $teacLogin::setCreateBuyingOrder($this->auth->id, $row['user_id'], $row['price'], $params['num'], $fee);
|
|
|
|
|
+
|
|
|
|
|
+ //修改状态
|
|
|
|
|
+ if($row->stock - $row->num == $params['num']) $row->status = ProductTeac::Complete;
|
|
|
|
|
+
|
|
|
|
|
+ $row->status = ProductTeac::Complete;
|
|
|
|
|
+ $row->save();
|
|
|
|
|
+ // 提交事务
|
|
|
|
|
+ Db::commit();
|
|
|
|
|
+ } catch (Exception $e) {
|
|
|
|
|
+ // 回滚事务
|
|
|
|
|
+ Db::rollback();
|
|
|
|
|
+ return $e->getMessage();
|
|
|
|
|
+ }
|
|
|
|
|
+ $this->success('ok');
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
/**
|
|
/**
|
|
|
* 获取配置
|
|
* 获取配置
|
|
|
*/
|
|
*/
|