DouYinController.php 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | likeadmin快速开发前后端分离管理后台(PHP版)
  4. // +----------------------------------------------------------------------
  5. // | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
  6. // | 开源版本可自由商用,可去除界面版权logo
  7. // | gitee下载:https://gitee.com/likeshop_gitee/likeadmin
  8. // | github下载:https://github.com/likeshop-github/likeadmin
  9. // | 访问官网:https://www.likeadmin.cn
  10. // | likeadmin团队 版权所有 拥有最终解释权
  11. // +----------------------------------------------------------------------
  12. // | author: likeadminTeam
  13. // +----------------------------------------------------------------------
  14. namespace app\api\controller;
  15. use app\api\lists\GoodsLists;
  16. use app\api\logic\GoodsLogic;
  17. use app\api\service\DouYinService;
  18. use app\common\enum\LoginEnum;
  19. use app\common\enum\user\UserTerminalEnum;
  20. use app\common\model\user\User;
  21. use app\api\validate\{LoginAccountValidate, RegisterValidate, WebScanLoginValidate, WechatLoginValidate};
  22. use app\api\logic\LoginLogic;
  23. /**
  24. * 抖音 - tmp
  25. * Class DouYinController
  26. * @package app\api\controller
  27. */
  28. class DouYinController extends BaseApiController
  29. {
  30. public array $notNeedLogin = ['register','account','payNotify'];
  31. /*手机号注册 + 通过code获取openId绑定
  32. (暂时无-试运营)授权手机号一键注册登录 - 通过code应该为getPhoneNumber返回
  33. token过期-登录 + 通过code 通过服务端获取openId,通过openId登录
  34. 手机号-验证码登录
  35. token-直接调去API
  36. 所有商品
  37. 商品详情(分类+商品Id)
  38. 用户地址管理(同原来)
  39. 下单(待支付/已支付-未预约/已预约/服务中/服务完成/取消并退款)
  40. 订单各状态列表
  41. 支付回调
  42. */
  43. /**
  44. * 手机号注册
  45. * @author liugc <466014217@qq.com>
  46. * @date 2025/5/20 13:39
  47. */
  48. public function register()
  49. {
  50. try {
  51. $params = $this->request->post();
  52. $this->validate($params,[
  53. "code" => "require",
  54. "mobile" => "require|mobile",
  55. ]);
  56. // 验证码验证
  57. $res = \app\workerapi\logic\LoginLogic::confirmMobile($params);
  58. if(!$res){
  59. throw new \Exception('验证码错误');
  60. }
  61. // 注册并登录
  62. $result = DouYinService::phoneLogin($params);
  63. return $this->data($result);
  64. } catch (\Exception $e) {
  65. return $this->fail($e->getMessage());
  66. }
  67. }
  68. /**
  69. * @notes 账号密码/手机号密码/手机号验证码登录
  70. * @return \think\response\Json
  71. * @author 段誉
  72. * @date 2022/9/16 10:42
  73. */
  74. public function account()
  75. {
  76. try {
  77. $params = (new LoginAccountValidate())->post()->goCheck();
  78. $result = LoginLogic::login($params);
  79. if (false === $result) {
  80. return $this->fail(LoginLogic::getError());
  81. }
  82. return $this->data($result);
  83. } catch (\Exception $e) {
  84. return $this->fail($e->getMessage());
  85. }
  86. }
  87. /**
  88. * @notes 退出登录
  89. * @return \think\response\Json
  90. * @throws \think\db\exception\DataNotFoundException
  91. * @throws \think\db\exception\DbException
  92. * @throws \think\db\exception\ModelNotFoundException
  93. * @author 段誉
  94. * @date 2022/9/16 10:42
  95. */
  96. public function logout()
  97. {
  98. LoginLogic::logout($this->userInfo);
  99. return $this->success();
  100. }
  101. /**
  102. * 所有商品
  103. * @return \think\response\Json
  104. * @author liugc <466014217@qq.com>
  105. * @date 2025/5/20 14:35
  106. */
  107. public function getAllGoods()
  108. {
  109. $params = $this->request->get();
  110. $params['platform_value'] = 6;
  111. return $this->dataLists((new GoodsLists())->setParams($params));
  112. }
  113. /**
  114. * 商品详情
  115. * @return \think\response\Json
  116. * @author liugc <466014217@qq.com>
  117. * @date 2025/5/20 14:35
  118. */
  119. public function getGoodsDetail()
  120. {
  121. $params = $this->request->get();
  122. $params['platform_value'] = 6;
  123. $result = GoodsLogic::detail($params['goods_category_id'],'category',$this->userId,$params);
  124. return $this->data($result);
  125. }
  126. /**
  127. * 下单
  128. * @return \think\response\Json
  129. * @author liugc <466014217@qq.com>
  130. * @date 2025/5/22 14:35
  131. */
  132. public function submitOrder()
  133. {
  134. try {
  135. $params = $this->request->post();
  136. $params['user_id'] = $this->userId;
  137. $params['user_info'] = $this->userInfo;
  138. DouYinService::submitOrder($params);
  139. return $this->success();
  140. } catch (\Exception $e) {
  141. return $this->fail($e->getMessage());
  142. }
  143. }
  144. /**
  145. * 支付回调
  146. * @return \think\response\Json
  147. * @author liugc <466014217@qq.com>
  148. * @date 2025/5/22 14:35
  149. */
  150. public function payNotify()
  151. {
  152. try {
  153. $params = $this->request->post();
  154. if(DouYinService::payNotify($params)){
  155. return $this->success();
  156. }
  157. return $this->fail('fail');
  158. } catch (\Exception $e) {
  159. return $this->fail($e->getMessage());
  160. }
  161. }
  162. /**
  163. * 预约
  164. * @return \think\response\Json
  165. * @author liugc <466014217@qq.com>
  166. * @date 2025/5/22 14:35
  167. */
  168. public function reservation()
  169. {
  170. try {
  171. $params = $this->request->post(); // order_number
  172. DouYinService::reservation($params);
  173. return $this->success();
  174. } catch (\Exception $e) {
  175. return $this->fail($e->getMessage());
  176. }
  177. }
  178. }