DouYinController.php 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337
  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. /**
  179. * 拉起支付所需参数
  180. * @return \think\response\Json
  181. * @author liugc <466014217@qq.com>
  182. * @date 2025/5/22 14:35
  183. */
  184. public function requestOrderData()
  185. {
  186. try {
  187. $params = $this->request->post();
  188. $params['user_id'] = $this->userId;
  189. $params['user_info'] = $this->userInfo;
  190. $requestOrderData = DouYinService::getPluginCreateOrderData($params['goods_id']??'',$params['quantity']??1,$params['dy_order_id']??'',$params);
  191. return $this->success('',$requestOrderData);
  192. } catch (\Exception $e) {
  193. return $this->fail($e->getMessage());
  194. }
  195. }
  196. public function submitOrderNotify()
  197. {
  198. try {
  199. $params = $this->request->post();
  200. $msg = is_array($params['msg'])?$params['msg']:json_decode($params['msg'],true);
  201. $res = DouYinService::submitOrderNotify($msg);
  202. if($res){
  203. return json(["err_no"=>0,"err_tips"=>"success","data"=>$res], 200);
  204. }
  205. } catch (\Exception $e) {
  206. return json(["err_no"=>1001,"err_tips"=>$e->getMessage()], 200);
  207. }
  208. }
  209. /**
  210. * 支付回调
  211. * @return \think\response\Json
  212. * @author liugc <466014217@qq.com>
  213. * @date 2025/5/22 14:35
  214. */
  215. public function payNotify()
  216. {
  217. try {
  218. $params = $this->request->post();
  219. $msg = is_array($params['msg'])?$params['msg']:json_decode($params['msg'],true);
  220. if(DouYinService::payNotify($msg)){
  221. return json(["err_no"=>0,"err_tips"=>"success"], 200);
  222. }
  223. } catch (\Exception $e) {
  224. return json(["err_no"=>1001,"err_tips"=>$e->getMessage()], 200);
  225. }
  226. }
  227. public function payTailNotify()
  228. {
  229. try {
  230. $params = $this->request->post();
  231. $msg = is_array($params['msg'])?$params['msg']:json_decode($params['msg'],true);
  232. if(DouYinService::payTailNotify($msg)){
  233. return json(["err_no"=>0,"err_tips"=>"success"], 200);
  234. }
  235. } catch (\Exception $e) {
  236. return json(["err_no"=>1001,"err_tips"=>$e->getMessage()], 200);
  237. }
  238. }
  239. // ******************************** 订单预约/改约
  240. /**
  241. * 预约
  242. * @return \think\response\Json
  243. * @author liugc <466014217@qq.com>
  244. * @date 2025/5/22 14:35
  245. */
  246. public function reservation()
  247. {
  248. try {
  249. $params = $this->request->post(); // order_number
  250. DouYinService::reservation($params);
  251. return $this->success();
  252. } catch (\Exception $e) {
  253. return $this->fail($e->getMessage());
  254. }
  255. }
  256. /**
  257. * 修改预约
  258. * @return \think\response\Json
  259. * @author liugc <466014217@qq.com>
  260. * @date 2025/5/22 14:35
  261. */
  262. public function upReservation()
  263. {
  264. try {
  265. $params = $this->request->post(); // order_number appointment_time
  266. DouYinService::upReservation($params);
  267. return $this->success();
  268. } catch (\Exception $e) {
  269. return $this->fail($e->getMessage());
  270. }
  271. }
  272. // ******************************** 订单 取消 退款
  273. /**
  274. * 取消订单
  275. * @return \think\response\Json
  276. * @author liugc <466014217@qq.com>
  277. * @date 2025/5/22 14:35
  278. */
  279. public function cancelOrder()
  280. {
  281. try {
  282. $params = $this->request->post(); // order_number
  283. DouYinService::cancelOrder($params);
  284. return $this->success();
  285. } catch (\Exception $e) {
  286. return $this->fail($e->getMessage());
  287. }
  288. }
  289. /**
  290. * 退款
  291. * @return \think\response\Json
  292. * @author liugc <466014217@qq.com>
  293. * @date 2025/5/22 14:35
  294. */
  295. public function refund()
  296. {
  297. try {
  298. $params = $this->request->post(); // order_number appointment_time
  299. $params['user_id'] = $this->userId;
  300. DouYinService::refund($params);
  301. return $this->success();
  302. } catch (\Exception $e) {
  303. return $this->fail($e->getMessage());
  304. }
  305. }
  306. /**
  307. * 退款回调
  308. * @author liugc <466014217@qq.com>
  309. * @date 2025/5/22 14:35
  310. */
  311. public function refundNotify()
  312. {
  313. try {
  314. $params = $this->request->post();
  315. $msg = is_array($params['msg'])?$params['msg']:json_decode($params['msg'],true);
  316. if(DouYinService::refundNotify($msg)){
  317. return json(["err_no"=>0,"err_tips"=>"success"], 200);
  318. }
  319. } catch (\Exception $e) {
  320. return json(["err_no"=>1001,"err_tips"=>$e->getMessage()], 200);
  321. }
  322. }
  323. }