| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269 |
- <?php
- /**
- * 重庆赤晓店信息科技有限公司
- * https://www.chixiaodian.com
- * Copyright (c) 2023 赤店商城 All rights reserved.
- */
- namespace app\utils\pospal;
- use app\models\Option;
- use app\constants\OptionSetting;
- /**
- * http://pospal.cn/openplatform/ticketapi.html#queryTicketPages
- */
- class Api
- {
- const TEST_DATA = 0;
- // const API_HOST = 'https://area11-win.pospal.cn:443';
- const API_PREFIX = '/pospal-api2/openapi/v1/';
- // const APP_ID = '8DA6E1645F34D18697DDC1ACCF6090E8';
- // const APP_KEY = '741629749281739495';
- public static function conf($store_id) {
- $conf = Option::get(OptionSetting::POSPAL, $store_id, 'store')['value'];
- if($conf){
- $conf = json_decode($conf, true);
- }
- return $conf;
- }
- public static function appid($store_id) {
- $conf = self::conf($store_id);
- return empty($conf['app_id']) ? '' : $conf['app_id'];
- }
- public static function appkey($store_id) {
- $conf = self::conf($store_id);
- return empty($conf['app_key']) ? '' : $conf['app_key'];
- }
- public static function apihost($store_id) {
- $conf = self::conf($store_id);
- return empty($conf['api_host']) ? '' : trim($conf['api_host'], '/');
- }
- public static function getUrl($store_id, $apiUrl) {
- return self::apihost($store_id) . self::API_PREFIX . $apiUrl;
- }
- public static function postUrl($store_id, $url, $arrayData)
- {
- $curl = curl_init();
- $json_data = json_encode($arrayData);
- $data_signature = self::signature($store_id, $json_data);
- $http_header = [
- 'User-Agent: openApi',
- 'Content-Type: application/json; charset=utf-8',
- 'accept-encoding: gzip,deflate',
- 'time-stamp:' . self::get_millisecond(),
- 'data-signature:' . $data_signature,
- 'Content-Type:' . 'application/json',
- ];
- debug_log('接口地址');
- debug_log(self::getUrl($store_id, $url));
- debug_log('请求参数');
- debug_log($arrayData);
- curl_setopt($curl, CURLOPT_URL, self::getUrl($store_id, $url));
- curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
- curl_setopt($curl, CURLOPT_ENCODING, '');
- curl_setopt($curl, CURLOPT_MAXREDIRS, 10);
- curl_setopt($curl, CURLOPT_TIMEOUT, 0);
- curl_setopt($curl, CURLOPT_FOLLOWLOCATION, true);
- curl_setopt($curl, CURLOPT_HTTP_VERSION, 'CURL_HTTP_VERSION_1_1');
- curl_setopt($curl, CURLOPT_CUSTOMREQUEST, 'POST');
- curl_setopt($curl, CURLOPT_POSTFIELDS, $json_data);
- curl_setopt($curl, CURLOPT_HTTPHEADER, $http_header);
- $response = curl_exec($curl);
- curl_close($curl);
- $res = json_decode($response,true);
- debug_log('返回');
- debug_log($response);
- return $res;
- }
- public static function api($store_id, $url, $arrayData) {
- $arrayData['appId'] = self::appid($store_id);
- return self::postUrl($store_id, $url, $arrayData);
- }
- private static function signature($store_id, $json_data)
- {
- $data_signature = strtoupper(md5(self::appkey($store_id). $json_data));
- return $data_signature;
- }
- private static function get_millisecond()
- {
- $time = explode(" ", microtime());
- $time = $time [1] . ($time [0] * 1000);
- $time2 = explode(".", $time);
- $time = $time2 [0];
- return $time;
- }
- public static function queryTicketPages($store_id, $param = []) {
- $json = '{
- "status": "success",
- "messages": [],
- "data": {
- "postBackParameter": {
- "parameterType": "abcd",
- "parameterValue": "abcd"
- },
- "result": [
- {
- "cashierUid": 832101480292933201,
- "customerUid": 922312867022331106,
- "sn": "' . bcadd('201511121602084680006', random_int(1000000000000, 9000000000000)) . '",
- "datetime": "'. date('Y-m-d H:i:s', time() - 600) .'",
- "totalAmount": 72,
- "totalProfit": 42,
- "discount": 100,
- "externalOrderNo": "2017121521001004460219576817",
- "remark": "收银测试",
- "rounding": 0,
- "ticketType": "SELL",
- "invalid": 0,
- "payments": [
- {
- "code": "payCode_2",
- "amount": 9.42
- }
- ],
- "pointUsage":{
- "customerUid": 922312867022331106,
- "point": 80.00,
- "money": 8.00,
- "exchangeType": 1
- },
- "items": [
- {
- "name": "a2至初 婴儿配方奶粉6-12月2段",
- "buyPrice": 10,
- "sellPrice": 24,
- "customerPrice": 22,
- "quantity": 1,
- "discount": 100,
- "customerDiscount": 100,
- "totalAmount": 24,
- "totalProfit": 14,
- "isCustomerDiscount": 1,
- "productUid": 376007949281628195,
- "ticketitemattributes": [
- {
- "attributeName": "加粮",
- "attributeValue": "一匙"
- }
- ]
- },
- {
- "name": "亨氏 苹果蓝莓紫胡萝卜紫薯果汁泥 120g",
- "buyPrice": 4.5,
- "sellPrice": 7.80,
- "customerPrice": 7.80,
- "quantity": 2,
- "discount": 100,
- "customerDiscount": 100,
- "totalAmount": 15.6,
- "totalProfit": 10,
- "isCustomerDiscount": 1,
- "productUid": 498684986632650050,
- "ticketitemattributes": [
- {
- "attributeName": "加粮",
- "attributeValue": "一匙"
- }
- ]
- }
- ]
- }
- ],
- "pageSize": 100
- }
- }
- ';
- if(self::TEST_DATA){
- return json_decode($json, true);
- }
- $res = self::api($store_id, 'ticketOpenApi/queryTicketPages', $param);
- return $res;
- }
- public static function queryCustomerPages($store_id, $param = []) {
- $res = self::api($store_id, 'customerOpenApi/queryCustomerPages', $param);
- return $res;
- }
- public static function queryUserByUid($store_id, $uid = 0) {
- // $json = '{"status":"success","messages":[],"data":{"customrUid":922312867022331106,"customerUid":922312867022331106,"categoryName":"普通","number":"13932800866","name":"张","point":0.00,"discount":100,"balance":0,"phone":"13932800866","qq":"","email":"","address":"","remarks":"","createdDate":"2019-05-03 00:00:00","onAccount":0,"enable":1,"createStoreAppIdOrAccount":"9D5491A79556D828BC80BA6E990EBC84"}}';
- // if(self::TEST_DATA){
- // return json_decode($json, true);
- // }
- $res = self::api($store_id, 'customerOpenApi/queryByUid', ["customerUid" => $uid]);
- return $res;
- }
- public static function queryUserBytel($store_id, $tel = 0) {
- // $json = '{"status":"success","messages":[],"data":{"customrUid":922312867022331106,"customerUid":922312867022331106,"categoryName":"普通","number":"13932800866","name":"张","point":0.00,"discount":100,"balance":0,"phone":"13932800866","qq":"","email":"","address":"","remarks":"","createdDate":"2019-05-03 00:00:00","onAccount":0,"enable":1,"createStoreAppIdOrAccount":"9D5491A79556D828BC80BA6E990EBC84"}}';
- // if(self::TEST_DATA){
- // return json_decode($json, true);
- // }
- $res = self::api($store_id, 'customerOpenApi/queryBytel', ["customerTel" => $tel]);
- return $res;
- }
- public static function addUser($store_id, $param = []) {
- $res = self::api($store_id, 'customerOpenApi/add', $param);
- return $res;
- }
- public static function updateBalancePointByIncrement($store_id, $param = []) {
- $res = self::api($store_id, 'customerOpenApi/updateBalancePointByIncrement', $param);
- return $res;
- }
- public static function queryProductCategoryPages($store_id, $param = []) {
- $res = self::api($store_id, 'productOpenApi/queryProductCategoryPages', $param);
- return $res;
- }
- public static function queryProductPages($store_id, $param = []) {
- $res = self::api($store_id, 'productOpenApi/queryProductPages', $param);
- return $res;
- }
- public static function queryProductImgPages($store_id, $param = []) {
- $res = self::api($store_id, 'productOpenApi/queryProductImagePages', $param);
- // $res = '{"status":"success","messages":[],"data":{"postBackParameter":{"parameterType":"LAST_RESULT_MAX_ID","parameterValue":"332253"},"result":[{"productUid":307524486551868475,"productName":"美汁源爽粒花语红葡萄+玫瑰汁饮料420ml","productBarcode":"6956416205130","imageUrl":"http://pospalstoreimg.area63.pospal.cn:80//productImages/3208961/3e83648f-ebb4-4382-9244-5762dea1c9ca.jpg"},{"productUid":341670696225363202,"productName":"美汁源汁汁桃桃桃汁饮料420ml","productBarcode":"6956416206830","imageUrl":"http://pospalstoreimg.area63.pospal.cn:80//spd/23/638114656312203846.jpg"}],"pageSize":100}}';
- // $res = json_decode($res, true);
- return $res;
- }
- public static function queryProductImagesByBarcode($store_id, $uid = 0) {
- $res = self::api($store_id, 'productOpenApi/queryProductImagesByBarcode', ["productBarcode" => $uid]);
- // $res = '{"status":"success","messages":[],"data":[{"productUid":163971162588607457,"productName":"黑葡萄雨伞货号19303","productBarcode":"6928265693031","imageUrl":"http://pospalstoreimg.area63.pospal.cn:80/productImages/4953454/354b70f8-6eef-4a99-91ab-0bb60b59b59b.jpg"},{"productUid":163971162588607457,"productName":"黑葡萄雨伞货号19303","productBarcode":"6928265693031","imageUrl":"http://pospalstoreimg.area63.pospal.cn:80/productImages/4953454/585252ba-ae47-4eb6-bd65-44699f1145bf.jpg"},{"productUid":163971162588607457,"productName":"黑葡萄雨伞货号19303","productBarcode":"6928265693031","imageUrl":"http://pospalstoreimg.area63.pospal.cn:80/productImages/4953454/02b8eeff-e19b-4f9f-855c-e7a067383e93.jpg"},{"productUid":163971162588607457,"productName":"黑葡萄雨伞货号19303","productBarcode":"6928265693031","imageUrl":"http://pospalstoreimg.area63.pospal.cn:80/productImages/4953454/9c334ff4-1442-479a-b6a4-3669848637a4.jpg"}]}';
- // $res = json_decode($res, true);
- return $res;
- }
- public static function queryProductByUid($store_id, $uid = 0) {
- // $json = '{"status":"success","messages":[],"data":{"uid":376007949281628195,"categoryUid":1650434916469386247,"name":"a2至初 奶粉婴儿配方奶粉6-12月2段900g 1罐 新西兰进口","barcode":"9421902960017","buyPrice":321.000,"sellPrice":458.00,"sellPrice2":458.00,"stock":100.000,"maxStock":0,"minStock":5.00,"pinyin":"a2nf900g2d","customerPrice":412.00,"description":"","isCustomerDiscount":0,"supplierUid":0,"enable":1,"productionDate":"","createdDatetime":"2022-05-09 14:15:24","updatedDatetime":"2022-06-23 14:51:30","attribute1":"","attribute2":"","attribute3":"","attribute4":"9421902960017","attribute5":"","attribute6":"","attribute10":"100"}}';
- // if(self::TEST_DATA){
- // return json_decode($json, true);
- // }
- $res = self::api($store_id, 'productOpenApi/queryProductByUid', ["productUid" => $uid]);
- return $res;
- }
- public static function queryProductByBarcode($store_id, $Barcode = 0) {
- // $json = '{"status":"success","messages":[],"data":{"uid":376007949281628195,"categoryUid":1650434916469386247,"name":"a2至初 奶粉婴儿配方奶粉6-12月2段900g 1罐 新西兰进口","barcode":"9421902960017","buyPrice":321.000,"sellPrice":458.00,"sellPrice2":458.00,"stock":100.000,"maxStock":0,"minStock":5.00,"pinyin":"a2nf900g2d","customerPrice":412.00,"description":"","isCustomerDiscount":0,"supplierUid":0,"enable":1,"productionDate":"","createdDatetime":"2022-05-09 14:15:24","updatedDatetime":"2022-06-23 14:51:30","attribute1":"","attribute2":"","attribute3":"","attribute4":"9421902960017","attribute5":"","attribute6":"","attribute10":"100"}}';
- // if(self::TEST_DATA){
- // return json_decode($json, true);
- // }
- $res = self::api($store_id, 'productOpenApi/queryProductByBarcode', ["barcode" => $Barcode]);
- return $res;
- }
- public static function addProductInfo($store_id, $param = []) {
- $res = self::api($store_id, 'productOpenApi/addProductInfo', $param);
- return $res;
- }
- public static function updateProductInfo($store_id, $param = []) {
- $res = self::api($store_id, 'productOpenApi/updateProductInfo', $param);
- return $res;
- }
- public static function queryAccessTimes($store_id, $param = []) {
- $res = self::api($store_id, 'openApiLimitAccess/queryAccessTimes', $param);
- return $res;
- }
- public static function queryDailyAccessTimesLog($store_id, $param = []) {
- $res = self::api($store_id, 'openApiLimitAccess/queryDailyAccessTimesLog', $param);
- return $res;
- }
- }
|