Yhuatong.php 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. <?php
  2. namespace app\sys\controller;
  3. use app\model\OutCallSetting;
  4. use call\Yhuatong as CallYhuatong;
  5. use think\facade\View;
  6. class Yhuatong
  7. {
  8. /**
  9. * 云话统设置页面
  10. *
  11. * @return String
  12. */
  13. public function setting()
  14. {
  15. $setting = OutCallSetting::where(['root_id' => request()->employee->root_id, 'type' => 'yhuatong'])->find();
  16. View::assign('data', $setting);
  17. return View::fetch();
  18. }
  19. /**
  20. * 云话统余额
  21. *
  22. * @return String
  23. */
  24. public function balence()
  25. {
  26. // 获取配置
  27. $setting = OutCallSetting::where(['root_id' => request()->employee->root_id, 'type' => 'yhuatong'])->find();
  28. if (empty($setting)) return json(['code' => 0, 'data' => '暂无']);
  29. $outCall = new CallYhuatong($setting->config['appid'], $setting->config['secretKey']);
  30. $rs = $outCall->balance();
  31. if ($rs['code'] != 10000) return json(['code' => 0, 'data' => $rs['msg']]);
  32. return json(['code' => 0, 'data' => $rs['data']['balance']]);
  33. }
  34. /**
  35. * 云话统配置
  36. *
  37. * @return String
  38. */
  39. public function settingSave()
  40. {
  41. // 单个企业只能设置一种外呼系统
  42. $setting = OutCallSetting::where(['root_id' => request()->employee->root_id])->findOrEmpty();
  43. if ($setting->isEmpty()) {
  44. $setting = new OutCallSetting;
  45. } elseif ($setting->type != 'yhuatong') {
  46. $setting->delete();
  47. $setting = new OutCallSetting;
  48. }
  49. $param = request()->only(['appid', 'secretKey', 'tel_x']);
  50. // 行业获取
  51. $outCall = new CallYhuatong($param['appid'], $param['secretKey']);
  52. $industryData = $outCall->comIndustryList();
  53. $param['industry'] = $industryData['data'];
  54. $data = [
  55. 'config' => $param,
  56. 'root_id' => request()->employee->root_id,
  57. 'type' => 'yhuatong'
  58. ];
  59. $rs = $setting->save($data);
  60. if (!$rs) return json(['code' => 1, 'msg' => '保存失败']);
  61. return json(['code' => 0, 'msg' => '保存成功']);
  62. }
  63. }