Airdrop.php 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. <?php
  2. namespace app\api\controller;
  3. use think\Exception;
  4. use app\api\logic\WelfareLoginc;
  5. use app\common\model\UserModel;
  6. use app\common\controller\Api;
  7. use app\common\model\UserWelfare;
  8. use think\Db;
  9. use think\exception\DbException;
  10. use app\common\model\ProductOrder;
  11. //空投
  12. class Airdrop extends Api
  13. {
  14. protected array $noNeedLogin = [''];
  15. protected string $lan = '';
  16. public function _initialize()
  17. {
  18. parent::_initialize();
  19. $this->lan = $this->request->getLan();
  20. }
  21. //新人福利
  22. public function newbie(UserWelfare $userWelfare, ProductOrder $productOrder, UserModel $userModel)
  23. {
  24. $row = $userWelfare::getIsWelfare();
  25. if(empty($row->is_newbie)) $this->error(__('暂未开启'));
  26. $info = $productOrder::getUserWelfare($this->auth->id, $productOrder::Newbie);
  27. if(!empty($info)) $this->error(__('您已领取'));
  28. Db::startTrans();
  29. try {
  30. //添加Rwa茶记录
  31. $result = WelfareLoginc::setUserWelfareLos($this->auth->id, $row->product_id, $row->num, $this->lan);
  32. //添加茶数量
  33. $userModel::updateForRwaNum($this->auth->id, $this->auth->parent_id, $row->num, '+');
  34. Db::commit();
  35. } catch (\Exception $e) {
  36. Db::rollback();
  37. $this->error($e->getMessage());
  38. }
  39. $this->success('', $result);
  40. }
  41. //超级福利
  42. public function super()
  43. {
  44. $info = (new AnnouncementModel)
  45. ->where('id', $id)
  46. ->where('status', 1)
  47. ->field('id,img_url,body,createtime,' . $this->lan.'_title as title')
  48. ->find();
  49. if(empty($info)){
  50. $this->error('公告信息不存');
  51. }
  52. $this->success('', $info);
  53. }
  54. }