123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135 |
- <?php
- namespace app\admin\controller;
- use app\common\controller\Backend;
- use app\common\library\Redis;
- use app\main\constants\CacheConstants;
- use app\main\constants\PayConstants;
- use app\main\service\FufenService;
- /**
- * 微信支付配置
- *
- * @icon fa fa-circle-o
- */
- class Wxpayfufen extends Backend
- {
- /**
- * @var \app\common\model\Wxpay
- */
- protected $model = null;
- public function _initialize()
- {
- parent::_initialize();
- $this->model = model('Wxpay');
- $this->view->assign("statusList", $this->model->getStatusList());
- $this->view->assign("isClosureList", $this->model->getIsClosureList());
- $this->view->assign("isdefaultList", $this->model->getIsdefaultList());
- $this->view->assign("paymentMethodList", $this->model->getPaymentMethodList());
- $this->view->assign("quartetIsSplitList", $this->model->getQuartetIsSplitList());
- }
-
- /**
- * 默认生成的控制器所继承的父类中有index/add/edit/del/multi五个方法
- * 因此在当前控制器中可不用编写增删改查的代码,如果需要自己控制这部分逻辑
- * 需要将application/admin/library/traits/Backend.php中对应的方法复制到当前控制器,然后进行修改
- */
- public function index($ids = '')
- {
- $this->assignconfig('data', ['fufenid' => $ids]);
- if ($this->request->isAjax()) {
- list($where, $sort, $order, $offset, $limit) = $this->buildparams();
- $wxpayIdList = FufenService::instance()->getFufenGroupModel()->column('wxpay_ids');
- $whereCondition = [
- 'fufen' => PayConstants::WXPAY_FUFEN_ON,
- 'status' => PayConstants::WXPAY_STATUS_ON,
- ];
- if ($wxpayIdList) {
- $wxpayIds = [];
- foreach ($wxpayIdList as $ids) {
- $wxpayIds = array_merge($wxpayIds, explode(',', $ids));
- }
- $whereCondition['id'] = ['not in', array_unique($wxpayIds)];
- }
- $total = $this->model
- ->where($where)
- ->where($whereCondition)
- ->count();
- $list = $this->model
- ->where($where)
- ->where($whereCondition)
- ->limit($offset, $limit)
- ->select();
- return json(["total" => $total, "rows" => $list]);
- }
- return $this->view->fetch();
- }
- /**
- * 批量关联
- */
- public function batch_relation()
- {
- $channelids = $this->request->param('wxpay_ids');
- $fufenid = $this->request->param('fufen_id');
- $action = $this->request->param('action');
- $origin = FufenService::instance()->getFufenGroupModel()->where(['id' => $fufenid])->find();
- $origin_array = explode(',', $origin['wxpay_ids']);
- $params = explode(',', $channelids);
- if ($action == 'add') {
- $update = array_unique(array_merge($origin_array, $params));
- } else {
- $update = array_unique(array_diff($origin_array, $params));
- }
- $update = array_filter($update, function($value){
- return $value;
- });
- if ($origin['channel_ids']) {
- $channels = explode(',', $origin['channel_ids']);
- foreach ($channels as $channel_id) {
- Redis::instance()->del(CacheConstants::getChannelWxpayIds($channel_id));
- }
- }
- FufenService::instance()->getFufenGroupModel()->update(['wxpay_ids' => implode(',', $update)], ['id' => $fufenid]);
- $this->success();
- }
- public function show($ids = '')
- {
- $this->assignconfig('data', ['fufenid' => $ids]);
- if ($this->request->isAjax()) {
- $wxpayIds = FufenService::instance()->getFufenGroupModel()->where('id', $ids)->value('wxpay_ids');
- if ($wxpayIds) {
- $whereIds = [
- 'id' => ['in', $wxpayIds],
- 'fufen' => PayConstants::WXPAY_FUFEN_ON,
- ];
- list($where, $sort, $order, $offset, $limit) = $this->buildparams();
- $total = $this->model
- ->where($where)
- ->where($whereIds)
- ->count();
- $list = $this->model
- ->where($where)
- ->where($whereIds)
- ->limit($offset, $limit)
- ->select();
- return json(["total" => $total, "rows" => $list]);
- } else {
- return json(["total" => 0, "rows" => []]);
- }
- }
- return $this->view->fetch();
- }
- }
|