Wxpayfufen.php 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  1. <?php
  2. namespace app\admin\controller;
  3. use app\common\controller\Backend;
  4. use app\common\library\Redis;
  5. use app\main\constants\CacheConstants;
  6. use app\main\constants\PayConstants;
  7. use app\main\service\FufenService;
  8. /**
  9. * 微信支付配置
  10. *
  11. * @icon fa fa-circle-o
  12. */
  13. class Wxpayfufen extends Backend
  14. {
  15. /**
  16. * @var \app\common\model\Wxpay
  17. */
  18. protected $model = null;
  19. public function _initialize()
  20. {
  21. parent::_initialize();
  22. $this->model = model('Wxpay');
  23. $this->view->assign("statusList", $this->model->getStatusList());
  24. $this->view->assign("isClosureList", $this->model->getIsClosureList());
  25. $this->view->assign("isdefaultList", $this->model->getIsdefaultList());
  26. $this->view->assign("paymentMethodList", $this->model->getPaymentMethodList());
  27. $this->view->assign("quartetIsSplitList", $this->model->getQuartetIsSplitList());
  28. }
  29. /**
  30. * 默认生成的控制器所继承的父类中有index/add/edit/del/multi五个方法
  31. * 因此在当前控制器中可不用编写增删改查的代码,如果需要自己控制这部分逻辑
  32. * 需要将application/admin/library/traits/Backend.php中对应的方法复制到当前控制器,然后进行修改
  33. */
  34. public function index($ids = '')
  35. {
  36. $this->assignconfig('data', ['fufenid' => $ids]);
  37. if ($this->request->isAjax()) {
  38. list($where, $sort, $order, $offset, $limit) = $this->buildparams();
  39. $wxpayIdList = FufenService::instance()->getFufenGroupModel()->column('wxpay_ids');
  40. $whereCondition = [
  41. 'fufen' => PayConstants::WXPAY_FUFEN_ON,
  42. 'status' => PayConstants::WXPAY_STATUS_ON,
  43. ];
  44. if ($wxpayIdList) {
  45. $wxpayIds = [];
  46. foreach ($wxpayIdList as $ids) {
  47. $wxpayIds = array_merge($wxpayIds, explode(',', $ids));
  48. }
  49. $whereCondition['id'] = ['not in', array_unique($wxpayIds)];
  50. }
  51. $total = $this->model
  52. ->where($where)
  53. ->where($whereCondition)
  54. ->count();
  55. $list = $this->model
  56. ->where($where)
  57. ->where($whereCondition)
  58. ->limit($offset, $limit)
  59. ->select();
  60. return json(["total" => $total, "rows" => $list]);
  61. }
  62. return $this->view->fetch();
  63. }
  64. /**
  65. * 批量关联
  66. */
  67. public function batch_relation()
  68. {
  69. $channelids = $this->request->param('wxpay_ids');
  70. $fufenid = $this->request->param('fufen_id');
  71. $action = $this->request->param('action');
  72. $origin = FufenService::instance()->getFufenGroupModel()->where(['id' => $fufenid])->find();
  73. $origin_array = explode(',', $origin['wxpay_ids']);
  74. $params = explode(',', $channelids);
  75. if ($action == 'add') {
  76. $update = array_unique(array_merge($origin_array, $params));
  77. } else {
  78. $update = array_unique(array_diff($origin_array, $params));
  79. }
  80. $update = array_filter($update, function($value){
  81. return $value;
  82. });
  83. if ($origin['channel_ids']) {
  84. $channels = explode(',', $origin['channel_ids']);
  85. foreach ($channels as $channel_id) {
  86. Redis::instance()->del(CacheConstants::getChannelWxpayIds($channel_id));
  87. }
  88. }
  89. FufenService::instance()->getFufenGroupModel()->update(['wxpay_ids' => implode(',', $update)], ['id' => $fufenid]);
  90. $this->success();
  91. }
  92. public function show($ids = '')
  93. {
  94. $this->assignconfig('data', ['fufenid' => $ids]);
  95. if ($this->request->isAjax()) {
  96. $wxpayIds = FufenService::instance()->getFufenGroupModel()->where('id', $ids)->value('wxpay_ids');
  97. if ($wxpayIds) {
  98. $whereIds = [
  99. 'id' => ['in', $wxpayIds],
  100. 'fufen' => PayConstants::WXPAY_FUFEN_ON,
  101. ];
  102. list($where, $sort, $order, $offset, $limit) = $this->buildparams();
  103. $total = $this->model
  104. ->where($where)
  105. ->where($whereIds)
  106. ->count();
  107. $list = $this->model
  108. ->where($where)
  109. ->where($whereIds)
  110. ->limit($offset, $limit)
  111. ->select();
  112. return json(["total" => $total, "rows" => $list]);
  113. } else {
  114. return json(["total" => 0, "rows" => []]);
  115. }
  116. }
  117. return $this->view->fetch();
  118. }
  119. }