721 行
28 KiB
PHP
可执行文件
721 行
28 KiB
PHP
可执行文件
<?php
|
|
|
|
namespace Admin\Controller;
|
|
|
|
use Common\Business\Plug;
|
|
use Common\Business\Role;
|
|
use Common\Model\JurisdictionUserModel;
|
|
use Common\Model\RetailAdminModel;
|
|
use Common\Model\RetailAgentModel;
|
|
use Common\Model\RetailMerchantModel;
|
|
use Common\Model\RetailPlugModel;
|
|
use Super\Business\ThirdErpSet;
|
|
use Think\Controller;
|
|
|
|
//[1.9.8]
|
|
class AgentController extends BaseController
|
|
{
|
|
//代理商信息展示管理
|
|
public function index()
|
|
{
|
|
$user = session('admin_userinfo');
|
|
$group = M('retail_group')->where(array('pid' => $user['pid']))->select();
|
|
$this->assign('group', json_encode($group));
|
|
$this->display();
|
|
}
|
|
|
|
public function getAgent()
|
|
{
|
|
//获取代理商信息
|
|
if (IS_POST) {
|
|
$Model = D('Agent');
|
|
$key = I('post.keyword');
|
|
if ($key) {
|
|
$condition['name'] = array('like', $key . "%");
|
|
$condition['phone'] = array('like', $key . "%");
|
|
$condition['_logic'] = 'or';
|
|
$map['_complex'] = $condition;
|
|
}
|
|
$discount = I('post.discountid');
|
|
if ($discount) {
|
|
$map['discountid'] = I('post.discountid');
|
|
}
|
|
$user = session('admin_userinfo');
|
|
$map['partnerid'] = $user['pid'];
|
|
$map['status'] = array('in', '1,2');
|
|
$map['type'] = 1;
|
|
$count = $Model->getCount($map);
|
|
$agentList = M('retail_agent')->where($map)->order('id desc')->page((int)$_POST['page'], (int)$_POST['limit'])->select();
|
|
foreach ($agentList as &$val) {
|
|
$curformat = 'Y-m-d';
|
|
$val['begin_time'] = newDate($curformat, $val['begin_time']);
|
|
$val['end_time'] = newDate($curformat, $val['end_time']);
|
|
$val['addtime'] = date('Y-m-d H:i:s', $val['addtime']);;
|
|
$val['image'] = C('shop_http') . $val['image'];
|
|
$val['groupname'] = M('retail_group')->where(array('id' => $val['discountid']))->getField('name');
|
|
if (!empty($val['bank_id'])) {
|
|
$val['bank_name'] = M('bank')->where(array('id' => $val['bank_id']))->getField("bank_name");
|
|
} else {
|
|
$val['bank_name'] = '';
|
|
}
|
|
}
|
|
if (!empty($agentList)) {
|
|
$rt['status'] = 1;
|
|
$rt['msg'] = '';
|
|
$rt['data'] = $agentList;
|
|
$rt['count'] = $count;
|
|
} else {
|
|
$rt['status'] = 1;
|
|
$rt['msg'] = '无代理商信息,请添加代理商';
|
|
$rt['data'] = [];
|
|
$rt['count'] = 0;
|
|
$rt['m'] = M()->_sql();
|
|
}
|
|
}
|
|
$this->ajaxReturn($rt);
|
|
}
|
|
|
|
/**
|
|
* 获取供选择的代理商
|
|
*/
|
|
public function getChooseAgent()
|
|
{
|
|
$AgentModel = new RetailAgentModel();
|
|
$list = $AgentModel->getSelect(['status' => ['in', '1,2']], 'id,name,status');
|
|
$this->ajaxReturn(callBack(statusCode()['success'], empty($list) ? '暂无数据' : '获取成功', $list));
|
|
}
|
|
|
|
//添加代理商页面addAgent
|
|
public function addAgent()
|
|
{
|
|
if (IS_POST) {
|
|
$id = I('post.id');
|
|
if (!empty($id)) {
|
|
$AgentModel = new RetailAgentModel();
|
|
$agent = $AgentModel->getFind(['id' => $id]);
|
|
|
|
$agent['begin_time'] = newDate('Y-m-d', $agent['begin_time']);
|
|
$agent['end_time'] = newDate('Y-m-d', $agent['end_time']);
|
|
$agent['bank_id'] = $agent['bank_id'] ? $agent['bank_id'] : '';
|
|
$this->ajaxReturn(callBack(statusCode()['success'], '获取成功', $agent));
|
|
}
|
|
} else {
|
|
$Plug = new Plug();
|
|
$systemPlug = $Plug->systemPlugState(['identification_arr' => ['moneyguestpay', 'lakalapay', 'happypay']]);
|
|
$this->assign('systemPlug', $systemPlug);
|
|
$this->display();
|
|
}
|
|
}
|
|
|
|
public function addAgentinfo()
|
|
{
|
|
if (IS_POST) {
|
|
//执行添加代理商的操作
|
|
$post = I('post.');
|
|
$user = session('admin_userinfo');
|
|
$AdminModel = new RetailAdminModel();
|
|
$juris = $AdminModel->getFindField(['phone' => $user['phone']], 'juris');
|
|
$agent['name'] = $post['name'];
|
|
$agent['status'] = 1;
|
|
$agent['type'] = 1;
|
|
$agent['begin_time'] = strtotime($post['begin_time']);
|
|
$agent['end_time'] = newStrToTime($post['end_time']);
|
|
$agent['phone'] = $post['phone'];
|
|
$agent['address'] = $post['address'];
|
|
$agent['province'] = $post['province'];
|
|
$agent['city'] = $post['city'];
|
|
$agent['area'] = $post['area'];
|
|
$agent['partnerid'] = $user['pid'];
|
|
$agent['image'] = $post['image'];
|
|
$agent['discountid'] = $post['discountid'];
|
|
$agent['agent_rate'] = $post['agent_rate'];
|
|
$agent['ali_rate'] = $post['ali_rate'];
|
|
$agent['wx_rate'] = $post['wx_rate'];
|
|
$agent['union_pay_rate'] = $post['union_pay_rate'];
|
|
$agent['happy_rate'] = $post['happy_rate'] ? $post['happy_rate'] : null;//代理商乐返费率
|
|
$agent['lakala_rate'] = $post['lakala_rate'] ? $post['lakala_rate'] : null;//代理商拉卡拉费率
|
|
$agent['qian_ke_rate'] = $post['qian_ke_rate'] ? $post['qian_ke_rate'] : null;//代理商钱客云费率
|
|
$agent['bank_card'] = $post['bank_card'];
|
|
$agent['bank_id'] = $post['bank_id'] ? $post['bank_id'] : null;
|
|
if ($agent['bank_card'] && $agent['bank_id'] == '' || $agent['bank_id'] && $agent['bank_card'] == '') {
|
|
$res['status'] = 0;
|
|
$res['msg'] = '请完善开户银行与银行卡号';
|
|
$this->ajaxReturn($res);
|
|
}
|
|
|
|
$AgentModel = new RetailAgentModel();
|
|
$JurUserModel = new JurisdictionUserModel();
|
|
if (empty($post['id'])) {
|
|
if (strlen($post['password']) > 16) {
|
|
$data['status'] = 0;
|
|
$data['msg'] = "密码长度不能大于16位";
|
|
$this->ajaxReturn($data);
|
|
}
|
|
$agent['addtime'] = time();
|
|
$agent['password'] = createPassword($post['password'], $agent['addtime']);
|
|
//添加代理商
|
|
$where['phone'] = $agent['phone'];
|
|
$agentInfo = $AgentModel->getFind($where);
|
|
if ($agentInfo) {
|
|
$data['status'] = 0;
|
|
$data['msg'] = "该手机号已注册";
|
|
$this->ajaxReturn($data);
|
|
}
|
|
if ($juris == 0) {
|
|
//无权添加
|
|
$data['status'] = 0;
|
|
$data['msg'] = "您无权添加代理商,请联系商家";
|
|
$this->ajaxReturn($data);
|
|
}
|
|
if ($juris == 1) {
|
|
//只能添加一个代理商
|
|
$oldAgent = $AgentModel->getCount(['partnerid' => $user['pid'], 'status' => 1]);
|
|
if ($oldAgent) {
|
|
$data['status'] = 0;
|
|
$data['msg'] = "您的权限只能添加一个代理商,请联系商家";
|
|
$this->ajaxReturn($data);
|
|
}
|
|
} else if ($juris != 2) {
|
|
$data['info'] = 4;
|
|
$data['status'] = 0;
|
|
$data['msg'] = "操作有误";
|
|
$this->ajaxReturn($data);
|
|
}
|
|
$re = $AgentModel->addOrder($agent);
|
|
if ($re) {
|
|
//添加ls_jurisdiction_user
|
|
$Role = new Role();
|
|
|
|
$jurData['login_name'] = $agent['phone'];
|
|
$jurData['password'] = $agent['password'];
|
|
$jurData['name'] = $agent['name'];
|
|
$jurData['add_time'] = $agent['addtime'];
|
|
$jurData['jurisdiction_group_id'] = $Role->createSystemGroup(['type' => 2]);
|
|
$jurData['user_type'] = 2;
|
|
$jurData['system_user_id'] = $re;
|
|
$jurData['pid'] = 1;
|
|
$jurAdd = $JurUserModel->addUser($jurData);
|
|
if ($jurAdd) {
|
|
$data['status'] = 1;
|
|
$data['msg'] = "添加成功";
|
|
} else {
|
|
$data['status'] = 0;
|
|
$data['msg'] = "系统发生错误,请联系服务商修改数据,否则该代理商将不能登录";
|
|
}
|
|
} else {
|
|
$data['status'] = 0;
|
|
$data['msg'] = "添加失败";
|
|
}
|
|
} else {
|
|
$agentInfo = $AgentModel->getFind(['id' => $post['id']]);
|
|
if (empty($agentInfo)) {
|
|
$data['status'] = 0;
|
|
$data['msg'] = "操作有误";
|
|
$this->ajaxReturn($data);
|
|
}
|
|
$map['id'] = ['neq', $post['id']];
|
|
$map['phone'] = $agent['phone'];
|
|
$map['status'] = 1;
|
|
$oldAgent = $AgentModel->getFind($map);
|
|
if (!empty($oldAgent) && $oldAgent['phone'] != $agent['phone']) {
|
|
$data['status'] = 0;
|
|
$data['msg'] = "该手机号已注册";
|
|
$this->ajaxReturn($data);
|
|
}
|
|
$map1['id'] = $post['id'];
|
|
$re = $AgentModel->updateOrder($map1, $agent);
|
|
if ($re !== false) {
|
|
//修改成功后修改ls_jurisdiction_user
|
|
if ($agentInfo['name'] != $agent['name'] || $agentInfo['phone'] != $agent['phone']) {
|
|
$jurMap['system_user_id'] = $post['id'];
|
|
$jurMap['user_type'] = 2;
|
|
$jurSave['login_name'] = $agent['phone'];
|
|
$jurSave['name'] = $agent['name'];
|
|
$jurUp = $JurUserModel->updateUser($jurMap, $jurSave);
|
|
if ($jurUp) {
|
|
$data['status'] = 1;
|
|
$data['msg'] = "修改成功";
|
|
} else {
|
|
$data['status'] = 0;
|
|
$data['msg'] = "数据库错误,请重试";
|
|
}
|
|
} else {
|
|
$data['status'] = 1;
|
|
$data['msg'] = "修改成功";
|
|
}
|
|
} else {
|
|
$data['status'] = 0;
|
|
$data['msg'] = "修改失败";
|
|
}
|
|
}
|
|
$this->ajaxReturn($data);
|
|
}
|
|
}
|
|
|
|
//省
|
|
public function Province()
|
|
{
|
|
$province = M('citys');
|
|
|
|
$prov = $province->where(array('parentid' => 0))->select();
|
|
return $prov;
|
|
}
|
|
|
|
//市
|
|
public function City()
|
|
{
|
|
$provinceid['parentid'] = $_POST['pro_id'];
|
|
$city = M('citys')->where($provinceid)->select();
|
|
$this->ajaxReturn($city);
|
|
}
|
|
|
|
public function Area()
|
|
{
|
|
$district = M('citys');
|
|
$cityid['parentid'] = $_POST['city_id'];
|
|
$districtinfo = $district->where($cityid)->select();
|
|
$this->ajaxReturn($districtinfo);
|
|
}
|
|
|
|
/**
|
|
* 禁用/启用代理商
|
|
*/
|
|
public function disableAgent()
|
|
{
|
|
$id = I('post.id');
|
|
$status = I('post.status');
|
|
$map['id'] = $id;
|
|
$AgentModel = new RetailAgentModel();
|
|
$re = $AgentModel->updateOrder($map, ['status' => $status]);
|
|
$JurisdictionUserModel = new JurisdictionUserModel();
|
|
$res = $JurisdictionUserModel->updateOrder(['system_user_id' => $id, 'user_type' => 2], ['status' => $status == 2 ? 0 : 1]);
|
|
if ($re) {
|
|
$data['status'] = 1;
|
|
$data['msg'] = "操作成功";
|
|
} else {
|
|
$data['status'] = 0;
|
|
$data['msg'] = "操作失败";
|
|
}
|
|
$this->ajaxReturn($data);
|
|
}
|
|
|
|
/**
|
|
* 删除代理商
|
|
*/
|
|
public function delAgent()
|
|
{
|
|
$id = I('post.id');
|
|
//查询该商户下有商家吗
|
|
$MerchantModel = new RetailMerchantModel();
|
|
$count = $MerchantModel->getCount(['agentid' => $id, 'status' => ['in', '1,2']]);
|
|
if ($count) {
|
|
$data['status'] = 0;
|
|
$data['msg'] = "无法删除,该代理商下已经有商户了";
|
|
} else {
|
|
$map['id'] = $id;
|
|
$AgentModel = new RetailAgentModel();
|
|
$re = $AgentModel->updateOrder($map, ['status' => 3]);
|
|
$JurisdictionUserModel = new JurisdictionUserModel();
|
|
$res = $JurisdictionUserModel->delUser(array('system_user_id' => $id, 'user_type' => 2));
|
|
if ($re) {
|
|
$data['status'] = 1;
|
|
$data['msg'] = "删除成功";
|
|
} else {
|
|
$data['status'] = 0;
|
|
$data['msg'] = "删除失败";
|
|
}
|
|
}
|
|
$this->ajaxReturn($data);
|
|
}
|
|
|
|
/**
|
|
* 修改商家的状态
|
|
*/
|
|
public function statusUpdate()
|
|
{
|
|
$status = I('post.status');
|
|
$merchant_id = I('post.id');
|
|
$map['id'] = $merchant_id;
|
|
$Merchant['status'] = $status;
|
|
$MerchantModel = new RetailMerchantModel();
|
|
$show = $MerchantModel->updateOrder($map, $Merchant);
|
|
if ($show !== false) {
|
|
$data['status'] = 1;
|
|
$data['msg'] = "操作成功";
|
|
} else {
|
|
$data['status'] = 0;
|
|
$data['msg'] = "操作失败";
|
|
}
|
|
$this->ajaxReturn($data);
|
|
}
|
|
|
|
//充值
|
|
public function recharge()
|
|
{
|
|
if (IS_POST) {
|
|
$user = session('admin_userinfo');
|
|
$data = I('post.');
|
|
$save = M('retail_agent')->where(array('id' => $data['id']))->setInc('money', $data['money']);
|
|
if ($save) {
|
|
$info['agentid'] = $data['id'];
|
|
$info['pid'] = $user['pid'];
|
|
$info['addtime'] = time();
|
|
$info['money'] = $data['money'];
|
|
$info['type'] = 1;
|
|
$add = M('retail_consum')->add($info);
|
|
if ($add) {
|
|
$res['status'] = 1;
|
|
$res['msg'] = '操作成功';
|
|
} else {
|
|
$res['status'] = 0;
|
|
$res['msg'] = '操作失败';
|
|
}
|
|
} else {
|
|
$res['status'] = 0;
|
|
$res['msg'] = '操作失败';
|
|
}
|
|
$this->ajaxReturn($res);
|
|
}
|
|
}
|
|
|
|
/*修改密码接口
|
|
* newpass 新密码
|
|
* id 代理商id
|
|
*/
|
|
public function newpass()
|
|
{
|
|
$pass = I('post.newpass');
|
|
$id = I('post.id');
|
|
if (!$pass || !$id) {
|
|
$res['status'] = 0;
|
|
$res['msg'] = '参数错误';
|
|
$this->ajaxReturn($res);
|
|
}
|
|
if (strlen($pass) > 16) {
|
|
$res['status'] = 0;
|
|
$res['msg'] = '密码不能大于16位';
|
|
$this->ajaxReturn($res);
|
|
}
|
|
$agent = M('retail_agent')->where(array('id' => $id))->find();
|
|
if (!empty($agent)) {
|
|
$CryptrModel = new \Addons\Api\Crypto ();
|
|
$newPass = $CryptrModel->encrypt($pass, date('YmdHis', $agent['addtime']));
|
|
if ($newPass != $agent['password']) {
|
|
$save = M('retail_agent')->where(array('id' => $id))->save(array('password' => $newPass));
|
|
$jurisdiction_user = M('jurisdiction_user')->where(array('system_user_id' => $agent['id'], 'user_type' => 2))->save(array('password' => $newPass));
|
|
if ($save && $jurisdiction_user) {
|
|
$res['status'] = 1;
|
|
$res['msg'] = '密码更新成功';
|
|
} else {
|
|
$res['status'] = 0;
|
|
$res['msg'] = '密码更新失败,请刷新重试';
|
|
}
|
|
} else {
|
|
$res['status'] = 0;
|
|
$res['msg'] = '您未修改密码';
|
|
}
|
|
}
|
|
$this->ajaxReturn($res);
|
|
}
|
|
|
|
//记录
|
|
public function record()
|
|
{
|
|
$this->display();
|
|
}
|
|
|
|
public function recordshow()
|
|
{
|
|
if (IS_POST) {
|
|
$agent_id = I('post.id');
|
|
$time = I('post.time');
|
|
$page = I('post.page');
|
|
$limit = I('post.limit');
|
|
if (!empty($time)) {
|
|
$where['addtime'] = ['between', [$time[0], $time[1]]];
|
|
}
|
|
$where['agentid'] = $agent_id;
|
|
$count = M('retail_consum')->where($where)->count();
|
|
$record = M('retail_consum')->where($where)->page($page, $limit)->order('id desc')->select();
|
|
foreach ($record as $key => &$val) {
|
|
$val['addtime'] = date('Y-m-d H:i:s', $val['addtime']);
|
|
if ($val['type'] == 1) {
|
|
$val['actualmoney'] = $val['money'];
|
|
$val['typename'] = '充值';
|
|
$val['discount'] = '无';
|
|
} else if ($val['type'] == 2) {
|
|
$val['typename'] = '消费';
|
|
}
|
|
}
|
|
$this->ajaxReturn(callBack(statusCode()['success'], !empty($record) ? '获取成功' : '暂无数据', [
|
|
'list' => $record ? $record : [],
|
|
'count' => (int)$count,
|
|
]));
|
|
}
|
|
|
|
}
|
|
|
|
//插件
|
|
public function agent_plug()
|
|
{
|
|
$id = I('get.id');
|
|
$agent = M('retail_agent')->where(array('id' => $id))->find();
|
|
$this->assign('agent', $agent);
|
|
$map = array(
|
|
array(
|
|
'p.origin_type' => 2,
|
|
'p.is_install' => 1
|
|
),
|
|
'p.origin_type' => 1,
|
|
'_logic' => 'OR',
|
|
);
|
|
$plug = M('plug as p')
|
|
->join('ls_plug_agent as a on a.plug_id=p.id AND a.agent_id=' . $id, 'LEFT')
|
|
->where($map)
|
|
->field('p.id,p.plug_name,p.icon_url,p.status,p.information,p.identification,a.a_status')
|
|
->select();
|
|
foreach ($plug as &$val) {
|
|
$val['status'] = $val['a_status'] == 1 ? true : false;
|
|
}
|
|
$this->assign('plugList', json_encode($plug));
|
|
$arr = array(
|
|
'doChangePlug' => '/index.php/Admin/Agent/doChangePlug', //修改插件状态
|
|
);
|
|
$authArr = checkFunction($arr);
|
|
$this->assign('authArr', $authArr);
|
|
$this->display();
|
|
}
|
|
|
|
public function doChangePlug()
|
|
{
|
|
$id = I('post.id');
|
|
$p_id = I('post.p_id');
|
|
$type = I('post.type');
|
|
$identification = I('post.identification');
|
|
if (empty($id) || empty($p_id) || empty($type)) {
|
|
$result['status'] = 0;
|
|
$result['msg'] = '缺少参数';
|
|
$this->ajaxReturn($result);
|
|
}
|
|
$agent = M('retail_agent')->where(array('id' => $id))->find();
|
|
if (empty($agent)) {
|
|
$result['status'] = 0;
|
|
$result['msg'] = '代理商不存在';
|
|
$this->ajaxReturn($result);
|
|
}
|
|
$PlugModel = new RetailPlugModel();
|
|
$plug = $PlugModel->getFind(array('id' => $p_id));
|
|
if (empty($plug)) {
|
|
$result['status'] = 0;
|
|
$result['msg'] = '插件不存在';
|
|
$this->ajaxReturn($result);
|
|
}
|
|
$map['plug_id'] = $p_id;
|
|
$map['agent_id'] = $id;
|
|
$p_plug = M('plug_agent')->where($map)->find();
|
|
switch ($type) {
|
|
case 1:
|
|
//开启
|
|
if (empty($p_plug)) {
|
|
//第一次添加
|
|
if ($identification == 'littlegift') {
|
|
//微礼插件判断接口是否配置
|
|
$ThirdClass = new ThirdErpSet();
|
|
$configResult = $ThirdClass->getList([
|
|
'identification' => $identification,
|
|
'fields' => 'route_url,type,route_name'
|
|
]);
|
|
if (empty($configResult['data'])) {
|
|
$result['status'] = 0;
|
|
$result['msg'] = '请先配置插件的基本信息';
|
|
$this->ajaxReturn($result);
|
|
}
|
|
$verifyResult = $ThirdClass->littleConfigure($configResult['data']);
|
|
if ($verifyResult['status'] != 1) {
|
|
$result['status'] = 0;
|
|
$result['msg'] = $verifyResult['message'];
|
|
$this->ajaxReturn($result);
|
|
}
|
|
}
|
|
$item['plug_id'] = $p_id;
|
|
$item['agent_id'] = $id;
|
|
$item['addtime'] = time();
|
|
$item['opentime'] = time();
|
|
$item['a_status'] = 1;
|
|
$add = M('plug_agent')->add($item);
|
|
if ($add) {
|
|
$result['status'] = 1;
|
|
$result['msg'] = '开启成功';
|
|
} else {
|
|
$result['status'] = 0;
|
|
$result['msg'] = '开启失败';
|
|
}
|
|
} else if ($p_plug['a_status'] == 2) {
|
|
$open = M('plug_agent')->where($map)->save(array('a_status' => 1, 'opentime' => time()));
|
|
if ($open) {
|
|
$result['status'] = 1;
|
|
$result['msg'] = '开启成功';
|
|
} else {
|
|
$result['status'] = 0;
|
|
$result['msg'] = '开启失败';
|
|
}
|
|
} else {
|
|
$result['status'] = 0;
|
|
$result['msg'] = '操作失败';
|
|
}
|
|
break;
|
|
case 2:
|
|
//关闭
|
|
if (empty($p_plug)) {
|
|
//未开启过
|
|
$result['status'] = 1;
|
|
$result['msg'] = '关闭成功';
|
|
} else if ($p_plug['a_status'] == 1) {
|
|
if ($identification == 'littlegift') {
|
|
//微礼插件不能随便关闭
|
|
$MerchantModel = new RetailMerchantModel();
|
|
$merchant_id = $MerchantModel->getFindField([
|
|
'agentid' => $id,
|
|
'status' => ['neq', 3],
|
|
'platform_type' => 2
|
|
], 'id');
|
|
if (!empty($merchant_id)) {
|
|
$result['status'] = 0;
|
|
$result['msg'] = '该代理商下有商户使用了Q3 ERP,无法关闭';
|
|
$this->ajaxReturn($result);
|
|
}
|
|
}
|
|
$PlugModel = new RetailPlugModel();
|
|
$PlugModel->closeAgentPlug($p_id, $id, $identification);
|
|
$result['status'] = 1;
|
|
$result['msg'] = '关闭成功';
|
|
} else {
|
|
$result['status'] = 0;
|
|
$result['msg'] = '操作失败';
|
|
}
|
|
break;
|
|
default:
|
|
$result['status'] = 0;
|
|
$result['msg'] = '访问有误';
|
|
}
|
|
$this->ajaxReturn($result);
|
|
}
|
|
|
|
/* 加载支付设置模板
|
|
* */
|
|
public function pay_pattern($id)
|
|
{
|
|
if (!$id) {
|
|
$this->assign('pay_list', json_encode(array()));
|
|
} else {
|
|
$pay_set = M('retail_pay_pattern')->where(array('agent_id' => $id))->find();
|
|
if (!$pay_set) {
|
|
$data['agent_id'] = $id;
|
|
M('retail_pay_pattern')->add($data);
|
|
$pay_set = M('retail_pay_pattern')->where(array('agent_id' => $id))->find();
|
|
}
|
|
$pay_list = array();
|
|
|
|
$Plug = new Plug();
|
|
$agentPlug = $Plug->agentPlugState(['agent_id' => $id, 'identification_arr' => ['moneyguestpay', 'lakalapay', 'happypay']]);
|
|
|
|
$plugPay = ['happy_pay' => 'happypay', 'lakala_pay' => 'lakalapay', 'qian_ke_pay' => 'moneyguestpay'];
|
|
|
|
foreach ($pay_set as $key => &$val) {
|
|
if ($key == 'id' || $key == 'agent_id' || strpos($key, '_name')) {
|
|
continue;
|
|
} else if (!isset($plugPay[$key]) || isset($plugPay[$key]) && $agentPlug[$plugPay[$key]]) {
|
|
$name = $pay_set[$key . '_name'] ? $pay_set[$key . '_name'] : '其他支付模式';
|
|
array_push($pay_list, array('name' => $name, 'key' => $key, 'status' => $val == 1 ? true : false));
|
|
}
|
|
}
|
|
$AgentModel = D('RetailAgent');
|
|
$map = array(
|
|
$AgentModel::ID => $id,
|
|
);
|
|
$set_server_pay = $AgentModel->getFindField($map, $AgentModel::SET_SERVER_PAY);
|
|
$this->assign('agent_id', $id);
|
|
$this->assign('set_server_pay', $set_server_pay);
|
|
$this->assign('pay_id', $pay_set['id']);
|
|
$arr = array(
|
|
'update_status' => '/index.php/Admin/Agent/update_status', //修改支付状态
|
|
);
|
|
$authArr = checkFunction($arr);
|
|
$this->assign('authArr', $authArr);
|
|
$this->assign('pay_list', json_encode($pay_list));
|
|
}
|
|
$this->display();
|
|
}
|
|
|
|
/* 修改支付状态
|
|
* @param
|
|
* $agent_id
|
|
* @param
|
|
* $status
|
|
* @return array
|
|
* */
|
|
public function update_status()
|
|
{
|
|
$id = I('post.id');
|
|
$key = I('post.key');
|
|
$status = I('post.status') ? I('post.status') : 0;
|
|
//$agent_id = I('post.agent_id');
|
|
if (!$id || !$key) {
|
|
$res['status'] = 0;
|
|
$res['msg'] = '参数缺失';
|
|
$this->ajaxReturn($res);
|
|
}
|
|
$find = M('retail_pay_pattern')->where(array('id' => $id))->find();
|
|
if (!$find) {
|
|
$res['status'] = 0;
|
|
$res['msg'] = '查询失败';
|
|
$this->ajaxReturn($res);
|
|
}
|
|
$save = M('retail_pay_pattern')->where(array('id' => $id))->save(array($key => $status));
|
|
if ($save) {
|
|
$res['status'] = 1;
|
|
$res['msg'] = '修改成功';
|
|
} else {
|
|
$res['status'] = 0;
|
|
$res['msg'] = '修改失败';
|
|
}
|
|
$this->ajaxReturn($res);
|
|
}
|
|
|
|
public function updateServerStatus()
|
|
{
|
|
$set_server_pay = I('post.set_server_pay');
|
|
$agent_id = I('post.agent_id');
|
|
if (empty($agent_id) || !isset($set_server_pay)) {
|
|
$res['status'] = 0;
|
|
$res['msg'] = '请求有误';
|
|
$this->ajaxReturn($res);
|
|
}
|
|
$AgentModel = D('RetailAgent');
|
|
$map = array(
|
|
$AgentModel::ID => $agent_id,
|
|
);
|
|
$save = array(
|
|
$AgentModel::SET_SERVER_PAY => $set_server_pay
|
|
);
|
|
$update = $AgentModel->updateOrder($map, $save);
|
|
if ($update) {
|
|
$res['status'] = 1;
|
|
$res['msg'] = '修改成功';
|
|
} else {
|
|
$res['status'] = 0;
|
|
$res['msg'] = '修改失败';
|
|
}
|
|
$this->ajaxReturn($res);
|
|
}
|
|
}
|
|
|
|
function newStrToTime($str_time)
|
|
{
|
|
$result = strtotime($str_time);
|
|
if (empty($result)) {
|
|
$date = new \DateTime($str_time);
|
|
$result = $date->format('U');
|
|
}
|
|
return $result;
|
|
} |