Commit 920219f7 authored by 王源's avatar 王源 🎧

Merge branch 'msg-rpc'

parents 1b164b3d ee443c91
......@@ -14,6 +14,7 @@
"ext-redis": "*",
"ext-gd": "*",
"ext-curl": "*",
"ext-mbstring": "*",
"hyperf/cache": "~1.1.0",
"hyperf/framework": "~1.1.0",
"hyperf/db-connection": "~1.1.0",
......
......@@ -113,4 +113,22 @@ class MessageHandler
$this->messageService->send($receiverIds, $application, 0, 0, [], $content);
}
/**
* 发送markdown 文本消息
* @param $receiverIds
* @param $content
* @param $title
* @throws HttpResponseException
*/
public function sendMarkDownText($receiverIds, $content, $title)
{
$application = $this->config->get('app_name');
if (!$application) {
throw new HttpResponseException("请设置应用名app_name");
}
$receiverIds = is_array($receiverIds) ? $receiverIds : [$receiverIds];
$sendUserId = Auth::id();
$this->messageService->SendMarkDownMessage($receiverIds, $application, 0, $sendUserId, [], $content, $title);
}
}
......@@ -18,4 +18,23 @@ interface AppServiceInterface
* @return mixed
*/
public function getAccessApps($user, $isSuperAdmin = false);
/**
* 获取单个数据
* @param int $id
* @param array $relations 关联关系只有['group']
* @param array $columns
* @return mixed
*/
public function get(int $id, array $relations = [], array $columns = ['id', 'title']);
/**
* 通过id列表获取应用数组
* @param array $idList 默认去重
* @param array $relations 关联关系只有['group']
* @param array $columns 默认展示id和title,可传['title', 'name', 'entry', 'prefix', 'group_id', 'is_inside', 'is_active', 'icon', 'desc', 'weight']
* @return array 默认keyBy('id')
*/
public function getByIdList(array $idList, array $relations = [], array $columns = ['id', 'title']): array;
}
......@@ -162,4 +162,30 @@ interface BaseInfoServiceInterface
*/
public function getReviewUsers($teamId, $authId);
/**
* 通过id数组获取部门数组
* @param array $idList 默认去重
* @param array $relations 关联关系,默认空 ['users', 'leader']
* @param array $columns 要显示的字段,默认全部 ['id', 'name', 'pid', 'remark']
* @return array 默认keyBY('id')
*/
public function getDepartmentListByIdList(array $idList, array $relations = [], array $columns = ['*']): array;
/**
* 获取单个部门数据
* @param int $id
* @param array $relations 关联关系,默认空 ['users', 'leader']
* @param array $columns 要显示的字段,默认全部 ['id', 'name', 'pid', 'remark']
* @return array|null
*/
public function getDepartmentById($id, array $relations = [], array $columns = ['*']);
/**
* 获取所有部门数据
* @param array $relations 关联关系,默认空 ['users', 'leader']
* @param array $columns 要显示的字段,默认全部 ['id', 'name', 'pid', 'remark']
* @return array 默认已keyBy('id')
*/
public function departments(array $relations = [], array $columns = ['*']): array;
}
......@@ -22,4 +22,31 @@ interface MessageServiceInterface
* @return bool
*/
public function send(array $receiveUserId, $application, $templateId = 0, $sendUserId = 0, $replace = [], $content = ''): bool;
/**
* description:发送邮件
* author: fuyunnan
* @param array $userList ['111@qq.com','222@qq.com']
* @param string $subject 邮件标题
* @param string $body 邮件内容
* @return bool
* @throws
* Date: 2020/9/10
*/
public function sendMail($userList, $subject, $body): bool;
/**
* 发送markdown文本消息
* @param array $receiveUserId
* @param $application
* @param int $templateId
* @param int $sendUserId
* @param array $replace
* @param string $content
* @param string $title
* @return bool
*/
public function SendMarkDownMessage(array $receiveUserId, $application, $templateId = 0, $sendUserId = 0, $replace = [], $content = '',$title = ''): bool;
}
......@@ -25,22 +25,22 @@ interface StoreServiceInterface
* author: fuyunnan
* @param array $data 需要入库的数组 格式 入库添加
* *
data[master][warehousing_date]:2020-01-08 入库时间
data[master][creator_id]:12 创建人id
data[master][warehouse_id]:2 仓库id
data[master][type_id]:1 入库单类型
data[master][source_no]:no_121333 来源单号 (选填)
data[master][stock_up_status]:1二次质检状态 (选填)
data[master][remark]:备注 (选填)
data[master][status]:2 状态 (选填 不填默认1)
* data[master][warehousing_date]:2020-01-08 入库时间
* data[master][creator_id]:12 创建人id
* data[master][warehouse_id]:2 仓库id
* data[master][type_id]:1 入库单类型
* data[master][source_no]:no_121333 来源单号 (选填)
* data[master][stock_up_status]:1二次质检状态 (选填)
* data[master][remark]:备注 (选填)
* data[master][status]:2 状态 (选填 不填默认1)
*
* 产品二维数组
data[goods][0][product_id]:16 产品id
data[goods][0][should_cnt]:133 应入数量
data[goods][0][real_cnt]:10 实入数量
data[goods][1][product_id]:18
data[goods][1][should_cnt]:10
data[goods][1][real_cnt]:15
* data[goods][0][product_id]:16 产品id
* data[goods][0][should_cnt]:133 应入数量
* data[goods][0][real_cnt]:10 实入数量
* data[goods][1][product_id]:18
* data[goods][1][should_cnt]:10
* data[goods][1][real_cnt]:15
*
* 或者参考yapi http://api.huaperfect.com/project/38/interface/api/1617
*
......@@ -51,30 +51,28 @@ interface StoreServiceInterface
public function createWarehousing(array $data): array;
/**
* description:批量创建出库单
* author: fuyunnan
* [
'main' => [
    'creator_id' => 1,
    'warehouse_id' => 1,
    'type' => 5,
],
'products' => [
[
    'source_no' => 1,
    'product_id' => 1,
    'real_cnt' => 1
],
[
    'source_no' => 1,
    'product_id' => 1,
    'real_cnt' => 1
]
]
]
* 'main' => [
*     'creator_id' => 1,
*     'warehouse_id' => 1,
*     'type' => 5,
* ],
* 'products' => [
* [
*     'source_no' => 1,
*     'product_id' => 1,
*     'real_cnt' => 1
* ],
* [
*     'source_no' => 1,
*     'product_id' => 1,
*     'real_cnt' => 1
* ]
* ]
* ]
*
* @param array $attributes 提交的数组 或参考yapi http://api.huaperfect.com/project/38/interface/api/6968
* @return array
......@@ -173,6 +171,17 @@ interface StoreServiceInterface
* @throws
* Date: 2020/7/31
*/
public function checkStock($ids):array;
public function checkStock($ids): array;
/**
* description:出库单 恢复库存 出库单定为已取消
* author: fuyunnan
* @param string $sourceNo 来源单号
* @return int
* @throws
* Date: 2020/9/7
*/
public function restoreStock($sourceNo): int;
}
\ No newline at end of file
......@@ -168,6 +168,20 @@ abstract class AbstractShopify
return $this->processResponse($response, $dataKey);
}
/**
* 分页
* @param null $url
* @param array $urlParams
* @return mixed ['data' => [数据], 'next_link' => '下一页链接']
* @throws Exception
*/
public function page($url = null, $urlParams = [])
{
if (!$url) $url = $this->generateUrl($urlParams);
$response = HttpRequestJson::get($url, $this->httpHeaders);
return $this->processPageResponse($response, $this->pluralizeKey);
}
/**
* 根据id获取一条数据
* @param $id
......@@ -284,4 +298,53 @@ abstract class AbstractShopify
}
}
/**
* 处理响应
* @param array $response
* @param null $dataKey
* @return mixed
* @throws Exception
*/
public function processPageResponse($response, $dataKey = null)
{
[$code, $header, $body] = $response;
$content = json_decode($body, true);
$link = $this->getLink($header);
if (isset($content['errors'])) {
throw new Exception($this->castString($content['errors']), $code);
}
if ($dataKey && isset($content[$dataKey])) {
$data = $content[$dataKey];
} else {
$data = $content;
}
return ['data' => $data, 'next_link' => $link];
}
public function getLink($header, $type = 'next')
{
if (array_key_exists('x-shopify-api-version', $header) && $header['x-shopify-api-version'] < '2019-07') {
return null;
}
if (!empty($header['link'])) {
if (stristr($header['link'], '; rel="' . $type . '"') > -1) {
$headerLinks = explode(',', $header['link']);
foreach ($headerLinks as $headerLink) {
if (stristr($headerLink, '; rel="' . $type . '"') === -1) {
continue;
}
$pattern = '#<(.*?)>; rel="' . $type . '"#m';
preg_match($pattern, $headerLink, $linkResponseHeaders);
if ($linkResponseHeaders) {
return $linkResponseHeaders[1];
}
}
}
}
return null;
}
}
......@@ -8,8 +8,8 @@
namespace Meibuyu\Micro\Tools;
use GuzzleHttp\Client;
use Psr\Http\Message\ResponseInterface;
//use GuzzleHttp\Client;
//use Psr\Http\Message\ResponseInterface;
/**
* json格式请求(非协程)
......@@ -19,54 +19,112 @@ use Psr\Http\Message\ResponseInterface;
class HttpRequestJson
{
protected static function prepareRequest($headers, $data = [])
{
$data = json_encode($data);
if (!empty($data)) {
$headers['Content-type'] = 'application/json';
$headers['Content-Length'] = strlen($data);
}
return [$headers, $data];
}
// /**
// * get请求
// * @param $url
// * @param array $httpHeaders
// * @return ResponseInterface
// */
// public static function get($url, $httpHeaders = [])
// {
// $client = new Client(['timeout' => 30]);
// return $client->get($url, ['headers' => $httpHeaders]);
// }
//
// /**
// * post请求
// * @param $url
// * @param $data
// * @param array $httpHeaders
// * @return ResponseInterface
// */
// public static function post($url, $data, $httpHeaders = [])
// {
// $client = new Client(['timeout' => 30]);
// return $client->post($url, ['headers' => $httpHeaders, 'json' => $data]);
// }
//
// /**
// * put请求
// * @param $url
// * @param $data
// * @param array $httpHeaders
// * @return ResponseInterface
// */
// public static function put($url, $data, $httpHeaders = [])
// {
// $client = new Client(['timeout' => 30]);
// return $client->put($url, ['headers' => $httpHeaders, 'json' => $data]);
// }
//
// /**
// * delete请求
// * @param $url
// * @param array $httpHeaders
// * @return ResponseInterface
// */
// public static function delete($url, $httpHeaders = [])
// {
// $client = new Client(['timeout' => 30]);
// return $client->delete($url, ['headers' => $httpHeaders]);
// }
/**
* get请求
* @param $url
* @param array $httpHeaders
* @return ResponseInterface
* @param array $headers
* @return array
*/
public static function get($url, $httpHeaders = [])
public static function get($url, $headers = [])
{
$client = new Client();
return $client->get($url, ['headers' => $httpHeaders]);
return CurlRequest::get($url, $headers);
}
/**
* post请求
* @param $url
* @param $dataArray
* @param array $httpHeaders
* @return ResponseInterface
* @param $data
* @param array $headers
* @return array
*/
public static function post($url, $dataArray, $httpHeaders = [])
public static function post($url, $data, $headers = [])
{
$client = new Client();
return $client->post($url, ['headers' => $httpHeaders, 'json' => $dataArray]);
[$headers, $data] = self::prepareRequest($headers, $data);
return CurlRequest::post($url, $data, $headers);
}
/**
* put请求
* @param $url
* @param $dataArray
* @param array $httpHeaders
* @return ResponseInterface
* @param $data
* @param array $headers
* @return array
*/
public static function put($url, $dataArray, $httpHeaders = [])
public static function put($url, $data, $headers = [])
{
$client = new Client();
return $client->put($url, ['headers' => $httpHeaders, 'json' => $dataArray]);
[$headers, $data] = self::prepareRequest($headers, $data);
return CurlRequest::put($url, $data, $headers);
}
/**
* delete请求
* @param $url
* @param array $httpHeaders
* @return ResponseInterface
* @param array $headers
* @return array
*/
public static function delete($url, $httpHeaders = [])
public static function delete($url, $headers = [])
{
$client = new Client();
return $client->delete($url, ['headers' => $httpHeaders]);
return CurlRequest::delete($url, $headers);
}
}
<?php
/**
* Created by PhpStorm.
* User: Zero
* Date: 2020/9/17
* Time: 8:40
*/
namespace Meibuyu\Micro\Tools;
use Exception;
/**
* 图片工具类
* Class Imager
* @package Meibuyu\Micro\Tools
*/
class Imager
{
/**
* 图片转base64,暂不支持外部地址图片
* @param $path
* @param bool $noPrefix 不需要前缀
* @return string
* @throws Exception
*/
public static function img2Base64($path, $noPrefix = false)
{
$path = self::parsePath($path);
if (file_exists($path)) {
$fp = fopen($path, "r"); // 图片是否可读权限
if ($fp) {
$imgInfo = getimagesize($path); // 取得图片的大小,类型等
$content = fread($fp, filesize($path));
$content = chunk_split(base64_encode($content)); // base64编码
if ($noPrefix) {
$base64 = $content;
} else {
$base64 = 'data:' . $imgInfo['mime'] . ';base64,' . $content; // 合成图片的base64编码
}
fclose($fp);
return $base64;
} else {
throw new Exception('图片读取失败');
}
} else {
throw new Exception('图片不存在');
}
}
/**
* @param $path
* @return string
* @throws Exception
*/
public static function parsePath($path)
{
if (strstr($path, 'http')) {
$appDomain = config('app_domain');
if (strstr($path, $appDomain)) {
$path = str_replace($appDomain, '', $path);
} else {
throw new Exception('暂不支持外部地址图片');
}
}
$documentRoot = config('server.settings.document_root');
if (!strstr($path, $documentRoot)) {
$path = trim(trim($path), '/');
$path = $documentRoot . '/' . $path;
}
return $path;
}
}
......@@ -754,7 +754,36 @@ if (!function_exists('to_camel_case')) {
}
}
if (!function_exists('mb_trim')) {
/**
* 去除两边带全角空格的字符串
* @param $str
* @return string
* @author zero
*/
function mb_trim($str)
{
mb_regex_encoding('utf-8');
$str = mb_ereg_replace(' ', '', $str);
return trim($str);
}
}
if (!function_exists('str_replace_first')) {
/**
* 用替换字符串替换第一个出现的搜索字符串
* @param mixed $search 搜索字符串
* @param mixed $replace 替换字符串
* @param mixed $subject 被替换字符串
* @return string
* @author zero
*/
function str_replace_first($search, $replace, $subject)
{
if (($position = strpos($subject, $search)) !== false) {
$replaceLen = strlen($search);
$subject = substr_replace($subject, $replace, $position, $replaceLen);
}
return $subject;
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment