params = $this->request->post(); if (empty($this->params['rwa_set'])) { if (empty($this->params) || !array_filter($this->params)) $this->error('参数错误'); $sign = ''; foreach ($this->params as $key => $value) { if ($key != 'sign') $sign .= $value; } $sign .= Env::get('rwa.AppID'); $sign = md5($sign); if ($this->params['sign'] != $sign) $this->error('签名验签错误'); } } /* * 判断登录 */ public function login(UserModel $userModel) { $user = $userModel::where('phone', $this->params['mobile'])->find(); if (!$user) $this->error('账号不存在', [], 4000); Token::marshal($user['id'], $user['address']); $user['token'] = Token::getEncryptedToken($user['id']); $this->success('ok', $user); } /* * 注册 */ public function register(UserModel $userModel) { //手机号存在 if ($userModel::where('phone', $this->params['mobile'])->find()) $this->error('账号已存在'); $newUserID = 0; Db::startTrans(); try { //注册 $time = time(); $data = [ 'phone' => $this->params['mobile'], 'nickname' => "188" . substr((string)$time, 2) . rand(10, 99), //188开头,时间戳去掉开头两位,再后面再加两位随机数 'avatar' => $this->request->domain() . '/assets/img/logo.png', 'create_time' => $time, 'team_level_id' => 0, ]; // 创建用户 $newUserID = $userModel->insertGetId($data); // 创建钱包 (new LedgerWalletModel())->insertGetId(['user_id' => $newUserID]); Token::marshal($newUserID); // 提交事务 Db::commit(); } catch (Exception $e) { // 回滚事务 Db::rollback(); $this->error($e->getMessage()); } if ($newUserID == 0) $this->error('注册失败'); $this->success('ok', ['token' => Token::getEncryptedToken($newUserID)]); } //绑定地址 public function bindAddress(UserModel $userModel) { $user = $userModel->getByAddress($this->params['address']); if (!$user) $this->error('钱包地址不存在'); if ($user->phone) $this->error('钱包地址已被绑定'); //修改手机号 $user->phone = $this->params['mobile']; $user->save(); $this->success('ok'); } //转让茶宝 public function chalink(UserModel $userModel, LedgerWalletModel $ledgerWalletModel) { $user = $userModel->getByPhone($this->params['mobile']); if (!$user) $this->error('钱包地址不存在'); //添加茶宝 $ledgerWalletModel->changeWalletAccount($user['id'], Asset::TOKEN, $this->params['chalink'], LedgerTokenChangeModel::ChaLink); $this->success('ok'); } //转入Teac public function teac(UserModel $userModel, LedgerWalletModel $ledgerWalletModel) { $user = $userModel->getByPhone($this->params['mobile']); if (!$user) $this->error('钱包地址不存在'); //添加Teac $ledgerWalletModel->changeWalletAccount($user['id'], Asset::TEAC_ANGEL, $this->params['teac'], LedgerTeacAngelChangeModel::TransferIn); $this->success('ok'); } //转入TeaC生态发展 public function teacecology(UserModel $userModel, LedgerWalletModel $ledgerWalletModel) { $user = $userModel->getByPhone($this->params['mobile']); if (!$user) $this->error('钱包地址不存在'); //添加Teac $ledgerWalletModel->changeWalletAccount($user['id'], Asset::TEAC_ECOLY, $this->params['teacecology'], LedgerTeacEcolyChangeModel::TransferIn); $this->success('ok'); } //茶付宝消费金额达到指定区间,赠送商品 public function give_rwa_goods_list() { $userModel = new UserModel(); $order_model = new ProductOrder(); $data = $this->params['data']; $mobile_list = array_column($data, 'mobile'); $order_id_arr = array_column($data, 'order_id'); $order_id_arr = array_map(function($item) { return 'CFB_' . $item; // 自动将数字转为字符串 }, $order_id_arr); $user = $userModel->whereIn('phone', $mobile_list)->field('phone,id')->select(); $product_arr = $order_model->whereIn('order_id', $order_id_arr)->column('order_id'); $add_data=[]; $ret_data=[]; foreach ($data as &$item) { $item_order_id='CFB_'.$item['order_id']; if(!in_array($item_order_id,$product_arr)){ foreach($user as &$item_1){ if($item['mobile']==$item_1['phone']){ $ret = $order_model->setGiverwagoods('CFB_'.$item['order_id'], 0, $item['product_id'], $item_1['id'], $order_model::Airdrop); $add_data[]=$ret; // if ($ret) { // $item['gift_record_type'] = 1; // $item['reason'] = '赠送RWA茶成功'; // } else { // $item['gift_record_type'] = 0; // $item['reason'] = '赠送RWA茶失败'; // } $item['gift_record_type'] = 1; $item['reason'] = '赠送RWA茶成功'; break; }else{ $item['gift_record_type'] = 2; $item['reason'] = '手机号未注册'; } } $item['order_id']=(int)$item['order_id']; $ret_data[]=$item; }else{ // $item['order_id']=(int)$item['order_id']; // $item['gift_record_type'] = 3; // $item['reason'] = '已经赠送'; } } if(empty($user)&&!empty($ret_data)){ foreach ($ret_data as &$item) { $item['gift_record_type'] = 2; $item['reason'] = '手机号未注册'; } } try { $order_model->saveAll($add_data); } catch (Exception $e) { Log::write('赠送RWA茶失败:'.$e->getMessage(),'info'); } unset($mobile_list); unset($user); $this->success('赠送RWA茶', $ret_data); } }