Airdrop.php 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  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. public function show(int $id)
  42. {
  43. $info = (new AnnouncementModel)
  44. ->where('id', $id)
  45. ->where('status', 1)
  46. ->field('id,img_url,body,createtime,' . $this->lan.'_title as title')
  47. ->find();
  48. if(empty($info)){
  49. $this->error('公告信息不存');
  50. }
  51. $this->success('', $info);
  52. }
  53. }