H5.php 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306
  1. <?php
  2. namespace app\mobile\controller;
  3. use app\core\exception\AppException;
  4. use app\core\model\UserBank;
  5. use app\core\model\UserDrawcash;
  6. use app\core\model\UserHongbao;
  7. use app\core\model\Active;
  8. use app\core\model\Cang;
  9. use app\core\model\Subject;
  10. use app\core\model\Loan;
  11. use app\core\model\UserRecharge;
  12. use app\core\service\Finance;
  13. use app\core\service\User;
  14. use think\Config;
  15. use think\Log;
  16. use think\Request;
  17. use tool\Common;
  18. class H5
  19. {
  20. public $user;
  21. public $data = [];
  22. public $track = [];
  23. public $request;
  24. public $app;
  25. public function __construct()
  26. {
  27. $this->request = request();
  28. $this->data = $this->request->param();
  29. $this->track = json_decode($this->data['track'], true);
  30. $this->check();
  31. $this->app = $this->track['app'];
  32. Log::info($this->app);
  33. Log::info($this->request);
  34. if(in_array($this->request->path(), Config::get('tourist_path')))
  35. {
  36. //游客直接跳过
  37. }
  38. else {
  39. $user = User::getUserByToken($this->track['token'], $this->track['osType']);
  40. if(!$user) {
  41. throw new AppException(-1000, 'token失效,需要重新登录');
  42. }
  43. $this->user = $user;
  44. }
  45. }
  46. public function check() {
  47. if(!isset($this->track['apiV'])) {
  48. throw new AppException(-101, 'api版本号不能为空');
  49. }
  50. if(!isset($this->track['osV'])) {
  51. throw new AppException(-102, 'osV操作系统版本号不能为空');
  52. }
  53. if(!isset($this->track['osType'])) {
  54. throw new AppException(-103, 'osType操作系统类型不能为空');
  55. }
  56. if(!isset($this->track['deviceID'])) {
  57. throw new AppException(-104, 'deviceID宿主app的唯一标识不能为空');
  58. }
  59. if(!isset($this->track['token'])) {
  60. throw new AppException(-105, 'token不能为空');
  61. }
  62. if(!isset($this->track['sign'])) {
  63. throw new AppException(-106, 'sign不能为空');
  64. }
  65. if(!isset($this->track['time'])) {
  66. throw new AppException(-107, 'time不能为空');
  67. }
  68. if(!isset($this->track['ip'])) {
  69. throw new AppException(-108, 'ip不能为空');
  70. }
  71. if(!isset($this->track['app'])) {
  72. throw new AppException(-109, 'app应用数据不能为空');
  73. }
  74. if(!isset($this->track['appV'])) {
  75. throw new AppException(-110, 'appV不能为空');
  76. }
  77. if(!isset($this->track['channel'])) {
  78. throw new AppException(-111, 'channel不能为空');
  79. }
  80. $key = '';
  81. if($this->track['osType'] == 1 || $this->track['osType'] == 2) {
  82. $key = Config::get('system.mobile_key');
  83. }
  84. else if($this->track['osType'] == 3) {
  85. $key = Config::get('system.pc_key');
  86. }
  87. $this->app = $this->track['app'];
  88. $signPre = '';
  89. if($this->app === '') {
  90. $signPre = $key.$this->track['token'].$this->track['time'].$this->track['appV'].$this->track['apiV'].$this->track['osV'].$this->track['osType'].$this->track['deviceID'].$this->track['ip'].$this->track['channel'];
  91. }
  92. else if($this->app === []) {
  93. $signPre = $key.$this->track['token'].$this->track['time'].$this->track['appV'].$this->track['apiV'].$this->track['osV'].$this->track['osType'].$this->track['deviceID'].$this->track['ip'].$this->track['channel'].'{}';
  94. }
  95. else {
  96. $signPre = $key.$this->track['token'].$this->track['time'].$this->track['appV'].$this->track['apiV'].$this->track['osV'].$this->track['osType'].$this->track['deviceID'].$this->track['ip'].$this->track['channel'].json_encode($this->track['app'], JSON_UNESCAPED_UNICODE);
  97. }
  98. Log::info($signPre);
  99. $sign = md5($signPre);
  100. Log::info($sign);
  101. if($sign != $this->track['sign']) {
  102. throw new AppException(-108, 'sign签名不正确');
  103. }
  104. }
  105. public function __call($name, $arguments)
  106. {
  107. // TODO: Implement __call() method.
  108. }
  109. public function getResourcePath()
  110. {
  111. $module = Request::instance()->module();
  112. $controller = Request::instance()->controller();
  113. $action = Request::instance()->action();
  114. return '/'.$module.'/'.$controller.'/'.$action;
  115. }
  116. public function activeList() {
  117. $list = Active::where([
  118. 'isOnLineApp'=>1
  119. ])->order('addTime desc')->select();
  120. return view(__FUNCTION__, ['resourcePath'=>'/static/'.request()->path(), 'activeList'=>$list]);
  121. }
  122. //内容
  123. public function subjectContent() {
  124. //Log::info($this->app['subjectID']);
  125. $list = Cang::with(['user'])->where([
  126. 'subjectID'=>$this->app['subjectID']
  127. ])->order('addTime desc')->select();
  128. $cangList = [];
  129. if(!$list->isEmpty()) {
  130. $cangList = $list->toArray();
  131. }
  132. $subject = Subject::get($this->app['subjectID']);
  133. $loan = null;
  134. if($subject) {
  135. $loan = Loan::get($subject['loanID']);
  136. }
  137. return view(__FUNCTION__, [
  138. 'resourcePath'=>'/static/'.request()->path(),
  139. 'cangList'=>$cangList,
  140. 'loan'=>$loan
  141. ]);
  142. }
  143. //首页
  144. public function guarantee() {
  145. return view(__FUNCTION__, ['resourcePath'=>'/static/'.request()->path()]);
  146. }
  147. public function contract() {
  148. return view(__FUNCTION__, ['resourcePath'=>'/static/'.request()->module().'/'.strtolower(request()->controller()).'/'.'contract']);
  149. }
  150. public function risk() {
  151. return view(__FUNCTION__, ['resourcePath'=>'/static/'.request()->module().'/'.strtolower(request()->controller()).'/'.'contract']);
  152. }
  153. public function userRecharge() {
  154. $userBank = UserBank::get($this->app['userBankID']);
  155. if(!$userBank) {
  156. return json(Common::rm(-3, '银行卡不存在'));
  157. }
  158. //第一步,添加提现记录
  159. $userRecharge = new UserRecharge();
  160. $userRecharge->save([
  161. 'userID'=>$this->user['userID'],
  162. 'money'=>$this->app['money'],
  163. 'status'=>UserRecharge::STATUS_UNPAY,
  164. 'type'=>UserRecharge::TYPE_BANK,
  165. 'bankID'=>$userBank->bank['bankID'],
  166. 'bankAccount'=>$userBank['bankAccount'],
  167. 'bankNumber'=>$userBank['bankNumber'],
  168. 'bankName'=>$userBank['bankNameFull'],
  169. 'trueName'=>$userBank['bankAccount'],
  170. 'mobile'=>$userBank['mobile'],
  171. 'outerName'=>$userBank['outerName']
  172. ]);
  173. //第二步,得到第三方提现记录
  174. vendor('payModel.Recharge');
  175. $recharge = new \Recharge();
  176. $recharge->setMoney($this->app['money']);
  177. $recharge->setLoginID($userBank['mobile']);
  178. $recharge->setPageUrl($this->h5RootUrl().'/notify/fuyou/rechargePage/userRechargeID/'.$userRecharge['userRechargeID'].'/from/'.request()->param('from'));
  179. $recharge->setNotifyUrl($this->h5RootUrl().'/notify/fuyou/rechargeNotify/userRechargeID/'.$userRecharge['userRechargeID']);
  180. $data = (new Finance())->userRecharge($msg, $recharge);
  181. //第三步,更新提现记录
  182. $userRecharge['outerNumber'] = $data['outerNumber'];
  183. $userRecharge['alias'] = $userRecharge->createAlias($userRecharge['userRechargeID']);
  184. $userRecharge->save();
  185. return view(__FUNCTION__, [
  186. 'resourcePath'=>'/static/'.request()->path(),
  187. 'param'=>$data['param'],
  188. 'url'=>$data['url']
  189. ]);
  190. }
  191. public function userDrawcash() {
  192. $userBank = UserBank::get($this->app['userBankID']);
  193. if(!$userBank) {
  194. return json(Common::rm(-3, '银行卡不存在'));
  195. }
  196. //第一步,添加提现记录
  197. $userDrawcash = new UserDrawcash();
  198. $userDrawcash->save([
  199. 'userID'=>$this->user['userID'],
  200. 'money'=>$this->app['money'],
  201. 'status'=>UserDrawcash::STATUS_SUBMIT,
  202. 'type'=>UserDrawcash::TYPE_BANK,
  203. 'userBankID'=>$userBank['userBankID'],
  204. 'bankID'=>$userBank['bankID'],
  205. 'bankAccount'=>$userBank['bankAccount'],
  206. 'bankNumber'=>$userBank['bankNumber'],
  207. 'bankName'=>$userBank['bankNameFull'],
  208. 'trueName'=>$userBank['bankAccount'],
  209. 'mobile'=>$userBank['mobile'],
  210. 'outerName'=>$userBank['outerName']
  211. ]);
  212. //第二步,得到第三方提现记录
  213. vendor('payModel.Drawcash');
  214. $drawcash = new \Drawcash();
  215. $drawcash->setMoney($this->app['money']);
  216. $drawcash->setLoginID($userBank['mobile']);
  217. $drawcash->setPageUrl($this->h5RootUrl().'/notify/fuyou/drawcashPage/userDrawcashID/'.$userDrawcash['userDrawcashID'].'/from/'.request()->param('from'));
  218. $drawcash->setNotifyUrl($this->h5RootUrl().'/notify/fuyou/drawcashNotify/userDrawcashID/'.$userDrawcash['userDrawcashID']);
  219. $data = (new Finance())->userDrawcash($msg, $drawcash);
  220. //第三步,更新提现记录
  221. $userDrawcash['outerNumber'] = $data['outerNumber'];
  222. $userDrawcash['alias'] = $userDrawcash->createAlias($userDrawcash['userDrawcashID']);
  223. $userDrawcash->save();
  224. return view(__FUNCTION__, [
  225. 'resourcePath'=>'/static/'.request()->path(),
  226. 'param'=>$data['param'],
  227. 'url'=>$data['url']
  228. ]);
  229. }
  230. public function safe() {
  231. return view(__FUNCTION__, ['resourcePath'=>'/static/'.request()->module().'/'.strtolower(request()->controller()).'/'.'safe']);
  232. }
  233. public function about() {
  234. return view(__FUNCTION__, ['resourcePath'=>'/static/'.request()->module().'/'.strtolower(request()->controller()).'/'.'activeList']);
  235. }
  236. //注册协议
  237. public function regAgreement() {
  238. return view(__FUNCTION__, ['resourcePath'=>'/static/'.request()->module().'/'.strtolower(request()->controller()).'/'.'regAgreement']);
  239. }
  240. public function userInvitationPage() {
  241. return view(__FUNCTION__, ['resourcePath'=>'/static/'.request()->module().'/'.strtolower(request()->controller()).'/'.'userInvitationPage']);
  242. }
  243. public function h5RootUrl() {
  244. return Config::get('h5RootUrl');
  245. }
  246. }