Airdrop.php 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. <?php
  2. namespace app\admin\controller\user;
  3. use app\common\controller\Backend;
  4. use app\admin\library\Auth;
  5. use Exception;
  6. use PhpOffice\PhpSpreadsheet\Cell\Coordinate;
  7. use PhpOffice\PhpSpreadsheet\Reader\Xlsx;
  8. use PhpOffice\PhpSpreadsheet\Reader\Xls;
  9. use PhpOffice\PhpSpreadsheet\Reader\Csv;
  10. use think\Db;
  11. use think\db\exception\BindParamException;
  12. use think\db\exception\DataNotFoundException;
  13. use think\db\exception\ModelNotFoundException;
  14. use think\exception\DbException;
  15. use think\exception\PDOException;
  16. use think\exception\ValidateException;
  17. use think\response\Json;
  18. /**
  19. * 空投管理管理
  20. *
  21. * @icon fa fa-circle-o
  22. */
  23. class Airdrop extends Backend
  24. {
  25. /**
  26. * Airdrop模型对象
  27. * @var \app\admin\model\user\Airdrop
  28. */
  29. protected $model = null;
  30. public function _initialize()
  31. {
  32. parent::_initialize();
  33. $this->model = new \app\common\model\UserAirdrop;
  34. }
  35. /**
  36. * 1. 从平台向指定账号空投一定数量的指定产品
  37. * 2.
  38. * 3.茶付宝上指定区域消费指定金额空投 D 茶权需要开发回调接口
  39. */
  40. /**
  41. * 查看
  42. *
  43. * @return string|Json
  44. * @throws \think\Exception
  45. * @throws DbException
  46. */
  47. public function index()
  48. {
  49. //设置过滤方法
  50. $this->request->filter(['strip_tags', 'trim']);
  51. if (false === $this->request->isAjax()) {
  52. return $this->view->fetch();
  53. }
  54. //如果发送的来源是 Selectpage,则转发到 Selectpage
  55. if ($this->request->request('keyField')) {
  56. return $this->selectpage();
  57. }
  58. [$where, $sort, $order, $offset, $limit] = $this->buildparams();
  59. $list = $this->model
  60. ->where($where)
  61. ->order($sort, $order)
  62. ->paginate($limit);
  63. $result = ['total' => $list->total(), 'rows' => $list->items()];
  64. return json($result);
  65. }
  66. /**
  67. * 添加
  68. *
  69. * @return string
  70. * @throws \think\Exception
  71. */
  72. public function add()
  73. {
  74. if (false === $this->request->isPost()) {
  75. return $this->view->fetch();
  76. }
  77. $params = $this->request->post('row/a');
  78. if (empty($params)) {
  79. $this->error(__('Parameter %s can not be empty', ''));
  80. }
  81. $params = $this->preExcludeFields($params);
  82. if ($this->dataLimit && $this->dataLimitFieldAutoFill) {
  83. $params[$this->dataLimitField] = $this->auth->id;
  84. }
  85. $result = false;
  86. Db::startTrans();
  87. try {
  88. //是否采用模型验证
  89. if ($this->modelValidate) {
  90. $name = str_replace("\\model\\", "\\validate\\", get_class($this->model));
  91. $validate = is_bool($this->modelValidate) ? ($this->modelSceneValidate ? $name . '.add' : $name) : $this->modelValidate;
  92. $this->model->validateFailException()->validate($validate);
  93. }
  94. $result = $this->model->allowField(true)->save($params);
  95. Db::commit();
  96. } catch (ValidateException|PDOException|Exception $e) {
  97. Db::rollback();
  98. $this->error($e->getMessage());
  99. }
  100. if ($result === false) {
  101. $this->error(__('No rows were inserted'));
  102. }
  103. hook('airdropSend',['phone'=>1,'code'=>2,'status'=>"3"]);
  104. $this->success();
  105. }
  106. }