DouYinController.php 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361
  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','getOpenid','register','account','goodsNotify','getAllGoods','getGoodsDetail','submitOrderNotify','payNotify','payTailNotify'];
  34. public function testNotify()
  35. {
  36. $params = $this->request->post();
  37. Log::info('testNotify'.formatLogData($params));
  38. return $this->success();
  39. }
  40. /**
  41. * 手机号注册
  42. * @author liugc <466014217@qq.com>
  43. * @date 2025/5/20 13:39
  44. */
  45. public function register()
  46. {
  47. try {
  48. $params = $this->request->post();
  49. $this->validate($params,[
  50. "code" => "require",
  51. "mobile" => "require|mobile",
  52. ]);
  53. // 验证码验证
  54. $res = \app\workerapi\logic\LoginLogic::confirmMobile($params);
  55. if(!$res){
  56. throw new \Exception('验证码错误');
  57. }
  58. // 注册并登录
  59. $result = DouYinService::phoneLogin($params);
  60. return $this->data($result);
  61. } catch (\Exception $e) {
  62. return $this->fail($e->getMessage());
  63. }
  64. }
  65. /**
  66. * @notes 账号密码/手机号密码/手机号验证码登录
  67. * @return \think\response\Json
  68. * @author 段誉
  69. * @date 2022/9/16 10:42
  70. */
  71. public function account()
  72. {
  73. try {
  74. $params = (new LoginAccountValidate())->post()->goCheck();
  75. $result = LoginLogic::login($params);
  76. if (false === $result) {
  77. return $this->fail(LoginLogic::getError());
  78. }
  79. return $this->data($result);
  80. } catch (\Exception $e) {
  81. return $this->fail($e->getMessage());
  82. }
  83. }
  84. /**
  85. * @notes 退出登录
  86. * @return \think\response\Json
  87. * @throws \think\db\exception\DataNotFoundException
  88. * @throws \think\db\exception\DbException
  89. * @throws \think\db\exception\ModelNotFoundException
  90. * @author 段誉
  91. * @date 2022/9/16 10:42
  92. */
  93. public function logout()
  94. {
  95. LoginLogic::logout($this->userInfo);
  96. return $this->success();
  97. }
  98. public function getOpenid()
  99. {
  100. $params = $this->request->post();
  101. $toData = [
  102. 'appid' => 'tt74fb0246ebf34b0601',
  103. 'secret' => "0c841cc324e8bea8a584d248556d6263fb2dadb2",
  104. 'code' => $params['code'],
  105. 'anonymous_code' => $params['anonymous_code']
  106. ];
  107. $res = DouYinService::toDyRequestUrl('https://developer.toutiao.com/api/apps/v2/jscode2session',$toData,['Content-Type' => 'application/json'],'errNoReturn',1);
  108. Log::info(json_encode($res));
  109. return $this->success('',$res);
  110. }
  111. // ******************************** 列表详情 _商品 _订单 _退款
  112. /*
  113. * 商品审核结果回调
  114. */
  115. public function goodsNotify()
  116. {
  117. $params = $this->request->post();
  118. Log::info('goodsNotify:'.formatLogData($params));
  119. return $this->success();
  120. }
  121. /**
  122. * 所有商品
  123. * @return \think\response\Json
  124. * @author liugc <466014217@qq.com>
  125. * @date 2025/5/20 14:35
  126. */
  127. public function getAllGoods()
  128. {
  129. $params = $this->request->get();
  130. $params['platform_value'] = 6;
  131. return $this->dataLists((new GoodsLists())->setParams($params));
  132. }
  133. /**
  134. * 商品详情
  135. * @return \think\response\Json
  136. * @author liugc <466014217@qq.com>
  137. * @date 2025/5/20 14:35
  138. */
  139. public function getGoodsDetail()
  140. {
  141. $params = $this->request->get();
  142. $params['platform_value'] = 6;
  143. $result = GoodsLogic::detail($params['goods_category_id'],'category',$this->userId,$params);
  144. return $this->data($result);
  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 getOrderLists()
  153. {
  154. $params = $this->request->get();
  155. $params['user_id'] = $this->userId;
  156. return $this->dataLists((new DouyinOrderLists())->setParams($params));
  157. }
  158. public function getOrderDetail()
  159. {
  160. $params = $this->request->get();
  161. $params['user_id'] = $this->userId;
  162. $result = DouYinService::getOrderDetail($params);
  163. return $this->data($result);
  164. }
  165. /**
  166. * 退款订单列表
  167. * @return \think\response\Json
  168. * @author liugc <466014217@qq.com>
  169. * @date 2025/5/22 14:35
  170. */
  171. public function getRefundLists()
  172. {
  173. $params = $this->request->get();
  174. $params['user_id'] = $this->userId;
  175. return $this->dataLists((new DouyinRefundOrderLists())->setParams($params));
  176. }
  177. // ******************************** 订单业务
  178. public function createOrder()
  179. {
  180. try {
  181. $params = $this->request->post();
  182. $params['user_id'] = $this->userId;
  183. $params['user_info'] = $this->userInfo;
  184. $requestOrderData = DouYinService::createOrder($params);
  185. return $this->success('',$requestOrderData);
  186. } catch (\Exception $e) {
  187. return $this->fail($e->getMessage());
  188. }
  189. }
  190. /**
  191. * 拉起支付所需参数
  192. * @return \think\response\Json
  193. * @author liugc <466014217@qq.com>
  194. * @date 2025/5/22 14:35
  195. */
  196. public function requestOrderData()
  197. {
  198. try {
  199. $params = $this->request->post();
  200. $params['user_id'] = $this->userId;
  201. $params['user_info'] = $this->userInfo;
  202. $requestOrderData = DouYinService::getPluginCreateOrderData($params['goods_id']??'',$params['quantity']??1,$params['dy_order_id']??'',$params);
  203. Log::info('requestOrderData:'.formatLogData($requestOrderData));
  204. return $this->success('',$requestOrderData);
  205. } catch (\Exception $e) {
  206. return $this->fail($e->getMessage());
  207. }
  208. }
  209. public function submitOrderNotify()
  210. {
  211. try {
  212. $params = $this->request->post();
  213. Log::info('submitOrderNotify:'.formatLogData($params));
  214. $msg = is_array($params['msg'])?$params['msg']:json_decode($params['msg'],true);
  215. $res = DouYinService::submitOrderNotify($msg);
  216. Log::info("submitOrderNotify:".formatLogData($res));
  217. if($res){
  218. return json(["err_no"=>0,"err_tips"=>"","data"=>$res], 200);
  219. }
  220. } catch (\Exception $e) {
  221. return json(["err_no"=>1001,"err_tips"=>$e->getMessage()], 200);
  222. }
  223. }
  224. /**
  225. * 支付回调
  226. * @return \think\response\Json
  227. * @author liugc <466014217@qq.com>
  228. * @date 2025/5/22 14:35
  229. */
  230. public function payNotify()
  231. {
  232. try {
  233. $params = $this->request->post();
  234. Log::info('payNotify:'.formatLogData($params));
  235. $msg = is_array($params['msg'])?$params['msg']:json_decode($params['msg'],true);
  236. if(DouYinService::payNotify($msg)){
  237. return json(["err_no"=>0,"err_tips"=>""], 200);
  238. }
  239. } catch (\Exception $e) {
  240. return json(["err_no"=>1001,"err_tips"=>$e->getMessage()], 200);
  241. }
  242. }
  243. public function payTailNotify()
  244. {
  245. try {
  246. $params = $this->request->post();
  247. Log::info('payTailNotify:'.formatLogData($params));
  248. $msg = is_array($params['msg'])?$params['msg']:json_decode($params['msg'],true);
  249. if(DouYinService::payTailNotify($msg)){
  250. return json(["err_no"=>0,"err_tips"=>""], 200);
  251. }
  252. } catch (\Exception $e) {
  253. return json(["err_no"=>1001,"err_tips"=>$e->getMessage()], 200);
  254. }
  255. }
  256. // ******************************** 订单预约/改约
  257. /**
  258. * 预约
  259. * @return \think\response\Json
  260. * @author liugc <466014217@qq.com>
  261. * @date 2025/5/22 14:35
  262. */
  263. public function reservation()
  264. {
  265. try {
  266. $params = $this->request->post(); // order_number
  267. Log::info('reservation:'.formatLogData($params));
  268. DouYinService::reservation($params);
  269. return $this->success();
  270. } catch (\Exception $e) {
  271. return $this->fail($e->getMessage());
  272. }
  273. }
  274. /**
  275. * 修改预约
  276. * @return \think\response\Json
  277. * @author liugc <466014217@qq.com>
  278. * @date 2025/5/22 14:35
  279. */
  280. public function upReservation()
  281. {
  282. try {
  283. $params = $this->request->post(); // order_number appointment_time
  284. Log::info('upReservation:'.formatLogData($params));
  285. DouYinService::upReservation($params);
  286. return $this->success();
  287. } catch (\Exception $e) {
  288. return $this->fail($e->getMessage());
  289. }
  290. }
  291. // ******************************** 订单 取消 退款
  292. /**
  293. * 取消订单
  294. * @return \think\response\Json
  295. * @author liugc <466014217@qq.com>
  296. * @date 2025/5/22 14:35
  297. */
  298. public function cancelOrder()
  299. {
  300. try {
  301. $params = $this->request->post(); // order_number
  302. Log::info('cancelOrder:'.formatLogData($params));
  303. DouYinService::cancelOrder($params);
  304. return $this->success();
  305. } catch (\Exception $e) {
  306. return $this->fail($e->getMessage());
  307. }
  308. }
  309. /**
  310. * 退款
  311. * @return \think\response\Json
  312. * @author liugc <466014217@qq.com>
  313. * @date 2025/5/22 14:35
  314. */
  315. public function refund()
  316. {
  317. try {
  318. $params = $this->request->post(); // order_number appointment_time
  319. $params['user_id'] = $this->userId;
  320. Log::info('refund:'.formatLogData($params));
  321. DouYinService::refund($params);
  322. return $this->success();
  323. } catch (\Exception $e) {
  324. return $this->fail($e->getMessage());
  325. }
  326. }
  327. /**
  328. * 退款回调
  329. * @author liugc <466014217@qq.com>
  330. * @date 2025/5/22 14:35
  331. */
  332. public function refundNotify()
  333. {
  334. try {
  335. $params = $this->request->post();
  336. Log::info('refundNotify:'.formatLogData($params));
  337. $msg = is_array($params['msg'])?$params['msg']:json_decode($params['msg'],true);
  338. if(DouYinService::refundNotify($msg)){
  339. return json(["err_no"=>0,"err_tips"=>"success"], 200);
  340. }
  341. } catch (\Exception $e) {
  342. return json(["err_no"=>1001,"err_tips"=>$e->getMessage()], 200);
  343. }
  344. }
  345. }