1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374 |
- <?php
- namespace app\sys\controller;
- use app\model\OutCallSetting;
- use call\Yhuatong as CallYhuatong;
- use think\facade\View;
- class Yhuatong
- {
- /**
- * 云话统设置页面
- *
- * @return String
- */
- public function setting()
- {
- $setting = OutCallSetting::where(['root_id' => request()->employee->root_id, 'type' => 'yhuatong'])->find();
- View::assign('data', $setting);
- return View::fetch();
- }
- /**
- * 云话统余额
- *
- * @return String
- */
- public function balence()
- {
- // 获取配置
- $setting = OutCallSetting::where(['root_id' => request()->employee->root_id, 'type' => 'yhuatong'])->find();
- if (empty($setting)) return json(['code' => 0, 'data' => '暂无']);
- $outCall = new CallYhuatong($setting->config['appid'], $setting->config['secretKey']);
- $rs = $outCall->balance();
- if ($rs['code'] != 10000) return json(['code' => 0, 'data' => $rs['msg']]);
- return json(['code' => 0, 'data' => $rs['data']['balance']]);
- }
- /**
- * 云话统配置
- *
- * @return String
- */
- public function settingSave()
- {
- // 单个企业只能设置一种外呼系统
- $setting = OutCallSetting::where(['root_id' => request()->employee->root_id])->findOrEmpty();
- if ($setting->isEmpty()) {
- $setting = new OutCallSetting;
- } elseif ($setting->type != 'yhuatong') {
- $setting->delete();
- $setting = new OutCallSetting;
- }
- $param = request()->only(['appid', 'secretKey', 'tel_x']);
- // 行业获取
- $outCall = new CallYhuatong($param['appid'], $param['secretKey']);
- $industryData = $outCall->comIndustryList();
- $param['industry'] = $industryData['data'];
- $data = [
- 'config' => $param,
- 'root_id' => request()->employee->root_id,
- 'type' => 'yhuatong'
- ];
- $rs = $setting->save($data);
- if (!$rs) return json(['code' => 1, 'msg' => '保存失败']);
- return json(['code' => 0, 'msg' => '保存成功']);
- }
- }
|