| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192 |
- <?php
- namespace app\api\controller;
- use think\Exception;
- use app\api\logic\WelfareLoginc;
- use app\common\model\UserModel;
- use app\common\controller\Api;
- use app\common\model\UserWelfare;
- use think\Db;
- use app\common\model\LedgerWalletModel;
- use app\common\model\ProductOrder;
- //空投
- class Airdrop extends Api
- {
- protected array $noNeedLogin = [''];
- protected string $lan = '';
- public function _initialize()
- {
- parent::_initialize();
- $this->lan = $this->request->getLan();
- }
- //获取领取福利信息
- public function getNewbieWeal(UserWelfare $userWelfare, ProductOrder $productOrder)
- {
- $info = $productOrder::getUserWelfare($this->auth->id, $productOrder::Newbie);
- $endTime = isset($info->create_time)? bcadd($info->create_time, 86400): 0;
- $rows = $userWelfare::getIsWelfare();
- $this->success('', ['is_super'=>$this->auth->is_super, 'end_time'=>$endTime, 'chabao'=>$rows->frozen]);
- }
- //新人福利
- public function setNewbieWeal(UserWelfare $userWelfare, ProductOrder $productOrder, UserModel $userModel)
- {
- $row = $userWelfare::getIsWelfare();
- if(empty($row->is_newbie)) $this->error(__('暂未开启'));
-
- $info = $productOrder::getUserWelfare($this->auth->id, $productOrder::Newbie);
- if(!empty($info)) $this->error(__('您已领取'));
- Db::startTrans();
- try {
- //添加Rwa茶记录
- $result = WelfareLoginc::setUserWelfareLos($this->auth->id, $row->new_product_id, $row->new_num, $this->lan, $productOrder::Newbie);
- //添加茶数量
- $userModel::updateForRwaNum($this->auth->id, $this->auth->parent_id, $row->new_num, '+');
- Db::commit();
- } catch (\Exception $e) {
- Db::rollback();
- $this->error($e->getMessage());
- }
- $this->success('', $result);
- }
- //超级福利
- public function setSuperWeal(UserWelfare $userWelfare, UserModel $userModel, ProductOrder $productOrder)
- {
- $row = $userWelfare::getIsWelfare();
- if(empty($row->is_super)) $this->error(__('暂未开启'));
- if(!empty($this->auth->is_super)) $this->error(__('您已领取'));
- $info = $productOrder::getUserWelfare($this->auth->id, $productOrder::Newbie);
- if((time()-$info->create_time) >= 86400) $this->error(__('您已过期'));
- Db::startTrans();
- try {
- //添加Rwa茶记录
- $result = WelfareLoginc::setUserWelfareLos($this->auth->id, $row->super_product_id, $row->super_num, $this->lan, $productOrder::Super);
- //添加超级福利标识/上级
- $userModel::updateUserSuper($this->auth->id, $this->auth->parent_id);
- //标识为社区长
- if($row->frozen > 0) LedgerWalletModel::sendUserSubFrozen($this->auth->id, $row->frozen, LedgerWalletModel::Super, '-');
-
- //添加茶数量
- $userModel::updateForRwaNum($this->auth->id, $this->auth->parent_id, $row->super_num, '+');
- Db::commit();
- } catch (\Exception $e) {
- Db::rollback();
- $this->error($e->getMessage());
- }
- $this->success('', $result);
- }
- }
|