fetchSql(false) ->field('u.*,p.distance') ->alias('u') ->join('user_path p', 'u.id = p.user_id') //->where('p.parent_id', 100098) ->where('p.parent_id', 100115) ->select(); halt($i); } /* * 求购列表 */ public function getBuyingList() { $params = $this->request->post(); $validate = \think\Loader::validate('Teac'); if(!$validate->scene('buying')->check($params)) $this->error($validate->getError()); halt(11); } /* * 发布求购 */ 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_price = $teacLogin::setCreateOrder($this->auth->id, $params['price'], $params['stock']); //冻结资产 $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()); } } //发布出售 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']); //冻结资产 $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()); } } /** * 手段向某会员报单算力 * @return void * @throws \think\db\exception\DataNotFoundException * @throws \think\db\exception\ModelNotFoundException * @throws \think\exception\DbException */ public function updateOrder() { //算力租赁订单处理 // 查询兑换比例 $usdtToPower = (new ParametersModel)->getValue('usdtToPowerRate'); $usdtToPowerFloat = floatval($usdtToPower); if (is_null($usdtToPower) || $usdtToPowerFloat <= 0) { return '获取USDT兑换算力的比例失败'; } $orderInfo = (new OfflineRechargeRecordModel()) ->where('id', 4) ->find(); if(empty($orderInfo)){ halt('订单信息不存在'); } $uid = $orderInfo['user_id']; $fee = $orderInfo['amount']; $power = bcmul($fee, $usdtToPowerFloat, 6); // 该用户兑得的算力 // 启动事务 Db::startTrans(); try { // 更新总算力和账变 (new LedgerWalletModel)->changeWalletAccount($uid, Asset::POWER, $power, Action::PowerRentalPower, $orderInfo['id']); // 更新服务器算力,不账变 (new LedgerWalletModel)->changeWalletOnly($uid, Asset::RENTAL_POWER, $power); // 更新自己(有效会员时间)和所有上级的信息(有效直推人数和团队总算力) (new UserModel())->updateForRental($uid, $power); // 发放直推USDT收益 (new LedgerWalletModel)->sendUsdtProfit($uid, $fee); // 发放直推算力收益 (new LedgerWalletModel)->sendDirectProfit($uid, $power); // 发代数收益 (new LedgerWalletModel)->sendGenerateProfit($uid, $fee); // 发放见点奖 (new LedgerWalletModel)->sendRegBonus($uid, $fee); // 更新购买(充值)记录 (new OfflineRechargeRecordModel())->updateOrderStatus($orderInfo['id'], RechargeStatus::StatusAuthSuccess, 0, $power); // 提交事务 Db::commit(); } catch (Exception $e) { // 回滚事务 Db::rollback(); return $e->getMessage(); } } /** *获取配置 */ public function getConfig() { $this->success('ok', config('teac_trade')); } }