DouYinController.php 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289
  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','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. /**
  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. * @return \think\response\Json
  101. * @author liugc <466014217@qq.com>
  102. * @date 2025/5/20 14:35
  103. */
  104. public function getAllGoods()
  105. {
  106. $params = $this->request->get();
  107. $params['platform_value'] = 6;
  108. return $this->dataLists((new GoodsLists())->setParams($params));
  109. }
  110. /**
  111. * 商品详情
  112. * @return \think\response\Json
  113. * @author liugc <466014217@qq.com>
  114. * @date 2025/5/20 14:35
  115. */
  116. public function getGoodsDetail()
  117. {
  118. $params = $this->request->get();
  119. $params['platform_value'] = 6;
  120. $result = GoodsLogic::detail($params['goods_category_id'],'category',$this->userId,$params);
  121. return $this->data($result);
  122. }
  123. /**
  124. * 下单
  125. * @return \think\response\Json
  126. * @author liugc <466014217@qq.com>
  127. * @date 2025/5/22 14:35
  128. */
  129. public function submitOrder()
  130. {
  131. try {
  132. $params = $this->request->post();
  133. $params['user_id'] = $this->userId;
  134. $params['user_info'] = $this->userInfo;
  135. $order_number = DouYinService::submitOrder($params);
  136. return $this->success('',['order_number'=>$order_number]);
  137. } catch (\Exception $e) {
  138. return $this->fail($e->getMessage());
  139. }
  140. }
  141. /**
  142. * 取消订单
  143. * @return \think\response\Json
  144. * @author liugc <466014217@qq.com>
  145. * @date 2025/5/22 14:35
  146. */
  147. public function cancelOrder()
  148. {
  149. try {
  150. $params = $this->request->post(); // order_number
  151. DouYinService::cancelOrder($params);
  152. return $this->success();
  153. } catch (\Exception $e) {
  154. return $this->fail($e->getMessage());
  155. }
  156. }
  157. /**
  158. * 支付回调
  159. * @return \think\response\Json
  160. * @author liugc <466014217@qq.com>
  161. * @date 2025/5/22 14:35
  162. */
  163. public function payNotify()
  164. {
  165. try {
  166. $params = $this->request->post();
  167. if(DouYinService::payNotify($params)){
  168. return $this->success();
  169. }
  170. return $this->fail('fail');
  171. } catch (\Exception $e) {
  172. return $this->fail($e->getMessage());
  173. }
  174. }
  175. /**
  176. * 预约
  177. * @return \think\response\Json
  178. * @author liugc <466014217@qq.com>
  179. * @date 2025/5/22 14:35
  180. */
  181. public function reservation()
  182. {
  183. try {
  184. $params = $this->request->post(); // order_number
  185. DouYinService::reservation($params);
  186. return $this->success();
  187. } catch (\Exception $e) {
  188. return $this->fail($e->getMessage());
  189. }
  190. }
  191. /**
  192. * 修改预约
  193. * @return \think\response\Json
  194. * @author liugc <466014217@qq.com>
  195. * @date 2025/5/22 14:35
  196. */
  197. public function upReservation()
  198. {
  199. try {
  200. $params = $this->request->post(); // order_number appointment_time
  201. DouYinService::upReservation($params);
  202. return $this->success();
  203. } catch (\Exception $e) {
  204. return $this->fail($e->getMessage());
  205. }
  206. }
  207. /**
  208. * 订单列表
  209. * @return \think\response\Json
  210. * @author liugc <466014217@qq.com>
  211. * @date 2025/5/22 14:35
  212. */
  213. public function getOrderLists()
  214. {
  215. $params = $this->request->get();
  216. $params['user_id'] = $this->userId;
  217. return $this->dataLists((new DouyinOrderLists())->setParams($params));
  218. }
  219. public function getOrderDetail()
  220. {
  221. $params = $this->request->get();
  222. $params['user_id'] = $this->userId;
  223. $result = DouYinService::getOrderDetail($params);
  224. return $this->data($result);
  225. }
  226. /**
  227. * 退款
  228. * @return \think\response\Json
  229. * @author liugc <466014217@qq.com>
  230. * @date 2025/5/22 14:35
  231. */
  232. public function refund()
  233. {
  234. try {
  235. $params = $this->request->post(); // order_number appointment_time
  236. $params['user_id'] = $this->userId;
  237. DouYinService::refund($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 getRefundLists()
  250. {
  251. $params = $this->request->get();
  252. $params['user_id'] = $this->userId;
  253. return $this->dataLists((new DouyinRefundOrderLists())->setParams($params));
  254. }
  255. /**
  256. * 退款回调
  257. * @author liugc <466014217@qq.com>
  258. * @date 2025/5/22 14:35
  259. */
  260. public function refundNotify()
  261. {
  262. try {
  263. $params = $this->request->post();
  264. $msg = is_array($params['msg'])?$params['msg']:json_decode($params['msg'],true);
  265. if(DouYinService::refundNotify($msg)){
  266. return json(["err_no"=>0,"err_tips"=>"success"], 200);
  267. }
  268. } catch (\Exception $e) {
  269. return json(["err_no"=>1001,"err_tips"=>$e->getMessage()], 200);
  270. }
  271. }
  272. }