DouYinController.php 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283
  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\adminapi\lists\external\DouyinOrderLists;
  16. use app\adminapi\lists\external\DouyinRefundOrderLists;
  17. use app\api\lists\GoodsLists;
  18. use app\api\logic\GoodsLogic;
  19. use app\api\service\DouYinService;
  20. use app\common\enum\LoginEnum;
  21. use app\common\enum\user\UserTerminalEnum;
  22. use app\common\model\user\User;
  23. use app\api\validate\{LoginAccountValidate, RegisterValidate, WebScanLoginValidate, WechatLoginValidate};
  24. use app\api\logic\LoginLogic;
  25. /**
  26. * 抖音 - tmp
  27. * Class DouYinController
  28. * @package app\api\controller
  29. */
  30. class DouYinController extends BaseApiController
  31. {
  32. public array $notNeedLogin = ['register','account','payNotify'];
  33. /*手机号注册 + 通过code获取openId绑定
  34. (暂时无-试运营)授权手机号一键注册登录 - 通过code应该为getPhoneNumber返回
  35. token过期-登录 + 通过code 通过服务端获取openId,通过openId登录
  36. 手机号-验证码登录
  37. token-直接调去API
  38. 所有商品
  39. 商品详情(分类+商品Id)
  40. 用户地址管理(同原来)
  41. 下单(待支付/已支付-未预约/已预约/服务中/服务完成/取消并退款)
  42. 订单各状态列表
  43. 支付回调
  44. */
  45. /**
  46. * 手机号注册
  47. * @author liugc <466014217@qq.com>
  48. * @date 2025/5/20 13:39
  49. */
  50. public function register()
  51. {
  52. try {
  53. $params = $this->request->post();
  54. $this->validate($params,[
  55. "code" => "require",
  56. "mobile" => "require|mobile",
  57. ]);
  58. // 验证码验证
  59. $res = \app\workerapi\logic\LoginLogic::confirmMobile($params);
  60. if(!$res){
  61. throw new \Exception('验证码错误');
  62. }
  63. // 注册并登录
  64. $result = DouYinService::phoneLogin($params);
  65. return $this->data($result);
  66. } catch (\Exception $e) {
  67. return $this->fail($e->getMessage());
  68. }
  69. }
  70. /**
  71. * @notes 账号密码/手机号密码/手机号验证码登录
  72. * @return \think\response\Json
  73. * @author 段誉
  74. * @date 2022/9/16 10:42
  75. */
  76. public function account()
  77. {
  78. try {
  79. $params = (new LoginAccountValidate())->post()->goCheck();
  80. $result = LoginLogic::login($params);
  81. if (false === $result) {
  82. return $this->fail(LoginLogic::getError());
  83. }
  84. return $this->data($result);
  85. } catch (\Exception $e) {
  86. return $this->fail($e->getMessage());
  87. }
  88. }
  89. /**
  90. * @notes 退出登录
  91. * @return \think\response\Json
  92. * @throws \think\db\exception\DataNotFoundException
  93. * @throws \think\db\exception\DbException
  94. * @throws \think\db\exception\ModelNotFoundException
  95. * @author 段誉
  96. * @date 2022/9/16 10:42
  97. */
  98. public function logout()
  99. {
  100. LoginLogic::logout($this->userInfo);
  101. return $this->success();
  102. }
  103. /**
  104. * 所有商品
  105. * @return \think\response\Json
  106. * @author liugc <466014217@qq.com>
  107. * @date 2025/5/20 14:35
  108. */
  109. public function getAllGoods()
  110. {
  111. $params = $this->request->get();
  112. $params['platform_value'] = 6;
  113. return $this->dataLists((new GoodsLists())->setParams($params));
  114. }
  115. /**
  116. * 商品详情
  117. * @return \think\response\Json
  118. * @author liugc <466014217@qq.com>
  119. * @date 2025/5/20 14:35
  120. */
  121. public function getGoodsDetail()
  122. {
  123. $params = $this->request->get();
  124. $params['platform_value'] = 6;
  125. $result = GoodsLogic::detail($params['goods_category_id'],'category',$this->userId,$params);
  126. return $this->data($result);
  127. }
  128. /**
  129. * 下单
  130. * @return \think\response\Json
  131. * @author liugc <466014217@qq.com>
  132. * @date 2025/5/22 14:35
  133. */
  134. public function submitOrder()
  135. {
  136. try {
  137. $params = $this->request->post();
  138. $params['user_id'] = $this->userId;
  139. $params['user_info'] = $this->userInfo;
  140. DouYinService::submitOrder($params);
  141. return $this->success();
  142. } catch (\Exception $e) {
  143. return $this->fail($e->getMessage());
  144. }
  145. }
  146. /**
  147. * 支付回调
  148. * @return \think\response\Json
  149. * @author liugc <466014217@qq.com>
  150. * @date 2025/5/22 14:35
  151. */
  152. public function payNotify()
  153. {
  154. try {
  155. $params = $this->request->post();
  156. if(DouYinService::payNotify($params)){
  157. return $this->success();
  158. }
  159. return $this->fail('fail');
  160. } catch (\Exception $e) {
  161. return $this->fail($e->getMessage());
  162. }
  163. }
  164. /**
  165. * 预约
  166. * @return \think\response\Json
  167. * @author liugc <466014217@qq.com>
  168. * @date 2025/5/22 14:35
  169. */
  170. public function reservation()
  171. {
  172. try {
  173. $params = $this->request->post(); // order_number
  174. DouYinService::reservation($params);
  175. return $this->success();
  176. } catch (\Exception $e) {
  177. return $this->fail($e->getMessage());
  178. }
  179. }
  180. /**
  181. * 修改预约
  182. * @return \think\response\Json
  183. * @author liugc <466014217@qq.com>
  184. * @date 2025/5/22 14:35
  185. */
  186. public function upReservation()
  187. {
  188. try {
  189. $params = $this->request->post(); // order_number appointment_time
  190. DouYinService::upReservation($params);
  191. return $this->success();
  192. } catch (\Exception $e) {
  193. return $this->fail($e->getMessage());
  194. }
  195. }
  196. /**
  197. * 订单列表
  198. * @return \think\response\Json
  199. * @author liugc <466014217@qq.com>
  200. * @date 2025/5/22 14:35
  201. */
  202. public function getOrderLists()
  203. {
  204. $params = $this->request->get();
  205. $params['user_id'] = $this->userId;
  206. return $this->dataLists((new DouyinOrderLists())->setParams($params));
  207. }
  208. public function getOrderDetail()
  209. {
  210. $params = $this->request->get();
  211. $params['user_id'] = $this->userId;
  212. $result = DouYinService::getOrderDetail($params);
  213. return $this->data($result);
  214. }
  215. /**
  216. * 退款
  217. * @return \think\response\Json
  218. * @author liugc <466014217@qq.com>
  219. * @date 2025/5/22 14:35
  220. */
  221. public function refund()
  222. {
  223. try {
  224. $params = $this->request->post(); // order_number appointment_time
  225. $params['user_id'] = $this->userId;
  226. DouYinService::refund($params);
  227. return $this->success();
  228. } catch (\Exception $e) {
  229. return $this->fail($e->getMessage());
  230. }
  231. }
  232. /**
  233. * 退款订单列表
  234. * @return \think\response\Json
  235. * @author liugc <466014217@qq.com>
  236. * @date 2025/5/22 14:35
  237. */
  238. public function getRefundLists()
  239. {
  240. $params = $this->request->get();
  241. $params['user_id'] = $this->userId;
  242. return $this->dataLists((new DouyinRefundOrderLists())->setParams($params));
  243. }
  244. /**
  245. * 退款回调
  246. * @author liugc <466014217@qq.com>
  247. * @date 2025/5/22 14:35
  248. */
  249. public function refundNotify()
  250. {
  251. try {
  252. $params = $this->request->post();
  253. $msg = is_array($params['msg'])?$params['msg']:json_decode($params['msg'],true);
  254. if(DouYinService::refundNotify($msg)){
  255. return json(["err_no"=>0,"err_tips"=>"success"], 200);
  256. }
  257. } catch (\Exception $e) {
  258. return json(["err_no"=>1001,"err_tips"=>$e->getMessage()], 200);
  259. }
  260. }
  261. }