DouYinController.php 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298
  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','getAllGoods','getGoodsDetail','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 cancelOrder()
  153. {
  154. try {
  155. $params = $this->request->post(); // order_number
  156. DouYinService::cancelOrder($params);
  157. return $this->success();
  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 payNotify()
  169. {
  170. try {
  171. $params = $this->request->post();
  172. if(DouYinService::payNotify($params)){
  173. return $this->success();
  174. }
  175. return $this->fail('fail');
  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 reservation()
  187. {
  188. try {
  189. $params = $this->request->post(); // order_number
  190. DouYinService::reservation($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 upReservation()
  203. {
  204. try {
  205. $params = $this->request->post(); // order_number appointment_time
  206. DouYinService::upReservation($params);
  207. return $this->success();
  208. } catch (\Exception $e) {
  209. return $this->fail($e->getMessage());
  210. }
  211. }
  212. /**
  213. * 订单列表
  214. * @return \think\response\Json
  215. * @author liugc <466014217@qq.com>
  216. * @date 2025/5/22 14:35
  217. */
  218. public function getOrderLists()
  219. {
  220. $params = $this->request->get();
  221. $params['user_id'] = $this->userId;
  222. return $this->dataLists((new DouyinOrderLists())->setParams($params));
  223. }
  224. public function getOrderDetail()
  225. {
  226. $params = $this->request->get();
  227. $params['user_id'] = $this->userId;
  228. $result = DouYinService::getOrderDetail($params);
  229. return $this->data($result);
  230. }
  231. /**
  232. * 退款
  233. * @return \think\response\Json
  234. * @author liugc <466014217@qq.com>
  235. * @date 2025/5/22 14:35
  236. */
  237. public function refund()
  238. {
  239. try {
  240. $params = $this->request->post(); // order_number appointment_time
  241. $params['user_id'] = $this->userId;
  242. DouYinService::refund($params);
  243. return $this->success();
  244. } catch (\Exception $e) {
  245. return $this->fail($e->getMessage());
  246. }
  247. }
  248. /**
  249. * 退款订单列表
  250. * @return \think\response\Json
  251. * @author liugc <466014217@qq.com>
  252. * @date 2025/5/22 14:35
  253. */
  254. public function getRefundLists()
  255. {
  256. $params = $this->request->get();
  257. $params['user_id'] = $this->userId;
  258. return $this->dataLists((new DouyinRefundOrderLists())->setParams($params));
  259. }
  260. /**
  261. * 退款回调
  262. * @author liugc <466014217@qq.com>
  263. * @date 2025/5/22 14:35
  264. */
  265. public function refundNotify()
  266. {
  267. try {
  268. $params = $this->request->post();
  269. $msg = is_array($params['msg'])?$params['msg']:json_decode($params['msg'],true);
  270. if(DouYinService::refundNotify($msg)){
  271. return json(["err_no"=>0,"err_tips"=>"success"], 200);
  272. }
  273. } catch (\Exception $e) {
  274. return json(["err_no"=>1001,"err_tips"=>$e->getMessage()], 200);
  275. }
  276. }
  277. }