DouYinController.php 9.7 KB

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