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.

252 lines
8.0 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\Constants\v3\SsdbKeys;
  8. use App\Libs\FeiePrintClient;
  9. use App\Model\v3\Order;
  10. use App\Model\v3\OrderGoods;
  11. use App\Model\v3\OrderMain;
  12. use App\Service\v3\Interfaces\CouponRebateServiceInterface;
  13. use App\Service\v3\Interfaces\CouponServiceInterface;
  14. use App\Service\v3\Interfaces\DeviceServiceInterface;
  15. use App\Service\v3\Interfaces\FeiePrintServiceInterface;
  16. use App\Service\v3\Interfaces\FinancialRecordServiceInterface;
  17. use App\Service\v3\Interfaces\GoodsActivityServiceInterface;
  18. use App\Service\v3\Interfaces\MiniprogramServiceInterface;
  19. use App\Service\v3\Interfaces\MqttServiceInterface;
  20. use App\Service\v3\Interfaces\OrderOnlineServiceInterface;
  21. use App\Service\v3\Interfaces\SeparateAccountsServiceInterface;
  22. use App\Service\v3\Interfaces\UserServiceInterface;
  23. use Hyperf\DbConnection\Db;
  24. use Hyperf\HttpServer\Contract\RequestInterface;
  25. use Hyperf\HttpServer\Annotation\AutoController;
  26. use Hyperf\Utils\Coroutine;
  27. use Hyperf\Utils\ApplicationContext;
  28. use Hyperf\Task\TaskExecutor;
  29. use Hyperf\Task\Task;
  30. use App\TaskWorker\SSDBTask;
  31. use App\Commons\Log;
  32. use Hyperf\Di\Annotation\Inject;
  33. /**
  34. * @AutoController()
  35. * Class TestController
  36. * @package App\Controller
  37. */
  38. class TestController extends AbstractController
  39. {
  40. private $name = 'default action';
  41. protected $client = null;
  42. /**
  43. * @Inject
  44. * @var MqttServiceInterface
  45. */
  46. protected $mqttService;
  47. /**
  48. * @Inject
  49. * @var DeviceServiceInterface
  50. */
  51. protected $deviceService;
  52. /**
  53. * @Inject
  54. * @var MiniprogramServiceInterface
  55. */
  56. protected $miniprogramService;
  57. /**
  58. * @Inject
  59. * @var FeiePrintServiceInterface
  60. */
  61. protected $feiePrintService;
  62. /**
  63. * @Inject
  64. * @var UserServiceInterface
  65. */
  66. protected $userService;
  67. /**
  68. * @Inject
  69. * @var CouponRebateServiceInterface
  70. */
  71. protected $couponRebateService;
  72. /**
  73. * @Inject
  74. * @var CouponServiceInterface
  75. */
  76. protected $couponService;
  77. /**
  78. * @Inject
  79. * @var OrderOnlineServiceInterface
  80. */
  81. protected $orderOnlineService;
  82. /**
  83. * @Inject
  84. * @var SeparateAccountsServiceInterface
  85. */
  86. protected $separateAccountsService;
  87. /**
  88. * @Inject
  89. * @var GoodsActivityServiceInterface
  90. */
  91. protected $goodsActivityService;
  92. /**
  93. * @Inject
  94. * @var FinancialRecordServiceInterface
  95. */
  96. protected $financialService;
  97. public function index1(RequestInterface $request)
  98. {
  99. // $container = ApplicationContext::getContainer();
  100. // $exec = $container->get(TaskExecutor::class);
  101. // $result = $exec->execute(new Task([MethodTask::class, 'handle'], [Coroutine::id()]));
  102. // $client = ApplicationContext::getContainer()->get(SSDBTask::class);
  103. // $result = $client->exec("set","bar","1234");
  104. // $result = $client->exec("get","bar");
  105. // $client = ApplicationContext::getContainer()->get(MethodTask::class);
  106. // $result = $client->handle("set");
  107. // //$log = ApplicationContext::getContainer()->get(Log::class);
  108. // $log = $this->log;
  109. //
  110. // $log->push(['test'=>1,'user_id'=>290,'msg'=>'order']);
  111. // $log->event('t1',['test'=>1,'user_id'=>290,'msg'=>'order']);
  112. //
  113. // //$this->name = 'index1 action '. $result;
  114. // return $this->name;
  115. // $time = time();
  116. // $msgInfo = array(
  117. // 'user' => '13161443713@163.com',
  118. // 'stime' => $time,
  119. // 'sig' => sha1('13161443713@163.com' . 'XsaHzgePdyWTfcMX' . $time),
  120. // 'apiname' => 'Open_printMsg',
  121. // 'sn' => '920527381',
  122. // 'content' => '1111',
  123. // 'times' => 1//打印次数
  124. // );
  125. // $this->client = new FeiePrintClient('api.feieyun.cn', 80);
  126. // if (!$this->client->post('/Api/Open/', $msgInfo)) {
  127. // return '12';
  128. // } else {
  129. // //服务器返回的JSON字符串,建议要当做日志记录起来
  130. // $result = $this->client->getContent();
  131. // return $result;
  132. // }
  133. $globalOrderId = $this->request->input('order_main_id');
  134. // 查询订单
  135. $orderMain = OrderMain::query()
  136. ->where([
  137. 'global_order_id' => $globalOrderId,
  138. 'type' => OrderType::ONLINE,
  139. 'state' => OrderState::REFUNDING
  140. ])
  141. ->first();
  142. // 订单不存在
  143. if (empty($orderMain)) {
  144. $this->log->event(
  145. LogLabel::ORDER_OFFLINE_PAY_NOTIFY_LOG,
  146. ['global_order_id_fail' => $globalOrderId]
  147. );
  148. return true;
  149. }
  150. // 线下回调
  151. // $orderPaid = $this->orderOfflineService->doPaid($globalOrderId);
  152. // var_dump('orderOfflineService', $orderPaid);
  153. // $separate = $this->separateAccountsService->orderOfflinePaid($globalOrderId);
  154. // var_dump('separateAccountsService', $separate);
  155. //
  156. // // 喇叭通知,兼容旧音响,MQTT+IOT
  157. // $res = $this->mqttService->speakToStore($globalOrderId);
  158. // var_dump('mqttService', $res);
  159. // $res = $this->deviceService->pubMsgToStoreByOrderMainId($globalOrderId);
  160. // var_dump('deviceService', $res);
  161. //
  162. // // 公众号模板消息
  163. // $res = $this->miniprogramService->sendTemMsgForOfflineOrder($globalOrderId);
  164. // var_dump('miniprogramService', $res);
  165. // 线上回调
  166. // $res = $this->orderOnlineService->doByPaid($globalOrderId);
  167. // var_dump('orderOnlineService', $res);
  168. // $res = $this->separateAccountsService->orderOnlinePaid($globalOrderId);
  169. // var_dump('separateAccountsService', $res);
  170. //
  171. // // 优惠券返券
  172. // $res = $this->couponRebateService->couponRebateInTask($globalOrderId);
  173. // var_dump('couponRebateService', $res);
  174. //
  175. // // 喇叭通知,兼容旧音响,MQTT+IOT
  176. // $res = $this->mqttService->speakToStore($globalOrderId);
  177. // var_dump('mqttService', $res);
  178. // $res = $this->deviceService->pubMsgToStoreByOrderMainId($globalOrderId);
  179. // var_dump('deviceService', $res);
  180. //
  181. // // 公众号模板消息
  182. // $res = $this->miniprogramService->sendTemMsgForOnlineOrder($globalOrderId);
  183. // var_dump('miniprogramService', $res);
  184. //
  185. // // 打印订单,自动打印
  186. // $res = $this->feiePrintService->feiePrint($globalOrderId);
  187. // var_dump('feiePrintService', $res);
  188. // 退款回调
  189. // 添加退款时间
  190. $orderMain->refund_time = time();
  191. $orderMain->state = OrderState::REFUNDED;
  192. $res = $orderMain->save();
  193. var_dump('$orderMain', $res);
  194. // 退款返还优惠券
  195. $res = $this->couponService->orderRefundCoupons($orderMain->global_order_id);
  196. var_dump('couponService', $res);
  197. // 处理特价商品缓存
  198. $orderChildren = Order::query()->where(['order_main_id' => $orderMain->global_order_id])->get()->toArray();
  199. $orderGoods = OrderGoods::query()
  200. ->where(['activity_type' => 2])
  201. ->whereIn('order_id', array_values(array_column($orderChildren, 'id')))->get();
  202. foreach ($orderGoods as $key => &$item) {
  203. $this->goodsActivityService->clearCacheRecord($item['goods_id'], $item['number'], $orderMain->userId);
  204. }
  205. var_dump('$orderChildren', $orderChildren);
  206. // 添加用户的流水
  207. $res = $this->financialService->userByOLOrderRefund($orderMain->user_id, $orderMain->global_order_id, $orderMain->money);
  208. var_dump('financialService', $res);
  209. }
  210. public function index2(RequestInterface $request)
  211. {
  212. $this->name = 'index2 action';
  213. return $this->name;
  214. }
  215. public function index3(RequestInterface $request)
  216. {
  217. return $this->name;
  218. }
  219. }