Commit 398c2a8e authored by hujun's avatar hujun

生成周报和日报图片

parent 01954bbd
......@@ -4,6 +4,7 @@ namespace app\api_broker\controller;
use app\api_broker\extend\Basic;
use app\api_broker\service\StatementService;
use app\model\RAgentReport;
use think\Exception;
use think\Request;
......@@ -49,63 +50,61 @@ class Statement extends Basic
}
/**
* 生成日报和周报图片
*
* @return \think\Response
*/
public function weekWorkImg()
{
$params = array(
"agent_id" => 1,
"img" => "12313",
"is_square" => "123123",
"start_time" => "2018-03-20 12:11:21",
"end_time" => "2018-03-21 12:11:21",
"type" => 1, //0日报 1周报
);
if (empty($params["agent_id"]) || empty($params["img"]) || empty($params["table"])) {
if (empty($this->params["agent_id"]) || empty($this->params["img"])) {
return $this->response("101", "参数错误");
}
$img_title = "";
$img = "";
//单图
$base64_image_content = $params["img"];
$base64_image_content = $this->params["img"];
if (preg_match('/^(data:\s*image\/(\w+);base64,)/', $base64_image_content, $array)) {
$img_title = $array[2]; //jpeg
$img = base64_decode(str_replace($array[1], '', $base64_image_content)); //返回文件流
}
$tmp_file = time();
$img_name = md5(uniqid($tmp_file)) . '.' . $img_title;//图片名
$url = "week_work_img/" . $img_name;
file_put_contents($url, $img);
$data['id'] = '';
$data['house_id'] = $this->request->data['house_id'];
$data['start_time'] = $this->request->data['start_time'];
$data['end_time'] = $this->request->data['end_time'];
$data['img'] = $img_name;
$data['agent_id'] = $params["agent_id"];
$data['table'] = $this->request->data['table'];
if (empty($this->request->data['type'])) {
$data['type'] = 0;//周报
$url = 'static/week_work_img/' . $img_name;
$code = 200;
$msg = '';
if (file_put_contents($url, $img)) {
$agent_report = new RAgentReport();
if (empty($this->params['type'])) {
$data['start_time'] = $this->params['start_time'];
$data['end_time'] = $this->params['start_time'];
} else {
$data['type'] = 1;//日报
$data['start_time'] = $this->params['start_time'];
$data['end_time'] = $this->params['end_time'];
}
$result1 = $this->Weekwork->save($data);
$data['agent_id'] = $this->params['agent_id'];
$data['img_url'] = $this->params['agent_id'];
$data['type'] = $this->params['type'];
if ($result1) {
$result["status"] = "1";
$result["imgname"] = $imgname;
$result["msg"] = "成功";
$result = $agent_report->editData($data);
} else {
$result["msg"] = "上传失败";
$result = 0;
}
echo json_encode($result);
exit;
if (!$result) {
$code = 101;
$msg = '生成图片失败';
}
return $this->response($code, $msg);
}
}
\ No newline at end of file
......@@ -21,6 +21,7 @@ define('CHAT_IMG_URL', CURRENT_URL . 'static'. DS . 'chat_image/'); //聊天图
define('CK_IMG_URL', CURRENT_URL . '/resource/lib/Attachments/'); //ck 资源文件
define('_POOLKEY','FC100000022056027');//隐私号码
define('_TLSYPoolKey','FC100000022056027');//隐私号码池
define('WEEK_WORK_IMG', CURRENT_URL . 'static'. DS . 'week_work_img/'); //周报日报目录
return [
// +----------------------------------------------------------------------
// | 应用设置
......
<?php
/**
* Created by PhpStorm.
* User: fuju
* Date: 2018/3/23
* Time: 14:30
*/
namespace app\model;
class RAgentReport extends BaseModel
{
}
\ No newline at end of file
......@@ -356,6 +356,7 @@ Route::group('broker', [
'selectPerformanceByTime' => ['api_broker/Performance/selectPerformanceByTime', ['method' => 'get']],
'weekWorkImg' => ['api_broker/Statement/weekWorkImg', ['method' => 'post']], //生成周报和日报图片
]);
......
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