123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311 |
- <?php
- namespace app\admin\controller;
- use app\common\controller\Backend;
- use app\main\constants\PayConstants;
- use app\main\service\AdminService;
- use app\main\service\FufenService;
- /**
- * 微信支付配置
- *
- * @icon fa fa-circle-o
- */
- class Wxpay extends Backend
- {
- protected $noNeedLogin = ['checkhostunique','checkappidunique'];
-
- /**
- * Wxpay模型对象
- */
- protected $model = null;
- protected $relationSearch = true;
- public function _initialize()
- {
- parent::_initialize();
- $this->model = model('Wxpay');
- $this->view->assign("isdefaultList", $this->model->getIsdefaultList());
- $this->view->assign("statusList", $this->model->getStatusList());
- $this->view->assign("fufenList", $this->model->getFufenList());
- $this->view->assign('paymentMethodList',$this->model->getPaymentMethodList());
- $this->assignconfig('paymentMethodList', json_encode($this->model->getPaymentMethodList()));
- $this->view->assign('isclosureList',$this->model->getIsclosureList());
- $this->view->assign('quartetIsSplit',$this->model->getQuartetIsSplit());
- $this->view->assign('dzPalmpaySubAccountList',$this->model->getDzPamlpaySubaccountList()); //获取四方支付分账点众子账户列表
- }
-
- /**
- * 默认生成的控制器所继承的父类中有index/add/edit/del/multi五个方法
- * 因此在当前控制器中可不用编写增删改查的代码,如果需要自己控制这部分逻辑
- * 需要将application/admin/library/traits/Backend.php中对应的方法复制到当前控制器,然后进行修改
- */
- /**
- * 查看
- */
- public function index()
- {
- //设置过滤方法
- $this->request->filter(['strip_tags']);
- if ($this->request->isAjax())
- {
- //如果发送的来源是Selectpage,则转发到Selectpage
- if ($this->request->request('pkey_name'))
- {
- return $this->selectpage();
- }
- list($where, $sort, $order, $offset, $limit) = $this->buildparams();
- $total = $this->model
- ->where($where)
- ->order($sort, $order)
- ->count();
- $list = $this->model
- ->with("platform")
- ->where($where)
- ->order($sort, $order)
- ->limit($offset, $limit)
- ->select();
- $result = array("total" => $total, "rows" => $list);
- return json($result);
- }
- $this->assignconfig('business',PayConstants::getBusinessLine());
- //拉取所有的appid
- $this->assignconfig("appidList", json_encode($this->model->column('appid')));
- return $this->view->fetch();
- }
- /**
- * 添加
- */
- public function add()
- {
- if ($this->request->isPost())
- {
- $params = $this->request->post("row/a");
- if ($params)
- {
- $params['business_line'] = implode(',',$params['business_line']);
- /*
- * 已经弃用,如果为了兼容老版可取消注释
- foreach ($params as $k => &$v)
- {
- $v = is_array($v) ? implode(',', $v) : $v;
- }
- */
- if ($this->dataLimit)
- {
- $params[$this->dataLimitField] = $this->auth->id;
- }
- try
- {
- //是否采用模型验证
- if ($this->modelValidate)
- {
- $name = basename(str_replace('\\', '/', get_class($this->model)));
- $validate = is_bool($this->modelValidate) ? ($this->modelSceneValidate ? $name . '.add' : true) : $this->modelValidate;
- $this->model->validate($validate);
- }
- if($params['status'] == 1){
- if($params['isdefault'] == 1){
- $data['isdefault'] = 0;
- $defaultRow = $this->model->where(["isdefault"=>1,"platform_id"=>$params['platform_id']])->find();
- if($defaultRow) {
- $defaultRow->allowField(true)->save($data);
- }
- $this->model->delCacheAll($defaultRow['id']);
- $this->model->delCacheByPlatformId($params['platform_id']);
- }
- }
- $result = $this->model->allowField(true)->save($params);
- if ($result !== false) {
- $this->model->delCachePayHost();
- if($payHosts = $this->model->getHosts()){
- foreach($payHosts as $val){
- $this->model->delCacheByHost($val);
- }
- }
- $this->success();
- }
- else
- {
- $this->error($this->model->getError());
- }
- }
- catch (\think\exception\PDOException $e)
- {
- $this->error($e->getMessage());
- }
- }
- $this->error(__('Parameter %s can not be empty', ''));
- }
- $this->assign('business',PayConstants::getBusinessLine());
- return $this->view->fetch();
- }
- /**
- * 编辑
- */
- public function edit($ids = NULL)
- {
- $row = $this->model->get($ids);
- if (!$row)
- $this->error(__('No Results were found'));
- $adminIds = $this->getDataLimitAdminIds();
- if (is_array($adminIds))
- {
- if (!in_array($row[$this->dataLimitField], $adminIds))
- {
- $this->error(__('You have no permission'));
- }
- }
- if ($this->request->isPost())
- {
- $params = $this->request->post("row/a");
- if ($params)
- {
- /*
- * 已经弃用,如果为了兼容老版可取消注释
- foreach ($params as $k => &$v)
- {
- $v = is_array($v) ? implode(',', $v) : $v;
- }
- */
- $params['business_line'] = implode(',',$params['business_line']);
- try
- {
- //是否采用模型验证
- if ($this->modelValidate)
- {
- $name = basename(str_replace('\\', '/', get_class($this->model)));
- $validate = is_bool($this->modelValidate) ? ($this->modelSceneValidate ? $name . '.edit' : true) : $this->modelValidate;
- $row->validate($validate);
- }
- if($params['platform_id'] != $row['platform_id'] && $params['isdefault'] ==1 && $row['isdefault'] == 1){
- $this->error("默认项不可更改平台");
- }
- //复粉支付修改状态时清空缓存
- if ($row['fufen'] && $params['status'] != $row['status']) {
- FufenService::instance()->clearChannelCacheByWxpayId($row['id']);
- }
- if($params['status'] != $row['status'] || $params['isdefault']!=$row['isdefault']){
- if($params['status'] == 1 && $params['isdefault'] == 1){
- $data['isdefault'] = 0;
- $defaultRow = $this->model->where(["isdefault" => 1, "platform_id" => $params['platform_id']])->where("id","not in",$ids)->find();
- if($defaultRow) {
- $defaultRow->allowField(true)->save($data);
- }
- $this->model->delCacheAll($defaultRow['id']);
- $this->model->delCacheByPlatformId($params['platform_id']);
- }elseif ($params['status'] == 0 && $params['isdefault'] == 1 && $row['isdefault'] == 1){
- //默认可以关闭 $this->error("默认项不可关闭");
- }elseif ($params['isdefault'] == 0 && $row['isdefault'] == 1){
- $this->error("默认项不可更改为非默认");
- }
- if ($params['status'] == 0 && $params['isdefault'] == 1) {
- //默认可以关闭 $this->error("变更默认项时,状态不可关闭");
- }
- if($params['status'] == 0 && $row['status'] == 1){ //关闭支付域名
- //检查是否有渠道正在使用
- if(model('AdminConfig')->where('wxpay_id',$row['id'])->find()){
- $this->error('有渠道的支付域名正在使用中,不能关闭');
- }
- if(model('AdminConfig')->where('menuwxpay_id',$row['id'])->find()){
- $this->error('有渠道的菜单支付域名正在使用中,不能关闭');
- }
- }
- }
- $result = $row->allowField(true)->save($params);
- if ($result !== false) {
- if($params['status'] == 1 && $params['isdefault'] == 1){
- $this->model->delCacheByPlatformId($params['platform_id']);
- }
- $this->model->delCacheAll($row['id']);
- $this->success();
- }
- else
- {
- $this->error($row->getError());
- }
- }
- catch (\think\exception\PDOException $e)
- {
- $this->error($e->getMessage());
- }
- }
- $this->error(__('Parameter %s can not be empty', ''));
- }
- $row['business_line'] = explode(',',$row['business_line']);
- if ($row['fufen']) {
- $row['fufen_disabled'] = (bool)FufenService::instance()->getFufenGroupModel()->where('find_in_set(' . $row['id'] . ',wxpay_ids)')->value('id');
- $row['fufen_tip'] = '复粉在用';
- } else {
- $row['fufen_disabled'] = (bool)AdminService::instance()->getAdminConfigModel()->where('wxpay_id', $ids)->whereOr('menuwxpay_id', $ids)->value('admin_id');
- $row['fufen_tip'] = '渠道在用';
- }
- $this->assign('business',PayConstants::getBusinessLine());
- $this->view->assign("row", $row);
- return $this->view->fetch();
- }
- /**
- * 检查支付域名是否唯一
- * @return \think\response\Json
- */
- public function checkhostunique(){
- $params = $this->request->param('row/a');
- if(isset($params['pay_host']) && !empty($params['pay_host'])){
- $map['pay_host'] = $params['pay_host'];
- //编辑检查
- if($this->request->has('id')){
- if($id = $this->request->get('id')){
- $map['id'] = ['neq',$id];
- }
- }
- if($this->model->where($map)->find()){
- return json(['code'=>600,'msg'=>'该支付域名已存在,请不要重复使用']);
- }
- return json(['code'=>200,'data'=>['ok'=>'支付域名可以使用']]);
- }
- return json(['code'=>600,'msg'=>'参数错误']);
- }
- /**
- * 检查支付Appid是否唯一
- * @return \think\response\Json
- */
- public function checkappidunique(){
- $params = $this->request->param('row/a');
- if(isset($params['appid']) && !empty($params['appid'])){
- $map['appid'] = $params['appid'];
- //编辑检查
- if($this->request->has('id')){
- if($id = $this->request->get('id')){
- $map['id'] = ['neq',$id];
- }
- }
- if($this->model->where($map)->find()){
- return json(['code'=>600,'msg'=>'该AppID已存在,请不要重复使用']);
- }
- return json(['code'=>200,'data'=>['ok'=>'AppID可以使用']]);
- }
- return json(['code'=>600,'msg'=>'参数错误']);
- }
- }
|