TestController.php 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. <?php
  2. namespace App\Http\Controllers\Api;
  3. use App\Service\Box\BoxService;
  4. use App\Service\ProductionOrderService;
  5. use Illuminate\Support\Facades\Config;
  6. use Illuminate\Support\Facades\DB;
  7. class TestController extends BaseController
  8. {
  9. public function delTestQ(){
  10. (new BoxService())->delBoxLock();
  11. dd(1);
  12. }
  13. public function delTestQ2(){
  14. (new ProductionOrderService())->delBoxLock();
  15. dd(1);
  16. }
  17. public function tt(){
  18. $model_box = DB::connection("mysqlT9");
  19. $u8 = $model_box->table('setting')
  20. ->where('setting_name','u8')
  21. ->where('setting_value','<>','')
  22. ->first();
  23. if(empty($u8)) return [false, 'u8配置参数不存在!'];
  24. $u8 = $u8->setting_value;
  25. // 使用 eval() 函数执行字符串并转换为数组
  26. $u8 = eval("return {$u8};");
  27. if(empty($u8['domain'])) return [false, '外部域名不能为空!'];
  28. if(empty($u8['u8_api_port'])) return [false, 'u8程序API端口不能为空!'];
  29. if(empty($u8['u8_database_port'])) return [false, 'u8程序数据库端口不能为空!'];
  30. if(empty($u8['database'])) return [false, 'u8程序数据库不能为空!'];
  31. if(empty($u8['database_account'])) return [false, 'u8程序数据库登录账号不能为空!'];
  32. if(empty($u8['database_password'])) return [false, 'u8程序数据库登录密码不能为空!'];
  33. if(empty($u8['sAccID'])) return [false, 'u8程序sAccID不能为空!'];
  34. if(empty($u8['sServer'])) return [false, 'u8程序sServer不能为空!'];
  35. if(empty($u8['sUserID'])) return [false, 'u8程序sUserID不能为空!'];
  36. if(empty($u8['sPassword'])) return [false, 'u8程序sPassword不能为空!'];
  37. $config = [
  38. 'driver' => 'sqlsrv',
  39. 'host' => $u8['domain'],
  40. 'port' => $u8['u8_database_port'],
  41. 'database' => $u8['database'],
  42. 'username' => $u8['database_account'],
  43. 'password' => $u8['database_password'],
  44. ];
  45. // 数据库配置设置
  46. Config::set('database.connections.sqlsrvs', $config);
  47. // 连接
  48. try {
  49. $pdo = DB::connection('sqlsrvs')->getPdo();
  50. if ($pdo instanceof \PDO) {
  51. // 连接成功的逻辑代码
  52. $db = DB::connection('sqlsrvs');
  53. $result = $db->table('ST_SNState')
  54. ->select('cinvCode as code','cInvSN as sn','AutoID as auto_id')
  55. ->whereIn("cWhCode", [001,003])
  56. ->where("cInvCode", "100000003")
  57. ->where("iSNState", 2)
  58. ->orderBy('cSNDefine1','desc')
  59. ->orderBy('AutoID','asc')
  60. ->get()->toArray();
  61. dd($result);
  62. } else {
  63. dd(1233);
  64. }
  65. } catch (\Throwable $e) {
  66. dd($e->getMessage());
  67. }
  68. }
  69. }