1
0

DouYinController.php 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332
  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($this->request->get()['isRefresh']??false);
  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. public function submitOrderNotify()
  149. {
  150. try {
  151. $params = $this->request->post();
  152. $msg = is_array($params['msg'])?$params['msg']:json_decode($params['msg'],true);
  153. $msg['user_id'] = $this->userId;
  154. $msg['user_info'] = $this->userInfo;
  155. $res = DouYinService::submitOrderNotify($msg);
  156. if($res){
  157. return json(["err_no"=>0,"err_tips"=>"success","data"=>$res], 200);
  158. }
  159. } catch (\Exception $e) {
  160. return json(["err_no"=>1001,"err_tips"=>$e->getMessage()], 200);
  161. }
  162. }
  163. /**
  164. * 拉起支付所需参数
  165. * @return \think\response\Json
  166. * @author liugc <466014217@qq.com>
  167. * @date 2025/5/22 14:35
  168. */
  169. public function requestOrderData()
  170. {
  171. try {
  172. $params = $this->request->post();
  173. $params['user_id'] = $this->userId;
  174. $params['user_info'] = $this->userInfo;
  175. $requestOrderData = DouYinService::getByteAuthorization($params['order_number']);
  176. $requestOrderData['order_number'] = $params['order_number'];
  177. return $this->success('',$requestOrderData);
  178. } catch (\Exception $e) {
  179. return $this->fail($e->getMessage());
  180. }
  181. }
  182. /**
  183. * 取消订单
  184. * @return \think\response\Json
  185. * @author liugc <466014217@qq.com>
  186. * @date 2025/5/22 14:35
  187. */
  188. public function cancelOrder()
  189. {
  190. try {
  191. $params = $this->request->post(); // order_number
  192. DouYinService::cancelOrder($params);
  193. return $this->success();
  194. } catch (\Exception $e) {
  195. return $this->fail($e->getMessage());
  196. }
  197. }
  198. /**
  199. * 支付回调
  200. * @return \think\response\Json
  201. * @author liugc <466014217@qq.com>
  202. * @date 2025/5/22 14:35
  203. */
  204. public function payNotify()
  205. {
  206. try {
  207. $params = $this->request->post();
  208. $msg = is_array($params['msg'])?$params['msg']:json_decode($params['msg'],true);
  209. if(DouYinService::payNotify($msg)){
  210. return json(["err_no"=>0,"err_tips"=>"success"], 200);
  211. }
  212. } catch (\Exception $e) {
  213. return json(["err_no"=>1001,"err_tips"=>$e->getMessage()], 200);
  214. }
  215. }
  216. /**
  217. * 预约
  218. * @return \think\response\Json
  219. * @author liugc <466014217@qq.com>
  220. * @date 2025/5/22 14:35
  221. */
  222. public function reservation()
  223. {
  224. try {
  225. $params = $this->request->post(); // order_number
  226. DouYinService::reservation($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 upReservation()
  239. {
  240. try {
  241. $params = $this->request->post(); // order_number appointment_time
  242. DouYinService::upReservation($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 getOrderLists()
  255. {
  256. $params = $this->request->get();
  257. $params['user_id'] = $this->userId;
  258. return $this->dataLists((new DouyinOrderLists())->setParams($params));
  259. }
  260. public function getOrderDetail()
  261. {
  262. $params = $this->request->get();
  263. $params['user_id'] = $this->userId;
  264. $result = DouYinService::getOrderDetail($params);
  265. return $this->data($result);
  266. }
  267. /**
  268. * 退款
  269. * @return \think\response\Json
  270. * @author liugc <466014217@qq.com>
  271. * @date 2025/5/22 14:35
  272. */
  273. public function refund()
  274. {
  275. try {
  276. $params = $this->request->post(); // order_number appointment_time
  277. $params['user_id'] = $this->userId;
  278. DouYinService::refund($params);
  279. return $this->success();
  280. } catch (\Exception $e) {
  281. return $this->fail($e->getMessage());
  282. }
  283. }
  284. /**
  285. * 退款订单列表
  286. * @return \think\response\Json
  287. * @author liugc <466014217@qq.com>
  288. * @date 2025/5/22 14:35
  289. */
  290. public function getRefundLists()
  291. {
  292. $params = $this->request->get();
  293. $params['user_id'] = $this->userId;
  294. return $this->dataLists((new DouyinRefundOrderLists())->setParams($params));
  295. }
  296. /**
  297. * 退款回调
  298. * @author liugc <466014217@qq.com>
  299. * @date 2025/5/22 14:35
  300. */
  301. public function refundNotify()
  302. {
  303. try {
  304. $params = $this->request->post();
  305. $msg = is_array($params['msg'])?$params['msg']:json_decode($params['msg'],true);
  306. if(DouYinService::refundNotify($msg)){
  307. return json(["err_no"=>0,"err_tips"=>"success"], 200);
  308. }
  309. } catch (\Exception $e) {
  310. return json(["err_no"=>1001,"err_tips"=>$e->getMessage()], 200);
  311. }
  312. }
  313. }