getFindField([ 'id' => $merchant_id ], 'platform_type'); return $platform_type ? $platform_type : '1'; } /** * 商户的第三方配置信息 * @param $param * [ * merchant_id * platform_type 2 第三方平台 * ] * @return mixed */ public function thirdConfigInfo($param) { if (empty($param['merchant_id']) || empty($param['platform_type'])) { return callBack(statusCode()['error'], '参数有误'); } $where = [ 'merchant_id' => $param['merchant_id'], 'platform_type' => $param['platform_type'] ]; try { $ThirdConfigModel = new ThirdConfigModel(); $info = $ThirdConfigModel->getFind($where); return callBack(statusCode()['success'], '查询成功', $info); } catch (\Exception $e) { return callBack(statusCode()['error'], '查询失败'); } } /** * 商户的第三方接口链接列表 * @param $param * [ * merchant_id * identification 插件标识 * ] * @return mixed */ public function thirdSetList($param) { $where = [ 'm.merchant_id' => $param['merchant_id'], 't.status' => 1, 't.identification' => $param['identification'] ]; $fields = 'm.status,m.third_id,t.id,t.type,t.route_url,t.route_name'; try { $ThirdErpSetModel = new ThirdErpSetModel(); $list = $ThirdErpSetModel->merchantThirdSet($where, $fields); if (!empty($list)) { foreach ($list as &$val) { if (empty($val['third_id'])) { $val['status'] = 2; } } } return callBack(statusCode()['success'], '查询成功', $list); } catch (\Exception $e) { return callBack(statusCode()['error'], '查询失败', []); } } /** * 添加商户第三方平台的参数验证 * @param $param * [ * agent_id 代理商id * platform_type 2微礼平台 * merchant_id * littlegift=>json字符串{ * id 主键id编辑所需 * third_domain_url 域名 * third_account_number 登录账户 * third_password 登录密码 * } * route_list=>json字符串{ * { * id 合伙人路径配置id * type 模块类型 * status 1开启 2关闭 * route_url 路径 * } * } * ] * @return mixed */ public function thirdAddMerchantVerify($param) { if (empty($param['agent_id'])) { return callBack(statusCode()['error'], '登录超时'); } if (!in_array($param['platform_type'], ['2'])) { return callBack(statusCode()['error'], '登录超时'); } switch ($param['platform_type']) { case 2: //微礼平台 if (empty($param['littlegift']) || empty($param['route_list'])) { return callBack(statusCode()['error'], '缺少插件必传参数'); } $littlegift = json_decode($param['littlegift'], true); $route_list = json_decode($param['route_list'], true); if (!is_array($littlegift) || !is_array($route_list)) { return callBack(statusCode()['error'], '插件参数格式有误'); } if (empty($littlegift['third_domain_url']) || empty($littlegift['third_account_number']) || empty($littlegift['third_password'])) { return callBack(statusCode()['error'], '缺少插件所需必要参数'); } $login_url = ''; foreach ($route_list as $val) { if ($val['type'] == 1) { if ($val['status'] == 2) { return callBack(statusCode()['error'], '登录必须开启'); } else { if (empty($val['route_url'])) { return callBack(statusCode()['error'], '缺少登录路径'); } else { $login_url = $val['route_url']; } break; } } } $identification_arr = ['littlegift']; break; } $PlugClass = new Plug(); $result = $PlugClass->agentPlugPermissions([ 'agent_id' => $param['agent_id'], 'identification_arr' => $identification_arr ]); switch ($param['platform_type']) { case 2: if (empty($result['data']['littlegift'])) { return callBack(statusCode()['error'], '暂无该插件权限'); } $LittleClass = new LittleGift([ 'domain_url' => $littlegift['third_domain_url'] ]); $result = $LittleClass->login([ 'method' => $login_url, 'account_number' => $littlegift['third_account_number'], 'password' => $littlegift['third_password'] ]); if ($result['status'] != 1) { return callBack(statusCode()['error'], 'Q3 ERP平台信息有误' . $result['error']['message']); } return callBack(statusCode()['success'], '验证成功', $result); break; } } /** * 会员充值分期到账设置 * @param $param * [ * merchant_id * ] * @return mixed * [ * data 分期设置 * ] */ public function getSetting($param) { $where = [ 'id' => $param['merchant_id'], 'status' => 1 ]; $fields = [ 'id', 'aging_cycle', 'aging_repay', 'aging_time' ]; try { $MerchantModel = new RetailMerchantModel(); $info = $MerchantModel->getFind($where, $fields); if (!empty($info)) { return callBack(statusCode()['success'], "商户的分期设置获取成功", $info); } else { return callBack(statusCode()['error'], "商户的分期设置获取失败"); } } catch (\Exception $e) { return callBack(statusCode()['error'], "商户的分期设置获取失败"); } } /** * 参数验证 * $param = [ * merchant_rate 新大陆费率 必填 * ali_rate 支付宝费率 必填 * wx_rate 微信费率 必填 * id 商户id 必填 * name 商户的名称 必填 * address 详细地址 必填 * mobile 商户手机号(登录账号) 必填 * time_limit 时间限制(判断结束时间) 必填 * mealid 套餐id 必填 * end_time 商户账号过期时间 * password 商户登录密码 必填 * ] * $user 当前登录人信息['id','partnerid'=>合伙人id] */ public function paramVerify($param, $user) { $MerchantModel = new MerchantModel(); $RetailAgentModel = new RetailAgentModel(); $RetailMealPriceModel = new RetailMealPriceModel(); $param['merchant_rate'] = $param['merchant_rate'] ? $param['merchant_rate'] : 0; $param['ali_rate'] = $param['ali_rate'] ? $param['ali_rate'] : 0; $param['wx_rate'] = $param['wx_rate'] ? $param['wx_rate'] : 0; if (empty($param['id'])) { $param['addtime'] = time(); $newParam['begin_time'] = strval(strtotime(date("Y-m-d 00:00:00", time()))); if ( empty($param['name']) || empty($param['address']) || empty($param['mobile']) || empty($param['time_limit']) || empty($param['mealid']) ) { return ['status' => 0, 'msg' => '表单信息有误,请重新操作']; } if ($param['time_limit'] == 7) { //自定义时间 if (empty($param['end_time'])) { return (['status' => 0, 'msg' => '自定义时间有误']); } if (strtotime($param['end_time']) < time()) { return ['status' => 0, 'msg' => '过期时间不能小于当前时间']; } } //手机号不能重复 $map['status'] = ['in', '1,2']; $map['mobile'] = $param['mobile']; $existence = $MerchantModel->getFind($map); if ($existence) { return ['status' => 0, 'msg' => '手机号已被使用,请重新完善信息']; } if (strlen($param['password']) > 16) { return ['status' => 0, 'msg' => '密码不能大于16位']; } $userinfo = $RetailAgentModel->getFind(['id' => $user['id']]); if (!$userinfo) { return (['status' => 0, 'msg' => '登录超时']); } //单价 $unitprice = $RetailMealPriceModel->getFindField(['meal_id' => $param['mealid'], 'time_limit' => $param['time_limit']], 'price'); if ($param['time_limit'] == 7) { //自定义时间 $start_time = strtotime(date('Y-m-d', $newParam['begin_time'])); $end_time = newStrToTime($param['end_time'] . "24:00:00"); $dat_num = (($end_time - $start_time) / 86400) * 1; $unitprice = $dat_num * $unitprice; } $otherParam['unitprice'] = $unitprice; if ($unitprice < 0) { return ['status' => 0, 'msg' => '价格不能小于0']; } } else { $map['id'] = $param['id']; //手机号不能重复 $oldMerchant = $MerchantModel->getFind($map); if ($oldMerchant['mobile'] != $param['mobile']) { $wh['status'] = ['in', '1,2']; $wh['mobile'] = $param['mobile']; $existence = $MerchantModel->getFind($wh); if ($existence) { return ['status' => 0, 'msg' => '手机号已被使用,请重新完善信息']; } } } return ['status' => 1, 'param' => $param, 'userinfo' => $userinfo, 'otherParam' => $otherParam]; } /** * 添加商户 */ public function addMerchant($param, $user) { $MerchantModel = new MerchantModel(); $RetailAdminModel = new RetailAdminModel(); $RetailAgentModel = new RetailAgentModel(); $RetailGroupModel = new RetailGroupModel(); $RetailConsumModel = new RetailConsumModel(); $JurisdictionUserModel = new JurisdictionUserModel(); $RetailMerchantConfigModel = new RetailMerchantConfigModel(); //验参 $paramRes = $this->paramVerify($param, $user); if ($paramRes['status'] == 1) { $param = $paramRes['param']; $userinfo = $paramRes['userinfo']; $otherParam = $paramRes['otherParam']; //封装 if (empty($param['id'])) { $end_time = $param['end_time']; $time_limit = $param['time_limit']; $MerchantData['mealid'] = $param['mealid']; $MerchantData['addtime'] = time(); $MerchantData['begin_time'] = strval(strtotime(date("Y-m-d 00:00:00", time()))); $CryptrModel = new \Addons\Api\Crypto(); $MerchantData['password'] = $CryptrModel->encrypt($param['password'], date('YmdHis', $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; } //折扣 $discount = $RetailGroupModel->getFindField(['id' => $userinfo['discountid']], 'discount'); $discount = $discount ? $discount : 1; //单价 $unitprice = $otherParam['unitprice']; //该扣除的价格 $reduce = round($unitprice * $discount, 2); //判断是否可以减 $surplus = $userinfo['money'] - $reduce; if ($surplus > 0 || $surplus == 0) { $success = $RetailAgentModel->tosetDec(['id' => $userinfo['id']], 'money', $reduce); if ($success || $reduce == 0) { $re = $MerchantModel->addMerchant($MerchantData); if ($re) { //添加默认仓库 $content = [ 'province' => '北京', 'number' => 'A_001', 'city' => '北京市', 'area' => '海淀区', 'name' => '默认采购仓', 'address' => '北京市海淀区', 'merchant_id' => $re, 'measure_area' => 100, 'person_name' => '小李', 'person_phone' => '18888888888', ]; $WarehouseClass = new Warehouse(); $WarehouseClass->merchantPurchaseWarehouseOperation($content); $content['name'] = '默认供给仓'; $WarehouseClass->merchantSaleWarehouseOperation($content); //添加默认商户设置 $merchantConfig = $RetailMerchantConfigModel->getFind(['merchant_id' => $re]); if (!$merchantConfig) { $merchantConfigAdd = [ 'integral_arrive_cash' => 0, 'integral_arrive_cash_data' => 0, 'integral_arrive_cash_rate' => 0, 'other_pay' => 1, ]; $configAddRes = $RetailMerchantConfigModel->addOrder($merchantConfigAdd); if (!$configAddRes) { return ['status' => 0, 'msg' => '默认商户设置添加失败!']; } } $consum['type'] = 2; $consum['actualmoney'] = $reduce; $consum['discount'] = $discount; $consum['money'] = $unitprice; $consum['agentid'] = $user['id']; $consum['addtime'] = $MerchantData['addtime']; $consuminfo = $RetailConsumModel->addOrder($consum); $reagent = $RetailAgentModel->getFind(['id' => $user['id']]); $readmin = $RetailAdminModel->getFind(['id' => $reagent['partnerid']], 'phone,name'); $shop['appid'] = 4; $shop['addtime'] = time(); $shop['site'] = C('adminhttp'); $shop['name'] = $readmin['name']; $shop['phone'] = $readmin['phone']; $shop['end_time'] = $MerchantData['end_time']; $shop['begin_time'] = $MerchantData['begin_time']; if ($consuminfo) { //添加ls_jurisdiction_user $jurData['name'] = $MerchantData['name']; $jurData['login_name'] = $MerchantData['mobile']; $jurData['add_time'] = $MerchantData['addtime']; $jurData['password'] = $MerchantData['password']; $jurData['jurisdiction_group_id'] = 3; $jurData['user_type'] = 3; $jurData['system_user_id'] = $re; $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); $res = ['statue' => 1, 'msg' => '添加成功']; } else { $res = ['statue' => 0, 'msg' => '添加失败']; } } else { $res = ['statue' => 0, 'msg' => '添加失败']; } } else { $res = ['statue' => 0, 'msg' => '操作失败']; } } else { $res = ['statue' => 0, 'msg' => '余额不足,请联系商家充值']; } } else { $map['id'] = $param['id']; //手机号不能重复 $oldMerchant = $MerchantModel->getFind($map); $re = $MerchantModel->UpdateMerchant($map, $param); $up['login_name'] = $param['mobile']; $up['name'] = $param['name']; $upres = $JurisdictionUserModel->updateUser(['system_user_id' => $oldMerchant['id'], 'user_type' => 3], $up); if ($re !== false) { $res = ['statue' => 1, 'msg' => '修改成功', 'num' => $param['storenum']]; } else { $res = ['statue' => 0, 'msg' => '修改失败']; } } return $res; } else { return $paramRes; } } }