|
|
@@ -101,13 +101,11 @@ class Market extends Api
|
|
|
*/
|
|
|
public function setBuying(LedgerWalletModel $ledgerWalletModel, ProductBuying $productBuying)
|
|
|
{
|
|
|
-
|
|
|
$params = $this->request->post();
|
|
|
$validate = \think\Loader::validate('Market');
|
|
|
if(!$validate->scene('buying')->check($params)) $this->error($validate->getError());
|
|
|
|
|
|
if($productBuying::getProductBuyingCount($this->auth->id, $params['product_id']) > config('market_buying.max_buying_num')) $this->error('您的求购次数已达上限');
|
|
|
-
|
|
|
$chabao = $ledgerWalletModel::getWalletChaBao($this->auth->id);
|
|
|
$total = bcmul($params['min_price'], $params['num'], 6); // 所需茶宝
|
|
|
if($chabao < $total) $this->error('您的茶币不足');
|
|
|
@@ -130,8 +128,39 @@ class Market extends Api
|
|
|
Db::rollback();
|
|
|
return $e->getMessage();
|
|
|
}
|
|
|
-
|
|
|
$this->success('ok');
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ //出售求购
|
|
|
+ public function sellBuying(LedgerWalletModel $ledgerWalletModel, ProductBuying $productBuying)
|
|
|
+ {
|
|
|
+ $params = $this->request->post();
|
|
|
+ $validate = \think\Loader::validate('Market');
|
|
|
+ if(!$validate->scene('sellbuying')->check($params)) $this->error($validate->getError());
|
|
|
+ $buying = $productBuying::get($params['id']);
|
|
|
+ if(empty($buying)) $this->error('订单不存在');
|
|
|
+ if($buying->user_id!= $this->auth->id) $this->error('无权操作');
|
|
|
+ if($buying->status != ProductBuying::Normal) $this->error('订单已完成');
|
|
|
+ $total = bcmul($buying->min_price, $buying->num, 6); // 所需茶宝
|
|
|
+ $chabao = $ledgerWalletModel::getWalletChaBao($this->auth->id);
|
|
|
+ if($chabao < $total) $this->error('您的茶币不足');
|
|
|
+ // 启动事务
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ //取消求购
|
|
|
+ public function cancelBuying(ProductBuying $productBuying)
|
|
|
+ {
|
|
|
+ $params = $this->request->post();
|
|
|
+ $validate = \think\Loader::validate('Market');
|
|
|
+ if(!$validate->scene('cancelbuying')->check($params)) $this->error($validate->getError());
|
|
|
+ $buying = $productBuying::get($params['id']);
|
|
|
+ if(empty($buying)) $this->error('订单不存在');
|
|
|
+ if($buying->user_id!= $this->auth->id) $this->error('无权操作');
|
|
|
+ if($buying->status != ProductBuying::Normal) $this->error('订单已完成');
|
|
|
+ $buying->status = ProductBuying::Close;
|
|
|
+ $buying->save();
|
|
|
|
|
|
}
|
|
|
|