lan = $this->request->getLan(); } //质押列表 public function list(ProductPledges $productPledges, PledgeLogic $pledgeLogic) { $type_id = $this->request->param('type_id', 0, 'intval'); if(empty($type_id)) $this->error(__("参数有误,无可用产品")); $list = $productPledges ->where('status', $productPledges::Normal) ->where('to_lang', $this->lan)->where('type_id', $type_id) ->field('id,title,day_num,income_reta,product_id,type_id') ->order('weigh desc') ->paginate($this->pageSize); $list = $pledgeLogic::getByProductIdList($list, $this->lan); $this->success('', $list); } /* * 质押详情 */ public function detail(ProductPledges $productPledges, ProductLists $productList) { $id = $this->request->param('id', 0, 'intval'); if(empty($id)) $this->error(__("参数有误,无可用产品")); //质押详情 $pledges = $productPledges::get($id); if (!empty($pledges)) { $pledges->product_list = $productList::getBySynthesisProduct($pledges->product_id, $pledges->type_id, $this->lan); } $this->success('', $pledges); } /* * 持有商品列表 */ public function holdProductList(PledgeLogic $pledgeLogic) { $product_id = $this->request->param('product_id', 0, 'intval'); if(empty($product_id)) $this->error(__("参数有误,无可用产品")); $pledges = $pledgeLogic::getHoldProductList($this->auth->id, $product_id); $this->success('', $pledges); } /* * 质押存储 */ public function create(ProductPledges $productPledges, PledgeLogic $pledgeLogic) { $pledge_id = $this->request->post('pledge_id', 0, 'intval'); $order_no = $this->request->post('order_no/a', ''); if(empty($pledge_id) || empty($order_no)) $this->error(__("参数有误,无可用产品")); $pledge = $productPledges::get($pledge_id); if($pledge->type_id == $productPledges::Combin && count(explode(',', $pledge->product_id)) != count($order_no)) $this->error(__("质押商品数量与订单数量不匹配")); if (empty($pledge)) $this->error(__("质抵活动不存在")); if (empty($pledge->status) )$this->error(__("质抵活动已结束")); Db::startTrans(); try { // 质抵押订单 $pledgeLogic::setPledgeOrder($pledge, $order_no, $this->auth->id); // 提交事务 Db::commit(); } catch (Exception $e) { // 回滚事务 Db::rollback(); $this->error($e->getMessage(), null, $e->getCode()); } $this->success('ok'); } /* * 我的茶矿 */ public function teamine(PledgeLogic $pledgeLogic) { try { // 质抵押订单 $res = $pledgeLogic::getPledgeOrderList($this->auth->id); } catch (Exception $e) { $this->error($e->getMessage(), null, $e->getCode()); } $this->success('ok', $res); } /* * 收取茶矿 */ public function collect(PledgeLogic $pledgeLogic) { if(cache('collect_'.$this->auth->id)) $this->error(__("正在挖矿中,请稍后再试")); Db::startTrans(); try { // 质抵押订单 $res = $pledgeLogic::getPledgeCollect($this->auth->id); //请求限制 cache('collect_'.$this->auth->id, time(), 300); // 提交事务 Db::commit(); } catch (Exception $e) { // 回滚事务 Db::rollback(); $this->error($e->getMessage(), null, $e->getCode()); } $this->success('ok', $res); } /* * 解除质押 */ public function remove(PledgeLogic $pledgeLogic) { $pledge_id = $this->request->post('pledge_id', 0, 'intval'); if(empty($pledge_id)) $this->error(__("参数有误,无可用产品")); Db::startTrans(); try { // 质抵押订单 $res = $pledgeLogic::setPledgeRemove($pledge_id, $this->auth->id); // 提交事务 Db::commit(); } catch (Exception $e) { // 回滚事务 Db::rollback(); $this->error($e->getMessage(), null, $e->getCode()); } $this->success('ok', $res); } }