1
0

DouYinController.php 9.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311
  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. $requestOrderData = DouYinService::getByteAuthorization($order_number);
  137. $requestOrderData['order_number'] = $order_number;
  138. return $this->success('',$requestOrderData);
  139. } catch (\Exception $e) {
  140. return $this->fail($e->getMessage());
  141. }
  142. }
  143. /**
  144. * 拉起支付所需参数
  145. * @return \think\response\Json
  146. * @author liugc <466014217@qq.com>
  147. * @date 2025/5/22 14:35
  148. */
  149. public function requestOrderData()
  150. {
  151. try {
  152. $params = $this->request->post();
  153. $params['user_id'] = $this->userId;
  154. $params['user_info'] = $this->userInfo;
  155. $requestOrderData = DouYinService::getByteAuthorization($params['order_number']);
  156. $requestOrderData['order_number'] = $params['order_number'];
  157. return $this->success('',$requestOrderData);
  158. } catch (\Exception $e) {
  159. return $this->fail($e->getMessage());
  160. }
  161. }
  162. /**
  163. * 取消订单
  164. * @return \think\response\Json
  165. * @author liugc <466014217@qq.com>
  166. * @date 2025/5/22 14:35
  167. */
  168. public function cancelOrder()
  169. {
  170. try {
  171. $params = $this->request->post(); // order_number
  172. DouYinService::cancelOrder($params);
  173. return $this->success();
  174. } catch (\Exception $e) {
  175. return $this->fail($e->getMessage());
  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 payNotify()
  185. {
  186. try {
  187. $params = $this->request->post();
  188. $msg = is_array($params['msg'])?$params['msg']:json_decode($params['msg'],true);
  189. if(DouYinService::payNotify($msg)){
  190. return json(["err_no"=>0,"err_tips"=>"success"], 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 reservation()
  203. {
  204. try {
  205. $params = $this->request->post(); // order_number
  206. DouYinService::reservation($params);
  207. return $this->success();
  208. } catch (\Exception $e) {
  209. return $this->fail($e->getMessage());
  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 upReservation()
  219. {
  220. try {
  221. $params = $this->request->post(); // order_number appointment_time
  222. DouYinService::upReservation($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 getOrderLists()
  235. {
  236. $params = $this->request->get();
  237. $params['user_id'] = $this->userId;
  238. return $this->dataLists((new DouyinOrderLists())->setParams($params));
  239. }
  240. public function getOrderDetail()
  241. {
  242. $params = $this->request->get();
  243. $params['user_id'] = $this->userId;
  244. $result = DouYinService::getOrderDetail($params);
  245. return $this->data($result);
  246. }
  247. /**
  248. * 退款
  249. * @return \think\response\Json
  250. * @author liugc <466014217@qq.com>
  251. * @date 2025/5/22 14:35
  252. */
  253. public function refund()
  254. {
  255. try {
  256. $params = $this->request->post(); // order_number appointment_time
  257. $params['user_id'] = $this->userId;
  258. DouYinService::refund($params);
  259. return $this->success();
  260. } catch (\Exception $e) {
  261. return $this->fail($e->getMessage());
  262. }
  263. }
  264. /**
  265. * 退款订单列表
  266. * @return \think\response\Json
  267. * @author liugc <466014217@qq.com>
  268. * @date 2025/5/22 14:35
  269. */
  270. public function getRefundLists()
  271. {
  272. $params = $this->request->get();
  273. $params['user_id'] = $this->userId;
  274. return $this->dataLists((new DouyinRefundOrderLists())->setParams($params));
  275. }
  276. /**
  277. * 退款回调
  278. * @author liugc <466014217@qq.com>
  279. * @date 2025/5/22 14:35
  280. */
  281. public function refundNotify()
  282. {
  283. try {
  284. $params = $this->request->post();
  285. $msg = is_array($params['msg'])?$params['msg']:json_decode($params['msg'],true);
  286. if(DouYinService::refundNotify($msg)){
  287. return json(["err_no"=>0,"err_tips"=>"success"], 200);
  288. }
  289. } catch (\Exception $e) {
  290. return json(["err_no"=>1001,"err_tips"=>$e->getMessage()], 200);
  291. }
  292. }
  293. }