$user['id'], ); $set_server_pay = $AgentModel->getFindField($map, $AgentModel::SET_SERVER_PAY); $this->assign('set_server_pay', $set_server_pay); $this->display(); } public function getMerchant() { //获取商户信息 if (IS_POST) { $key = I('post.keyword'); $page = I('post.page'); $limit = I('post.limit'); if (!empty($key)) { $map['name|mobile'] = array("like", "%" . $key . "%"); } $user = session('agent_userinfo'); $map['partnerid'] = $user['partnerid']; $map['agentid'] = $user['id']; $map['status'] = ['in', '1,2']; $MerchantModel = new RetailMerchantModel(); $StoreModel = new RetailStoreModel(); $list = $MerchantModel->getSelect($map, '*', 'id desc', $page . ',' . $limit); $count = $MerchantModel->getCount($map); foreach ($list as &$val) { $val['addtime'] = newDate('Y-m-d H:i:s', $val['addtime']); $val['begin_time'] = newDate('Y-m-d H:i:s', $val['begin_time']); $val['end_time'] = newDate('Y-m-d H:i:s', $val['end_time']); $val['meal_name'] = M('retail_meal')->where(array('id' => $val['mealid']))->getField('name'); //剩余可创建数量 $store_num = $StoreModel->getCount(['merchantid' => $val['id'], 'state' => 0]); $val['less_count'] = round($val['storenum'] - $store_num); } $this->ajaxReturn(callBack(statusCode()['success'], !empty($list) ? '获取成功' : '暂无数据', [ 'list' => $list, 'count' => $count ])); } } /** * 获取供选择的商户列表 */ public function getChooseMerchant() { $MerchantModel = new RetailMerchantModel(); $user = session('agent_userinfo'); $map = [ 'agentid' => $user['id'], 'status' => ['in', '1,2'], ]; $list = $MerchantModel->getSelect($map, 'id,name,status', 'id desc'); $this->ajaxReturn(callBack(statusCode()['success'], empty($list) ? '暂无数据' : '获取成功', [ 'list' => $list ? $list : []] )); } //添加商户 public function addMerchant() { if (IS_POST) { //执行添加商户的操作 $user = session('agent_userinfo'); $post = I('post.'); $time = $_SERVER['REQUEST_TIME']; //商户类型 1默认系统 2微礼平台 $platform_type = $post['platform_type'] ? $post['platform_type'] : 1; switch ($platform_type) { case 2: //微礼平台 $PlugClass = new Plug(); $plugResult = $PlugClass->agentPlugPermissions([ 'agent_id' => $user['id'], 'identification_arr' => ['littlegift'] ]); $plug_littlegift = $plugResult['data']['littlegift'] ? $plugResult['data']['littlegift'] : ''; if (!empty($plug_littlegift)) { $verify_arr = [ 'agent_id' => $user['id'], 'platform_type' => $platform_type, 'littlegift' => $post['littlegift'], 'route_list' => $post['route_list'], 'merchant_id' => $post['id'] ? $post['id'] : 0 ]; $MerchantClass = new Merchant(); $verifyResult = $MerchantClass->thirdAddMerchantVerify($verify_arr); if ($verifyResult['status'] != 1) { $res['status'] = 0; $res['msg'] = $verifyResult['message']; $this->ajaxReturn($res); } $littlegift = json_decode($post['littlegift'], true); //基本配置 $littlegift['token'] = $verifyResult['data']['token'];//验签 } break; } $MerchantData['name'] = $post['name']; $MerchantData['province'] = $post['pro']; $MerchantData['city'] = $post['city']; $MerchantData['area'] = $post['area']; $MerchantData['mobile'] = $post['mobile']; $MerchantData['address'] = $post['address']; $MerchantData['status'] = 1; $MerchantData['merchant_rate'] = $post['merchant_rate'] ? $post['merchant_rate'] : 0; $MerchantData['ali_rate'] = $post['ali_rate'] ? $post['ali_rate'] : 0; $MerchantData['wx_rate'] = $post['wx_rate'] ? $post['wx_rate'] : 0; $MerchantData['union_pay_rate'] = $post['union_pay_rate'] ? $post['union_pay_rate'] : null; $MerchantData['happy_rate'] = $post['happy_rate'] ? $post['happy_rate'] : null;//商户乐返费率 $MerchantData['lakala_rate'] = $post['lakala_rate'] ? $post['lakala_rate'] : null;//商户拉卡拉费率 $MerchantData['qian_ke_rate'] = $post['qian_ke_rate'] ? $post['qian_ke_rate'] : null;//商户钱客云费率 $MerchantModel = new RetailMerchantModel(); if (empty($post['id'])) { $time_limit = $post['time_limit']; $end_time = $post['end_time']; $MerchantData['platform_type'] = $platform_type; $MerchantData['mealid'] = $post['mealid']; $MerchantData['addtime'] = $time; $MerchantData['begin_time'] = strval(strtotime(date("Y-m-d 00:00:00", time()))); if (empty($MerchantData['name']) || empty($MerchantData['address']) || empty($MerchantData['mobile']) || empty($time_limit) || empty($MerchantData['mealid'])) { $res['status'] = 0; $res['msg'] = "表单信息有误,请重新操作"; $this->ajaxReturn($res); } if ($time_limit == 7) { //自定义时间 if (empty($end_time)) { $res['status'] = 0; $res['msg'] = "自定义时间有误"; $this->ajaxReturn($res); } if (strtotime($end_time) < time()) { $res['status'] = 0; $res['msg'] = "过期时间不能小于当前时间"; $this->ajaxReturn($res); } } //手机号不能重复 $map['status'] = array('in', '1,2'); $map['mobile'] = $MerchantData['mobile']; $existence = $MerchantModel->getFind($map); if ($existence) { $data['status'] = 0; $data['msg'] = "手机号已被使用,请重新完善信息"; $this->ajaxReturn($data); } if (strlen($post['password']) > 16) { $data['status'] = 0; $data['msg'] = "密码不能大于16位"; $this->ajaxReturn($data); exit; } $MerchantData['password'] = createPassword($post['password'], $MerchantData['addtime']); //添加商户 $MerchantData['partnerid'] = $user['partnerid']; $MerchantData['agentid'] = $user['id']; //时限 switch ($time_limit) { case 1: $MerchantData['end_time'] = strtotime("+1 month" . "24:00:00"); break; case 2: $MerchantData['end_time'] = strtotime("+3 month" . "24:00:00"); break; case 3: $MerchantData['end_time'] = strtotime("+6 month" . "24:00:00"); break; case 4: $MerchantData['end_time'] = strtotime("+1 year" . "24:00:00"); break; case 5: $MerchantData['end_time'] = strtotime("+2 year" . "24:00:00"); break; case 6: $MerchantData['end_time'] = strtotime("+3 year" . "24:00:00"); break; case 7: $MerchantData['end_time'] = newStrToTime($end_time . "24:00:00"); break; } $userinfo = M('retail_agent')->where(array('id' => $user['id']))->find(); if (!$userinfo) { $res['status'] = 0; $res['msg'] = '登录超时'; $this->ajaxReturn($res); } //折扣 $discount = M('retail_group')->where(array('id' => $userinfo['discountid']))->getField('discount'); $discount = $discount ? $discount : 1; //单价 $unitproce = M('retail_meal_price')->where(array('meal_id' => $MerchantData['mealid'], 'time_limit' => $time_limit))->getField('price'); if ($time_limit == 7) { //自定义时间 $start_time = strtotime(date('Y-m-d', $MerchantData['begin_time'])); $end_time = newStrToTime($end_time . "24:00:00"); $dat_num = (($end_time - $start_time) / 86400) * 1; $unitproce = $dat_num * $unitproce; } if ($unitproce < 0) { $res['status'] = 0; $res['msg'] = '价格不能小于0'; $this->ajaxReturn($res); } //该扣除的价格 $reduce = round($unitproce * $discount, 2); //判断是否可以减 $surplus = $userinfo['money'] - $reduce; if ($surplus > 0 || $surplus == 0) { $success = M('retail_agent')->where(array('id' => $userinfo['id']))->setDec('money', $reduce); if ($success || $reduce == 0) { $merchant_id = $MerchantModel->addOrder($MerchantData); if (!empty($merchant_id)) { $consum['addtime'] = $time; $consum['money'] = $unitproce; $consum['actualmoney'] = $reduce; $consum['discount'] = $discount; $consum['agentid'] = $user['id']; $consum['type'] = 2; $consuminfo = M('retail_consum')->add($consum); $reagent = M('retail_agent')->where(array('id' => $user['id']))->find(); $readmin = M('retail_admin')->where(array('id' => $reagent['partnerid']))->field('phone,name')->find(); $shop['addtime'] = time(); $shop['begin_time'] = $MerchantData['begin_time']; $shop['end_time'] = $MerchantData['end_time']; $shop['site'] = C('adminhttp'); $shop['phone'] = $readmin['phone']; $shop['name'] = $readmin['name']; $shop['appid'] = 4; if ($consuminfo) { //添加默认仓库 $content = [ 'name' => '默认采购仓', 'number' => 'A_001', 'province' => '北京', 'city' => '北京市', 'area' => '海淀区', 'address' => '北京市海淀区', 'measure_area' => 100, 'person_name' => '小李', 'person_phone' => '18888888888', 'merchant_id' => $merchant_id ]; $WarehouseClass = new Warehouse(); $WarehouseClass->merchantPurchaseWarehouseOperation($content); $content['name'] = '默认供给仓'; $WarehouseClass->merchantSaleWarehouseOperation($content); //添加基本配置 $ConfigModel = new RetailMerchantConfigModel(); $basic_config = [ 'merchant_id' => $merchant_id, 'add_time' => $time, ]; $ConfigModel->addOrder($basic_config); //添加ls_jurisdiction_user $Role = new Role(); $jurData['login_name'] = $MerchantData['mobile']; $jurData['password'] = $MerchantData['password']; $jurData['name'] = $MerchantData['name']; $jurData['add_time'] = $MerchantData['addtime']; $jurData['jurisdiction_group_id'] = $Role->createSystemGroup(['type' => 3, 'platform_type' => $platform_type]); $jurData['user_type'] = 3; $jurData['system_user_id'] = $merchant_id; $jurData['pid'] = session('jurisdiction_user')['id']; $jurAdd = D('JurisdictionUser')->addUser($jurData); $url = "http://console.mobzhifu.com/index.php/VersionApi/Agent/addMerchant"; $re = http_request($url, $shop); $data['status'] = 1; $data['msg'] = "添加成功"; } else { $data['status'] = 0; $data['msg'] = "添加失败"; } } else { $data['status'] = 0; $data['msg'] = "添加失败"; } } else { $data['status'] = 0; $data['msg'] = "操作失败"; } } else { $data['status'] = 0; $data['msg'] = "余额不足,请联系商家充值"; } } else { $map['id'] = $post['id']; $map['status'] = ['in', '1,2']; //手机号不能重复 $oldMerchant = D('RetailMerchant')->getFind($map); if ($oldMerchant['mobile'] != $MerchantData['mobile']) { $wh['status'] = ['in', '1,2']; $wh['mobile'] = $MerchantData['mobile']; $existence = D('RetailMerchant')->getFind($wh); if ($existence) { $data['status'] = 0; $data['msg'] = "手机号已被使用,请重新完善信息"; $this->ajaxReturn($data); exit; } } $re = D('RetailMerchant')->updateOrder($map, $MerchantData); $up['login_name'] = $MerchantData['mobile']; $up['name'] = $MerchantData['name']; $ret1 = D('JurisdictionUser')->updateUser(array('system_user_id' => $oldMerchant['id'], 'user_type' => 3), $up); if ($re !== false) { $data['num'] = $MerchantData['storenum']; $data['status'] = 1; $data['msg'] = "修改成功"; } else { $data['status'] = 0; $data['msg'] = "修改失败"; } $merchant_id = $post['id']; } //平台参数配置 if (!empty($merchant_id) && !empty($plug_littlegift)) { switch ($platform_type) { case 2: //微礼平台参数配置 //第三方平台的配置参数 $MerchantConfigClass = new MerchantConfig(); $result = $MerchantConfigClass->addThirdConfig([ 'merchant_id' => $merchant_id, 'platform_type' => 2, 'info' => json_encode($littlegift) ]); if ($result['status'] != 1) { $data['msg'] = $data['msg'] . $result['message']; } //商户与第三方平台的接口路径关联信息 $result = $MerchantConfigClass->ThirdErpSetOperation([ 'merchant_id' => $merchant_id, 'info' => $post['route_list'] ]); if ($result['status'] != 1) { $data['msg'] = $data['msg'] . $result['message']; } break; } } $this->ajaxReturn($data); } else { $user = session('agent_userinfo'); $prov = $this->Province(); $this->assign('prov', $prov); //套餐 $meal = M('retail_meal')->where(array('pid' => $user['partnerid']))->select(); $this->assign('meal', $meal); //折扣 $group = M('retail_group')->where(array('id' => $user['discountid']))->getField('discount'); $this->assign('discount', $group); //判断第三方平台权限 $PlugClass = new Plug(); $agentPlug = $PlugClass->agentPlugState([ 'agent_id' => $user['id'], 'identification_arr' => ['moneyguestpay', 'lakalapay', 'happypay', 'littlegift']]); $this->assign('agentPlug', $agentPlug); $this->assign('littlegift', $agentPlug['littlegift'] ? 1 : 0); $route_list = []; $config = []; $id = I('get.id'); if (!empty($id)) { $map['id'] = $id; $map['status'] = ['in', '1,2']; $cache = D('RetailMerchant')->getFind($map); $this->assign('cache', $cache); //微礼第三方平台信息 if (!empty($agentPlug['littlegift']) && $cache['platform_type'] == 2) { $MerchantClass = new Merchant(); $result = $MerchantClass->thirdSetList([ 'merchant_id' => $cache['id'], 'identification' => 'littlegift' ]); $route_list = $result['data']; $config = $MerchantClass->thirdConfigInfo([ 'merchant_id' => $cache['id'], 'platform_type' => 2 ]); $config = $config['data']; } } else { //微礼第三方平台信息 if (!empty($agentPlug['littlegift'])) { $ThirdClass = new ThirdErpSet(); $result = $ThirdClass->getList([ 'identification' => 'littlegift', 'fields' => 'id,type,route_url,route_name' ]); $route_list = $result['data']; if (!empty($route_list)) { foreach ($route_list as $key => &$val) { $val['status'] = 1; } } } } $this->assign('route_list', $route_list); //接口路径列表 $this->assign('config', $config); //域名配置 $this->display(); } } public function Province() { $province = M('citys'); $prov = $province->where(array('parentid' => 0))->select(); return $prov; } //时限 public function timeLimit() { $id = I("post.id"); if (!$id) { $res['status'] = 0; $res['msg'] = '登录超时'; $this->ajaxReturn($res); } $where['meal_id'] = $id; $where['price'] = array('exp', 'is not null'); $info = M('retail_meal_price')->where($where)->select(); foreach ($info as $key => &$val) { switch ($val['time_limit']) { case 1: $val['time_limit_name'] = "月"; break; case 2: $val['time_limit_name'] = "季度"; break; case 3: $val['time_limit_name'] = "半年"; break; case 4: $val['time_limit_name'] = "一年"; break; case 5: $val['time_limit_name'] = "二年"; break; case 6: $val['time_limit_name'] = "三年"; break; case 7: $val['time_limit_name'] = "自定义"; break; } } $res['status'] = 1; $res['data'] = $info; $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); } $merchant = M('retail_merchant')->where(array('id' => $id))->find(); if (!empty($merchant)) { $newPass = createPassword($pass, $merchant['addtime']); $save = M('retail_merchant')->where(array('id' => $id))->save(array('password' => $newPass)); $JurUserModel = new JurisdictionUserModel(); $jurisdiction_user = $JurUserModel->updateOrder(['system_user_id' => $merchant['id'], 'user_type' => 3], ['password' => $newPass]); if ($save || $jurisdiction_user) { $res['status'] = 1; $res['msg'] = '密码更新成功'; } else { $res['status'] = 0; $res['msg'] = '您未修改密码'; } } $this->ajaxReturn($res); } //市 public function City() { $city = M('citys'); $provinceid['parentid'] = $_POST['pro_id']; $cityinfo = $city->where($provinceid)->select(); $opt = ''; foreach ($cityinfo as $key => $value) { if ($value['cityid'] == I('post.check')) { $opt .= ""; } else { $opt .= ""; } } echo json_encode($opt); } public function Area() { $district = M('citys'); $cityid['parentid'] = $_POST['city_id']; $districtinfo = $district->where($cityid)->select(); $opt = ''; foreach ($districtinfo as $key => $value) { if ($value['cityid'] == I('post.check')) { $opt .= ""; } else { $opt .= ""; } } echo json_encode($opt); } /** * 删除商户 */ public function delMerchant() { $id = I('post.id'); //查询该商户下有商家吗 $map['merchantid'] = $id; $map['state'] = 0; $count = M('retail_store')->where($map)->count(); if ($count) { $data['status'] = 0; $data['msg'] = "无法删除,该商户下已经有门店了"; } else { $re = D('RetailMerchant')->updateOrder(['id' => $id], ['status' => 3]); $res = D('JurisdictionUser')->delUser(['system_user_id' => $id, 'user_type' => 3]); $GzhDelRes = D('Wxconfig')->where(['merchantid' => $id])->delete(); //删除商户对应公众号信息 $WxappinfoModel = new WxappinfoModel(); $XcxDekRes = $WxappinfoModel->where(['merchant_id' => $id])->delete(); //删除商户对应小程序 if ($re) { $data['status'] = 1; $data['msg'] = "删除成功"; } else { $data['status'] = 1; $data['msg'] = "删除失败"; } } $this->ajaxReturn($data); } /** * 修改商家的状态 */ public function statusUpdate() { $status = I('post.status'); $merchant_id = I('post.id'); $map['id'] = $merchant_id; $Merchant['status'] = $status; $show = D('RetailMerchant')->updateOrder($map, $Merchant); if ($show !== false) { $data['status'] = 1; $data['msg'] = "操作成功"; } else { $data['status'] = 0; $data['msg'] = "操作失败"; } $this->ajaxReturn($data); } /*计算套餐价 * @param $meal_id 套餐id * @param $time_limit 时限类型 * @param $date 过期时间 * @param $type 1续费自定义时限 ""添加商户时自定义时限 * @param $merchant_id 续费自定义时限时的商户id * @param $money 套餐价 * @param $discoujnt 折扣 */ public function meal() { if (IS_POST) { $meal_id = I('post.meal_id'); $time_limit = I("post.time_limit"); $date = I("post.date"); $type = I("post.type"); $merchant_id = I("post.merchant_id"); if ($meal_id && $time_limit) { $user = session('agent_userinfo'); $money = M('retail_meal_price')->where(array('meal_id' => $meal_id, 'time_limit' => $time_limit))->getField('price'); $discoujnt = M('retail_group')->where(array('id' => $user['discountid']))->getField('discount'); $map['id'] = $merchant_id; $fields = "end_time"; $merchant_end_time = D('RetailMerchant')->getFindField($map, $fields); if ($time_limit == 7) { if (empty($date)) { $res['status'] = 0; $res['msg'] = '请选择过期时间'; $this->ajaxReturn($res); } if ($type == 1) { //续费 if ($merchant_end_time > time()) { //未过期 $end_time = newStrToTime($date . "24:00:00"); $time_difference = (($end_time - $merchant_end_time) / 86400) ? (($end_time - $merchant_end_time) / 86400) : 1; } else { //过期 $time = strtotime(date("Y-m-d", time())); $end_time = newStrToTime($date . "24:00:00"); $time_difference = (($end_time - $time) / 86400) ? (($end_time - $time) / 86400) : 1; } } else { //添加 $time = strtotime(date("Y-m-d", time())); $end_time = newStrToTime($date . "24:00:00"); $time_difference = (($end_time - $time) / 86400) ? (($end_time - $time) / 86400) : 1; } $agentmoney = round($money * $time_difference * 1 * $discoujnt, 2); } else { $agentmoney = round($money * $discoujnt, 2); } $res['agentmoney'] = $agentmoney; $res['status'] = 1; $this->ajaxReturn($res); } else { $res['status'] = 0; $res['msg'] = '登录超时'; $this->ajaxReturn($res); } } } //权限设置 public function juris() { $id = I('get.id'); $juris = M('retail_merchant')->where(array('id' => $id))->getField('juris'); $this->assign('juris', $juris); $this->assign('id', $id); $this->display(); } //修改权限 public function diction() { if (IS_POST) { $id = I('post.id'); $juris = I('post.juris'); $res = M('retail_merchant')->where(array('id' => $id))->save(array('juris' => $juris)); if ($res) { $rt['status'] = 1; $rt['msg'] = '设置成功'; } else { $rt['status'] = 1; $rt['msg'] = '设置失败'; } $this->ajaxReturn($rt); } } //插件 public function merchant_plug() { $id = I('get.id'); $user = session('agent_userinfo'); $merchant = M('retail_merchant')->where(array('id' => $id))->find(); $this->assign('merchant', $merchant); $plug = M('plug_agent as a') ->join('ls_plug as p on a.plug_id=p.id', 'LEFT') ->join('ls_plug_merchant as m on m.plug_id=a.plug_id AND m.merchant_id=' . $id, 'LEFT') ->where(array('a.agent_id' => $user['id'], 'a.a_status' => 1)) ->field('p.*,m.m_status') ->select(); $this->assign('plugs', $plug); $this->display(); } //功能套餐 public function functional() { $user = session('agent_userinfo'); $id = I('get.id'); $merchant = M('retail_merchant')->where(array('id' => $id))->find(); //插件 $map = array( array( array( 'p.origin_type' => 2, 'p.is_install' => 1 ), 'p.origin_type' => 1, '_logic' => 'OR', ), 'a.agent_id' => $user['id'], 'a.a_status' => 1 ); $plug = M('plug_agent as a') ->join('ls_plug as p on a.plug_id=p.id') ->join('ls_plug_merchant as m on m.plug_id=a.plug_id AND m.merchant_id=' . $id, "LEFT") ->where($map) ->field('p.*,m.m_status') ->select(); //去除第三方Q3 ERP插件 foreach ($plug as $key => $val) { if ($val['identification'] == 'littlegift') { unset($plug[$key]); } } //小程序权限 $this->assign('merchant', $merchant); $this->assign('plugs', $plug); $this->assign('empty', '暂无数据'); $this->display(); } //功能套餐提交 /*storenum 门店数 * set 功能套餐 * xcx 小程序权限 * id 商户id * setnot 没选择的功能套餐 */ public function mealset() { $id = I('post.id'); $storenum = I('post.storenum'); $set = I('post.set'); $setnot = I('post.setnot'); $xcx = I('post.xcx'); if (!$id) { $res['status'] = 0; $res['msg'] = '商户不存在'; $this->ajaxReturn($res); exit; } //小程序权限和门店数量 if (!empty($xcx)) { M('retail_merchant')->where(array('id' => $id))->save(array('juris' => 2, 'storenum' => $storenum)); } else { M('retail_merchant')->where(array('id' => $id))->save(array('juris' => 1, 'storenum' => $storenum)); } //选中功能套餐相当于启用 if (!empty($set)) { foreach ($set as $val) { $map['plug_id'] = $val; $map['merchant_id'] = $id; $p_plug = M('plug_merchant')->where($map)->find(); if (empty($p_plug)) { //第一次添加 $item['plug_id'] = $val; $item['merchant_id'] = $id; $item['addtime'] = time(); $item['opentime'] = time(); $item['m_status'] = 1; $add = M('plug_merchant')->add($item); if ($add) { $result['status'] = 1; $result['msg'] = '开启成功'; } else { $result['status'] = 0; $result['msg'] = '开启失败'; } } else if ($p_plug['m_status'] == 2) { $close = M('plug_merchant')->where($map)->save(array('m_status' => 1, 'opentime' => time())); if ($close) { $result['status'] = 1; $result['msg'] = '开启成功'; } else { $result['status'] = 0; $result['msg'] = '开启失败'; } } else { $result['status'] = 1; $result['msg'] = '开启成功'; } } } //未选中功能套餐相当于关闭 if (!empty($setnot)) { foreach ($setnot as $va) { $identification = M('plug')->where(['id' => $va])->getField('identification'); if ($identification == 'moraleducationcoin') { //德育币插件不能关闭 $result['status'] = 0; $result['msg'] = '该商户的德育币插件无法关闭'; $this->ajaxReturn($result); } $map['plug_id'] = $va; $map['merchant_id'] = $id; $p_plug = M('plug_merchant')->where($map)->find(); //关闭 if (empty($p_plug)) { //未开启过 $result['status'] = 1; $result['msg'] = '关闭成功'; } else if ($p_plug['m_status'] == 1) { $close = M('plug_merchant')->where($map)->save(array('m_status' => 2)); if ($close) { $storeIds = M('retail_store')->where(['merchantid' => $id, 'state' => 0])->getField('id', true); if (!empty($storeIds)) { M('plug_store')->where(['plug_id' => $va, 'storeid' => ['in', $storeIds], 's_status' => 1])->save(array('s_status' => 2)); } $result['status'] = 1; $result['msg'] = '关闭成功'; } else { $result['status'] = 0; $result['msg'] = '关闭失败'; } } else { $result['status'] = 1; $result['msg'] = '关闭成功'; } } } if ($result['status'] == 1) { $data['status'] = 1; $data['msg'] = '设置成功'; } else { $data['status'] = 0; $data['msg'] = '设置失败'; } $this->ajaxReturn($data); } /* 加载支付设置模板 * */ public function pay_pattern($merchantid) { /* url错误 */ if (!$merchantid) { $this->assign('pay_list', array()); } else { /* 查询代理商 */ $agent_id = M('retail_merchant')->where(array('id' => $merchantid))->getField('agentid'); if (!$agent_id) { $this->assign('pay_list', array()); } else { /* 获取代理商支付权限 */ $agent_pay_pattern = M('retail_pay_pattern')->where(array('agent_id' => $agent_id))->find(); // 该代理商暂无支付权限 if (!$agent_pay_pattern) { $this->assign('pay_list', array()); } else { /* 商户支付权限 */ $pay_set = M('retail_pay_pattern_merchant')->where(array('merchant_id' => $merchantid))->find(); if (!$pay_set) { $data['merchant_id'] = $merchantid; M('retail_pay_pattern_merchant')->add($data); $pay_set = M('retail_pay_pattern_merchant')->where(array('merchant_id' => $merchantid))->find(); } /* 判断代理商支付权限 */ if ($agent_pay_pattern['general_pay'] == 0) { unset($pay_set['general_pay']); } if ($agent_pay_pattern['service_pay'] == 0) { unset($pay_set['service_pay']); } if ($agent_pay_pattern['new_continent_pay'] == 0) { unset($pay_set['new_continent_pay']); } if ($agent_pay_pattern['cloud_pay'] == 0) { unset($pay_set['cloud_pay']); } if ($agent_pay_pattern['happy_pay'] == 0) { unset($pay_set['happy_pay']); } if ($agent_pay_pattern['lakala_pay'] == 0) { unset($pay_set['lakala_pay']); } if ($agent_pay_pattern['qian_ke_pay'] == 0) { unset($pay_set['qian_ke_pay']); } $pay_list = array(); $Plug = new Plug(); $merPlug = $Plug->merPlugState([ 'merchant_id' => $merchantid, '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 == 'merchant_id' || strpos($key, '_name')) { continue; } else if (!isset($plugPay[$key]) || isset($plugPay[$key]) && $merPlug[$plugPay[$key]]) { $name = $pay_set[$key . '_name'] ? $pay_set[$key . '_name'] : '其他支付模式'; array_push($pay_list, array('name' => $name, 'key' => $key, 'status' => $val)); } } $this->assign('pay_id', $pay_set['id']); $this->assign('pay_list', $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; $merchantid = I('post.merchantid'); if (!$id || !$key || !$merchantid) { $res['status'] = 0; $res['msg'] = '参数缺失'; $this->ajaxReturn($res); } $find = M('retail_pay_pattern_merchant')->where(array('id' => $id, 'merchantid' => $merchantid))->find(); if (!$find) { $res['status'] = 0; $res['msg'] = '查询失败'; $this->ajaxReturn($res); } $save = M('retail_pay_pattern_merchant')->where(array('id' => $id))->save(array($key => $status)); if ($save) { $res['status'] = 1; $res['msg'] = '修改成功'; } else { $res['status'] = 0; $res['msg'] = '修改失败'; } $this->ajaxReturn($res); } /* * 续费 * @param $meal 套餐 * @param $group 折扣 */ public function renew() { $user = session('agent_userinfo'); $id = I("get.id"); $meal = M('retail_meal')->where(array('pid' => $user['partnerid']))->select(); $group = M('retail_group')->where(array('id' => $user['discountid']))->getField('discount'); $this->assign('meal', $meal); $this->assign('discount', $group); $this->assign('id', $id); $this->display(); } /*续费管理 * @param $meal_id 套餐id * @param $time_limit 时限类型 1月 2季度 3半年 4一年 5二年 6三年 7自定义 * @param $end_time 自定义过期时间 * @param $userinfo 代理商信息 * @param $merchant_end_time 商户过期时间 * @param $discount 代理商折扣 * @param $unitproce 时限对应的价格 * @param $reduce 该扣除的价格 * @param $surplus 判断代理商余额是否充足 */ public function renew_operation() { $user = session('agent_userinfo'); $data = I("post."); $meal_id = $data['meal_id']; $time_limit = $data['time_limit']; $end_time = $data['end_time']; if (!$data['id'] || !$data['meal_id'] || !$data['time_limit']) { $res['status'] = 0; $res['msg'] = '登录超时,请重新登录'; $this->ajaxReturn($res); } $userinfo = M('retail_agent')->where(array('id' => $user['id']))->find(); if (!$userinfo) { $res['status'] = 0; $res['msg'] = '登录超时'; $this->ajaxReturn($res); } $discount = M('retail_group')->where(array('id' => $user['discountid']))->getField('discount'); $discount = $discount ? $discount : 1; $unitproce = M('retail_meal_price')->where(array('meal_id' => $meal_id, 'time_limit' => $time_limit))->getField('price'); $map['id'] = $data['id']; $fields = "end_time"; $merchant_end_time = D('RetailMerchant')->getFindField($map, $fields); if ($time_limit == 7) { if (strtotime($end_time) < $merchant_end_time) { $res['status'] = 0; $res['msg'] = '自定义过期时间不能小于当前过期时间'; $this->ajaxReturn($res); } if ($merchant_end_time > time()) { //未过期 $start_time = strtotime(date('Y-m-d', $merchant_end_time)); $end_time = newStrToTime($end_time . "24:00:00"); $unitproce = (($end_time - $start_time) / 86400) * 1 * $unitproce; } else { //过期 $start_time = strtotime(date('Y-m-d 00:00:00', time())); $end_time = newStrToTime($end_time . "24:00:00"); $unitproce = (($end_time - $start_time) / 86400) * 1 * $unitproce; } } if ($unitproce < 0) { $res['status'] = 0; $res['msg'] = '价格不能小于0'; $this->ajaxReturn($res); } $reduce = round($unitproce * $discount, 2); $surplus = $userinfo['money'] - $reduce; if ($surplus > 0 || $surplus == 0) { //可以扣除金额 $success = M('retail_agent')->where(array('id' => $userinfo['id']))->setDec('money', $reduce); if ($success && $reduce > 0) { //消费记录 $consum = [ 'addtime' => time(), 'money' => $unitproce, 'actualmoney' => $reduce, 'discount' => $discount, 'agentid' => $user['id'], 'type' => 2 ]; M('retail_consum')->add($consum); } if ($success || $reduce == 0) { if ($merchant_end_time <= time()) { //过期 $content['begin_time'] = strtotime(date("Y-m-d 00:00:00", time())); } switch ($time_limit) { case 1: $content['end_time'] = strtotime("+1 month" . "24:00:00", $merchant_end_time); break; case 2: $content['end_time'] = strtotime("+3 month" . "24:00:00", $merchant_end_time); break; case 3: $content['end_time'] = strtotime("+6 month", $merchant_end_time); break; case 4: $content['end_time'] = strtotime("+1 year", $merchant_end_time); break; case 5: $content['end_time'] = strtotime("+2 year", $merchant_end_time); break; case 6: $content['end_time'] = strtotime("+3 year", $merchant_end_time); break; case 7: $content['end_time'] = $end_time; break; } $where['id'] = $data['id']; $operation = D('RetailMerchant')->updateOrder($where, $content); if ($operation) { $res['status'] = 1; $res['msg'] = '操作成功'; } else { $res['status'] = 0; $res['msg'] = '操作失败'; } } else { $res['status'] = 0; $res['msg'] = '操作失败'; } } else { $res['status'] = 0; $res['msg'] = '余额不足,请联系商家充值'; } $this->ajaxReturn($res); } /** * 编辑支付配置 */ public function editServerPay() { $user = session('agent_userinfo'); $AgentModel = D('RetailAgent'); $map = array( $AgentModel::ID => $user['id'], ); $server_pay_state = $AgentModel->getFindField($map, $AgentModel::SERVER_PAY_STATE); $APCModel = D('AgentPayConfig'); $cMap = array( $APCModel::AGENT_ID => $user['id'] ); $config = $APCModel->getFind($cMap); $this->assign('server_pay_state', $server_pay_state); $this->assign('config', $config); $this->display(); } //判断验证码是否正确 protected function verifyCode() { $verifyCode = session('identifying_codes'); $code = I('post.code'); if ($verifyCode == $code) { session('identifying_codes', null); return true; } else { return false; } } public function submitServerPay() { if (!$this->verifyCode()) { $data['status'] = 0; $data['msg'] = "验证码错误"; $this->ajaxReturn($data); } $alipay_appid = I('post.alipay_appid'); //"444" $alipay_pid = I('post.alipay_pid'); //"555" $alipay_private_key = I('post.alipay_private_key'); //"777" $alipay_public_key = I('post.alipay_public_key'); //"666" $mch_id = I('post.mch_id'); //"333" $server_pay_state = I('post.server_pay_state'); //"1" $wx_apiclient_cert = I('post.wx_apiclient_cert'); //"" $wx_apiclient_key = I('post.wx_apiclient_key'); //"" $wx_appid = I('post.wx_appid'); //"111" $wx_key = I('post.wx_key'); //"222" $wx_serial_no = I('post.wx_serial_no'); //"222" $appsecret = I('post.appsecret'); //"222" $data = array( 'alipay_appid' => $alipay_appid, //'"444" 'alipay_pid' => $alipay_pid, //'"555" 'alipay_private_key' => $alipay_private_key, //'"777" 'alipay_public_key' => $alipay_public_key, //'"666" 'mch_id' => $mch_id, //'"333" 'wx_apiclient_cert' => $wx_apiclient_cert, //'"" 'wx_apiclient_key' => $wx_apiclient_key, //'"" 'wx_appid' => $wx_appid, //'"111" 'wx_key' => $wx_key, //'"222" 'wx_serial_no' => $wx_serial_no, 'appsecret' => $appsecret ); $user = session('agent_userinfo'); $AgentModel = D('RetailAgent'); $aMap = array( $AgentModel::ID => $user['id'], ); $save = array( $AgentModel::SERVER_PAY_STATE => $server_pay_state, ); $server_pay_state = $AgentModel->updateOrder($aMap, $save); $APCModel = D('AgentPayConfig'); $cMap = array( $APCModel::AGENT_ID => $user['id'] ); $config = $APCModel->getFind($cMap); if (!empty($config)) { $res = $APCModel->updateOrder($cMap, $data); } else { $data[$APCModel::ADD_TIME] = time(); $data[$APCModel::AGENT_ID] = $user['id']; $res = $APCModel->addOrder($data); } if ($server_pay_state || $res) { $result['status'] = 1; $result['msg'] = '保存成功'; } else { $result['status'] = 0; $result['msg'] = '保存失败'; } $this->ajaxReturn($result); } /** * 上传证书 */ public function upload() { $upload = new \Think\Upload(); // 实例化上传类 $upload->maxSize = 5242880 / 2; // 设置附件上传大小5M/5 $upload->exts = array( 'pkcs12', 'pem' ); // 设置附件上传类型 $upload->rootPath = 'Uploads'; // 设置附件上传根目录 $upload->savePath = '/cache/'; // 设置附件上传(子)目录 $upload->saveName = array( 'uniqid', array('', true) ); // 上传文件 $info = $upload->upload(); if (!empty($info['file']['savename'])) { $path = "/" . $upload->rootPath . $info['file']['savepath'] . $info['file']['savename']; $rt['status'] = 1; $rt['path'] = $_SERVER['DOCUMENT_ROOT'] . $path; $rt['msg'] = '文件上传成功'; } else { $rt['status'] = 0; $rt['msg'] = '文件上传失败'; } $this->ajaxReturn($rt); } /** * 发送验证码 */ public function sendCode() { $user = session('agent_userinfo'); $phone = M('retail_agent')->where(array('id' => $user['id']))->getField('phone'); $result = A('Api/Alidayu')->sendSmsCode($phone); if ($result['status'] == 1) { session('identifying_codes', $result['code'], 300); //把验证码存到session } $result['msg'] = $result['message']; $this->ajaxReturn($result); } /** * 商户小程序配置 */ public function xcxConfig() { $merchant_id = I('get.merchant_id'); if (empty($merchant_id)) { echo '您的操作有误'; exit; } $this->assign('merchant_id', $merchant_id); $this->assign('type', 2); //1合伙人 2代理商 3商户 $authArr = array( 'submitAudit' => true, ); $this->assign('authArr', $authArr); $this->display(); } /** * 小程序获取基本信息 */ public function getBaseData() { $MerXcxConf = new \Addons\Api\MerXcxConf(I('post.merchant_id')); $res = $MerXcxConf->getBaseData(); //获取小程序当前信息 $this->ajaxReturn($res); } /** * 修改充值入口显示状态 */ public function changeOnlineStatus() { $MerXcxConf = new \Addons\Api\MerXcxConf(I('post.merchant_id')); $res = $MerXcxConf->changeOnlineStatus(); //修改充值入口是否显示 $this->ajaxReturn($res); } /** * 小程序获取预览码 */ public function getPreviewQrImg() { $MerXcxConf = new \Addons\Api\MerXcxConf(I('post.merchant_id')); $res = $MerXcxConf->getPreviewQrImg(); //获取小程序当前信息 $this->ajaxReturn($res); } /** * 小程序的授权功能 */ public function authIndex() { $MerXcxConf = new \Addons\Api\MerXcxConf(I('get.merchant_id')); $url = $MerXcxConf->authIndex('Agent/Merchant/authSuccess'); header('location:' . $url); } /** * 小程序授权回调 */ public function authSuccess() { $MerXcxConf = new \Addons\Api\MerXcxConf(I('get.merchant_id')); $res = $MerXcxConf->authSuccess(); $this->assign('status', $res ? 1 : 0); if (!$res) { $this->assign('msg', $MerXcxConf->errMsg); } $this->display(); } /** * 小程序提交审核 */ public function submitAudit() { $MerXcxConf = new \Addons\Api\MerXcxConf(I('post.merchant_id')); $res = $MerXcxConf->submitAudit(); $this->ajaxReturn($res); } /** * 绑定开发体验用户 */ public function bindUser() { $MerXcxConf = new \Addons\Api\MerXcxConf(I('post.merchant_id')); $res = $MerXcxConf->bindUser(); $this->ajaxReturn($res); } /** * 小程序审核撤回 */ public function undoCodeAudit() { $MerXcxConf = new \Addons\Api\MerXcxConf(I('post.merchant_id')); $res = $MerXcxConf->undoCodeAudit(); $this->ajaxReturn($res); } /** * 发布小程序版本 */ public function release() { $MerXcxConf = new \Addons\Api\MerXcxConf(I('post.merchant_id')); $res = $MerXcxConf->release(); $this->ajaxReturn($res); } /** * 回退小程序版本 */ public function reBack() { $MerXcxConf = new \Addons\Api\MerXcxConf(I('post.merchant_id')); $res = $MerXcxConf->reBack(); $this->ajaxReturn($res); } /** * 回退小程序版本 */ public function clearAuthInfo() { $MerXcxConf = new \Addons\Api\MerXcxConf(I('post.merchant_id')); $res = $MerXcxConf->clearAuthInfo(); $this->ajaxReturn($res); } /** * 修改商户状态 */ public function modifyState() { $data = I('post.'); $MerchantModel = new RetailMerchantModel(); $JurisdictionUserModel = new JurisdictionUserModel(); $state = $MerchantModel->updateOrder(['id' => $data['id']], ['status' => $data['status']]); if ($state) { $status = $data['status'] == 1 ? 1 : 0; $state = $JurisdictionUserModel->updateOrder(['user_type' => 3, 'system_user_id' => $data['id']], ['status' => $status]); if ($state) { $res = [ 'status' => 1, 'msg' => '操作成功' ]; } else { $res = [ 'status' => 0, 'msg' => '操作失败' ]; } } else { $res = [ 'status' => 0, 'msg' => '操作失败1' ]; } $this->ajaxReturn($res); } }