DouYinController.php 10 KB

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