DouYinController.php 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325
  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','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. // ******************************** 列表详情 _商品 _订单 _退款
  99. /*
  100. * 商品审核结果回调
  101. */
  102. public function goodsNotify()
  103. {
  104. $params = $this->request->post();
  105. Log::info('goodsNotify:'.formatLogData($params));
  106. return $this->success();
  107. }
  108. /**
  109. * 所有商品
  110. * @return \think\response\Json
  111. * @author liugc <466014217@qq.com>
  112. * @date 2025/5/20 14:35
  113. */
  114. public function getAllGoods()
  115. {
  116. $params = $this->request->get();
  117. $params['platform_value'] = 6;
  118. return $this->dataLists((new GoodsLists())->setParams($params));
  119. }
  120. /**
  121. * 商品详情
  122. * @return \think\response\Json
  123. * @author liugc <466014217@qq.com>
  124. * @date 2025/5/20 14:35
  125. */
  126. public function getGoodsDetail()
  127. {
  128. $params = $this->request->get();
  129. $params['platform_value'] = 6;
  130. $result = GoodsLogic::detail($params['goods_category_id'],'category',$this->userId,$params);
  131. return $this->data($result);
  132. }
  133. /**
  134. * 订单列表
  135. * @return \think\response\Json
  136. * @author liugc <466014217@qq.com>
  137. * @date 2025/5/22 14:35
  138. */
  139. public function getOrderLists()
  140. {
  141. $params = $this->request->get();
  142. $params['user_id'] = $this->userId;
  143. return $this->dataLists((new DouyinOrderLists())->setParams($params));
  144. }
  145. public function getOrderDetail()
  146. {
  147. $params = $this->request->get();
  148. $params['user_id'] = $this->userId;
  149. $result = DouYinService::getOrderDetail($params);
  150. return $this->data($result);
  151. }
  152. /**
  153. * 退款订单列表
  154. * @return \think\response\Json
  155. * @author liugc <466014217@qq.com>
  156. * @date 2025/5/22 14:35
  157. */
  158. public function getRefundLists()
  159. {
  160. $params = $this->request->get();
  161. $params['user_id'] = $this->userId;
  162. return $this->dataLists((new DouyinRefundOrderLists())->setParams($params));
  163. }
  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 requestOrderData()
  172. {
  173. try {
  174. $params = $this->request->post();
  175. $params['user_id'] = $this->userId;
  176. $params['user_info'] = $this->userInfo;
  177. $requestOrderData = DouYinService::getPluginCreateOrderData($params['goods_id']??'',$params['quantity']??1,$params['dy_order_id']??'',$params);
  178. return $this->success('',$requestOrderData);
  179. } catch (\Exception $e) {
  180. return $this->fail($e->getMessage());
  181. }
  182. }
  183. public function submitOrderNotify()
  184. {
  185. try {
  186. $params = $this->request->post();
  187. $msg = is_array($params['msg'])?$params['msg']:json_decode($params['msg'],true);
  188. $res = DouYinService::submitOrderNotify($msg);
  189. if($res){
  190. return json(["err_no"=>0,"err_tips"=>"success","data"=>$res], 200);
  191. }
  192. } catch (\Exception $e) {
  193. return json(["err_no"=>1001,"err_tips"=>$e->getMessage()], 200);
  194. }
  195. }
  196. /**
  197. * 支付回调
  198. * @return \think\response\Json
  199. * @author liugc <466014217@qq.com>
  200. * @date 2025/5/22 14:35
  201. */
  202. public function payNotify()
  203. {
  204. try {
  205. $params = $this->request->post();
  206. $msg = is_array($params['msg'])?$params['msg']:json_decode($params['msg'],true);
  207. if(DouYinService::payNotify($msg)){
  208. return json(["err_no"=>0,"err_tips"=>"success"], 200);
  209. }
  210. } catch (\Exception $e) {
  211. return json(["err_no"=>1001,"err_tips"=>$e->getMessage()], 200);
  212. }
  213. }
  214. public function payTailNotify()
  215. {
  216. try {
  217. $params = $this->request->post();
  218. $msg = is_array($params['msg'])?$params['msg']:json_decode($params['msg'],true);
  219. if(DouYinService::payTailNotify($msg)){
  220. return json(["err_no"=>0,"err_tips"=>"success"], 200);
  221. }
  222. } catch (\Exception $e) {
  223. return json(["err_no"=>1001,"err_tips"=>$e->getMessage()], 200);
  224. }
  225. }
  226. // ******************************** 订单预约/改约
  227. /**
  228. * 预约
  229. * @return \think\response\Json
  230. * @author liugc <466014217@qq.com>
  231. * @date 2025/5/22 14:35
  232. */
  233. public function reservation()
  234. {
  235. try {
  236. $params = $this->request->post(); // order_number
  237. DouYinService::reservation($params);
  238. return $this->success();
  239. } catch (\Exception $e) {
  240. return $this->fail($e->getMessage());
  241. }
  242. }
  243. /**
  244. * 修改预约
  245. * @return \think\response\Json
  246. * @author liugc <466014217@qq.com>
  247. * @date 2025/5/22 14:35
  248. */
  249. public function upReservation()
  250. {
  251. try {
  252. $params = $this->request->post(); // order_number appointment_time
  253. DouYinService::upReservation($params);
  254. return $this->success();
  255. } catch (\Exception $e) {
  256. return $this->fail($e->getMessage());
  257. }
  258. }
  259. // ******************************** 订单 取消 退款
  260. /**
  261. * 取消订单
  262. * @return \think\response\Json
  263. * @author liugc <466014217@qq.com>
  264. * @date 2025/5/22 14:35
  265. */
  266. public function cancelOrder()
  267. {
  268. try {
  269. $params = $this->request->post(); // order_number
  270. DouYinService::cancelOrder($params);
  271. return $this->success();
  272. } catch (\Exception $e) {
  273. return $this->fail($e->getMessage());
  274. }
  275. }
  276. /**
  277. * 退款
  278. * @return \think\response\Json
  279. * @author liugc <466014217@qq.com>
  280. * @date 2025/5/22 14:35
  281. */
  282. public function refund()
  283. {
  284. try {
  285. $params = $this->request->post(); // order_number appointment_time
  286. $params['user_id'] = $this->userId;
  287. DouYinService::refund($params);
  288. return $this->success();
  289. } catch (\Exception $e) {
  290. return $this->fail($e->getMessage());
  291. }
  292. }
  293. /**
  294. * 退款回调
  295. * @author liugc <466014217@qq.com>
  296. * @date 2025/5/22 14:35
  297. */
  298. public function refundNotify()
  299. {
  300. try {
  301. $params = $this->request->post();
  302. $msg = is_array($params['msg'])?$params['msg']:json_decode($params['msg'],true);
  303. if(DouYinService::refundNotify($msg)){
  304. return json(["err_no"=>0,"err_tips"=>"success"], 200);
  305. }
  306. } catch (\Exception $e) {
  307. return json(["err_no"=>1001,"err_tips"=>$e->getMessage()], 200);
  308. }
  309. }
  310. }