SokabeController.php 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208
  1. <?php
  2. namespace addons\YunfastPay\backend\controllers;
  3. use addons\HiGo\common\listeners\order\store\CashierOrderPaidListener;
  4. use addons\Store\common\events\order\CashierOrderPaidEvent;
  5. use addons\Store\common\events\order\CashierOrderSettledEvent;
  6. use addons\Store\common\models\StoreCashierOrder;
  7. use addons\YunfastPay\common\services\AgentService;
  8. use addons\YunfastPay\common\services\NotifyService;
  9. use addons\YunfastPay\common\services\PayService;
  10. use addons\YunfastPay\common\services\RefundService;
  11. use addons\YunfastPay\common\services\SplitBillService;
  12. use addons\YunfastPay\common\services\StoreService;
  13. use addons\YunfastPay\common\services\trans\nocash\AgentTrans;
  14. use addons\YunfastPay\common\services\trans\nocash\ScanPayTrans;
  15. use addons\YunfastPay\common\services\YunPayService;
  16. use Yii;
  17. use yii\helpers\Json;
  18. /**
  19. * 测试
  20. * @package addons\YunfastPay\backend\controllers
  21. */
  22. class SokabeController extends BaseController
  23. {
  24. /**
  25. * 支付
  26. *
  27. * @return void
  28. */
  29. public function actionPay()
  30. {
  31. try {
  32. $service = new StoreService(['mall_id' => $this->mall_id]);
  33. $service->agentBySplitBillLogId(105);
  34. } catch (\Exception $e) {
  35. dd($e);
  36. }
  37. }
  38. /**
  39. * 代付
  40. *
  41. * @return void
  42. */
  43. public function actionAgent()
  44. {
  45. $service = new YunPayService(['mall_id' => $this->mall_id]);
  46. $agent = new AgentTrans(
  47. date('YmdHis') . rand(100, 999),
  48. 0.01,
  49. '6227003172460193052',
  50. '杨金城',
  51. '测试'
  52. );
  53. $service->sendPayRq($agent);
  54. }
  55. /**
  56. * 签约链接
  57. *
  58. * @return void
  59. */
  60. public function actionSign()
  61. {
  62. $service = new YunPayService(['mall_id' => $this->mall_id]);
  63. $url = $service->getSignUrl();
  64. dd($url);
  65. }
  66. public function actionScan()
  67. {
  68. $service = new YunPayService(['mall_id' => $this->mall_id]);
  69. $service->scanUrl();
  70. }
  71. public function actionCashier()
  72. {
  73. $id = 51;
  74. $order = StoreCashierOrder::findOne($id);
  75. // 触发门店收银台订单结算事件
  76. $event = new CashierOrderSettledEvent($this->mall_id);
  77. $order_data['order_no'] = $order['order_no'];
  78. $order_data['amount_received'] = 0.9;
  79. $order_data['user_id'] = $order['user_id'];
  80. $order_data['store_id'] = $order['store_id'];
  81. $order_data['mall_id'] = $order['mall_id'];
  82. $order_data['type'] = 2; //类型:1:o2o订单;2:o2o收银台订单
  83. Yii::$app->services->events->dispatch($event, $order_data, $event->listeners);
  84. }
  85. public function actionNotify()
  86. {
  87. $json = <<<EOR
  88. {
  89. "chanelType": "1",
  90. "channelssn": "4292974146842808321215",
  91. "chnlCd": "sft",
  92. "cityCode": "420600",
  93. "districtCode": "420684",
  94. "mchtCd": "MCHT100142019",
  95. "mchtName": "湖北盒兴信息科技有限公司",
  96. "mchtRate": "0.005",
  97. "mchtRateBase": "0.0035",
  98. "orderCd": "20230330221392742152914985",
  99. "orgCd": "202303021805019",
  100. "outMchtCd": "20230302hx",
  101. "outOrderId": "TX20230330143140723112837",
  102. "procCd": "660000",
  103. "provinceCode": "420000",
  104. "transAmt": "0.1",
  105. "transDatetime": "20230330151439",
  106. "transStatus": "100",
  107. "trscode": "TRANS0010",
  108. "txnNum": "1108"
  109. }
  110. EOR;
  111. $data = Json::decode($json);
  112. $service = new AgentService(['mall_id' => $this->mall_id]);
  113. // $service = new NotifyService(['mall_id' => $this->mall_id]);
  114. $service->notify($data);
  115. }
  116. public function actionRefund()
  117. {
  118. // $json = <<<JSON
  119. // {"id":"742","step_status":"6","address":{"consignee":null,"mobile":null,"address":null},"express":{"saler_express":null,"saler_express_no":null,"customer_name":null}}
  120. // JSON;
  121. // $data = Json::decode($json);
  122. $json = <<<JSON
  123. {
  124. "chanelType": "1",
  125. "channelssn": "MR20230401848927169949978624",
  126. "chnlCd": "sft",
  127. "cityCode": "420600",
  128. "districtCode": "420684",
  129. "mchtCd": "MCHT100142019",
  130. "mchtName": "湖北盒兴信息科技有限公司",
  131. "mchtRate": "0.005",
  132. "mchtRateBase": "0.0035",
  133. "orderCd": "20230401789137101353010735",
  134. "orgCd": "202303021805019",
  135. "outMchtCd": "20230302hx",
  136. "outOrderId": "r202304011412514046443398",
  137. "payType": "alipay",
  138. "procCd": "660000",
  139. "provinceCode": "420000",
  140. "transAmt": "0.06",
  141. "transDatetime": "20230401141331",
  142. "transStatus": "100",
  143. "trscode": "TRANS0002",
  144. "txnNum": "5301"
  145. }
  146. JSON;
  147. $data = Json::decode($json);
  148. $service = new RefundService(['mall_id' => $this->mall_id]);
  149. $service->notify($data);
  150. }
  151. public function actionLog()
  152. {
  153. $service = new NotifyService(['mall_id' => $this->mall_id]);
  154. $service->addFileLog('123', '123', [123]);
  155. }
  156. public function actionHai()
  157. {
  158. $event = new CashierOrderPaidEvent($this->mall_id);
  159. $order['id'] = 302;
  160. $order['operator_id'] = 0;
  161. $order['operator_name'] = '';
  162. Yii::$app->services->events->dispatch($event, $order, $event->listeners);
  163. }
  164. public function actionC()
  165. {
  166. $id = 51;
  167. $order = StoreCashierOrder::findOne($id);
  168. // 触发门店收银台订单结算事件
  169. $order_data['order_no'] = $order['order_no'];
  170. $order_data['amount_received'] = 0.9;
  171. $order_data['user_id'] = $order['user_id'];
  172. $order_data['store_id'] = $order['store_id'];
  173. $order_data['mall_id'] = $order['mall_id'];
  174. $order_data['type'] = 2; //类型:1:o2o订单;2:o2o收银台订单
  175. (new SplitBillService(['mall_id' => $order['mall_id']]))->divide($order_data);
  176. }
  177. }