BindingController.php 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. <?php
  2. namespace app\controller;
  3. use app\business\GoodsBusiness;
  4. use app\business\LoginBusiness;
  5. use app\business\PayorderBusiness;
  6. use app\business\WithdrawBusiness;
  7. use Illuminate\Support\Arr;
  8. use Respect\Validation\Validator;
  9. use support\Db;
  10. use support\Redis;
  11. use support\Request;
  12. use hg\apidoc\annotation as Apidoc;
  13. use Webman\Captcha\CaptchaBuilder;
  14. use Webman\Captcha\PhraseBuilder;
  15. // #[Apidoc\Title("绑定")]
  16. #[Apidoc\Group("Binding")]
  17. #[Apidoc\Sort(5)]
  18. class BindingController
  19. {
  20. #[Apidoc\Title("绑定支付宝,绑定微信,绑定数字人民币 扫码支付")]
  21. #[Apidoc\Url("api/binding.html")]
  22. #[Apidoc\Method("POST")]
  23. #[Apidoc\Header("token", type: "string", require: true, desc: "身份令牌Token", mock: "@token")]
  24. #[Apidoc\Param("account_number", type: "int", require: true, desc: "账号", mock: 10)]
  25. #[Apidoc\Param("type", type: "int", require: true, desc: "类型:1=支付宝,2=微信 ", mock: 2)]
  26. public function addbinding(Request $request)
  27. {
  28. $param = $request->param_data;
  29. $param['user_data'] = $request->user_data;
  30. Db::beginTransaction();
  31. try {
  32. Validator::input($param, [
  33. 'account_number' => Validator::notEmpty()->setName('账号'),
  34. 'type' => Validator::notEmpty()->setName('类型'),
  35. ]);
  36. $data = [
  37. 'user_id' => $param['user_data']['id'],
  38. 'account_number' => $param['account_number'],
  39. 'mobile' => $param['user_data']['mobile'],
  40. 'type' => $param['type'],
  41. 'created_at' => date('Y-m-d H:i:s'),
  42. 'updated_at' => date('Y-m-d H:i:s'),
  43. ];
  44. $binding = Db::table('wa_binding')
  45. ->where('user_id', $param['user_data']['id'])
  46. ->where('type', $param['type'])->first();
  47. if (empty($binding)) {
  48. Db::table('wa_binding')->insert($data);
  49. } else {
  50. Db::table('wa_binding')->where('id', $binding->id)->update($data);
  51. }
  52. } catch (\Throwable $exception) {
  53. Db::rollBack();
  54. return error($exception->getMessage());
  55. }
  56. Db::commit();
  57. return success();
  58. }
  59. #[Apidoc\Title("绑定记录详情")]
  60. #[Apidoc\Url("api/binding/binding_details.html")]
  61. #[Apidoc\Method("POST")]
  62. #[Apidoc\Header("token", type: "string", require: true, desc: "身份令牌Token", mock: "@token")]
  63. #[Apidoc\Param("type", type: "int", require: true, desc: "类型:1=支付宝,2=微信", mock: 2)]
  64. #[Apidoc\Returned(name: "account_number", type: "string", require: true, desc: '账号', default: '0.00')]
  65. #[Apidoc\Returned(name: "mobile", type: "string", require: true, desc: '手机号', default: '0.00')]
  66. public function binding_details(Request $request)
  67. {
  68. $param = $request->param_data;
  69. $param['user_data'] = $request->user_data;
  70. Db::beginTransaction();
  71. try {
  72. Validator::input($param, [
  73. 'type' => Validator::notEmpty()->setName('类型'),
  74. ]);
  75. $bindingdata = Db::table('wa_binding')
  76. ->where('user_id', $param['user_data']['id'])
  77. ->where('type', $param['type'])
  78. ->first();
  79. if (empty($bindingdata)) {
  80. $data = [
  81. 'id' => '',
  82. 'account_number' => '',
  83. 'mobile' => '',
  84. 'type' => '',
  85. ];
  86. } else {
  87. $data = [
  88. 'id' => $bindingdata->id,
  89. 'account_number' => $bindingdata->account_number,
  90. 'mobile' => $bindingdata->mobile,
  91. 'type' => $bindingdata->type,
  92. ];
  93. }
  94. } catch (\Throwable $exception) {
  95. Db::rollBack();
  96. return error($exception->getMessage());
  97. }
  98. Db::commit();
  99. return success($data);
  100. }
  101. }