DouYinController.php 9.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316
  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. use think\facade\Log;
  26. /**
  27. * 抖音 - tmp
  28. * Class DouYinController
  29. * @package app\api\controller
  30. */
  31. class DouYinController extends BaseApiController
  32. {
  33. public array $notNeedLogin = ['testNotify','getClientToken','register','account','getAllGoods','getGoodsDetail','payNotify'];
  34. public function testNotify()
  35. {
  36. // https://weixiudev.kyjlkj.com/api/dou_yin/testNotify
  37. $params = $this->request->post();
  38. Log::info('dy_testNotify:'.json_encode($params));
  39. }
  40. public function getClientToken()
  41. {
  42. $access_token = DouYinService::getClientToken();
  43. return $this->success('',['access_token'=>$access_token]);
  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. $order_number = DouYinService::submitOrder($params);
  141. $requestOrderData = DouYinService::getByteAuthorization($order_number);
  142. $requestOrderData['order_number'] = $order_number;
  143. return $this->success('',$requestOrderData);
  144. } catch (\Exception $e) {
  145. return $this->fail($e->getMessage());
  146. }
  147. }
  148. /**
  149. * 拉起支付所需参数
  150. * @return \think\response\Json
  151. * @author liugc <466014217@qq.com>
  152. * @date 2025/5/22 14:35
  153. */
  154. public function requestOrderData()
  155. {
  156. try {
  157. $params = $this->request->post();
  158. $params['user_id'] = $this->userId;
  159. $params['user_info'] = $this->userInfo;
  160. $requestOrderData = DouYinService::getByteAuthorization($params['order_number']);
  161. $requestOrderData['order_number'] = $params['order_number'];
  162. return $this->success('',$requestOrderData);
  163. } catch (\Exception $e) {
  164. return $this->fail($e->getMessage());
  165. }
  166. }
  167. /**
  168. * 取消订单
  169. * @return \think\response\Json
  170. * @author liugc <466014217@qq.com>
  171. * @date 2025/5/22 14:35
  172. */
  173. public function cancelOrder()
  174. {
  175. try {
  176. $params = $this->request->post(); // order_number
  177. DouYinService::cancelOrder($params);
  178. return $this->success();
  179. } catch (\Exception $e) {
  180. return $this->fail($e->getMessage());
  181. }
  182. }
  183. /**
  184. * 支付回调
  185. * @return \think\response\Json
  186. * @author liugc <466014217@qq.com>
  187. * @date 2025/5/22 14:35
  188. */
  189. public function payNotify()
  190. {
  191. try {
  192. $params = $this->request->post();
  193. $msg = is_array($params['msg'])?$params['msg']:json_decode($params['msg'],true);
  194. if(DouYinService::payNotify($msg)){
  195. return json(["err_no"=>0,"err_tips"=>"success"], 200);
  196. }
  197. } catch (\Exception $e) {
  198. return json(["err_no"=>1001,"err_tips"=>$e->getMessage()], 200);
  199. }
  200. }
  201. /**
  202. * 预约
  203. * @return \think\response\Json
  204. * @author liugc <466014217@qq.com>
  205. * @date 2025/5/22 14:35
  206. */
  207. public function reservation()
  208. {
  209. try {
  210. $params = $this->request->post(); // order_number
  211. DouYinService::reservation($params);
  212. return $this->success();
  213. } catch (\Exception $e) {
  214. return $this->fail($e->getMessage());
  215. }
  216. }
  217. /**
  218. * 修改预约
  219. * @return \think\response\Json
  220. * @author liugc <466014217@qq.com>
  221. * @date 2025/5/22 14:35
  222. */
  223. public function upReservation()
  224. {
  225. try {
  226. $params = $this->request->post(); // order_number appointment_time
  227. DouYinService::upReservation($params);
  228. return $this->success();
  229. } catch (\Exception $e) {
  230. return $this->fail($e->getMessage());
  231. }
  232. }
  233. /**
  234. * 订单列表
  235. * @return \think\response\Json
  236. * @author liugc <466014217@qq.com>
  237. * @date 2025/5/22 14:35
  238. */
  239. public function getOrderLists()
  240. {
  241. $params = $this->request->get();
  242. $params['user_id'] = $this->userId;
  243. return $this->dataLists((new DouyinOrderLists())->setParams($params));
  244. }
  245. public function getOrderDetail()
  246. {
  247. $params = $this->request->get();
  248. $params['user_id'] = $this->userId;
  249. $result = DouYinService::getOrderDetail($params);
  250. return $this->data($result);
  251. }
  252. /**
  253. * 退款
  254. * @return \think\response\Json
  255. * @author liugc <466014217@qq.com>
  256. * @date 2025/5/22 14:35
  257. */
  258. public function refund()
  259. {
  260. try {
  261. $params = $this->request->post(); // order_number appointment_time
  262. $params['user_id'] = $this->userId;
  263. DouYinService::refund($params);
  264. return $this->success();
  265. } catch (\Exception $e) {
  266. return $this->fail($e->getMessage());
  267. }
  268. }
  269. /**
  270. * 退款订单列表
  271. * @return \think\response\Json
  272. * @author liugc <466014217@qq.com>
  273. * @date 2025/5/22 14:35
  274. */
  275. public function getRefundLists()
  276. {
  277. $params = $this->request->get();
  278. $params['user_id'] = $this->userId;
  279. return $this->dataLists((new DouyinRefundOrderLists())->setParams($params));
  280. }
  281. /**
  282. * 退款回调
  283. * @author liugc <466014217@qq.com>
  284. * @date 2025/5/22 14:35
  285. */
  286. public function refundNotify()
  287. {
  288. try {
  289. $params = $this->request->post();
  290. $msg = is_array($params['msg'])?$params['msg']:json_decode($params['msg'],true);
  291. if(DouYinService::refundNotify($msg)){
  292. return json(["err_no"=>0,"err_tips"=>"success"], 200);
  293. }
  294. } catch (\Exception $e) {
  295. return json(["err_no"=>1001,"err_tips"=>$e->getMessage()], 200);
  296. }
  297. }
  298. }