cqp hace 10 meses
padre
commit
48c1a2f981

+ 11 - 1
app/Http/Controllers/Api/MayCurController.php

@@ -7,7 +7,17 @@ use Illuminate\Http\Request;
 class MayCurController extends BaseController
 class MayCurController extends BaseController
 {
 {
     public function getToken(Request $request){
     public function getToken(Request $request){
-        list($bool, $data) = (new MayCurServerService())->getToken($request->all());
+        list($bool, $data) = (new MayCurServerService())->getToken();
+
+        if($bool){
+            return $this->json_return(200,'',$data);
+        }else{
+            return $this->json_return(201,$data);
+        }
+    }
+
+    public function reimburse(Request $request){
+        list($bool, $data) = (new MayCurServerService())->reimburse($request->all());
 
 
         if($bool){
         if($bool){
             return $this->json_return(200,'',$data);
             return $this->json_return(200,'',$data);

+ 120 - 14
app/Service/MayCurServerService.php

@@ -10,21 +10,25 @@ class MayCurServerService extends Service
 {
 {
     protected $param = "";
     protected $param = "";
     protected $domain_url = "";
     protected $domain_url = "";
+    protected $head = null;
 
 
     public function __construct()
     public function __construct()
     {
     {
         $this->param = config("maycur");
         $this->param = config("maycur");
-        $this->domain_url = $this->param['zs_url'];
+        $this->domain_url = $this->param['dd_url'];
     }
     }
 
 
-    public function getToken($data){
+    public function getToken(){
         //每刻所有配置
         //每刻所有配置
         $url_array = $this->param;
         $url_array = $this->param;
 
 
         //redis 存储的token
         //redis 存储的token
         $key = $this->domain_url . $url_array['login_redis_topic'];
         $key = $this->domain_url . $url_array['login_redis_topic'];
         $token = Redis::get($key);
         $token = Redis::get($key);
-        if(! empty($token))  return [true, json_decode($token,true)];
+        if(! empty($token)) {
+            $this->head = json_decode($token,true);
+            return [true, ''];
+        }
 
 
         //获取token的参数
         //获取token的参数
         $appcode = env('maycur_appcode');
         $appcode = env('maycur_appcode');
@@ -34,7 +38,7 @@ class MayCurServerService extends Service
         //组织获取参数
         //组织获取参数
         $url = $this->domain_url . $url_array['login'];
         $url = $this->domain_url . $url_array['login'];
         $time = microtime(true);
         $time = microtime(true);
-        $timeStamp = round($time * 1000);
+        $timeStamp = intval($time * 1000);
         //生成secret
         //生成secret
         $secret = $this->getSecret($appcode, $appsercet, $timeStamp);
         $secret = $this->getSecret($appcode, $appsercet, $timeStamp);
 
 
@@ -46,15 +50,17 @@ class MayCurServerService extends Service
         $header = ['Content-Type:application/json'];
         $header = ['Content-Type:application/json'];
         list($status, $result) = $this->post_helper($url,$post, $header);
         list($status, $result) = $this->post_helper($url,$post, $header);
         if(! $status) return [$status, $result];
         if(! $status) return [$status, $result];
-        if(empty($result['data']['entCode']) || empty($result['data']['tokenId'])) return [false, $result['message'] ?? '鉴权失败,请联系开发者'];
+        if(isset($result['code']) && $result['code'] != 'ACK') return [false, $result['message'] ?? '鉴权失败,请联系开发者'];
 
 
         $token_array = [
         $token_array = [
-            'entCode' => $result['data']['entCode'],
-            'tokenId' => $result['data']['tokenId'],
+            'tokenId:' . $result['data']['tokenId'],
+            'entCode:' . $result['data']['entCode'],
         ];
         ];
+        $this->head = $token_array;
+
         Redis::setex($key, $url_array['login_expire_time'], json_encode($token_array));
         Redis::setex($key, $url_array['login_expire_time'], json_encode($token_array));
 
 
-        return [true, $token_array];
+        return [true, ''];
     }
     }
 
 
     private function getSecret($appCode, $appSecret, $timeStamp) {
     private function getSecret($appCode, $appSecret, $timeStamp) {
@@ -65,8 +71,108 @@ class MayCurServerService extends Service
         return $hashedString;
         return $hashedString;
     }
     }
 
 
+    public function reimburse($data){
+       //校验
+       list($status, $msg) = $this->reimburseRule($data);
+       if(! $status) return [false, $msg];
+       //获取token
+       list($status, $token) = $this->getToken();
+       if(! $status) return [false, $token];
+
+       $header = $this->head;
+       //每刻所有配置
+       $url_array = $this->param;
+       //组织获取参数
+       $url = $this->domain_url . $url_array['reimburse'];
+       $header = array_merge(['Content-Type:application/json'], $header);
+       list($status, $result) = $this->post_helper($url,$msg, $header);
+       if(! $status) return [$status, $result];
+       if(isset($result['code']) && $result['code'] != 'ACK') return [false, $result['message']];
+
+       //组织返回数据
+       if(empty($result['data'])) return [true, $result['data']];
+
+       //获取报销单详情填充
+       list($status, $return) = $this->reimburseDetailGet($result['data']);
+       if(! $status) return [false, $return];
+
+       return [true, $return];
+    }
+
+    public function reimburseRule($data){
+        if(empty($data['createdAtStart']) || empty($data['createdAtEnd'])) return [false, '单据的创建时间不能为空'];
+        $createAtStart = strtotime($data['createdAtStart'] . '00:00:00');
+        $createdAtEnd = strtotime($data['createdAtEnd'] . '23:59:59');
+        if(empty($createAtStart)) return [false, '单据的创建开始时间格式错误'];
+        if(empty($createdAtEnd)) return [false, '单据的创建结束时间格式错误'];
+
+        $pageNo = 1;
+        $pageSize = 10;
+        if(! empty($data['pageNo'])) $pageNo = $data['pageNo'];
+        if(! empty($data['pageSize'])) {
+            if($data['pageSize'] >= 100) {
+                $pageSize = 10;
+            }else{
+                $pageSize = $data['pageSize'];
+            }
+        }
+
+        $return = [
+            'createdAtStart' => $createAtStart * 1000,
+            'createdAtEnd' => $createdAtEnd * 1000,
+            'pageNo' => $pageNo,
+            'pageSize' => $pageSize,
+        ];
+
+        return [true, $return];
+    }
+
+    public function reimburseDetailGet($list){
+        if(empty($list['list'])) return [true, $list];
+
+        foreach ($list['list'] as $key => $value){
+            list($status, $msg) = $this->reimburseDetail($value);
+            if(! $status) return [false, $msg];
+
+            $list['list'][$key]['reimburseDetail'] = $msg;
+        }
+
+        return [true, $list];
+    }
+
+    public function reimburseDetail($data){
+        if(empty($data['formCode'])) return [false, ["报销单详情请求缺失formCode"]];
+
+        $post = [
+            "formCode"=> $data['formCode'],
+            "enablePayeeInfo"=> true,
+            "enablePayerInfo"=> true,
+            "enableAssociatedForms"=> true,
+            "enableTravelRouteList"=> true,
+            "enableCreditInfo"=> true,
+            "enableExpenseList"=> true,
+            "enableInvoiceList"=> true,
+            "enableExpenseAllocationList"=> true,
+            "enableTravelPartnerInfo"=> true,
+            "enableAttachments"=> true,
+            "enableCapitalPlanPaymentLog"=> true
+        ];
+
+        $header = $this->head;
+        //每刻所有配置
+        $url_array = $this->param;
+        //组织获取参数
+        $url = $this->domain_url . $url_array['reimburseDetail'];
+        $header = array_merge(['Content-Type:application/json'], $header);
+        list($status, $result) = $this->post_helper($url,$post, $header);
+        if(! $status) return [$status, $result];
+        if(isset($result['code']) && $result['code'] != 'ACK') return [false, $result['message']];
+
+        return [true, $result['data'] ?? []];
+    }
+
     public function post_helper($url, $data, $header = [], $timeout = 20){
     public function post_helper($url, $data, $header = [], $timeout = 20){
-        Log::channel('apiLog')->info('每刻POST', ["api" => $url , "param" => $data ,"header" => $header]);
+        Log::channel('apiMcLog')->info('每刻POST', ["api" => $url , "param" => $data ,"header" => $header]);
 
 
         $ch = curl_init();
         $ch = curl_init();
         curl_setopt($ch, CURLOPT_URL, $url);
         curl_setopt($ch, CURLOPT_URL, $url);
@@ -88,19 +194,19 @@ class MayCurServerService extends Service
             $errorMessage = curl_error($ch);
             $errorMessage = curl_error($ch);
             $message = "cURL Error #{$errorNumber}: {$errorMessage}";
             $message = "cURL Error #{$errorNumber}: {$errorMessage}";
 
 
-            Log::channel('apiLog')->info('每刻POST结果', ["message" => $message]);
+            Log::channel('apiMcLog')->info('每刻POST结果', ["message" => $message]);
             return [false, $message];
             return [false, $message];
         }
         }
         curl_close($ch);
         curl_close($ch);
 
 
         $return = json_decode($r, true);
         $return = json_decode($r, true);
-        Log::channel('apiLog')->info('每刻POST结果', ["message" => $return]);
+        Log::channel('apiMcLog')->info('每刻POST结果', ["message" => $return]);
 
 
         return [true, $return];
         return [true, $return];
     }
     }
 
 
     public function get_helper($url,$header=[],$timeout = 20){
     public function get_helper($url,$header=[],$timeout = 20){
-        Log::channel('apiLog')->info('每刻GET', ["api" => $url ,"header" => $header]);
+        Log::channel('apiMcLog')->info('每刻GET', ["api" => $url ,"header" => $header]);
         $ch = curl_init();
         $ch = curl_init();
         curl_setopt_array($ch, array(
         curl_setopt_array($ch, array(
             CURLOPT_URL => $url,
             CURLOPT_URL => $url,
@@ -122,14 +228,14 @@ class MayCurServerService extends Service
             // 获取错误信息
             // 获取错误信息
             $errorMessage = curl_error($ch);
             $errorMessage = curl_error($ch);
             $message = "cURL Error #{$errorNumber}: {$errorMessage}";
             $message = "cURL Error #{$errorNumber}: {$errorMessage}";
-            Log::channel('apiLog')->info('每刻GET', ["message" => $message]);
+            Log::channel('apiMcLog')->info('每刻GET', ["message" => $message]);
             return [false, $message];
             return [false, $message];
         }
         }
 
 
         curl_close($ch);
         curl_close($ch);
 
 
         $return = json_decode($r, true);
         $return = json_decode($r, true);
-        Log::channel('apiLog')->info('每刻GET', ["message" => $return]);
+        Log::channel('apiMcLog')->info('每刻GET', ["message" => $return]);
 
 
         return [true, $return];
         return [true, $return];
     }
     }

+ 7 - 0
config/logging.php

@@ -121,6 +121,13 @@ return [
             'level' => 'debug',
             'level' => 'debug',
             'days' => 7,
             'days' => 7,
         ],
         ],
+
+        'apiMcLog' => [
+            'driver' => 'daily',
+            'path' => storage_path('logs/maycur.log'),
+            'level' => 'debug',
+            'days' => 7,
+        ],
     ],
     ],
 
 
 ];
 ];

+ 6 - 0
config/maycur.php

@@ -5,10 +5,16 @@ return [
     'cs_url' => 'https://ng-uat.maycur.com',
     'cs_url' => 'https://ng-uat.maycur.com',
     //正式
     //正式
     'zs_url' => 'https://ng.maycur.com',
     'zs_url' => 'https://ng.maycur.com',
+    //钉钉云
+    'dd_url' => 'https://dt.maycur.com',
     //登录标识
     //登录标识
     'login_redis_topic' => 'MAYCURLOGIN',
     'login_redis_topic' => 'MAYCURLOGIN',
     //登录过期时间
     //登录过期时间
     'login_expire_time' => 1750, // 1800
     'login_expire_time' => 1750, // 1800
     //登录
     //登录
     'login' => '/api/openapi/auth/login',
     'login' => '/api/openapi/auth/login',
+    //报销单
+    'reimburse' => '/api/openapi/form/v2/reimburse',
+    //报销单详情
+    'reimburseDetail' => '/api/openapi/form/reimburse/detail',
 ];
 ];

+ 2 - 1
routes/maycur.php

@@ -17,4 +17,5 @@ Route::middleware('auth:api')->get('/user', function (Request $request) {
     return $request->user();
     return $request->user();
 });
 });
 
 
-Route::any('getToken', 'Api\MayCurController@getToken');
+//Route::any('getToken', 'Api\MayCurController@getToken');
+Route::any('reimburse', 'Api\MayCurController@reimburse');