You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

198 lines
6.1 KiB

5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
  1. <?php
  2. declare(strict_types=1);
  3. namespace App\Controller;
  4. use App\Constants\v3\LogLabel;
  5. use App\Constants\v3\OrderState;
  6. use App\Constants\v3\OrderType;
  7. use App\Libs\FeiePrintClient;
  8. use App\Model\v3\OrderMain;
  9. use App\Service\v3\Interfaces\CouponRebateServiceInterface;
  10. use App\Service\v3\Interfaces\DeviceServiceInterface;
  11. use App\Service\v3\Interfaces\FeiePrintServiceInterface;
  12. use App\Service\v3\Interfaces\MiniprogramServiceInterface;
  13. use App\Service\v3\Interfaces\MqttServiceInterface;
  14. use App\Service\v3\Interfaces\OrderOnlineServiceInterface;
  15. use App\Service\v3\Interfaces\SeparateAccountsServiceInterface;
  16. use App\Service\v3\Interfaces\UserServiceInterface;
  17. use Hyperf\HttpServer\Contract\RequestInterface;
  18. use Hyperf\HttpServer\Annotation\AutoController;
  19. use Hyperf\Utils\Coroutine;
  20. use Hyperf\Utils\ApplicationContext;
  21. use Hyperf\Task\TaskExecutor;
  22. use Hyperf\Task\Task;
  23. use App\TaskWorker\SSDBTask;
  24. use App\Commons\Log;
  25. use Hyperf\Di\Annotation\Inject;
  26. /**
  27. * @AutoController()
  28. * Class TestController
  29. * @package App\Controller
  30. */
  31. class TestController extends AbstractController
  32. {
  33. private $name = 'default action';
  34. protected $client = null;
  35. /**
  36. * @Inject
  37. * @var MqttServiceInterface
  38. */
  39. protected $mqttService;
  40. /**
  41. * @Inject
  42. * @var DeviceServiceInterface
  43. */
  44. protected $deviceService;
  45. /**
  46. * @Inject
  47. * @var MiniprogramServiceInterface
  48. */
  49. protected $miniprogramService;
  50. /**
  51. * @Inject
  52. * @var FeiePrintServiceInterface
  53. */
  54. protected $feiePrintService;
  55. /**
  56. * @Inject
  57. * @var UserServiceInterface
  58. */
  59. protected $userService;
  60. /**
  61. * @Inject
  62. * @var CouponRebateServiceInterface
  63. */
  64. protected $couponRebateService;
  65. /**
  66. * @Inject
  67. * @var OrderOnlineServiceInterface
  68. */
  69. protected $orderOnlineService;
  70. /**
  71. * @Inject
  72. * @var SeparateAccountsServiceInterface
  73. */
  74. protected $separateAccountsService;
  75. public function index1(RequestInterface $request)
  76. {
  77. // $container = ApplicationContext::getContainer();
  78. // $exec = $container->get(TaskExecutor::class);
  79. // $result = $exec->execute(new Task([MethodTask::class, 'handle'], [Coroutine::id()]));
  80. // $client = ApplicationContext::getContainer()->get(SSDBTask::class);
  81. // $result = $client->exec("set","bar","1234");
  82. // $result = $client->exec("get","bar");
  83. // $client = ApplicationContext::getContainer()->get(MethodTask::class);
  84. // $result = $client->handle("set");
  85. // //$log = ApplicationContext::getContainer()->get(Log::class);
  86. // $log = $this->log;
  87. //
  88. // $log->push(['test'=>1,'user_id'=>290,'msg'=>'order']);
  89. // $log->event('t1',['test'=>1,'user_id'=>290,'msg'=>'order']);
  90. //
  91. // //$this->name = 'index1 action '. $result;
  92. // return $this->name;
  93. // $time = time();
  94. // $msgInfo = array(
  95. // 'user' => '13161443713@163.com',
  96. // 'stime' => $time,
  97. // 'sig' => sha1('13161443713@163.com' . 'XsaHzgePdyWTfcMX' . $time),
  98. // 'apiname' => 'Open_printMsg',
  99. // 'sn' => '920527381',
  100. // 'content' => '1111',
  101. // 'times' => 1//打印次数
  102. // );
  103. // $this->client = new FeiePrintClient('api.feieyun.cn', 80);
  104. // if (!$this->client->post('/Api/Open/', $msgInfo)) {
  105. // return '12';
  106. // } else {
  107. // //服务器返回的JSON字符串,建议要当做日志记录起来
  108. // $result = $this->client->getContent();
  109. // return $result;
  110. // }
  111. $orderMainId = $this->request->input('order_main_id');
  112. // 查询订单
  113. $orderMain = OrderMain::query()
  114. ->where([
  115. 'id' => $orderMainId,
  116. 'type' => OrderType::ONLINE,
  117. 'state' => OrderState::UNPAID
  118. ])
  119. ->first();
  120. // 订单不存在
  121. if (empty($orderMain)) {
  122. $this->log->event(
  123. LogLabel::ORDER_OFFLINE_PAY_NOTIFY_LOG,
  124. ['global_order_id_fail' => $orderMainId]
  125. );
  126. return true;
  127. }
  128. // $orderPaid = $this->orderOfflineService->doPaid($orderMainId);
  129. // var_dump('orderOfflineService', $orderPaid);
  130. // $separate = $this->separateAccountsService->orderOfflinePaid($orderMainId);
  131. // var_dump('separateAccountsService', $separate);
  132. //
  133. // // 喇叭通知,兼容旧音响,MQTT+IOT
  134. // $res = $this->mqttService->speakToStore($orderMainId);
  135. // var_dump('mqttService', $res);
  136. // $res = $this->deviceService->pubMsgToStoreByOrderMainId($orderMainId);
  137. // var_dump('deviceService', $res);
  138. //
  139. // // 公众号模板消息
  140. // $res = $this->miniprogramService->sendTemMsgForOfflineOrder($orderMainId);
  141. // var_dump('miniprogramService', $res);
  142. $res = $this->orderOnlineService->doByPaid($orderMainId);
  143. var_dump('orderOnlineService', $res);
  144. $res = $this->separateAccountsService->orderOnlinePaid($orderMainId);
  145. var_dump('separateAccountsService', $res);
  146. // 优惠券返券
  147. $res = $this->couponRebateService->couponRebateInTask($orderMainId);
  148. var_dump('couponRebateService', $res);
  149. // 喇叭通知,兼容旧音响,MQTT+IOT
  150. $res = $this->mqttService->speakToStore($orderMainId);
  151. var_dump('mqttService', $res);
  152. $res = $this->deviceService->pubMsgToStoreByOrderMainId($orderMainId);
  153. var_dump('deviceService', $res);
  154. // 公众号模板消息
  155. $res = $this->miniprogramService->sendTemMsgForOnlineOrder($orderMainId);
  156. var_dump('miniprogramService', $res);
  157. // 打印订单,自动打印
  158. $res = $this->feiePrintService->feiePrint($orderMainId);
  159. var_dump('feiePrintService', $res);
  160. }
  161. public function index2(RequestInterface $request)
  162. {
  163. $this->name = 'index2 action';
  164. return $this->name;
  165. }
  166. public function index3(RequestInterface $request)
  167. {
  168. return $this->name;
  169. }
  170. }