'token', 2=>'teac']; protected $order = [1=>'desc', 2=>'asc']; public function _initialize() { parent::_initialize(); $this->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(__("参数有误,无可用产品")); $title = $this->request->param('title/s', ''); $day_num = $this->request->param('day_num/d', 0); $income_reta = $this->request->param('income_reta/d', 0); $map = []; $order = 'weigh desc,id desc'; if(!empty($title)) $map['title'] = [ 'LIKE', '%'.$title.'%']; if ($day_num > 0) $order = 'day_num '.$this->order[$day_num]; if ($income_reta > 0) $order = 'income_reta '.$this->order[$income_reta]; if ($day_num > 0 && $income_reta > 0) $order = 'day_num '.$this->order[$day_num].',income_reta '.$this->order[$income_reta]; $list = $productPledges ->where('status', $productPledges::Normal) ->where('to_lang', $this->lan)->where('type_id', $type_id) ->where($map) ->field('id,title,day_num,income_reta,product_id,type_id') ->order($order) ->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); } //dump($pledges);die; $num = $pledges->type_id == $productPledges::Single? 3 : 1; //单品最大三个限制 $pledges['day_num'] = bcmul($pledges['day_num'] *$num, 30, 2); $pledges['announcement_id'] = ['zh'=>339, 'en'=>340]; //协议ID $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, LedgerWalletModel $ledgerWalletModel) { $pledge_id = $this->request->post('pledge_id', 0, 'intval'); $order_id = $this->request->post('order_id/a', ''); $pay_type = $this->request->post('pay_type/d', 1);//支付方式 1 茶宝 2 Teac if(empty($pledge_id) || empty($order_id) || in_array($pay_type, [1,2]) == false) $this->error(__("参数有误,无可用产品")); $pledge = $productPledges::get($pledge_id); $count = count($order_id);//选择商品数量 if($pledge->type_id == $productPledges::Combin && count(explode(',', $pledge->product_id)) != $count) $this->error(__("质押商品数量与订单数量不匹配")); //单品最大三个限制 if($pledge->type_id == $productPledges::Single && $count > config('pledge_single_max')) $this->error(__("单品最大三个限制")); if (empty($pledge)) $this->error(__("质抵活动不存在")); if (empty($pledge->status))$this->error(__("质抵活动已结束")); //余额判断 if(empty($pledge[$this->pay[$pay_type]])) $this->error(__("无法使用此服务费方式支付")); $user = $ledgerWalletModel::getWallet($this->auth->id); //判断余额是否足够 if($pledgeLogic::isUserBalance($user, $pay_type, $pledge[$this->pay[$pay_type]]) == false) $this->error(__("余额不足")); Db::startTrans(); try { // 质抵押订单 $res = $pledgeLogic::setPledgeOrder($pledge, $order_id, $this->auth->id, $count, $this->pay[$pay_type], $pledge[$this->pay[$pay_type]]); //组合质押 if($pledge->type_id == 2) CommonLogic::setIsUpLevel($this->auth->id, $this->auth->team_level_id); // 提交事务 Db::commit(); } catch (Exception $e) { // 回滚事务 Db::rollback(); $this->error($e->getMessage(), null, $e->getCode()); } if ($res === false) { $this->error(__("订单创建失败")); } $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'); $order_id = $this->request->post('order_id/s', ''); if(empty($pledge_id) || empty($order_id)) $this->error(__("参数有误,无可用产品")); Db::startTrans(); try { // 质抵押订单 $res = $pledgeLogic::setPledgeRemove($pledge_id, $order_id, $this->auth->id, $this->auth->team_level_id, $this->auth->address_level); // 提交事务 Db::commit(); } catch (Exception $e) { // 回滚事务 Db::rollback(); $this->error($e->getMessage(), null, $e->getCode()); } $this->success('ok', $res); } //存储续费 public function setRenew(UserPledge $userPledge, PledgeLogic $pledgeLogic, LedgerWalletModel $ledgerWalletModel) { $pledge_id = $this->request->post('pledge_id', 0, 'intval'); $pay_type = $this->request->post('pay_type/d', 1);//支付方式 1 茶宝 2 Teac if(empty($pledge_id) || in_array($pay_type, [1,2]) == false) $this->error(__("参数有误,无可用产品")); //记录 $pledge = $userPledge::alias('a')->where('a.id', $pledge_id)->join('product_pledge p', 'p.id = a.pledge_id')->field('a.*,p.token,p.teac,p.type_id,p.is_renew,p.status as p_status')->find(); if (empty($pledge)) $this->error(__("质抵活动不存在")); if ($pledge->status != $userPledge::Ongoing || empty($pledge->is_renew) || empty($pledge->p_status))$this->error(__("质抵活动已结束")); //余额判断 if($pledge[$this->pay[$pay_type]] > 0){ $user = $ledgerWalletModel::getWallet($this->auth->id); //判断余额是否足够 if($pledgeLogic::isUserBalance($user, $pay_type, $pledge[$this->pay[$pay_type]]) == false) $this->error(__("余额不足")); } Db::startTrans(); try { // 质抵押订单 $pledgeLogic::setPledgeOrderRenew($pledge, $this->auth->id, $this->pay[$pay_type]); // 提交事务 Db::commit(); } catch (Exception $e) { // 回滚事务 Db::rollback(); $this->error($e->getMessage(), null, $e->getCode()); } $this->success('ok'); } //添加用户存储产品 public function addPledgeProduct(UserPledge $userPledge, PledgeLogic $pledgeLogic, ProductPledges $productPledges) { $order_id = $this->request->post('order_id/s', ''); $pledge_id = $this->request->post('pledge_id/d', 0);//存储Id if(empty($order_id) || empty($pledge_id)) $this->error(__("参数有误,无可用产品")); $order_arr= explode(',', $order_id); $count = count($order_arr); $pledge = $userPledge::alias('a')->where('a.id', $pledge_id)->join('product_pledge p', 'p.id = a.pledge_id')->field('a.*,p.type_id,p.status as p_status')->find(); if (empty($pledge) || $pledge->status != $userPledge::Ongoing || empty($pledge->p_status) || $pledge->type_id != $productPledges::Single) $this->error(__("产品质抵活动不存在不存在")); if(($count + $pledge->num) > config('pledge_single_max')) $this->error(__("产品数量超出限制")); Db::startTrans(); try { // 质抵押订单 $pledgeLogic::setPledgeProductAdd($pledge, $this->auth->id, $count, $order_arr); // 提交事务 Db::commit(); } catch (Exception $e) { // 回滚事务 Db::rollback(); $this->error($e->getMessage(), null, $e->getCode()); } $this->success('ok'); } }