SokabeService.php 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194
  1. <?php
  2. namespace addons\AvoidTax\common\service;
  3. use addons\AvoidTax\common\enums\StatusEnum;
  4. use addons\AvoidTax\common\models\TaxConfig;
  5. use addons\AvoidTax\common\models\TaxOrder;
  6. use addons\AvoidTax\common\models\TaxOrderLog;
  7. use common\models\user\UserWithdrawLog;
  8. /**
  9. * SokabeService class
  10. * @package addons\AvoidTax\common\service
  11. */
  12. class SokabeService extends BaseService
  13. {
  14. /**
  15. * 手续费未成功的列表
  16. *
  17. * @param array $params
  18. * @return array
  19. */
  20. public function getTaxList(array $params = [])
  21. {
  22. $page = $this->getPage($params);
  23. $limit = $this->getLimit($params);
  24. return TaxOrder::getPageList($page, $limit, function($model) use ($params) {
  25. // 手续费未成功
  26. $batch_nums = TaxOrder::find()->where([
  27. 'mall_id' => $this->mall_id,
  28. 'sub_type' => 1,
  29. 'status' => 5,
  30. ])->select('batch_num');
  31. // 但是用户打款成功
  32. $model->with(['withdraw'])->where(['batch_num' => $batch_nums, 'status' => 1]);
  33. });
  34. }
  35. /**
  36. * 重新提交
  37. *
  38. * @param integer $id
  39. * @return boolean
  40. */
  41. public function resub(int $id)
  42. {
  43. $order = TaxOrder::find()->where([
  44. 'mall_id' => $this->mall_id, 'id' => $id, 'sub_type' => TaxOrder::SUB_TYPE_TAX
  45. ])->one();
  46. if (empty($order)) {
  47. return $this->error('订单不存在');
  48. }
  49. $type = (new TaxConfigService(['mall_id' => $this->mall_id]))->getType();
  50. $service = new OrderService(['mall_id' => $this->mall_id]);
  51. // 自用版手续费打款
  52. if ($type == TaxConfig::PERSONAL) {
  53. if ($service->transToTaxByOrder($order) === false) {
  54. return $this->error($service->getError());
  55. }
  56. }
  57. // 服务商版手续费打款
  58. if ($type == TaxConfig::SERVICE) {
  59. if ($service->bookTransToTaxByOrder($order) === false) {
  60. return $this->error($service->getError());
  61. }
  62. }
  63. return true;
  64. }
  65. /**
  66. * 列表
  67. *
  68. * @param array $params
  69. * @return array
  70. */
  71. public function getOrderList(array $params = [])
  72. {
  73. $page = $this->getPage($params);
  74. $limit = $this->getLimit($params);
  75. return TaxOrder::getPageList($page, $limit, function($model) use ($params) {
  76. $model->andWhere(['mall_id' => $this->mall_id])
  77. // ->andWhere(['status' => [-1, 1]])
  78. ->andWhere(['sub_type' => 1]);
  79. });
  80. }
  81. /**
  82. * 失败提交
  83. *
  84. * @param integer $id
  85. * @return boolean
  86. */
  87. public function toFail(int $id)
  88. {
  89. $order = TaxOrder::find()->where([
  90. 'mall_id' => $this->mall_id, 'id' => $id
  91. // , 'status' => [1, -1]
  92. , 'sub_type' => 1
  93. ])->one();
  94. if (empty($order)) {
  95. return $this->error('订单不存在');
  96. }
  97. if ($this->getConfigService()->isLYApiType()) {
  98. // 发送订单成功通知
  99. if ($this->getLyService()->asyncTransferResultNotifyNo($order) === false) {
  100. return $this->error('支付时异步请求接口请求失败');
  101. }
  102. }
  103. return true;
  104. }
  105. public function toSuccess(int $id)
  106. {
  107. $order = TaxOrder::find()->where(['id' => $id, 'sub_type' => 1])->one();
  108. if ($this->getConfigService()->isLYApiType()) {
  109. // 发送订单成功通知
  110. if ($this->getLyService()->asyncTransferResultNotifyOk($order) === false) {
  111. return $this->error('支付时异步请求接口请求失败');
  112. }
  113. }
  114. return true;
  115. }
  116. /**
  117. * @param array $params
  118. * @return array
  119. */
  120. public function getList(array $params = [])
  121. {
  122. return TaxOrder::getPageList(1, 20, function($model) use ($params) {
  123. $model->andWhere(['mall_id' => $this->mall_id])
  124. ->andWhere(['status' => 1])
  125. ->andWhere(['sub_type' => 2]);
  126. if (isset($params['keyword'])) {
  127. $model->andWhere([
  128. 'or',
  129. ['like', 'order_sn', '%' . $params['keyword'] . '%'],
  130. ['like', 'batch_num', '%' . $params['keyword'] . '%']
  131. ]);
  132. }
  133. });
  134. }
  135. /**
  136. * @param integer $id
  137. * @return boolean
  138. */
  139. public function subSuccess(int $id)
  140. {
  141. $order = TaxOrder::find()->where([
  142. 'mall_id' => $this->mall_id, 'id' => $id, 'sub_type' => 2, 'status' => 1
  143. ])->one();
  144. if (empty($order)) return $this->error('订单不存在');
  145. /**
  146. * @var OrderService
  147. */
  148. $service = new OrderService(['mall_id' => $this->mall_id]);
  149. $service->setUserOrder($order->userLog);
  150. $service->setSignUser($order->userLog->withdraw2);
  151. $service->setFeeOrder($order);
  152. if ($service->orderSuccess($order) === false) return $this->error($service->getError());
  153. $order->status = StatusEnum::STATUS_OUT_OK;
  154. $order->save();
  155. return true;
  156. }
  157. /**
  158. * @param integer $id
  159. * @return boolean
  160. */
  161. public function subFial(int $id)
  162. {
  163. $order = TaxOrder::find()->where([
  164. 'mall_id' => $this->mall_id, 'id' => $id, 'sub_type' => 2, 'status' => 1
  165. ])->one();
  166. if (empty($order)) return $this->error('订单不存在');
  167. return $this->error('未完善');
  168. return true;
  169. }
  170. }