| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176 |
- <?php
- namespace app\api\controller;
- use app\common\controller\Api;
- use app\common\model\AnnouncementModel;
- use app\common\model\UserCollect;
- use app\common\model\ProductBuying;
- use app\common\model\ParametersModel;
- use app\common\model\ProductOrder;
- use app\common\model\UserModel;
- use app\common\model\LedgerWalletModel;
- use app\common\model\ProductTransfer;
- use app\api\logic\MarketLogic;
- use fast\Action;
- use fast\Asset;
- use fast\Http;
- use fast\RechargeStatus;
- use think\Db;
- use think\Exception;
- class Market extends Api
- {
- const LockTime = 180; // 锁定时间 3分钟
- //用户收藏
- public function collect(UserCollect $userCollect)
- {
- $params = $this->request->post();
- $validate = \think\Loader::validate('Market');
- if(!$validate->scene('collect')->check($params)) $this->error($validate->getError());
- $userCollect::setUserCollect($this->auth->id, $params['market_id']);
- $this->success("ok");
- }
- /*
- * 相关公告
- */
- public function announcement(AnnouncementModel $announcementModel)
- {
- $params = $this->request->post();
- $validate = \think\Loader::validate('Market');
- if(!$validate->scene('announcement')->check($params)) $this->error($validate->getError());
- $announcement = $announcementModel
- ->where('find_in_set(:id,product_id)',['id'=>$params['product_id']])
- ->where('status', $announcementModel::Normal)
- ->where('to_lang', $this->request->getLan())
- ->order('id desc')
- ->paginate($this->pageSize);
- $this->success('ok', $announcement);
- }
- //获取产品最大求购价格
- public function getBuyingMaxPrice(ProductBuying $productBuying)
- {
- $params = $this->request->post();
- $validate = \think\Loader::validate('Market');
- if(!$validate->scene('announcement')->check($params)) $this->error($validate->getError());
- $this->success('ok', $productBuying::getProductBuyingMaxPrice($params['product_id']));
- }
-
- //锁定寄售
- public function setTransferLock(ProductTransfer $productTransfer, MarketLogic $marketLogic)
- {
- $params = $this->request->post();
- $validate = \think\Loader::validate('Market');
- if(!$validate->scene('transferlock')->check($params)) $this->error($validate->getError());
-
- Db::startTrans();
- try {
- $marketLogic->setTransferLock($productTransfer, time() + self::LockTime, $params);
-
- // 提交事务
- Db::commit();
- } catch (Exception $e) {
- // 回滚事务
- Db::rollback();
- $this->error($e->getMessage(), null, $e->getCode());
- }
- $this->success('ok');
- }
-
- //求购
- public function buying()
- {
- $params = $this->request->post();
- $validate = \think\Loader::validate('Market');
- if(!$validate->scene('announcement')->check($params)) $this->error($validate->getError());
- }
- //求购列表
- public function buyingList()
- {
-
-
- }
- /**
- * 手段向某会员报单算力
- * @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();
- }
- }
-
- }
|